From 7a1ab2693de593026b420fd89b977881eee484ff Mon Sep 17 00:00:00 2001
From: Fancy <Fancy.fx@outlook.com>
Date: 星期三, 16 十月 2024 17:10:48 +0800
Subject: [PATCH] command crud
---
pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/process/ProcessSv.java | 200 ++++++++++++++++++++++++++++++++++---------------
1 files changed, 138 insertions(+), 62 deletions(-)
diff --git a/pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/process/ProcessSv.java b/pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/process/ProcessSv.java
index 961200e..697912e 100644
--- a/pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/process/ProcessSv.java
+++ b/pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/process/ProcessSv.java
@@ -3,18 +3,12 @@
import com.dy.common.webFilter.UserTokenContext;
import com.dy.common.webUtil.QueryResultVo;
import com.dy.pmsGlobal.daoOth.OthFileMapper;
-import com.dy.pmsGlobal.daoPr.PrAssemblyPlanMapper;
-import com.dy.pmsGlobal.daoPr.PrProductionNodeMapper;
-import com.dy.pmsGlobal.daoPr.PrProductionProcessMapper;
-import com.dy.pmsGlobal.daoPr.PrWorkingInstructionMapper;
+import com.dy.pmsGlobal.daoPr.*;
import com.dy.pmsGlobal.dyFile.FileOperate;
import com.dy.pmsGlobal.dyFile.FileRestVo;
import com.dy.pmsGlobal.pojoBa.BaUser;
import com.dy.pmsGlobal.pojoOth.OthFile;
-import com.dy.pmsGlobal.pojoPr.PrAssemblyPlan;
-import com.dy.pmsGlobal.pojoPr.PrProductionNode;
-import com.dy.pmsGlobal.pojoPr.PrProductionProcess;
-import com.dy.pmsGlobal.pojoPr.PrWorkingInstruction;
+import com.dy.pmsGlobal.pojoPr.*;
import com.dy.pmsGlobal.util.UserUtil;
import com.dy.pmsProduct.taskPlan.PlanStatusEnum;
import lombok.extern.slf4j.Slf4j;
@@ -26,8 +20,10 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@Slf4j
@@ -37,41 +33,54 @@
private PrProductionProcessMapper processDao;
private PrProductionNodeMapper nodeDao;
private PrWorkingInstructionMapper workDao;
+ private PrBillOfMaterialMapper billDao;
private UserUtil userUtil;
private FileOperate fileOperate;
private OthFileMapper othFileMapper;
@Value("${dy.webFile.fmUrl}")
- private String fmUrl ;
+ private String fmUrl;
+
@Autowired
public void setAssemblyDao(PrAssemblyPlanMapper assemblyDao) {
this.assemblyDao = assemblyDao;
}
+
@Autowired
- public void setProcessDao(PrProductionProcessMapper dao){
+ public void setProcessDao(PrProductionProcessMapper dao) {
processDao = dao;
}
+
@Autowired
- public void setNodeDao(PrProductionNodeMapper dao){
+ public void setNodeDao(PrProductionNodeMapper dao) {
nodeDao = dao;
}
+
@Autowired
- public void setWorkDao(PrWorkingInstructionMapper dao){
+ public void setWorkDao(PrWorkingInstructionMapper dao) {
workDao = dao;
}
+
@Autowired
- public void setUserUtil(UserUtil userUtil){
+ public void setUserUtil(UserUtil userUtil) {
this.userUtil = userUtil;
}
+
@Autowired
- public void setFileOperate(FileOperate fileOperate){
+ public void setFileOperate(FileOperate fileOperate) {
this.fileOperate = fileOperate;
}
+
@Autowired
- public void setOthFileMapper(OthFileMapper othFileMapper){
+ public void setOthFileMapper(OthFileMapper othFileMapper) {
this.othFileMapper = othFileMapper;
}
+ @Autowired
+ public void setBillDao(PrBillOfMaterialMapper billDao) {
+ this.billDao = billDao;
+ }
+
@Transactional
- public int save(PrProductionProcess process){
+ public int save(PrProductionProcess process) {
//娴佺▼鍚嶇О涓嶈兘閲嶅
if (processDao.exists(process.name, process.id)) {
throw new RuntimeException("娴佺▼鍚嶇О涓嶈兘閲嶅");
@@ -83,106 +92,156 @@
}
@Transactional
- public int update(PrProductionProcess process){
+ public int update(PrProductionProcess process) {
//娴佺▼鍚嶇О涓嶈兘閲嶅
if (processDao.exists(process.name, process.id)) {
throw new RuntimeException("娴佺▼鍚嶇О涓嶈兘閲嶅");
}
PrProductionProcess originProductionProcess = processDao.selectByPrimaryKey(process.id);
- //濡傛灉宸茬粡缁戝畾浠诲姟(鐩墠涓嶅寘鎷殏鍋淺缁撴潫鐘舵�� 鎶曞叆鏁颁负0鐨勪换鍔� 浠ュ鐨� 鎵�鏈変换鍔�),浜у搧\鑺傜偣id涓嶈兘鍒犻櫎涓嶈兘淇敼
- if(!originProductionProcess.getProName().equals(process.getProName())){
- //缁勮浠诲姟璁″垝
- PrAssemblyPlan params = new PrAssemblyPlan();
- params.setProcessId(process.id);
- List<PrAssemblyPlan> planList = assemblyDao.selectAssyPlanSimplify(params);
- List<PrAssemblyPlan> onlinePlanList = planList.stream().filter(plan -> plan.getStatus() == PlanStatusEnum.NORMAL.getCode()).collect(Collectors.toList());
- if (CollectionUtils.isNotEmpty(planList)) {
- if (planList.stream().anyMatch(plan -> plan.getInputNumber() > 0)) {
- throw new RuntimeException("瀛樺湪缁戝畾鐨勪换鍔�,骞朵笖鎶曞叆鐢熶骇,浜у搧涓嶈兘淇敼");
- }else if(CollectionUtils.isNotEmpty(onlinePlanList)){
- //鍏堝皢缁勮浠诲姟缃负鏆傚仠鐘舵��
- onlinePlanList.forEach(plan -> {
- plan.status = PlanStatusEnum.PAUSE.getCode();
- assemblyDao.updateByPrimaryKeySelective(plan);
- });
+ //濡傛灉宸茬粡缁戝畾缁勮浠诲姟璁″垝(鐩墠涓嶅寘鎷殏鍋淺缁撴潫鐘舵�� 鎶曞叆鏁颁负0鐨勪换鍔� 浠ュ鐨� 鎵�鏈変换鍔�),浜у搧\鑺傜偣id涓嶈兘鍒犻櫎涓嶈兘淇敼
+ PrAssemblyPlan params = new PrAssemblyPlan();
+ params.setProcessId(process.id);
+ List<PrAssemblyPlan> planList = assemblyDao.selectAssyPlanSimplify(params);
+ List<PrAssemblyPlan> onlinePlanList = planList.stream().filter(plan -> plan.getStatus() == PlanStatusEnum.NORMAL.getCode()).collect(Collectors.toList());
+ if (CollectionUtils.isNotEmpty(planList)) {
+ if (planList.stream().anyMatch(plan -> plan.getInputNumber() > 0)) { //瀛樺湪浠诲姟宸茬粡鎶曞叆鐢熶骇
+ if (!originProductionProcess.getProId().equals(process.getProId())) {
+ throw new RuntimeException("瀛樺湪宸茬粡鎶曞叆鐢熶骇鐨勭粦瀹氫换鍔�,浜у搧涓嶈兘淇敼");
}
+ //鑺傜偣id涓嶈兘鍒犻櫎
+ if (!originProductionProcess.getNodes().stream().allMatch(node -> process.getNodes().stream().anyMatch(newNode -> node.getId().equals(newNode.getId())))) {
+ throw new RuntimeException("宸叉湁缁戝畾鐨勪换鍔℃姇鍏ョ敓浜�,鑺傜偣涓嶈兘鍒犻櫎");
+ }
+ } else if (CollectionUtils.isNotEmpty(onlinePlanList)) {
+ //鍏堝皢缁勮浠诲姟缃负鏆傚仠鐘舵��
+ onlinePlanList.forEach(plan -> {
+ plan.status = PlanStatusEnum.PAUSE.getCode();
+ assemblyDao.updateByPrimaryKeySelective(plan);
+ });
}
}
prepareProcess(process);
int count = processDao.updateByPrimaryKeySelective(process);
- // 浼樺寲锛氬彧鏈夊綋鑺傜偣鏈夊彉鏇存椂鎵嶅垹闄ゅ苟閲嶆柊鎻掑叆
- if (!process.nodes.isEmpty()) {
- List<Long> nodeIdsToDelete = process.getNodes().stream()
- .map(PrProductionNode::getId) // 鏄犲皠鑺傜偣鍒板叾ID
- .collect(Collectors.toList());
- workDao.deleteByNodeId(nodeIdsToDelete);
- nodeDao.deleteByProcessId(process.id);
+ // 浼樺寲锛氬彧鏈夊綋鑺傜偣鏈夊彉鏇存椂 鏍规嵁ID鏇存柊鍐呭 娌℃湁鍖归厤鍒扮殑ID 鍒犻櫎 澶氫綑鐨処D 鏂板
+
+ List<Long> nodeIdsToDelete = originProductionProcess.getNodes().stream()
+ .filter(node -> process.nodes.stream().filter(newNode -> node.getId().equals(newNode.getId())).count() == 0)
+ .map(PrProductionNode::getId) // 鏄犲皠鑺傜偣鍒板叾ID
+ .collect(Collectors.toList());
+ if (CollectionUtils.isNotEmpty(nodeIdsToDelete)) {
+ nodeDao.deleteByNodeId(nodeIdsToDelete);
+ }
+ //鍘熸潵鑺傜偣鐨凷OP鍏ㄩ儴鍒犻櫎
+ List<Long> originNodeIds = originProductionProcess.getNodes().stream()
+ .map(PrProductionNode::getId) // 鏄犲皠鑺傜偣鍒板叾ID
+ .collect(Collectors.toList());
+ if (CollectionUtils.isNotEmpty(originNodeIds)) {
+ workDao.deleteByNodeId(originNodeIds);
}
saveNodesAndInstructions(process);
return count;
}
// 鎻愬彇鍏遍�氶�昏緫鍒板崟鐙柟娉曚互鍑忓皯浠g爜閲嶅
- private void prepareProcess(PrProductionProcess process){
+ private void prepareProcess(PrProductionProcess process) {
process.disabled = false;
process.deleted = false;
BaUser loginUser = userUtil.getUser(UserTokenContext.get());
- if(loginUser!=null){
+ if (loginUser != null) {
process.creator = loginUser.id;
}
+ AtomicInteger startCount = new AtomicInteger();
+ AtomicInteger endCount = new AtomicInteger();
process.nodes.forEach(node -> {
node.processId = process.id;
- node.deleted= false;
+ node.deleted = false;
+ if(node.isStart){
+ startCount.getAndIncrement();
+ }
+ if(node.isEnd){
+ endCount.getAndIncrement();
+ }
});
+ if (startCount.get() != 1 || endCount.get() != 1) {
+ throw new RuntimeException("寮�濮嬭妭鐐瑰拰缁撴潫鑺傜偣鏈変笖鍙兘鏈変竴涓�");
+ }
}
// 灏嗚妭鐐瑰拰宸ヤ綔鎸囩ず鐨勪繚瀛橀�昏緫灏佽鍒颁竴涓柟娉曚腑
- private void saveNodesAndInstructions(PrProductionProcess process){
+ private void saveNodesAndInstructions(PrProductionProcess process) {
+ List<PrProductionNode> haveIdList = new ArrayList<>();
+ List<PrProductionNode> noIdList = new ArrayList<>();
+
process.nodes.forEach(node -> {
node.processId = process.id;
+ if (node.getId() != null && node.getId() != 0) {
+ haveIdList.add(node);
+ } else {
+ noIdList.add(node);
+ }
});
- try{
- nodeDao.insertMany(process.nodes);
- }catch (DuplicateKeyException e){
+ try {
+ if (haveIdList.size() > 0) {
+ for (int i = 0; i < haveIdList.size(); i++) {
+ nodeDao.updateByPrimaryKeySelective(haveIdList.get(i));
+ }
+ }
+ if (noIdList.size() > 0) {//CollectionUtils.isNotEmpty(noIdList)
+ nodeDao.insertMany(noIdList);
+ }
+ } catch (DuplicateKeyException e) {
throw new RuntimeException("鑺傜偣椤哄簭閲嶅");
}
List<PrWorkingInstruction> workList = process.nodes.stream().map(node -> {
- if(node.instruction !=null){
+ if (node.instruction != null) {
node.instruction.nodeId = node.id;
return node.instruction;
}
return null;
}).filter(work -> work != null).toList();
- if(CollectionUtils.isNotEmpty(workList)){
+ if (CollectionUtils.isNotEmpty(workList)) {
workDao.insertMany(workList);
+ }
+
+ List<PrBillOfMaterial> billList = process.nodes.stream().map(node -> {
+ if (node.bill != null) {
+ node.bill.nodeId = node.id;
+ return node.bill;
+ }
+ return null;
+ }).filter(bill -> bill != null).toList();
+ if (CollectionUtils.isNotEmpty(billList)) {
+ billDao.deleteByNodeId(billList.stream().map(PrBillOfMaterial::getNodeId).toList());
+ billDao.insertMany(billList);
}
}
-
-
- public int delete(Long id){
+ public int delete(Long id) {
return processDao.deleteLogicById(id);
}
- public PrProductionProcess selectById(Long id){
+ public PrProductionProcess selectById(Long id) {
PrProductionProcess process = processDao.selectByPrimaryKey(id);
- if(process != null){
+ if (process != null) {
process.nodes.forEach(node -> {
- if(node.instruction != null){
+ if (node.instruction != null) {
addUrl(node.instruction);
+ }
+ if (node.bill != null) {
+ addBillUrl(node.bill);
}
});
}
return process;
}
- public QueryResultVo<List<PrProductionProcess>> selectSome(QueryVo queryVo){
+ public QueryResultVo<List<PrProductionProcess>> selectSome(QueryVo queryVo) {
Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo);
//鏌ヨ绗﹀悎鏉′欢鐨勮褰曟�绘暟
Long itemTotal = processDao.selectSomeCount(params);
- QueryResultVo<List<PrProductionProcess>> rsVo = new QueryResultVo<>(queryVo.pageSize, queryVo.pageCurr) ;
+ QueryResultVo<List<PrProductionProcess>> rsVo = new QueryResultVo<>(queryVo.pageSize, queryVo.pageCurr);
//璁$畻鍒嗛〉绛変俊鎭�
rsVo.calculateAndSet(itemTotal, params);
@@ -190,19 +249,22 @@
rsVo.obj = processDao.selectSome(params);
rsVo.obj.stream().forEach(process -> {
process.nodes.forEach(node -> {
- if(node.instruction != null){
+ if (node.instruction != null) {
addUrl(node.instruction);
+ }
+ if (node.bill != null) {
+ addBillUrl(node.bill);
}
});
});
- return rsVo ;
+ return rsVo;
}
- public List<Map<String,String>> queryAll(Long proId){
+ public List<Map<String, String>> queryAll(Long proId) {
return processDao.queryAll(proId);
}
- private void addUrl(PrWorkingInstruction ins){
+ private void addUrl(PrWorkingInstruction ins) {
if (ins == null || ins.fileId == null) {
return;
}
@@ -211,8 +273,22 @@
return;
}
FileRestVo fileRestVo = fileOperate.parseHashcode(fmUrl, file.hash);
- ins.webUrl = fileRestVo.fileSysRestUrl + fileRestVo.fileWebDownloadPath + ins.fileId;
+ ins.webUrl = fileRestVo.fileWebDownloadPath + ins.fileId;
ins.orgName = file.orgName;
ins.extName = file.extName;
}
+
+ private void addBillUrl(PrBillOfMaterial bill) {
+ if (bill == null || bill.fileId == null) {
+ return;
+ }
+ OthFile file = othFileMapper.selectByPrimaryKey(bill.fileId);
+ if (file == null) {
+ return;
+ }
+ FileRestVo fileRestVo = fileOperate.parseHashcode(fmUrl, file.hash);
+ bill.webUrl = fileRestVo.fileWebDownloadPath + bill.fileId;
+ bill.orgName = file.orgName;
+ bill.extName = file.extName;
+ }
}
--
Gitblit v1.8.0