From 098d4e74eb55b47c75869c3c51202b2f22937a7f Mon Sep 17 00:00:00 2001
From: 田源 <lastanimals@163.com>
Date: 星期二, 09 一月 2024 11:30:10 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
Source/UBCS/ubcs-service-api/ubcs-code-api/src/main/java/com/vci/ubcs/code/entity/GroupMapAttrXML.java | 37 ++++++
Source/UBCS/ubcs-service-api/ubcs-code-api/src/main/java/com/vci/ubcs/code/vo/GroupMapAttrXMLVO.java | 23 +++
Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/IGroupMapAttrXMLService.java | 33 +++++
Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/GroupMapAttrXMLServiceImpl.java | 196 +++++++++++++++++++++++++++++++
Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/controller/GroupMapAttrXMLController.java | 51 +++++++-
5 files changed, 327 insertions(+), 13 deletions(-)
diff --git a/Source/UBCS/ubcs-service-api/ubcs-code-api/src/main/java/com/vci/ubcs/code/entity/GroupMapAttrXML.java b/Source/UBCS/ubcs-service-api/ubcs-code-api/src/main/java/com/vci/ubcs/code/entity/GroupMapAttrXML.java
new file mode 100644
index 0000000..4cc82db
--- /dev/null
+++ b/Source/UBCS/ubcs-service-api/ubcs-code-api/src/main/java/com/vci/ubcs/code/entity/GroupMapAttrXML.java
@@ -0,0 +1,37 @@
+package com.vci.ubcs.code.entity;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * 鏄犲皠鏂囦欢
+ * @author ludc
+ * @date 2024/1/8 15:44
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class GroupMapAttrXML {
+
+ /**
+ * 灞炴�ф槧灏勬枃浠跺悕绉�
+ */
+ private String groupMapAttrName;
+
+ /**
+ * 灞炴�ф槧灏勬枃浠朵繚瀛樼殑璺緞
+ */
+ private String attrMapPath;
+
+ /**
+ * 灞炴�ф槧灏勬枃浠跺唴瀹�
+ */
+ private String groupMapAttrContent;
+
+ /**
+ * 鏄惁姝e湪浣跨敤
+ */
+ private Boolean isEnable;
+
+}
diff --git a/Source/UBCS/ubcs-service-api/ubcs-code-api/src/main/java/com/vci/ubcs/code/vo/GroupMapAttrXMLVO.java b/Source/UBCS/ubcs-service-api/ubcs-code-api/src/main/java/com/vci/ubcs/code/vo/GroupMapAttrXMLVO.java
new file mode 100644
index 0000000..f470ab6
--- /dev/null
+++ b/Source/UBCS/ubcs-service-api/ubcs-code-api/src/main/java/com/vci/ubcs/code/vo/GroupMapAttrXMLVO.java
@@ -0,0 +1,23 @@
+package com.vci.ubcs.code.vo;
+
+import com.vci.ubcs.code.entity.GroupMapAttrXML;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * 鏄犲皠鏂囦欢
+ * @author ludc
+ * @date 2024/1/8 15:44
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class GroupMapAttrXMLVO extends GroupMapAttrXML {
+
+ /**
+ * 淇敼xml鏂囦欢鍚嶇О
+ */
+ private String updateXMLName;
+
+}
diff --git a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/controller/GroupMapAttrXMLController.java b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/controller/GroupMapAttrXMLController.java
index 40105b9..7f87250 100644
--- a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/controller/GroupMapAttrXMLController.java
+++ b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/controller/GroupMapAttrXMLController.java
@@ -1,18 +1,22 @@
package com.vci.ubcs.code.controller;
+import com.vci.ubcs.code.entity.GroupMapAttrXML;
import com.vci.ubcs.code.service.IGroupMapAttrXMLService;
+import com.vci.ubcs.code.vo.GroupMapAttrXMLVO;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
+import oracle.jdbc.proxy.annotation.Post;
+import org.apache.ibatis.annotations.Update;
import org.springblade.core.tool.api.R;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
import org.xml.sax.SAXException;
import javax.annotation.Resource;
+import javax.ws.rs.PUT;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
+import java.rmi.ServerException;
+import java.util.List;
/**
* 闆嗗洟灞炴�ф槧灏剎ml閰嶇疆绠$悊
@@ -27,11 +31,44 @@
private final IGroupMapAttrXMLService groupMapAttrXMLService;
- @GetMapping("/getGroupMapXML")
- public R<String> getGroupMapXMLInfo(@RequestParam("xmlName") String xmlName) throws ParserConfigurationException, IOException, SAXException {
- return R.data(groupMapAttrXMLService.getGroupMapXMLInfo(xmlName));
+ /**
+ * 鑾峰彇xml鏂囦欢鐨勮缁嗕俊鎭�
+ * @param groupMapAttrXML
+ * @return
+ * @throws IOException
+ */
+ @GetMapping("/detail")
+ public R<GroupMapAttrXML> getGroupMapXMLInfo(GroupMapAttrXML groupMapAttrXML) throws ServerException {
+ return R.data(groupMapAttrXMLService.getGroupMapXMLInfo(groupMapAttrXML));
}
+ /**
+ * 鑾峰彇鎵�鏈夐厤缃湪nacos涓婄殑xml鏂囦欢鍐呭锛岋紙涔熷氨鏄湪鍚敤鐨剎ml鏄犲皠鏂囦欢锛�
+ * @return
+ */
+ @GetMapping("getGroupMapXMLList")
+ public R<List<GroupMapAttrXML>> getGroupMapXMLList(){
+ return R.data(groupMapAttrXMLService.getGroupMapXMLList());
+ }
+ /**
+ * 淇敼灞炴�ф槧灏勬枃浠�
+ * @param groupMapAttrXMLVO
+ * @return
+ */
+ @PutMapping("/updateGroupMapXML")
+ public R updateGroupMapXML(@RequestBody GroupMapAttrXMLVO groupMapAttrXMLVO) throws IOException {
+ return groupMapAttrXMLService.updateGroupMapXML(groupMapAttrXMLVO);
+ }
+
+ /**
+ * 鏂板闆嗗洟灞炴�ф槧灏勯厤缃枃浠�
+ * @param groupMapAttrXML
+ * @return
+ */
+ @PostMapping("/addGroupMapXML")
+ public R addGroupMapXML(@RequestBody GroupMapAttrXML groupMapAttrXML) throws IOException {
+ return groupMapAttrXMLService.addGroupMapXML(groupMapAttrXML);
+ }
}
diff --git a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/IGroupMapAttrXMLService.java b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/IGroupMapAttrXMLService.java
index 873e6a5..27a4ced 100644
--- a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/IGroupMapAttrXMLService.java
+++ b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/IGroupMapAttrXMLService.java
@@ -1,10 +1,15 @@
package com.vci.ubcs.code.service;
+import com.vci.ubcs.code.entity.GroupMapAttrXML;
+import com.vci.ubcs.code.vo.GroupMapAttrXMLVO;
+import org.springblade.core.tool.api.R;
import org.springframework.stereotype.Service;
import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
+import java.rmi.ServerException;
+import java.util.List;
/**
* 闆嗗洟灞炴�ф槧灏剎ml閰嶇疆绠$悊
@@ -13,6 +18,32 @@
*/
public interface IGroupMapAttrXMLService {
- String getGroupMapXMLInfo(String xmlName) throws ParserConfigurationException, IOException, SAXException;
+ /**
+ * 鑾峰彇xml鏂囦欢鐨勮缁嗕俊鎭�
+ * @param groupMapAttrXML
+ * @return
+ * @throws IOException
+ */
+ GroupMapAttrXML getGroupMapXMLInfo(GroupMapAttrXML groupMapAttrXML) throws ServerException;
+
+ /**
+ * 鑾峰彇鎵�鏈夐厤缃湪nacos涓婄殑xml鏂囦欢鍐呭锛岋紙涔熷氨鏄湪鍚敤鐨剎ml鏄犲皠鏂囦欢锛�
+ * @return
+ */
+ List<GroupMapAttrXML> getGroupMapXMLList();
+
+ /**
+ * 淇敼灞炴�ф槧灏勬枃浠�
+ * @param groupMapAttrXMLVO
+ * @return
+ */
+ R updateGroupMapXML(GroupMapAttrXMLVO groupMapAttrXMLVO) throws IOException;
+
+ /**
+ * 鏂板闆嗗洟灞炴�ф槧灏勯厤缃枃浠�
+ * @param groupMapAttrXML
+ * @return
+ */
+ R addGroupMapXML(GroupMapAttrXML groupMapAttrXML) throws IOException;
}
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