From fa9516b7ac97541c7bd2b7220bf97ef84f7461be Mon Sep 17 00:00:00 2001 From: erdanergou Date: Wed, 22 Feb 2023 15:21:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=BD=E7=A6=BB=E7=BB=84=E5=90=88=E5=85=A5?= =?UTF-8?q?=E5=BA=93=E7=9B=B8=E5=90=8C=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/GroupServiceImpl.java | 108 +++++++++++------- 1 file changed, 68 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/dreamchaser/depository_manage/service/impl/GroupServiceImpl.java b/src/main/java/com/dreamchaser/depository_manage/service/impl/GroupServiceImpl.java index 3d50068c..86e5fdf5 100644 --- a/src/main/java/com/dreamchaser/depository_manage/service/impl/GroupServiceImpl.java +++ b/src/main/java/com/dreamchaser/depository_manage/service/impl/GroupServiceImpl.java @@ -666,7 +666,7 @@ public class GroupServiceImpl implements GroupService { parentId = paramForOut.get("id"); // 插入子订单 - result += insertApplicationOutMinRecord(userToken, code, parentId, gid, quantityForGroup,depositoryIdList); + result += insertApplicationOutMinRecord(userToken, code, parentId, gid, quantityForGroup, depositoryIdList); if (params != null && params.size() > 0) { // 如果提交的不是单个 @@ -688,7 +688,7 @@ public class GroupServiceImpl implements GroupService { quantityForTotal += quantityForGroup * groupInfo.getQuantity(); priceForTotal += inventory.get(0).getPrice() * 100 * quantityForGroup; } - result += insertApplicationOutMinRecord(userToken, code, parentId, gid, quantityForGroup,depositoryIdList); + result += insertApplicationOutMinRecord(userToken, code, parentId, gid, quantityForGroup, depositoryIdList); } } @@ -698,6 +698,7 @@ public class GroupServiceImpl implements GroupService { /** * 插入一条入库记录 + * * @param map 具体数据 * @return */ @@ -706,7 +707,6 @@ public class GroupServiceImpl implements GroupService { public Integer insertApplicationInRecord(Map map, UserByPort userToken) { - // 获取当前提交数 List params = (List) map.get("params"); @@ -716,38 +716,52 @@ public class GroupServiceImpl implements GroupService { // 循环参数列表 for (String temp : params) { - Map paramForMethod = new HashMap<>(); - paramForMethod.put("quantity",map.get("quantity" + temp)); - paramForMethod.put("gid",map.get("gid" + temp)); - paramForMethod.put("placeId",map.get("placeId" + temp)); - paramForMethod.put("depositoryId",map.get("depositoryId" + temp)); - paramForMethod.put("applyRemark",map.get("applyRemark" + temp)); - result += insertOrUpdateInventoryForGroupInfo(paramForMethod,userToken,true); + Map paramForMethod = new HashMap<>(); + paramForMethod.put("quantity", map.get("quantity" + temp)); + paramForMethod.put("gid", map.get("gid" + temp)); + paramForMethod.put("placeId", map.get("placeId" + temp)); + paramForMethod.put("depositoryId", map.get("depositoryId" + temp)); + paramForMethod.put("applyRemark", map.get("applyRemark" + temp)); + result += insertOrUpdateInventoryForGroupInfo(paramForMethod, userToken, true); } - result += insertOrUpdateInventoryForGroupInfo(map,userToken,false); + result += insertOrUpdateInventoryForGroupInfo(map, userToken, false); return result; } /** * 用于处理组合入库时的库位 - * @param map 入库数据 + * + * @param map 入库数据 * @param userToken 入库人员 - * @param flag 标志是否需要保存入库单号(true时不需要,false时需要) + * @param flag 标志是否需要保存入库单号(true时不需要,false时需要) * @return */ - Integer insertOrUpdateInventoryForGroupInfo(Map map,UserByPort userToken,boolean flag){ + Integer insertOrUpdateInventoryForGroupInfo(Map map, UserByPort userToken, boolean flag) { // 用于存储申请数 Integer result = 0; + // 定义列表用于储存入库单id + List recordIds = new ArrayList<>(); + // 定义列表用于存储入库仓库id + List depositoryIds = new ArrayList<>(); + // 获取入库的仓库 Integer depositoryId = ObjectFormatUtil.toInteger(map.get("depositoryId")); + List depositoryIdForIn = roleMapper.findRoleAndDepositoryByDepositoryIdForIn(depositoryId); + + // 用于标志该仓库是否需要进行审批 + boolean flagForApproval = false; // 默认不需要 + if (depositoryIdForIn.size() > 0) { + flagForApproval = true; // 需要 + } + map.put("flagForApproval", flagForApproval); // 定义参数用与入库 - Map insertForApplicationInRecord = new HashMap<>(); + Map insertForApplicationInRecord = new HashMap<>(); insertForApplicationInRecord.put("applicantId", userToken.getId()); @@ -765,8 +779,8 @@ public class GroupServiceImpl implements GroupService { Integer placeId = ObjectFormatUtil.toInteger(map.get("placeId")); - insertForApplicationInRecord.put("depositoryId",depositoryId); - insertForApplicationInRecord.put("placeId",placeId); + insertForApplicationInRecord.put("depositoryId", depositoryId); + insertForApplicationInRecord.put("placeId", placeId); insertForApplicationInRecord.put("applyRemark", map.get("applyRemark")); // 循环当前组合信息 @@ -774,39 +788,53 @@ public class GroupServiceImpl implements GroupService { groupInfoByGid) { // 获取当前组合记录中的单位 String unit = groupInfo.getUnit(); - insertForApplicationInRecord.put("mid",groupInfo.getMid()); - insertForApplicationInRecord.put("quantity",String.valueOf(groupInfo.getQuantity() * quantityForGroup)); - insertForApplicationInRecord.put("code",groupInfo.getMcode()); - if("-1".equals(unit)){ + insertForApplicationInRecord.put("mid", groupInfo.getMid()); + insertForApplicationInRecord.put("quantity", String.valueOf(groupInfo.getQuantity() * quantityForGroup)); + insertForApplicationInRecord.put("code", groupInfo.getMcode()); + if ("-1".equals(unit)) { // 如果是基础单位 insertForApplicationInRecord.put("price", String.valueOf(0)); Material material = materialMapper.findMaterialById(groupInfo.getMid()); - insertForApplicationInRecord.put("unit",material.getUnit()); - result += depositoryRecordService.applicationInPlace(insertForApplicationInRecord,false); - depositoryRecordMapper.deleteApplicationInRecordById(ObjectFormatUtil.toInteger(insertForApplicationInRecord.get("id"))); - }else{ + insertForApplicationInRecord.put("unit", material.getUnit()); + result += depositoryRecordService.applicationInPlace(insertForApplicationInRecord, false); + if (!flagForApproval) { + // 当不需要审批时删除冗余订单 + depositoryRecordMapper.deleteApplicationInRecordById(ObjectFormatUtil.toInteger(insertForApplicationInRecord.get("applicationInId"))); + } else { + // 如果需要将其添加到列表中待后续使用 + recordIds.add(ObjectFormatUtil.toInteger(map.get("applicationInId"))); + depositoryIds.add(ObjectFormatUtil.toInteger(map.get("depositoryId"))); + } + } else { insertForApplicationInRecord.put("price", String.valueOf(0)); - insertForApplicationInRecord.put("unit",unit); - insertForApplicationInRecord.put("type","in"); + insertForApplicationInRecord.put("unit", unit); + insertForApplicationInRecord.put("type", "in"); result += splitUnitService.addSplitInventory(insertForApplicationInRecord); - depositoryRecordMapper.deleteApplicationInRecordById(ObjectFormatUtil.toInteger(insertForApplicationInRecord.get("applicationInId"))); + if (!flagForApproval) { + // 当不需要审批时删除冗余订单 + depositoryRecordMapper.deleteApplicationInRecordById(ObjectFormatUtil.toInteger(insertForApplicationInRecord.get("applicationInId"))); + } else { + // 如果需要将其添加到列表中待后续使用 + recordIds.add(ObjectFormatUtil.toInteger(map.get("applicationInId"))); + depositoryIds.add(ObjectFormatUtil.toInteger(map.get("depositoryId"))); + } insertForApplicationInRecord.remove("applicationInId"); } } - insertForApplicationInRecord.put("flagForGroup",2); - insertForApplicationInRecord.put("quantity",quantityForGroup.toString()); - insertForApplicationInRecord.put("mid",gid); - insertForApplicationInRecord.put("unit",-1); + + insertForApplicationInRecord.put("flagForGroup", 2); + insertForApplicationInRecord.put("quantity", quantityForGroup.toString()); + insertForApplicationInRecord.put("mid", gid); + insertForApplicationInRecord.put("unit", -1); Depository depository = depositoryMapper.findDepositoryById(depositoryId); - insertForApplicationInRecord.put("code",depositoryRecordService.createCode(depository.getDname(), "InOrderNumber", "in", "")); - insertForApplicationInRecord.put("applicant_time",System.currentTimeMillis()); + insertForApplicationInRecord.put("code", depositoryRecordService.createCode(depository.getDname(), "InOrderNumber", "in", "")); + insertForApplicationInRecord.put("applicant_time", System.currentTimeMillis()); + // 添加一个组合订单用于展示 depositoryRecordMapper.insertApplicationInRecord(insertForApplicationInRecord); - if(!flag){ - depositoryRecordMapper.deleteApplicationInRecordById(ObjectFormatUtil.toInteger(insertForApplicationInRecord.get("applicationInId"))); - insertForApplicationInRecord.remove("applicationInId"); - } + insertForApplicationInRecord.remove("id"); return result; } + /** * 用于插入子出库订单 * @@ -818,7 +846,7 @@ public class GroupServiceImpl implements GroupService { * @return */ @Transactional(rollbackFor = Exception.class) - public Integer insertApplicationOutMinRecord(UserByPort userToken, String code, Object parentId, Integer gid, Integer quantityForGroup,List depositoryIdList) { + public Integer insertApplicationOutMinRecord(UserByPort userToken, String code, Object parentId, Integer gid, Integer quantityForGroup, List depositoryIdList) { // 用于存储申请数 Integer result = 0; @@ -851,7 +879,7 @@ public class GroupServiceImpl implements GroupService { paramForInventory.put("did", depositoryId); // 获取对应库存 Inventory inventoryByMidAndDid = materialMapper.findInventoryByMidAndDid(paramForInventory); - if(inventoryByMidAndDid != null) { + if (inventoryByMidAndDid != null) { if (inventoryByMidAndDid.getQuantity() >= quantity) { // 如果当前库存充足 did = depositoryId;