diff --git a/ktg-mes/src/main/java/com/ktg/mes/md/controller/BaseKnifeController.java b/ktg-mes/src/main/java/com/ktg/mes/md/controller/BaseKnifeController.java index 8b0a1a0..ab52ab3 100644 --- a/ktg-mes/src/main/java/com/ktg/mes/md/controller/BaseKnifeController.java +++ b/ktg-mes/src/main/java/com/ktg/mes/md/controller/BaseKnifeController.java @@ -6,6 +6,7 @@ import javax.servlet.http.HttpServletResponse; import com.alibaba.fastjson.JSON; import com.ktg.common.utils.DateUtils; +import com.ktg.generator.util.MultiModuleCodeGenerator; import com.ktg.mes.md.domain.*; import com.ktg.mes.md.mapper.WmsOutPlanDetailEntityMapper; import com.ktg.mes.md.mapper.WmsOutPlanMapper; @@ -305,12 +306,19 @@ public class BaseKnifeController extends BaseController { @PostMapping("/open/productionArrangements/{planSheet}") @ResponseBody public AjaxResult productionArrangements(@PathVariable String planSheet, @RequestBody List processCodeList) { + // 检查计划单是否已存在 BaseKnife baseKnifePlan = new BaseKnife(); baseKnifePlan.setPlanSheet(planSheet); if (!baseKnifeService.selectBaseKnifeList(baseKnifePlan).isEmpty()) return AjaxResult.error("该计划单已存在,请更换重试"); + // 齐套性检查 + AjaxResult ajaxResult = this.checkForAlignment(processCodeList); + if (Integer.parseInt(String.valueOf(ajaxResult.get("code"))) != 200){ + return AjaxResult.error(ajaxResult.get("msg").toString(), ajaxResult.get("data")); + } + // 验证bom工艺 List technologyBomList = baseTechnologyBomService.selectBaseTechnologyBomListByProcessCodeList(processCodeList); if (technologyBomList.isEmpty() || technologyBomList.size() == 1 && technologyBomList.get(0).getKnifeCode() == null) @@ -804,6 +812,9 @@ public class BaseKnifeController extends BaseController { // 入库任务 MdItem mdItem = mdItemService.selectMdItemById(zdTask.getmProductId()); WmsInTask wmsInTask = new WmsInTask(); + // 生成任务号 + String taskInCode = MultiModuleCodeGenerator.generateTaskCode("RKT"); + wmsInTask.setTaskInCode(taskInCode); wmsInTask.setPlanInId(wmsInPlan.getPlanId().toString()); wmsInTask.setPlanInCode(wmsInPlan.getPlanCode()); wmsInTask.setMaterialCode(mdItem.getItemCode()); diff --git a/ktg-mes/src/main/java/com/ktg/mes/wm/controller/WmsZdTaskController.java b/ktg-mes/src/main/java/com/ktg/mes/wm/controller/WmsZdTaskController.java index 18269fe..7cf82a1 100644 --- a/ktg-mes/src/main/java/com/ktg/mes/wm/controller/WmsZdTaskController.java +++ b/ktg-mes/src/main/java/com/ktg/mes/wm/controller/WmsZdTaskController.java @@ -34,6 +34,29 @@ public class WmsZdTaskController extends BaseController @Autowired private IWmsZdTaskService wmsZdTaskService; + + /** + * 开始组装任务 + */ + @PreAuthorize("@ss.hasPermi('wm:zdTask:edit')") + @Log(title = "开始组装", businessType = BusinessType.UPDATE) + @PutMapping("/out") + public AjaxResult out(@RequestBody WmsZdTask wmsZdTask) + { + return wmsZdTaskService.createOutTaskByWmsZdTask(wmsZdTask); + } + + /** + * 完成组装任务 + */ + @PreAuthorize("@ss.hasPermi('wm:zdTask:edit')") + @Log(title = "完成组装", businessType = BusinessType.UPDATE) + @PutMapping("/in") + public AjaxResult in(@RequestBody WmsZdTask wmsZdTask) + { + return wmsZdTaskService.createInTaskByWmsZdTask(wmsZdTask); + } + /** * 查询组装任务列表 */ diff --git a/ktg-mes/src/main/java/com/ktg/mes/wm/service/IWmsZdTaskService.java b/ktg-mes/src/main/java/com/ktg/mes/wm/service/IWmsZdTaskService.java index b7878ef..d66cc6c 100644 --- a/ktg-mes/src/main/java/com/ktg/mes/wm/service/IWmsZdTaskService.java +++ b/ktg-mes/src/main/java/com/ktg/mes/wm/service/IWmsZdTaskService.java @@ -1,6 +1,8 @@ package com.ktg.mes.wm.service; import java.util.List; + +import com.ktg.common.core.domain.AjaxResult; import com.ktg.mes.wm.domain.WmsZdTask; /** @@ -58,4 +60,8 @@ public interface IWmsZdTaskService * @return 结果 */ public int deleteWmsZdTaskByWmsZdTaskId(String wmsZdTaskId); + + AjaxResult createOutTaskByWmsZdTask(WmsZdTask wmsZdTask); + + AjaxResult createInTaskByWmsZdTask(WmsZdTask wmsZdTask); } diff --git a/ktg-mes/src/main/java/com/ktg/mes/wm/service/impl/WmsZdTaskServiceImpl.java b/ktg-mes/src/main/java/com/ktg/mes/wm/service/impl/WmsZdTaskServiceImpl.java index 5230865..c5cd172 100644 --- a/ktg-mes/src/main/java/com/ktg/mes/wm/service/impl/WmsZdTaskServiceImpl.java +++ b/ktg-mes/src/main/java/com/ktg/mes/wm/service/impl/WmsZdTaskServiceImpl.java @@ -1,13 +1,33 @@ package com.ktg.mes.wm.service.impl; +import java.util.ArrayList; import java.util.List; + +import com.ktg.common.core.domain.AjaxResult; import com.ktg.common.utils.DateUtils; +import com.ktg.generator.util.MultiModuleCodeGenerator; +import com.ktg.mes.md.domain.*; +import com.ktg.mes.md.mapper.*; +import com.ktg.mes.md.service.IBaseKnifeService; +import com.ktg.mes.md.service.IBaseTechnologyBomService; +import com.ktg.mes.md.service.IBomRouteService; +import com.ktg.mes.md.service.IMdItemService; +import com.ktg.mes.wm.domain.*; +import com.ktg.mes.wm.mapper.WmStorageAreaMapper; +import com.ktg.mes.wm.mapper.WmsInPlanMapper; +import com.ktg.mes.wm.mapper.WmsInTaskMapper; +import com.ktg.mes.wm.service.IWmStorageAreaService; +import com.ktg.mes.wm.service.IWmsInPlanService; +import com.ktg.mes.wm.service.IWmsInTaskService; +import com.ktg.system.mapper.SysOperLogMapper; +import com.ktg.system.service.ISysOperLogService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ktg.mes.wm.mapper.WmsZdTaskMapper; -import com.ktg.mes.wm.domain.WmsZdTask; import com.ktg.mes.wm.service.IWmsZdTaskService; +import static com.ktg.common.utils.SecurityUtils.getUsername; +import static com.ktg.generator.util.MultiModuleCodeGenerator.generateTaskCode; import static org.apache.commons.lang3.SystemUtils.getUserName; /** @@ -19,9 +39,39 @@ import static org.apache.commons.lang3.SystemUtils.getUserName; @Service public class WmsZdTaskServiceImpl implements IWmsZdTaskService { + @Autowired + private BaseKnifeMapper baseKnifeMapper; + + @Autowired + private BomRouteMapper bomRouteMapper; + + @Autowired + private MdItemMapper mdItemMapper; + + @Autowired + private BaseTechnologyBomMapper baseTechnologyBomMapper; + @Autowired private WmsZdTaskMapper wmsZdTaskMapper; + @Autowired + private WmStorageAreaMapper wmStorageAreaMapper; + + @Autowired + private WmsInPlanMapper wmsInPlanMapper; + + @Autowired + private WmsInTaskMapper wmsInTaskMapper; + + @Autowired + private WmsOutPlanMapper wmsOutPlanMapper; + + @Autowired + private WmsOutPlanDetailEntityMapper wmsOutPlanDetailEntityMapper; + + @Autowired + private WmsOutTaskMapper wmsOutTaskMapper; + /** * 查询组装任务 * @@ -97,4 +147,243 @@ public class WmsZdTaskServiceImpl implements IWmsZdTaskService { return wmsZdTaskMapper.deleteWmsZdTaskByWmsZdTaskId(wmsZdTaskId); } + + @Override + public AjaxResult createOutTaskByWmsZdTask(WmsZdTask zdTask) { + String batchNum = "ZZPC001"; + + // 判断物料是否充足 + BomRoute bomRoute = bomRouteMapper.selectBomRouteByBomRouteId(zdTask.getAttr1()); + BaseKnife baseKnifeWrapper = new BaseKnife(); + List baseKnifeList = new ArrayList<>(); + + // 遍历组装整刀需要的bom物料 + for (MbbProduBom mbbProduBom : bomRoute.getMbbProduBomList()) { + // 查找未锁定的物料 + baseKnifeWrapper.setMbbBdMrlId(mbbProduBom.getMdItemId()); + baseKnifeWrapper.setIsLocked(0); + baseKnifeList = baseKnifeMapper.selectBaseKnifeList(baseKnifeWrapper); + + // 如果未锁定的物料不足所需数量 + if (baseKnifeList.size() < mbbProduBom.getStandardDosage() * zdTask.getProductIdQty()) + return AjaxResult.error("bom物料不足进行组装:" + mbbProduBom.getMdItemCode()); + } + + List wmsOutPlanDetailList = new ArrayList<>(); + List baseKnifeListOutPlan = new ArrayList<>(); + + BaseTechnologyBom technologyBom = new BaseTechnologyBom(); + + // 出库基础物料, 根据图号查询出库计划,如果不存在生成计划,存在则往计划中添加任务 + WmsOutPlan outPlan = wmsOutPlanMapper.selectWmsOutPlanByPlanCode(zdTask.getAttr4()); + if (outPlan == null){ + // 构建新的出库计划 + WmsOutPlan outPlanTemp = new WmsOutPlan(); + outPlanTemp.setPlanCode(zdTask.getAttr4() == null ? zdTask.getCode() : zdTask.getAttr4()); + outPlanTemp.setWmsBusinessTypeId(12L); + outPlanTemp.setPlanState("1"); + outPlanTemp.setPlanType("ZDCK"); + outPlanTemp.setCreateBy(getUsername()); + outPlanTemp.setCreateTime(DateUtils.getNowDate()); + wmsOutPlanMapper.insertWmsOutPlan(outPlanTemp); + outPlan = outPlanTemp; + } + + // 出库任务 + for (MbbProduBom mbbProduBom : bomRoute.getMbbProduBomList()) { + // 出库任务,进行基础物料的出库 + MdItem mdItemOutPlan = mdItemMapper.selectMdItemById(mbbProduBom.getMdItemId()); + WmsOutPlanDetail outPlanDetail = new WmsOutPlanDetail(); + outPlanDetail.setWmsOutPlanId(outPlan.getWmsOutPlanId()); + outPlanDetail.setMdItemId(mbbProduBom.getMdItemId()); + outPlanDetail.setMdItemCode(mdItemOutPlan.getItemCode()); + outPlanDetail.setMdItemName(mdItemOutPlan.getItemName()); + outPlanDetail.setMdItemUnit(mdItemOutPlan.getUnitName()); + outPlanDetail.setPlannedQuantity(mbbProduBom.getStandardDosage() * zdTask.getProductIdQty()); + outPlanDetail.setRealQuantity(mbbProduBom.getStandardDosage() * zdTask.getProductIdQty()); + outPlanDetail.setDetailBatchNum(batchNum); + // 查询库位信息 + WmStorageArea wmStorageArea = wmStorageAreaMapper.selectWmStorageAreaByAreaCode(zdTask.getAttr3()); + outPlanDetail.setWmStorageAreaId(wmStorageArea.getAreaId()); + outPlanDetail.setWmStorageAreaCode(wmStorageArea.getAreaCode()); + outPlanDetail.setWmStorageAreaName(wmStorageArea.getAreaName()); + outPlanDetail.setDetailState("1"); + wmsOutPlanDetailList.add(outPlanDetail); + + // 查询未锁定的物料 + baseKnifeWrapper.setMbbBdMrlId(mbbProduBom.getMdItemId()); + baseKnifeWrapper.setIsLocked(0); + baseKnifeList = baseKnifeMapper.selectBaseKnifeList(baseKnifeWrapper); + + // 锁定基础 物料 + int bomCount = mbbProduBom.getStandardDosage(); + for (BaseKnife wmsBaseKnife : baseKnifeList){ + if (bomCount > 0){ + wmsBaseKnife.setIsLocked(1); + wmsBaseKnife.setKnifeFineState(2); + wmsBaseKnife.setLockedStartTime(technologyBom.getLockedStartTime()); + wmsBaseKnife.setLockedEndTime(technologyBom.getLockedEndTime()); +// wmsBaseKnife.setAttr1(baseKnife.getBaseKnifeId()); + wmsBaseKnife.setPlanSheet(zdTask.getAttr4()); + baseKnifeListOutPlan.add(wmsBaseKnife); + baseKnifeMapper.updateBaseKnife(wmsBaseKnife); + bomCount--; + } + } + } + + // 出库 + int i = 0; + for (WmsOutPlanDetail outPlanDetail : wmsOutPlanDetailList){ + wmsOutPlanMapper.insertWmsOutPlanDetail(outPlanDetail); + + // 出库计划明细,绑定实体 + for (int j = 0; j < outPlanDetail.getPlannedQuantity(); j++) { + WmsOutPlanDetailEntity wmsOutPlanDetailEntity = new WmsOutPlanDetailEntity(); + wmsOutPlanDetailEntity.setBaseKnifeId(baseKnifeListOutPlan.get(i).getBaseKnifeId()); + wmsOutPlanDetailEntity.setAreaCode(baseKnifeListOutPlan.get(i).getAreaCode()); + wmsOutPlanDetailEntity.setItemOrProduct(baseKnifeListOutPlan.get(i).getItemOrProduct()); + wmsOutPlanDetailEntity.setKnifeCode(baseKnifeListOutPlan.get(i).getKnifeCode()); + wmsOutPlanDetailEntity.setKnifeName(baseKnifeListOutPlan.get(i).getKnifeName()); + wmsOutPlanDetailEntity.setPlanSheet(baseKnifeListOutPlan.get(i).getPlanSheet()); + wmsOutPlanDetailEntity.setKnifeLife(baseKnifeListOutPlan.get(i).getKnifeLife()); + wmsOutPlanDetailEntity.setResetCount(baseKnifeListOutPlan.get(i).getResetCount()); + wmsOutPlanDetailEntity.setKnifeUnit(baseKnifeListOutPlan.get(i).getKnifeUnit()); + wmsOutPlanDetailEntity.setSafeStock(baseKnifeListOutPlan.get(i).getKnifeType()); + wmsOutPlanDetailEntity.setStandardQuantity(baseKnifeListOutPlan.get(i++).getStandardQuantity()); + wmsOutPlanDetailEntity.setWmsOutPlanDetailId(outPlanDetail.getWmsOutPlanDetailId()); + wmsOutPlanDetailEntity.setCreateBy(getUsername()); + wmsOutPlanDetailEntity.setCreateTime(DateUtils.getNowDate()); + wmsOutPlanDetailEntityMapper.insertWmsOutPlanDetailEntity(wmsOutPlanDetailEntity); + } + + // 生成出库任务 + WmsOutTask wmsOutTask = new WmsOutTask(); + wmsOutTask.setWmsOutPlanId(outPlan.getWmsOutPlanId()); + wmsOutTask.setWmsOutPlanCode(outPlan.getPlanCode()); + wmsOutTask.setWmsOutPlanDetailId(outPlanDetail.getWmsOutPlanDetailId()); + // 出库类型 12组刀出库 + wmsOutTask.setWmsBusinessTypeId(12L); + wmsOutTask.setTaskCode(generateTaskCode(outPlan.getPlanCode())); + wmsOutTask.setTaskNumber(outPlanDetail.getPlannedQuantity()); + wmsOutTask.setOutNumber(outPlanDetail.getRealQuantity()); + wmsOutTask.setWmStorageAreaId(outPlanDetail.getWmStorageAreaId()); + wmsOutTask.setBatchNum(batchNum); + wmsOutTask.setMdItemId(outPlanDetail.getMdItemId()); + wmsOutTask.setMdItemCode(outPlanDetail.getMdItemCode()); + wmsOutTask.setMdItemName(outPlanDetail.getMdItemName()); + wmsOutTask.setMdItemUnit(outPlanDetail.getMdItemUnit()); + wmsOutTask.setTaskState("1"); + wmsOutTask.setRecipientUsername(""); + wmsOutTask.setCreateBy(getUsername()); + wmsOutTask.setCreateTime(DateUtils.getNowDate()); + wmsOutTaskMapper.insertWmsOutTask(wmsOutTask); + } + + // 更新组装任务 + zdTask.setStatus("1"); + zdTask.setQtyOk(zdTask.getProductIdQty()); + wmsZdTaskMapper.updateWmsZdTask(zdTask); + return AjaxResult.success(); + } + + + @Override + public AjaxResult createInTaskByWmsZdTask(WmsZdTask zdTask) { + String batchNum = "ZZPC001"; + + BaseTechnologyBom technologyBom = new BaseTechnologyBom(); + + for (int i = 0; i < zdTask.getProductIdQty(); i++) { + // 构建整刀 + BaseKnife baseKnife = new BaseKnife(); + MdItem mdItem = mdItemMapper.selectMdItemById(zdTask.getmProductId()); + baseKnife.setMbbBdMrlId(zdTask.getmProductId()); + baseKnife.setKnifeCode(mdItem.getItemCode()); + baseKnife.setKnifeName(mdItem.getItemName()); + baseKnife.setKnifeUnit(mdItem.getUnitName()); + baseKnife.setKnifeType(mdItem.getItemTypeName()); + // attr3 库位编码 + baseKnife.setAreaCode(zdTask.getAttr3()); + baseKnife.setSafeStock(mdItem.getMinStock()); + baseKnife.setStandardQuantity("1"); + baseKnife.setKnifeLife(100); + baseKnife.setKnifeFineState(1); + // 判断是否需要锁定整刀 + baseKnife.setIsLocked(1); + baseKnife.setLockedStartTime(technologyBom.getLockedStartTime()); + baseKnife.setLockedEndTime(technologyBom.getLockedEndTime()); + + // attr4 计划编码, 整刀 + baseKnife.setPlanSheet(zdTask.getAttr4()); + baseKnife.setItemOrProduct("PRODUCT"); + baseKnife.setCreateBy(getUsername()); + baseKnife.setCreateTime(DateUtils.getNowDate()); + baseKnifeMapper.insertBaseKnife(baseKnife); + } + + // 整刀入库计划, 根据图号查询入库计划,如果不存在生成计划,存在则往计划中添加任务 + WmsInPlan wmsInPlan = wmsInPlanMapper.selectWmsInPlanByPlanCode(zdTask.getAttr4()); + if (wmsInPlan == null){ + WmsInPlan wmsInPlanTemp = new WmsInPlan(); + wmsInPlanTemp.setState("1"); + wmsInPlanTemp.setSourceType("SGLR"); + wmsInPlanTemp.setCellCode(zdTask.getAttr3()); + wmsInPlanTemp.setPlanCode(zdTask.getAttr4() == null ? zdTask.getCode() : zdTask.getAttr4()); + wmsInPlanTemp.setRelBillCode("组装单据"); + wmsInPlanTemp.setPlanTypeId("13"); + wmsInPlanTemp.setCreateBy(getUsername()); + wmsInPlanTemp.setCreateTime(DateUtils.getNowDate()); + + // 入库任务明细 + List wmsInPlanDetailsList = new ArrayList<>(); + WmsInPlanDetails wmsInPlanDetails = new WmsInPlanDetails(); + wmsInPlanDetails.setMaterialId(zdTask.getmProductId().toString()); + wmsInPlanDetails.setBatch(batchNum); + wmsInPlanDetails.setCellId(1L); + wmsInPlanDetails.setQuantity(zdTask.getProductIdQty().toString()); + wmsInPlanDetails.setQuantityIn(zdTask.getProductIdQty().toString()); + wmsInPlanDetails.setPlanInStatus("0"); + wmsInPlanDetailsList.add(wmsInPlanDetails); + wmsInPlanTemp.setWmsInPlanDetailsList(wmsInPlanDetailsList); + wmsInPlanMapper.insertWmsInPlan(wmsInPlanTemp); + wmsInPlan = wmsInPlanTemp; + } else { + // 入库任务明细 + List wmsInPlanDetailsList = wmsInPlan.getWmsInPlanDetailsList(); + WmsInPlanDetails wmsInPlanDetails = new WmsInPlanDetails(); + wmsInPlanDetails.setMaterialId(zdTask.getmProductId().toString()); + wmsInPlanDetails.setBatch(batchNum); + wmsInPlanDetails.setCellId(1L); + wmsInPlanDetails.setQuantity(zdTask.getProductIdQty().toString()); + wmsInPlanDetails.setQuantityIn(zdTask.getProductIdQty().toString()); + wmsInPlanDetails.setPlanInStatus("0"); + wmsInPlanDetailsList.add(wmsInPlanDetails); + wmsInPlan.setWmsInPlanDetailsList(wmsInPlanDetailsList); + wmsInPlanMapper.updateWmsInPlan(wmsInPlan); + } + + // 入库任务 + MdItem mdItem = mdItemMapper.selectMdItemById(zdTask.getmProductId()); + WmsInTask wmsInTask = new WmsInTask(); + wmsInTask.setTaskInCode(MultiModuleCodeGenerator.generateTaskCode("RKT")); + wmsInTask.setPlanInId(wmsInPlan.getPlanId().toString()); + wmsInTask.setPlanInCode(wmsInPlan.getPlanCode()); + wmsInTask.setMaterialCode(mdItem.getItemCode()); + wmsInTask.setTaskInQuantity(zdTask.getProductIdQty()); + wmsInTask.setActualInQuantity(zdTask.getProductIdQty()); + WmStorageArea wmStorageArea = wmStorageAreaMapper.selectWmStorageAreaByAreaCode(zdTask.getAttr3()); + wmsInTask.setCellTgt(wmStorageArea.getAreaId()); + wmsInTask.setBatch(batchNum); + wmsInTask.setMaterialId(zdTask.getmProductId().toString()); + wmsInTask.setPlanTypeId("9"); + wmsInTask.setPlanInStatus("1"); + wmsInTaskMapper.insertWmsInTask(wmsInTask); + + // 更新组装任务 + zdTask.setStatus("2"); + zdTask.setQtyOk(zdTask.getProductIdQty()); + wmsZdTaskMapper.updateWmsZdTask(zdTask); + return AjaxResult.success(); + } } diff --git a/ktg-mes/src/main/resources/mapper/md/MdUnitMeasureMapper.xml b/ktg-mes/src/main/resources/mapper/md/MdUnitMeasureMapper.xml index eace785..7db9a8b 100644 --- a/ktg-mes/src/main/resources/mapper/md/MdUnitMeasureMapper.xml +++ b/ktg-mes/src/main/resources/mapper/md/MdUnitMeasureMapper.xml @@ -41,6 +41,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and attr3 = #{attr3} and attr4 = #{attr4} + order by create_time desc