From 91975c055de14ba4e0f77055d7437ebf6ef3d481 Mon Sep 17 00:00:00 2001 From: daiweihong <242520063@qq.com> Date: Thu, 5 Sep 2024 11:53:25 +0800 Subject: [PATCH] =?UTF-8?q?2024/9/5=E6=9C=8D=E5=8A=A1=E5=99=A8=E6=9C=80?= =?UTF-8?q?=E6=96=B0=E4=BB=A3=E7=A0=81=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/BusinStockInvController.java | 5 - .../shkj/wms/mapper/BaseLocationMapper.java | 3 + .../java/com/shkj/wms/plc/PlcEventTask.java | 29 +++-- .../main/java/com/shkj/wms/plc/PlcInit.java | 2 +- .../shkj/wms/scheduled/ScheduledTasks.java | 115 +++++++++++++++++- .../wms/service/IBusinDataTaskService.java | 5 + .../service/impl/BaseLocationServiceImpl.java | 14 +++ .../impl/BusinDataTaskServiceImpl.java | 62 +++++++++- .../service/impl/BusinPickupServiceImpl.java | 4 +- .../impl/BusinStockInvServiceImpl.java | 59 +++++++-- .../impl/IBusinEnptyContainerServiceImpl.java | 94 ++------------ .../mapper/wms/BaseLocationMapper.xml | 31 +++++ 12 files changed, 300 insertions(+), 123 deletions(-) diff --git a/shkj-wms/src/main/java/com/shkj/wms/controller/business/BusinStockInvController.java b/shkj-wms/src/main/java/com/shkj/wms/controller/business/BusinStockInvController.java index 1722727..dcf3e80 100644 --- a/shkj-wms/src/main/java/com/shkj/wms/controller/business/BusinStockInvController.java +++ b/shkj-wms/src/main/java/com/shkj/wms/controller/business/BusinStockInvController.java @@ -79,7 +79,6 @@ public class BusinStockInvController extends BaseController { */ @PostMapping("/setEmptyLocation") public Result setEmptyLocation(Long invId) { - startPage(); Result booleanResult = iBusinStockInvService.setEmptyLocation(invId); return booleanResult; } @@ -89,7 +88,6 @@ public class BusinStockInvController extends BaseController { */ @PostMapping("/setEmptyContainer") public Result setEmptyContainer(Long invId) { - startPage(); Result booleanResult = iBusinStockInvService.setEmptyContainer(invId); return booleanResult; } @@ -99,7 +97,6 @@ public class BusinStockInvController extends BaseController { */ @PostMapping("/flagAsDiff") public Result flagAsDiff(Long invId) { - startPage(); Result booleanResult = iBusinStockInvService.flagAsDiff(invId); return booleanResult; } @@ -109,7 +106,6 @@ public class BusinStockInvController extends BaseController { */ @PostMapping("/issueTask") public Result issueTask(Long invId) { - startPage(); Result booleanResult = iBusinStockInvService.issueTask(invId); return booleanResult; } @@ -119,7 +115,6 @@ public class BusinStockInvController extends BaseController { */ @PostMapping("/invFinish") public Result invFinish( Long invId) { - startPage(); Result booleanResult = iBusinStockInvService.invFinish(invId); return booleanResult; } diff --git a/shkj-wms/src/main/java/com/shkj/wms/mapper/BaseLocationMapper.java b/shkj-wms/src/main/java/com/shkj/wms/mapper/BaseLocationMapper.java index 7088803..18e46b5 100644 --- a/shkj-wms/src/main/java/com/shkj/wms/mapper/BaseLocationMapper.java +++ b/shkj-wms/src/main/java/com/shkj/wms/mapper/BaseLocationMapper.java @@ -97,6 +97,9 @@ public interface BaseLocationMapper extends BaseMapper { */ List gettunnel(List goodsNo); + List getTunnelByContainer(); + + List getEmptyContainerFromLocation(Long areaId); List queryBaseLocationListByGoods(BaseLocationQueryListBo bo); 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 ed87fd6..3ed910c 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 @@ -141,7 +141,7 @@ public class PlcEventTask { private ScheduledExecutorService executorService = Executors.newScheduledThreadPool(8); - // @Scheduled(fixedRate = 200) + @Scheduled(fixedRate = 200) public void init() { //查询需要连接的PLC,初始化连接对象 List plcList = iWcsPlcConnectService.selectWcsPlcConnectList(new WcsPlcConnect().setIsActive("1")); @@ -224,7 +224,7 @@ public class PlcEventTask { } } - // @Scheduled(fixedRate = 200) + @Scheduled(fixedRate = 200) public void init1() { //查询需要连接的PLC,初始化连接对象 List plcList = iWcsPlcConnectService.selectWcsPlcConnectList(new WcsPlcConnect().setIsActive("1")); @@ -242,7 +242,7 @@ public class PlcEventTask { } } - // @Scheduled(fixedRate = 200) + @Scheduled(fixedRate = 200) public void init2() { //查询需要连接的PLC,初始化连接对象 List plcList = iWcsPlcConnectService.selectWcsPlcConnectList(new WcsPlcConnect().setIsActive("1")); @@ -260,7 +260,7 @@ public class PlcEventTask { } } - // @Scheduled(fixedDelay = 6000) + @Scheduled(fixedDelay = 6000) public void writePlcheartbeat() { //根据连接的plcId获取属性 PlcOperate plcOperate = plcInit.getPlcOperate_41(); @@ -605,20 +605,25 @@ public class PlcEventTask { oneByTask.setIsState("1"); businDpsContainerRecordMapper.updateById(oneByTask); } + + //完成后更新库位状态为空闲 + BaseLocation location = iBaseLocationService.getById(businDataTaskFinish.getLocationId()); + location.setLocationStatus("0"); + iBaseLocationService.updateById(location); // Boolean delStock = iBusinPickupService.subtractStockDetailByLocation(businDataTaskServiceById); // log.info("空治具出库任务号:"+businDataTaskServiceById.getId()+"处理的货位id:"+businDataTaskServiceById.getLocationId()+"结果:"+ delStock); // if (delStock){ // checkValue=true; // } } - Map writeMap = new HashMap<>(1); - writeMap.put("SHORT", 0); - Map allMap = new HashMap<>(1); - allMap.put(readfinishPoint, writeMap); - if (plcReadAndWrite.execWrite(plcOperate, JsonUtil.toJSONString(allMap))) { - //请求成功,记录已下发 - redisTemplate.opsForValue().set(RedisConstant.redisSTKWare + taskId, taskId,5,TimeUnit.MINUTES); - } +// Map writeMap = new HashMap<>(1); +// writeMap.put("SHORT", 0); +// Map allMap = new HashMap<>(1); +// allMap.put(readfinishPoint, writeMap); +// if (plcReadAndWrite.execWrite(plcOperate, JsonUtil.toJSONString(allMap))) { +// //请求成功,记录已下发 +// redisTemplate.opsForValue().set(RedisConstant.redisSTKWare + taskId, taskId,5,TimeUnit.MINUTES); +// } checkValue = true; } } else { diff --git a/shkj-wms/src/main/java/com/shkj/wms/plc/PlcInit.java b/shkj-wms/src/main/java/com/shkj/wms/plc/PlcInit.java index e3f80f5..4c94631 100644 --- a/shkj-wms/src/main/java/com/shkj/wms/plc/PlcInit.java +++ b/shkj-wms/src/main/java/com/shkj/wms/plc/PlcInit.java @@ -42,7 +42,7 @@ public class PlcInit { RedisTemplate redisTemplate; private ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1); - // @PostConstruct + @PostConstruct public void init(){ log.info("初始化连接对象"); executorService.scheduleWithFixedDelay( 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 c86a3b3..3f5264d 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 @@ -173,7 +173,7 @@ public class ScheduledTasks { } - // @Scheduled(fixedRate = 200) + @Scheduled(fixedRate = 200) public void task() { // log.info("开始获取需要执行的任务"); @@ -971,6 +971,105 @@ public class ScheduledTasks { //给堆垛机下命令 BusinDataTask businDataTask = iBusinDataTaskService.getById(taskId); if (ObjectUtils.isNotEmpty(businDataTask)) { + BaseLocation location = iBaseLocationService.getById(businDataTask.getLocationId()); + log.info("任务号:"+businDataTask.getId()+" 空托出库当前的货位状态:"+JsonUtil.toJSONString(location)); + Boolean isAnew =false; + if (location.getLocationStatus().equals("0")){ + log.info("当前任务号:"+businDataTask.getId()+"货位状态已无货"); + //如果货位已经无货,重新分配货位 + isAnew=true; + + }else{ + //有库存,在判断是否是空托 + //1.查询当前货位上的保险杠信息 + List sysStockDetailVos = iSysStockDetailService.queryStrockByLocation(businDataTask.getLocationId()); + //库存与任务的保险杠信息不一样,重新分配货位 + if (sysStockDetailVos !=null && sysStockDetailVos.size()>0) { + String goodsNo = sysStockDetailVos.get(0).getGoodsNo(); + if (StringUtils.isNotEmpty(goodsNo)){ + //清空预占的库存 + for (SysStockDetail sysStockDetail : sysStockDetailVos) { + sysStockDetail.setOutQty(0); + } + iSysStockDetailService.updateBatchById(sysStockDetailVos); + //更新货位状态为有货 + location.setLocationStatus("1"); + iBaseLocationService.updateById(location); + isAnew=true; + } + } + } + + if (isAnew){ + BaseLocationVo baseLocationVo = iBusinDataTaskService.outboundInfoByContainer(); + businDataTask.setFromLayer(baseLocationVo.getLayer()); + businDataTask.setFromColumn(baseLocationVo.getLocationColumn()); + businDataTask.setFromRow(baseLocationVo.getLocationRow()); + businDataTask.setLocationId(baseLocationVo.getId()); + } + + //根据货位查询是否有单深位的货位,如果有货,则查询单深位是否有任务,如果有则切换任务 + location = iBaseLocationService.getById(businDataTask.getLocationId()); + String isDeep = location.getIsDeep(); + if (isDeep.equals("2")){ + //查询单深位 + String locationRow = location.getLocationRow(); + String locationColumn = location.getLocationColumn(); + String layer = location.getLayer(); + if (locationRow.equals("1")) { + locationRow = "2"; + } else if (locationRow.equals("4")) { + locationRow = "3"; + } else if (locationRow.equals("15")) { + locationRow = "14"; + } + BaseLocation one = iBaseLocationService.getOne(new LambdaQueryWrapper() + .eq(BaseLocation::getLocationRow, locationRow) + .eq(BaseLocation::getLocationColumn, locationColumn) + .eq(BaseLocation::getLayer, layer)); + if(one !=null){ + BusinDataTask businDataTaskIsnotDeep = iBusinDataTaskService.getOne( + new LambdaQueryWrapper() + .eq(BusinDataTask::getLocationId, one.getId()) + .in(BusinDataTask::getTaskStatus, Arrays.asList("0", "-1")) + .last("limit 1") + ); + if (businDataTaskIsnotDeep != null){ + //单深位有任务,优先下发单深位任务 + log.info("当然任务的:"+taskId+"单深位任务:"+businDataTaskIsnotDeep.getId()); + businDataTask=businDataTaskIsnotDeep; + location=one; + }else{ + log.info(businDataTask.getId()+"单深位无任务,单有货:"+JsonUtil.toJSONString(one)); + //单深位无任务,再查询外面深位是否有库存,如果有,更新此任务的取货路径 + if ("1".equals(one.getLocationStatus()) || "2".equals(one.getLocationStatus())){ + //先把深位的货位状态改为有货或空托状态 + location.setLocationStatus("2"); + List oldStockDetailList = sysStockDetailMapper.getStockDetailByLocationId(String.valueOf(location.getId())); + oldStockDetailList.stream().forEach(e -> { + e.setOutQty(0); + }); + + //删除货位预占状态 + Long locationId = location.getId(); + redisTemplate.delete(RedisConstant.redisOutLoc+locationId); + + iSysStockDetailService.updateBatchById(oldStockDetailList); + iBaseLocationService.updateById(location); + + businDataTask.setFromColumn(one.getLocationColumn()); + businDataTask.setFromRow(one.getLocationRow()); + businDataTask.setFromLayer(one.getLayer()); + businDataTask.setLocationId(one.getId()); + } + } + //更新货位状态为已占用 + location.setLocationStatus("4"); + location.setExtend2(businDataTask.getId()+""); + iBaseLocationService.updateById(location); + } + } + Result taskResult = outTask(businDataTask); if (Result.isOk(taskResult)) { if (inVehicheModel.equals("3LN") || inVehicheModel.equals("3UE")) { @@ -978,10 +1077,6 @@ public class ScheduledTasks { log.info("3LN待出库空治具任务数:" + waitIssueEmpTaskNum); } - //完成后更新库位状态为空闲 - BaseLocation location = iBaseLocationService.getById(businDataTask.getLocationId()); - location.setLocationStatus("0"); - iBaseLocationService.updateById(location); businDataTaskVo.setTaskStatus(TaskStatusEnum.wait_callback.getValue()); /**空治具出库库存信息处理*/ iSysStockDetailService.deleteBySysStockByLocationId(businDataTask.getLocationId()); @@ -1729,6 +1824,9 @@ public class ScheduledTasks { if (plcReadAndWrite.execWrite(stkOperate, JsonUtil.toJSONString(allMap))) { log.info("盘点移动任务下发成功!" + businStockInv.getInvOrderNo()); businStockInv.setInvStatus(InvStatusEnum.exec.getValue()); + //巷道 + businStockInv.setExtend5(baseLocation.getTunnel()); + businStockInv.setExtend4(plcConnect.getPlcIp()); businStockInvService.updateById(businStockInv); return Result.ok().msg("盘点移动任务下发成功"); } else { @@ -1736,7 +1834,7 @@ public class ScheduledTasks { return Result.err().msg("盘点移动任务下发失败"); } } else { - return Result.err(); + return Result.err().msg("堆垛机繁忙,稍后再下发"); } } @@ -2165,6 +2263,11 @@ public class ScheduledTasks { businDataTaskVo.setToRow(locationVo.getLocationRow()); businDataTaskVo.setTunnel(tunnel); businDataTaskVo.setLocationId(locationVo.getId()); + //记录货位使用的任务号 + BaseLocation baseLocation = BeanUtil.toBean(locationVo, BaseLocation.class); + baseLocation.setExtend5(businDataTaskVo.getId()+""); + iBaseLocationService.updateById(baseLocation); + //获取货位对应的巷道及巷道对应的设备信息 pointQueryBo.setTunnel(tunnel); pointQueryBo.setDirection("0"); diff --git a/shkj-wms/src/main/java/com/shkj/wms/service/IBusinDataTaskService.java b/shkj-wms/src/main/java/com/shkj/wms/service/IBusinDataTaskService.java index dc4555f..fc65f62 100644 --- a/shkj-wms/src/main/java/com/shkj/wms/service/IBusinDataTaskService.java +++ b/shkj-wms/src/main/java/com/shkj/wms/service/IBusinDataTaskService.java @@ -88,6 +88,11 @@ public interface IBusinDataTaskService extends IService { BusinTaskExeBo outboundInfo(List goods, String id,Boolean isAnew); + /** + * 空托分配货位 + * @return + */ + BaseLocationVo outboundInfoByContainer(); /** * 查询待出库的出库单据 */ diff --git a/shkj-wms/src/main/java/com/shkj/wms/service/impl/BaseLocationServiceImpl.java b/shkj-wms/src/main/java/com/shkj/wms/service/impl/BaseLocationServiceImpl.java index 0481371..6169803 100644 --- a/shkj-wms/src/main/java/com/shkj/wms/service/impl/BaseLocationServiceImpl.java +++ b/shkj-wms/src/main/java/com/shkj/wms/service/impl/BaseLocationServiceImpl.java @@ -17,6 +17,7 @@ import com.shkj.system.service.ISysParameterService; import com.shkj.wms.bo.*; import com.shkj.wms.constants.ParameterConstants; import com.shkj.wms.domain.*; +import com.shkj.wms.enums.LocationStatusEnum; import com.shkj.wms.mapper.BaseLocationMapper; import com.shkj.wms.service.*; import com.shkj.wms.config.ValidList; @@ -1422,6 +1423,11 @@ public class BaseLocationServiceImpl extends ServiceImpl getTunnelByContaner() { + return this.baseMapper.getTunnelByContainer(); + } + + @Override public List getBaseLocationForMap(BaseLocationQueryPageBo bo) { @@ -1521,6 +1527,10 @@ public class BaseLocationServiceImpl extends ServiceImpl locationVoResult = this.assignEmptyLocationAll(assingEmptyLocBo, null); if (Result.isOk(locationVoResult)) { + //把之前的预占状态改为空 + baseLocation.setLocationStatus(LocationStatusEnum.empty.getValue()); + this.updateById(baseLocation); + BaseLocationVo baseLocationVo = locationVoResult.getData(); baseLocation = BeanUtil.toBean(baseLocationVo, BaseLocation.class); }else { @@ -1534,6 +1544,10 @@ public class BaseLocationServiceImpl extends ServiceImpl locationVoResult = this.assignEmptyLocationAll(assingEmptyLocBo, businDataTask.getTunnel()); if (Result.isOk(locationVoResult)) { + //把之前的预占状态改为空 + baseLocation.setLocationStatus(LocationStatusEnum.empty.getValue()); + this.updateById(baseLocation); + BaseLocationVo baseLocationVo = locationVoResult.getData(); baseLocation = BeanUtil.toBean(baseLocationVo, BaseLocation.class); }else { diff --git a/shkj-wms/src/main/java/com/shkj/wms/service/impl/BusinDataTaskServiceImpl.java b/shkj-wms/src/main/java/com/shkj/wms/service/impl/BusinDataTaskServiceImpl.java index e0670ca..bb215ec 100644 --- a/shkj-wms/src/main/java/com/shkj/wms/service/impl/BusinDataTaskServiceImpl.java +++ b/shkj-wms/src/main/java/com/shkj/wms/service/impl/BusinDataTaskServiceImpl.java @@ -1009,15 +1009,69 @@ public class BusinDataTaskServiceImpl extends ServiceImpl tunnelVo = baseLocationService.getTunnelByContaner(); + if (tunnelVo != null && tunnelVo.size() == 0) { + log.info("要出库的空托的无库存"); + } + //TODO 获取redis中的货位,从查询的列表中删除 + String redisKeys=RedisConstant.redisOutLoc+"*"; + Set redisOutLocaList = redisTemplate.keys(redisKeys); + for (BaseLocationVo baseLocationVo : tunnelVo) { + for (String s : redisOutLocaList) { + if (baseLocationVo.getLocationCode().equals(s)){ + tunnelVo.remove(baseLocationVo); + } + } + } + + Map tunnelLocQtyDic = tunnelVo.stream().collect(Collectors.groupingBy(BaseLocationVo::getTunnel, Collectors.counting())); + log.info("空托所在的巷道:"+JsonUtil.toJSONString(tunnelLocQtyDic)); + //排序后的巷道货位数(降序) + Map tunnelLocQtyDicSort = new LinkedHashMap<>(); + tunnelLocQtyDic.entrySet().stream().sorted(Map.Entry.comparingByValue().reversed()).forEachOrdered(e -> tunnelLocQtyDicSort.put(e.getKey(), e.getValue().intValue())); + log.info("空托所在的排序后的巷道:"+JsonUtil.toJSONString(tunnelLocQtyDicSort)); + //拿到任务数最少的巷道并且库存量是最大的 + String tunnelone = this.quickSortTaskQty(tunnelLocQtyDicSort); + log.info("空托所在的任务数最少的巷道:"+tunnelone); + List tunnelLocation = tunnelVo.stream().filter(e -> e.getTunnel().equals(tunnelone)).collect(Collectors.toList()); + List tunnelLocationSorted = tunnelLocation.stream().sorted(Comparator.comparing(BaseLocationVo::getRoute).thenComparing(BaseLocationVo::getIsDeep)).collect(Collectors.toList()); + + + //生成出库明细 + if (tunnelLocationSorted.size() == 0) { + log.info("空托没有可出货的货位了"); + } + + //根据巷道分配货位 + BaseLocationVo baseLocationVo = tunnelLocationSorted.get(0); + log.info("空托分配到的货位:"+JsonUtil.toJSONString(baseLocationVo)); + redisTemplate.opsForValue().set(RedisConstant.redisOutLoc, baseLocationVo.getId()); + return baseLocationVo; + + }catch (Exception e){ + log.error(" outboundInfoByContainer:"+e.getMessage()); + return null; + } + + } + + + /** + * 空托出库查找库存 + * @param goods + * @param id + * @param isAnew + * @return + */ public synchronized BusinTaskExeBo outboundInfo(List goods, String id,Boolean isAnew) { BusinTaskExeBo exeBo = new BusinTaskExeBo(); try { diff --git a/shkj-wms/src/main/java/com/shkj/wms/service/impl/BusinPickupServiceImpl.java b/shkj-wms/src/main/java/com/shkj/wms/service/impl/BusinPickupServiceImpl.java index 416af92..1165417 100644 --- a/shkj-wms/src/main/java/com/shkj/wms/service/impl/BusinPickupServiceImpl.java +++ b/shkj-wms/src/main/java/com/shkj/wms/service/impl/BusinPickupServiceImpl.java @@ -422,7 +422,7 @@ public class BusinPickupServiceImpl extends ServiceImpl booleanResult = iBusinEnptyContainerService.emptyContainerFlowDir(point, bo.getContainerId(), agvno, null); if (Result.isOk(booleanResult)){ - redisTemplate.opsForValue().set("xzz:"+DataTask.getId(),agvno,5, TimeUnit.MINUTES); + redisTemplate.opsForValue().set("xzz:"+DataTask.getId(),agvno,3, TimeUnit.MINUTES); } // 创建任务 @@ -753,7 +753,7 @@ public class BusinPickupServiceImpl extends ServiceImpl booleanResult = iBusinEnptyContainerService.emptyContainerFlowDir(point, businPickupAddBo.getContainerId(), agvno, null); if (Result.isOk(booleanResult)){ log.info("小组装放行完成:"+point+" AGV编号:"+agvno+" 任务号:"+businPickupAddBo.getTaskCode()); - redisTemplate.opsForValue().set("xzz:"+DataTask.getId(),agvno,5,TimeUnit.MINUTES); + redisTemplate.opsForValue().set("xzz:"+DataTask.getId(),agvno,3,TimeUnit.MINUTES); //修改为3分钟 DataTask.setTaskStatus("2"); businDataTaskService.updateById(DataTask); diff --git a/shkj-wms/src/main/java/com/shkj/wms/service/impl/BusinStockInvServiceImpl.java b/shkj-wms/src/main/java/com/shkj/wms/service/impl/BusinStockInvServiceImpl.java index b995858..11fa885 100644 --- a/shkj-wms/src/main/java/com/shkj/wms/service/impl/BusinStockInvServiceImpl.java +++ b/shkj-wms/src/main/java/com/shkj/wms/service/impl/BusinStockInvServiceImpl.java @@ -4,9 +4,12 @@ import cn.hutool.core.bean.BeanUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.shkj.common.annotation.DataScopeConsignor; +import com.shkj.common.constant.RedisConstant; import com.shkj.common.core.domain.Result; import com.shkj.common.utils.DateUtils; import com.shkj.common.utils.SecurityUtils; +import com.shkj.plc.sdk.device.PLCReadAndWrite; +import com.shkj.plc.sdk.device.PlcOperate; import com.shkj.system.service.ISysParameterService; import com.shkj.wms.bo.BusinStockInvAddBo; import com.shkj.wms.bo.BusinStockInvEditBo; @@ -20,13 +23,16 @@ import com.shkj.wms.enums.InvStatusEnum; import com.shkj.wms.enums.LocationStatusEnum; import com.shkj.wms.enums.TaskStatusEnum; import com.shkj.wms.mapper.BusinStockInvMapper; +import com.shkj.wms.plc.PlcInit; import com.shkj.wms.scheduled.ScheduledTasks; import com.shkj.wms.service.*; import com.shkj.wms.utils.IntIdUtil; +import com.shkj.wms.utils.JsonUtil; import com.shkj.wms.vo.BusinStockInvExeVo; import com.shkj.wms.vo.BusinStockInvVo; import com.shkj.wms.vo.StockLocationInvVo; import lombok.extern.slf4j.Slf4j; +import org.aspectj.weaver.ast.Var; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; @@ -35,6 +41,7 @@ import org.springframework.util.CollectionUtils; import java.math.BigDecimal; import java.util.*; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -51,20 +58,22 @@ public class BusinStockInvServiceImpl extends ServiceImpl queryList(BusinStockInvQueryBo bo) { @@ -159,7 +168,7 @@ public class BusinStockInvServiceImpl extends ServiceImpl invFinish(Long invId) { BusinStockInv businStockInv = this.getById(invId); businStockInv.setInvStatus(InvStatusEnum.end.getValue()); - return this.updateById(businStockInv)?Result.ok().msg("盘点完成成功"):Result.err().msg("盘点完成失败"); + + Boolean clearBl = clearStkStatus(businStockInv); + if (clearBl){ + return this.updateById(businStockInv)?Result.ok().msg("盘点完成成功"):Result.err().msg("盘点完成失败"); + }else { + return Result.err().msg("盘点完成失败"); + } + } + + + public Boolean clearStkStatus(BusinStockInv businStockInv){ + String stkPlcIp = businStockInv.getExtend4(); + String tunnel =businStockInv.getExtend5(); + PlcOperate plcOperate = plcInit.getPlcOperateByIp(stkPlcIp); + + String readfinishPoint="DB20.150"; + + PLCReadAndWrite plcReadAndWrite = new PLCReadAndWrite(); + Map writeMap = new HashMap<>(1); + writeMap.put("SHORT", 0); + Map allMap = new HashMap<>(1); + allMap.put(readfinishPoint, writeMap); + if (plcReadAndWrite.execWrite(plcOperate, JsonUtil.toJSONString(allMap))) { + log.info("清空堆垛机状态完成"); + redisTemplate.opsForValue().set("stackerLock:" + tunnel, "false"); + return true; + } + else { + return false; + } } diff --git a/shkj-wms/src/main/java/com/shkj/wms/service/impl/IBusinEnptyContainerServiceImpl.java b/shkj-wms/src/main/java/com/shkj/wms/service/impl/IBusinEnptyContainerServiceImpl.java index b53f42a..7b7d560 100644 --- a/shkj-wms/src/main/java/com/shkj/wms/service/impl/IBusinEnptyContainerServiceImpl.java +++ b/shkj-wms/src/main/java/com/shkj/wms/service/impl/IBusinEnptyContainerServiceImpl.java @@ -364,93 +364,12 @@ public class IBusinEnptyContainerServiceImpl extends ServiceImpl baseLocationVoList = baseLocationMapper.getEmptyContainerFromLocation(emptyconArea); - - List tunnelList = baseLocationVoList.stream().map(e -> e.getTunnel()).distinct().collect(Collectors.toList()); - if (tunnelList.size() == 0){ - log.error("无空托可以出库"); - return; - } - //从存在存放空治具货位的巷道里选择较优的巷道进行入库 - //首选选择任务数为空或者任务数最少的巷道 - //任务数相同时选取存放空治具货位最多的巷道 - List tunnelResult = new ArrayList<>(); - Integer minTaskNum = 0; - Integer maxEmptyLocationNum = 0; - for (int i = 0; i < tunnelList.size(); i++) { - String tunnel = tunnelList.get(i); - Integer taskNum = tunnelTaskUtil.getTotalTaskNum(tunnel,1); - int curEmptyNum = baseLocationVoList.stream().filter(e -> tunnel.equals(e.getTunnel())).collect(Collectors.toList()).size(); - if (minTaskNum == 0 && taskNum.equals(minTaskNum)) { - if(i != 0){ - if (curEmptyNum > maxEmptyLocationNum) { - tunnelResult.clear(); - tunnelResult.add(tunnel); - maxEmptyLocationNum = curEmptyNum; - } - } else { - minTaskNum = taskNum; - tunnelResult.add(tunnel); - maxEmptyLocationNum = curEmptyNum; - } - }else if (minTaskNum == 0) { - if(i == 0){ - minTaskNum = taskNum; - tunnelResult.add(tunnel); - maxEmptyLocationNum = curEmptyNum; - } - } else if (minTaskNum != 0 && taskNum.equals(minTaskNum)) { - if (curEmptyNum > maxEmptyLocationNum) { - tunnelResult.clear(); - tunnelResult.add(tunnel); - maxEmptyLocationNum = curEmptyNum; - } - } else if (minTaskNum != 0 && taskNum < minTaskNum) { - minTaskNum = taskNum; - tunnelResult.clear(); - tunnelResult.add(tunnel); - maxEmptyLocationNum = curEmptyNum; - } - } - String tunnel = tunnelResult.get(0); - tunnles = tunnel; - - List locationVoList = baseLocationVoList.stream().filter(e -> e.getTunnel().equals(tunnel)).collect(Collectors.toList()); - - List listlocationId=new ArrayList<>(); - //如果是双深位 查看外侧的货位是否有托盘 - for (BaseLocationVo baseLovationVO: locationVoList) { - if (baseLovationVO.getIsDeep().equals("2")){ - BaseLocation one=null; - one = iBaseLocationService.getOne(new LambdaQueryWrapper() - .eq(BaseLocation::getRoute,baseLovationVO.getRoute()) - .eq(BaseLocation::getIsDeep,"1") - .eq(BaseLocation::getTunnel,baseLovationVO.getTunnel()) - .eq(BaseLocation::getAreaId,baseLovationVO.getAreaId())); - if (one!=null&&(one.getLocationStatus().equals("4")||one.getLocationStatus().equals("2")||one.getLocationStatus().equals("1"))){ - listlocationId.add(baseLovationVO.getId()); - } - } - } - if (listlocationId.size()>0){ - for (int i=0;i{ - if (e.equals(locationVoList.get(number).getId())){ - locationVoList.remove(number); - } - }); - } - } - if(locationVoList.size() != 0){ - //根据巷道分配货位 - baseLocationVo=locationVoList.get(0); - } + baseLocationVo = businDataTaskService.outboundInfoByContainer(); + }else{ + log.info("无需要空托的点位。。。。"); + return; } + //库内有空治具 if (baseLocationVo !=null){ //输送线PLCID @@ -520,6 +439,9 @@ public class IBusinEnptyContainerServiceImpl extends ServiceImpl + + +