diff --git a/lms/nladmin-system/src/main/java/org/nl/b_lms/pdm/subpackagerelation/service/impl/PdmBiSubpackagerelationServiceImpl.java b/lms/nladmin-system/src/main/java/org/nl/b_lms/pdm/subpackagerelation/service/impl/PdmBiSubpackagerelationServiceImpl.java index c00444781..ffc31300b 100644 --- a/lms/nladmin-system/src/main/java/org/nl/b_lms/pdm/subpackagerelation/service/impl/PdmBiSubpackagerelationServiceImpl.java +++ b/lms/nladmin-system/src/main/java/org/nl/b_lms/pdm/subpackagerelation/service/impl/PdmBiSubpackagerelationServiceImpl.java @@ -14,6 +14,7 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import lombok.SneakyThrows; import lombok.extern.log4j.Log4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -42,6 +43,8 @@ import org.nl.modules.common.exception.BadRequestException; import org.nl.system.service.param.ISysParamService; import org.nl.wms.ext.mes.service.impl.LmsToMesServiceImpl; import org.nl.wms.sch.manage.TaskStatusEnum; +import org.redisson.api.RLock; +import org.redisson.api.RedissonClient; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; @@ -52,6 +55,7 @@ import java.math.BigDecimal; import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -65,6 +69,9 @@ import java.util.stream.Collectors; @Log4j public class PdmBiSubpackagerelationServiceImpl extends ServiceImpl implements IpdmBiSubpackagerelationService { + + @Resource + private RedissonClient redissonClient; @Resource private IschBaseTaskService taskService; @Resource @@ -353,11 +360,11 @@ public class PdmBiSubpackagerelationServiceImpl extends ServiceImpl workIdList = JSONObject.parseArray(whereJson.getJSONArray("tableMater").toJSONString(), PdmBiSubpackagerelation.class).stream() .map(PdmBiSubpackagerelation::getWorkorder_id) .map(String::valueOf) @@ -835,9 +846,6 @@ public class PdmBiSubpackagerelationServiceImpl extends ServiceImpl containerNameList, String deviceCode, String boxSn) { //待检区点位 List djqPointList = packageinfoivtService @@ -897,34 +906,47 @@ public class PdmBiSubpackagerelationServiceImpl extends ServiceImpl schBaseTaskList = new ArrayList<>(); - //确定起点,安装装箱组标识加入任务队列 - djqPoints.forEach(r -> { - //校验重复任务 - List taskList = taskService.list(new LambdaQueryWrapper().eq(SchBaseTask::getVehicle_code, r.getContainer_name()).eq(SchBaseTask::getTask_type, PackageInfoIvtEnum.TASK_TYPE.code("待检区->装箱区")) - .eq(SchBaseTask::getIs_delete, IOSEnum.IS_NOTANDYES.code("否")).lt(SchBaseTask::getTask_status, TaskStatusEnum.FINISHED)); - if (CollectionUtils.isEmpty(taskList)) { - JSONObject jo = new JSONObject(); - jo.put("task_type", PackageInfoIvtEnum.TASK_TYPE.code("待检区->装箱区")); - jo.put("vehicle_code", r.getContainer_name()); - jo.put("point_code1", r.getPoint_code()); - jo.put("task_status", TaskStatusEnum.SURE_START.getCode()); - //木箱号 - jo.put("vehicle_code2", groupId); - //任务组id - SchBaseTask task = new SchBaseTask(); - //保存任务子卷号 - SchBaseTask taskDto = zxqTask.createTaskReturnTask(jo); - task.setTask_id(taskDto.getTask_id()); - task.setVehicle_code(taskDto.getVehicle_code()); - //增加任务到队列 - schBaseTaskList.add(task); + RLock lock = redissonClient.getLock(groupId); + boolean tryLock = lock.tryLock(0, TimeUnit.SECONDS); + try { + if (tryLock) { + List schBaseTaskList = new ArrayList<>(); + //确定起点,安装装箱组标识加入任务队列 + djqPoints.forEach(r -> { + //校验重复任务 + List taskList = taskService.list(new LambdaQueryWrapper().eq(SchBaseTask::getVehicle_code, r.getContainer_name()).eq(SchBaseTask::getTask_type, PackageInfoIvtEnum.TASK_TYPE.code("待检区->装箱区")) + .eq(SchBaseTask::getIs_delete, IOSEnum.IS_NOTANDYES.code("否")).lt(SchBaseTask::getTask_status, TaskStatusEnum.FINISHED)); + if (CollectionUtils.isEmpty(taskList)) { + JSONObject jo = new JSONObject(); + jo.put("task_type", PackageInfoIvtEnum.TASK_TYPE.code("待检区->装箱区")); + jo.put("vehicle_code", r.getContainer_name()); + jo.put("point_code1", r.getPoint_code()); + jo.put("task_status", TaskStatusEnum.SURE_START.getCode()); + //木箱号 + jo.put("vehicle_code2", groupId); + //任务组id + SchBaseTask task = new SchBaseTask(); + //保存任务子卷号 + SchBaseTask taskDto = zxqTask.createTaskReturnTask(jo); + task.setTask_id(taskDto.getTask_id()); + task.setVehicle_code(taskDto.getVehicle_code()); + //增加任务到队列 + schBaseTaskList.add(task); + } + }); + if (CollectionUtils.isNotEmpty(schBaseTaskList)) { + taskQueue.addTasksToQueue(groupId, schBaseTaskList); + } + } else { + log.info("待检区->装箱区任务队列正在创建被锁住。"); + } + } finally { + if (tryLock) { + lock.unlock(); } - }); - if (CollectionUtils.isNotEmpty(schBaseTaskList)) { - taskQueue.addTasksToQueue(groupId, schBaseTaskList); } } + } diff --git a/lms/nladmin-system/src/main/java/org/nl/b_lms/sch/tasks/first_floor_area/auto/AutoSendZxToDjw.java b/lms/nladmin-system/src/main/java/org/nl/b_lms/sch/tasks/first_floor_area/auto/AutoSendZxToDjw.java index 48a88ea9d..882bd9d38 100644 --- a/lms/nladmin-system/src/main/java/org/nl/b_lms/sch/tasks/first_floor_area/auto/AutoSendZxToDjw.java +++ b/lms/nladmin-system/src/main/java/org/nl/b_lms/sch/tasks/first_floor_area/auto/AutoSendZxToDjw.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -28,6 +29,8 @@ import org.nl.modules.common.exception.BadRequestException; import org.nl.system.service.param.ISysParamService; import org.nl.wms.ext.mes.service.impl.LmsToMesServiceImpl; import org.nl.wms.sch.manage.TaskStatusEnum; +import org.redisson.api.RLock; +import org.redisson.api.RedissonClient; import org.springframework.stereotype.Component; import javax.annotation.Resource; @@ -35,6 +38,7 @@ import java.math.BigDecimal; import java.util.List; import java.util.Objects; import java.util.Set; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import static org.nl.wms.util.TaskUtil.getMaxNum; @@ -45,6 +49,7 @@ import static org.nl.wms.util.TaskUtil.getMaxNum; @RequiredArgsConstructor public class AutoSendZxToDjw { + private final RedissonClient redissonClient; @Resource private IschBaseTaskService taskService; @Resource @@ -76,7 +81,8 @@ public class AutoSendZxToDjw { this.sendZxToDjw(); } - void sendZxToDjw() { + @SneakyThrows + public void sendZxToDjw() { //装箱位有木箱 List zxwPackageinfoivtList = packageinfoivtService.checkEndPointTask(PackageInfoIvtEnum.POINT_STATUS.code("装箱位"), PackageInfoIvtEnum.IVT_STATUS.code("空载具"), "", PackageInfoIvtEnum.SORT_TYPE.code("升序"), PackageInfoIvtEnum.TASK_TYPE.code("装箱区->装箱对接位")); if (CollectionUtils.isEmpty(zxwPackageinfoivtList)) { @@ -106,51 +112,63 @@ public class AutoSendZxToDjw { } //获取与该木箱号匹配的子卷号 String containerName = relationList.get(0).getContainer_name(); - List zxqPoint = zxqPackageinfoivtList.stream().filter(r -> r.getContainer_name().equals(containerName)).collect(Collectors.toList()); - //装箱区点位上有与该木箱号匹配的子卷 - if (CollectionUtils.isNotEmpty(zxqPoint)) { - List productionPlanList = pdmBiSlittingproductionplanMapper.selectList(new LambdaQueryWrapper().eq(PdmBiSlittingproductionplan::getContainer_name, containerName)); - if (productionPlanList.isEmpty()) { - log.info("装箱区的子卷号为" + containerName + "无对应的分切计划信息,请检查!"); - throw new BadRequestException("装箱区的子卷号为" + containerName + "无对应的分切计划信息,请检查!"); - } - //校验是否存在相同子卷号任务 - List taskList = taskService.list(new LambdaQueryWrapper().eq(SchBaseTask::getVehicle_code, containerName).eq(SchBaseTask::getTask_type, PackageInfoIvtEnum.TASK_TYPE.code("装箱区->装箱对接位")).eq(SchBaseTask::getIs_delete, IOSEnum.IS_NOTANDYES.code("否")).lt(SchBaseTask::getTask_status, TaskStatusEnum.FINISHED.getCode())); - if (CollectionUtils.isEmpty(taskList)) { - //创建搬运任务到装箱位 - JSONObject jo = new JSONObject(); - jo.put("task_type", PackageInfoIvtEnum.TASK_TYPE.code("装箱区->装箱对接位")); - jo.put("acs_task_type", PackageInfoIvtEnum.ACS_TASK_TYPE.code("桁架任务")); - jo.put("point_code1", zxqPoint.get(0).getPoint_code()); - jo.put("point_code2", zxwPackageinfoivtList.get(0).getPoint_code()); - jo.put("vehicle_code", containerName); - jo.put("vehicle_code2", boxNo); - jo.put("is_send", IOSEnum.IS_NOTANDYES.code("是")); - //扩展参数 - JSONObject param = new JSONObject(); - //查询是否为最后一个子卷,暂时默认1 - param.put("lastOne", IOSEnum.IS_NOTANDYES.code("是")); - //获取木箱高度等级 - param.put("heightLevel", getHeightLevel(bstIvtBoxinfo)); - //获取子卷长度 - param.put("len", getMaxNum(productionPlanList.get(0), null)); - //木箱最大数量 - param.put("maxNo", bstIvtBoxinfo.getNum()); - //托盘类型 1小托盘 2大托盘 - param.put("containerType", bstIvtBoxinfo.getVehicle_type()); - //木箱需放入子卷数量 - //param.put("boxNo", relationList.get(0).getQuanlity_in_box()); - param.put("boxNo", 1); - //子卷号 - param.put("barcode", containerName); - jo.put("request_param", param.toString()); - zxDjwTask.createTask(jo); - try { - //传输子卷包装关系至MES - transferBoxPackageToMes(relationList, bstIvtBoxinfo); - } catch (Exception ex) { - log.error("装箱区->装箱对接位sendZxToDjw,传输子卷包装关系至MES接口捕获异常信息:" + ex); + RLock lock = redissonClient.getLock(containerName); + boolean tryLock = lock.tryLock(0, TimeUnit.SECONDS); + try { + if (tryLock) { + List zxqPoint = zxqPackageinfoivtList.stream().filter(r -> r.getContainer_name().equals(containerName)).collect(Collectors.toList()); + //装箱区点位上有与该木箱号匹配的子卷 + if (CollectionUtils.isNotEmpty(zxqPoint)) { + List productionPlanList = pdmBiSlittingproductionplanMapper.selectList(new LambdaQueryWrapper().eq(PdmBiSlittingproductionplan::getContainer_name, containerName)); + if (productionPlanList.isEmpty()) { + log.info("装箱区的子卷号为" + containerName + "无对应的分切计划信息,请检查!"); + throw new BadRequestException("装箱区的子卷号为" + containerName + "无对应的分切计划信息,请检查!"); + } + //校验是否存在相同子卷号任务 + List taskList = taskService.list(new LambdaQueryWrapper().eq(SchBaseTask::getVehicle_code, containerName).eq(SchBaseTask::getTask_type, PackageInfoIvtEnum.TASK_TYPE.code("装箱区->装箱对接位")).eq(SchBaseTask::getIs_delete, IOSEnum.IS_NOTANDYES.code("否")).lt(SchBaseTask::getTask_status, TaskStatusEnum.FINISHED.getCode())); + if (CollectionUtils.isEmpty(taskList)) { + //创建搬运任务到装箱位 + JSONObject jo = new JSONObject(); + jo.put("task_type", PackageInfoIvtEnum.TASK_TYPE.code("装箱区->装箱对接位")); + jo.put("acs_task_type", PackageInfoIvtEnum.ACS_TASK_TYPE.code("桁架任务")); + jo.put("point_code1", zxqPoint.get(0).getPoint_code()); + jo.put("point_code2", zxwPackageinfoivtList.get(0).getPoint_code()); + jo.put("vehicle_code", containerName); + jo.put("vehicle_code2", boxNo); + jo.put("is_send", IOSEnum.IS_NOTANDYES.code("是")); + //扩展参数 + JSONObject param = new JSONObject(); + //查询是否为最后一个子卷,暂时默认1 + param.put("lastOne", IOSEnum.IS_NOTANDYES.code("是")); + //获取木箱高度等级 + param.put("heightLevel", getHeightLevel(bstIvtBoxinfo)); + //获取子卷长度 + param.put("len", getMaxNum(productionPlanList.get(0), null)); + //木箱最大数量 + param.put("maxNo", bstIvtBoxinfo.getNum()); + //托盘类型 1小托盘 2大托盘 + param.put("containerType", bstIvtBoxinfo.getVehicle_type()); + //木箱需放入子卷数量 + //param.put("boxNo", relationList.get(0).getQuanlity_in_box()); + param.put("boxNo", 1); + //子卷号 + param.put("barcode", containerName); + jo.put("request_param", param.toString()); + zxDjwTask.createTask(jo); + // try { + //todo 传输子卷包装关系至MES,暂时不计算,MES会推过来 + //transferBoxPackageToMes(relationList, bstIvtBoxinfo); + // } catch (Exception ex) { + // log.error("装箱区->装箱对接位sendZxToDjw,传输子卷包装关系至MES接口捕获异常信息:" + ex); + // } + } } + } else { + log.info("装箱区->装箱对接位agv自动搬运任务正在创建被锁住。"); + } + } finally { + if (tryLock) { + lock.unlock(); } } }