From 8d0b4aed82ffc5c7eb06d42a34f7b52190c776bf Mon Sep 17 00:00:00 2001 From: LGH <1746689524@qq.com> Date: Tue, 12 Jul 2022 22:36:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9apms=E4=B8=8A=E6=8A=A5?= =?UTF-8?q?=E6=97=B6=E6=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mt/wms/empty/task/AsynRunTaskService.java | 238 ++++++++++++------ .../com/mt/wms/empty/task/RunTaskUtils.java | 13 +- .../com/mt/wms/empty/task/ScheduledTask.java | 11 +- 3 files changed, 171 insertions(+), 91 deletions(-) diff --git a/6.program/wms-empty/src/main/java/com/mt/wms/empty/task/AsynRunTaskService.java b/6.program/wms-empty/src/main/java/com/mt/wms/empty/task/AsynRunTaskService.java index a702815..08be078 100644 --- a/6.program/wms-empty/src/main/java/com/mt/wms/empty/task/AsynRunTaskService.java +++ b/6.program/wms-empty/src/main/java/com/mt/wms/empty/task/AsynRunTaskService.java @@ -99,20 +99,6 @@ public class AsynRunTaskService extends BaseService { runTask.setEndPosition(currTask.getTargetPosition()); runTask.setBeginTime(LocalDateTime.now()); runTaskServiceBiz.save(runTask); - //任务为自动任务第一步或任务为非自动任务时创建生产单,其他情况下开始生产单 - if (isFirstTask(currTask)) { - //通知apms创建一个生产单 - Boolean createProcess = apmsCreateProcess(currTask); - if (!createProcess) { - return; - } - } else { - //通知apms开始生产单 - Boolean startProcess = apmsStartProcess(currTask); - if (!startProcess) { - return; - } - } //调用车辆填入起终点,得到车辆执行结果 Long startPoint = pointInfoServiceBiz.getOne(new QueryWrapper().eq(PointInfo.NOTE, runTask.getStartPosition())).getCode(); Long endPoint = pointInfoServiceBiz.getOne(new QueryWrapper().eq(PointInfo.NOTE, runTask.getEndPosition())).getCode(); @@ -120,8 +106,6 @@ public class AsynRunTaskService extends BaseService { logger.info(String.valueOf(status)); //执行成功,托盘进炉 if (status == 1) { - // TODO: 2022/7/7 开始记录能源消耗 - logger.info("===执行任务:" + currTaskId + " ,车辆搬运任务,车辆:" + vehicleId + " ,起点:" + startPoint + " ,终点:" + endPoint + "任务执行成功==="); //更新调度表状态为完成 runTask.setUpdateTime(LocalDateTime.now()); @@ -137,15 +121,42 @@ public class AsynRunTaskService extends BaseService { //更新小车状态 vehicle.setStatus(0); vehicleInfoServiceBiz.updateById(vehicle); + //任务为自动任务第一步或任务为非自动任务时创建生产单,其他情况下开始生产单 + if (isFirstTask(currTask)) { + //通知apms创建一个生产单 + apmsCreateProcess(currTask); + } else { + int secondSetp = autoExeTaskServiceBiz.count(new QueryWrapper().eq(AutoExeTask.T_TASK_ID, currTaskId)); + if (secondSetp>0){ + //当前任务为自动任务里的第二步,先上报第一步的apms-endProcess + AutoExeTask autoExeTask = autoExeTaskServiceBiz.getOne(new QueryWrapper().eq(AutoExeTask.T_TASK_ID, currTaskId)); + CurrTask firstCurrTask = currTaskServiceBiz.getById(autoExeTask.getFTaskId()); + firstCurrTask.setIsIn(2); + currTaskServiceBiz.updateById(firstCurrTask); + apmsEndProcess(firstCurrTask); + //再上报第二步开始处理 + apmsStartProcess(currTask); + } + int threeSetp = autoExeTaskServiceBiz.count(new QueryWrapper().eq(AutoExeTask.TH_TASK_ID, currTaskId)); + if (threeSetp>0){ + //当前任务为自动任务里的第三步,先上报第二步的apms处理endProcess + AutoExeTask autoExeTask = autoExeTaskServiceBiz.getOne(new QueryWrapper().eq(AutoExeTask.TH_TASK_ID, currTaskId)); + CurrTask secondCurrTask = currTaskServiceBiz.getById(autoExeTask.getFTaskId()); + secondCurrTask.setIsIn(2); + currTaskServiceBiz.updateById(secondCurrTask); + apmsEndProcess(secondCurrTask); + //再上报第三步开始处理 + apmsStartProcess(currTask); + } + } asynStartRecordConsume(currTaskId, currTask.getKilnId()); } else { runTask.setStatus(3); runTask.setUpdateTime(LocalDateTime.now()); runTaskServiceBiz.updateById(runTask); logger.info("===执行任务:" + currTaskId + " ,车辆搬运任务,车辆:" + vehicleId + " ,起点:" + startPoint + " ,终点:" + endPoint + "任务执行失败==="); - logger.info("任务 " + currTask.getTaskCode() + " 车辆从液压台台到加工炉过程中失败。"); - // TODO: 2021/12/14 websocket推送到前端,小车管理界面添加一个重置小车状态的接口。 - webSocketServer.sendtoAll("任务 " + currTask.getTaskCode() + " 车辆从液压台台到加工炉过程中失败。"); + logger.info("任务 " + currTask.getTaskCode() + " 车辆从起点"+startPoint+"台到加工炉过程中失败。"); + webSocketServer.sendtoAll("任务 " + currTask.getTaskCode() + " 车辆从起点"+startPoint+"台到加工炉过程中失败。"); } } @@ -171,20 +182,6 @@ public class AsynRunTaskService extends BaseService { //修改缓存区存储情况表状态 inStockInfo.setStatus(1); inStockInfoServiceBiz.updateById(inStockInfo); - //任务为自动任务第一步或任务为非自动任务时创建生产单,其他情况下开始生产单 - if (isFirstTask(currTask)) { - //通知apms创建一个生产单 - Boolean createProcess = apmsCreateProcess(currTask); - if (!createProcess) { - return; - } - } else { - //通知apms开始生产单 - Boolean startProcess = apmsStartProcess(currTask); - if (!startProcess) { - return; - } - } // 调用车辆填入起终点,得到车辆执行结果 Long startPoint = pointInfoServiceBiz.getOne(new QueryWrapper().eq(PointInfo.NOTE, runTask.getStartPosition())).getCode(); Long endPoint = pointInfoServiceBiz.getOne(new QueryWrapper().eq(PointInfo.NOTE, runTask.getEndPosition())).getCode(); @@ -217,7 +214,35 @@ public class AsynRunTaskService extends BaseService { //更新小车状态 vehicle.setStatus(0); vehicleInfoServiceBiz.updateById(vehicle); - // TODO: 2022/7/7 + //任务为自动任务第一步或任务为非自动任务时创建生产单,其他情况下开始生产单 + if (isFirstTask(currTask)) { + //通知apms创建一个生产单 + apmsCreateProcess(currTask); + } else { + int secondSetp = autoExeTaskServiceBiz.count(new QueryWrapper().eq(AutoExeTask.T_TASK_ID, currTaskId)); + if (secondSetp>0){ + //当前任务为自动任务里的第二步,先上报第一步的apms-endProcess + AutoExeTask autoExeTask = autoExeTaskServiceBiz.getOne(new QueryWrapper().eq(AutoExeTask.T_TASK_ID, currTaskId)); + CurrTask firstCurrTask = currTaskServiceBiz.getById(autoExeTask.getFTaskId()); + firstCurrTask.setIsIn(2); + currTaskServiceBiz.updateById(firstCurrTask); + apmsEndProcess(firstCurrTask); + //再上报第二步开始处理 + apmsStartProcess(currTask); + } + int threeSetp = autoExeTaskServiceBiz.count(new QueryWrapper().eq(AutoExeTask.TH_TASK_ID, currTaskId)); + if (threeSetp>0){ + //当前任务为自动任务里的第三步,先上报第二步的apms处理endProcess + AutoExeTask autoExeTask = autoExeTaskServiceBiz.getOne(new QueryWrapper().eq(AutoExeTask.TH_TASK_ID, currTaskId)); + CurrTask secondCurrTask = currTaskServiceBiz.getById(autoExeTask.getFTaskId()); + secondCurrTask.setIsIn(2); + currTaskServiceBiz.updateById(secondCurrTask); + apmsEndProcess(secondCurrTask); + //再上报第三步开始处理 + apmsStartProcess(currTask); + } + } + // 记录开始加工时的消耗值 asynStartRecordConsume(currTaskId, currTask.getKilnId()); } else { runTask.setStatus(3); @@ -284,6 +309,24 @@ public class AsynRunTaskService extends BaseService { //更新小车状态 vehicle.setStatus(0); vehicleInfoServiceBiz.updateById(vehicle); + //如果任务为多步骤任务的非第一步,置前置任务isIn为2 + if (currTask.getIsAuto()==1){ + int count = autoExeTaskServiceBiz.count(new QueryWrapper().eq(AutoExeTask.F_TASK_ID, currTaskId)); + if (count==0){ + int secondCount = autoExeTaskServiceBiz.count(new QueryWrapper().eq(AutoExeTask.T_TASK_ID, currTaskId)); + if (secondCount==1){ + AutoExeTask autoExeTask = autoExeTaskServiceBiz.getOne(new QueryWrapper().eq(AutoExeTask.T_TASK_ID, currTaskId)); + CurrTask firstCurrTask = currTaskServiceBiz.getById(autoExeTask.getFTaskId()); + firstCurrTask.setIsIn(2); + currTaskServiceBiz.updateById(firstCurrTask); + }else { + AutoExeTask autoExeTask = autoExeTaskServiceBiz.getOne(new QueryWrapper().eq(AutoExeTask.TH_TASK_ID, currTaskId)); + CurrTask secondCurrTask = currTaskServiceBiz.getById(autoExeTask.getThTaskId()); + secondCurrTask.setIsIn(2); + currTaskServiceBiz.updateById(secondCurrTask); + } + } + } } else { runTask.setStatus(3); runTask.setUpdateTime(LocalDateTime.now()); @@ -334,8 +377,6 @@ public class AsynRunTaskService extends BaseService { Long endPoint = pointInfoServiceBiz.getOne(new QueryWrapper().eq(PointInfo.NOTE, runTask.getEndPosition())).getCode(); Integer status = sendTaskToRgv(vehicleId, currTaskId, startPoint, endPoint, currTask.getPlcValue()); if (status == 1) { - // TODO: 2022/7/7 加工完成,记录结束时能源消耗 - logger.info("===执行任务:" + currTaskId + " ,车辆搬运任务,车辆:" + vehicleId + " ,起点:" + startPoint + " ,终点:" + endPoint + "任务执行成功==="); //更新关系表状态为完成 runTask.setUpdateTime(LocalDateTime.now()); @@ -355,50 +396,35 @@ public class AsynRunTaskService extends BaseService { //更新小车状态 vehicle.setStatus(0); vehicleInfoServiceBiz.updateById(vehicle); - asynEndRecordConsume(currTaskId, currTask.getKilnId()); - // TODO: 2022/7/6 上报apms加工完成.每次进炉加工完成后就上报apms完成处理生产单,等所有加工步骤都完成后上报apms完成生产单。 - logger.info("任务:" + currTaskId + " 生产单号:" + currTask.getSheetNo() + "开始上报apm完成处理生产单!"); - ApmsEndProcess apmsEndProcess = new ApmsEndProcess(); - apmsEndProcess.setEndTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); - apmsEndProcess.setEndUser("QJJP03"); - apmsEndProcess.setSheetNo(currTask.getSheetNo()); - R apmsEndProcessVoR = apmsController.endProcess(apmsEndProcess); - if (apmsEndProcessVoR.getCode() != 0) { - logger.info("任务:" + currTaskId + " 生产单号:" + currTask.getSheetNo() + "上报apm完成处理生产单失败!"); - } - if (currTask.getIsAuto() == 1) { - //两步且是第二步 - List twoSpet = autoExeTaskServiceBiz.list(new QueryWrapper() - .eq(AutoExeTask.PROCESS_FLOW_TYPE, 1) - .eq(AutoExeTask.T_TASK_ID, currTaskId)); - //三步且是第三步 - List threeSpet = autoExeTaskServiceBiz.list(new QueryWrapper() - .eq(AutoExeTask.PROCESS_FLOW_TYPE, 2) - .eq(AutoExeTask.TH_TASK_ID, currTaskId)); - if (!(threeSpet.size() != 0 || twoSpet.size() != 0)) { - return; + //任务为非自动任务上报apms-end-finish + if (currTask.getIsOut()==0) { + //上报apms完成处理 + logger.info("此任务为单步骤任务,任务结束,上报apms-end-finish"); + apmsEndProcess(currTask); + apmsFinishProcess(currTask); + } else { + int secondSetp = autoExeTaskServiceBiz.count(new QueryWrapper().eq(AutoExeTask.T_TASK_ID, currTaskId)); + if (secondSetp>0){ + AutoExeTask autoExeTask = autoExeTaskServiceBiz.getOne(new QueryWrapper().eq(AutoExeTask.T_TASK_ID, currTaskId)); + if (autoExeTask.getProcessFlowType()==1){ + logger.info("此任务为为自动任务里的第二步且一共只有两步,任务结束,上报apms-end-finish"); + //当前任务为自动任务里的第三步且一共只有两步,先上报apms处理endProcess + apmsEndProcess(currTask); + //再上报apms-finishProcess + apmsFinishProcess(currTask); + } } - } - logger.info("任务:" + currTask.getTaskCode() + "开始上报apms完成生产单!"); - ApmsFinishProcessSheet apmsFinishProcessSheet = new ApmsFinishProcessSheet(); - apmsFinishProcessSheet.setSheetNo(currTask.getSheetNo()); - apmsFinishProcessSheet.setEndTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); - apmsFinishProcessSheet.setEndUser("QJJP03"); - List finishItems = new ArrayList<>(); - List currTaskDets = currTaskDetServiceBiz.list(new QueryWrapper().eq(CurrTaskDet.CURR_TASK_ID, currTaskId)); - for (CurrTaskDet currTaskDet : currTaskDets - ) { - FinishItem finishItem = new FinishItem(); - BigDecimal bigDecimal = new BigDecimal(currTaskDet.getWeight()); - finishItem.setFinishWeight(bigDecimal.doubleValue()); - finishItem.setFinishQuantity(Math.round(currTaskDet.getQuantity())); - finishItem.setItemCode(currTaskDet.getIdenCardNum()); - finishItems.add(finishItem); - } - apmsFinishProcessSheet.setItems(finishItems); - R apmsFinishProcessSheetVoR = apmsController.finishProcessSheet(apmsFinishProcessSheet); - if (apmsFinishProcessSheetVoR.getCode() != 0) { - logger.info("任务:" + currTask.getTaskCode() + "完成后上报apms完成生产单失败!"); + int threeSetp = autoExeTaskServiceBiz.count(new QueryWrapper().eq(AutoExeTask.TH_TASK_ID, currTaskId)); + if (threeSetp>0){ + logger.info("此任务为为自动任务里的第三步,任务结束,上报apms-end-finish"); + //当前任务为自动任务里的第三步,先上报apms处理endProcess + apmsEndProcess(currTask); + //再上报apms-finishProcess + apmsFinishProcess(currTask); + } + logger.info("此任务为为自动任务里的第一步或第二步,任务结束,上报apms-end-finish"); + //为自动任务的非第三步 + apmsEndProcess(currTask); } } else { runTask.setStatus(3); @@ -1088,6 +1114,56 @@ public class AsynRunTaskService extends BaseService { logger.info("任务号" + currTask.getTaskCode() + "生产单号:" + currTask.getSheetNo() + "生产单开始生产上报apms成功"); return true; } + + /** + * 上报apms-end + * @param currTask + * @return + */ + private Boolean apmsEndProcess(CurrTask currTask){ + ApmsEndProcess apmsEndProcess = new ApmsEndProcess(); + apmsEndProcess.setEndTime(currTask.getEndTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); + apmsEndProcess.setEndUser("QJJP03"); + apmsEndProcess.setSheetNo(currTask.getSheetNo()); + R apmsEndProcessVoR = apmsController.endProcess(apmsEndProcess); + if (apmsEndProcessVoR.getCode() != 0) { + logger.info("任务号" + currTask.getTaskCode() + "生产单号:" + currTask.getSheetNo() + "生产单完成处理上报apms失败"); + return false; + } + logger.info("任务号" + currTask.getTaskCode() + "生产单号:" + currTask.getSheetNo() + "生产单完成处理上报apms成功"); + return true; + } + + /** + * 上报apms-finish + * @param currTask + * @return + */ + private Boolean apmsFinishProcess(CurrTask currTask){ + logger.info("任务:" + currTask.getTaskCode() + "开始上报apms完成生产单!"); + ApmsFinishProcessSheet apmsFinishProcessSheet = new ApmsFinishProcessSheet(); + apmsFinishProcessSheet.setSheetNo(currTask.getSheetNo()); + apmsFinishProcessSheet.setEndTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); + apmsFinishProcessSheet.setEndUser("QJJP03"); + List finishItems = new ArrayList<>(); + List currTaskDets = currTaskDetServiceBiz.list(new QueryWrapper().eq(CurrTaskDet.CURR_TASK_ID, currTask.getId())); + for (CurrTaskDet currTaskDet : currTaskDets + ) { + FinishItem finishItem = new FinishItem(); + BigDecimal bigDecimal = new BigDecimal(currTaskDet.getWeight()); + finishItem.setFinishWeight(bigDecimal.doubleValue()); + finishItem.setFinishQuantity(Math.round(currTaskDet.getQuantity())); + finishItem.setItemCode(currTaskDet.getIdenCardNum()); + finishItems.add(finishItem); + } + apmsFinishProcessSheet.setItems(finishItems); + R apmsFinishProcessSheetVoR = apmsController.finishProcessSheet(apmsFinishProcessSheet); + if (apmsFinishProcessSheetVoR.getCode() != 0) { + logger.info("任务:" + currTask.getTaskCode() + "完成后上报apms完成生产单失败!"); + return false; + } + return true; + } /** * 车辆是否在线 * @param vehicleId 车辆id @@ -1177,11 +1253,13 @@ public class AsynRunTaskService extends BaseService { * @return 单步骤任务true,多步骤任务第一步true,其他false */ public Boolean isFirstTask(CurrTask currTask){ - if (currTask.getAutoExeTaskId()==1){ + if (currTask.getIsOut()==1){ int count = autoExeTaskServiceBiz.count(new QueryWrapper().eq(AutoExeTask.F_TASK_ID, currTask.getId())); return count>0; }else { return true; } } + + } diff --git a/6.program/wms-empty/src/main/java/com/mt/wms/empty/task/RunTaskUtils.java b/6.program/wms-empty/src/main/java/com/mt/wms/empty/task/RunTaskUtils.java index 035c760..38a2ff6 100644 --- a/6.program/wms-empty/src/main/java/com/mt/wms/empty/task/RunTaskUtils.java +++ b/6.program/wms-empty/src/main/java/com/mt/wms/empty/task/RunTaskUtils.java @@ -7,6 +7,9 @@ import com.mt.wms.core.dal.entity.*; import com.mt.wms.core.dal.service.*; import com.mt.wms.core.utils.HttpClient; import com.mt.wms.core.vo.R; +import com.mt.wms.empty.controller.ApmsController; +import com.mt.wms.empty.params.ApmsEndProcess; +import com.mt.wms.empty.vo.ApmsEndProcessVo; import com.mt.wms.empty.websocket.WebSocketServer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -18,6 +21,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.io.IOException; import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -55,6 +59,8 @@ public class RunTaskUtils { private PlcNameSpaceServiceBiz plcNameSpaceServiceBiz; @Resource private WebSocketServer webSocketServer; + @Resource + private ApmsController apmsController; /** * 进炉加工 @@ -200,11 +206,7 @@ public class RunTaskUtils { logger.info("自动任务第一步:"+currTask.getTaskCode()+"已执行完成。开始执行第二步任务:"+currTaskTwo); // 2022/2/27 websocket推送到页面显示 webSocketServer.sendtoAll("自动任务第一步:"+currTask.getTaskCode()+"已执行完成。开始执行第二步任务:"+currTaskTwo); - // TODO: 2022/7/12 第一步任务的结束上报 - currTask.setEndTime(LocalDateTime.now()); - currTask.setIsIn(2); - currTaskServiceBiz.updateById(currTask); - return runTaskForInKiln(taskId); + return runTaskForInKiln(taskId); } catch (InterruptedException e) { e.printStackTrace(); } @@ -222,7 +224,6 @@ public class RunTaskUtils { logger.info("自动任务第二步:"+currTask.getTaskCode()+"已执行完成。开始执行第三步任务:"+currTaskThree); // 2022/2/27 websocket推送到页面显示 webSocketServer.sendtoAll("自动任务第二步:"+currTask.getTaskCode()+"已执行完成。开始执行第三步任务:"+currTaskThree); - // TODO: 2022/7/12 第二步任务的结束上报 return runTaskForInKiln(thTaskId); } catch (InterruptedException e) { e.printStackTrace(); diff --git a/6.program/wms-empty/src/main/java/com/mt/wms/empty/task/ScheduledTask.java b/6.program/wms-empty/src/main/java/com/mt/wms/empty/task/ScheduledTask.java index 7a58632..2d3bc2c 100644 --- a/6.program/wms-empty/src/main/java/com/mt/wms/empty/task/ScheduledTask.java +++ b/6.program/wms-empty/src/main/java/com/mt/wms/empty/task/ScheduledTask.java @@ -9,6 +9,7 @@ import com.mt.wms.core.dal.service.*; import com.mt.wms.core.utils.BeanUtils; import com.mt.wms.core.utils.CodeGeneratorHelper; import com.mt.wms.core.utils.HttpClient; +import com.mt.wms.core.utils.StringUtils; import com.mt.wms.core.vo.R; import com.mt.wms.empty.vo.CurrTaskDetVo; import com.mt.wms.empty.vo.NowCurrTaskDetVo; @@ -74,7 +75,6 @@ public class ScheduledTask extends BaseService { @Resource private OrderInfoServiceBiz orderInfoServiceBiz; - @Test //@Scheduled(fixedDelay = 1000*20) public void test() throws IOException { } @@ -216,10 +216,11 @@ public class ScheduledTask extends BaseService { logger.info(kilnInfo.getCode()+kilnInfo.getKilnAlias()+"识别到允许出炉信号,进入出库程序!"); asynRunTaskService.asynEndRecordConsume(currTask.getId(),kilnId); logger.info(kilnInfo.getCode()+"炉子中的任务:"+currTask.getId()+"已加工结束,记录加工结束能源消耗值"); - //更新加工单工艺结束时间 - currTask.setEndTime(LocalDateTime.now()); - currTaskServiceBiz.updateById(currTask); - //上报apms结束加工 + //更新加工单工艺结束时间,只更新一次,因为可能因为不满住出炉条件而进入到下一次定时任务 + if (StringUtils.isBlank(currTask.getEndTime().toString())){ + currTask.setEndTime(LocalDateTime.now()); + currTaskServiceBiz.updateById(currTask); + } runTaskUtils.runTaskForOutKiln(kilnId); break; }