Commit ac4c1c7c by wuwenlong

物料清单删除构建批量删除零件生产计划

parent f51a968b
...@@ -6,6 +6,7 @@ import com.baosight.iplat4j.core.data.DaoEPBase; ...@@ -6,6 +6,7 @@ import com.baosight.iplat4j.core.data.DaoEPBase;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import com.baosight.iplat4j.core.util.StringUtils; import com.baosight.iplat4j.core.util.StringUtils;
...@@ -142,6 +143,17 @@ public class HGSC005A extends DaoEPBase { ...@@ -142,6 +143,17 @@ public class HGSC005A extends DaoEPBase {
private String updatedName = " "; /* 修改人名称*/ private String updatedName = " "; /* 修改人名称*/
private String updatedTime = " "; /* 更新时间*/ private String updatedTime = " "; /* 更新时间*/
private List<HGSC005A> partList;
public List<HGSC005A> getPartList() {
return partList;
}
public void setPartList(List<HGSC005A> partList) {
this.partList = partList;
}
/** /**
* initialize the metadata. * initialize the metadata.
*/ */
......
...@@ -36,6 +36,7 @@ import org.apache.commons.lang3.StringUtils; ...@@ -36,6 +36,7 @@ import org.apache.commons.lang3.StringUtils;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collector;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.baosight.hggp.common.AssignStatusEnum.*; import static com.baosight.hggp.common.AssignStatusEnum.*;
...@@ -478,6 +479,25 @@ public class HGSCTools { ...@@ -478,6 +479,25 @@ public class HGSCTools {
return returnOldObjMap; return returnOldObjMap;
} }
private static Map<String,HGSC005A> queryOldPartPlanDetail(List<HGSC005A> hgsc005aList){
if(CollectionUtils.isNotEmpty(hgsc005aList)) {
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());
paramMap.put("productCodes", productCodes);
paramMap.put(HGSC005A.FIELD_product_type, ProductTypeEnum.PART.getCode());
List<HGSC005A> oldObjList = DaoBase.getInstance().query(HGSC005A.QUERY, paramMap);
return Optional.ofNullable(oldObjList).orElse(new ArrayList<>()).stream()
.collect(Collectors.groupingBy(o -> {
return o.getProductCode() + "#" + o.getInventProcessId();
},
Collectors.collectingAndThen(Collectors.maxBy(
Comparator.comparingInt(HGSC005A::getQuantity)), Optional::get)));
}
return null;
}
private static Map<Long,Optional<HGSC005A>> queryOldPlanDetail(HGSC005A hgsc005a){ private static Map<Long,Optional<HGSC005A>> queryOldPlanDetail(HGSC005A hgsc005a){
Map paramMap = new HashMap(); Map paramMap = new HashMap();
paramMap.put(HGSC005A.FIELD_mat_id, hgsc005a.getMatId()); paramMap.put(HGSC005A.FIELD_mat_id, hgsc005a.getMatId());
...@@ -617,6 +637,52 @@ public class HGSCTools { ...@@ -617,6 +637,52 @@ public class HGSCTools {
if(CollectionUtils.isNotEmpty(updateList)){ if(CollectionUtils.isNotEmpty(updateList)){
DaoUtils.updateBatch(HGSC005A.UPDATE,updateList); DaoUtils.updateBatch(HGSC005A.UPDATE,updateList);
} }
if(hgsc005a.getProductType().compareTo(ProductTypeEnum.STRUCT.getCode())==0
&& CollectionUtils.isNotEmpty(hgsc005a.getPartList())){
deletePartList(hgsc005a.getPartList());
}
}
public static void deletePartList(List<HGSC005A> hgsc005aList){
List<Long> deleteIds = new ArrayList<>();
List<HGSC005A> updateList = new ArrayList<>();
if(CollectionUtils.isNotEmpty(hgsc005aList)) {
Map<String, HGSC005A> hgsc005aMap = hgsc005aList.stream().collect(Collectors.toMap(HGSC005A::getProductCode, o -> o, (o1, o2) -> {
o1.setQuantity(o1.getQuantity() + o2.getQuantity());
o1.setTotalWeight(o1.getSingleWeight().multiply(new BigDecimal(o1.getQuantity())));
return o1;
}));
checkUpdateData(hgsc005aList);
Map<String, HGSC005A> oldObjMap = queryOldPartPlanDetail(hgsc005aList);
if (Objects.nonNull(oldObjMap)) {
oldObjMap.forEach((k, oldObj) -> {
if(Objects.nonNull(oldObj)) {
HGSC005A hgsc005a = hgsc005aMap.get(k.split("#")[0]);
if (oldObj.getQuantity() - hgsc005a.getQuantity() <= 0) {
handleWeight(hgsc005a, oldObj);
deleteIds.add(oldObj.getId());
} else {
oldObj.setQuantity(oldObj.getQuantity() - hgsc005a.getQuantity());
oldObj.setUnfinishQuantity(oldObj.getQuantity() - oldObj.getFinishQuantity());
handleWeight(hgsc005a, oldObj);
updateList.add(oldObj);
}
}
});
}
}
if(CollectionUtils.isNotEmpty(deleteIds)){
Long matId = hgsc005aList.get(0).getMatId();
List<HGSC005A> dbList = queryByMatId(matId);
//如果全部删除则删除主表
if(deleteIds.size() == dbList.size()){
DaoUtils.update(HGSC005.DELETE_BY_MAT_ID,new HashMap<String,Object>(){{put(HGSC005.FIELD_mat_id,matId);}});
}
DaoUtils.update(HGSC005A.BATCH_DELETE, new HashMap<String,Object>(){{put("ids",deleteIds);}});
}
if(CollectionUtils.isNotEmpty(updateList)){
DaoUtils.updateBatch(HGSC005A.UPDATE,updateList);
}
} }
private static void handleWeight(HGSC005A hgsc005a, HGSC005A target){ private static void handleWeight(HGSC005A hgsc005a, HGSC005A target){
......
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