Browse Source

抽离组合入库相同方法

lwx_dev
erdanergou 3 years ago
parent
commit
fa9516b7ac
  1. 102
      src/main/java/com/dreamchaser/depository_manage/service/impl/GroupServiceImpl.java

102
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<String, Object> map, UserByPort userToken) {
// 获取当前提交数
List<String> params = (List<String>) map.get("params");
@ -716,38 +716,52 @@ public class GroupServiceImpl implements GroupService {
// 循环参数列表
for (String temp : params) {
Map<String,Object> 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<String, Object> 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 userToken 入库人员
* @param flag 标志是否需要保存入库单号true时不需要false时需要
* @return
*/
Integer insertOrUpdateInventoryForGroupInfo(Map<String,Object> map,UserByPort userToken,boolean flag){
Integer insertOrUpdateInventoryForGroupInfo(Map<String, Object> map, UserByPort userToken, boolean flag) {
// 用于存储申请数
Integer result = 0;
// 定义列表用于储存入库单id
List<Integer> recordIds = new ArrayList<>();
// 定义列表用于存储入库仓库id
List<Integer> depositoryIds = new ArrayList<>();
// 获取入库的仓库
Integer depositoryId = ObjectFormatUtil.toInteger(map.get("depositoryId"));
List<RoleAndDepository> depositoryIdForIn = roleMapper.findRoleAndDepositoryByDepositoryIdForIn(depositoryId);
// 用于标志该仓库是否需要进行审批
boolean flagForApproval = false; // 默认不需要
if (depositoryIdForIn.size() > 0) {
flagForApproval = true; // 需要
}
map.put("flagForApproval", flagForApproval);
// 定义参数用与入库
Map<String,Object> insertForApplicationInRecord = new HashMap<>();
Map<String, Object> 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);
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<Integer> depositoryIdList) {
public Integer insertApplicationOutMinRecord(UserByPort userToken, String code, Object parentId, Integer gid, Integer quantityForGroup, List<Integer> 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;

Loading…
Cancel
Save