Browse Source

组合入库第一次尝试

lwx_dev
erdanergou 3 years ago
parent
commit
277ec25890
  1. 3
      src/main/java/com/dreamchaser/depository_manage/controller/DepositoryRecordController.java
  2. 2
      src/main/java/com/dreamchaser/depository_manage/controller/GroupController.java
  3. 10
      src/main/java/com/dreamchaser/depository_manage/mapper/DepositoryRecordMapper.xml
  4. 5
      src/main/java/com/dreamchaser/depository_manage/pojo/ApplicationInRecordP.java
  5. 1
      src/main/java/com/dreamchaser/depository_manage/pojo/RestResponse.java
  6. 21
      src/main/java/com/dreamchaser/depository_manage/pojo/ResultForGroupReturn.java
  7. 2
      src/main/java/com/dreamchaser/depository_manage/service/GroupService.java
  8. 113
      src/main/java/com/dreamchaser/depository_manage/service/impl/GroupServiceImpl.java
  9. 10
      target/classes/com/dreamchaser/depository_manage/mapper/DepositoryRecordMapper.xml

3
src/main/java/com/dreamchaser/depository_manage/controller/DepositoryRecordController.java

@ -236,7 +236,8 @@ public class DepositoryRecordController {
}
}
}
} else {
}
else {
List<Object> errMsg = new ArrayList<>();
List<Object> successMsg = new ArrayList<>();
for (Integer param : params) {

2
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()));
}

10
src/main/java/com/dreamchaser/depository_manage/mapper/DepositoryRecordMapper.xml

@ -78,6 +78,7 @@
<result column="mdepositoryCode" property="mdepositoryCode" jdbcType="VARCHAR"/>
<result column="airapproverPass" property="airapproverPass" jdbcType="INTEGER"/>
<result column="airapproverTime" property="airapproverTime" jdbcType="INTEGER"/>
<result column="airtoGroupId" property="airtoGroupId" jdbcType="INTEGER"/>
<result column="airmproducedDate" property="mproducedDate" jdbcType="INTEGER"/>
<result column="airapproverId" property="airapproverId" jdbcType="VARCHAR"/>
<result column="airstate" property="airstate" jdbcType="VARCHAR"/>
@ -408,6 +409,7 @@
<if test="endDate != null and endDate != ''">
and applicant_time &lt;= #{endDate}
</if>
and airtoGroupId is null
order by applicant_time desc
@ -459,6 +461,7 @@
<if test="endDate != null and endDate != ''">
and applicant_time &lt;= #{endDate}
</if>
and airtoGroupId is null
</select>
<!--根据条件查询入库记录-->
@ -489,6 +492,7 @@
<if test="code != null and code != ''">
and mcode = #{code}
</if>
and airtoGroupId is null
order by applicant_time desc
<if test="begin != null and size != null">
LIMIT #{begin},#{size}
@ -787,6 +791,7 @@
<if test="applicantTime != null and applicantTime != ''">
and applicant_time >= #{applicantTime}
</if>
and airtoGroupId is null
</select>
<!-- 根据条件查询出库记录数-->
@ -929,7 +934,7 @@
<!-- 插入一条入库记录-->
<insert id="insertApplicationInRecord" parameterType="map" useGeneratedKeys="true" keyProperty="id">
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}
)
</insert>

5
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无需审批
*/

1
src/main/java/com/dreamchaser/depository_manage/pojo/RestResponse.java

@ -18,7 +18,6 @@ import java.util.Map;
/**
* 所有服务统一响应数据格式
* @author 金昊霖
*/
@Accessors(chain = true)
@Data

21
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<Integer> recordIds;
// 定义列表用于存储入库仓库id
List<Integer> depositoryIds;
// 定义列表用于存储展示的入库单id
List<Integer> showRecordIds;
// 用于存储申请数
Integer result;
}

2
src/main/java/com/dreamchaser/depository_manage/service/GroupService.java

@ -197,7 +197,7 @@ public interface GroupService {
* @param map 具体数据
* @return
*/
Integer insertApplicationInRecord(Map<String,Object> map, UserByPort userToken);
Integer insertApplicationInRecord(Map<String,Object> map, UserByPort userToken,String userAgent);
/**

113
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<String, Object> map, UserByPort userToken) {
public Integer insertApplicationInRecord(Map<String, Object> map, UserByPort userToken,String userAgent) {
// 获取当前提交数
@ -713,6 +718,14 @@ public class GroupServiceImpl implements GroupService {
// 用于存储申请数
Integer result = 0;
// 定义列表用于储存入库单id
List<Integer> recordIds = new ArrayList<>();
// 定义列表用于存储入库仓库id
List<Integer> depositoryIds = new ArrayList<>();
// 定义列表用于存储展示的入库单id
List<Integer> 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<Integer, List<Integer>> 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<Integer> integers = depositoryIdToRecordId.get(depositoryId);
if (integers != null) {
// 如果有对应关系
integers.add(recordId);
} else {
// 如果没有
integers = new ArrayList<>();
integers.add(recordId);
depositoryIdToRecordId.put(depositoryId, integers);
}
}
}
// 获取遍历器
Iterator<Integer> iterator = depositoryIdToRecordId.keySet().iterator();
if (iterator.hasNext()) {
// 获取当前仓库
Integer next = iterator.next();
// 获取入库到当前仓库的订单id
List<Integer> integerList = depositoryIdToRecordId.get(next);
// 获取当前仓库的管理员
List<RoleAndDepository> 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<String, Object> 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<String, Object> map, UserByPort userToken, boolean flag) {
ResultForGroupReturn insertOrUpdateInventoryForGroupInfo(Map<String, Object> map, UserByPort userToken) {
// 用于存储申请数
Integer result = 0;
@ -746,7 +835,8 @@ public class GroupServiceImpl implements GroupService {
List<Integer> recordIds = new ArrayList<>();
// 定义列表用于存储入库仓库id
List<Integer> depositoryIds = new ArrayList<>();
// 定义列表用于存储展示的入库单id
List<Integer> showRecordIds = new ArrayList<>();
// 获取入库的仓库
Integer depositoryId = ObjectFormatUtil.toInteger(map.get("depositoryId"));
@ -763,7 +853,6 @@ public class GroupServiceImpl implements GroupService {
// 定义参数用与入库
Map<String, Object> 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;
}
/**

10
target/classes/com/dreamchaser/depository_manage/mapper/DepositoryRecordMapper.xml

@ -78,6 +78,7 @@
<result column="mdepositoryCode" property="mdepositoryCode" jdbcType="VARCHAR"/>
<result column="airapproverPass" property="airapproverPass" jdbcType="INTEGER"/>
<result column="airapproverTime" property="airapproverTime" jdbcType="INTEGER"/>
<result column="airtoGroupId" property="airtoGroupId" jdbcType="INTEGER"/>
<result column="airmproducedDate" property="mproducedDate" jdbcType="INTEGER"/>
<result column="airapproverId" property="airapproverId" jdbcType="VARCHAR"/>
<result column="airstate" property="airstate" jdbcType="VARCHAR"/>
@ -408,6 +409,7 @@
<if test="endDate != null and endDate != ''">
and applicant_time &lt;= #{endDate}
</if>
and airtoGroupId is null
order by applicant_time desc
@ -459,6 +461,7 @@
<if test="endDate != null and endDate != ''">
and applicant_time &lt;= #{endDate}
</if>
and airtoGroupId is null
</select>
<!--根据条件查询入库记录-->
@ -489,6 +492,7 @@
<if test="code != null and code != ''">
and mcode = #{code}
</if>
and airtoGroupId is null
order by applicant_time desc
<if test="begin != null and size != null">
LIMIT #{begin},#{size}
@ -787,6 +791,7 @@
<if test="applicantTime != null and applicantTime != ''">
and applicant_time >= #{applicantTime}
</if>
and airtoGroupId is null
</select>
<!-- 根据条件查询出库记录数-->
@ -929,7 +934,7 @@
<!-- 插入一条入库记录-->
<insert id="insertApplicationInRecord" parameterType="map" useGeneratedKeys="true" keyProperty="id">
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}
)
</insert>

Loading…
Cancel
Save