From b5b668d2728665ca05d15be8862ceb0a2796fc67 Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期一, 11 八月 2025 09:18:10 +0800
Subject: [PATCH] 增加替换文件上传

---
 blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/NcNodeService.java |  248 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 240 insertions(+), 8 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 be75a9a..dae2753 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
@@ -1,22 +1,21 @@
 
 package org.springblade.mdm.program.service;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-import org.flowable.engine.*;
 import org.springblade.core.mp.base.BizServiceImpl;
-import org.springblade.core.secure.utils.AuthUtil;
 import org.springblade.core.tool.utils.Func;
-import org.springblade.mdm.basesetting.machine.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.NcNodeVO;
+import org.springblade.mdm.program.vo.*;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
 
 /**
  * 绋嬪簭鑺傜偣
@@ -34,17 +33,37 @@
 
 		BeanUtils.copyProperties(vo, ncNode);
 		ncNode.setId(null);
+		ncNode.setParentIds(buildParentIds(vo.getParentId()));
 
 		this.save(ncNode);
 	}
 
+	/**
+	 * 鏋勫缓鐖秈d鑺傜偣
+	 * @param nodeId 鑺傜偣id
+	 * @return
+	 */
+	String buildParentIds(long nodeId){
+		if(nodeId == 0L){
+			return "0";
+		}
+		NcNode pNode = this.baseMapper.selectById(nodeId);
 
-	public void updateNcCode(NcNodeVO vo) {
+		return pNode.getParentIds()+","+pNode.getId();
+	}
+	/**
+	 * 鏇存柊鑺傜偣
+	 * @param vo
+	 */
+	public void updateNcNode(NcNodeVO vo) {
 		NcNode ncNode = this.getById(vo.getId());
 		ncNode.setName(vo.getName());
 		ncNode.setNodeType(vo.getNodeType());
 		ncNode.setDescription(vo.getDescription());
 		ncNode.setRemark(vo.getRemark());
+		ncNode.setMachineCode(vo.getMachineCode());
+		ncNode.setParentIds(buildParentIds(vo.getParentId()));
+
 		this.updateById(ncNode);
 	}
 
@@ -54,11 +73,224 @@
 	 * @return
 	 */
 	public List<NcNodeVO> lazyList(Long parentId) {
-// 鍒ゆ柇鐐瑰嚮鎼滅储浣嗘槸娌℃湁鏌ヨ鏉′欢鐨勬儏鍐�
+		// 鍒ゆ柇鐐瑰嚮鎼滅储浣嗘槸娌℃湁鏌ヨ鏉′欢鐨勬儏鍐�
 		if (Func.isEmpty(parentId)) {
 			parentId = 0L;
 		}
 
 		return baseMapper.lazyList(parentId);
 	}
+
+
+	/**
+	 * 鏌ヨ鐜版湁鍥哄寲鐨勭▼搴忥紝鏆傚畾鏉′欢锛氶浂缁勪欢鍙风浉鍚岋紝涓旀槸鍚屼竴鏈哄簥缁�
+	 * 	 * @param name 绋嬪簭鍚嶇О
+	 * @param name
+	 * @return
+	 */
+	public NcNode getLastProgramNode(String name) {
+		return this.getBaseMapper().getLastProgramNode(name);
+	}
+
+
+	/**
+	 * 棣栭〉鏍戞煡璇�
+	 * @param queryVO
+	 * @return
+	 */
+	public List<NcNodeVO> searchList(NcNodeQueryVO queryVO) {
+		//1.鏍规嵁鍏宠繘瀛楀拰鑺傜偣绫诲瀷鏌ヨ鍒濆鍒楄〃,鏌ヨ鐨勫師濮嬪垪琛紝闇�瑕乭asChild瀛楁锛屾墍浠ヤ娇鐢╩apper.xml
+		List<NcNodeVO> oriList = this.getBaseMapper().searchList(queryVO);
+		if ("10".equals(queryVO.getNodeType())) {
+			//鎼滅储鐨勬牴绾у埆锛岀洿鎺ヨ繑鍥�
+			return oriList;
+		}
+
+		List<NcNodeVO> allVos = new ArrayList<NcNodeVO>();//宸茬粡鍔犲叆杩囩殑鑺傜偣锛岀敤浜庡幓閲�
+		List<NcNodeVO> rootVos = new ArrayList<NcNodeVO>();
+
+		//List<NcNode> rootNodes = 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.add(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())){
+				node.addChildren(vo);
+			}
+		}
+
+		if(node.getChildren()!=null && !node.getChildren().isEmpty()){
+			for(NcNodeVO child : node.getChildren()){
+				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);
+		}
+
+	}
+
+	/**
+	 * 鏌ヨ鑺傜偣鐨勫巻鍙插垪琛紙鑺傜偣鐨勪笂绾ц妭鐐光�濈▼搴忓寘鍚嶁�滃洜涓哄瓨鍦ㄥ涓増鏈紝鎵�浠ュ巻鍙茶褰曚篃闇�瑕佹牴鎹笉鍚岀増鏈▼搴忓寘鍚嶈繘琛屾煡璇級
+	 * @param id
+	 * @return
+	 */
+	@Transactional(readOnly = true)
+    public List<NcNodeVO> historyByNodeId(Long id) {
+		NcNode node = this.getById(id);
+		NcNode parentNode = this.getById(node.getParentId());
+		return this.baseMapper.historyByParentIdAndName(node.getName(),parentNode);
+    }
+
+	/**
+	 * 鑾峰彇鈥滅▼搴忓寘鍚嶁�濊瘯鍒囩殑鏈�鏂扮増鏈�
+	 * @param name 鑺傜偣鍚嶇О
+	 * @return 鏈�鏂扮増鏈▼搴忔姤鍚嶈妭鐐�
+	 */
+	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).orderByDesc(NcNode::getCreateTime).list();
+
+		if(pkgList.isEmpty()){
+			return null;
+		}else{
+			return pkgList.get(0);
+		}
+	}
+
+	/**
+	 * 鏍规嵁鐖惰妭鐐瑰拰鍚嶇О锛屾煡璇㈡枃浠剁晫鑺傜偣鍒楄〃
+	 * @param name 鑺傜偣/鏂囦欢鍚嶇О
+	 * @param parentId 鐖惰妭鐐筰d
+	 */
+    public NcNode getLastEditionProgramFile(String name,Long parentId) {
+		List<NcNode> nodes = lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_FILE)
+			.eq(NcNode::getName, name).eq(NcNode::getParentId,parentId)
+			.eq(NcNode::getIsLastEdition,1).list();
+		if(nodes.isEmpty()){
+			return null;
+		}else {
+			return nodes.get(0);
+		}
+	}
+
+	/**
+	 * 鑾峰彇node鐨勫巻鍙插垪琛�(鍚屼竴涓埗鑺傜偣涓嬶紝鍚屽悕鐨勬墍鏈夎妭鐐癸級
+	 * @param pkgNode node
+	 * @return 鍘嗗彶鍒楄〃锛屾姤閿欒妭鐐规湰韬�
+	 */
+    public List<NcNode> getNodeHistory(NcNode pkgNode) {
+		return this.lambdaQuery().eq(NcNode::getParentId,pkgNode.getParentId())
+			.eq(NcNode::getName,pkgNode.getName()).list();
+    }
+
+	/**
+	 * 鐢熸垚绋嬪簭鍖呭悕/绋嬪簭鍚嶇О
+	 * @param drawingNo 闆剁粍浠跺彿
+	 * @param processNo 宸ュ簭鐗堟
+	 * @return 绋嬪簭鍖呭悕/绋嬪簭鍚嶇О
+	 */
+	public static String genProgramName(String drawingNo,String processNo){
+		return drawingNo+"-"+processNo;
+	}
+
+	/**
+	 * 鑾峰彇鏈�鏂扮増鏈殑 宸插浐鍖栬妭鐐�
+	 * @param programPkgName
+	 * @return
+	 */
+	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::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);
+
+	}
 }

--
Gitblit v1.9.3