Commit 23e40119 by wuwenlong

生成生产计划dev;

parent cb38f304
...@@ -6,10 +6,9 @@ import com.baosight.hggp.core.dao.DaoBase; ...@@ -6,10 +6,9 @@ import com.baosight.hggp.core.dao.DaoBase;
import com.baosight.hggp.core.dao.DaoUtils; import com.baosight.hggp.core.dao.DaoUtils;
import com.baosight.hggp.core.enums.ValidFlagEnum; import com.baosight.hggp.core.enums.ValidFlagEnum;
import com.baosight.hggp.hg.constant.HGConstant; import com.baosight.hggp.hg.constant.HGConstant;
import com.baosight.hggp.hg.pz.domain.HGPZ004; import com.baosight.hggp.hg.pz.domain.*;
import com.baosight.hggp.hg.pz.domain.HGPZ005; import com.baosight.hggp.hg.sc.domain.HGSC001A;
import com.baosight.hggp.hg.pz.domain.HGPZ007; import com.baosight.hggp.hg.sc.domain.HGSC005A;
import com.baosight.hggp.hg.pz.domain.HGPZ009;
import com.baosight.hggp.hg.sj.domain.HGSJ003; import com.baosight.hggp.hg.sj.domain.HGSJ003;
import com.baosight.hggp.util.*; import com.baosight.hggp.util.*;
import com.baosight.iplat4j.common.ed.domain.TEDCM01; import com.baosight.iplat4j.common.ed.domain.TEDCM01;
...@@ -391,4 +390,21 @@ public class HGPZTools { ...@@ -391,4 +390,21 @@ public class HGPZTools {
} }
} }
} }
public static class HgPz005A{
/**
* 通过存货编码查询存货工序*
* @param inventCode
* @return
*/
public static List<HGPZ005A> queryByInventCode(String inventCode){
AssertUtils.isEmpty(inventCode, "存货编码不能为空!");
Map paramMap = new HashMap();
paramMap.put(HGPZ005A.FIELD_INVENT_CODE, inventCode);
List<HGPZ005A> results = DaoBase.getInstance().query(HGPZ005A.QUERY, paramMap);
return CollectionUtils.isEmpty(results) ? null : results;
}
}
} }
...@@ -89,7 +89,7 @@ public class HGSC005 extends DaoEPBase { ...@@ -89,7 +89,7 @@ public class HGSC005 extends DaoEPBase {
private String updatedName = " "; /* 修改人名称*/ private String updatedName = " "; /* 修改人名称*/
private String updatedTime = " "; /* 更新时间*/ private String updatedTime = " "; /* 更新时间*/
private List<HGSC005A> hgsc005AList; // private List<HGSC005A> hgsc005AList;
/** /**
* initialize the metadata. * initialize the metadata.
...@@ -482,13 +482,13 @@ public class HGSC005 extends DaoEPBase { ...@@ -482,13 +482,13 @@ public class HGSC005 extends DaoEPBase {
this.updatedTime = updatedTime; this.updatedTime = updatedTime;
} }
public List<HGSC005A> getHgsc005AList() { // public List<HGSC005A> getHgsc005AList() {
return hgsc005AList; // return hgsc005AList;
} // }
//
public void setHgsc005AList(List<HGSC005A> hgsc005AList) { // public void setHgsc005AList(List<HGSC005A> hgsc005AList) {
this.hgsc005AList = hgsc005AList; // this.hgsc005AList = hgsc005AList;
} // }
/** /**
* get the value from Map. * get the value from Map.
......
...@@ -32,6 +32,7 @@ public class HGSC005A extends DaoEPBase { ...@@ -32,6 +32,7 @@ public class HGSC005A extends DaoEPBase {
public static final String FIELD_proj_code = "projCode"; /* 项目编码*/ public static final String FIELD_proj_code = "projCode"; /* 项目编码*/
public static final String FIELD_proj_name = "projName"; /* 项目名称*/ public static final String FIELD_proj_name = "projName"; /* 项目名称*/
public static final String FIELD_plan_code = "planCode"; /* 计划编码*/ public static final String FIELD_plan_code = "planCode"; /* 计划编码*/
public static final String FIELD_product_type = "productType"; /* 产品类型*/
public static final String FIELD_product_code = "productCode"; /* 产品编号*/ public static final String FIELD_product_code = "productCode"; /* 产品编号*/
public static final String FIELD_product_name = "productName"; /* 产品名称*/ public static final String FIELD_product_name = "productName"; /* 产品名称*/
public static final String FIELD_finish_date = "finishDate"; /* 完工日期*/ public static final String FIELD_finish_date = "finishDate"; /* 完工日期*/
...@@ -83,8 +84,11 @@ public class HGSC005A extends DaoEPBase { ...@@ -83,8 +84,11 @@ public class HGSC005A extends DaoEPBase {
private Long id = new Long(0); private Long id = new Long(0);
private Long matId = new Long(0); /* 物料清单ID*/
private Long matDetailId = new Long(0); /* 物料清单明细ID*/ private Long matDetailId = new Long(0); /* 物料清单明细ID*/
private Long techFlowId = new Long(0); /* 工艺流程ID*/ private Long techFlowId = new Long(0); /* 工艺流程ID*/
private Long processId = new Long(0); /* 工序ID*/
private String processName = " "; /* 工序名称*/
private String companyCode = " "; /* 公司编码*/ private String companyCode = " "; /* 公司编码*/
private String companyName = " "; /* 公司名称*/ private String companyName = " "; /* 公司名称*/
private String depCode = " "; /* 部门编码*/ private String depCode = " "; /* 部门编码*/
...@@ -92,6 +96,7 @@ public class HGSC005A extends DaoEPBase { ...@@ -92,6 +96,7 @@ public class HGSC005A extends DaoEPBase {
private String projCode = " "; /* 项目编码*/ private String projCode = " "; /* 项目编码*/
private String projName = " "; /* 项目名称*/ private String projName = " "; /* 项目名称*/
private String planCode = " "; /* 计划编码*/ private String planCode = " "; /* 计划编码*/
private Integer productType = new Integer(0); /* 产品类型*/
private String productCode = " "; /* 产品编号*/ private String productCode = " "; /* 产品编号*/
private String productName = " "; /* 产品名称*/ private String productName = " "; /* 产品名称*/
private String finishDate = " "; /* 完工日期*/ private String finishDate = " "; /* 完工日期*/
...@@ -393,6 +398,14 @@ public class HGSC005A extends DaoEPBase { ...@@ -393,6 +398,14 @@ public class HGSC005A extends DaoEPBase {
return this.productCode; return this.productCode;
} }
public Integer getProductType() {
return productType;
}
public void setProductType(Integer productType) {
this.productType = productType;
}
/** /**
* set the productCode - 产品编号. * set the productCode - 产品编号.
* *
...@@ -625,6 +638,31 @@ public class HGSC005A extends DaoEPBase { ...@@ -625,6 +638,31 @@ public class HGSC005A extends DaoEPBase {
public void setUpdatedTime(String updatedTime) { public void setUpdatedTime(String updatedTime) {
this.updatedTime = updatedTime; this.updatedTime = updatedTime;
} }
public Long getMatId() {
return matId;
}
public void setMatId(Long matId) {
this.matId = matId;
}
public Long getProcessId() {
return processId;
}
public void setProcessId(Long processId) {
this.processId = processId;
}
public String getProcessName() {
return processName;
}
public void setProcessName(String processName) {
this.processName = processName;
}
/** /**
* get the value from Map. * get the value from Map.
* *
......
...@@ -4,10 +4,13 @@ import com.baosight.hggp.core.dao.DaoBase; ...@@ -4,10 +4,13 @@ import com.baosight.hggp.core.dao.DaoBase;
import com.baosight.hggp.core.dao.DaoUtils; import com.baosight.hggp.core.dao.DaoUtils;
import com.baosight.hggp.core.security.UserSessionUtils; import com.baosight.hggp.core.security.UserSessionUtils;
import com.baosight.hggp.hg.constant.HGConstant; import com.baosight.hggp.hg.constant.HGConstant;
import com.baosight.hggp.hg.pz.domain.HGPZ005A;
import com.baosight.hggp.hg.pz.tools.HGPZTools;
import com.baosight.hggp.hg.sc.domain.HGSC001A; import com.baosight.hggp.hg.sc.domain.HGSC001A;
import com.baosight.hggp.hg.sc.domain.HGSC005; import com.baosight.hggp.hg.sc.domain.HGSC005;
import com.baosight.hggp.hg.sc.domain.HGSC005A; import com.baosight.hggp.hg.sc.domain.HGSC005A;
import com.baosight.hggp.util.AssertUtils; import com.baosight.hggp.util.AssertUtils;
import com.baosight.hggp.util.BeanUtils;
import com.baosight.iplat4j.ed.util.SequenceGenerator; import com.baosight.iplat4j.ed.util.SequenceGenerator;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
...@@ -114,9 +117,9 @@ public class HGSCTools { ...@@ -114,9 +117,9 @@ public class HGSCTools {
checkSaveData(hgsc005); checkSaveData(hgsc005);
hgsc005.setPlanCode(SequenceGenerator.getNextSequence(HGConstant.SequenceId.HGSC005_PLAN_CODE)); hgsc005.setPlanCode(SequenceGenerator.getNextSequence(HGConstant.SequenceId.HGSC005_PLAN_CODE));
DaoUtils.insert(HGSC005.INSERT,hgsc005); DaoUtils.insert(HGSC005.INSERT,hgsc005);
hgsc005.getHgsc005AList().forEach(hgsc005A -> { // hgsc005.getHgsc005AList().forEach(hgsc005A -> {
DaoUtils.insert(HGSC005A.INSERT,THGSC005A.constructObj(hgsc005A,hgsc005)); // DaoUtils.insert(HGSC005A.INSERT,THGSC005A.constructObj(hgsc005A,hgsc005));
}); // });
return hgsc005; return hgsc005;
} }
...@@ -134,52 +137,142 @@ public class HGSCTools { ...@@ -134,52 +137,142 @@ public class HGSCTools {
// AssertUtils.isEmpty(hgsc005.getDepCode(), "部门不能为空!"); // AssertUtils.isEmpty(hgsc005.getDepCode(), "部门不能为空!");
AssertUtils.isEmpty(hgsc005.getProjCode(), "项目编号不能为空!"); AssertUtils.isEmpty(hgsc005.getProjCode(), "项目编号不能为空!");
AssertUtils.isEmpty(hgsc005.getProjName(), "项目名称不能为空!"); AssertUtils.isEmpty(hgsc005.getProjName(), "项目名称不能为空!");
AssertUtils.isEmpty(hgsc005.getHgsc005AList(), "计划明细不能为空"); // AssertUtils.isEmpty(hgsc005.getHgsc005AList(), "计划明细不能为空");
hgsc005.getHgsc005AList().forEach(hgsc005A -> { // hgsc005.getHgsc005AList().forEach(hgsc005A -> {
AssertUtils.isTrue(Objects.isNull(hgsc005A.getMatDetailId())||hgsc005A.getMatDetailId()<=0, "物料清单明细ID不能为空!"); // AssertUtils.isTrue(Objects.isNull(hgsc005A.getMatDetailId())||hgsc005A.getMatDetailId()<=0, "物料清单明细ID不能为空!");
AssertUtils.isEmpty(hgsc005A.getProductCode(), "产品编码不能为空!"); // AssertUtils.isEmpty(hgsc005A.getProductCode(), "产品编码不能为空!");
AssertUtils.isEmpty(hgsc005A.getProductName(), "产品名称不能为空!"); // AssertUtils.isEmpty(hgsc005A.getProductName(), "产品名称不能为空!");
AssertUtils.isTrue(Objects.isNull(hgsc005A.getTechFlowId())||hgsc005A.getTechFlowId()<=0, "工艺流程ID不能为空!"); // AssertUtils.isTrue(Objects.isNull(hgsc005A.getTechFlowId())||hgsc005A.getTechFlowId()<=0, "工艺流程ID不能为空!");
AssertUtils.isTrue(Objects.isNull(hgsc005A.getQuantity())||hgsc005A.getQuantity()<=0, "数量不能为空!"); // AssertUtils.isTrue(Objects.isNull(hgsc005A.getQuantity())||hgsc005A.getQuantity()<=0, "数量不能为空!");
// AssertUtils.isTrue(Objects.isNull(hgsc005A.getFinishQuantity())||hgsc005A.getFinishQuantity()<=0, "完工数量不能为空!"); //// AssertUtils.isTrue(Objects.isNull(hgsc005A.getFinishQuantity())||hgsc005A.getFinishQuantity()<=0, "完工数量不能为空!");
// AssertUtils.isTrue(Objects.isNull(hgsc005A.getUnfinishQuantity())||hgsc005A.getUnfinishQuantity()<=0, "未完工数量不能为空!"); //// AssertUtils.isTrue(Objects.isNull(hgsc005A.getUnfinishQuantity())||hgsc005A.getUnfinishQuantity()<=0, "未完工数量不能为空!");
}); // });
}
public static HGSC005 queryByMatId(Long matId){
AssertUtils.isTrue(Objects.isNull(matId)||matId<=0, "物料清单ID不能为空!");
HGSC005 result = (HGSC005) DaoBase.getInstance().get(HGSC005.QUERY, HGSC005.FIELD_mat_id, matId);
return result;
} }
} }
public static class THGSC005A{ public static class THGSC005A{
public static List<HGSC005A> queryByPlanCodes(List<String> planCodes){ public static List<HGSC005A> queryByPlanCodes(List<String> planCodes){
AssertUtils.isEmpty(planCodes, "计划编码不能为空!"); AssertUtils.isEmpty(planCodes, "计划编码不能为空!");
Map paramMap = new HashMap(); Map paramMap = new HashMap();
paramMap.put("planCodes", planCodes); paramMap.put("planCodes", planCodes);
List<HGSC005A> results = DaoBase.getInstance().query(HGSC001A.QUERY, paramMap); List<HGSC005A> results = DaoBase.getInstance().query(HGSC005A.QUERY, paramMap);
return CollectionUtils.isEmpty(results) ? null : results; return CollectionUtils.isEmpty(results) ? null : results;
} }
public static HGSC005A save(HGSC005A hgsc005a, Long matId){
AssertUtils.isTrue(Objects.isNull(matId)||matId<=0, "物料清单ID不能为空!"); private static List<HGSC005A> generatorNewPlanDetail(HGSC005A hgsc005a){
//通过存货档案编码查询存货档案工序
List<HGPZ005A> hgpz005AList = HGPZTools.HgPz005A.queryByInventCode(hgsc005a.getProductCode());
AssertUtils.isEmpty(hgpz005AList, String.format("产品[%s]工序不存在,请先到存货档案配置产品工序!",hgsc005a.getProductName()));
List<HGSC005A> hgsc005AList = new ArrayList<>();
hgpz005AList.forEach(pz -> {
HGSC005A obj = new HGSC005A();
BeanUtils.copyProperties(hgsc005a,obj);
obj.setProcessId(pz.getId());
obj.setProcessName(pz.getProcessName());
hgsc005AList.add(obj);
});
return hgsc005AList;
}
private static Map<Long,Optional<HGSC005A>> queryOldPlanDetail(HGSC005A hgsc005a){
Map paramMap = new HashMap();
paramMap.put(HGSC005A.FIELD_plan_code, hgsc005a.getPlanCode());
paramMap.put(HGSC005A.FIELD_product_code, hgsc005a.getProductCode());
//构建计划物料明细ID唯一 TODO
if(hgsc005a.getProductType()==1){
paramMap.put(HGSC005A.FIELD_product_code, hgsc005a.getMatDetailId());
}
List<HGSC005A> oldObjList = DaoBase.getInstance().query(HGSC005A.QUERY, paramMap);
Map<Long,Optional<HGSC005A>> oldObjMap = Optional.ofNullable(oldObjList).orElse(new ArrayList<>()).stream()
.collect(Collectors.groupingBy(HGSC005A::getProcessId,Collectors.maxBy(
Comparator.comparingInt(HGSC005A::getQuantity))));
return oldObjMap;
}
public static HGSC005A save(HGSC005A hgsc005a){
checkUpdateData(hgsc005a); checkUpdateData(hgsc005a);
HGSC005 hgsc005 = (HGSC005) DaoBase.getInstance().get(HGSC005.QUERY,HGSC005.FIELD_mat_id, matId); constructObj(hgsc005a);
DaoUtils.insert(HGSC005A.INSERT,THGSC005A.constructObj(hgsc005a,hgsc005)); List<HGSC005A> hgsc005AList = generatorNewPlanDetail(hgsc005a);
Map<Long,Optional<HGSC005A>> oldObjMap = queryOldPlanDetail(hgsc005a);
List<HGSC005A> createList = new ArrayList<>();
List<HGSC005A> updateList = new ArrayList<>();
hgsc005AList.forEach(o -> {
Optional<HGSC005A> op = oldObjMap.get(o.getProcessId());
if(Objects.nonNull(op)){
HGSC005A uo = op.get();
uo.setQuantity(uo.getQuantity()+o.getQuantity());
uo.setUnfinishQuantity(uo.getUnfinishQuantity()+o.getQuantity());
updateList.add(uo);
}else{
createList.add(o);
}
});
if(CollectionUtils.isNotEmpty(createList)){
createList.forEach(obj -> {
DaoUtils.insert(HGSC005A.INSERT,obj);
});
}
if(CollectionUtils.isNotEmpty(updateList)){
updateList.forEach(obj -> {
DaoUtils.insert(HGSC005A.UPDATE,obj);
});
}
return hgsc005a; return hgsc005a;
} }
public static HGSC005A update(HGSC005A hgsc005a){ public static HGSC005A update(HGSC005A hgsc005a){
checkUpdateData(hgsc005a); checkUpdateData(hgsc005a);
HGSC005A result = (HGSC005A) DaoBase.getInstance().get(HGSC005A.QUERY,HGSC005A.FIELD_mat_detail_id, hgsc005a.getMatDetailId()); constructObj(hgsc005a);
result.setProductCode(hgsc005a.getProductCode()); List<HGSC005A> hgsc005AList = generatorNewPlanDetail(hgsc005a);
result.setProductName(hgsc005a.getProductName()); Map<Long,Optional<HGSC005A>> oldObjMap = queryOldPlanDetail(hgsc005a);
result.setQuantity(hgsc005a.getQuantity()); List<HGSC005A> createList = new ArrayList<>();
result.setUnfinishQuantity(hgsc005a.getQuantity()); List<HGSC005A> updateList = new ArrayList<>();
result.setFinishQuantity(0); hgsc005AList.forEach(o -> {
DaoUtils.update(HGSC005A.UPDATE,result); Optional<HGSC005A> op = oldObjMap.get(o.getProcessId());
return result; if(Objects.nonNull(op)){
HGSC005A uo = op.get();
uo.setQuantity(o.getQuantity());
uo.setUnfinishQuantity(o.getQuantity()-uo.getFinishQuantity());
updateList.add(uo);
}else{
createList.add(o);
}
});
if(CollectionUtils.isNotEmpty(createList)){
createList.forEach(obj -> {
DaoUtils.insert(HGSC005A.INSERT,obj);
});
}
if(CollectionUtils.isNotEmpty(updateList)){
updateList.forEach(obj -> {
DaoUtils.update(HGSC005A.UPDATE,obj);
});
}
return hgsc005a;
} }
public static void delete(Long matDetailId){ public static void delete(HGSC005A hgsc005a){
AssertUtils.isTrue(Objects.isNull(matDetailId)||matDetailId<=0, "物料清单明细ID不能为空!"); checkUpdateData(hgsc005a);
DaoUtils.update(HGSC005A.DELETE,matDetailId); Map<Long,Optional<HGSC005A>> oldObjMap = queryOldPlanDetail(hgsc005a);
oldObjMap.forEach((k,v)->{
HGSC005A oldObj = v.get();
if(oldObj.getQuantity()-hgsc005a.getQuantity()<=0){
DaoUtils.update(HGSC005A.DELETE, new HashMap<String,Object>(){{put(HGSC005A.FIELD_id,oldObj.getId());}});
}else{
oldObj.setQuantity(oldObj.getQuantity()-hgsc005a.getQuantity());
oldObj.setUnfinishQuantity(oldObj.getQuantity()-oldObj.getFinishQuantity());
DaoUtils.update(HGSC005A.UPDATE,oldObj);
}
});
} }
/** /**
...@@ -188,6 +281,7 @@ public class HGSCTools { ...@@ -188,6 +281,7 @@ public class HGSCTools {
* @param hgsc005a * @param hgsc005a
*/ */
private static void checkUpdateData(HGSC005A hgsc005a) { private static void checkUpdateData(HGSC005A hgsc005a) {
AssertUtils.isTrue(Objects.isNull(hgsc005a.getMatId())||hgsc005a.getMatId()<=0, "物料清单ID不能为空!");
AssertUtils.isTrue(Objects.isNull(hgsc005a.getMatDetailId())||hgsc005a.getMatDetailId()<=0, "物料清单明细ID不能为空!"); AssertUtils.isTrue(Objects.isNull(hgsc005a.getMatDetailId())||hgsc005a.getMatDetailId()<=0, "物料清单明细ID不能为空!");
AssertUtils.isEmpty(hgsc005a.getProductCode(), "产品编码不能为空!"); AssertUtils.isEmpty(hgsc005a.getProductCode(), "产品编码不能为空!");
AssertUtils.isEmpty(hgsc005a.getProductName(), "产品名称不能为空!"); AssertUtils.isEmpty(hgsc005a.getProductName(), "产品名称不能为空!");
...@@ -195,7 +289,8 @@ public class HGSCTools { ...@@ -195,7 +289,8 @@ public class HGSCTools {
AssertUtils.isTrue(Objects.isNull(hgsc005a.getQuantity())||hgsc005a.getQuantity()<=0, "数量不能为空!"); AssertUtils.isTrue(Objects.isNull(hgsc005a.getQuantity())||hgsc005a.getQuantity()<=0, "数量不能为空!");
} }
public static HGSC005A constructObj(HGSC005A hgsc005a, HGSC005 hgsc005){ public static HGSC005A constructObj(HGSC005A hgsc005a){
HGSC005 hgsc005 = THGSC005.queryByMatId(hgsc005a.getMatId());
hgsc005a.setPlanCode(hgsc005.getPlanCode()); hgsc005a.setPlanCode(hgsc005.getPlanCode());
hgsc005a.setCompanyCode(hgsc005.getCompanyCode()); hgsc005a.setCompanyCode(hgsc005.getCompanyCode());
hgsc005a.setCompanyName(hgsc005.getCompanyName()); hgsc005a.setCompanyName(hgsc005.getCompanyName());
......
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