From 4494a005613728c9dc22d018bca42ef5d3ebcf69 Mon Sep 17 00:00:00 2001
From: xiejun <xiejun@vci-tech.com>
Date: 星期二, 14 一月 2025 20:41:47 +0800
Subject: [PATCH] 产品型号集成,类型转换,人员组织加日志,申请接口引用码段值校验

---
 Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/GroupMapAttrXMLServiceImpl.java |  196 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 191 insertions(+), 5 deletions(-)

diff --git a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/GroupMapAttrXMLServiceImpl.java b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/GroupMapAttrXMLServiceImpl.java
index 1c5b5ce..7c23a2b 100644
--- a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/GroupMapAttrXMLServiceImpl.java
+++ b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/GroupMapAttrXMLServiceImpl.java
@@ -1,24 +1,33 @@
 package com.vci.ubcs.code.service.impl;
 
+import com.vci.ubcs.code.entity.GroupMapAttrXML;
 import com.vci.ubcs.code.service.IGroupMapAttrXMLService;
 import com.vci.ubcs.code.util.gennerAttrMapUtil;
+import com.vci.ubcs.code.vo.GroupMapAttrXMLVO;
 import com.vci.ubcs.code.vo.webserviceModel.attrmap.ClsfAttrMappingDO;
 import com.vci.ubcs.code.vo.webserviceModel.attrmap.LibraryClsfDO;
 import com.vci.ubcs.code.vo.webserviceModel.attrmap.LibraryDO;
 import com.vci.ubcs.code.webService.config.AttributeMapConfig;
 import lombok.extern.slf4j.Slf4j;
 import org.springblade.core.log.exception.ServiceException;
+import org.springblade.core.tool.api.R;
+import org.springblade.core.tool.utils.Func;
 import org.springblade.core.tool.utils.StringUtil;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.EnvironmentAware;
+import org.springframework.core.env.Environment;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 import org.xml.sax.SAXException;
 import javax.xml.parsers.ParserConfigurationException;
 import java.io.File;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.rmi.ServerException;
+import java.security.acl.Group;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -29,18 +38,195 @@
  */
 @Service
 @Slf4j
-public class GroupMapAttrXMLServiceImpl implements IGroupMapAttrXMLService {
+public class GroupMapAttrXMLServiceImpl implements IGroupMapAttrXMLService,EnvironmentAware {
 
-	private static final String XML_FILE_PATH = "C:\\data1\\ubcs\\ubcs-server\\xml\\PDM.xml";
+	@Autowired
+	private AttributeMapConfig attributeMapConfig;
+
+	@Value("${code.universalinterface.attrconfig.attrmap_parent_path:/data1/ubcs/ubcs-server/xml}")
+	private String ATTRMAP_PARENT_PATH;
+
+	/**
+	 * 褰撳墠鎿嶄綔绯荤粺锛屾槸鍚︿负windows绯荤粺
+	 */
+	private String separator = "\\";
+
+	/**
+	 * 鏍规嵁褰撳墠杩愯鐨勭幆澧冿紝鍖归厤鍒嗛殧绗�
+	 * @param environment
+	 */
+	@Override
+	public void setEnvironment(Environment environment) {
+		String os = environment.getProperty("os.name").toLowerCase();
+		if (!os.contains("win")) {
+			this.separator = "/";
+		}
+	}
+
+	/**
+	 * 鑾峰彇xml鏂囦欢鐨勮缁嗕俊鎭�
+	 * @param groupMapAttrXML
+	 * @return
+	 * @throws IOException
+	 */
+	@Override
+	public GroupMapAttrXML getGroupMapXMLInfo(GroupMapAttrXML groupMapAttrXML) throws ServerException {
+		if(Func.isEmpty(groupMapAttrXML.getAttrMapPath())){
+			throw new ServiceException("灞炴�ф槧灏勬枃浠惰矾寰勪笉鑳戒负绌猴紒");
+		}
+		File file = new File(groupMapAttrXML.getAttrMapPath());
+		Map<String, String> stringStringMap = attributeMapConfig.getSystem_attrmap();
+		GroupMapAttrXML data = new GroupMapAttrXML();
+		if (file.exists() && file.isFile()) {
+			data.setGroupMapAttrName(file.getName());
+			data.setAttrMapPath(file.getPath());
+			if(!stringStringMap.isEmpty() && stringStringMap.containsKey(file.getName().replace(".xml",""))){
+				groupMapAttrXML.setIsEnable(true);
+			}else {
+				groupMapAttrXML.setIsEnable(false);
+			}
+			data.setGroupMapAttrContent(getXMLContent(file.getPath()));
+		}
+		return data;
+	}
+
+	/**
+	 * 鑾峰彇鎵�鏈夐厤缃湪nacos涓婄殑xml鏂囦欢鍐呭锛岋紙涔熷氨鏄湪鍚敤鐨剎ml鏄犲皠鏂囦欢锛�
+	 * @return
+	 */
+	@Override
+	public List<GroupMapAttrXML> getGroupMapXMLList() {
+		// 鑾峰彇鍒板凡鍦╪acos涓婇厤缃殑鐨剎ml鏄犲皠鏂囦欢
+		Map<String, String> stringStringMap = attributeMapConfig.getSystem_attrmap();
+		List<GroupMapAttrXML> groupMapAttrXMLList = new ArrayList<>();
+		// 鑾峰彇鍒扮埗璺緞涓嬬殑鏂囦欢淇℃伅
+		File fileDir = new File(ATTRMAP_PARENT_PATH);
+		File[] childDir = fileDir.listFiles();
+		if(Func.isNotEmpty(childDir) && childDir.length > 0){
+			Arrays.stream(childDir).forEach(file->{
+				GroupMapAttrXML groupMapAttrXML = new GroupMapAttrXML();
+				if(!stringStringMap.isEmpty() && stringStringMap.containsKey(file.getName().replace(".xml",""))){
+					groupMapAttrXML.setIsEnable(true);
+				}else {
+					groupMapAttrXML.setIsEnable(false);
+				}
+				groupMapAttrXML.setGroupMapAttrName(file.getName());
+				groupMapAttrXML.setAttrMapPath(file.getPath());
+				try {
+					groupMapAttrXML.setGroupMapAttrContent(getXMLContent(file.getPath()));
+				} catch (ServerException e) {
+					throw new ServiceException(e.getMessage());
+				}
+				groupMapAttrXMLList.add(groupMapAttrXML);
+			});
+		}
+		return groupMapAttrXMLList;
+	}
+
+	/**
+	 * 淇敼灞炴�ф槧灏勬枃浠�
+	 * @param groupMapAttrXMLVO
+	 * @return
+	 */
+	public R updateGroupMapXML(GroupMapAttrXMLVO groupMapAttrXMLVO) throws IOException {
+		if(Func.isEmpty(groupMapAttrXMLVO.getAttrMapPath())){
+			throw new ServiceException("灞炴�ф槧灏勬枃浠惰矾寰勪笉鑳戒负绌猴紒");
+		}
+		File file = new File(groupMapAttrXMLVO.getAttrMapPath());
+		// 鏂囦欢鍚嶇浉鍚岋紝灏卞彧闇�瑕佷慨鏀瑰唴瀹�
+		if(groupMapAttrXMLVO.getGroupMapAttrName().equals(groupMapAttrXMLVO.getUpdateXMLName())){
+			if(!file.exists()){
+				return R.fail("琚慨鏀圭殑"+groupMapAttrXMLVO.getGroupMapAttrName()+"鏂囦欢涓嶅瓨鍦紒");
+			}
+			FileWriter writer = null;
+			try{
+				writer = new FileWriter(file);
+				writer.write(groupMapAttrXMLVO.getGroupMapAttrContent());
+			}catch (IOException e) {
+				e.printStackTrace();
+				throw new ServerException("鏂囦欢鍐呭淇敼澶辫触锛屽師鍥狅細"+e.getMessage());
+			}finally {
+				writer.close();
+			}
+		}else{
+			//淇敼浜嗘枃浠跺悕,灏遍渶瑕佸皢鏂囦欢鍚嶅拰鍐呭杩涜淇敼
+			File newFile = new File(groupMapAttrXMLVO.getAttrMapPath().replace(groupMapAttrXMLVO.getGroupMapAttrName(),groupMapAttrXMLVO.getUpdateXMLName()));
+			FileWriter writer = null;
+			try {
+				writer = new FileWriter(newFile);
+				writer.write(groupMapAttrXMLVO.getGroupMapAttrContent());
+			} catch (IOException e) {
+				e.printStackTrace();
+				throw new ServerException("灞炴�ф槧灏勬枃浠朵慨鏀瑰け璐ワ紝鍘熷洜锛�"+e.getMessage());
+			}finally {
+				writer.close();
+			}
+			if (!file.delete()) {
+				R.fail("灞炴�ф槧灏勬枃浠跺悕淇敼澶辫触锛岃妫�鏌ユ枃浠跺悕鏄惁閲嶅锛�");
+			}
+		}
+		Map<String, String> stringStringMap = attributeMapConfig.getSystem_attrmap();
+		if (!stringStringMap.containsKey(groupMapAttrXMLVO.getUpdateXMLName().replace(".xml",""))) {
+			return R.success("淇敼鎴愬姛锛屼慨鏀瑰睘鎬ф槧灏勬枃浠跺悕涔嬪悗锛屾湭鍦╪acos涓婃壘鍒扮浉鍏抽厤缃紝璇峰強鏃舵洿鏂皀acos涓婄殑閰嶇疆锛�");
+		}
+		return R.success("灞炴�ф槧灏勬枃浠朵慨鏀规垚鍔燂紒");
+	}
 
 	@Override
-	public String getGroupMapXMLInfo(String xmlName) throws IOException {
+	public R addGroupMapXML(GroupMapAttrXML groupMapAttrXML) throws IOException {
+		if(Func.isEmpty(groupMapAttrXML.getGroupMapAttrName())){
+			throw new ServiceException("灞炴�ф槧灏勬枃浠跺悕绉颁笉鑳戒负绌猴紒");
+		}
+		// 鍒涘缓涓�涓柊鏂囦欢
+		File file = new File(ATTRMAP_PARENT_PATH);
+		if(!file.exists()){
+			return R.fail("nacos涓妜ml灞炴�ф槧灏勬枃浠讹紝鐖惰矾寰勯厤缃湁璇紝璇锋鏌ワ紒");
+		}
+		File[] files = file.listFiles();
+		if(files.length>0){
+			List<File> repeatNameFile = Arrays.stream(files).filter(item -> {
+				if (item.getName().equals(groupMapAttrXML.getGroupMapAttrName())) {
+					return true;
+				}
+				return false;
+			}).collect(Collectors.toList());
+			if (!repeatNameFile.isEmpty()) {
+				return R.fail("鏂板鐨勫睘鎬ф槧灏剎ml鏂囦欢鍚嶅凡瀛樺湪锛�");
+			}
+		}
+		File addXMLFile = new File(ATTRMAP_PARENT_PATH + separator + groupMapAttrXML.getGroupMapAttrName());
+		FileWriter writer = null;
 		try {
-			File file = new File(XML_FILE_PATH);
+			// 鍚戞枃浠朵腑鍐欏叆鎸囧畾鍐呭
+			writer = new FileWriter(addXMLFile);
+			writer.write(groupMapAttrXML.getGroupMapAttrContent());
+		} catch (IOException e) {
+			e.printStackTrace();
+			throw new ServerException("鏂囦欢鍐呭鍐欏叆澶辫触锛屽師鍥狅細"+e.getMessage());
+		}finally {
+			writer.close();
+		}
+		Map<String, String> stringStringMap = attributeMapConfig.getSystem_attrmap();
+		if (!stringStringMap.containsKey(groupMapAttrXML.getGroupMapAttrName().replace(".xml",""))) {
+			groupMapAttrXML.setIsEnable(false);
+			return R.success("鏂板鎴愬姛锛屼絾鏂板鐨勫睘鎬ф槧灏勬枃浠跺悕锛屾湭鍦╪acos涓婃壘鍒扮浉鍏抽厤缃紝璇峰強鏃舵洿鏂皀acos涓婄殑閰嶇疆锛�");
+		}else {
+			groupMapAttrXML.setIsEnable(true);
+			return R.success("鏂板鎴愬姛锛�");
+		}
+	}
+
+	/**
+	 * 鑾峰彇xml鏂囦欢涓唴瀹�
+	 * @return
+	 */
+	private String getXMLContent(String xmlPath) throws ServerException {
+		try {
+			File file = new File(xmlPath);
 			byte[] bytes = Files.readAllBytes(Paths.get(file.toURI()));
 			return new String(bytes);
 		} catch (Exception e) {
-			throw new ServerException(StringUtil.format("璇诲彇%s鏂囦欢澶辫触锛屽師鍥狅細%s",xmlName,e.getMessage()));
+			throw new ServerException(StringUtil.format("璇诲彇%s璺緞涓嬬殑xml鏂囦欢澶辫触锛屽師鍥狅細%s",xmlPath,e.getMessage()));
 		}
 	}
 

--
Gitblit v1.9.3