优化代码

main
judy 1 year ago
parent 33bb34dd59
commit 15d40ade74
  1. 64
      shkj-wms/src/main/java/com/shkj/wcs/plc/PlcEventTask.java
  2. 6
      shkj-wms/src/main/java/com/shkj/wcs/plc/PlcInit.java
  3. 2
      shkj-wms/src/main/java/com/shkj/wcs/third/stacker/StkCallUtil.java
  4. 1
      shkj-wms/src/main/java/com/shkj/wms/service/impl/BaseMoldServiceImpl.java
  5. 5
      shkj-wms/src/main/java/com/shkj/wms/service/impl/BusinOutInPlanServiceImpl.java

@ -118,14 +118,14 @@ public class PlcEventTask {
} }
//输送线心跳
@Scheduled(fixedDelay = 4000) @Scheduled(fixedDelay = 4000)
public void writePlcheartbeat(){ public void writePlcheartbeatDps(){
//根据连接的plcId获取属性 //根据连接的plcId获取属性
PlcOperate plcOperate = plcInit.getPlcOperate_dps(); PlcOperate plcOperate = plcInit.getPlcOperate_dps();
PLCReadAndWrite plcReadAndWrite = new PLCReadAndWrite(); PLCReadAndWrite plcReadAndWrite = new PLCReadAndWrite();
Map<String, Object> readPointMap = new HashMap<>(); Map<String, Object> readPointMap = new HashMap<>();
String heartbeat="DB320.0.1"; String heartbeat="DB320.0.0";
readPointMap.put(heartbeat,"Boolean"); readPointMap.put(heartbeat,"Boolean");
Map<String, Object> pointMap = plcReadAndWrite.readPlcData(plcOperate, JsonUtil.toJSONString(readPointMap)); Map<String, Object> pointMap = plcReadAndWrite.readPlcData(plcOperate, JsonUtil.toJSONString(readPointMap));
@ -142,11 +142,38 @@ public class PlcEventTask {
allHbMap.put(heartbeat, writeHbMap); allHbMap.put(heartbeat, writeHbMap);
Boolean heartType = plcReadAndWrite.execWrite(plcOperate, JsonUtil.toJSONString(allHbMap)); Boolean heartType = plcReadAndWrite.execWrite(plcOperate, JsonUtil.toJSONString(allHbMap));
if(!heartType){ if(!heartType){
log.info("心跳写入失败,重连服务器"); log.info("dps心跳写入失败,重连服务器");
plcInit.connect(); plcInit.connect();
} }
} }
//堆垛机心跳
@Scheduled(fixedDelay = 4000)
public void writePlcheartbeatStk(){
//根据连接的plcId获取属性
PlcOperate plcOperate = plcInit.getPlcOperate_stk();
PLCReadAndWrite plcReadAndWrite = new PLCReadAndWrite();
Map<String, Object> readPointMap = new HashMap<>();
String heartbeat="DB20.0.4";
readPointMap.put(heartbeat,"Boolean");
Map<String, Object> pointMap = plcReadAndWrite.readPlcData(plcOperate, JsonUtil.toJSONString(readPointMap));
//读取心跳,并判断是写入true还是false;
Boolean heartbeatV = false;
if (pointMap.containsKey(heartbeat)) {
heartbeatV = Boolean.valueOf(pointMap.get(heartbeat).toString());
}
heartbeatV = (heartbeatV == true) ? false : true;
Map<String, Object> writeHbMap = new HashMap<>(1);
writeHbMap.put("Boolean", heartbeatV);
Map<String, Object> allHbMap = new HashMap<>(1);
allHbMap.put(heartbeat, writeHbMap);
Boolean heartType = plcReadAndWrite.execWrite(plcOperate, JsonUtil.toJSONString(allHbMap));
if(!heartType){
log.info("stk心跳写入失败,重连服务器");
plcInit.connect();
}
}
public void plcTask(PlcOperate plcOperate, WcsPlcConnectVo conn, String pointTables) { public void plcTask(PlcOperate plcOperate, WcsPlcConnectVo conn, String pointTables) {
@ -330,7 +357,7 @@ public class PlcEventTask {
Boolean twoOverlengthV=false,twoLwideV=false,twoRwideV=false,twoHighV=false; Boolean twoOverlengthV=false,twoLwideV=false,twoRwideV=false,twoHighV=false;
String oneWcsErrExit ="",twoWcsErrExit =""; String oneWcsErrExit ="",twoWcsErrExit ="";
String oneEcsErrExitVT ="",twoWcsErrExitVT =""; String oneWcsErrExitVT="",twoWcsErrExitVT ="";
for (WcsPlcProperty plcProperty : propertyList) { for (WcsPlcProperty plcProperty : propertyList) {
String pointType = plcProperty.getPointType(); String pointType = plcProperty.getPointType();
//请求分配 //请求分配
@ -384,7 +411,7 @@ public class PlcEventTask {
twoHigh =plcProperty.getAddress(); twoHigh =plcProperty.getAddress();
} else if (pointType.equals("ontExit")){ } else if (pointType.equals("ontExit")){
oneWcsErrExit =plcProperty.getAddress(); oneWcsErrExit =plcProperty.getAddress();
oneEcsErrExitVT = plcProperty.getValueType(); oneWcsErrExitVT = plcProperty.getValueType();
} else if (pointType.equals("twoExit")){ } else if (pointType.equals("twoExit")){
twoWcsErrExit =plcProperty.getAddress(); twoWcsErrExit =plcProperty.getAddress();
twoWcsErrExitVT = plcProperty.getValueType(); twoWcsErrExitVT = plcProperty.getValueType();
@ -411,12 +438,13 @@ public class PlcEventTask {
PlanOrderLocationVo data = orderResult.getData(); PlanOrderLocationVo data = orderResult.getData();
taskId = data.getOrderNo(); taskId = data.getOrderNo();
cargoHeight = data.getType();//获取托盘或模具类型 cargoHeight = data.getType();//获取托盘或模具类型
}else { }
else {
redisTemplate.opsForValue().set(RedisConstant.redisPutInExeMsg+orderResult.getMsg(),orderResult.getMsg()); redisTemplate.opsForValue().set(RedisConstant.redisPutInExeMsg+orderResult.getMsg(),orderResult.getMsg());
log.info("获取任务信息失败:"+orderResult.getMsg()+"托盘条码:"+barcodeValue); log.info("获取任务信息失败:"+orderResult.getMsg()+"托盘条码:"+barcodeValue);
//回填任务号 //回填任务号
Map<String, Boolean> writeMap = new HashMap<>(1); Map<String, Integer> writeMap = new HashMap<>(1);
writeMap.put(oneEcsErrExitVT, true); writeMap.put(oneWcsErrExitVT, 1);
Map<String, Object> allMap = new HashMap<>(1); Map<String, Object> allMap = new HashMap<>(1);
allMap.put(oneWcsErrExit, writeMap); allMap.put(oneWcsErrExit, writeMap);
Boolean errBoolean = plcReadAndWrite.execWrite(plcOperate, JsonUtil.toJSONString(allMap)); Boolean errBoolean = plcReadAndWrite.execWrite(plcOperate, JsonUtil.toJSONString(allMap));
@ -441,6 +469,10 @@ public class PlcEventTask {
Map<String, String> cargoHeightMap = new HashMap<>(1); Map<String, String> cargoHeightMap = new HashMap<>(1);
cargoHeightMap.put(oneHignTypeVT, cargoHeight); cargoHeightMap.put(oneHignTypeVT, cargoHeight);
allMap.put(oneHignType, cargoHeightMap); allMap.put(oneHignType, cargoHeightMap);
Map<String, Integer> wcsErrwriteMap = new HashMap<>(1);
wcsErrwriteMap.put(oneWcsErrExitVT, 0);
allMap.put(oneWcsErrExit,wcsErrwriteMap);
log.info("1楼按下入库按钮时,给输送线写命令数据:{}"+allMap); log.info("1楼按下入库按钮时,给输送线写命令数据:{}"+allMap);
Boolean taskBoolean = plcReadAndWrite.execWrite(plcOperate, JsonUtil.toJSONString(allMap)); Boolean taskBoolean = plcReadAndWrite.execWrite(plcOperate, JsonUtil.toJSONString(allMap));
@ -476,8 +508,8 @@ public class PlcEventTask {
redisTemplate.opsForValue().set(RedisConstant.redisPutInExeMsg+orderResult.getMsg(),orderResult.getMsg()); redisTemplate.opsForValue().set(RedisConstant.redisPutInExeMsg+orderResult.getMsg(),orderResult.getMsg());
log.info("2楼获取任务信息失败:"+orderResult.getMsg()+"托盘条码:"+barcodeValue); log.info("2楼获取任务信息失败:"+orderResult.getMsg()+"托盘条码:"+barcodeValue);
//回填任务号 //回填任务号
Map<String, Boolean> writeMap = new HashMap<>(1); Map<String, Integer> writeMap = new HashMap<>(1);
writeMap.put(twoWcsErrExitVT, true); writeMap.put(twoWcsErrExitVT, 1);
Map<String, Object> allMap = new HashMap<>(1); Map<String, Object> allMap = new HashMap<>(1);
allMap.put(twoWcsErrExit, writeMap); allMap.put(twoWcsErrExit, writeMap);
Boolean errBoolean = plcReadAndWrite.execWrite(plcOperate, JsonUtil.toJSONString(allMap)); Boolean errBoolean = plcReadAndWrite.execWrite(plcOperate, JsonUtil.toJSONString(allMap));
@ -502,6 +534,10 @@ public class PlcEventTask {
Map<String, String> cargoHeightMap = new HashMap<>(1); Map<String, String> cargoHeightMap = new HashMap<>(1);
cargoHeightMap.put(twoHignTypeVT, cargoHeight); cargoHeightMap.put(twoHignTypeVT, cargoHeight);
allMap.put(twoHignType, cargoHeightMap); allMap.put(twoHignType, cargoHeightMap);
Map<String, Integer> wcsErrwriteMap = new HashMap<>(1);
wcsErrwriteMap.put(twoWcsErrExitVT, 0);
allMap.put(twoWcsErrExit,wcsErrwriteMap);
log.info("2楼按下入库按钮时,给输送线写命令数据:{}"+allMap); log.info("2楼按下入库按钮时,给输送线写命令数据:{}"+allMap);
@ -670,10 +706,9 @@ public class PlcEventTask {
public void stkRealTimeTask(List<WcsPlcProperty> propertyList,Map<String, Object> pointMap, PLCReadAndWrite plcReadAndWrite,PlcOperate plcOperate,String pointTables){ public void stkRealTimeTask(List<WcsPlcProperty> propertyList,Map<String, Object> pointMap, PLCReadAndWrite plcReadAndWrite,PlcOperate plcOperate,String pointTables){
try { try {
if (pointMap.isEmpty()){ if (pointMap.isEmpty()){
plcInit.connect();
pointMap = plcReadAndWrite.readPlcData(plcOperate, pointTables); pointMap = plcReadAndWrite.readPlcData(plcOperate, pointTables);
log.info("堆垛机为空时,重新读取的属性值{} ",pointMap); log.info("堆垛机为空时,重新读取的属性值{} ",pointMap);
}else {
plcInit.connect();
} }
//实时监测堆垛机完成状态,调用库存处理逻辑 //实时监测堆垛机完成状态,调用库存处理逻辑
Long taskId=0L; Long taskId=0L;
@ -828,6 +863,9 @@ public class PlcEventTask {
} else if (stkProperty.getPointType().equals("102")) { } else if (stkProperty.getPointType().equals("102")) {
plcOrderType = stkProperty.getAddress(); plcOrderType = stkProperty.getAddress();
plcOrderTypeValue=stkProperty.getValueType(); plcOrderTypeValue=stkProperty.getValueType();
}else if (stkProperty.getPointType().equals("103")) {
plcPlatform =stkProperty.getAddress();
plcPlatformValueType=stkProperty.getValueType();
}else if (stkProperty.getPointType().equals("4")) { }else if (stkProperty.getPointType().equals("4")) {
readfinish = stkProperty.getAddress(); readfinish = stkProperty.getAddress();
readfinishValueType=stkProperty.getValueType(); readfinishValueType=stkProperty.getValueType();

@ -36,7 +36,7 @@ public class PlcInit {
public void init(){ public void init(){
log.info("初始化连接对象"); log.info("初始化连接对象");
executorService.scheduleWithFixedDelay( executorService.scheduleWithFixedDelay(
() -> reconnect(), 20, 20, TimeUnit.SECONDS () -> reconnect(), 200, 200, TimeUnit.SECONDS
); );
connect(); connect();
} }
@ -73,10 +73,10 @@ public class PlcInit {
} }
private void reconnect(){ private void reconnect(){
if (!plcOperate_dps.isConnectd()){ if (!plcOperate_dps.isConnectd()){
connect(); // connect();
} }
if (!plcOperate_stk.isConnectd()){ if (!plcOperate_stk.isConnectd()){
connect(); // connect();
} }
} }

@ -301,7 +301,7 @@ public class StkCallUtil {
redisTemplate.opsForValue().set(RedisConstant.redisTaskOut, taskId); redisTemplate.opsForValue().set(RedisConstant.redisTaskOut, taskId);
return Result.ok(); return Result.ok();
} else { } else {
log.info("堆垛机下发命令失败:"+one.getTaskId()); log.info(one.getTaskId()+"堆垛机下发命令失败");
return Result.err(); return Result.err();
} }
} }

@ -319,7 +319,6 @@ public class BaseMoldServiceImpl extends ServiceImpl<BaseMoldMapper, BaseMold> i
baseMoldVo.setIsOut("out"); baseMoldVo.setIsOut("out");
} }
} }
} }
} }
return Result.ok().data(moldVoList); return Result.ok().data(moldVoList);

@ -971,7 +971,8 @@ public class BusinOutInPlanServiceImpl extends ServiceImpl<BusinOutInPlanMapper,
//正在执行入库计划,如果有多个入库则取最新一次入库的; //正在执行入库计划,如果有多个入库则取最新一次入库的;
LambdaQueryWrapper<BusinOutInPlan> eq = new LambdaQueryWrapper<BusinOutInPlan>() LambdaQueryWrapper<BusinOutInPlan> eq = new LambdaQueryWrapper<BusinOutInPlan>()
.eq(BusinOutInPlan::getContainerCode, containerCode) .eq(BusinOutInPlan::getContainerCode, containerCode)
.eq(BusinOutInPlan::getPlanStatus, PlanStatusEnum.WAIT.getValue()) .in(BusinOutInPlan::getPlanStatus,PlanStatusEnum.WAIT.getValue(),PlanStatusEnum.DOING.getValue())
//.eq(BusinOutInPlan::getPlanStatus, PlanStatusEnum.WAIT.getValue())
.in(BusinOutInPlan::getType,PlanTypeEnum.IN.getValue(),PlanTypeEnum.BACK.getValue(),PlanTypeEnum.INV_BACK.getValue(),PlanTypeEnum.EMPTY_IN.getValue()) .in(BusinOutInPlan::getType,PlanTypeEnum.IN.getValue(),PlanTypeEnum.BACK.getValue(),PlanTypeEnum.INV_BACK.getValue(),PlanTypeEnum.EMPTY_IN.getValue())
.orderByDesc(BusinOutInPlan::getCreateTime) .orderByDesc(BusinOutInPlan::getCreateTime)
// .eq(BusinOutInPlan::getType, planType) // .eq(BusinOutInPlan::getType, planType)
@ -1004,13 +1005,11 @@ public class BusinOutInPlanServiceImpl extends ServiceImpl<BusinOutInPlanMapper,
}else if(qtySum ==invQtySum && qtySum==0 && qtySum ==0){ }else if(qtySum ==invQtySum && qtySum==0 && qtySum ==0){
vo.setType(LocationPlanTypeEnum.EMPTY.getValue()); vo.setType(LocationPlanTypeEnum.EMPTY.getValue());
} }
}else { }else {
BigDecimal qty = ones.stream().map(x -> x.getQty()).reduce(BigDecimal.ZERO, BigDecimal::add); BigDecimal qty = ones.stream().map(x -> x.getQty()).reduce(BigDecimal.ZERO, BigDecimal::add);
vo.setType(qty.compareTo(BigDecimal.ZERO) == 0 ? LocationPlanTypeEnum.EMPTY.getValue() : location.getType()); vo.setType(qty.compareTo(BigDecimal.ZERO) == 0 ? LocationPlanTypeEnum.EMPTY.getValue() : location.getType());
} }
vo.setOrderNo(one.getOrderNo()); vo.setOrderNo(one.getOrderNo());
return Result.ok().data(vo); return Result.ok().data(vo);
} }

Loading…
Cancel
Save