Commit 51e5fcfd by wuwenlong

物料清单删除同步生产计划优化

parent 73224a31
...@@ -71,6 +71,8 @@ public class HGSC005 extends DaoEPBase { ...@@ -71,6 +71,8 @@ public class HGSC005 extends DaoEPBase {
public static final String UPDATE = "HGSC005.update"; public static final String UPDATE = "HGSC005.update";
public static final String DELETE = "HGSC005.delete"; public static final String DELETE = "HGSC005.delete";
public static final String BATCH_COMMIT = "HGSC005.batch_commit"; public static final String BATCH_COMMIT = "HGSC005.batch_commit";
public static final String DELETE_BY_MAT_ID = "HGSC005.delete_by_mat_id";
private Long id = new Long(0); private Long id = new Long(0);
private Long matId = new Long(0); /* 物料清单ID*/ private Long matId = new Long(0); /* 物料清单ID*/
......
...@@ -102,6 +102,7 @@ public class HGSC005A extends DaoEPBase { ...@@ -102,6 +102,7 @@ public class HGSC005A extends DaoEPBase {
public static final String INSERT = "HGSC005A.insert"; public static final String INSERT = "HGSC005A.insert";
public static final String UPDATE = "HGSC005A.update"; public static final String UPDATE = "HGSC005A.update";
public static final String DELETE = "HGSC005A.delete"; public static final String DELETE = "HGSC005A.delete";
public static final String BATCH_DELETE = "HGSC005.batch_delete";
public static final String UPDATE_PLAN_DATE = "HGSC005A.update_plan_date"; public static final String UPDATE_PLAN_DATE = "HGSC005A.update_plan_date";
private Long id = new Long(0); private Long id = new Long(0);
......
...@@ -213,6 +213,11 @@ ...@@ -213,6 +213,11 @@
id = #id# id = #id#
</delete> </delete>
<delete id="delete_by_mat_id">
DELETE FROM ${hggpSchema}.HGSC005 WHERE
mat_id = #matId#
</delete>
<update id="update"> <update id="update">
UPDATE ${hggpSchema}.HGSC005 UPDATE ${hggpSchema}.HGSC005
SET SET
......
...@@ -367,6 +367,11 @@ ...@@ -367,6 +367,11 @@
id = #id# id = #id#
</delete> </delete>
<delete id="batch_delete">
DELETE FROM ${hggpSchema}.HGSC005A WHERE
id IN <iterate close=")" open="(" conjunction="," property="ids">#ids[]#</iterate>
</delete>
<update id="update"> <update id="update">
UPDATE ${hggpSchema}.HGSC005A UPDATE ${hggpSchema}.HGSC005A
SET SET
......
...@@ -294,6 +294,14 @@ public class HGSCTools { ...@@ -294,6 +294,14 @@ public class HGSCTools {
return CollectionUtils.isEmpty(results) ? null : results; return CollectionUtils.isEmpty(results) ? null : results;
} }
public static List<HGSC005A> queryByMatId(Long matId){
AssertUtils.isTrue(Objects.isNull(matId)||matId<=0, "物料清单ID不能为空!");
Map paramMap = new HashMap();
paramMap.put(HGSC005A.FIELD_mat_id, matId);
List<HGSC005A> results = DaoBase.getInstance().query(HGSC005A.QUERY, paramMap);
return CollectionUtils.isEmpty(results) ? null : results;
}
private static List<HGSC005A> generatorNewPlanDetail(HGSC005A hgsc005a){ private static List<HGSC005A> generatorNewPlanDetail(HGSC005A hgsc005a){
//通过存货档案编码查询存货档案工序 //通过存货档案编码查询存货档案工序
...@@ -392,16 +400,29 @@ public class HGSCTools { ...@@ -392,16 +400,29 @@ public class HGSCTools {
public static void delete(HGSC005A hgsc005a){ public static void delete(HGSC005A hgsc005a){
checkUpdateData(hgsc005a); checkUpdateData(hgsc005a);
Map<Long,Optional<HGSC005A>> oldObjMap = queryOldPlanDetail(hgsc005a); Map<Long,Optional<HGSC005A>> oldObjMap = queryOldPlanDetail(hgsc005a);
List<Long> deleteIds = new ArrayList<>();
List<HGSC005A> updateList = new ArrayList<>();
oldObjMap.forEach((k,v)->{ oldObjMap.forEach((k,v)->{
HGSC005A oldObj = v.get(); HGSC005A oldObj = v.get();
if(oldObj.getQuantity()-hgsc005a.getQuantity()<=0){ if(oldObj.getQuantity()-hgsc005a.getQuantity()<=0){
DaoUtils.update(HGSC005A.DELETE, new HashMap<String,Object>(){{put(HGSC005A.FIELD_id,oldObj.getId());}}); deleteIds.add(oldObj.getId());
}else{ }else{
oldObj.setQuantity(oldObj.getQuantity()-hgsc005a.getQuantity()); oldObj.setQuantity(oldObj.getQuantity()-hgsc005a.getQuantity());
oldObj.setUnfinishQuantity(oldObj.getQuantity()-oldObj.getFinishQuantity()); oldObj.setUnfinishQuantity(oldObj.getQuantity()-oldObj.getFinishQuantity());
DaoUtils.update(HGSC005A.UPDATE,oldObj); updateList.add(oldObj);
} }
}); });
if(CollectionUtils.isNotEmpty(deleteIds)){
List<HGSC005A> dbList = queryByMatId(hgsc005a.getMatId());
//如果全部删除则删除主表
if(deleteIds.size() == dbList.size()){
DaoUtils.update(HGSC005.DELETE_BY_MAT_ID,new HashMap<String,Object>(){{put(HGSC005.FIELD_mat_id,hgsc005a.getMatId());}});
}
DaoUtils.update(HGSC005A.BATCH_DELETE, new HashMap<String,Object>(){{put("ids",deleteIds);}});
}
if(CollectionUtils.isNotEmpty(updateList)){
DaoUtils.updateBatch(HGSC005A.UPDATE,updateList);
}
} }
/** /**
......
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