Commit ab82e8bf by wuwenlong

批量生成生产计划bugfix

parent fbdbaec1
......@@ -410,7 +410,7 @@ public class HGSCTools {
}
private static List<HGSC005A> generatorNewPlanDetail(List<HGSC005A> hgsc005aList){
List<String> inventCodes = hgsc005aList.stream().map(HGSC005A::getProductCode).collect(Collectors.toList());
List<String> inventCodes = hgsc005aList.stream().map(HGSC005A::getProductCode).distinct().collect(Collectors.toList());
//通过存货档案编码查询存货档案工序
List<HGPZ005A> hgpz005AList = HGPZTools.HgPz005A.queryByInventCodes(inventCodes);
List<HGSC005A> hgsc005AList = new ArrayList<>();
......@@ -448,7 +448,7 @@ public class HGSCTools {
}
private static Map<Long,Optional<HGSC005A>> queryOldPlanDetail(List<HGSC005A> hgsc005aList){
List<String> productCodes = hgsc005aList.stream().map(HGSC005A::getProductCode).collect(Collectors.toList());
List<String> productCodes = hgsc005aList.stream().map(HGSC005A::getProductCode).distinct().collect(Collectors.toList());
Map paramMap = new HashMap();
//因为提交时肯定matid相同,直接取第一个即可
paramMap.put(HGSC005A.FIELD_mat_id, hgsc005aList.get(0).getMatId());
......@@ -497,28 +497,28 @@ public class HGSCTools {
checkUpdateData(hgsc005aList);
constructObj(hgsc005aList);
List<HGSC005A> hgsc005AList = generatorNewPlanDetail(hgsc005aList);
Map<Long,Optional<HGSC005A>> oldObjMap = queryOldPlanDetail(hgsc005aList);
List<HGSC005A> createList = new ArrayList<>();
List<HGSC005A> updateList = new ArrayList<>();
hgsc005AList.forEach(o -> {
Optional<HGSC005A> op = oldObjMap.get(o.getInventProcessId());
if(Objects.nonNull(op)){
HGSC005A uo = op.get();
uo.setQuantity(uo.getQuantity()+o.getQuantity());
uo.setUnfinishQuantity(uo.getUnfinishQuantity()+o.getQuantity());
handleWeight(o,uo);
updateList.add(uo);
}else{
handleWeight(o,o);
createList.add(o);
}
});
if(CollectionUtils.isNotEmpty(createList)){
DaoUtils.insertBatch(HGSC005A.INSERT,createList);
}
if(CollectionUtils.isNotEmpty(updateList)){
DaoUtils.updateBatch(HGSC005A.UPDATE,updateList);
// Map<Long,Optional<HGSC005A>> oldObjMap = queryOldPlanDetail(hgsc005aList);
// List<HGSC005A> createList = new ArrayList<>();
// List<HGSC005A> updateList = new ArrayList<>();
// hgsc005AList.forEach(o -> {
// Optional<HGSC005A> op = oldObjMap.get(o.getInventProcessId());
// if(Objects.nonNull(op)){
// HGSC005A uo = op.get();
// uo.setQuantity(uo.getQuantity()+o.getQuantity());
// uo.setUnfinishQuantity(uo.getUnfinishQuantity()+o.getQuantity());
// handleWeight(o,uo);
// updateList.add(uo);
// }else{
// handleWeight(o,o);
// createList.add(o);
// }
// });
if(CollectionUtils.isNotEmpty(hgsc005AList)){
DaoUtils.insertBatch(HGSC005A.INSERT,hgsc005AList);
}
// if(CollectionUtils.isNotEmpty(updateList)){
// DaoUtils.updateBatch(HGSC005A.UPDATE,updateList);
// }
return hgsc005aList;
}
......@@ -635,17 +635,14 @@ public class HGSCTools {
*/
private static void checkUpdateData(List<HGSC005A> hgsc005aList) {
for(HGSC005A hgsc005a : hgsc005aList){
AssertUtils.isTrue(Objects.isNull(hgsc005a.getMatId())||hgsc005a.getMatId()<=0, "物料清单ID不能为空!");
AssertUtils.isTrue(Objects.isNull(hgsc005a.getMatDetailId())||hgsc005a.getMatDetailId()<=0, "物料清单明细ID不能为空!");
AssertUtils.isEmpty(hgsc005a.getProductCode(), "产品编码不能为空!");
AssertUtils.isEmpty(hgsc005a.getProductName(), "产品名称不能为空!");
AssertUtils.isTrue(Objects.isNull(hgsc005a.getTechFlowId())||hgsc005a.getTechFlowId()<=0, "工艺流程ID不能为空!");
AssertUtils.isTrue(Objects.isNull(hgsc005a.getQuantity())||hgsc005a.getQuantity()<=0, "数量不能为空!");
checkUpdateData(hgsc005a);
}
}
public static List<HGSC005A> constructObj(List<HGSC005A> hgsc005aList){
HGSC005 hgsc005 = THGSC005.queryByMatId(hgsc005aList.get(0).getMatId());
List<HGSC005A> result = new ArrayList<>();
Map<String,HGSC005A> hgsc005AMap = new HashMap<>();
hgsc005aList.forEach(hgsc005a -> {
hgsc005a.setPlanCode(hgsc005.getPlanCode());
hgsc005a.setCompanyCode(hgsc005.getCompanyCode());
......@@ -658,7 +655,23 @@ public class HGSCTools {
hgsc005a.setUnfinishQuantity(hgsc005a.getQuantity());
hgsc005a.setFinishQuantity(0);
hgsc005a.setUnfinishWeight(hgsc005a.getTotalWeight());
//零件
if(hgsc005a.getProductType().compareTo(ProductTypeEnum.PART.getCode())==0){
HGSC005A hisObj = hgsc005AMap.get(hgsc005a.getProductCode());
if(Objects.nonNull(hisObj)){
hgsc005a.setQuantity(hgsc005a.getQuantity() + hisObj.getQuantity());
hgsc005a.setUnfinishQuantity(hgsc005a.getQuantity());
hgsc005a.setTotalWeight(hgsc005a.getTotalWeight().add(hisObj.getTotalWeight()));
hgsc005a.setUnfinishWeight(hgsc005a.getTotalWeight());
}
hgsc005AMap.put(hgsc005a.getProductCode(),hgsc005a);
}else{
result.add(hgsc005a);
}
});
if(MapUtils.isNotEmpty(hgsc005AMap)){
result.addAll(hgsc005AMap.values().stream().collect(Collectors.toList()));
}
return hgsc005aList;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment