Browse Source

抽离组合入库相同方法

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

108
src/main/java/com/dreamchaser/depository_manage/service/impl/GroupServiceImpl.java

@ -666,7 +666,7 @@ public class GroupServiceImpl implements GroupService {
parentId = paramForOut.get("id"); 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) { if (params != null && params.size() > 0) {
// 如果提交的不是单个 // 如果提交的不是单个
@ -688,7 +688,7 @@ public class GroupServiceImpl implements GroupService {
quantityForTotal += quantityForGroup * groupInfo.getQuantity(); quantityForTotal += quantityForGroup * groupInfo.getQuantity();
priceForTotal += inventory.get(0).getPrice() * 100 * quantityForGroup; 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 具体数据 * @param map 具体数据
* @return * @return
*/ */
@ -706,7 +707,6 @@ public class GroupServiceImpl implements GroupService {
public Integer insertApplicationInRecord(Map<String, Object> map, UserByPort userToken) { public Integer insertApplicationInRecord(Map<String, Object> map, UserByPort userToken) {
// 获取当前提交数 // 获取当前提交数
List<String> params = (List<String>) map.get("params"); List<String> params = (List<String>) map.get("params");
@ -716,38 +716,52 @@ public class GroupServiceImpl implements GroupService {
// 循环参数列表 // 循环参数列表
for (String temp : params) { for (String temp : params) {
Map<String,Object> paramForMethod = new HashMap<>(); Map<String, Object> paramForMethod = new HashMap<>();
paramForMethod.put("quantity",map.get("quantity" + temp)); paramForMethod.put("quantity", map.get("quantity" + temp));
paramForMethod.put("gid",map.get("gid" + temp)); paramForMethod.put("gid", map.get("gid" + temp));
paramForMethod.put("placeId",map.get("placeId" + temp)); paramForMethod.put("placeId", map.get("placeId" + temp));
paramForMethod.put("depositoryId",map.get("depositoryId" + temp)); paramForMethod.put("depositoryId", map.get("depositoryId" + temp));
paramForMethod.put("applyRemark",map.get("applyRemark" + temp)); paramForMethod.put("applyRemark", map.get("applyRemark" + temp));
result += insertOrUpdateInventoryForGroupInfo(paramForMethod,userToken,true); result += insertOrUpdateInventoryForGroupInfo(paramForMethod, userToken, true);
} }
result += insertOrUpdateInventoryForGroupInfo(map,userToken,false); result += insertOrUpdateInventoryForGroupInfo(map, userToken, false);
return result; return result;
} }
/** /**
* 用于处理组合入库时的库位 * 用于处理组合入库时的库位
* @param map 入库数据 *
* @param map 入库数据
* @param userToken 入库人员 * @param userToken 入库人员
* @param flag 标志是否需要保存入库单号true时不需要false时需要 * @param flag 标志是否需要保存入库单号true时不需要false时需要
* @return * @return
*/ */
Integer insertOrUpdateInventoryForGroupInfo(Map<String,Object> map,UserByPort userToken,boolean flag){ Integer insertOrUpdateInventoryForGroupInfo(Map<String, Object> map, UserByPort userToken, boolean flag) {
// 用于存储申请数 // 用于存储申请数
Integer result = 0; Integer result = 0;
// 定义列表用于储存入库单id
List<Integer> recordIds = new ArrayList<>();
// 定义列表用于存储入库仓库id
List<Integer> depositoryIds = new ArrayList<>();
// 获取入库的仓库 // 获取入库的仓库
Integer depositoryId = ObjectFormatUtil.toInteger(map.get("depositoryId")); 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()); insertForApplicationInRecord.put("applicantId", userToken.getId());
@ -765,8 +779,8 @@ public class GroupServiceImpl implements GroupService {
Integer placeId = ObjectFormatUtil.toInteger(map.get("placeId")); Integer placeId = ObjectFormatUtil.toInteger(map.get("placeId"));
insertForApplicationInRecord.put("depositoryId",depositoryId); insertForApplicationInRecord.put("depositoryId", depositoryId);
insertForApplicationInRecord.put("placeId",placeId); insertForApplicationInRecord.put("placeId", placeId);
insertForApplicationInRecord.put("applyRemark", map.get("applyRemark")); insertForApplicationInRecord.put("applyRemark", map.get("applyRemark"));
// 循环当前组合信息 // 循环当前组合信息
@ -774,39 +788,53 @@ public class GroupServiceImpl implements GroupService {
groupInfoByGid) { groupInfoByGid) {
// 获取当前组合记录中的单位 // 获取当前组合记录中的单位
String unit = groupInfo.getUnit(); String unit = groupInfo.getUnit();
insertForApplicationInRecord.put("mid",groupInfo.getMid()); insertForApplicationInRecord.put("mid", groupInfo.getMid());
insertForApplicationInRecord.put("quantity",String.valueOf(groupInfo.getQuantity() * quantityForGroup)); insertForApplicationInRecord.put("quantity", String.valueOf(groupInfo.getQuantity() * quantityForGroup));
insertForApplicationInRecord.put("code",groupInfo.getMcode()); insertForApplicationInRecord.put("code", groupInfo.getMcode());
if("-1".equals(unit)){ if ("-1".equals(unit)) {
// 如果是基础单位 // 如果是基础单位
insertForApplicationInRecord.put("price", String.valueOf(0)); insertForApplicationInRecord.put("price", String.valueOf(0));
Material material = materialMapper.findMaterialById(groupInfo.getMid()); Material material = materialMapper.findMaterialById(groupInfo.getMid());
insertForApplicationInRecord.put("unit",material.getUnit()); insertForApplicationInRecord.put("unit", material.getUnit());
result += depositoryRecordService.applicationInPlace(insertForApplicationInRecord,false); result += depositoryRecordService.applicationInPlace(insertForApplicationInRecord, false);
depositoryRecordMapper.deleteApplicationInRecordById(ObjectFormatUtil.toInteger(insertForApplicationInRecord.get("id"))); if (!flagForApproval) {
}else{ // 当不需要审批时删除冗余订单
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("price", String.valueOf(0));
insertForApplicationInRecord.put("unit",unit); insertForApplicationInRecord.put("unit", unit);
insertForApplicationInRecord.put("type","in"); insertForApplicationInRecord.put("type", "in");
result += splitUnitService.addSplitInventory(insertForApplicationInRecord); 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.remove("applicationInId");
} }
} }
insertForApplicationInRecord.put("flagForGroup",2);
insertForApplicationInRecord.put("quantity",quantityForGroup.toString()); insertForApplicationInRecord.put("flagForGroup", 2);
insertForApplicationInRecord.put("mid",gid); insertForApplicationInRecord.put("quantity", quantityForGroup.toString());
insertForApplicationInRecord.put("unit",-1); insertForApplicationInRecord.put("mid", gid);
insertForApplicationInRecord.put("unit", -1);
Depository depository = depositoryMapper.findDepositoryById(depositoryId); Depository depository = depositoryMapper.findDepositoryById(depositoryId);
insertForApplicationInRecord.put("code",depositoryRecordService.createCode(depository.getDname(), "InOrderNumber", "in", "")); insertForApplicationInRecord.put("code", depositoryRecordService.createCode(depository.getDname(), "InOrderNumber", "in", ""));
insertForApplicationInRecord.put("applicant_time",System.currentTimeMillis()); insertForApplicationInRecord.put("applicant_time", System.currentTimeMillis());
// 添加一个组合订单用于展示
depositoryRecordMapper.insertApplicationInRecord(insertForApplicationInRecord); depositoryRecordMapper.insertApplicationInRecord(insertForApplicationInRecord);
if(!flag){ insertForApplicationInRecord.remove("id");
depositoryRecordMapper.deleteApplicationInRecordById(ObjectFormatUtil.toInteger(insertForApplicationInRecord.get("applicationInId")));
insertForApplicationInRecord.remove("applicationInId");
}
return result; return result;
} }
/** /**
* 用于插入子出库订单 * 用于插入子出库订单
* *
@ -818,7 +846,7 @@ public class GroupServiceImpl implements GroupService {
* @return * @return
*/ */
@Transactional(rollbackFor = Exception.class) @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; Integer result = 0;
@ -851,7 +879,7 @@ public class GroupServiceImpl implements GroupService {
paramForInventory.put("did", depositoryId); paramForInventory.put("did", depositoryId);
// 获取对应库存 // 获取对应库存
Inventory inventoryByMidAndDid = materialMapper.findInventoryByMidAndDid(paramForInventory); Inventory inventoryByMidAndDid = materialMapper.findInventoryByMidAndDid(paramForInventory);
if(inventoryByMidAndDid != null) { if (inventoryByMidAndDid != null) {
if (inventoryByMidAndDid.getQuantity() >= quantity) { if (inventoryByMidAndDid.getQuantity() >= quantity) {
// 如果当前库存充足 // 如果当前库存充足
did = depositoryId; did = depositoryId;

Loading…
Cancel
Save