From ec8f519a552206a22806aabdd36a102def1d35f9 Mon Sep 17 00:00:00 2001
From: 刘小明 <liuxm_a@163.com>
Date: 星期二, 23 七月 2024 09:19:00 +0800
Subject: [PATCH] id生成,sql优化
---
pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/process/ProcessSv.java | 160 ++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 122 insertions(+), 38 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 e7bed98..4f2a3b7 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,6 +3,7 @@
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;
@@ -10,11 +11,14 @@
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.util.UserUtil;
+import com.dy.pmsProduct.taskPlan.PlanStatusEnum;
import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
import org.apache.dubbo.common.utils.PojoUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -22,13 +26,16 @@
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
@Service
public class ProcessSv {
+ private PrAssemblyPlanMapper assemblyDao;
private PrProductionProcessMapper processDao;
private PrProductionNodeMapper nodeDao;
private PrWorkingInstructionMapper workDao;
@@ -36,33 +43,49 @@
private FileOperate fileOperate;
private OthFileMapper othFileMapper;
@Value("${dy.webFile.fmUrl}")
- private String fmUrl ;
+ private String fmUrl;
+
@Autowired
- public void setProcessDao(PrProductionProcessMapper dao){
+ public void setAssemblyDao(PrAssemblyPlanMapper assemblyDao) {
+ this.assemblyDao = assemblyDao;
+ }
+
+ @Autowired
+ 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;
}
+
@Transactional
- public int save(PrProductionProcess process){
+ public int save(PrProductionProcess process) {
+ //娴佺▼鍚嶇О涓嶈兘閲嶅
+ if (processDao.exists(process.name, process.id)) {
+ throw new RuntimeException("娴佺▼鍚嶇О涓嶈兘閲嶅");
+ }
prepareProcess(process);
int count = processDao.insertSelective(process);
saveNodesAndInstructions(process);
@@ -70,66 +93,127 @@
}
@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涓嶈兘鍒犻櫎涓嶈兘淇敼
+ 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();
- workDao.insertMany(workList);
+ if (CollectionUtils.isNotEmpty(workList)) {
+ workDao.insertMany(workList);
+ }
}
-
-
- 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);
}
});
@@ -137,13 +221,13 @@
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);
@@ -151,19 +235,19 @@
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);
}
});
});
- return rsVo ;
+ return rsVo;
}
- public List<Map<String,String>> queryAll(){
- return processDao.queryAll();
+ 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;
}
--
Gitblit v1.8.0