From dc01577b31204fd3c80645b45d81ff693f79a985 Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期三, 10 九月 2025 23:04:20 +0800
Subject: [PATCH] 程序包名增加版次

---
 blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/NcNodeService.java |  147 +++++++++++++++++++++++++++++++++++-------------
 1 files changed, 106 insertions(+), 41 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 fbfc9d6..55aff67 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,7 +5,7 @@
 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.MachineService;
+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;
@@ -95,13 +95,12 @@
 		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);
 		if ("10".equals(queryVO.getNodeType())) {
@@ -111,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);
@@ -133,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())){
@@ -145,31 +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::getIsLastEdition,1)
-			.eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE).list();
-		if(pkgs.isEmpty()){
-			return null;
-		}else{
-			return pkgs.get(0);
-		}
-
 	}
 
 	/**
@@ -189,13 +197,13 @@
 	 * @param name 鑺傜偣鍚嶇О
 	 * @return 鏈�鏂扮増鏈▼搴忔姤鍚嶈妭鐐�
 	 */
-	public NcNode getLastEditionTryingProgramPackage(String name,String processEdition){
+	public NcNode getLastEditionTryingProgramPackage(String name){
 		//.or(NcNode::getIsCured,0)
 		List<NcNode> pkgList = lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE)
 			.eq(NcNode::getName, name).and(i->{
 				i.eq(NcNode::getIsCured, 0).or().isNull(NcNode::getIsCured);
 			}).likeRight(NcNode::getParentIds,"0,1,")
-			.eq(NcNode::getIsLastEdition,1).eq(NcNode::getProcessEdition,processEdition).orderByDesc(NcNode::getCreateTime).list();
+			.eq(NcNode::getIsLastEdition,1).orderByDesc(NcNode::getCreateTime).list();//.eq(NcNode::getProcessEdition,processEdition)
 
 		if(pkgList.isEmpty()){
 			return null;
@@ -236,8 +244,8 @@
 	 * @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;
 	}
 
 	/**
@@ -245,10 +253,10 @@
 	 * @param programPkgName
 	 * @return
 	 */
-	public NcNode getLastEditionCuredProgramPackage(String programPkgName,String processEdition) {
+	public NcNode getLastEditionCuredProgramPackage(String programPkgName) {
 		List<NcNode> nodes = lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE)
 			.eq(NcNode::getName, programPkgName).likeRight(NcNode::getParentIds,"0,2,").eq(NcNode::getIsCured,1)
-			.eq(NcNode::getProcessEdition, processEdition)
+			//.eq(NcNode::getProcessEdition, processEdition)
 			.eq(NcNode::getIsLastEdition,1).list();
 
 		if(nodes.isEmpty()){
@@ -264,14 +272,40 @@
 	 * @param machineCode 鏈哄簥缂栧彿
 	 * @return
 	 */
-	public NcNode getCuredProgramPackage(String programPkgName,String machineCode) {
+	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).likeRight(NcNode::getParentIds,"0,2,").eq(NcNode::getIsCured,1)
+			.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;
@@ -285,10 +319,10 @@
 	 * @param programPkgName 绋嬪簭鍖呭悕
 	 * @return 鍋忕鐨勭▼搴忚妭鐐�
 	 */
-	public NcNode getLastEditionDeviationProgramPackage(String programPkgName,String processEdition) {
+	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)
+			//.eq(NcNode::getProcessEdition, processEdition)
 			.likeRight(NcNode::getParentIds,"0,3,")
 			.eq(NcNode::getIsLastEdition,1).list();
 
@@ -326,7 +360,6 @@
 		return this.lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_FILE)
 			.eq(NcNode::getParentId,packageNodeId).eq(NcNode::getIsLastEdition,1).list();
 	}
-
 	/**
 	 * 鍗囩骇鐗堟湰鍙凤紙+1锛�
 	 * @param nodeId 鑺傜偣id
@@ -350,9 +383,41 @@
 		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);
+	}
 }

--
Gitblit v1.9.3