diff --git a/6.program/wms-empty/src/main/java/com/mt/wms/empty/controller/CurrTaskController.java b/6.program/wms-empty/src/main/java/com/mt/wms/empty/controller/CurrTaskController.java index 439493b..b9f6213 100644 --- a/6.program/wms-empty/src/main/java/com/mt/wms/empty/controller/CurrTaskController.java +++ b/6.program/wms-empty/src/main/java/com/mt/wms/empty/controller/CurrTaskController.java @@ -266,7 +266,7 @@ public class CurrTaskController extends BaseController { } @PostMapping(value = "currentTaskNow") - @ApiOperation(value = "获取当前执行的任务 (车辆名称传id)") + @ApiOperation(value = "获取当前执行的任务") public R> currentTask(@Validated @RequestBody CurrTaskQueryParam param) { return currTaskService.currentTaskPage(param); } @@ -276,7 +276,11 @@ public class CurrTaskController extends BaseController { public R> currentTaskInfo(@Validated @RequestBody CurrTaskQueryParam param) { return currTaskService.currentTaskInfoPage(param); } - + @PostMapping(value = "updateCurrTaskStatus") + @ApiOperation(value = "更新任务状态") + public R updateCurrTaskStatus(@Validated @RequestBody CurrTaskParam param){ + return currTaskService.updateCurrTaskStatus(param); + } @PostMapping(value = "completeTask") @ApiOperation(value = "执行任务完成(仅wms,不通知apms)") public R completeTask(@Validated @RequestBody IdParam param) { diff --git a/6.program/wms-empty/src/main/java/com/mt/wms/empty/service/CurrTaskService.java b/6.program/wms-empty/src/main/java/com/mt/wms/empty/service/CurrTaskService.java index 6fd1028..09870a0 100644 --- a/6.program/wms-empty/src/main/java/com/mt/wms/empty/service/CurrTaskService.java +++ b/6.program/wms-empty/src/main/java/com/mt/wms/empty/service/CurrTaskService.java @@ -7,6 +7,7 @@ import com.mt.wms.core.vo.IdVo; import com.mt.wms.core.vo.PageVo; import com.mt.wms.core.vo.R; import com.mt.wms.empty.params.AutoCurrTaskParam; +import com.mt.wms.empty.params.CurrTaskParam; import com.mt.wms.empty.params.CurrTaskQueryParam; import com.mt.wms.empty.params.TaskCreateParam; import com.mt.wms.empty.vo.CurrTaskInfoVo; @@ -73,6 +74,14 @@ public interface CurrTaskService { */ R> currentTaskInfoPage(CurrTaskQueryParam param); + /** + * 更新任务状态 + * + * @param param 查询参数 + * @return 结果 + */ + R updateCurrTaskStatus(CurrTaskParam param); + /** * 完成执行任务 不会物理删除,会将删除值置为0,同时在历史表复制一份记录 方便在订单未完成时查询任务详情 * diff --git a/6.program/wms-empty/src/main/java/com/mt/wms/empty/service/impl/CurrTaskServiceImpl.java b/6.program/wms-empty/src/main/java/com/mt/wms/empty/service/impl/CurrTaskServiceImpl.java index 93a5abf..f56aaea 100644 --- a/6.program/wms-empty/src/main/java/com/mt/wms/empty/service/impl/CurrTaskServiceImpl.java +++ b/6.program/wms-empty/src/main/java/com/mt/wms/empty/service/impl/CurrTaskServiceImpl.java @@ -14,13 +14,12 @@ import com.mt.wms.core.vo.PageVo; import com.mt.wms.core.vo.R; import com.mt.wms.empty.controller.ApmsController; import com.mt.wms.empty.enums.TaskTypeEnum; -import com.mt.wms.empty.params.AutoCurrTaskParam; -import com.mt.wms.empty.params.CurrTaskQueryParam; -import com.mt.wms.empty.params.TaskCreateParam; +import com.mt.wms.empty.params.*; import com.mt.wms.empty.service.*; import com.mt.wms.empty.task.RunTaskUtils; import com.mt.wms.empty.task.TaskDistanceUtils; import com.mt.wms.empty.vo.*; +import com.mt.wms.empty.websocket.WebSocketServer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; @@ -28,8 +27,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; 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.*; import java.util.stream.Collectors; @@ -59,6 +60,8 @@ public class CurrTaskServiceImpl extends BaseService implements CurrTaskService @Autowired ApmsController apmsControl; + @Autowired + WebSocketServer webSocketServer; @Autowired OrderInfoServiceBiz orderInfoServiceBiz; @@ -165,7 +168,7 @@ public class CurrTaskServiceImpl extends BaseService implements CurrTaskService List currTaskVos = com.mt.wms.core.utils.BeanUtils.copyList(currTasks, CurrTaskVo.class); currTaskInfoVo.setCurrTaskVoList(currTaskVos); String allStep="液压台"; - String nowStep=""; + String nowStep="未开始"; for (CurrTask currTask1:currTasks ) { if (currTask1.getStatus()==1){ @@ -198,7 +201,80 @@ public class CurrTaskServiceImpl extends BaseService implements CurrTaskService return successful(list); } - + @Override + public R updateCurrTaskStatus(CurrTaskParam param) { + CurrTask currTask = currTaskServiceBiz.getById(param.getId()); + Integer status = param.getStatus(); + //修改为加工中,多步骤任务修改为加工中,查询缓存区,查询前置任务状态,并修改 + if (status==1){ + InStockInfo inStockInfo = inStockInfoServiceBiz.getOne(new QueryWrapper().eq(InStockInfo.TASK_ID, currTask.getId())); + if (inStockInfo!=null){ + //更新库位状态为未占用 + Location location = locationServiceBiz.getById(inStockInfo.getLocationId()); + location.setStatus(0); + locationServiceBiz.updateById(location); + //删除库位缓存 + inStockInfoServiceBiz.removeById(inStockInfo); + } + if (currTask.getIsAuto()==1){ + AutoExeTask autoExeTask = autoExeTaskServiceBiz.getById(currTask.getAutoExeTaskId()); + if (currTask.getId().equals(autoExeTask.getFTaskId())){ + //该任务为自动任务第一条,是否有sheetNo,若无上报apms + if (currTask.getSheetNo()==null){ + try { + apmsCreateProcess(currTask); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + if (currTask.getId().equals(autoExeTask.getTTaskId())){ + //该任务为自动任务第二条,修改自动任务第一条的状态 + CurrTask currTask1 = currTaskServiceBiz.getById(autoExeTask.getFTaskId()); + currTask1.setStatus(2); + currTask1.setIsIn(2); + //99代表该条记录手动修改过 + currTask1.setCreatorId(99); + currTaskServiceBiz.updateById(currTask1); + }else if (currTask.getId().equals(autoExeTask.getThTaskId())){ + //该任务为自动任务第三条,修改自动任务第二条的状态 + CurrTask currTask2 = currTaskServiceBiz.getById(autoExeTask.getFTaskId()); + currTask2.setStatus(2); + currTask2.setIsIn(2); + //99代表该条记录手动修改过 + currTask2.setCreatorId(99); + currTaskServiceBiz.updateById(currTask2); + } + } + currTask.setStatus(1); + currTask.setCreatorId(99); + currTask.setBeginTime(LocalDateTime.now()); + currTaskServiceBiz.updateById(currTask); + return successful("修改任务状态为加工中成功"); + } + //修改为加工完成,查询缓存,并修改 + if (status==2){ + InStockInfo inStockInfo = inStockInfoServiceBiz.getOne(new QueryWrapper().eq(InStockInfo.TASK_ID, currTask.getId())); + if (inStockInfo!=null){ + //更新库位状态为未占用 + Location location = locationServiceBiz.getById(inStockInfo.getLocationId()); + location.setStatus(0); + locationServiceBiz.updateById(location); + //删除库位缓存 + inStockInfoServiceBiz.removeById(inStockInfo); + } + currTask.setStatus(1); + currTask.setCreatorId(99); + currTask.setBeginTime(LocalDateTime.now()); + currTaskServiceBiz.updateById(currTask); + return successful("修改任务状态为加工完成成功"); + } + currTask.setStatus(status); + currTask.setCreatorId(99); + currTask.setBeginTime(LocalDateTime.now()); + currTaskServiceBiz.updateById(currTask); + return successful("修改任务状态为未加工成功"); + } @Override @@ -408,4 +484,57 @@ public class CurrTaskServiceImpl extends BaseService implements CurrTaskService inStockInfoServiceBiz.updateById(inStockInfo); return R.ok("当前任务置顶成功",""); } + /** + * 上报apms创建生产单并开始处理 + * + * @param currTask 任务 + * @return 成功与否 + * @throws IOException + */ + private Boolean apmsCreateProcess(CurrTask currTask) throws IOException { + List currTaskDetList = currTaskDetServiceBiz.list(new QueryWrapper().eq(CurrTaskDet.CURR_TASK_ID, currTask.getId())); + String code = kilnInfoServiceBiz.getById(currTask.getKilnId()).getCode(); + //通知apms创建一个生产单 + ApmsCreateProcessSheet apmsCreateSheet = new ApmsCreateProcessSheet(); + apmsCreateSheet.setWorkShopCode("BM"); + apmsCreateSheet.setStartTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); + apmsCreateSheet.setTechCode(currTask.getCraftCodeId().toString()); + //fixme 暂时没有正式user,使用测试账户 + apmsCreateSheet.setStartUser("QJJP03"); + ArrayList createItems = new ArrayList<>(); + currTaskDetList.forEach(e -> { + CreateItem createItem = new CreateItem(); + createItem.setItemCode(e.getIdenCardNum()); + createItem.setQuantity(e.getQuantity().intValue()); + createItem.setWeight(e.getWeight().doubleValue()); + createItems.add(createItem); + }); + apmsCreateSheet.setStoveCode(code); + apmsCreateSheet.setItems(createItems); + logger.info(currTask.getId() + "开始创建apms生产单号"); + R processSheet = apmsControl.createProcessSheet(apmsCreateSheet); + if (!processSheet.getData().getSuccess()) { + logger.info(currTask.getId() + "创建失败,APMS报错:" + processSheet.getData().getMsg()); + webSocketServer.sendtoUser("创建失败,APMS报错:" + processSheet.getData().getMsg(), "1"); + return false; + } else { + logger.info(currTask.getId() + "创建apms生产单号成功"); + currTask.setSheetNo(processSheet.getData().getSheetNo()); + currTaskServiceBiz.updateById(currTask); + //多步骤任务除了第一步写入sheetNo + if (currTask.getIsAuto()==1){ + AutoExeTask autoExeTask = autoExeTaskServiceBiz.getById(currTask.getAutoExeTaskId()); + CurrTask secondCurrTask = currTaskServiceBiz.getById(autoExeTask.getTTaskId()); + secondCurrTask.setSheetNo(currTask.getSheetNo()); + currTaskServiceBiz.updateById(secondCurrTask); + //三步任务 + if (autoExeTask.getProcessFlowType()==2){ + CurrTask threeCurrTask = currTaskServiceBiz.getById(autoExeTask.getThTaskId()); + threeCurrTask.setSheetNo(currTask.getSheetNo()); + currTaskServiceBiz.updateById(threeCurrTask); + } + } + return true; + } + } }