1 2 楼出入库并发问题,1楼输送线有货,2楼可以正常出库

main
judy 11 months ago
parent 8828ff7318
commit bd98b21694
  1. 2
      shkj-admin/src/main/resources/application-pro.yml
  2. 3
      shkj-common/src/main/java/com/shkj/common/constant/RedisConstant.java
  3. 72
      shkj-wms/src/main/java/com/shkj/wcs/plc/PlcEventTask.java
  4. 38
      shkj-wms/src/main/java/com/shkj/wcs/third/stacker/StkCallUtil.java
  5. 1
      shkj-wms/src/main/java/com/shkj/wms/service/impl/BaseContainerServiceImpl.java
  6. 51
      shkj-wms/src/main/java/com/shkj/wms/service/impl/BusinOutInPlanServiceImpl.java
  7. 10
      shkj-wms/src/main/java/com/shkj/wms/service/impl/BusinStockInvServiceImpl.java
  8. 9
      shkj-wms/src/main/java/com/shkj/wms/service/impl/SysAppVersionServiceImpl.java
  9. 1
      shkj-wms/src/main/java/com/shkj/wms/service/impl/SysThirdExceptionRequestServiceImpl.java
  10. 2
      shkj-wms/src/main/resources/mapper/wms/BaseLocationMapper.xml

@ -64,7 +64,7 @@ spring:
# redis 配置
redis:
# 地址
host: 127.0.0.1
host: 192.168.155.145
# 端口,默认为6379
port: 6379
# 数据库索引

@ -30,7 +30,8 @@ public class RedisConstant {
//任务下发时间
public static String redisTaskTime ="redisTaskTime:";
public static String redisTaskOut ="redisTaskOut:";
public static String redisTaskOutOne ="redisTaskOutOne:";
public static String redisTaskOutTwo ="redisTaskOutTwo:";
public static String redisTaskIn ="redisTaskIn:";

@ -78,7 +78,7 @@ public class PlcEventTask {
@Autowired
PlcInit plcInit;
@Scheduled(fixedDelay = 4000)
@Scheduled(fixedDelay = 5000)
public void init() {
//查询需要连接的PLC,初始化连接对象
List<WcsPlcConnectVo> plcList =(List<WcsPlcConnectVo>) redisTemplate.opsForValue().get(RedisConstant.redisPlcListConnect);
@ -407,12 +407,18 @@ public class PlcEventTask {
Long taskIdOne = 0L;
//1楼是否请求分配
if (pointMap.containsKey(oneAllotAddress) && Boolean.valueOf(pointMap.get(oneAllotAddress).toString())) {
//请求入库分配时,判断是否有正在执行的出库任务,如果有则返回
Object taskOutId = redisTemplate.opsForValue().get(RedisConstant.redisTaskOut);
if (taskOutId != null) {
log.info("1楼入库分配请求时,有出库任务,不可分配,返回");
return;
}
// //请求入库分配时,判断是否有正在执行的出库任务,如果有则返回
// Object oneTaskOutId = redisTemplate.opsForValue().get(RedisConstant.redisTaskOutOne);
// if (oneTaskOutId != null) {
// log.info("1楼入库分配请求时,1楼有出库任务,不可分配:"+oneTaskOutId);
// return;
// }
//
// Object twoTaskOutId = redisTemplate.opsForValue().get(RedisConstant.redisTaskOutTwo);
// if (twoTaskOutId != null) {
// log.info("1楼入库分配请求时,2楼有出库任务,不可分配:"+twoTaskOutId);
// return;
// }
//读取托盘条码内容
String barcodeValueOne = pointMap.get(onePalletAddress).toString();
@ -467,9 +473,10 @@ public class PlcEventTask {
log.info("1楼按下入库按钮时,给输送线写命令数据:{}" + allMap);
Boolean taskBoolean = plcReadAndWrite.execWrite(plcOperate, JsonUtil.toJSONString(allMap));
log.info("1楼按下入库按钮时,写入的命令返回结果:"+taskBoolean.toString());
if (taskBoolean) {
//分配任务成功时,记录已下发入库任务,不可在下发出库或入库任务
redisTemplate.opsForValue().set(RedisConstant.redisTaskIn, taskIdOne);
log.info("分配成功后写入redis的数据:"+taskIdOne);
//更改入库计划为1
iBusinOutInPlanService.updPlanStatus(taskIdOne, PlanStatusEnum.DOING.getValue());
}
@ -481,11 +488,17 @@ public class PlcEventTask {
if (pointMap.containsKey(twoAllotAddress) && Boolean.valueOf(pointMap.get(twoAllotAddress).toString())) {
Long taskIdTwo = 0L;
//请求入库分配时,判断是否有正在执行的出库任务,如果有则返回
Object taskOutId = redisTemplate.opsForValue().get(RedisConstant.redisTaskOut);
if (taskOutId != null) {
log.info("2楼入库分配请求时,有出库任务,不可分配,返回");
return;
}
// Object oneTaskOutId = redisTemplate.opsForValue().get(RedisConstant.redisTaskOutOne);
// if (oneTaskOutId != null) {
// log.info("2F入库分配请求时,1F有出库任务,不可分配,返回");
// return;
// }
//
// Object twoTaskOutId = redisTemplate.opsForValue().get(RedisConstant.redisTaskOutTwo);
// if (twoTaskOutId != null) {
// log.info("2F入库分配请求时,2F有出库任务,不可分配,返回");
// return;
// }
//读取托盘条码内容
String barcodeValueTwo = pointMap.get(twoPalletAddress).toString();
log.info("1楼请求入库时,读取的条码内容:" + barcodeValueTwo);
@ -540,7 +553,7 @@ public class PlcEventTask {
Boolean taskBoolean = plcReadAndWrite.execWrite(plcOperate, JsonUtil.toJSONString(allMap));
if (taskBoolean) {
//分配任务成功时,记录已下发入库任务,不可在下发出库任务
redisTemplate.opsForValue().set(RedisConstant.redisTaskIn, taskIdTwo);
//redisTemplate.opsForValue().set(RedisConstant.redisTaskIn, taskIdTwo);
//更改入库计划为1
iBusinOutInPlanService.updPlanStatus(taskIdTwo, PlanStatusEnum.DOING.getValue());
}
@ -769,18 +782,22 @@ public class PlcEventTask {
if (plcReadAndWrite.execWrite(plcOperate, JsonUtil.toJSONString(allMap))) {
//堆垛机完成状态后,把redis中的ID删除,代表此任务已经完成
Object taskInId = redisTemplate.opsForValue().get(RedisConstant.redisTaskIn);
Object taskOutId = redisTemplate.opsForValue().get(RedisConstant.redisTaskOut);
if (taskInId != null && String.valueOf(taskInId).equals(taskId.toString())) {
log.info("入库完成时,删除redis中的入库任务状态记录:");
redisTemplate.delete(RedisConstant.redisTaskIn);
}
if (taskOutId != null && String.valueOf(taskOutId).equals(taskId.toString())) {
Object oneTaskOutId = redisTemplate.opsForValue().get(RedisConstant.redisTaskOutOne);
if (oneTaskOutId != null && String.valueOf(oneTaskOutId).equals(taskId.toString())) {
log.info("出库完成时,删除redis中的出库任务状态记录");
redisTemplate.delete(RedisConstant.redisTaskOut);
redisTemplate.delete(RedisConstant.redisTaskOutOne);
}
if (taskInId != null && String.valueOf(taskInId).equals(taskId.toString())) {
log.info("入库完成时,删除redis中的入库任务状态记录");
redisTemplate.delete(RedisConstant.redisTaskIn);
Object twoTaskOutId = redisTemplate.opsForValue().get(RedisConstant.redisTaskOutTwo);
if (twoTaskOutId != null && String.valueOf(twoTaskOutId).equals(taskId.toString())) {
log.info("出库完成时,删除redis中的出库任务状态记录");
redisTemplate.delete(RedisConstant.redisTaskOutTwo);
}
log.info("给堆垛机下发完成信号为0,成功:" + taskId);
//请求成功,记录已下发
redisTemplate.delete(RedisConstant.redisReqWare + taskId);
@ -811,9 +828,15 @@ public class PlcEventTask {
return false;
}
Object taskOutId = redisTemplate.opsForValue().get(RedisConstant.redisTaskOut);
if (taskOutId != null) {
log.info("有出库任务在执行,无法下发入库任务:" + taskOutId);
Object oneTaskOutId = redisTemplate.opsForValue().get(RedisConstant.redisTaskOutOne);
if (oneTaskOutId != null) {
log.info("1F有出库任务在执行,无法下发入库任务:" + oneTaskOutId);
return false;
}
Object twoTaskOutId = redisTemplate.opsForValue().get(RedisConstant.redisTaskOutTwo);
if (twoTaskOutId != null) {
log.info("2F有出库任务在执行,无法下发入库任务:" + twoTaskOutId);
return false;
}
@ -972,6 +995,7 @@ public class PlcEventTask {
log.info(taskId + "请求入库:任务下发之前" + JsonUtil.toJSONString(allMap));
if (plcReadAndWrite.execWrite(stkOperate, JsonUtil.toJSONString(allMap))) {
log.info(taskId + "请求入库,任务下发成功:");
redisTemplate.opsForValue().set(RedisConstant.redisTaskIn, taskId);
//请求成功,记录已下发
redisTemplate.opsForValue().set(RedisConstant.redisReqWare + taskId, taskId, 24, TimeUnit.HOURS);
//请求分配任务ID dps

@ -74,19 +74,26 @@ public class StkCallUtil {
return Result.err().msg("有入库任务在执行,无法下发出库任务");
}
Object taskOutId = redisTemplate.opsForValue().get(RedisConstant.redisTaskOut);
if (taskOutId !=null ){
log.info("有出库任务在执行,无法下发出库任务:"+taskOutId);
return Result.err().msg("有出库任务在执行,无法下发出库任");
Object oneTaskOutId = redisTemplate.opsForValue().get(RedisConstant.redisTaskOutOne);
if (oneTaskOutId !=null ){
log.info("1F有出库任务在执行,无法下发出库任务:"+oneTaskOutId);
return Result.err().msg("1F有出库任务在执行,无法下发出库任");
}
Object twoTaskOutId = redisTemplate.opsForValue().get(RedisConstant.redisTaskOutTwo);
if (twoTaskOutId !=null ){
log.info("2F有出库任务在执行,无法下发出库任务:"+twoTaskOutId);
return Result.err().msg("2F有出库任务在执行,无法下发出库任务");
}
Long taskId = stkMoveBo.getTaskId();
SysThirdExceptionRequest one = sysThirdExceptionRequestService.getOneByOrderNo(taskId.toString());
if (one != null){
if (!one.getCode().equals(taskId.toString())){
log.info("有更早未执行的任务,排队执行:"+JsonUtil.toJSONString(one));
return Result.err().msg("有更早未执行的任务,排队执行");
}
}
// if (one != null){
// if (!one.getCode().equals(taskId.toString())){
// log.info("有更早未执行的任务,排队执行:"+JsonUtil.toJSONString(one));
// return Result.err().msg("有更早未执行的任务,排队执行");
// }
// }
String fromLayer = stkMoveBo.getFromLayer();
String fromColumn = stkMoveBo.getFromColumn();
@ -296,11 +303,16 @@ public class StkCallUtil {
finishPointMap.put(finishPointVT, 0);
allMap.put(finishPoint, finishPointMap);
PLCReadAndWrite plcReadAndWrite = new PLCReadAndWrite();
if ( plcReadAndWrite.execWrite(stkOperate, JsonUtil.toJSONString(allMap)) ){
if ( plcReadAndWrite.execWrite(stkOperate, JsonUtil.toJSONString(allMap)) && layer ==1 ){
redisTemplate.opsForValue().set(RedisConstant.redisTaskTime, DateUtils.getNowDate());
redisTemplate.opsForValue().set(RedisConstant.redisTaskOutOne, taskId);
return Result.ok();
}else if ( plcReadAndWrite.execWrite(stkOperate, JsonUtil.toJSONString(allMap)) && layer ==2 ){
redisTemplate.opsForValue().set(RedisConstant.redisTaskTime, DateUtils.getNowDate());
redisTemplate.opsForValue().set(RedisConstant.redisTaskOut, taskId);
redisTemplate.opsForValue().set(RedisConstant.redisTaskOutTwo, taskId);
return Result.ok();
} else {
}
else {
log.info(one.getTaskId()+"堆垛机下发命令失败");
return Result.err();
}

@ -169,6 +169,7 @@ public class BaseContainerServiceImpl extends ServiceImpl<BaseContainerMapper, B
@Override
public Result<BaseContainerVo> checkContainerCodeNoInv(String containerCode) {
log.info("扫描的托盘编号:"+containerCode);
LambdaQueryWrapper<BaseContainer> lqw = Wrappers.lambdaQuery();
lqw.eq(BaseContainer::getContainerCode, containerCode);
lqw.eq(BaseContainer::getBranchId, SecurityUtils.getCurrentBranchId()).last("limit 1");

@ -604,11 +604,17 @@ public class BusinOutInPlanServiceImpl extends ServiceImpl<BusinOutInPlanMapper,
sysStockDetailService.removeByIds(detailList.stream().map(x -> x.getId()).collect(Collectors.toList()));
}
//堆垛机非自动完成状态后,把redis中的ID删除,代表此任务已经完成
Object taskOutId = redisTemplate.opsForValue().get(RedisConstant.redisTaskOut);
Long orderNo = updList.get(0).getOrderNo();
if (taskOutId !=null && String.valueOf(taskOutId).equals(orderNo.toString())){
Object oneTaskOutId = redisTemplate.opsForValue().get(RedisConstant.redisTaskOutOne);
if (oneTaskOutId !=null && String.valueOf(oneTaskOutId).equals(orderNo.toString())){
log.info("出库完成时判断redis中的数据是否还存在,存在则删除,删除redis中的出库任务状态记录:",orderNo);
redisTemplate.delete(RedisConstant.redisTaskOut);
redisTemplate.delete(RedisConstant.redisTaskOutOne);
}
Object twoTaskOutId = redisTemplate.opsForValue().get(RedisConstant.redisTaskOutTwo);
if (twoTaskOutId !=null && String.valueOf(twoTaskOutId).equals(orderNo.toString())){
log.info("出库完成时判断redis中的数据是否还存在,存在则删除,删除redis中的出库任务状态记录:",orderNo);
redisTemplate.delete(RedisConstant.redisTaskOutTwo);
}
//出库成功写入wcs异常点位为0
@ -1013,20 +1019,12 @@ public class BusinOutInPlanServiceImpl extends ServiceImpl<BusinOutInPlanMapper,
if (container == null) {
return Result.err().msg("托盘不存在");
}
// 如果没有指定计划类型 就默认是入库
if (StringUtils.isBlank(planType)) {
planType = PlanTypeEnum.IN.getValue();
}
//正在执行入库计划,如果有多个入库则取最新一次入库的;
LambdaQueryWrapper<BusinOutInPlan> eq = new LambdaQueryWrapper<BusinOutInPlan>()
.eq(BusinOutInPlan::getContainerCode, containerCode)
.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())
.orderByDesc(BusinOutInPlan::getCreateTime)
// .eq(BusinOutInPlan::getType, planType)
// .last("limit 1")
;
List<BusinOutInPlan> ones = this.list(eq);
@ -1043,7 +1041,7 @@ public class BusinOutInPlanServiceImpl extends ServiceImpl<BusinOutInPlanMapper,
}
PlanOrderLocationVo vo = new PlanOrderLocationVo();
if (one.getType().equals(PlanTypeEnum.INV_BACK.getValue())){
List<BusinStockInv> businStockInvs = iBusinStockInvService.queryStockInvList(one.getOrderNo().toString());
List<BusinStockInv> businStockInvs = iBusinStockInvService.queryStockInvList(one.getDirection().toString()); //存的盘点单号
long qtySum = businStockInvs.stream().mapToLong(x -> x.getQty().longValue()).sum();
long invQtySum = businStockInvs.stream().mapToLong(x -> x.getInvQty().longValue()).sum();
if (qtySum == invQtySum && qtySum !=0 && qtySum !=0){
@ -1122,25 +1120,16 @@ public class BusinOutInPlanServiceImpl extends ServiceImpl<BusinOutInPlanMapper,
// 根据当前的托盘查询库存数据
List<SysStockDetail> detailList = redisCache.getCacheList(RedisLockConstants.containerCode + "_" + container.getContainerCode());
// List<SysStockDetail> detailList = sysStockDetailService.getByContainerId(container.getId());
/*if (CollectionUtils.isEmpty(detailList)) {
log.info("不需要处理数据了 = {}", container);
isEmpty = true;
//return Result.err().data(StringUtils.EMPTY);
}*/
//去掉库存为0的
List<SysStockDetail> newDetailList=null;
if ( !CollectionUtils.isEmpty(detailList) ){
newDetailList = detailList.stream().filter(x -> x.getQty().add(x.getInQty()).add(x.getOutQty()).compareTo(BigDecimal.ZERO) > 0).collect(Collectors.toList());
}
if (CollectionUtils.isEmpty(newDetailList)) {
isEmpty = true;
}
log.info("是否是空托盘了 = {}", isEmpty);
List<BusinOutInPlan> inPlans = new ArrayList<>();
Long no = IntIdUtil.generateIntId();;
@ -1166,11 +1155,6 @@ public class BusinOutInPlanServiceImpl extends ServiceImpl<BusinOutInPlanMapper,
if (CollectionUtils.isEmpty(inPlans)) {
//新增空托盘信息
BusinOutInPlan plan = initReturnPlan(container.getId(), container.getContainerCode(), no);
//设置第一个模具即可 因为是空托盘了()TODO 需要测试
/* SysStockDetail stockDetail = detailList.get(0);
plan.setMoldBarcode("")
.setMoldId(stockDetail.getMoldId())
.setMoldNo(stockDetail.getMoldNo());*/
inPlans.add(plan);
}
@ -1178,10 +1162,6 @@ public class BusinOutInPlanServiceImpl extends ServiceImpl<BusinOutInPlanMapper,
if (isEmpty) {
location = sysStockDetailService.findLocationByContainer(container.getContainerCode(), SecurityUtils.erpBranchId);
} else {
//找货位
/*List<String> moldBarcodeList = newDetailList.stream().map(x -> x.getBarcode()).collect(Collectors.toList());
List<BaseMold> baseMoldBarcodeList = baseMoldService.queryByMoldBarcodeList(moldBarcodeList);*/
//baseMoldBarcodeList 一定都有库存的
location = sysStockDetailService.findLocationByContainer(container.getContainerCode(),SecurityUtils.erpBranchId);
}
if (location == null) {
@ -1193,17 +1173,6 @@ public class BusinOutInPlanServiceImpl extends ServiceImpl<BusinOutInPlanMapper,
inPlans.forEach(x -> x.setLocationId(finalLocation.getId()));
this.saveBatch(inPlans);
//老数据需要清空 新货位先预占然后在实际回库的时候进行更新
// sysStockDetailService.removeByIds(detailList.stream().map(x -> x.getId()).collect(Collectors.toList()));
// detailList.forEach(detail -> {
// detail.setQty(BigDecimal.ZERO)
// .setInQty(BigDecimal.ZERO)
// .setOutQty(BigDecimal.ZERO)
// .setContainerId(0L)
// .setContainerCode("-");
// });
// sysStockDetailService.updateBatchById(detailList);
//增加预库存
if (!isEmpty) {
sysStockDetailService.addStockByIn(inPlans, location, false);

@ -133,13 +133,6 @@ public class BusinStockInvServiceImpl extends ServiceImpl<BusinStockInvMapper, B
@Override
@Transactional(rollbackFor = Exception.class)
public Result<Boolean> insertByAddBo(BusinStockInvAddBo bo) {
Long branchId = SecurityUtils.getCurrentBranchId();
// Result<String> result = sysSeqManaService.generatorCode(NumberPreEnum.PD.getValue(), NumberPreEnum.PD.getType(), branchId);
// if (!Result.isOk(result)) {
// return Result.err().msg(result.getMsg());
// }
// String orderNo = result.getData();
Long orderNo = IntIdUtil.generateIntId();
List<BusinStockInv> addList = new ArrayList<>();
for (Long stockId : bo.getIds()) {
@ -320,8 +313,9 @@ public class BusinStockInvServiceImpl extends ServiceImpl<BusinStockInvMapper, B
//新增回库任务
BusinStockInv inv = entry.getValue().get(0);
BusinOutInPlan inPlan = new BusinOutInPlan();
inPlan.setOrderNo(Long.parseLong(inv.getInvOrderNo()));
inPlan.setOrderNo(IntIdUtil.generateIntId());
inPlan.setContainerId(inv.getContainerId());
inPlan.setDirection(inv.getInvOrderNo());
BaseContainer container = baseContainerService.getById(inv.getContainerId());
if (container == null) {
continue;

@ -81,12 +81,12 @@ public class SysAppVersionServiceImpl extends ServiceImpl<SysAppVersionMapper, S
@Override
public Result<SysAppVersionVo> checkAppNeedUpdate(String code) {
SysAppVersion one = getOne(new LambdaQueryWrapper<SysAppVersion>()
/* SysAppVersion one = getOne(new LambdaQueryWrapper<SysAppVersion>()
.eq(SysAppVersion::getBranchId, SecurityUtils.getCurrentBranchId())
.orderByDesc(SysAppVersion::getCreateTime)
.last("limit 1"));
if (one == null) {
// return Result.err().msg("没有版本");
return Result.err().msg("没有版本");
}
if (!one.getCode().equals(code) || StringUtils.isBlank(code)) {
@ -96,8 +96,9 @@ public class SysAppVersionServiceImpl extends ServiceImpl<SysAppVersionMapper, S
}
SysAppVersionVo map = BeanMapperUtils.map(one, SysAppVersionVo.class);
map.setIsUpdate(0);
return Result.ok().data(map);
map.setIsUpdate(0);*/
//return Result.ok().data(map);
return Result.ok().data("");
}

@ -198,7 +198,6 @@ public class SysThirdExceptionRequestServiceImpl extends ServiceImpl<SysThirdExc
LambdaQueryWrapper<SysThirdExceptionRequest> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(SysThirdExceptionRequest::getStatus, ThirdApiStatusEnum.fail.getValue());
wrapper.orderByAsc(SysThirdExceptionRequest::getCreateTime);
wrapper.last("limit 1");
List<SysThirdExceptionRequest> thirdExceptionRequestList = list(wrapper);
// log.info("定时任务当前执行数量 = {}", thirdExceptionRequestList.size());
for (SysThirdExceptionRequest request : thirdExceptionRequestList) {

@ -406,7 +406,7 @@
and (loc.location_code like concat('%', #{locationMsg}, '%'))
</if>
</where>
order by location_column desc
</select>
</mapper>

Loading…
Cancel
Save