From 0a1e1261596e18e4bc59d1dafbffb4a3a41bef1a Mon Sep 17 00:00:00 2001 From: judy <278197488@qq.com> Date: Fri, 12 Jul 2024 10:27:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E5=88=86?= =?UTF-8?q?=E5=BC=80=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application-test.yml | 4 +- .../java/com/shkj/wms/plc/PlcEventTask.java | 140 ++++++++----- .../com/shkj/wms/plc/PlcEventTmpTask.java | 2 +- .../shkj/wms/scheduled/ScheduledTasks.java | 191 +++++++++--------- .../mapper/wms/BusinDataTaskMapper.xml | 2 +- 5 files changed, 192 insertions(+), 147 deletions(-) diff --git a/shkj-admin/src/main/resources/application-test.yml b/shkj-admin/src/main/resources/application-test.yml index 92f1997..784f71c 100644 --- a/shkj-admin/src/main/resources/application-test.yml +++ b/shkj-admin/src/main/resources/application-test.yml @@ -15,7 +15,7 @@ spring: url: jdbc:mysql://127.0.0.1:3306/po1_wms_wcs?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 # url: jdbc:mysql://127.0.0.1:3306/po1testsh?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 username: root - password: root + password: 123456 # 从库数据源 slave: # 从数据源开关/默认关闭 @@ -69,7 +69,7 @@ spring: # 端口,默认为6379 port: 6379 # 数据库索引 - database: 1 + database: 0 # 密码 password: # password: 123456 diff --git a/shkj-wms/src/main/java/com/shkj/wms/plc/PlcEventTask.java b/shkj-wms/src/main/java/com/shkj/wms/plc/PlcEventTask.java index 8a1edc8..58c5546 100644 --- a/shkj-wms/src/main/java/com/shkj/wms/plc/PlcEventTask.java +++ b/shkj-wms/src/main/java/com/shkj/wms/plc/PlcEventTask.java @@ -143,76 +143,114 @@ public class PlcEventTask { if (plcList.size() == 0) { return; } - for (WcsPlcConnectVo conn : plcList) { - if(conn.getPlcIp().contains(".41")){ - PlcOperate plcOperate_41 = plcInit.getPlcOperate_41(); - if (plcOperate_41 ==null){ - plcInit.connect(conn.getPlcIp()); + if ("1".equals(conn.getDevType())){ + if(conn.getPlcIp().contains(".60")){ + PlcOperate plcOperate_60 = plcInit.getPlcOperate_60(); + if (plcOperate_60 ==null){ + plcInit.connect(conn.getPlcIp()); + } + plcTask(plcOperate_60, conn, conn.getPointTables()); + doDevStatus(plcOperate_60,"1"); } - plcTask(plcInit.getPlcOperate_41(), conn, conn.getPointTables()); - } - if(conn.getPlcIp().contains(".50")){ - PlcOperate plcOperate_50 = plcInit.getPlcOperate_50(); - if (plcOperate_50 ==null){ - plcInit.connect(conn.getPlcIp()); + if(conn.getPlcIp().contains(".70")){ + PlcOperate plcOperate_70 = plcInit.getPlcOperate_70(); + if (plcOperate_70 ==null){ + plcInit.connect(conn.getPlcIp()); + } + plcTask(plcOperate_70, conn, conn.getPointTables()); + doDevStatus(plcOperate_70,"2"); } - plcTask(plcOperate_50, conn, conn.getPointTables()); - } - if(conn.getPlcIp().contains(".60")){ - PlcOperate plcOperate_60 = plcInit.getPlcOperate_60(); - if (plcOperate_60 ==null){ - plcInit.connect(conn.getPlcIp()); + if(conn.getPlcIp().contains(".80")){ + PlcOperate plcOperate_80 = plcInit.getPlcOperate_80(); + if (plcOperate_80 ==null){ + plcInit.connect(conn.getPlcIp()); + } + plcTask(plcOperate_80, conn, conn.getPointTables()); + doDevStatus(plcOperate_80,"3"); } - plcTask(plcOperate_60, conn, conn.getPointTables()); - doDevStatus(plcOperate_60,"1"); - } - if(conn.getPlcIp().contains(".70")){ - PlcOperate plcOperate_70 = plcInit.getPlcOperate_70(); - if (plcOperate_70 ==null){ - plcInit.connect(conn.getPlcIp()); + if(conn.getPlcIp().contains(".90")){ + PlcOperate plcOperate_90 = plcInit.getPlcOperate_90(); + if (plcOperate_90 ==null){ + plcInit.connect(conn.getPlcIp()); + } + plcTask(plcOperate_90, conn, conn.getPointTables()); + doDevStatus(plcOperate_90,"4"); } - plcTask(plcOperate_70, conn, conn.getPointTables()); - doDevStatus(plcOperate_70,"2"); - } - if(conn.getPlcIp().contains(".80")){ - PlcOperate plcOperate_80 = plcInit.getPlcOperate_80(); - if (plcOperate_80 ==null){ - plcInit.connect(conn.getPlcIp()); + if(conn.getPlcIp().contains(".100")){ + PlcOperate plcOperate_100 = plcInit.getPlcOperate_100(); + if (plcOperate_100 ==null){ + plcInit.connect(conn.getPlcIp()); + } + plcTask(plcOperate_100, conn, conn.getPointTables()); + doDevStatus(plcOperate_100,"5"); } - plcTask(plcOperate_80, conn, conn.getPointTables()); - doDevStatus(plcOperate_80,"3"); - } - if(conn.getPlcIp().contains(".90")){ - PlcOperate plcOperate_90 = plcInit.getPlcOperate_90(); - if (plcOperate_90 ==null){ - plcInit.connect(conn.getPlcIp()); + if(conn.getPlcIp().contains(".110")){ + PlcOperate plcOperate_110 = plcInit.getPlcOperate_110(); + if (plcOperate_110 ==null){ + plcInit.connect(conn.getPlcIp()); + } + plcTask(plcOperate_110, conn, conn.getPointTables()); + doDevStatus(plcOperate_110,"6"); } - plcTask(plcOperate_90, conn, conn.getPointTables()); - doDevStatus(plcOperate_90,"4"); } +// if(conn.getPlcIp().contains(".41")){ +// PlcOperate plcOperate_41 = plcInit.getPlcOperate_41(); +// if (plcOperate_41 ==null){ +// plcInit.connect(conn.getPlcIp()); +// } +// plcTask(plcInit.getPlcOperate_41(), conn, conn.getPointTables()); +// } +// +// if(conn.getPlcIp().contains(".50")){ +// PlcOperate plcOperate_50 = plcInit.getPlcOperate_50(); +// if (plcOperate_50 ==null){ +// plcInit.connect(conn.getPlcIp()); +// } +// plcTask(plcOperate_50, conn, conn.getPointTables()); +// } - if(conn.getPlcIp().contains(".100")){ - PlcOperate plcOperate_100 = plcInit.getPlcOperate_100(); - if (plcOperate_100 ==null){ + + } + } + + // @Scheduled(fixedRate = 200) + public void init1() { + //查询需要连接的PLC,初始化连接对象 + List plcList = iWcsPlcConnectService.selectWcsPlcConnectList(new WcsPlcConnect().setIsActive("1")); + if (plcList.size() == 0) { + return; + } + for (WcsPlcConnectVo conn : plcList) { + if ("2".equals(conn.getDevType()) && conn.getPlcIp().contains(".41")){ + PlcOperate plcOperate_41 = plcInit.getPlcOperate_41(); + if (plcOperate_41 ==null){ plcInit.connect(conn.getPlcIp()); } - plcTask(plcOperate_100, conn, conn.getPointTables()); - doDevStatus(plcOperate_100,"5"); + plcTask(plcInit.getPlcOperate_41(), conn, conn.getPointTables()); } + } + } - if(conn.getPlcIp().contains(".110")){ - PlcOperate plcOperate_110 = plcInit.getPlcOperate_110(); - if (plcOperate_110 ==null){ + // @Scheduled(fixedRate = 200) + public void init2() { + //查询需要连接的PLC,初始化连接对象 + List plcList = iWcsPlcConnectService.selectWcsPlcConnectList(new WcsPlcConnect().setIsActive("1")); + if (plcList.size() == 0) { + return; + } + for (WcsPlcConnectVo conn : plcList) { + if ("3".equals(conn.getDevType()) && conn.getPlcIp().contains(".50")){ + PlcOperate plcOperate_50 = plcInit.getPlcOperate_50(); + if (plcOperate_50 ==null){ plcInit.connect(conn.getPlcIp()); } - plcTask(plcOperate_110, conn, conn.getPointTables()); - doDevStatus(plcOperate_110,"6"); + plcTask(plcOperate_50, conn, conn.getPointTables()); } } } @@ -870,7 +908,7 @@ public class PlcEventTask { //从redis中验证是否已经下发任务 BusinDataTask redisTask = (BusinDataTask)redisTemplate.opsForValue().get(RedisConstant.redisReqWare + taskId); if(redisTask != null){ - return; + return; } //获取任务ID diff --git a/shkj-wms/src/main/java/com/shkj/wms/plc/PlcEventTmpTask.java b/shkj-wms/src/main/java/com/shkj/wms/plc/PlcEventTmpTask.java index e862e9c..e7eab3d 100644 --- a/shkj-wms/src/main/java/com/shkj/wms/plc/PlcEventTmpTask.java +++ b/shkj-wms/src/main/java/com/shkj/wms/plc/PlcEventTmpTask.java @@ -427,7 +427,7 @@ class WeightRandomStrategy { } } - public java.lang.String randome(){ + public String randome(){ Map.putAll(weightMap); String k = random(); return k; diff --git a/shkj-wms/src/main/java/com/shkj/wms/scheduled/ScheduledTasks.java b/shkj-wms/src/main/java/com/shkj/wms/scheduled/ScheduledTasks.java index 1614d9f..7049f48 100644 --- a/shkj-wms/src/main/java/com/shkj/wms/scheduled/ScheduledTasks.java +++ b/shkj-wms/src/main/java/com/shkj/wms/scheduled/ScheduledTasks.java @@ -228,8 +228,14 @@ public class ScheduledTasks { taskQueryBo.setTaskType("21"); List businDataTaskVo21 = iBusinDataTaskService.selectBusinDataTask1(taskQueryBo); businDataTaskVos.addAll(businDataTaskVo21); + for (BusinDataTaskVo businDataTaskVo : businDataTaskVos){ + doTask(businDataTaskVo); + } + } + - for (BusinDataTaskVo businDataTaskVo : businDataTaskVos) { + @Transactional(rollbackFor = Exception.class) + public void doTask(BusinDataTaskVo businDataTaskVo) { String taskType = businDataTaskVo.getTaskType(); Long taskId = businDataTaskVo.getId(); Long containerId = businDataTaskVo.getContainerId(); @@ -240,9 +246,9 @@ public class ScheduledTasks { if (taskType.equals("0") || taskType.equals("7")) { //获取要出入库的条码信息 List businDataTaskGoodsVos = iBusinDataTaskGoodsService.selectBusinTaskGoodsByTaskCode(businDataTaskVo.getId()); - if(ObjectUtils.isEmpty(businDataTaskGoodsVos)){ + /* if(ObjectUtils.isEmpty(businDataTaskGoodsVos)){ continue; - } + }*/ BusinDataTaskGoodsVo goodsVo = businDataTaskGoodsVos.get(0); String vehicheModel = goodsVo.getVehicheModel(); String color = goodsVo.getColor(); @@ -346,7 +352,7 @@ public class ScheduledTasks { //根据车型分配库位 先判断该任务是否已经分配了货位 Result locationVoResult = null; if(ObjectUtils.isEmpty(businDataTaskVo.getToRow())){ - // locationVoResult = iBaseLocationService.assignEmptyLocation(vehicheModel, color,DateUtils.getDate(),businDataTaskGoodsVos); + // locationVoResult = iBaseLocationService.assignEmptyLocation(vehicheModel, color,DateUtils.getDate(),businDataTaskGoodsVos); // TODO: 2024/6/28 zjx locationVoResult = iBaseLocationService.assignEmptyLocationByStock( goodsNo, vehicheModel,DateUtils.getDate(),businDataTaskGoodsVos); @@ -493,7 +499,7 @@ public class ScheduledTasks { businDataTaskVo.setTaskPath(toLocation); businDataTaskVo.setTaskStatus(TaskStatusEnum.wait_callback.getValue()); - //生成入库单 + //生成入库单 if (randome.equals("P01")){ Result stringResult = iPutInOutStorageService.exeTaskPutinStorage(exeBo); @@ -603,7 +609,7 @@ public class ScheduledTasks { //// exeBo.setTransQual("1"); // } // }else { - basePointDeviceVo = basePointDeviceVos.get(0); + basePointDeviceVo = basePointDeviceVos.get(0); // } //plcId =basePointDeviceVo.getPlcId(); @@ -1038,40 +1044,40 @@ public class ScheduledTasks { //获取要出库的物料信息 List businDataTaskGoodsVos = iBusinDataTaskGoodsService.getTaskGoodsByTaskCodeForOut(businDataTaskVo.getId()); - //拿到按比例分配的库区 + //拿到按比例分配的库区 // randome = allocationTasksUtils.randomeout(); - //测试时使用 - randome="P01"; + //测试时使用 + randome="P01"; //TODO 测试注释 要到开 // if (randome.equals("P02")) { - if (businDataTaskVo.getDistinction().equals("2")) { - int number = businDataTaskGoodsVos.size(); - List goodsno = businDataTaskGoodsVos.stream().map(e -> e.getGoodsNo()).collect(Collectors.toList()); - //根据GoodsNo查看立库是否有库存 - List list = iSysStockDetailService.list(new LambdaQueryWrapper() - .in(SysStockDetail::getGoodsNo, goodsno) - .eq(SysStockDetail::getQty, "1") - .isNull(SysStockDetail::getOutQty) - .isNull(SysStockDetail::getLocationId)); - if (ObjectUtils.isEmpty(list)) { - businDataTaskVo.setDistinction("1"); - } else { - String frompoint=null; - String tepairGroup = sysParameterService.selectConfigByKey(ParameterConstants.ParameterSystem.P_out01); - pointQueryBo.setGroupNo(tepairGroup); - BasePointDeviceVo pointDeviceout = basePointDeviceMapper.selectBasePointByGroupno(pointQueryBo); - frompoint = pointDeviceout.getPointNo(); - //查询平库出库任务使用状态 - businDataTaskVo.setTaskStatus(TaskStatusEnum.four_out.getValue()); - businDataTaskVo.setTaskType(TaskTypeEnum.thirteen_out.getValue()); - businDataTaskVo.setTaskPath(frompoint); - } - + if (businDataTaskVo.getDistinction().equals("2")) { + int number = businDataTaskGoodsVos.size(); + List goodsno = businDataTaskGoodsVos.stream().map(e -> e.getGoodsNo()).collect(Collectors.toList()); + //根据GoodsNo查看立库是否有库存 + List list = iSysStockDetailService.list(new LambdaQueryWrapper() + .in(SysStockDetail::getGoodsNo, goodsno) + .eq(SysStockDetail::getQty, "1") + .isNull(SysStockDetail::getOutQty) + .isNull(SysStockDetail::getLocationId)); + if (ObjectUtils.isEmpty(list)) { + businDataTaskVo.setDistinction("1"); + } else { + String frompoint=null; + String tepairGroup = sysParameterService.selectConfigByKey(ParameterConstants.ParameterSystem.P_out01); + pointQueryBo.setGroupNo(tepairGroup); + BasePointDeviceVo pointDeviceout = basePointDeviceMapper.selectBasePointByGroupno(pointQueryBo); + frompoint = pointDeviceout.getPointNo(); + //查询平库出库任务使用状态 + businDataTaskVo.setTaskStatus(TaskStatusEnum.four_out.getValue()); + businDataTaskVo.setTaskType(TaskTypeEnum.thirteen_out.getValue()); + businDataTaskVo.setTaskPath(frompoint); } + } + //TODO 测试注释 要到开 // if (!randome.equals("P02")) { - if (!businDataTaskVo.getDistinction().equals("2")) { + if (!businDataTaskVo.getDistinction().equals("2")) { // int number = businDataTaskGoodsVos.size(); // List goodsno = businDataTaskGoodsVos.stream().map(e -> e.getGoodsNo()).collect(Collectors.toList()); //根据GoodsNo查看立库是否有库存 @@ -1081,66 +1087,66 @@ public class ScheduledTasks { // .eq(SysStockDetail::getQty, "1") // .ne(SysStockDetail::getOutQty ,"1" ) // .isNotNull(SysStockDetail::getLocationId)); - //查询库存并返回库位信息 + //查询库存并返回库位信息 BusinTaskExeBo businTaskExeBo = iBusinDataTaskService.outboundInfo(businDataTaskGoodsVos, String.valueOf(businDataTaskVo.getId())); - BusinDataTask businDataTask = iBusinDataTaskService.getById(businDataTaskVo.getId()); - if (ObjectUtils.isNotEmpty(businDataTask) && ObjectUtils.isNotEmpty(businDataTask.getFromLayer())) { - if (ObjectUtils.isNotEmpty(businTaskExeBo)){ - ////生成出库单 - Result billResult = iPutInOutStorageService.exeTaskPutinStorage(businTaskExeBo); - businDataTask.setTransId(billResult.getData()); - } - //添加货位预占和库存预占 - //获取货位信息 - BaseLocation location = iBaseLocationService.getById(businDataTask.getLocationId()); - location.setLocationStatus("4"); - iBaseLocationService.updateById(location); - //根据货位拿到库存信息 - List sysStockDetailList = sysStockDetailMapper.getStockDetailByLocationId(String.valueOf(location.getId())); - sysStockDetailList.stream().forEach(e -> { - e.setOutQty(1); - }); - //给库存添加出货预占 - iSysStockDetailService.updateBatchById(sysStockDetailList); + BusinDataTask businDataTask = iBusinDataTaskService.getById(businDataTaskVo.getId()); + if (ObjectUtils.isNotEmpty(businDataTask) && ObjectUtils.isNotEmpty(businDataTask.getFromLayer())) { + if (ObjectUtils.isNotEmpty(businTaskExeBo)){ + ////生成出库单 + Result billResult = iPutInOutStorageService.exeTaskPutinStorage(businTaskExeBo); + businDataTask.setTransId(billResult.getData()); + } + //添加货位预占和库存预占 + //获取货位信息 + BaseLocation location = iBaseLocationService.getById(businDataTask.getLocationId()); + location.setLocationStatus("4"); + iBaseLocationService.updateById(location); + //根据货位拿到库存信息 + List sysStockDetailList = sysStockDetailMapper.getStockDetailByLocationId(String.valueOf(location.getId())); + sysStockDetailList.stream().forEach(e -> { + e.setOutQty(1); + }); + //给库存添加出货预占 + iSysStockDetailService.updateBatchById(sysStockDetailList); // Result taskResult =new Result<>(); - Result taskResult = outTask(businDataTask); - if (taskResult.getCode() == HttpStatus.SUCCESS.getCode()) { - businDataTask.setTaskStatus(TaskStatusEnum.wait_callback.getValue()); - if (ObjectUtils.isEmpty(redisTemplate.opsForValue().get("outbound:"+businDataTask.getId()))){ - redisTemplate.opsForValue().set("outbound:"+businDataTask.getId(), businDataTask.toString()); - } - - - //拿到库存里的治具编号(不分体的每个保险杠在一个货位一个任务,分体的只有一个任务一个货位所以只随机拿到一个库存信息的治具号就可以) - businDataTask.setContainerId(sysStockDetailList.get(0).getContainerCode()); - if(!"5".equals(businDataTask.getTaskType())){ - //根据过点时间更改out表里的状态信息 - List businDataTaskGoods = iBusinDataTaskGoodsService.list(new LambdaQueryWrapper() - .eq(BusinDataTaskGoods::getTaskCode, businDataTask.getId())); - BaseBarcodesOut baseBarcodesOutServiceOne = iBaseBarcodesOutService.getOne(new LambdaQueryWrapper() - .eq(BaseBarcodesOut::getTraverseDate, businDataTaskGoods.get(0).getTraverseDate())); - baseBarcodesOutServiceOne.setOutStatus("2"); - iBaseBarcodesOutService.updateById(baseBarcodesOutServiceOne); - } - - //添加巷道任务数和总任务数 - //tunnelTaskUtil.addOutboundTaskNum(businDataTask.getTunnel()); - } else { - if (ObjectUtils.isEmpty(redisTemplate.opsForValue().get("outbound:"+businDataTask.getId()))){ - businDataTask.setExceptionMsg("下发堆垛机失败"); - businDataTask.setTaskStatus(TaskStatusEnum.err.getValue()); - }else { - businDataTask.setExceptionMsg("已经下发堆垛机"); - businDataTask.setTaskStatus("-3"); - } - } - businDataTask.setDistinction(businDataTaskVo.getDistinction()); - iBusinDataTaskService.saveOrUpdate(businDataTask); - businDataTaskVo = BeanUtil.toBean(businDataTask, BusinDataTaskVo.class); - }else { - businDataTaskVo.setExceptionMsg("当前开放的货位已无当前库存"); - businDataTaskVo.setTaskStatus("-3"); - } + Result taskResult = outTask(businDataTask); + if (taskResult.getCode() == HttpStatus.SUCCESS.getCode()) { + businDataTask.setTaskStatus(TaskStatusEnum.wait_callback.getValue()); + if (ObjectUtils.isEmpty(redisTemplate.opsForValue().get("outbound:"+businDataTask.getId()))){ + redisTemplate.opsForValue().set("outbound:"+businDataTask.getId(), businDataTask.toString()); + } + + + //拿到库存里的治具编号(不分体的每个保险杠在一个货位一个任务,分体的只有一个任务一个货位所以只随机拿到一个库存信息的治具号就可以) + businDataTask.setContainerId(sysStockDetailList.get(0).getContainerCode()); + if(!"5".equals(businDataTask.getTaskType())){ + //根据过点时间更改out表里的状态信息 + List businDataTaskGoods = iBusinDataTaskGoodsService.list(new LambdaQueryWrapper() + .eq(BusinDataTaskGoods::getTaskCode, businDataTask.getId())); + BaseBarcodesOut baseBarcodesOutServiceOne = iBaseBarcodesOutService.getOne(new LambdaQueryWrapper() + .eq(BaseBarcodesOut::getTraverseDate, businDataTaskGoods.get(0).getTraverseDate())); + baseBarcodesOutServiceOne.setOutStatus("2"); + iBaseBarcodesOutService.updateById(baseBarcodesOutServiceOne); + } + + //添加巷道任务数和总任务数 + //tunnelTaskUtil.addOutboundTaskNum(businDataTask.getTunnel()); + } else { + if (ObjectUtils.isEmpty(redisTemplate.opsForValue().get("outbound:"+businDataTask.getId()))){ + businDataTask.setExceptionMsg("下发堆垛机失败"); + businDataTask.setTaskStatus(TaskStatusEnum.err.getValue()); + }else { + businDataTask.setExceptionMsg("已经下发堆垛机"); + businDataTask.setTaskStatus("-3"); + } + } + businDataTask.setDistinction(businDataTaskVo.getDistinction()); + iBusinDataTaskService.saveOrUpdate(businDataTask); + businDataTaskVo = BeanUtil.toBean(businDataTask, BusinDataTaskVo.class); + }else { + businDataTaskVo.setExceptionMsg("当前开放的货位已无当前库存"); + businDataTaskVo.setTaskStatus("-3"); + } // if (ObjectUtils.isNotEmpty(list)) { // @@ -1550,7 +1556,8 @@ public class ScheduledTasks { //统一提交任务数据 iBusinDataTaskService.saveOrUpdate(BeanUtil.toBean(businDataTaskVo, BusinDataTask.class)); } - } + + //查看堆垛机是否拥堵 public Result PLCout(BusinDataTask businDataTask){ diff --git a/shkj-wms/src/main/resources/mapper/wms/BusinDataTaskMapper.xml b/shkj-wms/src/main/resources/mapper/wms/BusinDataTaskMapper.xml index ab3b573..29e6703 100644 --- a/shkj-wms/src/main/resources/mapper/wms/BusinDataTaskMapper.xml +++ b/shkj-wms/src/main/resources/mapper/wms/BusinDataTaskMapper.xml @@ -231,7 +231,7 @@