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 92c7d3e..7e22997 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 @@ -1,5 +1,6 @@ package com.ktg.mes.md.controller; +import java.io.IOException; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; import javax.servlet.http.HttpServletResponse; @@ -7,6 +8,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.cal.utils.CalendarUtil; import com.ktg.mes.md.domain.*; import com.ktg.mes.md.mapper.BaseKnifeLockedMapper; import com.ktg.mes.md.mapper.WmsOutPlanDetailEntityMapper; @@ -21,6 +23,10 @@ import com.ktg.mes.wm.service.IWmsInTaskService; import com.ktg.mes.wm.service.IWmsZdTaskService; import com.ktg.system.domain.SysOperLog; import com.ktg.system.service.ISysOperLogService; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; @@ -86,6 +92,8 @@ public class BaseKnifeController extends BaseController { @Autowired private BaseKnifeLockedMapper baseKnifeLockedMapper; + @Autowired + private MyConfig myConfig; /** @@ -138,6 +146,31 @@ public class BaseKnifeController extends BaseController { return getDataTable(list); } + /** + * 列表查询 + * + * @return + */ + @PostMapping("/open/life") + public AjaxResult life(@RequestBody BaseKnife baseKnife) { + // 检查台账是否存在 + BaseKnife baseKnifeOrigin = baseKnifeService.selectBaseKnifeByBaseKnifeId(baseKnife.getBaseKnifeId()); + if (baseKnifeOrigin == null) return AjaxResult.error(); + + // 计算消耗寿命 + int currentLife = baseKnifeOrigin.getKnifeLife() + baseKnifeOrigin.getResetCount() * 100 - baseKnife.getKnifeLife(); + if (currentLife > 0){ + baseKnifeOrigin.setKnifeLife(currentLife % 100); + baseKnifeOrigin.setResetCount(currentLife / 100); + } else { + baseKnifeOrigin.setKnifeLife(0); + baseKnifeOrigin.setResetCount(0); + } + + baseKnifeService.updateBaseKnife(baseKnifeOrigin); + return AjaxResult.success(); + } + @PostMapping("/open/checkForAlignment/{technologyCode}") @ResponseBody public AjaxResult checkForAlignment(@PathVariable String technologyCode) { @@ -147,7 +180,7 @@ public class BaseKnifeController extends BaseController { // List technologyBomList = baseTechnologyBomService.selectBaseTechnologyBomListByProcessCodeList(productionArrangements.getProcessCodes()); List technologyBomList = baseTechnologyBomService.selectBaseTechnologyBomList(baseTechnologyBomWrapper); if (technologyBomList.isEmpty() || technologyBomList.size() == 1 && technologyBomList.get(0).getKnifeCode() == null) - return AjaxResult.error("未检测到工艺bom项"); + throw new RuntimeException("未检测到工艺bom项"); // 构建日志 SysOperLog operLog = new SysOperLog(); @@ -179,7 +212,7 @@ public class BaseKnifeController extends BaseController { if (mdItemTemp == null) { operLog.setJsonResult("物料台账查询错误:" + techBom.getKnifeCode()); operLogService.insertOperlog(operLog); - return AjaxResult.error("物料台账查询错误", techBom.getKnifeCode()); + throw new RuntimeException("物料台账查询错误" + techBom.getKnifeCode()); } baseKnifeWrapper.setMbbBdMrlId(mdItemTemp.getItemId()); @@ -197,7 +230,7 @@ public class BaseKnifeController extends BaseController { if (bomRouteList.isEmpty()) { operLog.setJsonResult("Bom头查询错误:" + techBom.getKnifeCode()); operLogService.insertOperlog(operLog); - return AjaxResult.error("Bom头查询错误", techBom.getKnifeCode()); + throw new RuntimeException("Bom头查询错误" + techBom.getKnifeCode()); } BomRoute bomRoute = bomRouteService.selectBomRouteByBomRouteId(bomRouteList.get(0).getBomRouteId()); @@ -213,14 +246,14 @@ public class BaseKnifeController extends BaseController { if (sitmTempList.isEmpty()) { operLog.setJsonResult("基础物料不足进行组装工具:" + bom.getMdItemCode()); operLogService.insertOperlog(operLog); - return AjaxResult.error("基础物料不足进行组装工具", bom.getMdItemCode()); + throw new RuntimeException("基础物料不足进行组装工具" + bom.getMdItemCode()); } else if (countMap.get(sitmTempList.get(0).getKnifeCode()) == null) { if (sitmTempList.size() >= bom.getStandardDosage() * knifeCount.get()) { countMap.put(sitmTempList.get(0).getKnifeCode(), bom.getStandardDosage() * knifeCount.get()); } else { operLog.setJsonResult("基础物料不足进行组装工具:" + bom.getMdItemCode()); operLogService.insertOperlog(operLog); - return AjaxResult.error("基础物料不足进行组装工具", bom.getMdItemCode()); + throw new RuntimeException("基础物料不足进行组装工具" + bom.getMdItemCode()); } } else { countMap.put(sitmTempList.get(0).getKnifeCode(), countMap.get(sitmTempList.get(0).getKnifeCode()) + bom.getStandardDosage() * knifeCount.get()); @@ -230,18 +263,18 @@ public class BaseKnifeController extends BaseController { if (sitmTempList.size() < countMap.get(sitmTempList.get(0).getKnifeCode()) && countMap.get(sitmTempList.get(0).getKnifeCode()) > bom.getStandardDosage() * knifeCount.get()) { operLog.setJsonResult("基础物料不足进行组装工具:" + techBom.getKnifeCode()); operLogService.insertOperlog(operLog); - return AjaxResult.error("基础物料不足进行组装工具", bom.getMdItemCode()); + throw new RuntimeException("基础物料不足进行组装工具" + bom.getMdItemCode()); } } } else { operLog.setJsonResult("暂无记录整刀bom项:" + techBom.getKnifeCode()); operLogService.insertOperlog(operLog); - return AjaxResult.error("暂无记录整刀bom项", techBom.getKnifeCode()); + throw new RuntimeException("暂无记录整刀bom项" + techBom.getKnifeCode()); } } else { operLog.setJsonResult("基础物料不足:" + techBom.getKnifeCode()); operLogService.insertOperlog(operLog); - return AjaxResult.error("基础物料不足", techBom.getKnifeCode()); + throw new RuntimeException("基础物料不足" + techBom.getKnifeCode()); } } else { // 将物料填入集合 @@ -261,7 +294,7 @@ public class BaseKnifeController extends BaseController { if (bomRouteList.isEmpty()) { operLog.setJsonResult("Bom头查询错误:" + techBom.getKnifeCode()); operLogService.insertOperlog(operLog); - return AjaxResult.error("Bom头查询错误", techBom.getKnifeCode()); + throw new RuntimeException("Bom头查询错误" + techBom.getKnifeCode()); } BomRoute bomRoute = bomRouteService.selectBomRouteByBomRouteId(bomRouteList.get(0).getBomRouteId()); @@ -277,14 +310,14 @@ public class BaseKnifeController extends BaseController { if (sitmTempList.isEmpty()) { operLog.setJsonResult("基础物料不足进行组装工具:" + bom.getMdItemCode()); operLogService.insertOperlog(operLog); - return AjaxResult.error("基础物料不足进行组装工具", bom.getMdItemCode()); + throw new RuntimeException("基础物料不足进行组装工具" + bom.getMdItemCode()); } else if (countMap.get(sitmTempList.get(0).getKnifeCode()) == null) { if (sitmTempList.size() >= bom.getStandardDosage() * knifeCount.get()) { countMap.put(sitmTempList.get(0).getKnifeCode(), bom.getStandardDosage() * knifeCount.get()); } else { operLog.setJsonResult("基础物料不足进行组装工具:" + bom.getMdItemCode()); operLogService.insertOperlog(operLog); - return AjaxResult.error("基础物料不足进行组装工具", bom.getMdItemCode()); + throw new RuntimeException("基础物料不足进行组装工具" + bom.getMdItemCode()); } } else { countMap.put(sitmTempList.get(0).getKnifeCode(), countMap.get(sitmTempList.get(0).getKnifeCode()) + bom.getStandardDosage() * knifeCount.get()); @@ -294,18 +327,18 @@ public class BaseKnifeController extends BaseController { if (sitmTempList.size() < countMap.get(sitmTempList.get(0).getKnifeCode()) && countMap.get(sitmTempList.get(0).getKnifeCode()) > bom.getStandardDosage() * knifeCount.get()) { operLog.setJsonResult("基础物料不足进行组装工具:" + techBom.getKnifeCode()); operLogService.insertOperlog(operLog); - return AjaxResult.error("基础物料不足进行组装工具", bom.getMdItemCode()); + throw new RuntimeException("基础物料不足进行组装工具" + bom.getMdItemCode()); } } } else { operLog.setJsonResult("暂无记录整刀bom项:" + techBom.getKnifeCode()); operLogService.insertOperlog(operLog); - return AjaxResult.error("暂无记录整刀bom项", techBom.getKnifeCode()); + throw new RuntimeException("暂无记录整刀bom项" + techBom.getKnifeCode()); } } else { operLog.setJsonResult("基础物料不足:" + techBom.getKnifeCode()); operLogService.insertOperlog(operLog); - return AjaxResult.error("基础物料不足", techBom.getKnifeCode()); + throw new RuntimeException("基础物料不足" + techBom.getKnifeCode()); } } } @@ -318,425 +351,10 @@ public class BaseKnifeController extends BaseController { } - @PostMapping("/open/productionArrangementsO") - @ResponseBody - @Transactional - public AjaxResult productionArrangementsO(@RequestBody ProductionArrangements productionArrangements) { - // 检查计划单是否已存在 从台账表中寻找 - BaseKnife baseKnifePlan = new BaseKnife(); - baseKnifePlan.setPlanSheet(productionArrangements.getPlanSheet()); - if (!baseKnifeService.selectBaseKnifeList(baseKnifePlan).isEmpty()) - return AjaxResult.error("该计划单已存在,请更换重试"); - // 检查计划单是否已存在 从组装任务表中寻找 - WmsZdTask wmsZdTaskValid = new WmsZdTask(); - wmsZdTaskValid.setPlanSheet(productionArrangements.getPlanSheet()); - if (!zdTaskService.selectWmsZdTaskList(wmsZdTaskValid).isEmpty()) - return AjaxResult.error("该计划单已存在,请更换重试"); - - // 齐套性检查 - AjaxResult ajaxResult = this.checkForAlignment(productionArrangements.getTechnologyCode()); - if (Integer.parseInt(String.valueOf(ajaxResult.get("code"))) != 200) { - return AjaxResult.error(ajaxResult.get("msg").toString(), ajaxResult.get("data")); - } - - // 验证工艺BOM - BaseTechnologyBom baseTechnologyBomWrapper = new BaseTechnologyBom(); - baseTechnologyBomWrapper.setTechnologyCode(productionArrangements.getTechnologyCode()); -// List technologyBomList = baseTechnologyBomService.selectBaseTechnologyBomListByProcessCodeList(productionArrangements.getProcessCodes()); - List technologyBomList = baseTechnologyBomService.selectBaseTechnologyBomList(baseTechnologyBomWrapper); - if (technologyBomList.isEmpty() || technologyBomList.size() == 1 && technologyBomList.get(0).getKnifeCode() == null) - return AjaxResult.error("未检测到工艺bom项"); - - // 记录数据修改 - List baseKnifeOriginList = new ArrayList<>(); - - // 参数列表 - Map params = new HashMap<>(); - params.put("planCode", productionArrangements.getPlanSheet()); - params.put("processCode", productionArrangements.getTechnologyCode()); - params.put("processUnit", productionArrangements.getProcessUnit()); - - // 构建日志 - SysOperLog operLog = new SysOperLog(); - operLog.setTitle("生产准备"); - operLog.setBusinessType(0); - operLog.setRequestMethod("POST"); - operLog.setOperName("上游系统"); - operLog.setOperIp("上游系统"); - operLog.setOperLocation("上游系统"); - operLog.setOperUrl("/mes/md/baseKnife/open/productionArrangements"); - operLog.setMethod("com.ktg.mes.md.controller.BaseKnifeController.productionArrangements()"); - operLog.setOperParam(JSON.toJSONString(params)); - operLog.setStatus(1); - operLog.setOperTime(new Date()); - // 接口返回信息 - String msg = "生产准备验证成功!"; - - // 记录所需物料数量的map - Map countMap = new HashMap<>(); - BaseKnife baseKnifeWrapper = new BaseKnife(); - BomRoute bomRouteTemp = new BomRoute(); - MdItem mdItemTemp = new MdItem(); - - // 遍历工艺bom, 所需要的所有材料 - for (BaseTechnologyBom techBom : technologyBomList) { - // 空则0 - countMap.putIfAbsent(techBom.getKnifeCode(), 0); - - // 台账表中查询工具 :并记录数量 - mdItemTemp = mdItemService.selectMdItemByCode(techBom.getKnifeCode()); - if (mdItemTemp == null) { - baseKnifeOriginList.forEach(baseKnife -> baseKnifeService.updateBaseKnife(baseKnife)); - operLog.setJsonResult("物料台账查询错误:" + techBom.getKnifeCode()); - operLogService.insertOperlog(operLog); - return AjaxResult.error("物料台账查询错误", techBom.getKnifeCode()); - } - - // 查询符合条件的台账 - baseKnifeWrapper.setMbbBdMrlId(mdItemTemp.getItemId()); - baseKnifeWrapper.setIsLocked(0); - List tempList = this.baseKnifeService.selectBaseKnifeList(baseKnifeWrapper); - // 过滤不符合需求的物料 - tempList.removeIf(baseKnife -> baseKnife.getKnifeLife() + baseKnife.getResetCount() * 100 < techBom.getExpendLife()); - AtomicInteger knifeCount = new AtomicInteger(techBom.getKnifeCount()); - - // 如果台账表中不存在,尝试组刀任务查询 - if (tempList.isEmpty()) { - if ("PRODUCT".equals(mdItemTemp.getItemOrProduct())) { - // 查询整刀bom项, 如果不存在说明 为基础物料,或者没有记录此整刀的组装 - bomRouteTemp.setMdItemId(mdItemTemp.getItemId()); - List bomRouteList = bomRouteService.selectBomRouteList(bomRouteTemp); - if (bomRouteList.isEmpty()) { - baseKnifeOriginList.forEach(baseKnife -> baseKnifeService.updateBaseKnife(baseKnife)); - operLog.setJsonResult("Bom头查询错误:" + techBom.getKnifeCode()); - operLogService.insertOperlog(operLog); - return AjaxResult.error("Bom头查询错误", techBom.getKnifeCode()); - } - - // 获取整刀BOM 进行子项遍历 - BomRoute bomRoute = bomRouteService.selectBomRouteByBomRouteId(bomRouteList.get(0).getBomRouteId()); - - if (!bomRoute.getMbbProduBomList().isEmpty()) { - // 遍历bom项, 从台账表中筛选对应基础物料 - for (MbbProduBom bom : bomRoute.getMbbProduBomList()) { - // 查询基础物料。不包含已锁定的 - baseKnifeWrapper.setMbbBdMrlId(bom.getMdItemId()); - baseKnifeWrapper.setIsLocked(0); - List sitmTempList = baseKnifeService.selectBaseKnifeList(baseKnifeWrapper); - - // 判断基础物料是否足够 - if (sitmTempList.isEmpty()) { - baseKnifeOriginList.forEach(baseKnife -> baseKnifeService.updateBaseKnife(baseKnife)); - operLog.setJsonResult("基础物料不足进行组装工具:" + bom.getMdItemCode()); - operLogService.insertOperlog(operLog); - return AjaxResult.error("基础物料不足进行组装工具", bom.getMdItemCode()); - } else if (countMap.get(sitmTempList.get(0).getKnifeCode()) == null) { - if (sitmTempList.size() >= bom.getStandardDosage() * knifeCount.get()) { - countMap.put(sitmTempList.get(0).getKnifeCode(), bom.getStandardDosage() * knifeCount.get()); - } else { - baseKnifeOriginList.forEach(baseKnife -> baseKnifeService.updateBaseKnife(baseKnife)); - operLog.setJsonResult("基础物料不足进行组装工具:" + bom.getMdItemCode()); - operLogService.insertOperlog(operLog); - return AjaxResult.error("基础物料不足进行组装工具", bom.getMdItemCode()); - } - } else { - countMap.put(sitmTempList.get(0).getKnifeCode(), countMap.get(sitmTempList.get(0).getKnifeCode()) + bom.getStandardDosage() * knifeCount.get()); - } - - // 判断基础物料是否充足 - if (sitmTempList.size() < countMap.get(sitmTempList.get(0).getKnifeCode()) && countMap.get(sitmTempList.get(0).getKnifeCode()) > bom.getStandardDosage() * knifeCount.get()) { - baseKnifeOriginList.forEach(baseKnife -> baseKnifeService.updateBaseKnife(baseKnife)); - operLog.setJsonResult("基础物料不足进行组装工具:" + techBom.getKnifeCode()); - operLogService.insertOperlog(operLog); - return AjaxResult.error("基础物料不足进行组装工具", bom.getMdItemCode()); - } - } - } else { - baseKnifeOriginList.forEach(baseKnife -> baseKnifeService.updateBaseKnife(baseKnife)); - operLog.setJsonResult("暂无记录整刀bom项:" + techBom.getKnifeCode()); - operLogService.insertOperlog(operLog); - return AjaxResult.error("暂无记录整刀bom项", techBom.getKnifeCode()); - } - } else { - baseKnifeOriginList.forEach(baseKnife -> baseKnifeService.updateBaseKnife(baseKnife)); - operLog.setJsonResult("基础物料不足:" + techBom.getKnifeCode()); - operLogService.insertOperlog(operLog); - return AjaxResult.error("基础物料不足", techBom.getKnifeCode()); - } - } else { - // 将物料填入集合 - tempList.forEach(item -> { - if (knifeCount.get() > 0 && tempList.size() > countMap.get(item.getKnifeCode())) { - // 更新数量 - knifeCount.getAndDecrement(); - countMap.put(item.getKnifeCode(), countMap.get(item.getKnifeCode()) + 1); - // 记录源数据然后锁定 - baseKnifeOriginList.add(item); - item.setPlanSheet(productionArrangements.getPlanSheet()); - item.setIsLocked(1); - item.setLockedStartTime(techBom.getLockedStartTime()); - item.setLockedEndTime(techBom.getLockedEndTime()); - baseKnifeService.updateBaseKnife(item); - } - }); - if (knifeCount.get() > 0) { - if ("PRODUCT".equals(mdItemTemp.getItemOrProduct())) { - // 查询整刀bom项, 如果不存在说明 为基础物料,或者没有记录此整刀的组装 - bomRouteTemp.setMdItemId(mdItemTemp.getItemId()); - - List bomRouteList = bomRouteService.selectBomRouteList(bomRouteTemp); - if (bomRouteList.isEmpty()) { - baseKnifeOriginList.forEach(baseKnife -> baseKnifeService.updateBaseKnife(baseKnife)); - operLog.setJsonResult("Bom头查询错误:" + techBom.getKnifeCode()); - operLogService.insertOperlog(operLog); - return AjaxResult.error("Bom头查询错误", techBom.getKnifeCode()); - } - - BomRoute bomRoute = bomRouteService.selectBomRouteByBomRouteId(bomRouteList.get(0).getBomRouteId()); - - if (!bomRoute.getMbbProduBomList().isEmpty()) { - // 遍历bom项, 从台账表中筛选对应基础物料 - for (MbbProduBom bom : bomRoute.getMbbProduBomList()) { - // 查询基础物料。不包含已锁定的 - baseKnifeWrapper.setMbbBdMrlId(bom.getMdItemId()); - baseKnifeWrapper.setIsLocked(0); - List sitmTempList = baseKnifeService.selectBaseKnifeList(baseKnifeWrapper); - - if (sitmTempList.isEmpty()) { - baseKnifeOriginList.forEach(baseKnife -> baseKnifeService.updateBaseKnife(baseKnife)); - operLog.setJsonResult("基础物料不足进行组装工具:" + bom.getMdItemCode()); - operLogService.insertOperlog(operLog); - return AjaxResult.error("基础物料不足进行组装工具", bom.getMdItemCode()); - } else if (countMap.get(sitmTempList.get(0).getKnifeCode()) == null) { - if (sitmTempList.size() >= bom.getStandardDosage() * knifeCount.get()) { - countMap.put(sitmTempList.get(0).getKnifeCode(), bom.getStandardDosage() * knifeCount.get()); - } else { - baseKnifeOriginList.forEach(baseKnife -> baseKnifeService.updateBaseKnife(baseKnife)); - operLog.setJsonResult("基础物料不足进行组装工具:" + bom.getMdItemCode()); - operLogService.insertOperlog(operLog); - return AjaxResult.error("基础物料不足进行组装工具", bom.getMdItemCode()); - } - } else { - countMap.put(sitmTempList.get(0).getKnifeCode(), countMap.get(sitmTempList.get(0).getKnifeCode()) + bom.getStandardDosage() * knifeCount.get()); - } - - // 判断基础物料是否充足 - if (sitmTempList.size() < countMap.get(sitmTempList.get(0).getKnifeCode()) && countMap.get(sitmTempList.get(0).getKnifeCode()) > bom.getStandardDosage() * knifeCount.get()) { - baseKnifeOriginList.forEach(baseKnife -> baseKnifeService.updateBaseKnife(baseKnife)); - operLog.setJsonResult("基础物料不足进行组装工具:" + techBom.getKnifeCode()); - operLogService.insertOperlog(operLog); - return AjaxResult.error("基础物料不足进行组装工具", bom.getMdItemCode()); - } - } - } else { - baseKnifeOriginList.forEach(baseKnife -> baseKnifeService.updateBaseKnife(baseKnife)); - operLog.setJsonResult("暂无记录整刀bom项:" + techBom.getKnifeCode()); - operLogService.insertOperlog(operLog); - return AjaxResult.error("暂无记录整刀bom项", techBom.getKnifeCode()); - } - } else { - baseKnifeOriginList.forEach(baseKnife -> baseKnifeService.updateBaseKnife(baseKnife)); - operLog.setJsonResult("基础物料不足:" + techBom.getKnifeCode()); - operLogService.insertOperlog(operLog); - return AjaxResult.error("基础物料不足", techBom.getKnifeCode()); - } - } - } - } - - // 组刀 - MdItem mdItem; - List baseKnifeList; - int count; - List bomList; - for (BaseTechnologyBom techBom : technologyBomList) { - mdItem = mdItemService.selectMdItemByCode(techBom.getKnifeCode()); - count = techBom.getKnifeCount() - countMap.get(techBom.getKnifeCode()); - - // 更新countMap - if (techBom.getKnifeCount() >= countMap.get(techBom.getKnifeCode())) - countMap.put(techBom.getKnifeCode(), 0); - else - countMap.put(techBom.getKnifeCode(), countMap.get(techBom.getKnifeCode()) + techBom.getKnifeCount()); - - // 先从台账表找 - baseKnifeWrapper.setMbbBdMrlId(mdItem.getItemId()); - baseKnifeWrapper.setIsLocked(0); - baseKnifeList = baseKnifeService.selectBaseKnifeList(baseKnifeWrapper); - baseKnifeList.removeIf(baseKnife -> baseKnife.getKnifeLife() + baseKnife.getResetCount() * 100 < techBom.getExpendLife()); - for (BaseKnife wmsBaseKnife : baseKnifeList) { - if (wmsBaseKnife.getKnifeLife() >= techBom.getExpendLife() && count > 0) { - count--; - } - } - - // 整刀不足进行组装 - if (count > 0) { - if ("PRODUCT".equals(mdItem.getItemOrProduct())) { - // 查询整刀bom项, 如果不存在说明 为基础物料,或者没有记录此整刀的组装 - bomRouteTemp.setMdItemId(mdItem.getItemId()); - List bomRouteList = bomRouteService.selectBomRouteList(bomRouteTemp); - if (bomRouteList.isEmpty()) { - baseKnifeOriginList.forEach(baseKnife -> baseKnifeService.updateBaseKnife(baseKnife)); - operLog.setJsonResult("Bom头查询错误:" + techBom.getKnifeCode()); - operLogService.insertOperlog(operLog); - return AjaxResult.error("Bom头查询错误", techBom.getKnifeCode()); - } - - // 判断是否存在组装任务 - WmsZdTask wmsZdTaskWrapper = new WmsZdTask(); - wmsZdTaskWrapper.setPlanSheet(productionArrangements.getPlanSheet()); - wmsZdTaskWrapper.setmProductId(mdItem.getItemId()); - List wmsZdTaskList = zdTaskService.selectWmsZdTaskList(wmsZdTaskWrapper); - if (wmsZdTaskList.isEmpty()){ - // 生成组装任务 - WmsZdTask wmsZdTask = new WmsZdTask(); - wmsZdTask.setmProductId(mdItem.getItemId()); - wmsZdTask.setPlanSheet(productionArrangements.getPlanSheet()); - wmsZdTask.setCode(generateTaskCode(techBom.getProcessCode())); - wmsZdTask.setName(techBom.getProcessName()); - wmsZdTask.setProductIdQty(count); - wmsZdTask.setBomId(bomRouteList.get(0).getBomRouteId()); - wmsZdTask.setCreateTime(DateUtils.getNowDate()); - zdTaskService.insertWmsZdTask(wmsZdTask); - msg = "生产准备验证成功!缺少物料已生成组装任务!"; - } else { - WmsZdTask wmsZdTask = wmsZdTaskList.get(0); - wmsZdTask.setProductIdQty(wmsZdTask.getProductIdQty() + count); - wmsZdTask.setCreateTime(DateUtils.getNowDate()); - msg = "生产准备验证成功!缺少物料已生成组装任务!"; - } - } else { - baseKnifeOriginList.forEach(baseKnife -> baseKnifeService.updateBaseKnife(baseKnife)); - operLog.setJsonResult("缺少BOM项:" + techBom.getKnifeCode()); - operLogService.insertOperlog(operLog); - return AjaxResult.error("缺少BOM项", techBom.getKnifeCode()); - } - } - } - - // 添加生产准备记录 -// productionArrangements.setProcessCode(productionArrangements.getProcessCodes().toString()); - productionArrangements.setTechnologyCode(productionArrangements.getTechnologyCode()); - productionArrangements.setProcessUnit(productionArrangements.getProcessUnit()); - productionArrangements.setStatus(0); - productionArrangements.setStartTime(productionArrangements.getStartTime()); - productionArrangements.setEndTime(productionArrangements.getEndTime()); - productionArrangements.setCreateTime(DateUtils.getNowDate()); - productionArrangementsMapper.insertProductionArrangements(productionArrangements); - - if (!msg.contains("缺少物料已生成组装任务!")) { - // 生成出库计划单 - WmsOutPlan outPlan = new WmsOutPlan(); - outPlan.setPlanCode(productionArrangements.getPlanSheet()); - outPlan.setWmsBusinessTypeId(16L); - outPlan.setPlanState("1"); - outPlan.setPlanType("ZDCK"); - outPlan.setCreateTime(DateUtils.getNowDate()); - wmsOutPlanMapper.insertWmsOutPlan(outPlan); - - String batchNum = "SCZBPC01"; - // 出库任务,进行基础物料的出库 - HashMap>> baseKnifeHashMapMap = new HashMap<>(); - - // 遍历构建map - baseKnifeOriginList.forEach(item -> { - // 判断当前物料主键是否已经被收录 - baseKnifeHashMapMap.computeIfAbsent(item.getMbbBdMrlId(), k -> new HashMap<>()); - - // 判断当前库位编码是否已经被收录 - baseKnifeHashMapMap.get(item.getMbbBdMrlId()).computeIfAbsent(item.getAreaCode(), k -> new ArrayList<>()); - - // 对当前台账对象进行收录 - baseKnifeHashMapMap.get(item.getMbbBdMrlId()).get(item.getAreaCode()).add(item); - - // 出库 - item.setKnifeFineState(2); - baseKnifeService.updateBaseKnife(item); - }); - - // 生成出库计划明细 - WmsOutPlan outPlanTemp = outPlan; - baseKnifeHashMapMap.keySet().forEach(mdItemId -> { - MdItem mdItemOutPlan = mdItemService.selectMdItemById(mdItemId); - // 根据库位编码遍历 - baseKnifeHashMapMap.get(mdItemId).keySet().forEach(areaCode -> { - // 获得库位对象 - WmStorageArea wmStorageAreaOutPlan = wmStorageAreaService.selectWmStorageAreaByAreaCode(areaCode); - - WmsOutPlanDetail outPlanDetail = new WmsOutPlanDetail(); - outPlanDetail.setWmsOutPlanId(outPlanTemp.getWmsOutPlanId()); - outPlanDetail.setMdItemId(mdItemId); - outPlanDetail.setMdItemCode(mdItemOutPlan.getItemCode()); - outPlanDetail.setMdItemName(mdItemOutPlan.getItemName()); - outPlanDetail.setMdItemUnit(mdItemOutPlan.getUnitName()); - outPlanDetail.setPlannedQuantity(baseKnifeHashMapMap.get(mdItemId).get(areaCode).size()); - outPlanDetail.setRealQuantity(baseKnifeHashMapMap.get(mdItemId).get(areaCode).size()); - outPlanDetail.setDetailBatchNum(batchNum); - outPlanDetail.setWmStorageAreaId(wmStorageAreaOutPlan.getAreaId()); - outPlanDetail.setWmStorageAreaCode(wmStorageAreaOutPlan.getAreaCode()); - outPlanDetail.setWmStorageAreaName(wmStorageAreaOutPlan.getAreaName()); - outPlanDetail.setDetailState("1"); - outPlanDetail.setCreateTime(DateUtils.getNowDate()); - wmsOutPlanMapper.insertWmsOutPlanDetail(outPlanDetail); - - // 遍历台账对象 - baseKnifeHashMapMap.get(mdItemId).get(areaCode).forEach(item -> { - // 构建出库计划明细实体 - WmsOutPlanDetailEntity wmsOutPlanDetailEntity = new WmsOutPlanDetailEntity(); - wmsOutPlanDetailEntity.setWmsOutPlanDetailId(outPlanDetail.getWmsOutPlanDetailId()); - wmsOutPlanDetailEntity.setBaseKnifeId(item.getBaseKnifeId()); - wmsOutPlanDetailEntity.setAreaCode(item.getAreaCode()); - wmsOutPlanDetailEntity.setItemOrProduct(item.getItemOrProduct()); - wmsOutPlanDetailEntity.setKnifeCode(item.getKnifeCode()); - wmsOutPlanDetailEntity.setKnifeName(item.getKnifeName()); - wmsOutPlanDetailEntity.setPlanSheet(item.getPlanSheet()); - wmsOutPlanDetailEntity.setKnifeLife(item.getKnifeLife()); - wmsOutPlanDetailEntity.setResetCount(item.getResetCount()); - wmsOutPlanDetailEntity.setKnifeUnit(item.getKnifeUnit()); - wmsOutPlanDetailEntity.setSafeStock(item.getKnifeType()); - wmsOutPlanDetailEntity.setStandardQuantity(item.getStandardQuantity()); - wmsOutPlanDetailEntity.setCreateTime(DateUtils.getNowDate()); - wmsOutPlanDetailEntityMapper.insertWmsOutPlanDetailEntity(wmsOutPlanDetailEntity); - }); - - // 生成出库任务 - WmsOutTask wmsOutTask = new WmsOutTask(); - wmsOutTask.setWmsOutPlanId(outPlanTemp.getWmsOutPlanId()); - wmsOutTask.setWmsOutPlanCode(outPlanTemp.getPlanCode()); - wmsOutTask.setWmsOutPlanDetailId(outPlanDetail.getWmsOutPlanDetailId()); - // 出库类型 12组刀出库 - wmsOutTask.setWmsBusinessTypeId(12L); - wmsOutTask.setTaskCode(generateTaskCode("CKT")); - 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("0"); - wmsOutTask.setRecipientUsername(""); - wmsOutTask.setCreateTime(DateUtils.getNowDate()); - wmsOutTaskMapper.insertWmsOutTask(wmsOutTask); - }); - }); - - productionArrangements.setStatus(1); - productionArrangementsMapper.updateProductionArrangements(productionArrangements); - } - - operLog.setJsonResult(msg); - operLog.setStatus(0); - operLogService.insertOperlog(operLog); - return AjaxResult.success(msg); - } - @PostMapping("/open/productionArrangements") @ResponseBody @Transactional - public AjaxResult productionArrangements(@RequestBody ProductionArrangements productionArrangements) { + public AjaxResult productionArrangements(@RequestBody ProductionArrangements productionArrangements) throws IOException { // 检查计划单是否已存在 从台账表中寻找 BaseKnife baseKnifePlan = new BaseKnife(); baseKnifePlan.setPlanSheet(productionArrangements.getPlanSheet()); @@ -747,6 +365,11 @@ public class BaseKnifeController extends BaseController { wmsZdTaskValid.setPlanSheet(productionArrangements.getPlanSheet()); if (!zdTaskService.selectWmsZdTaskList(wmsZdTaskValid).isEmpty()) return AjaxResult.error("该计划单已存在,请更换重试"); + // 检查计划单是否已存在 从物料预订表中寻找 + BaseKnifeLocked baseKnifeLockedValid = new BaseKnifeLocked(); + baseKnifeLockedValid.setPlanSheet(productionArrangements.getPlanSheet()); + if (!baseKnifeLockedMapper.selectBaseKnifeLockedList(baseKnifeLockedValid).isEmpty()) + return AjaxResult.error("该计划单已存在,请更换重试"); // 验证工艺BOM是否存在 BaseTechnologyBom baseTechnologyBomWrapper = new BaseTechnologyBom(); @@ -755,7 +378,7 @@ public class BaseKnifeController extends BaseController { if (technologyBomList.isEmpty() || technologyBomList.size() == 1 && technologyBomList.get(0).getKnifeCode() == null) return AjaxResult.error("未检测到工艺bom项"); - // 记录数据修改 + // 记录已经列入订单需求的物料数据 List baseKnifeOriginList = new ArrayList<>(); // 参数列表 @@ -780,8 +403,9 @@ public class BaseKnifeController extends BaseController { // 接口返回信息 String msg = "生产准备验证成功!"; - // 记录所符合需求的物料数量 map + // 记录所符合需求的物料数量 map 和 需要组装的物料数量 Map countMap = new HashMap<>(); + Map zdTaskMap = new HashMap<>(); BaseKnife baseKnifeWrapper = new BaseKnife(); BomRoute bomRouteTemp = new BomRoute(); MdItem mdItemTemp = new MdItem(); @@ -790,14 +414,14 @@ public class BaseKnifeController extends BaseController { for (BaseTechnologyBom techBom : technologyBomList) { // 空则0 countMap.putIfAbsent(techBom.getKnifeCode(), 0); + zdTaskMap.putIfAbsent(techBom.getKnifeCode(), 0); - // 台账表中查询工具 :并记录数量 + // 查询物料编码是否存在 mdItemTemp = mdItemService.selectMdItemByCode(techBom.getKnifeCode()); if (mdItemTemp == null) { - baseKnifeOriginList.forEach(baseKnife -> baseKnifeService.updateBaseKnife(baseKnife)); operLog.setJsonResult("物料台账查询错误:" + techBom.getKnifeCode()); operLogService.insertOperlog(operLog); - return AjaxResult.error("物料台账查询错误", techBom.getKnifeCode()); + throw new RuntimeException("物料台账查询错误" + techBom.getKnifeCode()); } // 查询符合条件的台账 锁定状态为 0 空闲中 @@ -806,7 +430,7 @@ public class BaseKnifeController extends BaseController { List tempList = this.baseKnifeService.selectBaseKnifeList(baseKnifeWrapper); // 过滤不符合需求的物料 当前寿命小于工艺消耗定额 if (Objects.equals("PRODUCT", mdItemTemp.getItemOrProduct())) tempList.removeIf(baseKnife -> baseKnife.getKnifeLife() + baseKnife.getResetCount() * 100 < techBom.getExpendLife()); - // 记录需要的物料数量 + // 记录此项工艺需要的物料数量 AtomicInteger knifeCount = new AtomicInteger(techBom.getKnifeCount()); // 如果台账表中不存在,尝试组刀任务查询 @@ -816,27 +440,110 @@ public class BaseKnifeController extends BaseController { bomRouteTemp.setMdItemId(mdItemTemp.getItemId()); List bomRouteList = bomRouteService.selectBomRouteList(bomRouteTemp); if (bomRouteList.isEmpty()) { - baseKnifeOriginList.forEach(baseKnife -> baseKnifeService.updateBaseKnife(baseKnife)); operLog.setJsonResult("Bom头查询错误:" + techBom.getKnifeCode()); operLogService.insertOperlog(operLog); - return AjaxResult.error("Bom头查询错误", techBom.getKnifeCode()); + throw new RuntimeException("Bom头查询错误" + techBom.getKnifeCode()); } // 获取整刀BOM 进行子项遍历 BomRoute bomRoute = bomRouteService.selectBomRouteByBomRouteId(bomRouteList.get(0).getBomRouteId()); if (!bomRoute.getMbbProduBomList().isEmpty()) { - // 遍历bom项, 从台账表中筛选对应基础物料 - for (MbbProduBom bom : bomRoute.getMbbProduBomList()) { - // 查询基础物料。不包含已锁定的 - baseKnifeWrapper.setMbbBdMrlId(bom.getMdItemId()); - baseKnifeWrapper.setIsLocked(0); - List sitmTempList = baseKnifeService.selectBaseKnifeList(baseKnifeWrapper); - // 判断基础物料是否足够 - if (sitmTempList.isEmpty()) { + // 记录需要组装的数量 和 能够组装的数量 + int knifeNeedQuantity = zdTaskMap.get(techBom.getKnifeCode()) + techBom.getKnifeCount(); + int knifeHaveQuantity = this.getBomZdTaskQuantity(bomRoute, knifeNeedQuantity); + + // 如果组装出来的数量不够 去预订其他订单中的 + if (knifeHaveQuantity < knifeNeedQuantity) { + + // 当前库内无符合需求的物料, 尝试查询已经在订单中的刀但作业时间不同 + List lockedBaseKnifeIds = this.getLockedBaseKnifeId(mdItemTemp.getItemCode(), productionArrangements, knifeNeedQuantity - knifeHaveQuantity, techBom.getExpendLife()); + if (!lockedBaseKnifeIds.isEmpty()) { + lockedBaseKnifeIds.forEach(lockedBaseKnifeId -> { + BaseKnife lockedBaseKnife = baseKnifeService.selectBaseKnifeByBaseKnifeId(lockedBaseKnifeId); + // 新增一条台账锁定记录 预订台账 + BaseKnifeLocked baseKnifeLocked = new BaseKnifeLocked(); + baseKnifeLocked.setPlanSheet(productionArrangements.getPlanSheet()); + baseKnifeLocked.setStatus(0); // 状态未完成 + baseKnifeLocked.setLockedStartTime(productionArrangements.getStartTime()); + baseKnifeLocked.setLockedEndTime(productionArrangements.getEndTime()); + baseKnifeLocked.setItemCode(lockedBaseKnife.getKnifeCode()); + baseKnifeLocked.setBaseKnifeId(lockedBaseKnife.getBaseKnifeId()); + baseKnifeLocked.setExpendLife(techBom.getExpendLife()); // 消耗定额,提供给预订时计算寿命是否符合需求 + baseKnifeLockedMapper.insertBaseKnifeLocked(baseKnifeLocked); + }); + + // 更新需要组装的数量 和 生产准备中已准备好的数量 + zdTaskMap.put(techBom.getKnifeCode(), knifeHaveQuantity); + countMap.put(techBom.getKnifeCode(), countMap.get(techBom.getKnifeCode()) + techBom.getKnifeCount()); + } else { + operLog.setJsonResult("基础物料不足进行组装工具:" + techBom.getKnifeCode()); + operLogService.insertOperlog(operLog); + throw new RuntimeException("基础物料不足进行组装工具" + techBom.getKnifeCode()); + } + } else { + // 更新需要组装的数量 和 生产准备中已准备好的数量 + zdTaskMap.put(techBom.getKnifeCode(), knifeHaveQuantity); + countMap.put(techBom.getKnifeCode(), countMap.get(techBom.getKnifeCode()) + techBom.getKnifeCount()); + } + } else { + operLog.setJsonResult("暂无记录整刀bom项:" + techBom.getKnifeCode()); + operLogService.insertOperlog(operLog); + throw new RuntimeException("暂无记录整刀bom项" + techBom.getKnifeCode()); + } + } else { + operLog.setJsonResult("基础物料不足:" + techBom.getKnifeCode()); + operLogService.insertOperlog(operLog); + throw new RuntimeException("基础物料不足" + techBom.getKnifeCode()); + } + } else { + // 将物料填入集合 + tempList.forEach(item -> { + if (knifeCount.get() > 0 && tempList.size() > countMap.get(item.getKnifeCode())) { + // 更新数量 + knifeCount.getAndDecrement(); + countMap.put(item.getKnifeCode(), countMap.get(item.getKnifeCode()) + 1); + // 锁定 + item.setPlanSheet(productionArrangements.getPlanSheet()); + item.setIsLocked(1); // 锁定整刀台账 + item.setLockedStartTime(productionArrangements.getStartTime()); + item.setLockedEndTime(productionArrangements.getEndTime()); + baseKnifeService.updateBaseKnife(item); + + // 利用预留字段来记录锁定的整刀的消耗定额 + item.setAttr1(Long.valueOf(techBom.getExpendLife())); + + // 记录锁定记录 + baseKnifeOriginList.add(item); + } + }); + if (knifeCount.get() > 0) { + if ("PRODUCT".equals(mdItemTemp.getItemOrProduct())) { + // 查询整刀bom项, 如果不存在说明 为基础物料,或者没有记录此整刀的组装 + bomRouteTemp.setMdItemId(mdItemTemp.getItemId()); + + List bomRouteList = bomRouteService.selectBomRouteList(bomRouteTemp); + if (bomRouteList.isEmpty()) { + operLog.setJsonResult("Bom头查询错误:" + techBom.getKnifeCode()); + operLogService.insertOperlog(operLog); + throw new RuntimeException("Bom头查询错误:" + techBom.getKnifeCode()); + } + + // 获取整刀BOM 进行子项遍历 + BomRoute bomRoute = bomRouteService.selectBomRouteByBomRouteId(bomRouteList.get(0).getBomRouteId()); + + if (!bomRoute.getMbbProduBomList().isEmpty()) { + + // 记录需要组装的数量 和 能够组装的数量 + int knifeNeedQuantity = zdTaskMap.get(techBom.getKnifeCode()) + knifeCount.get(); + int knifeHaveQuantity = this.getBomZdTaskQuantity(bomRoute, knifeNeedQuantity); + + // 如果组装出来的数量不够 去预订其他订单中的 + if (knifeHaveQuantity < knifeNeedQuantity) { + // 当前库内无符合需求的物料, 尝试查询已经在订单中的刀但作业时间不同 - List lockedBaseKnifeIds = this.getLockedBaseKnifeId(mdItemTemp.getItemCode(), productionArrangements, knifeCount.get(), techBom.getExpendLife()); + List lockedBaseKnifeIds = this.getLockedBaseKnifeId(mdItemTemp.getItemCode(), productionArrangements, knifeNeedQuantity - knifeHaveQuantity, techBom.getExpendLife()); if (!lockedBaseKnifeIds.isEmpty()) { lockedBaseKnifeIds.forEach(lockedBaseKnifeId -> { BaseKnife lockedBaseKnife = baseKnifeService.selectBaseKnifeByBaseKnifeId(lockedBaseKnifeId); @@ -850,278 +557,58 @@ public class BaseKnifeController extends BaseController { baseKnifeLocked.setBaseKnifeId(lockedBaseKnife.getBaseKnifeId()); baseKnifeLocked.setExpendLife(techBom.getExpendLife()); baseKnifeLockedMapper.insertBaseKnifeLocked(baseKnifeLocked); - - // 生产准备中的物料更新数量 - countMap.put(techBom.getKnifeCode(), countMap.get(techBom.getKnifeCode()) + 1); }); - } else { - baseKnifeOriginList.forEach(baseKnife -> baseKnifeService.updateBaseKnife(baseKnife)); - operLog.setJsonResult("基础物料不足进行组装工具:" + bom.getMdItemCode()); - operLogService.insertOperlog(operLog); - return AjaxResult.error("基础物料不足进行组装工具", bom.getMdItemCode()); - } - } else if (countMap.get(sitmTempList.get(0).getKnifeCode()) == null) { - if (sitmTempList.size() >= bom.getStandardDosage() * knifeCount.get()) { - countMap.put(sitmTempList.get(0).getKnifeCode(), bom.getStandardDosage() * knifeCount.get()); - } else { - // 当前库内无符合需求的物料, 尝试查询已经在订单中的刀但作业时间不同 - List lockedBaseKnifeIds = new ArrayList<>(); - // 判断当前物料能组成几把刀, 不够的刀从锁定中的拿 - while (knifeCount.getAndDecrement() > 0) { - if (sitmTempList.size() >= bom.getStandardDosage() * knifeCount.get()) { - lockedBaseKnifeIds = this.getLockedBaseKnifeId(mdItemTemp.getItemCode(), productionArrangements, techBom.getKnifeCount() - knifeCount.get(), techBom.getExpendLife()); - break; - } - } - if (!lockedBaseKnifeIds.isEmpty()) { - lockedBaseKnifeIds.forEach(lockedBaseKnifeId -> { - BaseKnife lockedBaseKnife = baseKnifeService.selectBaseKnifeByBaseKnifeId(lockedBaseKnifeId); - // 新增一条台账锁定记录 预订台账 - BaseKnifeLocked baseKnifeLocked = new BaseKnifeLocked(); - baseKnifeLocked.setPlanSheet(productionArrangements.getPlanSheet()); - baseKnifeLocked.setStatus(0); - baseKnifeLocked.setLockedStartTime(productionArrangements.getStartTime()); - baseKnifeLocked.setLockedEndTime(productionArrangements.getEndTime()); - baseKnifeLocked.setItemCode(lockedBaseKnife.getKnifeCode()); - baseKnifeLocked.setBaseKnifeId(lockedBaseKnife.getBaseKnifeId()); - baseKnifeLocked.setExpendLife(techBom.getExpendLife()); - baseKnifeLockedMapper.insertBaseKnifeLocked(baseKnifeLocked); - // 生产准备中的物料更新数量 - countMap.put(techBom.getKnifeCode(), countMap.get(techBom.getKnifeCode()) + 1); - }); - } else { - baseKnifeOriginList.forEach(baseKnife -> baseKnifeService.updateBaseKnife(baseKnife)); - operLog.setJsonResult("基础物料不足进行组装工具:" + bom.getMdItemCode()); - operLogService.insertOperlog(operLog); - return AjaxResult.error("基础物料不足进行组装工具", bom.getMdItemCode()); - } + // 更新需要组装的数量 和 生产准备中已准备好的数量 + zdTaskMap.put(techBom.getKnifeCode(), knifeHaveQuantity); + countMap.put(techBom.getKnifeCode(), countMap.get(techBom.getKnifeCode()) + techBom.getKnifeCount()); + } else { + operLog.setJsonResult("基础物料不足进行组装工具:" + techBom.getKnifeCode()); + operLogService.insertOperlog(operLog); + throw new RuntimeException("基础物料不足进行组装工具" + techBom.getKnifeCode()); } } else { - countMap.put(sitmTempList.get(0).getKnifeCode(), countMap.get(sitmTempList.get(0).getKnifeCode()) + bom.getStandardDosage() * knifeCount.get()); - } - -// // 判断基础物料是否充足 -// if (sitmTempList.size() < countMap.get(sitmTempList.get(0).getKnifeCode()) && countMap.get(sitmTempList.get(0).getKnifeCode()) > bom.getStandardDosage() * knifeCount.get()) { -// baseKnifeOriginList.forEach(baseKnife -> baseKnifeService.updateBaseKnife(baseKnife)); -// operLog.setJsonResult("基础物料不足进行组装工具:" + techBom.getKnifeCode()); -// operLogService.insertOperlog(operLog); -// return AjaxResult.error("基础物料不足进行组装工具", bom.getMdItemCode()); -// } - } - } else { - baseKnifeOriginList.forEach(baseKnife -> baseKnifeService.updateBaseKnife(baseKnife)); - operLog.setJsonResult("暂无记录整刀bom项:" + techBom.getKnifeCode()); - operLogService.insertOperlog(operLog); - return AjaxResult.error("暂无记录整刀bom项", techBom.getKnifeCode()); - } - } else { - baseKnifeOriginList.forEach(baseKnife -> baseKnifeService.updateBaseKnife(baseKnife)); - operLog.setJsonResult("基础物料不足:" + techBom.getKnifeCode()); - operLogService.insertOperlog(operLog); - return AjaxResult.error("基础物料不足", techBom.getKnifeCode()); - } - } else { - // 将物料填入集合 - tempList.forEach(item -> { - if (knifeCount.get() > 0 && tempList.size() > countMap.get(item.getKnifeCode())) { - // 更新数量 - knifeCount.getAndDecrement(); - countMap.put(item.getKnifeCode(), countMap.get(item.getKnifeCode()) + 1); - // 记录源数据然后锁定 - baseKnifeOriginList.add(item); - item.setPlanSheet(productionArrangements.getPlanSheet()); - item.setIsLocked(1); - item.setLockedStartTime(productionArrangements.getStartTime()); - item.setLockedEndTime(productionArrangements.getEndTime()); - baseKnifeService.updateBaseKnife(item); - } - }); - if (knifeCount.get() > 0) { - if ("PRODUCT".equals(mdItemTemp.getItemOrProduct())) { - // 查询整刀bom项, 如果不存在说明 为基础物料,或者没有记录此整刀的组装 - bomRouteTemp.setMdItemId(mdItemTemp.getItemId()); - - List bomRouteList = bomRouteService.selectBomRouteList(bomRouteTemp); - if (bomRouteList.isEmpty()) { - baseKnifeOriginList.forEach(baseKnife -> baseKnifeService.updateBaseKnife(baseKnife)); - operLog.setJsonResult("Bom头查询错误:" + techBom.getKnifeCode()); - operLogService.insertOperlog(operLog); - return AjaxResult.error("Bom头查询错误", techBom.getKnifeCode()); - } - - BomRoute bomRoute = bomRouteService.selectBomRouteByBomRouteId(bomRouteList.get(0).getBomRouteId()); - - if (!bomRoute.getMbbProduBomList().isEmpty()) { - // 遍历bom项, 从台账表中筛选对应基础物料 - for (MbbProduBom bom : bomRoute.getMbbProduBomList()) { - // 查询基础物料。不包含已锁定的 - baseKnifeWrapper.setMbbBdMrlId(bom.getMdItemId()); - baseKnifeWrapper.setIsLocked(0); - List sitmTempList = baseKnifeService.selectBaseKnifeList(baseKnifeWrapper); - - if (sitmTempList.isEmpty()) { - List lockedBaseKnifeIds = this.getLockedBaseKnifeId(mdItemTemp.getItemCode(), productionArrangements, knifeCount.get(), techBom.getExpendLife()); - if (!lockedBaseKnifeIds.isEmpty()) { - lockedBaseKnifeIds.forEach(lockedBaseKnifeId -> { - BaseKnife lockedBaseKnife = baseKnifeService.selectBaseKnifeByBaseKnifeId(lockedBaseKnifeId); - // 新增一条台账锁定记录 预订台账 - BaseKnifeLocked baseKnifeLocked = new BaseKnifeLocked(); - baseKnifeLocked.setPlanSheet(productionArrangements.getPlanSheet()); - baseKnifeLocked.setStatus(0); - baseKnifeLocked.setLockedStartTime(productionArrangements.getStartTime()); - baseKnifeLocked.setLockedEndTime(productionArrangements.getEndTime()); - baseKnifeLocked.setItemCode(lockedBaseKnife.getKnifeCode()); - baseKnifeLocked.setBaseKnifeId(lockedBaseKnife.getBaseKnifeId()); - baseKnifeLocked.setExpendLife(techBom.getExpendLife()); - baseKnifeLockedMapper.insertBaseKnifeLocked(baseKnifeLocked); - - // 生产准备中的物料更新数量 - countMap.put(techBom.getKnifeCode(), countMap.get(techBom.getKnifeCode()) + 1); - }); - } else { - baseKnifeOriginList.forEach(baseKnife -> baseKnifeService.updateBaseKnife(baseKnife)); - operLog.setJsonResult("基础物料不足进行组装工具:" + bom.getMdItemCode()); - operLogService.insertOperlog(operLog); - return AjaxResult.error("基础物料不足进行组装工具", bom.getMdItemCode()); - } - } else if (countMap.get(sitmTempList.get(0).getKnifeCode()) == null) { - if (sitmTempList.size() >= bom.getStandardDosage() * knifeCount.get()) { - countMap.put(sitmTempList.get(0).getKnifeCode(), bom.getStandardDosage() * knifeCount.get()); - } else { - List lockedBaseKnifeIds = new ArrayList<>(); - // 判断当前物料能组成几把刀, 不够的刀从锁定中的拿 - while (knifeCount.getAndDecrement() > 0) { - if (sitmTempList.size() >= bom.getStandardDosage() * knifeCount.get()) { - lockedBaseKnifeIds = this.getLockedBaseKnifeId(mdItemTemp.getItemCode(), productionArrangements, techBom.getKnifeCount() - knifeCount.get(), techBom.getExpendLife()); - break; - } - } - if (!lockedBaseKnifeIds.isEmpty()) { - lockedBaseKnifeIds.forEach(lockedBaseKnifeId -> { - BaseKnife lockedBaseKnife = baseKnifeService.selectBaseKnifeByBaseKnifeId(lockedBaseKnifeId); - // 新增一条台账锁定记录 预订台账 - BaseKnifeLocked baseKnifeLocked = new BaseKnifeLocked(); - baseKnifeLocked.setPlanSheet(productionArrangements.getPlanSheet()); - baseKnifeLocked.setStatus(0); - baseKnifeLocked.setLockedStartTime(productionArrangements.getStartTime()); - baseKnifeLocked.setLockedEndTime(productionArrangements.getEndTime()); - baseKnifeLocked.setItemCode(lockedBaseKnife.getKnifeCode()); - baseKnifeLocked.setBaseKnifeId(lockedBaseKnife.getBaseKnifeId()); - baseKnifeLocked.setExpendLife(techBom.getExpendLife()); - baseKnifeLockedMapper.insertBaseKnifeLocked(baseKnifeLocked); - - // 生产准备中的物料更新数量 - countMap.put(techBom.getKnifeCode(), countMap.get(techBom.getKnifeCode()) + 1); - }); - } else { - baseKnifeOriginList.forEach(baseKnife -> baseKnifeService.updateBaseKnife(baseKnife)); - operLog.setJsonResult("基础物料不足进行组装工具:" + bom.getMdItemCode()); - operLogService.insertOperlog(operLog); - return AjaxResult.error("基础物料不足进行组装工具", bom.getMdItemCode()); - } - } - } else { - countMap.put(sitmTempList.get(0).getKnifeCode(), countMap.get(sitmTempList.get(0).getKnifeCode()) + bom.getStandardDosage() * knifeCount.get()); - } - -// // 判断基础物料是否充足 -// if (sitmTempList.size() < countMap.get(sitmTempList.get(0).getKnifeCode()) && countMap.get(sitmTempList.get(0).getKnifeCode()) > bom.getStandardDosage() * knifeCount.get()) { -// baseKnifeOriginList.forEach(baseKnife -> baseKnifeService.updateBaseKnife(baseKnife)); -// operLog.setJsonResult("基础物料不足进行组装工具:" + techBom.getKnifeCode()); -// operLogService.insertOperlog(operLog); -// return AjaxResult.error("基础物料不足进行组装工具", bom.getMdItemCode()); -// } + // 更新需要组装的数量 和 生产准备中已准备好的数量 + zdTaskMap.put(techBom.getKnifeCode(), knifeHaveQuantity); + countMap.put(techBom.getKnifeCode(), countMap.get(techBom.getKnifeCode()) + knifeCount.get()); } } else { - baseKnifeOriginList.forEach(baseKnife -> baseKnifeService.updateBaseKnife(baseKnife)); operLog.setJsonResult("暂无记录整刀bom项:" + techBom.getKnifeCode()); operLogService.insertOperlog(operLog); - return AjaxResult.error("暂无记录整刀bom项", techBom.getKnifeCode()); + throw new RuntimeException("暂无记录整刀bom项" + techBom.getKnifeCode()); } } else { - baseKnifeOriginList.forEach(baseKnife -> baseKnifeService.updateBaseKnife(baseKnife)); operLog.setJsonResult("基础物料不足:" + techBom.getKnifeCode()); operLogService.insertOperlog(operLog); - return AjaxResult.error("基础物料不足", techBom.getKnifeCode()); + throw new RuntimeException("基础物料不足" + techBom.getKnifeCode()); } } } } // 组刀 - MdItem mdItem; - List baseKnifeList; - int count; - List bomList; - for (BaseTechnologyBom techBom : technologyBomList) { - mdItem = mdItemService.selectMdItemByCode(techBom.getKnifeCode()); - count = techBom.getKnifeCount() - countMap.get(techBom.getKnifeCode()); + for (Map.Entry zdTaskItem : zdTaskMap.entrySet()){ + if (zdTaskItem.getValue() != 0){ + MdItem mdItem = mdItemService.selectMdItemByCode(zdTaskItem.getKey()); + BomRoute bomRouteWrapper = new BomRoute(); + bomRouteWrapper.setMdItemId(mdItem.getItemId()); + List bomRouteList = bomRouteService.selectBomRouteList(bomRouteWrapper); - // 更新countMap - if (techBom.getKnifeCount() >= countMap.get(techBom.getKnifeCode())) - countMap.put(techBom.getKnifeCode(), 0); - else - countMap.put(techBom.getKnifeCode(), countMap.get(techBom.getKnifeCode()) + techBom.getKnifeCount()); - - // 先从台账表找 - baseKnifeWrapper.setMbbBdMrlId(mdItem.getItemId()); - baseKnifeWrapper.setIsLocked(0); - baseKnifeList = baseKnifeService.selectBaseKnifeList(baseKnifeWrapper); - if (Objects.equals("PRODUCT", mdItem.getItemOrProduct())) baseKnifeList.removeIf(baseKnife -> baseKnife.getKnifeLife() + baseKnife.getResetCount() * 100 < techBom.getExpendLife()); - for (BaseKnife wmsBaseKnife : baseKnifeList) { - if (wmsBaseKnife.getKnifeLife() >= techBom.getExpendLife() && count > 0) { - count--; - } - } - - // 整刀不足进行组装 - if (count > 0) { - if ("PRODUCT".equals(mdItem.getItemOrProduct())) { - // 查询整刀bom项, 如果不存在说明 为基础物料,或者没有记录此整刀的组装 - bomRouteTemp.setMdItemId(mdItem.getItemId()); - List bomRouteList = bomRouteService.selectBomRouteList(bomRouteTemp); - if (bomRouteList.isEmpty()) { - baseKnifeOriginList.forEach(baseKnife -> baseKnifeService.updateBaseKnife(baseKnife)); - operLog.setJsonResult("Bom头查询错误:" + techBom.getKnifeCode()); - operLogService.insertOperlog(operLog); - return AjaxResult.error("Bom头查询错误", techBom.getKnifeCode()); - } - - // 判断是否存在组装任务 - WmsZdTask wmsZdTaskWrapper = new WmsZdTask(); - wmsZdTaskWrapper.setPlanSheet(productionArrangements.getPlanSheet()); - wmsZdTaskWrapper.setmProductId(mdItem.getItemId()); - List wmsZdTaskList = zdTaskService.selectWmsZdTaskList(wmsZdTaskWrapper); - if (wmsZdTaskList.isEmpty()){ - // 生成组装任务 - WmsZdTask wmsZdTask = new WmsZdTask(); - wmsZdTask.setmProductId(mdItem.getItemId()); - wmsZdTask.setPlanSheet(productionArrangements.getPlanSheet()); - wmsZdTask.setCode(generateTaskCode(techBom.getProcessCode())); - wmsZdTask.setName(techBom.getProcessName()); - wmsZdTask.setProductIdQty(count); - wmsZdTask.setBomId(bomRouteList.get(0).getBomRouteId()); - wmsZdTask.setCreateTime(DateUtils.getNowDate()); - zdTaskService.insertWmsZdTask(wmsZdTask); - msg = "生产准备验证成功!缺少物料已生成组装任务!"; - } else { - WmsZdTask wmsZdTask = wmsZdTaskList.get(0); - wmsZdTask.setProductIdQty(wmsZdTask.getProductIdQty() + count); - wmsZdTask.setCreateTime(DateUtils.getNowDate()); - msg = "生产准备验证成功!缺少物料已生成组装任务!"; - } - } else { - baseKnifeOriginList.forEach(baseKnife -> baseKnifeService.updateBaseKnife(baseKnife)); - operLog.setJsonResult("缺少BOM项:" + techBom.getKnifeCode()); - operLogService.insertOperlog(operLog); - return AjaxResult.error("缺少BOM项", techBom.getKnifeCode()); - } + // 生成组装任务 + WmsZdTask wmsZdTask = new WmsZdTask(); + wmsZdTask.setmProductId(mdItem.getItemId()); + wmsZdTask.setPlanSheet(productionArrangements.getPlanSheet()); + wmsZdTask.setCode(generateTaskCode(productionArrangements.getTechnologyCode())); + wmsZdTask.setName(productionArrangements.getPlanSheet()); + wmsZdTask.setProductIdQty(zdTaskItem.getValue()); + wmsZdTask.setBomId(bomRouteList.get(0).getBomRouteId()); + wmsZdTask.setCreateTime(DateUtils.getNowDate()); + zdTaskService.insertWmsZdTask(wmsZdTask); + msg = "生产准备验证成功!缺少物料已生成组装任务!"; } } // 添加生产准备记录 -// productionArrangements.setProcessCode(productionArrangements.getProcessCodes().toString()); productionArrangements.setTechnologyCode(productionArrangements.getTechnologyCode()); productionArrangements.setProcessUnit(productionArrangements.getProcessUnit()); productionArrangements.setStatus(0); @@ -1155,9 +642,17 @@ public class BaseKnifeController extends BaseController { // 对当前台账对象进行收录 baseKnifeHashMapMap.get(item.getMbbBdMrlId()).get(item.getAreaCode()).add(item); - // 出库 - item.setKnifeFineState(2); - baseKnifeService.updateBaseKnife(item); + // 新增一条台账锁定记录 预订台账 + BaseKnifeLocked baseKnifeLocked = new BaseKnifeLocked(); + baseKnifeLocked.setPlanSheet(productionArrangements.getPlanSheet()); + baseKnifeLocked.setStatus(0); + baseKnifeLocked.setLockedStartTime(productionArrangements.getStartTime()); + baseKnifeLocked.setLockedEndTime(productionArrangements.getEndTime()); + baseKnifeLocked.setItemCode(item.getKnifeCode()); + baseKnifeLocked.setBaseKnifeId(item.getBaseKnifeId()); + // 利用隐藏字段记录整刀的消耗定额 + baseKnifeLocked.setExpendLife(Math.toIntExact(item.getAttr1())); + baseKnifeLockedMapper.insertBaseKnifeLocked(baseKnifeLocked); }); // 生成出库计划明细 @@ -1230,6 +725,7 @@ public class BaseKnifeController extends BaseController { productionArrangements.setStatus(1); productionArrangementsMapper.updateProductionArrangements(productionArrangements); + this.productionArrangementsIsOk(productionArrangements); } operLog.setJsonResult(msg); @@ -1238,6 +734,97 @@ public class BaseKnifeController extends BaseController { return AjaxResult.success(msg); } + // 调用生产准备完成接口 + public void productionArrangementsIsOk(ProductionArrangements productionArrangements) throws IOException { + // 产线控制系统生产准备完成接口 + String url = myConfig.getProductionControlPath() + "/cutterapi/cutComplete"; + + // 请求客户端 + OkHttpClient client = new OkHttpClient(); + + // 构建请求数据 + Map requestMap = new HashMap<>(); + requestMap.put("prodordercode", productionArrangements.getPlanSheet()); + requestMap.put("result", "0"); + requestMap.put("completetime", CalendarUtil.getDateTimeStr()); + + // 获取工艺信息 + BaseTechnologyBom technologyBomWrapper = new BaseTechnologyBom(); + technologyBomWrapper.setTechnologyCode(productionArrangements.getTechnologyCode()); + List technologyBomList = baseTechnologyBomService.selectBaseTechnologyBomList(technologyBomWrapper); + + BaseKnife baseKnifeWrapper = new BaseKnife(); + baseKnifeWrapper.setPlanSheet(productionArrangements.getPlanSheet()); + + // 获取刀具信息 + List> cutterList = new ArrayList<>(); + technologyBomList.forEach(baseTechnologyBom -> { + baseKnifeWrapper.setKnifeCode(baseTechnologyBom.getKnifeCode()); + List baseKnifeList = baseKnifeService.selectBaseKnifeList(baseKnifeWrapper); + baseKnifeList.forEach(baseKnife -> { + Map map = new HashMap<>(); + map.put("specno", baseTechnologyBom.getProcessCode()); + map.put("code", baseKnife.getKnifeCode()); + map.put("name", baseKnife.getKnifeName()); + map.put("life", baseKnife.getKnifeLife().toString()); + cutterList.add(map); + }); + }); + requestMap.put("cutterinfo", cutterList); + + // 构建请求数据 + MediaType mediaType = MediaType.parse("application/json; charset=utf-8"); + okhttp3.RequestBody requestBody = okhttp3.RequestBody.create(mediaType, JSON.toJSONString(requestMap)); + + // 请求体 + Request request = new Request.Builder() + .url(url) + .post(requestBody) + .build(); + + // 发送请求 + try(Response response = client.newCall(request).execute()) { + if (!response.isSuccessful()) + throw new IOException("Unexpected code " + response); + + // 请求响应 + String responseBody = response.body().string(); + System.out.println(responseBody); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public int getBomZdTaskQuantity(BomRoute bomRoute, Integer knifeCount){ + + // 记录基础物料数量的map + Map baseKnifeItemCount = new HashMap<>(); + + // 遍历bom项, 从台账表中筛选对应基础物料 + for (MbbProduBom bom : bomRoute.getMbbProduBomList()) { + // 查询基础物料。不包含已锁定的 + BaseKnife baseKnifeWrapper = new BaseKnife(); + baseKnifeWrapper.setMbbBdMrlId(bom.getMdItemId()); + baseKnifeWrapper.setIsLocked(0); + List sitmTempList = baseKnifeService.selectBaseKnifeList(baseKnifeWrapper); + + // 填充基础物料数量 + baseKnifeItemCount.put(bom.getMdItemCode(), sitmTempList.size()); + } + + // 更具需要的物料数量计算基础物料能组装多少 + for (int i = 0; i < knifeCount; i++){ + // 遍历bom项, 并减去数量 + for (MbbProduBom bom : bomRoute.getMbbProduBomList()) { + if (baseKnifeItemCount.get(bom.getMdItemCode()) - bom.getStandardDosage() >= 0){ + baseKnifeItemCount.put(bom.getMdItemCode(), baseKnifeItemCount.get(bom.getMdItemCode()) - bom.getStandardDosage()); + } else return i; + } + } + + return knifeCount; + } + public List getLockedBaseKnifeId(String mdItemCode, ProductionArrangements productionArrangements, int count, int expendLife){ // 查询该物料编码的锁定记录 BaseKnifeLocked baseKnifeLockedWrapper = new BaseKnifeLocked(); @@ -1317,7 +904,7 @@ public class BaseKnifeController extends BaseController { // 如果未锁定的物料不足所需数量 if (baseKnifeList.size() < mbbProduBom.getStandardDosage() * zdTask.getProductIdQty()) - return AjaxResult.error("bom物料不足进行组装:" + mbbProduBom.getMdItemCode()); + throw new RuntimeException("bom物料不足进行组装:" + mbbProduBom.getMdItemCode()); } List wmsOutPlanDetailList = new ArrayList<>(); diff --git a/ktg-mes/src/main/java/com/ktg/mes/md/domain/MdItem.java b/ktg-mes/src/main/java/com/ktg/mes/md/domain/MdItem.java index 1374927..9ed376f 100644 --- a/ktg-mes/src/main/java/com/ktg/mes/md/domain/MdItem.java +++ b/ktg-mes/src/main/java/com/ktg/mes/md/domain/MdItem.java @@ -36,6 +36,9 @@ public class MdItem extends BaseEntity { private String safeStockFlag; private Integer minStock; private Double maxStock; + private Double length; + private Double width; + private Double height; private String highValue; private Integer attr1; private Integer attr2; @@ -228,6 +231,30 @@ public class MdItem extends BaseEntity { this.count = count; } + public Double getLength() { + return length; + } + + public void setLength(Double length) { + this.length = length; + } + + public Double getWidth() { + return width; + } + + public void setWidth(Double width) { + this.width = width; + } + + public Double getHeight() { + return height; + } + + public void setHeight(Double height) { + this.height = height; + } + @Override public String toString() { return "MdItem{" + diff --git a/ktg-mes/src/main/java/com/ktg/mes/md/mapper/BaseKnifeMapper.java b/ktg-mes/src/main/java/com/ktg/mes/md/mapper/BaseKnifeMapper.java index 9c17bf1..711b86b 100644 --- a/ktg-mes/src/main/java/com/ktg/mes/md/mapper/BaseKnifeMapper.java +++ b/ktg-mes/src/main/java/com/ktg/mes/md/mapper/BaseKnifeMapper.java @@ -123,4 +123,6 @@ public interface BaseKnifeMapper { List selectBaseKnifeNotValidList(BaseKnife baseKnifeWrapper); List selectNotEmptyAreaCodeList(); + + List selectBaseKnifeListByMbbBdMrlId(Long itemId); } diff --git a/ktg-mes/src/main/java/com/ktg/mes/md/service/impl/BaseKnifeServiceImpl.java b/ktg-mes/src/main/java/com/ktg/mes/md/service/impl/BaseKnifeServiceImpl.java index dcf3620..f8e8e52 100644 --- a/ktg-mes/src/main/java/com/ktg/mes/md/service/impl/BaseKnifeServiceImpl.java +++ b/ktg-mes/src/main/java/com/ktg/mes/md/service/impl/BaseKnifeServiceImpl.java @@ -127,27 +127,6 @@ public class BaseKnifeServiceImpl implements IBaseKnifeService { hashMap.put("isToolSetting", nowWmsOutPlanDetailEntity.getIsToolSetting()); // 是否对刀 hashMap.put("toolSettingParam", nowWmsOutPlanDetailEntity.getToolSettingParam()); // 对刀参数 -// // 读取xml配置文件 -// if ("PRODUCT".equals(nowWmsOutPlanDetailEntity.getItemOrProduct())) { -// try { -// // 抓取远程文件 -// this.getRemoteFile(); -// -// // 读取本地文件 -// File xmlFile = new File(myConfig.getToolSettingXmlPath() + CalendarUtil.getDateTimeStrForFile() + "/TSP1203.xml"); -// JAXBContext jaxbContext = JAXBContext.newInstance(Tools.class); -// Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); -// Tools paramXml = (Tools) unmarshaller.unmarshal(xmlFile); -// -// hashMap.put("isToolSetting", 1); // 是否对刀 -// hashMap.put("toolSettingParam", JSON.toJSONString(paramXml)); // 对刀参数 -// -// } catch (Exception e) { -// System.out.println("系统找不到指定文件!"); -//// throw new RuntimeException(e); -// } -// } - /* 实体 */ String outTime = null; if (nowWmsOutPlanDetailEntity.getCreateTime() != null) @@ -176,74 +155,6 @@ public class BaseKnifeServiceImpl implements IBaseKnifeService { return baseKnifeList; } - /** - * 获取远程文件 - */ - public void getRemoteFile() throws IOException { - try { - // 创建认证用户 - NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("", myConfig.getRemoteUser(), myConfig.getRemotePass()); - - // 构建远程文件对象 - SmbFile remoteFile = new SmbFile(myConfig.getRemoteUrl(), auth); - // 尝试链接 - remoteFile.connect(); - if(remoteFile.exists()){ - // 获取共享文件夹中文件列表 - SmbFile[] smbFiles = remoteFile.listFiles(); - for (SmbFile smbFile : smbFiles){ - createFile(smbFile); - } - } else { - System.out.println("==============START================="); - System.out.println("远程文件不存在"); - System.out.println("===============END=================="); - } - } catch (Exception e){ - throw new RuntimeException(e); - } - } - - /** - * 创建本地文件 - */ - public void createFile(SmbFile remoteFile) { - InputStream in = null; - OutputStream out = null; - try { - // 创建本地文件 -// File localFile = new File("E:/xml_wjj/" + CalendarUtil.getDateTimeStrForFile() + "/" + remoteFile.getName()); - File localFile = new File(myConfig.getToolSettingXmlPath() + CalendarUtil.getDateTimeStrForFile() + "/" + remoteFile.getName()); - if (!localFile.getParentFile().exists()) localFile.getParentFile().mkdirs(); - if (!localFile.exists()) localFile.createNewFile(); - else { - localFile.delete(); - localFile.createNewFile(); - } - in = new BufferedInputStream(new SmbFileInputStream(remoteFile)); - // 获取远程输出流 - out = new BufferedOutputStream(new FileOutputStream(localFile)); - byte[] buffer = new byte[4096]; - int len = 0; - // 写入 - while ((len = in.read(buffer, 0, buffer.length)) != -1) { - out.write(buffer, 0, len); - } - out.flush(); // 刷新缓冲 - } catch (Exception e) { - throw new RuntimeException(e); - } finally { - try { - if (out != null) out.close(); - if (in != null) in.close(); - } catch (Exception e){ - System.out.println("==============START================="); - System.out.println("关闭资源发生错误!"); - System.out.println("===============END=================="); - } - } - } - /** * 新增工具台账 * diff --git a/ktg-mes/src/main/java/com/ktg/mes/wm/controller/WmsInTaskController.java b/ktg-mes/src/main/java/com/ktg/mes/wm/controller/WmsInTaskController.java index 10a235e..36e27a2 100644 --- a/ktg-mes/src/main/java/com/ktg/mes/wm/controller/WmsInTaskController.java +++ b/ktg-mes/src/main/java/com/ktg/mes/wm/controller/WmsInTaskController.java @@ -242,9 +242,12 @@ public class WmsInTaskController extends BaseController { List baseKnifeLockedList = baseKnifeLockedMapper.selectBaseKnifeLockedList(baseKnifeLockedWrapper); // 获取实体并修改状态 - BaseKnifeLocked baseKnifeLocked = baseKnifeLockedList.get(0); - baseKnifeLocked.setStatus(1); - baseKnifeLockedMapper.updateBaseKnifeLocked(baseKnifeLocked); + BaseKnifeLocked baseKnifeLocked; + if (!baseKnifeLockedList.isEmpty()){ + baseKnifeLocked = baseKnifeLockedList.get(0); + baseKnifeLocked.setStatus(1); + baseKnifeLockedMapper.updateBaseKnifeLocked(baseKnifeLocked); + } // 再次查询物料是否有预订订单 baseKnifeLockedWrapper.setPlanSheet(null); diff --git a/ktg-mes/src/main/java/com/ktg/mes/wm/service/impl/WmsInTaskServiceImpl.java b/ktg-mes/src/main/java/com/ktg/mes/wm/service/impl/WmsInTaskServiceImpl.java index e9496cc..5377be2 100644 --- a/ktg-mes/src/main/java/com/ktg/mes/wm/service/impl/WmsInTaskServiceImpl.java +++ b/ktg-mes/src/main/java/com/ktg/mes/wm/service/impl/WmsInTaskServiceImpl.java @@ -87,8 +87,8 @@ public class WmsInTaskServiceImpl implements IWmsInTaskService { task.setCellY(wmStorageArea.getPositionY().toString()); task.setCellZ(wmStorageArea.getPositionZ().toString()); - List wmsInPlanDetailEntityList = wmsInPlanDetailEntityService.selectWmsInPlanDetailEntityList(wmsInPlanDetailEntityQuery); - task.setWmsInPlanDetailEntityList(wmsInPlanDetailEntityList); +// List wmsInPlanDetailEntityList = wmsInPlanDetailEntityService.selectWmsInPlanDetailEntityList(wmsInPlanDetailEntityQuery); +// task.setWmsInPlanDetailEntityList(wmsInPlanDetailEntityList); wmsInTaskList.add(task); }); return wmsInTaskList; 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 3f54432..aeb0365 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 @@ -270,7 +270,6 @@ public class WmsZdTaskServiceImpl implements IWmsZdTaskService // 锁定物料 int resetCount = 0; - String rfid = ""; for (MbbProduBom mbbProduBom : bomRoute.getMbbProduBomList()) { // 查询未锁定的物料 baseKnifeWrapper.setMbbBdMrlId(mbbProduBom.getMdItemId()); @@ -281,12 +280,8 @@ public class WmsZdTaskServiceImpl implements IWmsZdTaskService int bomCount = mbbProduBom.getStandardDosage(); for (BaseKnife wmsBaseKnife : baseKnifeList) { if (bomCount > 0) { - if ("ITEM".equals(wmsBaseKnife.getItemOrProduct())) rfid = wmsBaseKnife.getRfid(); wmsBaseKnife.setZdTaskId(zdTask.getWmsZdTaskId()); wmsBaseKnife.setIsLocked(1); - wmsBaseKnife.setRfid(""); -// wmsBaseKnife.setLockedStartTime(technologyBom.getLockedStartTime()); -// wmsBaseKnife.setLockedEndTime(technologyBom.getLockedEndTime()); wmsBaseKnife.setParentId(baseKnife.getBaseKnifeId()); wmsBaseKnife.setPlanSheet(zdTask.getPlanSheet()); baseKnifeListOutPlan.add(wmsBaseKnife); @@ -301,7 +296,9 @@ public class WmsZdTaskServiceImpl implements IWmsZdTaskService // 更新重置次数 baseKnife.setResetCount(resetCount - 1); - baseKnife.setRfid(rfid); + // 设置rfid, 为整刀编码加序号 例如整刀编码为 aaa 则整刀rfid为 aaa0001 aaa0002, 传个i:在当前事务中新增的台账还没提交,所以把循环系数加上 + baseKnife.setRfid(this.getProductRfid(zdTask.getmProductId(), i)); + baseKnifeMapper.updateBaseKnife(baseKnife); } @@ -397,6 +394,18 @@ public class WmsZdTaskServiceImpl implements IWmsZdTaskService return AjaxResult.success(); } + public String getProductRfid(Long itemId, int i){ + MdItem mdItem = mdItemMapper.selectMdItemById(itemId); + + List baseKnifeList = baseKnifeMapper.selectBaseKnifeListByMbbBdMrlId(itemId); + if (baseKnifeList.isEmpty()) return mdItem.getItemCode() + String.format("%04d", 1); + else { + String index = baseKnifeList.get(0).getRfid().substring(baseKnifeList.get(0).getRfid().length() - 4); + Integer indexInt = Integer.parseInt(index) + 1 + i; + return mdItem.getItemCode() + String.format("%04d", indexInt); + } + } + @Override @Transactional diff --git a/ktg-mes/src/main/resources/mapper/md/BaseKnifeMapper.xml b/ktg-mes/src/main/resources/mapper/md/BaseKnifeMapper.xml index 431e94b..4f236d4 100644 --- a/ktg-mes/src/main/resources/mapper/md/BaseKnifeMapper.xml +++ b/ktg-mes/src/main/resources/mapper/md/BaseKnifeMapper.xml @@ -619,4 +619,15 @@ WHERE KNIFE_FINE_STATE == 1 GROUP BY AREA_CODE + + \ No newline at end of file diff --git a/ktg-mes/src/main/resources/mapper/md/MdItemMapper.xml b/ktg-mes/src/main/resources/mapper/md/MdItemMapper.xml index fbaf1f4..44a8028 100644 --- a/ktg-mes/src/main/resources/mapper/md/MdItemMapper.xml +++ b/ktg-mes/src/main/resources/mapper/md/MdItemMapper.xml @@ -21,6 +21,9 @@ + + + @@ -50,6 +53,9 @@ min_stock, max_stock, high_value, + length, + width, + height, attr1, attr2, attr3, @@ -195,6 +201,15 @@ high_value, + + length, + + + width, + + + height, + remark, @@ -247,6 +262,15 @@ #{highValue}, + + #{length}, + + + #{width}, + + + #{height}, + #{remark}, @@ -316,6 +340,15 @@ high_value = #{highValue}, + + length = #{length}, + + + width = #{width}, + + + height = #{height}, + remark = #{remark},