From d4ca3871c18474768c924fcbfd6e8d3178040092 Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期一, 15 九月 2025 01:19:56 +0800
Subject: [PATCH] 性能优化
---
blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/NcNodeService.java | 295 +++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 257 insertions(+), 38 deletions(-)
diff --git a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/NcNodeService.java b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/NcNodeService.java
index f8f4b51..48d78fd 100644
--- a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/NcNodeService.java
+++ b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/NcNodeService.java
@@ -5,6 +5,8 @@
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.mp.base.BizServiceImpl;
import org.springblade.core.tool.utils.Func;
+import org.springblade.mdm.basesetting.machine.service.MachineService;
+import org.springblade.mdm.basesetting.machine.entity.Machine;
import org.springblade.mdm.program.entity.NcNode;
import org.springblade.mdm.program.mapper.NcNodeMapper;
import org.springblade.mdm.program.vo.*;
@@ -15,6 +17,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
+import java.util.Optional;
/**
* 绋嬪簭鑺傜偣
@@ -26,6 +29,7 @@
@AllArgsConstructor
public class NcNodeService extends BizServiceImpl<NcNodeMapper, NcNode> {
+ private final MachineService machineService;
public void saveNcCode(NcNodeVO vo) {
NcNode ncNode = new NcNode();
@@ -72,7 +76,7 @@
* @return
*/
public List<NcNodeVO> lazyList(Long parentId) {
-// 鍒ゆ柇鐐瑰嚮鎼滅储浣嗘槸娌℃湁鏌ヨ鏉′欢鐨勬儏鍐�
+ // 鍒ゆ柇鐐瑰嚮鎼滅储浣嗘槸娌℃湁鏌ヨ鏉′欢鐨勬儏鍐�
if (Func.isEmpty(parentId)) {
parentId = 0L;
}
@@ -91,16 +95,14 @@
return this.getBaseMapper().getLastProgramNode(name);
}
-
/**
* 棣栭〉鏍戞煡璇�
* @param queryVO
* @return
*/
- public List<NcNodeVO> searchList(NcNodeQueryVO queryVO) {
+ public List<NcNodeVO> searchList(NcNodeOldQueryVO queryVO) {
//1.鏍规嵁鍏宠繘瀛楀拰鑺傜偣绫诲瀷鏌ヨ鍒濆鍒楄〃,鏌ヨ鐨勫師濮嬪垪琛紝闇�瑕乭asChild瀛楁锛屾墍浠ヤ娇鐢╩apper.xml
List<NcNodeVO> oriList = this.getBaseMapper().searchList(queryVO);
- //List<NcNode> list = this.lambdaQuery().eq(NcNode::getNodeType, queryVO.getNodeType()).like(NcNode::getName, queryVO.getName()).list();
if ("10".equals(queryVO.getNodeType())) {
//鎼滅储鐨勬牴绾у埆锛岀洿鎺ヨ繑鍥�
return oriList;
@@ -108,8 +110,6 @@
List<NcNodeVO> allVos = new ArrayList<NcNodeVO>();//宸茬粡鍔犲叆杩囩殑鑺傜偣锛岀敤浜庡幓閲�
List<NcNodeVO> rootVos = new ArrayList<NcNodeVO>();
-
- //List<NcNode> rootNodes = new ArrayList<>();
for(NcNodeVO vo : oriList){
allVos.add(vo);
@@ -130,6 +130,42 @@
return rootVos;
}
+ /**
+ * 棣栭〉鎼滅储 鏂扮殑
+ * @param queryVO 鏌ヨ鍙傛暟
+ * @return
+ */
+ public List<NcNodeVO> searchList2(NcNodeQueryVO queryVO) {
+ //1.鏍规嵁闆剁粍浠跺彿鍜屽垱寤烘椂闂存煡璇㈠垵濮嬪垪琛�,鏌ヨ鐨勫師濮嬪垪琛紝闇�瑕乭asChild瀛楁锛屾墍浠ヤ娇鐢╩apper.xml
+ if(queryVO.getCreateTimeEnd()!=null){
+ queryVO.setCreateTimeEnd(queryVO.getCreateTimeEnd().plusDays(1));
+ }
+ List<NcNodeVO> oriList = this.getBaseMapper().searchList2(queryVO);
+
+ List<NcNodeVO> allVos = new ArrayList<>();//宸茬粡鍔犲叆杩囩殑鑺傜偣锛岀敤浜庡幓閲�
+ List<NcNodeVO> rootVos = new ArrayList<>();
+
+ for(NcNodeVO vo : oriList){
+ allVos.add(vo);
+ //涓婄骇鍚勭骇鐨勮妭鐐�
+ List<NcNodeVO> parents = this.getBaseMapper().searchListInIds(Func.toLongList(vo.getParentIds()));
+
+ for(NcNodeVO pvo : parents){
+ if(pvo.getParentId() == 0L && !rootVos.contains(pvo)){
+ rootVos.add(pvo);
+ }
+ if(!allVos.contains(pvo)){
+ allVos.add(pvo);
+ }
+
+ }
+ }
+ for(NcNodeVO root : rootVos){
+ addNodeChildren(root, allVos);
+ }
+ return rootVos;
+ }
+
void addNodeChildren(NcNodeVO node, List<NcNodeVO> allNodes) {
for(NcNodeVO vo : allNodes){
if(Objects.equals(vo.getParentId(), node.getId())){
@@ -142,29 +178,6 @@
addNodeChildren(child, allNodes);
}
}
- }
-
- NcNodeVO toNodeVO(NcNode node){
- NcNodeVO vo = new NcNodeVO();
-
- BeanUtils.copyProperties(node, vo);
-
- return vo;
- }
-
- /**
- * 鑾峰彇绋嬪簭鍖呭悕鐨勬暟鎹�
- * @param programName 绋嬪簭鍚嶇О锛堢▼搴忓寘鍚嶏級
- * @return 绋嬪簭鎶ュ寘鍚嶇殑鑺傜偣
- */
- public NcNode getProgramPackageByName(String programName) {
- List<NcNode> pkgs = this.lambdaQuery().eq(NcNode::getName, programName).eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE).list();
- if(pkgs.isEmpty()){
- return null;
- }else{
- return pkgs.get(0);
- }
-
}
/**
@@ -180,13 +193,17 @@
}
/**
- * 鑾峰彇鈥滅▼搴忓寘鍚嶁�濈殑鏈�鏂扮増鏈�
+ * 鑾峰彇鈥滅▼搴忓寘鍚嶁�濊瘯鍒囩殑鏈�鏂扮増鏈�
* @param name 鑺傜偣鍚嶇О
* @return 鏈�鏂扮増鏈▼搴忔姤鍚嶈妭鐐�
*/
- public NcNode getLastEditionProgramPackage(String name){
+ public NcNode getLastEditionTryingProgramPackage(String name){
+ //.or(NcNode::getIsCured,0)
List<NcNode> pkgList = lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE)
- .eq(NcNode::getName, name).eq(NcNode::getIsLastEdition,1).orderByDesc(NcNode::getCreateTime).list();
+ .eq(NcNode::getName, name).and(i->{
+ i.eq(NcNode::getIsCured, 0).or().isNull(NcNode::getIsCured);
+ }).likeRight(NcNode::getParentIds,"0,1,")
+ .eq(NcNode::getIsLastEdition,1).orderByDesc(NcNode::getCreateTime).list();//.eq(NcNode::getProcessEdition,processEdition)
if(pkgList.isEmpty()){
return null;
@@ -212,23 +229,60 @@
}
/**
- * 鑾峰彇node鐨勫巻鍙插垪琛�(鍚屼竴涓埗鑺傜偣涓嬶紝鍚屽悕鐨勬墍鏈夎妭鐐癸級
+ * 鑾峰彇璇曞垏鑺傜偣node鐨勫巻鍙插垪琛�(闆剁粍浠跺彿锛屽伐搴忓彿锛屽伐搴忕増鏈紝鏈哄簥缁勶級
* @param pkgNode node
* @return 鍘嗗彶鍒楄〃锛屾姤閿欒妭鐐规湰韬�
*/
- public List<NcNode> getNodeHistory(NcNode pkgNode) {
+ public List<NcNode> getTryNodeHistory(NcNode pkgNode) {
+ return this.lambdaQuery().eq(NcNode::getDrawingNo,pkgNode.getDrawingNo())
+ .eq(NcNode::getProcessNo,pkgNode.getProcessNo())
+ .eq(NcNode::getProcessEdition,pkgNode.getProcessEdition())
+ .eq(NcNode::getMachineGroupCode,pkgNode.getMachineGroupCode())
+ .likeLeft(NcNode::getParentIds,"0,1,")
+ .list();//.ne(NcNode::getId,pkgNode.getId())
+ /*
return this.lambdaQuery().eq(NcNode::getParentId,pkgNode.getParentId())
- .eq(NcNode::getName,pkgNode.getName()).list();
+ .eq(NcNode::getName,pkgNode.getName()).list();//.ne(NcNode::getId,pkgNode.getId())
+
+ */
}
+ /**
+ * 璁$畻鍘嗗彶搴忓彿锛屾牴鎹浂缁勪欢鍙凤紝宸ュ簭鍙凤紝宸ュ簭鐗堟锛屾満搴婄粍鏌ヨ锛屾煡璇㈤亾鍒欎娇鐢ㄨ鍘嗗彶缂栧彿锛屾煡璇笉鍒颁娇鐢ㄦ柊鐢熸垚鐨�
+ */
+ public long calculateHistorySerial(NcNode pkgNode) {
+ NcNode node = this.lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE).eq(NcNode::getDrawingNo,pkgNode.getDrawingNo())
+ .eq(NcNode::getProcessNo,pkgNode.getProcessNo()).eq(NcNode::getProcessEdition,pkgNode.getProcessEdition())
+ .eq(NcNode::getMachineGroupCode,pkgNode.getMachineGroupCode()).last("limit 1").one();
+
+ if(node != null && node.getHisSerial()!=null){
+ return node.getHisSerial();
+ }else{
+ //浠ュ線娌℃湁锛岀敓鎴愪竴涓柊鐨�
+ return System.currentTimeMillis();//浣跨敤褰撳墠姣鏁�
+ }
+ }
+
+ public int calculateVersionNumber(NcNode pkgNode) {
+ NcNode node = this.lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE).eq(NcNode::getDrawingNo,pkgNode.getDrawingNo())
+ .eq(NcNode::getProcessNo,pkgNode.getProcessNo()).eq(NcNode::getProcessEdition,pkgNode.getProcessEdition())
+ .eq(NcNode::getMachineGroupCode,pkgNode.getMachineGroupCode()).last("limit 1").one();
+
+ if(node != null && node.getVersionNumber()!=null){
+ return node.getVersionNumber()+1;
+ }else{
+ //浠ュ線娌℃湁锛岀敓鎴愪竴涓柊鐨�
+ return 1;
+ }
+ }
/**
* 鐢熸垚绋嬪簭鍖呭悕/绋嬪簭鍚嶇О
* @param drawingNo 闆剁粍浠跺彿
* @param processNo 宸ュ簭鐗堟
* @return 绋嬪簭鍖呭悕/绋嬪簭鍚嶇О
*/
- public static String genProgramName(String drawingNo,String processNo){
- return drawingNo+"-"+processNo;
+ public static String genProgramName(String drawingNo,String processNo,String processEdition){
+ return drawingNo+"-"+processNo+"-"+processEdition;
}
/**
@@ -238,7 +292,8 @@
*/
public NcNode getLastEditionCuredProgramPackage(String programPkgName) {
List<NcNode> nodes = lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE)
- .eq(NcNode::getName, programPkgName).eq(NcNode::getIsCured,1)
+ .eq(NcNode::getName, programPkgName).likeRight(NcNode::getParentIds,"0,2,").eq(NcNode::getIsCured,1)
+ //.eq(NcNode::getProcessEdition, processEdition)
.eq(NcNode::getIsLastEdition,1).list();
if(nodes.isEmpty()){
@@ -247,4 +302,168 @@
return nodes.get(0);
}
}
+
+ /**
+ * 鑾峰彇鏈�鏂扮増鏈殑 宸插浐鍖栬妭鐐�
+ * @param programPkgName 绋嬪簭鍖呭悕
+ * @param machineCode 鏈哄簥缂栧彿
+ * @return
+ */
+ public NcNode getCuredProgramPackage(String programPkgName,String processEdition,String machineCode) {
+ Machine machine = machineService.getByCode(machineCode);
+ List<Machine> sameGroupMachines = machineService.lambdaQuery().eq(Machine::getMachineGroupCode,machine.getMachineGroupCode()).list();
+ List<String> machineCodesInGroup = sameGroupMachines.stream().map(Machine::getCode).toList();
+ List<NcNode> nodes = lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE)
+ .eq(NcNode::getName, programPkgName)
+ .eq(NcNode::getProcessEdition,processEdition)
+ .likeRight(NcNode::getParentIds,"0,2,").eq(NcNode::getIsCured,1)
+ .in(!machineCodesInGroup.isEmpty(),NcNode::getMachineCode,machineCodesInGroup)
+ .eq(NcNode::getIsLastEdition,1).list();
+
+ if(nodes.isEmpty()){
+ return null;
+ }else {
+ return nodes.get(0);
+ }
+ }
+
+ /**
+ * 鑾峰彇鏈�鏂扮殑鍥哄寲绋嬪簭锛屼笉鐢ㄥ伐搴忕増娆″尮閰�
+ * @param drawingNo
+ * @param processNo
+ * @param machineCode
+ * @return
+ */
+ public NcNode getLastCuredProgramWithoutProcessEdition(String drawingNo, String processNo, String machineCode) {
+ Machine machine = machineService.getByCode(machineCode);
+ List<Machine> sameGroupMachines = machineService.lambdaQuery().eq(Machine::getMachineGroupCode,machine.getMachineGroupCode()).list();
+ List<String> machineCodesInGroup = sameGroupMachines.stream().map(Machine::getCode).toList();
+ List<NcNode> nodes = lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE)
+ .eq(NcNode::getDrawingNo, drawingNo).eq(NcNode::getProcessNo, processNo)
+ .likeRight(NcNode::getParentIds,"0,2,").eq(NcNode::getIsCured,1)
+ .in(!machineCodesInGroup.isEmpty(),NcNode::getMachineCode,machineCodesInGroup)
+ .eq(NcNode::getIsLastEdition,1).orderByDesc(NcNode::getCreateTime).list();
+
+ if(nodes.isEmpty()){
+ return null;
+ }else {
+ return nodes.get(0);
+ }
+ }
+
+ /**
+ * 鑾峰彇鏈�鏂扮増鏈殑 鍋忕鑺傜偣
+ * @param programPkgName 绋嬪簭鍖呭悕
+ * @return 鍋忕鐨勭▼搴忚妭鐐�
+ */
+ public NcNode getLastEditionDeviationProgramPackage(String programPkgName) {//,String processEdition
+ List<NcNode> nodes = lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE)
+ .eq(NcNode::getName, programPkgName)
+ //.eq(NcNode::getProcessEdition, processEdition)
+ .likeRight(NcNode::getParentIds,"0,3,")
+ .eq(NcNode::getIsLastEdition,1).list();
+
+ if(nodes.isEmpty()){
+ return null;
+ }else {
+ return nodes.get(0);
+ }
+ }
+
+ /**
+ * 鏍规嵁娴佺▼瀹炰緥id鑾峰彇node鑺傜偣锛岄兘鏄▼搴忓寘鑺傜偣
+ * @param processInstanceId 娴佺▼瀹炰緥id
+ * @return 瀵瑰簲棰濈郴娆镐絾閭�
+ */
+ public NcNode getByProcessInstanceId(String processInstanceId) {
+ Optional<NcNode> nodeOpt = this.lambdaQuery().eq(NcNode::getProcessInstanceId,processInstanceId).oneOpt();
+ return nodeOpt.orElse(null);
+ }
+
+ /**
+ * 鐗╃悊鍒犻櫎鑺傜偣id涓嬬殑瀛愯妭鐐癸紙鎬ц兘鑰冭檻锛屽惁鍒欐暟鎹お澶氾級
+ * @param nodeId 鑺傜偣id
+ */
+ public void deleteSubNodes(Long nodeId) {
+ this.baseMapper.deleteSubNodes(nodeId);
+ }
+
+ /**
+ * 鑾峰彇绋嬪簭鍖呬笅鎵�鏈夊眰搴忔枃浠惰妭鐐�
+ * @param packageNodeId 绋嬪簭鍖呭悕 鑺傜偣id
+ * @return 鍖呬笅灞炵殑绋嬪簭鏂囦欢
+ */
+ public List<NcNode> getProgramFilesByPackageId(Long packageNodeId) {
+ return this.lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_FILE)
+ .eq(NcNode::getParentId,packageNodeId).eq(NcNode::getIsLastEdition,1).list();
+ }
+ /**
+ * 鍗囩骇鐗堟湰鍙凤紙+1锛�
+ * @param nodeId 鑺傜偣id
+ */
+ @Transactional
+ public void upgradeVersionNumber(Long nodeId) {
+ NcNode node = this.getById(nodeId);
+ node.upgradeVersionNumber();
+ this.updateById(node);
+
+ }
+
+ /**
+ * 閿佸畾鑺傜偣
+ * @param id 绋嬪簭鍖呰妭鐐筰d
+ */
+ @Transactional
+ public void lock(Long id) {
+ NcNode node = this.getById(id);
+ node.lock();
+ this.updateById(node);
+ }
+ @Transactional
+ public void lock(Long id,String remark) {
+ NcNode node = this.getById(id);
+ node.lock(remark);
+ this.updateById(node);
+ }
+ @Transactional
+ public void unlock(Long id) {
+ NcNode node = this.getById(id);
+ node.unlock();
+ this.updateById(node);
+ }
+
+ /**
+ * 鏌ヨ鍋忕鍗曠殑搴忓彿
+ * @param programPkgNode 鍋忕鍗曠殑绋嬪簭鍖呭悕鑺傜偣
+ * @return 搴忓彿
+ */
+ /*
+ public long getDeviationSerialForNode(NcNode programPkgNode) {
+ return lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE)
+ .eq(NcNode::getName,programPkgNode.getName())
+
+ .eq(NcNode::getDrawingNo,programPkgNode.getDrawingNo())
+ .eq(NcNode::getProcessNo,programPkgNode.getProcessNo())
+ .eq(NcNode::getProcessEdition,programPkgNode.getProcessEdition())
+
+ .isNotNull(NcNode::getDeviation)
+ .le(NcNode::getCreateTime,programPkgNode.getCreateTime()) //鏃堕棿灏忎簬绛変簬褰撳墠鑺傜偣
+ .count();
+ }
+ */
+
+ /**
+ * 鏍规嵁涓婄骇鑺傜偣id锛岀Щ鍔ㄤ笅闈㈢殑鍔犲伐鏈哄簥鑺傜偣
+ * @param parentId 涓婄骇鑺傜偣id
+ */
+ public void deleteMachineNodeByParentId(Long parentId) {
+ baseMapper.deleteMachineNodeByParentId(parentId);
+ }
+
+ /**
+ * 鍒犻櫎鎵�鍋堕潪鏈�鏂扮増鏈殑鏁版嵁锛坔odeHIs閲岄潰宸茬粡淇濆瓨杩囷級
+ */
+ public void deleteOldEditionNodeData() {
+ baseMapper.deleteOldEditionNodeData();
+ }
}
--
Gitblit v1.9.3