localizer
parent
0d1b9f679c
commit
077aefb7a8
|
|
@ -1,5 +1,7 @@
|
|||
package com.njzscloud.supervisory.device.service;
|
||||
|
||||
import cn.hutool.cache.CacheUtil;
|
||||
import cn.hutool.cache.impl.TimedCache;
|
||||
import cn.hutool.core.map.MapBuilder;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
|
@ -7,6 +9,7 @@ import com.alibaba.fastjson2.JSONObject;
|
|||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njzscloud.common.core.tuple.Tuple2;
|
||||
import com.njzscloud.common.mp.support.PageParam;
|
||||
import com.njzscloud.common.mp.support.PageResult;
|
||||
import com.njzscloud.common.mqtt.util.Mqtt;
|
||||
|
|
@ -39,6 +42,7 @@ import java.util.Objects;
|
|||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DeviceInfoService extends ServiceImpl<DeviceInfoMapper, DeviceInfoEntity> implements IService<DeviceInfoEntity> {
|
||||
private static final TimedCache<String, Tuple2<String, String>> waitOpen = CacheUtil.newTimedCache(600000);
|
||||
private final OrderInfoService orderInfoService;
|
||||
|
||||
/**
|
||||
|
|
@ -306,6 +310,27 @@ public class DeviceInfoService extends ServiceImpl<DeviceInfoMapper, DeviceInfoE
|
|||
.build();
|
||||
}
|
||||
|
||||
public static void open(String oredrSn) {
|
||||
Tuple2<String, String> tuple2 = waitOpen.get(oredrSn);
|
||||
if (tuple2 == null) {
|
||||
log.warn("开门: {} 无等待订单", oredrSn);
|
||||
return;
|
||||
}
|
||||
String sn = tuple2.get_0();
|
||||
String cid = tuple2.get_1();
|
||||
log.info("开门: {} {}", sn, cid);
|
||||
Mqtt.publish(cid + "/1/barrier", MapUtil.builder()
|
||||
.put("deviceNo", sn)
|
||||
.build());
|
||||
}
|
||||
|
||||
private void open(String sn, String cid) {
|
||||
log.info("开门: {} {}", sn, cid);
|
||||
Mqtt.publish(cid + "/1/barrier", MapUtil.builder()
|
||||
.put("deviceNo", sn)
|
||||
.build());
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Map<String, Object> report2(JSONObject data) {
|
||||
MapBuilder<String, Object> resBuilder = MapUtil.<String, Object>builder()
|
||||
|
|
@ -382,7 +407,7 @@ public class DeviceInfoService extends ServiceImpl<DeviceInfoMapper, DeviceInfoE
|
|||
BigDecimal weight_ = new BigDecimal(weight);
|
||||
BigDecimal v = weight_.divide(new BigDecimal(1000), 2, RoundingMode.HALF_UP);
|
||||
try {
|
||||
orderInfoService.truckLeaving(new TruckLeavingOrderParam()
|
||||
boolean b = orderInfoService.truckLeaving(new TruckLeavingOrderParam()
|
||||
.setOrderId(orderId)
|
||||
.setWeight(weight)
|
||||
.setFrontPhoto(frontPhoto)
|
||||
|
|
@ -390,8 +415,12 @@ public class DeviceInfoService extends ServiceImpl<DeviceInfoMapper, DeviceInfoE
|
|||
0);
|
||||
// 播语音
|
||||
playVoice(sn, cid, "{}称重完成,磅重{}吨", licensePlate, v.toPlainString());
|
||||
// 开门
|
||||
open(sn, cid);
|
||||
if (b) {
|
||||
// 开门
|
||||
open(sn, cid);
|
||||
} else {
|
||||
waitOpen.put(orderPagingResult.getSn(), Tuple2.create(sn, cid));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
playVoice(sn, cid, "{}称重异常,磅重{}吨", licensePlate, v.toPlainString());
|
||||
}
|
||||
|
|
@ -402,13 +431,6 @@ public class DeviceInfoService extends ServiceImpl<DeviceInfoMapper, DeviceInfoE
|
|||
.build();
|
||||
}
|
||||
|
||||
private void open(String sn, String cid) {
|
||||
log.info("开门: {} {}", sn, cid);
|
||||
Mqtt.publish(cid + "/1/barrier", MapUtil.builder()
|
||||
.put("deviceNo", sn)
|
||||
.build());
|
||||
}
|
||||
|
||||
private void playVoice(String sn, String cid, String content, Object... params) {
|
||||
String format = StrUtil.format(content, params);
|
||||
log.info("播语音: {} {} {}", sn, cid, format);
|
||||
|
|
|
|||
|
|
@ -1033,7 +1033,7 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
|||
* @param i 0-->自动、1-->手动
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void truckLeaving(TruckLeavingOrderParam truckLeavingOrderParam, int i) {
|
||||
public boolean truckLeaving(TruckLeavingOrderParam truckLeavingOrderParam, int i) {
|
||||
OrderInfoEntity orderInfoEntity = this.getById(truckLeavingOrderParam.getOrderId());
|
||||
Long truckId = orderInfoEntity.getTruckId();
|
||||
try {
|
||||
|
|
@ -1080,7 +1080,9 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
|||
|
||||
// 扣费
|
||||
handleCompanyPay(orderInfoEntity);
|
||||
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
} finally {
|
||||
|
|
|
|||
Loading…
Reference in New Issue