From a341854361b1262b81a3cb245a6a47bffbd27c39 Mon Sep 17 00:00:00 2001 From: liuxy Date: Fri, 27 Oct 2023 14:14:58 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=E9=85=8D=E7=B2=89=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nl/wms/pf/rest/FlourworkController.java | 13 +- .../nl/wms/pf/service/FlourworkService.java | 5 + .../pf/service/impl/FlourworkServiceImpl.java | 346 ++++++++++++------ .../org/nl/wms/pf/wql/QPDM_BI_FORMULA02.wql | 22 ++ .../instor/service/HandMoveStorService.java | 1 + .../service/impl/HandMoveStorServiceImpl.java | 43 ++- 6 files changed, 314 insertions(+), 116 deletions(-) diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/pf/rest/FlourworkController.java b/mes/hd/nladmin-system/src/main/java/org/nl/wms/pf/rest/FlourworkController.java index d4b78f5e..174af66e 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/wms/pf/rest/FlourworkController.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/pf/rest/FlourworkController.java @@ -8,20 +8,17 @@ import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.nl.annotation.Log; -import org.nl.modules.mnt.service.dto.AppQueryCriteria; +import org.nl.wms.common.util.RedissonUtils; import org.nl.wms.pf.service.FlourworkService; -import org.nl.wms.pf.service.FormingmaterialService; -import org.nl.wms.pf.service.dto.FormingmaterialDto; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.Map; +import java.util.concurrent.atomic.AtomicReference; /** * @author Lxy @@ -90,7 +87,11 @@ public class FlourworkController { @Log("自动叫料") @ApiOperation("自动叫料") public ResponseEntity autoCalledMater(@RequestBody JSONObject whereJson){ - return new ResponseEntity<>(flourworkService.autoCalledMater(whereJson),HttpStatus.OK); + AtomicReference result = new AtomicReference<>(new JSONObject()); + RedissonUtils.lock(a -> { + result.set(flourworkService.autoCalledMater(whereJson)); + }, "autoCalledMater", 1); + return new ResponseEntity<>(result.get(),HttpStatus.OK); } @PostMapping("/startWork") diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/pf/service/FlourworkService.java b/mes/hd/nladmin-system/src/main/java/org/nl/wms/pf/service/FlourworkService.java index a28c7faf..14f4989e 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/wms/pf/service/FlourworkService.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/pf/service/FlourworkService.java @@ -4,9 +4,11 @@ package org.nl.wms.pf.service; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import org.springframework.data.domain.Pageable; +import org.springframework.scheduling.annotation.Async; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.util.ArrayList; import java.util.Map; /** @@ -65,6 +67,9 @@ public interface FlourworkService { */ void outConfirm(JSONObject whereJson); + @Async + void asyncdown(ArrayList objects); + /** * 投料确认 * @param whereJson / diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/pf/service/impl/FlourworkServiceImpl.java b/mes/hd/nladmin-system/src/main/java/org/nl/wms/pf/service/impl/FlourworkServiceImpl.java index f9c3d112..389da3b3 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/wms/pf/service/impl/FlourworkServiceImpl.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/pf/service/impl/FlourworkServiceImpl.java @@ -33,12 +33,17 @@ import org.nl.wql.WQL; import org.nl.wql.core.bean.ResultBean; import org.nl.wql.core.bean.WQLObject; import org.nl.wql.util.WqlUtil; +import org.springframework.aop.framework.AopContext; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; import org.springframework.data.domain.Pageable; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.math.BigDecimal; import java.util.*; import java.util.stream.Collectors; @@ -57,6 +62,10 @@ public class FlourworkServiceImpl implements FlourworkService { private final MaterialbaseService materialbaseService; private final WmsToAcsService wmsToAcsService; + @Autowired + @Lazy + private FlourworkService flourworkService; + @Override public Map queryAll(Map whereJson, Pageable page) { String is_all = MapUtil.getStr(whereJson, "is_all"); @@ -186,12 +195,70 @@ public class FlourworkServiceImpl implements FlourworkService { JSONObject jsonFormMst = formTabMst.query("formula_id = '" + formula_id + "' and status <> '99'").uniqueResult(0); if (ObjectUtil.isEmpty(jsonFormMst)) throw new BadRequestException("配方已完成"); + String workorder_id = jsonFormMst.getString("workorder_id"); // 工令标识 + /* * 查询需要移库的物料(配方明细表)条件: * 1.状态等于10生成、20生产中 * 2.是否需要移库 = 1 * 3.按照配粉序号排序 ASC */ + // --------1.计算未领重量前置查询--------- + // 查询当前配粉工位的所有上料位 + JSONArray jsonDeviceArr = devicePointTab.query("device_uuid = '" + device_id + "' and point_type = '03'").getResultJSONArray(0); + String join = jsonDeviceArr.stream() + .map(row -> JSON.parseObject(row.toString())) + .map(row -> row.getString("point_uuid")) + .collect(Collectors.joining("','")); + + // 当前上料位所有点位集合 + JSONArray pointArr = WQLObject.getWQLObject("sch_base_point").query("point_id in ('" + join + "')").getResultJSONArray(0); + + // 当前上料位所有点位可用数:根据pcsn和material_id 分组 + String point_uuid_in = pointArr.stream() + .map(row -> JSON.parseObject(row.toString())) + .map(row -> row.getString("source_id")) + .collect(Collectors.joining("','")); + + JSONArray jsonIvtArr = WQL.getWO("QPDM_BI_FORMULA02").addParam("flag", "11") + .addParam("point_uuid_in", "('" + point_uuid_in + "')") + .process().getResultJSONArray(0); + + //此工令移库数总和集合 + JSONArray jsonMoveDtlArr = WQL.getWO("QPDM_BI_FORMULA02").addParam("flag", "2") + .addParam("workorder_id", workorder_id) + .process().getResultJSONArray(0); + + // --------2.生成移库单前置查询--------- + // 查询全部可用重量集合 -- 库存数大于未领重量 + JSONArray moveOutIvtAllArr = WQL.getWO("QPDM_BI_FORMULA02").addParam("flag", "3").process().getResultJSONArray(0); + + // 查询全部可用重量集合 -- 库存数大于0 + JSONArray moveOutIvtAllArr2 = WQL.getWO("QPDM_BI_FORMULA02").addParam("flag", "4").process().getResultJSONArray(0); + + // 查询移入货位 -- 钴粉 + List moveInGFArr = WQL.getWO("QPDM_BI_FORMULA02") + .addParam("flag", "5") + .addParam("device_id", device_id) + .process().getResultJSONArray(0).stream() + .map(row -> JSON.parseObject(row.toString())) + .collect(Collectors.toList()); + + // 查询移入货位 -- 非钴粉 + List moveInNGFArr = WQL.getWO("QPDM_BI_FORMULA02") + .addParam("flag", "9") + .addParam("device_id", device_id) + .process().getResultJSONArray(0).stream() + .map(row -> JSON.parseObject(row.toString())) + .collect(Collectors.toList()); + + // 查询所有仓位 + JSONArray attrArr = strucTab.query("1 = 1").getResultJSONArray(0); + + // 生成移库单的所有集合 + ArrayList createMove = new ArrayList<>(); + + ArrayList arr = new ArrayList<>(); ArrayList arr2 = new ArrayList<>(); JSONObject result = new JSONObject(); @@ -208,34 +275,29 @@ public class FlourworkServiceImpl implements FlourworkService { */ // 1.计算剩余需投料: 剩余需投料=此配方明细的重量-已投料重量 double subQty = NumberUtil.sub(jsonFormDtl.getDoubleValue("formula_qty"), jsonFormDtl.getDoubleValue("put_qty")); - // 2.查询当前配粉工位的所有上料位 - JSONArray jsonDeviceArr = devicePointTab.query("device_uuid = '" + device_id + "' and point_type = '03'").getResultJSONArray(0); - // 3.查询当前可用数:当前可用数=sum(此配粉工位点位仓位此物料可用数) + // 2.查询当前可用数:当前可用数=sum(此配粉工位点位仓位此物料可用数) double canuse_qty = 0.0; // 总当前可用数 if (ObjectUtil.isNotEmpty(jsonDeviceArr)) { - for (int j = 0; j < jsonDeviceArr.size(); j++) { - JSONObject json = jsonDeviceArr.getJSONObject(j); - JSONObject jsonObject = WQLObject.getWQLObject("sch_base_point").query("point_id ='" + json.getString("point_uuid") + "'").uniqueResult(0); - HashMap map = new HashMap<>(); - map.put("flag", "1"); - map.put("point_uuid", jsonObject.getString("source_id")); - map.put("pcsn", pcsn); - map.put("material_id", material_id); - JSONObject jsonIvt = WQL.getWO("QPDM_BI_FORMULA02").addParamMap(map).process().uniqueResult(0); - if (ObjectUtil.isNotEmpty(jsonIvt)) - canuse_qty = NumberUtil.add(canuse_qty, jsonIvt.getDoubleValue("canuse_qty")); - } + // 总可用数 + canuse_qty = jsonIvtArr.stream() + .map(row -> JSON.parseObject(row.toString())) + .filter(row -> row.getString("material_id").equals(material_id) && row.getString("pcsn").equals(pcsn)) + .mapToDouble(row -> row.getDoubleValue("canuse_qty")).sum(); } - // 4.查询正在移库数:正在移库数=sum(未完成移库单、此工令、此物料移库数量) - String workorder_id = jsonFormMst.getString("workorder_id"); // 工令标识 - JSONObject jsonMoveDtl = WQL.getWO("QPDM_BI_FORMULA02").addParam("flag", "2").addParam("workorder_id", workorder_id).addParam("material_id", material_id).addParam("pcsn", pcsn).process().uniqueResult(0); + + // 3.查询正在移库数:正在移库数=sum(未完成移库单、此工令、此物料移库数量) double move_qty = 0.0; // 正在移库数 - if (ObjectUtil.isNotEmpty(jsonMoveDtl)) { - move_qty = jsonMoveDtl.getDoubleValue("qty"); + if (ObjectUtil.isNotEmpty(jsonMoveDtlArr)) { + move_qty = jsonMoveDtlArr.stream() + .map(row -> JSON.parseObject(row.toString())) + .filter(row -> row.getString("material_id").equals(material_id) && row.getString("pcsn").equals(pcsn)) + .mapToDouble(row -> row.getDoubleValue("qty")).sum(); + } - // 5.计算未领重量:未领重量=剩余需投料 - 当前可用数 - 正在移库数 + + // 4.计算未领重量:未领重量=剩余需投料 - 当前可用数 - 正在移库数 double uncla_qty = Double.parseDouble(String.valueOf(NumberUtil.sub(subQty, canuse_qty, move_qty))); - // 6.判断物料是否为钴粉 + // 5.判断物料是否为钴粉 boolean is_GF = materialbaseService.isAlongMaterType(MaterOptTypeEnum.GF.getCode(), material_id, null); /* @@ -243,90 +305,130 @@ public class FlourworkServiceImpl implements FlourworkService { */ // 1.查询移出货位:此物料批次、未锁定、可用数量>=未领重量,按可用数量排序的第一个货位物料; 取不到:此物料批次、未锁定 JSONObject moveOutIvt = WQL.getWO("QPDM_BI_FORMULA02").addParam("flag", "3").addParam("uncla_qty", String.valueOf(uncla_qty)).addParam("material_id", material_id).addParam("pcsn", pcsn).process().uniqueResult(0); + + double finalCanuse_qty = uncla_qty; + List moveOutIvtAllFilterArr = moveOutIvtAllArr.stream() + .map(row -> JSON.parseObject(row.toString())) + .filter(row -> row.getString("material_id").equals(material_id) + && row.getString("pcsn").equals(pcsn) + && row.getDoubleValue("canuse_qty") >= finalCanuse_qty + ) + .collect(Collectors.toList()); + // 2.如果为空:说明需要进行多次生成移库任务 - if (ObjectUtil.isEmpty(moveOutIvt)) { - JSONArray moveOutIvtArr = WQL.getWO("QPDM_BI_FORMULA02").addParam("flag", "4").addParam("material_id", material_id).addParam("pcsn", pcsn).process().getResultJSONArray(0); - if (ObjectUtil.isNotEmpty(moveOutIvtArr)) { - for (int k = 0; k < moveOutIvtArr.size(); k++) { - JSONObject jsonMoveOutIvt = moveOutIvtArr.getJSONObject(k); // 移出货位 - double canuse_qty1 = jsonMoveOutIvt.getDoubleValue("canuse_qty"); - // 3.判断未领重量是否 <= 0 ,如果是则跳出循环 - if (uncla_qty <= 0) break; - // 4.查找移入货位,判断物料是否是钴粉 - JSONObject moveInIvt = new JSONObject(); - if (is_GF) { - moveInIvt = WQL.getWO("QPDM_BI_FORMULA02").addParam("flag", "5").addParam("device_id", whereJson.getString("device_id")).process().uniqueResult(0); - } else { - moveInIvt = WQL.getWO("QPDM_BI_FORMULA02").addParam("flag", "9").addParam("device_id", whereJson.getString("device_id")).process().uniqueResult(0); - } - if (ObjectUtil.isEmpty(moveInIvt)) break; - // 5.生成移库单 - //校验点位是否有执行中任务: - ; - JSONArray runingtask = WQLObject.getWQLObject("SCH_BASE_Task").query("next_point_code = '" + moveInIvt.getString("point_code") + "' and task_status <> '99' and is_delete = '0'").getResultJSONArray(0); - if (runingtask.size()>0){ - throw new BadRequestException("分配点位存在未完成任务:"+moveInIvt.getString("point_code")); - } - JSONObject map = new JSONObject(); - JSONArray tableData = new JSONArray(); - map.put("bill_status", "10"); - map.put("bill_type", "21"); - map.put("biz_date", DateUtil.today()); - map.put("stor_code", "01"); - map.put("stor_id", "1473161852946092032"); - map.put("stor_name", "原材料库"); - JSONObject param = new JSONObject(); - param.put("edit", true); - param.put("is_active", jsonMoveOutIvt.getString("is_active")); - param.put("ivt_level", jsonMoveOutIvt.getString("ivt_level")); - param.put("material_id", jsonMoveOutIvt.getString("material_id")); - param.put("pcsn", jsonMoveOutIvt.getString("pcsn")); - param.put("qty", jsonMoveOutIvt.getString("canuse_qty")); - param.put("qty_unit_id", jsonMoveOutIvt.getString("qty_unit_id")); - param.put("quality_scode", jsonMoveOutIvt.getString("quality_scode")); - JSONObject trunIn = strucTab.query("struct_code = '" + moveInIvt.getString("point_code") + "'").uniqueResult(0); - JSONObject trunOut = strucTab.query("struct_code = '" + jsonMoveOutIvt.getString("struct_code") + "'").uniqueResult(0); - param.put("turnin_sect_id", trunIn.getString("sect_id")); - param.put("turnin_sect_code", trunIn.getString("sect_code")); - param.put("turnin_sect_name", trunIn.getString("sect_name")); - param.put("turnin_struct_id", trunIn.getString("struct_id")); - param.put("turnin_struct_code", trunIn.getString("struct_code")); - param.put("turnin_struct_name", trunIn.getString("struct_name")); - param.put("turnout_sect_id", trunOut.getString("sect_id")); - param.put("turnout_sect_code", trunOut.getString("sect_code")); - param.put("turnout_sect_name", trunOut.getString("sect_name")); - param.put("turnout_struct_id", trunOut.getString("struct_id")); - param.put("turnout_struct_code", trunOut.getString("struct_code")); - param.put("turnout_struct_name", trunOut.getString("struct_name")); - param.put("storagevehicle_code", trunOut.getString("storagevehicle_code")); - param.put("work_status", "10"); - param.put("source_billdtl_id", formuladtl_id); - tableData.add(param); - map.put("tableData", tableData); - String moveinv_id = handMoveStorService.insertDtl2(map); - // 6.下发移库单 - JSONObject jsonMoveParam = new JSONObject(); - jsonMoveParam.put("moveinv_id", moveinv_id); - handMoveStorService.handdown(jsonMoveParam); - // 7.下发移库单后减去未领重量 - uncla_qty = NumberUtil.sub(uncla_qty, canuse_qty1); - // 回馈任务数 - taskNum = String.valueOf(NumberUtil.add(taskNum, "1")); - } - } else { + if (ObjectUtil.isEmpty(moveOutIvtAllFilterArr)) { + List moveOutIvtArr = moveOutIvtAllArr2.stream() + .map(row -> JSON.parseObject(row.toString())) + .filter(row -> row.getString("material_id").equals(material_id) + && row.getString("pcsn").equals(pcsn) + ) + .collect(Collectors.toList()); + + if (ObjectUtil.isEmpty(moveOutIvtArr)) { // 没有找到移出货位 ,说明没有物料 arr.add(jsonFormDtl.getString("material_id")); } + + for (int j = 0; j < moveOutIvtArr.size(); j++) { + JSONObject jsonMoveOutIvt = moveOutIvtArr.get(j); // 移出货位 + double canuse_qty1 = jsonMoveOutIvt.getDoubleValue("canuse_qty"); // 移出数量 + + // 判断未领重量是否 <= 0 ,如果是则跳出循环 + if (uncla_qty <= 0) break; + + // 查找移入货位,判断物料是否是钴粉 + JSONObject moveInIvt = new JSONObject(); + + if (is_GF) { + if (ObjectUtil.isNotEmpty(moveInNGFArr)) { + moveInIvt = moveInGFArr.get(0); + moveInGFArr.remove(0); + } + } else { + if (ObjectUtil.isNotEmpty(moveInNGFArr)) { + moveInIvt = moveInNGFArr.get(0); + moveInNGFArr.remove(0); + } + } + + if (ObjectUtil.isEmpty(moveInIvt)) break; + + // 校验点位是否有执行中的任务 + JSONArray runingtask = WQLObject.getWQLObject("SCH_BASE_Task").query("next_point_code = '" + moveInIvt.getString("point_code") + "' and task_status <> '99' and is_delete = '0'").getResultJSONArray(0); + if (runingtask.size()>0){ + throw new BadRequestException("分配点位存在未完成任务:"+moveInIvt.getString("point_code")); + } + + // 生成移库单 + JSONObject map = new JSONObject(); + JSONArray tableData = new JSONArray(); + map.put("bill_status", "10"); + map.put("bill_type", "21"); + map.put("biz_date", DateUtil.today()); + map.put("stor_code", "01"); + map.put("stor_id", "1473161852946092032"); + map.put("stor_name", "原材料库"); + JSONObject param = new JSONObject(); + param.put("edit", true); + param.put("is_active", jsonMoveOutIvt.getString("is_active")); + param.put("ivt_level", jsonMoveOutIvt.getString("ivt_level")); + param.put("material_id", jsonMoveOutIvt.getString("material_id")); + param.put("pcsn", jsonMoveOutIvt.getString("pcsn")); + param.put("qty", jsonMoveOutIvt.getString("canuse_qty")); + param.put("qty_unit_id", jsonMoveOutIvt.getString("qty_unit_id")); + param.put("quality_scode", jsonMoveOutIvt.getString("quality_scode")); + + JSONObject finalMoveInIvt = moveInIvt; + JSONObject trunIn = attrArr.stream() + .map(row -> JSON.parseObject(row.toString())) + .filter(row -> row.getString("struct_code").equals(finalMoveInIvt.getString("point_code"))) + .collect(Collectors.toList()).get(0); + + JSONObject trunOut = attrArr.stream() + .map(row -> JSON.parseObject(row.toString())) + .filter(row -> row.getString("struct_code").equals(jsonMoveOutIvt.getString("struct_code"))) + .collect(Collectors.toList()).get(0); + + param.put("turnin_sect_id", trunIn.getString("sect_id")); + param.put("turnin_sect_code", trunIn.getString("sect_code")); + param.put("turnin_sect_name", trunIn.getString("sect_name")); + param.put("turnin_struct_id", trunIn.getString("struct_id")); + param.put("turnin_struct_code", trunIn.getString("struct_code")); + param.put("turnin_struct_name", trunIn.getString("struct_name")); + param.put("turnout_sect_id", trunOut.getString("sect_id")); + param.put("turnout_sect_code", trunOut.getString("sect_code")); + param.put("turnout_sect_name", trunOut.getString("sect_name")); + param.put("turnout_struct_id", trunOut.getString("struct_id")); + param.put("turnout_struct_code", trunOut.getString("struct_code")); + param.put("turnout_struct_name", trunOut.getString("struct_name")); + param.put("storagevehicle_code", trunOut.getString("storagevehicle_code")); + param.put("work_status", "10"); + param.put("source_billdtl_id", formuladtl_id); + tableData.add(param); + map.put("tableData", tableData); + createMove.add(map); + + // 减去未领重量 + uncla_qty = NumberUtil.sub(uncla_qty, canuse_qty1); + } } else { - // 8.到这一步说明没有进入步骤 2 - // 8.1 查找移入货位,判断物料是否是钴粉 + // 到这一步说明没有进入步骤 2 + // 查找移入货位,判断物料是否是钴粉 if (uncla_qty > 0) { JSONObject moveInIvt2 = new JSONObject(); + if (is_GF) { - moveInIvt2 = WQL.getWO("QPDM_BI_FORMULA02").addParam("flag", "5").addParam("device_id", whereJson.getString("device_id")).process().uniqueResult(0); + if (ObjectUtil.isNotEmpty(moveInNGFArr)) { + moveInIvt2 = moveInGFArr.get(0); + moveInGFArr.remove(0); + } } else { - moveInIvt2 = WQL.getWO("QPDM_BI_FORMULA02").addParam("flag", "9").addParam("device_id", whereJson.getString("device_id")).process().uniqueResult(0); + if (ObjectUtil.isNotEmpty(moveInNGFArr)) { + moveInIvt2 = moveInNGFArr.get(0); + moveInNGFArr.remove(0); + } } + if (ObjectUtil.isNotEmpty(moveInIvt2)) { // 8.2 生成移库单 JSONObject map = new JSONObject(); @@ -346,8 +448,18 @@ public class FlourworkServiceImpl implements FlourworkService { param.put("qty", moveOutIvt.getString("canuse_qty")); param.put("qty_unit_id", moveOutIvt.getString("qty_unit_id")); param.put("quality_scode", moveOutIvt.getString("quality_scode")); - JSONObject trunIn = strucTab.query("struct_code = '" + moveInIvt2.getString("point_code") + "'").uniqueResult(0); - JSONObject trunOut = strucTab.query("struct_code = '" + moveOutIvt.getString("struct_code") + "'").uniqueResult(0); + + JSONObject finalMoveInIvt = moveInIvt2; + JSONObject trunIn = attrArr.stream() + .map(row -> JSON.parseObject(row.toString())) + .filter(row -> row.getString("struct_code").equals(finalMoveInIvt.getString("point_code"))) + .collect(Collectors.toList()).get(0); + + JSONObject trunOut = attrArr.stream() + .map(row -> JSON.parseObject(row.toString())) + .filter(row -> row.getString("struct_code").equals(moveOutIvt.getString("struct_code"))) + .collect(Collectors.toList()).get(0); + param.put("turnin_sect_id", trunIn.getString("sect_id")); param.put("turnin_sect_code", trunIn.getString("sect_code")); param.put("turnin_sect_name", trunIn.getString("sect_name")); @@ -365,25 +477,49 @@ public class FlourworkServiceImpl implements FlourworkService { param.put("source_billdtl_id", formuladtl_id); tableData.add(param); map.put("tableData", tableData); - String moveinv_id = handMoveStorService.insertDtl2(map); - // 6.下发移库单 - JSONObject jsonMoveParam = new JSONObject(); - jsonMoveParam.put("moveinv_id", moveinv_id); - handMoveStorService.handdown(jsonMoveParam); - // 回馈任务数 - taskNum = String.valueOf(NumberUtil.add(taskNum, "1")); + createMove.add(map); } else { arr2.add(String.valueOf(i)); } } } } + + Long currentUserId = SecurityUtils.getCurrentUserId(); + String nickName = SecurityUtils.getNickName(); + // 创建移库单并下发 + ArrayList objects = new ArrayList<>(); + for (JSONObject map : createMove) { + // 移库单创建 + String moveinv_id = handMoveStorService.insertDtl2(map); + // 下发 + JSONObject jsonMoveParam = new JSONObject(); + jsonMoveParam.put("moveinv_id", moveinv_id); + jsonMoveParam.put("currentUserId", currentUserId); + jsonMoveParam.put("nickName", nickName); + objects.add(jsonMoveParam); + + taskNum = String.valueOf(NumberUtil.add(taskNum, "1")); + } if (dtlArr.size() == arr.size()) throw new BadRequestException("叫料失败,此配方明细没有符合的库存"); if (dtlArr.size() == arr2.size()) throw new BadRequestException("叫料失败,配粉间没有空位"); result.put("task", taskNum); + flourworkService.asyncdown(objects); return result; } + @Override + public void asyncdown(ArrayList objects){ + try { + Thread.sleep(500); + } catch (Exception e) { + } + for (JSONObject json : objects) { + handMoveStorService.handdown(json); + } + + } + @Override @Transactional(rollbackFor = Exception.class) public void startWork(JSONObject whereJson) { diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/pf/wql/QPDM_BI_FORMULA02.wql b/mes/hd/nladmin-system/src/main/java/org/nl/wms/pf/wql/QPDM_BI_FORMULA02.wql index e7d97956..e2a4f0ee 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/wms/pf/wql/QPDM_BI_FORMULA02.wql +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/pf/wql/QPDM_BI_FORMULA02.wql @@ -22,6 +22,7 @@ 输入.device_id TYPEAS s_string 输入.formula_id TYPEAS s_string 输入.storagevehicle_id TYPEAS s_string + 输入.point_uuid_in TYPEAS f_string [临时表] @@ -75,6 +76,27 @@ ENDQUERY ENDIF + IF 输入.flag = "11" + QUERY + SELECT + SUM(ivt.canuse_qty) AS canuse_qty, + ivt.material_id, + ivt.pcsn + FROM + ST_IVT_StructIvt ivt + WHERE + 1=1 + + OPTION 输入.point_uuid_in <> "" + ivt.struct_id in 输入.point_uuid_in + ENDOPTION + + group by ivt.material_id,ivt.pcsn + + ENDSELECT + ENDQUERY + ENDIF + IF 输入.flag = "2" QUERY SELECT diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/st/instor/service/HandMoveStorService.java b/mes/hd/nladmin-system/src/main/java/org/nl/wms/st/instor/service/HandMoveStorService.java index 99c0619b..0b142c48 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/wms/st/instor/service/HandMoveStorService.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/st/instor/service/HandMoveStorService.java @@ -3,6 +3,7 @@ package org.nl.wms.st.instor.service; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import org.springframework.data.domain.Pageable; +import org.springframework.scheduling.annotation.Async; import java.util.Map; diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/st/instor/service/impl/HandMoveStorServiceImpl.java b/mes/hd/nladmin-system/src/main/java/org/nl/wms/st/instor/service/impl/HandMoveStorServiceImpl.java index f1488b1c..4becc61f 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/wms/st/instor/service/impl/HandMoveStorServiceImpl.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/st/instor/service/impl/HandMoveStorServiceImpl.java @@ -28,7 +28,9 @@ import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** * PC端出入库新增 @@ -375,6 +377,18 @@ public class HandMoveStorServiceImpl implements HandMoveStorService { //定义返回数据 JSONObject ret = new JSONObject(); + // 点位集合 + List pointList = wo_Point.query("1 = 1").getResultJSONArray(0) + .stream() + .map(row -> JSON.parseObject(row.toString())) + .collect(Collectors.toList()); + + // 任务集合 + List taskList = wo_Task.query("is_delete = '0' and taskdtl_type='07' and task_status='01'") + .getResultJSONArray(0).stream() + .map(row -> JSON.parseObject(row.toString())) + .collect(Collectors.toList()); + Long currentUserId = SecurityUtils.getCurrentUserId(); String nickName = SecurityUtils.getNickName(); String now = DateUtil.now(); @@ -420,14 +434,32 @@ public class HandMoveStorServiceImpl implements HandMoveStorService { jo.put("turnin_struct_id", turnin_struct_id); jo.put("turnin_struct_code", row.getString("turnin_struct_code")); jo.put("turnin_struct_name", row.getString("turnin_struct_name")); + //查询移入点位 - JSONObject point = wo_Point.query("source_id='" + turnin_struct_id + "'").uniqueResult(0); + JSONObject point = new JSONObject(); + List pointArr = pointList.stream() + .filter(a -> a.getString("source_id").equals(turnin_struct_id)) + .collect(Collectors.toList()); + + if (ObjectUtil.isNotEmpty(pointArr)) { + point = pointArr.get(0); + } + +// JSONObject point = wo_Point.query("source_id='" + turnin_struct_id + "'").uniqueResult(0); if (point == null) { throw new BadRequestException(row.getString("turnin_struct_code") + "仓位数据异常,找不到对应点位!"); } + //判断是否已生成过了任务,无未生成则插入任务 - JSONObject task = wo_Task.query("is_delete = '0' and taskdtl_type='07' and task_status='01' and start_point_code='" + jo.getString("start_point_code") + "'").uniqueResult(0); - if (task != null) { + JSONObject task = new JSONObject(); + List taskArr = taskList.stream() + .filter(a -> a.getString("start_point_code").equals(jo.getString("start_point_code"))) + .collect(Collectors.toList()); + if (ObjectUtil.isNotEmpty(taskArr)) { + task = taskArr.get(0); + } + + if (ObjectUtil.isNotEmpty(task)) { jo.put("task_id", task.getString("task_id")); } else { task = new JSONObject(); @@ -455,6 +487,7 @@ public class HandMoveStorServiceImpl implements HandMoveStorService { task.put("priority", "1"); wo_Task.insert(task); jo.put("task_id", task_id); + taskList.add(task); } //插入明细表 wo_dtl.insert(jo); @@ -939,8 +972,8 @@ public class HandMoveStorServiceImpl implements HandMoveStorService { HandMoveStorAcsTask handMoveStorAcsTask = new HandMoveStorAcsTask(); - Long currentUserId = SecurityUtils.getCurrentUserId(); - String nickName = SecurityUtils.getNickName(); + Long currentUserId = whereJson.getLong("currentUserId"); + String nickName = whereJson.getString("nickName"); String now = DateUtil.now(); String moveinv_id = whereJson.getString("moveinv_id"); From 92406223511da31040d15ea599f8b5bff08e74a9 Mon Sep 17 00:00:00 2001 From: zhangzhiqiang Date: Tue, 31 Oct 2023 09:10:51 +0800 Subject: [PATCH 2/2] =?UTF-8?q?rev:=E4=BF=AE=E6=94=B9=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8F=AB=E6=96=99=E9=80=BB=E8=BE=91=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/nl/wms/pf/service/impl/FlourworkServiceImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/pf/service/impl/FlourworkServiceImpl.java b/mes/hd/nladmin-system/src/main/java/org/nl/wms/pf/service/impl/FlourworkServiceImpl.java index 389da3b3..f302c713 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/wms/pf/service/impl/FlourworkServiceImpl.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/pf/service/impl/FlourworkServiceImpl.java @@ -340,7 +340,7 @@ public class FlourworkServiceImpl implements FlourworkService { JSONObject moveInIvt = new JSONObject(); if (is_GF) { - if (ObjectUtil.isNotEmpty(moveInNGFArr)) { + if (ObjectUtil.isNotEmpty(moveInGFArr)) { moveInIvt = moveInGFArr.get(0); moveInGFArr.remove(0); } @@ -418,7 +418,7 @@ public class FlourworkServiceImpl implements FlourworkService { JSONObject moveInIvt2 = new JSONObject(); if (is_GF) { - if (ObjectUtil.isNotEmpty(moveInNGFArr)) { + if (ObjectUtil.isNotEmpty(moveInGFArr)) { moveInIvt2 = moveInGFArr.get(0); moveInGFArr.remove(0); }