diff --git a/ktg-admin/pom.xml b/ktg-admin/pom.xml
index 93677f9..246b229 100644
--- a/ktg-admin/pom.xml
+++ b/ktg-admin/pom.xml
@@ -124,27 +124,6 @@
jtds
1.3.1
-
-
- org.springframework.boot
- spring-boot-starter-web-services
-
-
-
- org.springframework
- spring-oxm
-
-
-
- org.apache.cxf
- cxf-spring-boot-starter-jaxws
- 4.0.3
-
-
- jakarta.jws
- jakarta.jws-api
- 2.1.0
-
diff --git a/ktg-mes/pom.xml b/ktg-mes/pom.xml
index 2dea2b1..2b4f85f 100644
--- a/ktg-mes/pom.xml
+++ b/ktg-mes/pom.xml
@@ -66,6 +66,12 @@
org.projectlombok
lombok
+
+
+ org.apache.cxf
+ cxf-spring-boot-starter-jaxws
+ 3.4.4
+
\ No newline at end of file
diff --git a/ktg-mes/src/main/java/com/ktg/mes/md/config/WebServiceConfig.java b/ktg-mes/src/main/java/com/ktg/mes/md/config/WebServiceConfig.java
new file mode 100644
index 0000000..463c196
--- /dev/null
+++ b/ktg-mes/src/main/java/com/ktg/mes/md/config/WebServiceConfig.java
@@ -0,0 +1,36 @@
+package com.ktg.mes.md.config;
+
+import com.ktg.mes.md.service.IMasterDataSyncService;
+import lombok.RequiredArgsConstructor;
+import org.apache.cxf.Bus;
+import org.apache.cxf.bus.spring.SpringBus;
+import org.apache.cxf.jaxws.EndpointImpl;
+import org.apache.cxf.transport.servlet.CXFServlet;
+import org.springframework.boot.web.servlet.ServletRegistrationBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import javax.xml.ws.Endpoint;
+
+@Configuration
+@RequiredArgsConstructor
+public class WebServiceConfig {
+ private final IMasterDataSyncService masterDataSyncService;
+
+ @Bean(name = Bus.DEFAULT_BUS_ID)
+ public SpringBus springBus() {
+ return new SpringBus();
+ }
+
+ @Bean
+ public ServletRegistrationBean cxfServlet() {
+ return new ServletRegistrationBean<>(new CXFServlet(), "/WebServices/open/*");
+ }
+
+ @Bean
+ public Endpoint endpoint() {
+ EndpointImpl endpoint = new EndpointImpl(springBus(), masterDataSyncService);
+ endpoint.publish("/MasterDataSyncService");
+ return endpoint;
+ }
+}
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