出库时给堆垛机下发指令

main
judy 1 year ago
parent c57019ab90
commit e7e66459d9
  1. 5
      shkj-common/src/main/java/com/shkj/common/utils/MessageUtils.java
  2. 1
      shkj-quartz/src/main/java/com/shkj/quartz/task/ThirdTask.java
  3. 43
      shkj-wms/src/main/java/com/shkj/wcs/plc/PlcEventTask.java
  4. 115
      shkj-wms/src/main/java/com/shkj/wcs/third/stacker/StkCallUtil.java
  5. 4
      shkj-wms/src/main/java/com/shkj/wms/domain/SysThirdExceptionRequest.java
  6. 19
      shkj-wms/src/main/java/com/shkj/wms/service/impl/SysThirdExceptionRequestServiceImpl.java

@ -24,13 +24,8 @@ public class MessageUtils {
public static String message(String code, Object... args) { public static String message(String code, Object... args) {
try { try {
MessageSource messageSource = SpringUtils.getBean(MessageSource.class); MessageSource messageSource = SpringUtils.getBean(MessageSource.class);
//log.info("获取到的语言:"+LocaleContextHolder.getLocale());
String message = messageSource.getMessage(code, args, LocaleContextHolder.getLocale());
//log.info("传入参数:"+code+"转换参数:"+message);
return messageSource.getMessage(code, args, LocaleContextHolder.getLocale()); return messageSource.getMessage(code, args, LocaleContextHolder.getLocale());
} catch (Exception e) { } catch (Exception e) {
// e.printStackTrace();
// log.error("国际化出错了 = {}", e.getMessage()); // log.error("国际化出错了 = {}", e.getMessage());
} }
return code; return code;

@ -17,7 +17,6 @@ public class ThirdTask {
public void doTask() { public void doTask() {
sysThirdExceptionRequestService.doTask(); sysThirdExceptionRequestService.doTask();
} }
} }

@ -106,11 +106,11 @@ public class PlcEventTask {
} }
for (WcsPlcConnectVo conn : plcList) { for (WcsPlcConnectVo conn : plcList) {
if (conn.getPlcIp().equals("192.168.150.154")){ if (conn.getPlcIp().contains("150.154")){
plcTask(plcInit.getPlcOperate_stk(), conn, conn.getPointTables()); plcTask(plcInit.getPlcOperate_stk(), conn, conn.getPointTables());
} }
if (conn.getPlcIp().equals("192.168.150.150")){ if (conn.getPlcIp().contains("150.150")){
plcTask(plcInit.getPlcOperate_dps(), conn, conn.getPointTables()); plcTask(plcInit.getPlcOperate_dps(), conn, conn.getPointTables());
} }
} }
@ -124,7 +124,7 @@ public class PlcEventTask {
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="DB2.0"; String heartbeat="DB320.0.1";
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));
@ -300,11 +300,9 @@ public class PlcEventTask {
public void dpsRealTimeTask(List<WcsPlcProperty> propertyList,Map<String, Object> pointMap, PLCReadAndWrite plcReadAndWrite,PlcOperate plcOperate ) { public void dpsRealTimeTask(List<WcsPlcProperty> propertyList,Map<String, Object> pointMap, PLCReadAndWrite plcReadAndWrite,PlcOperate plcOperate ) {
try { try {
// log.info("监听输送线的值:"+pointMap);
String requestAddress = "", writeTaskId = "", valueType = ""; String requestAddress = "", writeTaskId = "", valueType = "";
String heartbeat = "", hbValueType = "", autoAddress = ""; String autoAddress = "";
Long taskId = 0L; Long taskId = 0L;
//货物高度wms的值 //货物高度wms的值
String cargoHeight =""; String cargoHeight ="";
@ -340,10 +338,6 @@ public class PlcEventTask {
} else if (wcsPlcProperty.getPointType().equals("6")) { } else if (wcsPlcProperty.getPointType().equals("6")) {
writeTaskId = wcsPlcProperty.getAddress(); writeTaskId = wcsPlcProperty.getAddress();
valueType = wcsPlcProperty.getValueType(); valueType = wcsPlcProperty.getValueType();
} else if (wcsPlcProperty.getPointType().equals("9")) {
//心跳
heartbeat = wcsPlcProperty.getAddress();
hbValueType = wcsPlcProperty.getValueType();
} else if (wcsPlcProperty.getPointType().equals("10")) { } else if (wcsPlcProperty.getPointType().equals("10")) {
autoAddress = wcsPlcProperty.getAddress(); autoAddress = wcsPlcProperty.getAddress();
} else if (wcsPlcProperty.getPointType().equals("7")) { } else if (wcsPlcProperty.getPointType().equals("7")) {
@ -373,34 +367,7 @@ public class PlcEventTask {
wcsErrExitVT =wcsPlcProperty.getValueType(); wcsErrExitVT =wcsPlcProperty.getValueType();
} }
} }
//
// //读取心跳,并判断是写入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(hbValueType, heartbeatV);
// Map<String, Object> allHbMap = new HashMap<>(1);
// allHbMap.put(heartbeat, writeHbMap);
// Boolean BooleanHeartbeat = plcReadAndWrite.execWrite(plcOperate, JsonUtil.toJSONString(allHbMap));
// if(!BooleanHeartbeat){
// log.info("第一次写入心跳成功失败*****************");
// new Thread(() -> {
// try {
// Thread.sleep(1000);
// log.error("第一次写入心跳失败!进行第二次写入");
// Boolean bool = plcReadAndWrite.execWrite(plcOperate, JsonUtil.toJSONString(allHbMap));
// if(bool){
// log.error("第二次写入心跳成功!");
// }
// } catch (InterruptedException e) {
// log.error("第二次写入心跳失败!");
// }
// }).start();
// }
// 电柜状态是否是自动,如果是自动则继续流程 // 电柜状态是否是自动,如果是自动则继续流程
if (pointMap.containsKey(autoAddress) && Boolean.valueOf(pointMap.get(autoAddress).toString())) { if (pointMap.containsKey(autoAddress) && Boolean.valueOf(pointMap.get(autoAddress).toString())) {
//是否请求分配 //是否请求分配

@ -67,17 +67,6 @@ public class StkCallUtil {
* @return * @return
*/ */
public Result<Boolean> outTask(STKMoveBo stkMoveBo) throws InterruptedException { public Result<Boolean> outTask(STKMoveBo stkMoveBo) throws InterruptedException {
/*//判断是否有出库任务没有执行,如果有先不下发
Date nowDate = DateUtils.getNowDate();
LambdaQueryWrapper<SysThirdExceptionRequest> wrapper = new LambdaQueryWrapper<SysThirdExceptionRequest>()
.eq(SysThirdExceptionRequest::getStatus, ThirdApiStatusEnum.fail.getValue())
.ne(SysThirdExceptionRequest::getCode,stkMoveBo.getTaskId())
.and(wq->wq.lt(SysThirdExceptionRequest::getPlanTime, nowDate)
.or().isNull(SysThirdExceptionRequest::getPlanTime))
.orderByAsc(SysThirdExceptionRequest::getCreateTime)
.last("limit 1 ");
SysThirdExceptionRequest one = sysThirdExceptionRequestService.getOne(wrapper);*/
//下发任务时,先查询是否有正在执行的入库任务,如果有,则不下发出库任务 //下发任务时,先查询是否有正在执行的入库任务,如果有,则不下发出库任务
Object taskInId = redisTemplate.opsForValue().get(RedisConstant.redisTaskIn); Object taskInId = redisTemplate.opsForValue().get(RedisConstant.redisTaskIn);
if (taskInId !=null ){ if (taskInId !=null ){
@ -127,24 +116,49 @@ public class StkCallUtil {
Map<String, Object> dpsPointMap = plcReadAndWrite.readPlcData(dpsOperate, dpsPointTables); Map<String, Object> dpsPointMap = plcReadAndWrite.readPlcData(dpsOperate, dpsPointTables);
List<WcsPlcProperty> dpsPropertyList = iWcsPlcPropertyService.getWcsPlcPropertyByPlcId(dpsPlcId); List<WcsPlcProperty> dpsPropertyList = iWcsPlcPropertyService.getWcsPlcPropertyByPlcId(dpsPlcId);
String dpsidle=""; String oneDpsidle="";
String dpsidleV=""; String twoDpsidle="";
String oneDpsidleV="";
String twoDpsidleV="";
for (WcsPlcProperty dpsProperty : dpsPropertyList) { for (WcsPlcProperty dpsProperty : dpsPropertyList) {
//是否允许出库 //1楼是否允许出库
if (dpsProperty.getPointType().equals("100")) { if (dpsProperty.getPointType().equals("oneOut")) {
dpsidle = dpsProperty.getAddress(); oneDpsidle = dpsProperty.getAddress();
}
//2楼是否允许出库
if (dpsProperty.getPointType().equals("twoOut")) {
twoDpsidle = dpsProperty.getAddress();
} }
} }
if (dpsPointMap.containsKey(dpsidle)){ if (dpsPointMap.containsKey(oneDpsidle)){
dpsidleV = dpsPointMap.get(dpsidle).toString(); oneDpsidleV = dpsPointMap.get(oneDpsidle).toString();
}
if (dpsPointMap.containsKey(twoDpsidle)){
twoDpsidleV = dpsPointMap.get(twoDpsidle).toString();
} }
log.info("是否允许出库状态点位:"+dpsidle); log.info("1楼是否允许出库::"+oneDpsidle+" 出库的值:"+oneDpsidleV);
log.info("是否允许出库状态值:"+dpsidleV); log.info("2楼是否允许出库::"+twoDpsidle+" 出库的值:"+twoDpsidleV);
Integer layer = one.getLayer();
if (layer==1){
//false不允许出库 //false不允许出库
if (!Boolean.valueOf(dpsidleV)){ if (!Boolean.valueOf(oneDpsidleV)){
return Result.err().msg("输送线繁忙,不允许出库"); String msg ="出库楼层是1楼,输送线繁忙,不允许出库";
log.info(msg);
return Result.err().msg(msg);
}
}else if(layer == 2){
if (!Boolean.valueOf(twoDpsidleV)){
String msg ="出库楼层是2楼,输送线繁忙,不允许出库";
log.info(msg);
return Result.err().msg(msg);
}
}else {
log.info("未匹配到楼层");
return Result.err().msg("未匹配到楼层,不允许出库");
} }
String plcTaskId = "",taskIdvalueType = "",plcToRow = "",toRowValueType = "",plcToColumn = "",toColumnValueType = "",plcToLayer = "",toLayerValueType = ""; String plcTaskId = "",taskIdvalueType = "",plcToRow = "",toRowValueType = "",plcToColumn = "",toColumnValueType = "",plcToLayer = "",toLayerValueType = "";
@ -215,51 +229,48 @@ public class StkCallUtil {
Thread.sleep(2000); Thread.sleep(2000);
Boolean stkAutoManualV= false; Integer stkRunV = 0;
if (stkPointMap.containsKey(stkRun)) {
stkRunV = Integer.valueOf(stkPointMap.get(stkRun).toString());
}
log.info("堆垛机运行状态:"+stkRunV);
if (stkRunV!=1){
return Result.err().msg("堆垛机尚未运行");
}
Integer stkAutoManualV=0;
if (stkPointMap.containsKey(stkAutoManual)) { if (stkPointMap.containsKey(stkAutoManual)) {
stkAutoManualV = Boolean.valueOf(stkPointMap.get(stkAutoManual).toString()); stkAutoManualV = Integer.valueOf(stkPointMap.get(stkAutoManual).toString());
} }
log.info("堆垛机自动状态:"+stkAutoManualV); log.info("堆垛机自动状态:"+stkAutoManualV);
if(stkAutoManualV ==0 ){
return Result.err().msg("堆垛机手动状态");
}
Boolean stkGroundV= false; Integer stkGroundV= 0;
if (stkPointMap.containsKey(stkGround)) { if (stkPointMap.containsKey(stkGround)) {
stkGroundV = Boolean.valueOf(stkPointMap.get(stkGround).toString()); stkGroundV = Integer.valueOf(stkPointMap.get(stkGround).toString());
} }
log.info("地面柜自动状态:"+stkGroundV); log.info("地面柜自动状态:"+stkGroundV);
if(stkGroundV==0){
Boolean stkidleV = false;
if (stkPointMap.containsKey(stkidle)) {
stkidleV = Boolean.valueOf(stkPointMap.get(stkidle).toString());
}
log.info("堆垛机是状态:"+stkidleV.toString());
Boolean stkRunV = false;
if (stkPointMap.containsKey(stkRun)) {
stkRunV = Boolean.valueOf(stkPointMap.get(stkRun).toString());
}
log.info("堆垛机运行状态:"+stkRunV);
/* //等于0
if (!stkRunV){
return Result.err().msg("堆垛机正在运行中");
}*/
if(!stkGroundV){
return Result.err().msg("堆垛机地面柜手动状态"); return Result.err().msg("堆垛机地面柜手动状态");
} }
if(!stkAutoManualV){ Integer stkidleV = 0;
return Result.err().msg("堆垛机手动状态"); if (stkPointMap.containsKey(stkidle)) {
stkidleV = Integer.valueOf(stkPointMap.get(stkidle).toString());
} }
log.info("堆垛机是状态:"+stkidleV);
//等于0繁忙 false代表繁忙 //1空闲 0繁忙
if(!stkidleV){ if(stkidleV==0){
return Result.err().msg("堆垛机繁忙"); return Result.err().msg("堆垛机繁忙");
} }
if(!Boolean.valueOf(dpsidleV) && !stkidleV){ if((!Boolean.valueOf(oneDpsidleV) || !Boolean.valueOf(twoDpsidleV)) && stkidleV == 0){
return Result.err().msg("出库状态与堆垛机的状态都不可出库"); return Result.err().msg("出库状态与堆垛机的状态都不可出库");
}else{ }else{
log.info("出库状态与堆垛机的状态可出库:"+Boolean.valueOf(dpsidleV)+"--"+stkidleV); log.info("出库状态与堆垛机的状态可出库one: "+Boolean.valueOf(oneDpsidleV)+" two:"+twoDpsidleV+" --"+stkidleV);
} }
//给堆垛机写命令 //给堆垛机写命令
Map<String, Object> allMap = new HashMap<>(1); Map<String, Object> allMap = new HashMap<>(1);
@ -302,9 +313,9 @@ public class StkCallUtil {
redisTemplate.opsForValue().set(RedisConstant.redisTaskOut,stkMoveBo.getTaskId()); redisTemplate.opsForValue().set(RedisConstant.redisTaskOut,stkMoveBo.getTaskId());
return Result.ok(); return Result.ok();
} else { } else {
log.info("堆垛机下发命令失败:"+one.getTaskId());
return Result.err(); return Result.err();
} }
// return plcReadAndWrite.execWrite(stkOperate, JsonUtil.toJSONString(allMap)) ? Result.ok() : Result.err();
} }
/** /**

@ -117,5 +117,9 @@ public class SysThirdExceptionRequest implements Serializable {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+7") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+7")
private Date planTime; private Date planTime;
/**
* 出入库楼层
*/
private Integer layer;
} }

@ -59,24 +59,6 @@ public class SysThirdExceptionRequestServiceImpl extends ServiceImpl<SysThirdExc
@Override @Override
public Result executeException(String taskCode) throws InterruptedException { public Result executeException(String taskCode) throws InterruptedException {
//获取redis中的出库下发时间,判断请求入库的时间与其之间的时间间隔,如果小于10秒,则不给输送线写命令
long seconds = 15L;
Object redisTaskTime = redisTemplate.opsForValue().get(RedisConstant.redisTaskTime);
if (redisTaskTime != null) {
Date dateTask = (Date) redisTaskTime;
Date nowDate = DateUtils.getNowDate();
long diffDate = nowDate.getTime() - dateTask.getTime();
seconds = diffDate / 1000;
log.info("上一个任务下发时间:" + redisTaskTime + " 现在时间:"+nowDate+" 相差的秒数:"+seconds);
}
if (seconds < 10) {
log.error("2个任务下发间隔时间小于10秒,下发频次太快");
// return Result.err().msg("2个任务下发间隔时间小于15秒,下发频次太快");
} else {
log.error("轮询数据,修改时间为空");
}
SysThirdExceptionRequest request = getOne(new LambdaQueryWrapper<SysThirdExceptionRequest>() SysThirdExceptionRequest request = getOne(new LambdaQueryWrapper<SysThirdExceptionRequest>()
.eq(SysThirdExceptionRequest::getCode, taskCode) .eq(SysThirdExceptionRequest::getCode, taskCode)
.eq(SysThirdExceptionRequest::getStatus, ThirdApiStatusEnum.fail.getValue()) .eq(SysThirdExceptionRequest::getStatus, ThirdApiStatusEnum.fail.getValue())
@ -125,7 +107,6 @@ public class SysThirdExceptionRequestServiceImpl extends ServiceImpl<SysThirdExc
STKMoveBo moveBo = JSONObject.parseObject(request.getRequestBody(), STKMoveBo.class); STKMoveBo moveBo = JSONObject.parseObject(request.getRequestBody(), STKMoveBo.class);
result = stkCallUtil.locationAdjustment(moveBo); result = stkCallUtil.locationAdjustment(moveBo);
break; break;
default: default:
log.info("type = {}", type); log.info("type = {}", type);
return Result.err().msg("类型异常"); return Result.err().msg("类型异常");

Loading…
Cancel
Save