From 277ec2589068fb48ead62082455628307c36fff3 Mon Sep 17 00:00:00 2001 From: erdanergou Date: Wed, 22 Feb 2023 15:55:51 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=84=E5=90=88=E5=85=A5=E5=BA=93=E7=AC=AC?= =?UTF-8?q?=E4=B8=80=E6=AC=A1=E5=B0=9D=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DepositoryRecordController.java | 3 +- .../controller/GroupController.java | 2 +- .../mapper/DepositoryRecordMapper.xml | 10 +- .../pojo/ApplicationInRecordP.java | 5 + .../depository_manage/pojo/RestResponse.java | 1 - .../pojo/ResultForGroupReturn.java | 21 ++++ .../service/GroupService.java | 2 +- .../service/impl/GroupServiceImpl.java | 113 ++++++++++++++++-- .../mapper/DepositoryRecordMapper.xml | 10 +- 9 files changed, 151 insertions(+), 16 deletions(-) create mode 100644 src/main/java/com/dreamchaser/depository_manage/pojo/ResultForGroupReturn.java diff --git a/src/main/java/com/dreamchaser/depository_manage/controller/DepositoryRecordController.java b/src/main/java/com/dreamchaser/depository_manage/controller/DepositoryRecordController.java index 70ff3367..ff899cf2 100644 --- a/src/main/java/com/dreamchaser/depository_manage/controller/DepositoryRecordController.java +++ b/src/main/java/com/dreamchaser/depository_manage/controller/DepositoryRecordController.java @@ -236,7 +236,8 @@ public class DepositoryRecordController { } } } - } else { + } + else { List errMsg = new ArrayList<>(); List successMsg = new ArrayList<>(); for (Integer param : params) { diff --git a/src/main/java/com/dreamchaser/depository_manage/controller/GroupController.java b/src/main/java/com/dreamchaser/depository_manage/controller/GroupController.java index 79fa1a82..16123f25 100644 --- a/src/main/java/com/dreamchaser/depository_manage/controller/GroupController.java +++ b/src/main/java/com/dreamchaser/depository_manage/controller/GroupController.java @@ -540,7 +540,7 @@ public class GroupController { } } try { - integer += groupService.insertApplicationInRecord(map, userToken); // 插入主订单 + integer += groupService.insertApplicationInRecord(map, userToken,crypt); // 插入主订单 } catch (Exception e) { return new RestResponse("", 666, new StatusInfo("出库失败", e.getMessage())); } diff --git a/src/main/java/com/dreamchaser/depository_manage/mapper/DepositoryRecordMapper.xml b/src/main/java/com/dreamchaser/depository_manage/mapper/DepositoryRecordMapper.xml index 1574f941..dda12b67 100644 --- a/src/main/java/com/dreamchaser/depository_manage/mapper/DepositoryRecordMapper.xml +++ b/src/main/java/com/dreamchaser/depository_manage/mapper/DepositoryRecordMapper.xml @@ -78,6 +78,7 @@ + @@ -408,6 +409,7 @@ and applicant_time <= #{endDate} + and airtoGroupId is null order by applicant_time desc @@ -459,6 +461,7 @@ and applicant_time <= #{endDate} + and airtoGroupId is null @@ -489,6 +492,7 @@ and mcode = #{code} + and airtoGroupId is null order by applicant_time desc LIMIT #{begin},#{size} @@ -787,6 +791,7 @@ and applicant_time >= #{applicantTime} + and airtoGroupId is null @@ -929,7 +934,7 @@ - insert into application_in_record (id,mid,quantity,price,applicant_id,applicant_time,depository_id,code,applyRemark,unit,flagForGroup,placeId,approverPass,approverTime,approverId,state,approverMessage,mproducedDate) + insert into application_in_record (id,mid,quantity,price,applicant_id,applicant_time,depository_id,code,applyRemark,unit,flagForGroup,placeId,approverPass,approverTime,approverId,state,approverMessage,mproducedDate,toGroupId) values( #{id}, #{mid}, @@ -948,7 +953,8 @@ #{approverId}, #{state}, #{approverMessage}, - #{producedDate} + #{producedDate}, + #{toGroupId} ) diff --git a/src/main/java/com/dreamchaser/depository_manage/pojo/ApplicationInRecordP.java b/src/main/java/com/dreamchaser/depository_manage/pojo/ApplicationInRecordP.java index 7bed6609..944fcbde 100644 --- a/src/main/java/com/dreamchaser/depository_manage/pojo/ApplicationInRecordP.java +++ b/src/main/java/com/dreamchaser/depository_manage/pojo/ApplicationInRecordP.java @@ -112,6 +112,11 @@ public class ApplicationInRecordP { */ private Integer placeId; + /** + * 用于标志该物料入库记录是那个组合下的入库记录 + */ + private Integer airtoGroupId; + /** * 1通过2驳回3待审批4无需审批 */ diff --git a/src/main/java/com/dreamchaser/depository_manage/pojo/RestResponse.java b/src/main/java/com/dreamchaser/depository_manage/pojo/RestResponse.java index 3e09e19d..69ea6a0c 100644 --- a/src/main/java/com/dreamchaser/depository_manage/pojo/RestResponse.java +++ b/src/main/java/com/dreamchaser/depository_manage/pojo/RestResponse.java @@ -18,7 +18,6 @@ import java.util.Map; /** * 所有服务统一响应数据格式 - * @author 金昊霖 */ @Accessors(chain = true) @Data diff --git a/src/main/java/com/dreamchaser/depository_manage/pojo/ResultForGroupReturn.java b/src/main/java/com/dreamchaser/depository_manage/pojo/ResultForGroupReturn.java new file mode 100644 index 00000000..c5d4a133 --- /dev/null +++ b/src/main/java/com/dreamchaser/depository_manage/pojo/ResultForGroupReturn.java @@ -0,0 +1,21 @@ +package com.dreamchaser.depository_manage.pojo; + +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +/** + * 该类专用于组合入库时存储一些用于发送审批的数据审批 + */ +@Data +public class ResultForGroupReturn { + // 定义列表用于储存入库单id + List recordIds; + // 定义列表用于存储入库仓库id + List depositoryIds; + // 定义列表用于存储展示的入库单id + List showRecordIds; + // 用于存储申请数 + Integer result; +} diff --git a/src/main/java/com/dreamchaser/depository_manage/service/GroupService.java b/src/main/java/com/dreamchaser/depository_manage/service/GroupService.java index 895642ce..b9e3ecae 100644 --- a/src/main/java/com/dreamchaser/depository_manage/service/GroupService.java +++ b/src/main/java/com/dreamchaser/depository_manage/service/GroupService.java @@ -197,7 +197,7 @@ public interface GroupService { * @param map 具体数据 * @return */ - Integer insertApplicationInRecord(Map map, UserByPort userToken); + Integer insertApplicationInRecord(Map map, UserByPort userToken,String userAgent); /** 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 86e5fdf5..6e6c1b1d 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 @@ -1,10 +1,12 @@ package com.dreamchaser.depository_manage.service.impl; +import com.alibaba.fastjson.JSONObject; import com.dreamchaser.depository_manage.entity.*; import com.dreamchaser.depository_manage.exception.MyException; import com.dreamchaser.depository_manage.mapper.*; import com.dreamchaser.depository_manage.pojo.GroupInfoP; import com.dreamchaser.depository_manage.pojo.MaterialAndPlaceForView; +import com.dreamchaser.depository_manage.pojo.ResultForGroupReturn; import com.dreamchaser.depository_manage.pojo.RoleAndDepository; import com.dreamchaser.depository_manage.service.DepositoryRecordService; import com.dreamchaser.depository_manage.service.GroupService; @@ -57,6 +59,9 @@ public class GroupServiceImpl implements GroupService { @Autowired RoleMapper roleMapper; + @Autowired + QyWxOperationService qyWxOperationService; + /** * 用于查找所有组合 * @@ -704,7 +709,7 @@ public class GroupServiceImpl implements GroupService { */ @Transactional(rollbackFor = Exception.class) @Override - public Integer insertApplicationInRecord(Map map, UserByPort userToken) { + public Integer insertApplicationInRecord(Map map, UserByPort userToken,String userAgent) { // 获取当前提交数 @@ -713,6 +718,14 @@ public class GroupServiceImpl implements GroupService { // 用于存储申请数 Integer result = 0; + + // 定义列表用于储存入库单id + List recordIds = new ArrayList<>(); + // 定义列表用于存储入库仓库id + List depositoryIds = new ArrayList<>(); + // 定义列表用于存储展示的入库单id + List showRecordIds = new ArrayList<>(); + // 循环参数列表 for (String temp : params) { @@ -722,10 +735,87 @@ public class GroupServiceImpl implements GroupService { 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); + ResultForGroupReturn resultForGroupReturn = insertOrUpdateInventoryForGroupInfo(paramForMethod, userToken); + // 添加当前入库数目 + result += resultForGroupReturn.getResult(); + // 获取需要审批的入库订单 + recordIds.addAll(resultForGroupReturn.getRecordIds()); + // 获取需要审批的入库订单的仓库 + depositoryIds.addAll(resultForGroupReturn.getDepositoryIds()); + // 获取用于展示的入库订单 + showRecordIds.addAll(resultForGroupReturn.getShowRecordIds()); } - result += insertOrUpdateInventoryForGroupInfo(map, userToken, false); + ResultForGroupReturn resultForGroupReturn = insertOrUpdateInventoryForGroupInfo(map, userToken); + // 添加当前入库数目 + result += resultForGroupReturn.getResult(); + // 获取需要审批的入库订单 + recordIds.addAll(resultForGroupReturn.getRecordIds()); + // 获取需要审批的入库订单的仓库 + depositoryIds.addAll(resultForGroupReturn.getDepositoryIds()); + // 获取用于展示的入库订单 + showRecordIds.addAll(resultForGroupReturn.getShowRecordIds()); + + + // 开启一个线程用于发送审批 + new Thread(new Runnable() { + @Override + public void run() { + Map> depositoryIdToRecordId = new HashMap<>(); + for (int i = 0; i < recordIds.size(); i++) { + Integer recordId = recordIds.get(i); + if (recordId != null) { + // 如果当前id不是空 获取对应的入库仓库id + Integer depositoryId = depositoryIds.get(i); + // 将对应仓库与订单id添加映射关系 + List integers = depositoryIdToRecordId.get(depositoryId); + if (integers != null) { + // 如果有对应关系 + integers.add(recordId); + } else { + // 如果没有 + integers = new ArrayList<>(); + integers.add(recordId); + depositoryIdToRecordId.put(depositoryId, integers); + } + } + } + // 获取遍历器 + Iterator iterator = depositoryIdToRecordId.keySet().iterator(); + if (iterator.hasNext()) { + // 获取当前仓库 + Integer next = iterator.next(); + // 获取入库到当前仓库的订单id + List integerList = depositoryIdToRecordId.get(next); + // 获取当前仓库的管理员 + List depositoryIdForIn = roleMapper.findRoleAndDepositoryByDepositoryIdForIn(next); + // 用于存储当前仓库的管理员企业微信userId + StringBuilder sb = new StringBuilder(); + for (RoleAndDepository depository : depositoryIdForIn + ) { + // 获取管理员数据 + UserByPort userByPort = LinkInterfaceUtil.FindUserById(depository.getUserId(), userToken); + String workwechat = userByPort.getWorkwechat(); + if (workwechat == null || "".equals(workwechat)) { + workwechat = userByPort.getWechat(); + } + sb.append(workwechat).append(","); + } + JSONObject jsonObject = qyWxOperationService.sendApprovalTemplateIn(userAgent, userToken, integerList, sb.toString()); + String sp_no = jsonObject.getString("sp_no"); + Map QyWxApprovalMap = new HashMap<>(); + QyWxApprovalMap.put("sp_no", sp_no); + QyWxApprovalMap.put("mainId", integerList.toString()); + QyWxApprovalMap.put("mainGidId", showRecordIds.toString()); + redisTemplate.opsForHash().putAll(sp_no, QyWxApprovalMap); + // 设置过期为7天 + redisTemplate.expire(sp_no, 7, TimeUnit.DAYS); + + } + + } + }).start(); + return result; } @@ -735,10 +825,9 @@ public class GroupServiceImpl implements GroupService { * * @param map 入库数据 * @param userToken 入库人员 - * @param flag 标志是否需要保存入库单号(true时不需要,false时需要) * @return */ - Integer insertOrUpdateInventoryForGroupInfo(Map map, UserByPort userToken, boolean flag) { + ResultForGroupReturn insertOrUpdateInventoryForGroupInfo(Map map, UserByPort userToken) { // 用于存储申请数 Integer result = 0; @@ -746,7 +835,8 @@ public class GroupServiceImpl implements GroupService { List recordIds = new ArrayList<>(); // 定义列表用于存储入库仓库id List depositoryIds = new ArrayList<>(); - + // 定义列表用于存储展示的入库单id + List showRecordIds = new ArrayList<>(); // 获取入库的仓库 Integer depositoryId = ObjectFormatUtil.toInteger(map.get("depositoryId")); @@ -763,7 +853,6 @@ public class GroupServiceImpl implements GroupService { // 定义参数用与入库 Map insertForApplicationInRecord = new HashMap<>(); - insertForApplicationInRecord.put("applicantId", userToken.getId()); // 获取当前入库的组合数量 @@ -791,6 +880,7 @@ public class GroupServiceImpl implements GroupService { insertForApplicationInRecord.put("mid", groupInfo.getMid()); insertForApplicationInRecord.put("quantity", String.valueOf(groupInfo.getQuantity() * quantityForGroup)); insertForApplicationInRecord.put("code", groupInfo.getMcode()); + insertForApplicationInRecord.put("toGroupId",gid); if ("-1".equals(unit)) { // 如果是基础单位 insertForApplicationInRecord.put("price", String.valueOf(0)); @@ -831,8 +921,15 @@ public class GroupServiceImpl implements GroupService { insertForApplicationInRecord.put("applicant_time", System.currentTimeMillis()); // 添加一个组合订单用于展示 depositoryRecordMapper.insertApplicationInRecord(insertForApplicationInRecord); + showRecordIds.add(ObjectFormatUtil.toInteger(insertForApplicationInRecord.get("id"))); insertForApplicationInRecord.remove("id"); - return result; + + ResultForGroupReturn resultForGroupReturn = new ResultForGroupReturn(); + resultForGroupReturn.setRecordIds(recordIds); + resultForGroupReturn.setDepositoryIds(depositoryIds); + resultForGroupReturn.setShowRecordIds(showRecordIds); + resultForGroupReturn.setResult(result); + return resultForGroupReturn; } /** diff --git a/target/classes/com/dreamchaser/depository_manage/mapper/DepositoryRecordMapper.xml b/target/classes/com/dreamchaser/depository_manage/mapper/DepositoryRecordMapper.xml index 1574f941..dda12b67 100644 --- a/target/classes/com/dreamchaser/depository_manage/mapper/DepositoryRecordMapper.xml +++ b/target/classes/com/dreamchaser/depository_manage/mapper/DepositoryRecordMapper.xml @@ -78,6 +78,7 @@ + @@ -408,6 +409,7 @@ and applicant_time <= #{endDate} + and airtoGroupId is null order by applicant_time desc @@ -459,6 +461,7 @@ and applicant_time <= #{endDate} + and airtoGroupId is null @@ -489,6 +492,7 @@ and mcode = #{code} + and airtoGroupId is null order by applicant_time desc LIMIT #{begin},#{size} @@ -787,6 +791,7 @@ and applicant_time >= #{applicantTime} + and airtoGroupId is null @@ -929,7 +934,7 @@ - insert into application_in_record (id,mid,quantity,price,applicant_id,applicant_time,depository_id,code,applyRemark,unit,flagForGroup,placeId,approverPass,approverTime,approverId,state,approverMessage,mproducedDate) + insert into application_in_record (id,mid,quantity,price,applicant_id,applicant_time,depository_id,code,applyRemark,unit,flagForGroup,placeId,approverPass,approverTime,approverId,state,approverMessage,mproducedDate,toGroupId) values( #{id}, #{mid}, @@ -948,7 +953,8 @@ #{approverId}, #{state}, #{approverMessage}, - #{producedDate} + #{producedDate}, + #{toGroupId} )