From f28acc0e219e7ee9460f4a67e448cea1431ca378 Mon Sep 17 00:00:00 2001
From: yuxc <yuxc@vci-tech.com>
Date: 星期三, 31 七月 2024 11:52:51 +0800
Subject: [PATCH] 增加平台连接类型的导入导出功能
---
Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/controller/OsLinkTypeController.java | 30 ++++
Source/plt-web/plt-web-parent/plt-web-api/src/main/java/com/vci/po/OsLinkTypePO.java | 108 +++++++++++++++
Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/OsLinkTypeServiceI.java | 14 ++
Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsLinkTypeServiceImpl.java | 210 +++++++++++++++++++++++++++++
4 files changed, 358 insertions(+), 4 deletions(-)
diff --git a/Source/plt-web/plt-web-parent/plt-web-api/src/main/java/com/vci/po/OsLinkTypePO.java b/Source/plt-web/plt-web-parent/plt-web-api/src/main/java/com/vci/po/OsLinkTypePO.java
new file mode 100644
index 0000000..b161c8d
--- /dev/null
+++ b/Source/plt-web/plt-web-parent/plt-web-api/src/main/java/com/vci/po/OsLinkTypePO.java
@@ -0,0 +1,108 @@
+package com.vci.po;
+
+import com.vci.starter.poi.annotation.ExcelColumn;
+import com.vci.starter.web.pagemodel.BaseModelVO;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * 閾炬帴绫诲瀷瀵煎叆瀵硅薄
+ * @author yuxc
+ * @date 2024/7/30 16:27
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class OsLinkTypePO extends BaseModelVO {
+
+ /**
+ * 绂佹淇敼杩欎釜鍊�
+ */
+ private static final long serialVersionUID = -2239512786206928201L;
+
+ /**
+ * 鎵�鍦ㄦ暟鎹
+ */
+ @ExcelColumn(rowIndexColumn = true,value = "")
+ private String rowIndex;
+
+ /**
+ * 鏍囩
+ */
+ @ExcelColumn(value="鏍囩",nullable = false)
+ private String tag;
+
+ /**
+ * 鍚嶇О
+ */
+ @ExcelColumn(value="鍚嶇О",nullable = false)
+ private String name;
+
+ /**
+ * 鎻忚堪
+ */
+ @ExcelColumn(value="鎻忚堪")
+ private String description;
+
+ /**
+ * 褰㈢姸
+ */
+ @ExcelColumn(value="褰㈢姸")
+ private String shape;
+
+ /**
+ * to绔搴斿叧绯�
+ */
+ @ExcelColumn(value="To绔搴斿叧绯�")
+ private String relationTo;
+
+ /**
+ * From绔搴斿叧绯�
+ */
+ @ExcelColumn(value="From绔搴斿叧绯�")
+ private String relationFrom;
+
+// /**
+// * 瀵瑰簲鍏崇郴锛宖rom绔湪鍓嶏紝to绔湪鍚�
+// */
+// @ExcelColumn(value="瀵瑰簲鍏崇郴锛宖rom绔湪鍓嶏紝to绔湪鍚�")
+// private String relation;
+
+ /**
+ * To绔富绫诲瀷
+ */
+ @ExcelColumn(value="To绔富绫诲瀷")
+ private String primitivesTo;
+
+ /**
+ * From绔富绫诲瀷
+ */
+ @ExcelColumn(value="From绔富绫诲瀷")
+ private String primitivesFrom;
+
+ /**
+ * 瀹炵幇绫�
+ */
+ @ExcelColumn(value="瀹炵幇绫�")
+ private String implClass;
+
+ /**
+ * From绔被鍨嬪垪琛�
+ */
+ @ExcelColumn(value="From绔被鍨嬪垪琛�")
+ private String btmItemsFrom;
+
+ /**
+ * To绔被鍨嬪垪琛�
+ */
+ @ExcelColumn(value="To绔被鍨嬪垪琛�")
+ private String btmItemsTo;
+
+ /**
+ * 灞炴�у垪琛�
+ */
+ @ExcelColumn(value="灞炴�у垪琛�")
+ private String attributes;
+
+}
diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/controller/OsLinkTypeController.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/controller/OsLinkTypeController.java
index 5d9a344..eededfb 100644
--- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/controller/OsLinkTypeController.java
+++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/controller/OsLinkTypeController.java
@@ -1,14 +1,17 @@
package com.vci.web.controller;
+import com.vci.constant.FrameWorkLangCodeConstant;
import com.vci.corba.common.PLException;
import com.vci.corba.omd.ltm.LinkType;
import com.vci.pagemodel.OsBtmTypeAttributeVO;
import com.vci.pagemodel.OsLinkTypeAttributeVO;
import com.vci.pagemodel.OsLinkTypeVO;
import com.vci.starter.web.annotation.controller.VciUnCheckRight;
+import com.vci.starter.web.exception.VciBaseException;
import com.vci.starter.web.pagemodel.BaseQueryObject;
import com.vci.starter.web.pagemodel.BaseResult;
import com.vci.starter.web.pagemodel.DataGrid;
+import com.vci.starter.web.util.LocalFileUtil;
import com.vci.starter.web.util.VciBaseUtil;
import com.vci.web.service.OsLinkTypeServiceI;
import org.apache.commons.lang3.StringUtils;
@@ -17,7 +20,10 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
@@ -227,4 +233,28 @@
return objectBaseResult;
}
}
+
+ /**
+ * 瀵煎嚭閾炬帴绫诲瀷
+ * name 閾炬帴绫诲瀷鍚嶇О
+ * @return
+ */
+ @GetMapping("/expData")
+ public void expData(String name,HttpServletResponse response) throws PLException, IOException {
+ linkTypeService.expData(name, response);
+ }
+
+ /**
+ * 瀵煎叆閾炬帴绫诲瀷
+ * @param file 涓婁紶鐨勬枃浠�
+ * @return
+ */
+ @PostMapping("/impData")
+ @VciUnCheckRight
+ public BaseResult impData(MultipartFile file){try {
+ return linkTypeService.impData(file);
+ }catch (Throwable e) {
+ throw new VciBaseException(VciBaseUtil.getExceptionMessage(e),new String[0],e);
+ }
+ }
}
diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/OsLinkTypeServiceI.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/OsLinkTypeServiceI.java
index 0fae7cb..d81d452 100644
--- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/OsLinkTypeServiceI.java
+++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/OsLinkTypeServiceI.java
@@ -8,7 +8,9 @@
import com.vci.pagemodel.OsBtmTypeAttributeVO;
import com.vci.pagemodel.OsLinkTypeAttributeVO;
import com.vci.pagemodel.OsLinkTypeVO;
+import org.springframework.web.multipart.MultipartFile;
+import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
@@ -145,4 +147,16 @@
* @return 鍒涘缓缁撴灉
*/
BaseResult createView() throws PLException;
+ /**
+ * 瀵煎嚭閾炬帴绫诲瀷
+ * name 閾炬帴绫诲瀷鍚嶇О
+ * @return 鍒涘缓缁撴灉
+ */
+ void expData(String oid, HttpServletResponse response) throws PLException, IOException;
+ /**
+ * 瀵煎叆閾炬帴绫诲瀷
+ * @param file 涓婁紶鐨勬枃浠�
+ * @return
+ */
+ BaseResult impData(MultipartFile file) throws Exception;
}
diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsLinkTypeServiceImpl.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsLinkTypeServiceImpl.java
index 8b2cf40..febe978 100644
--- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsLinkTypeServiceImpl.java
+++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsLinkTypeServiceImpl.java
@@ -1,26 +1,40 @@
package com.vci.web.service.impl;
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.ZipUtil;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.vci.constant.FrameWorkLangCodeConstant;
import com.vci.corba.common.PLException;
import com.vci.corba.omd.atm.AttributeDef;
import com.vci.corba.omd.btm.BizType;
import com.vci.corba.omd.data.BusinessObject;
import com.vci.corba.omd.ltm.LinkType;
+import com.vci.corba.omd.ltm.LinkTypeServicePrx;
+import com.vci.dto.OsAttributeDTO;
+import com.vci.omd.constants.LinkTypeConstants;
import com.vci.omd.utils.ObjectTool;
import com.vci.pagemodel.*;
+import com.vci.po.OsAttributePO;
+import com.vci.po.OsLinkTypePO;
+import com.vci.starter.poi.bo.ReadExcelOption;
+import com.vci.starter.poi.bo.WriteExcelData;
+import com.vci.starter.poi.bo.WriteExcelOption;
+import com.vci.starter.poi.constant.ExcelLangCodeConstant;
+import com.vci.starter.poi.util.ExcelUtil;
import com.vci.starter.web.annotation.log.VciUnLog;
import com.vci.starter.web.enumpck.VciFieldTypeEnum;
+import com.vci.starter.web.exception.VciBaseException;
import com.vci.starter.web.pagemodel.BaseQueryObject;
import com.vci.starter.web.pagemodel.BaseResult;
import com.vci.starter.web.pagemodel.DataGrid;
-import com.vci.starter.web.util.BeanUtil;
-import com.vci.starter.web.util.VciBaseUtil;
-import com.vci.starter.web.util.VciDateUtil;
+import com.vci.starter.web.util.*;
import com.vci.model.OsLinkTypeDO;
import com.vci.web.service.*;
+import com.vci.web.util.Func;
import com.vci.web.util.PlatformClientUtil;
import com.vci.web.util.WebUtil;
+import javafx.scene.shape.HLineTo;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -28,8 +42,10 @@
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
+import org.springframework.web.multipart.MultipartFile;
-import java.io.IOException;
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
import java.util.*;
import java.util.stream.Collectors;
@@ -40,6 +56,16 @@
*/
@Service
public class OsLinkTypeServiceImpl implements OsLinkTypeServiceI {
+
+ private static final String OID = "oid";
+ private static final String NAME = "name";
+ private static final String LABEL = "label";
+ private static final String DESCRIPTION = "description";
+ private static final String TS = "ts";
+ private static final String CREATOR = "creator";
+ private static final String CREATETIME = "createTime";
+ private static final String MODIFIER = "modifier";
+ private static final String MODIFYTIME = "modifyTime";
/**
* 鏃ュ織
@@ -487,6 +513,182 @@
}
}
+ /**
+ * 瀵煎嚭閾炬帴绫诲瀷
+ * name 閾炬帴绫诲瀷鍚嶇О
+ * @return 鍒涘缓缁撴灉
+ */
+ @Override
+ public void expData(String names, HttpServletResponse response) throws PLException, IOException {
+ String defaultTempFolder = LocalFileUtil.getDefaultTempFolder();
+ //鍐檈xcel
+ String excelPath = defaultTempFolder + File.separator + "lt.xls";
+ //璁剧疆鍒楀悕
+ List<String> columns = new ArrayList<>(
+ Arrays.asList("鍚嶇О", "鏍囩", "瀹炵幇绫�", "褰㈢姸", "From绔被鍨嬪垪琛�", "From绔富绫诲瀷", "From绔搴斿叧绯�",
+ "To绔被鍨嬪垪琛�", "To绔富绫诲瀷", "To绔搴斿叧绯�", "灞炴�у垪琛�", "鎻忚堪")
+ );
+ try {
+ new File(excelPath).createNewFile();
+ //璁剧疆鍒�
+ List<WriteExcelData> excelDataList = new ArrayList<>();
+ //璁剧疆鍒楀ご
+ for (int index = 0; index < columns.size(); index++) {
+ excelDataList.add(new WriteExcelData(0,index, columns.get(index)));
+ }
+ HashSet<String> attributes = new HashSet<>();
+ int i = 0;
+ for (String name : names.split(",")) {
+ LinkType lt = platformClientUtil.getLinkTypeService().getLinkType(name);
+ excelDataList.add(new WriteExcelData(i+1,0, lt.name));
+ excelDataList.add(new WriteExcelData(i+1,1, lt.tag));
+ excelDataList.add(new WriteExcelData(i+1,2, lt.implClass));
+ excelDataList.add(new WriteExcelData(i+1,3, lt.shape));
+ excelDataList.add(new WriteExcelData(i+1,4, String.join(",",lt.btmItemsFrom)));
+ excelDataList.add(new WriteExcelData(i+1,5, lt.primitivesFrom));
+ excelDataList.add(new WriteExcelData(i+1,6, lt.relationFrom));
+ excelDataList.add(new WriteExcelData(i+1,7, String.join(",",lt.btmItemsTo)));
+ excelDataList.add(new WriteExcelData(i+1,8, lt.primitivesTo));
+ excelDataList.add(new WriteExcelData(i+1,9, lt.relationTo));
+ excelDataList.add(new WriteExcelData(i+1,10, String.join(",",lt.attributes)));
+ excelDataList.add(new WriteExcelData(i+1,11, lt.description));
+ attributes.addAll(Arrays.asList(lt.attributes));
+ i++;
+ }
+ WriteExcelOption excelOption = new WriteExcelOption(excelDataList);
+ ExcelUtil.writeDataToFile(excelPath, excelOption);
+ //瀵煎嚭灞炴��
+ String attrPath = attributeService.exportAttributes("attr",
+ String.valueOf(attributes.stream().collect(Collectors.joining(","))));
+ //绉诲姩灞炴�у埌閾炬帴绫诲瀷鏂囦欢澶归噷闈㈠幓
+ FileUtil.move(new File(attrPath), new File(defaultTempFolder),true);
+ FileUtil.del(attrPath.substring(0,attrPath.lastIndexOf("\\")));
+ //todo 瀵煎嚭涓氬姟绫诲瀷杩樻病鏈夊疄鐜�
+// List<BizType> bts = new ArrayList<BizType>();
+// for (String btName : btNameSet) {
+// BizType bt = BtmProvider.getBtmItemByName(btName);
+// bts.add(bt);
+// }
+// boolean btFlag = BtmProvider.expData(rootPath, bts.toArray(new BizType[0]));
+ }catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ File zip = ZipUtil.zip(defaultTempFolder);
+ FileUtil.del(defaultTempFolder + File.separator);
+ ControllerUtil.writeFileToResponse(response,zip.getAbsoluteFile());
+ }
+
+ /**
+ * 瀵煎叆閾炬帴绫诲瀷
+ * @param file 涓婁紶鐨勬枃浠�
+ * @return
+ */
+ @Override
+ public BaseResult impData(MultipartFile file) throws Exception {
+ String defaultTempFolder = LocalFileUtil.getDefaultTempFolder();
+ String fileName = defaultTempFolder + File.separator + LocalFileUtil.getFileNameForIE(file.getOriginalFilename());
+ file.transferTo(new File(fileName));
+ if (file == null) {
+ return BaseResult.fail(FrameWorkLangCodeConstant.IMPORT_FAIL, new String[]{"鏃犲鍏ョ殑鏂囦欢"});
+ }
+ if (!fileName.endsWith(".zip")) {
+ throw new VciBaseException("浠呰兘涓婁紶zip鍘嬬缉鏂囦欢锛岃閲嶆柊涓婁紶锛�");
+ }
+ File unzip = ZipUtil.unzip(fileName);
+ File ltExcel = new File(unzip.getAbsolutePath() + File.separator + "lt.xls");
+ File attrExcel = new File(unzip.getAbsolutePath() + File.separator + "attr.xls");
+ if (!attrExcel.exists()) {
+ //澧炲姞瑙e帇鐨勮矾寰勶紝鐪嬫枃浠惰繕鍦ㄦ病鏈�
+ attrExcel = new File(unzip.getAbsolutePath() + File.separator + unzip.getName() + File.separator + "attr.xls");
+ if (!attrExcel.exists()) {
+ return BaseResult.fail(FrameWorkLangCodeConstant.IMPORT_FAIL, new String[]{"娌℃湁瀵煎叆鐨勫睘鎬ф枃浠躲�傚鍏ョ粓姝紒"});
+ }
+ }
+ BaseResult baseResult = attributeService.importAttributes(attrExcel);
+ if(!baseResult.isSuccess()){
+ //鍒犻櫎涓婁紶鐨勬枃浠跺す
+ FileUtil.del(defaultTempFolder + File.separator);
+ return baseResult;
+ }
+ //todo 杩橀渶瀵煎叆涓氬姟绫诲瀷锛岀瓑寰呭姛鑳藉疄鐜�
+ if (!ltExcel.exists()) {
+ //澧炲姞瑙e帇鐨勮矾寰勶紝鐪嬫枃浠惰繕鍦ㄦ病鏈�
+ ltExcel = new File(unzip.getAbsolutePath() + File.separator + unzip.getName() + File.separator + "lt.xls");
+ if (!ltExcel.exists()) {
+ //鍒犻櫎涓婁紶鐨勬枃浠跺す
+ FileUtil.del(defaultTempFolder + File.separator);
+ return BaseResult.fail(FrameWorkLangCodeConstant.IMPORT_FAIL, new String[]{"娌℃湁瀵煎叆鐨勯摼鎺ユ枃浠躲�傚鍏ョ粓姝紒"});
+ }
+ }
+ try{
+ //1銆佽鍙杄xcel涓殑鏁版嵁锛岀粍鎴愬璞�
+ ReadExcelOption excelOption = new ReadExcelOption();
+ List<OsLinkTypePO> poList = ExcelUtil.readDataObjectFromExcel(ltExcel, OsLinkTypePO.class,excelOption,(value, po, fieldName)->{});
+ //鍘婚櫎閮芥槸绌虹殑鎯呭喌
+ if(CollectionUtils.isEmpty(poList)){
+ return BaseResult.fail(ExcelLangCodeConstant.IMPORT_CONTENT_NULL,new String[]{});
+ }
+ //褰撳墠excel涓槸鍚﹂噸澶嶇敤鐨勫垽閲峂ap:锛坘ey锛氬垽閲嶅睘鎬э紝value锛氳鍙凤級
+ Map<String, String> excelReapeat = new HashMap<>();
+ int maxLength = platformClientUtil.getLinkTypeService().getLTNameMaxLength();
+
+ //鍒ゆ柇蹇呭~灞炴�ф槸鍚︿负绌猴紝鐢ㄦ埛鏄惁宸插瓨鍦紝浠ュ強閮ㄩ棬鏄惁濉敊绛夋牎楠岄�昏緫
+ poList.stream().forEach(osLinkTypePO -> {
+ if(Func.isBlank(osLinkTypePO.getName())){//灞炴�у悕鍒ょ┖
+ throw new VciBaseException("绗��"+osLinkTypePO.getRowIndex()+"銆戣锛宯ame");
+ }else if(osLinkTypePO.getName().length() > maxLength){
+ throw new VciBaseException("绗��"+osLinkTypePO.getRowIndex()+"銆戣锛岄摼鎺ョ被鍨嬪悕闀垮害涓嶈兘瓒呰繃" + maxLength);
+ }else if(!osLinkTypePO.getName().matches("^[A-Za-z]+$")){
+ throw new VciBaseException("绗��"+osLinkTypePO.getRowIndex()+"銆戣锛岄摼鎺ョ被鍨嬪悕绉板彧鑳戒负鑻辨枃瀛楁瘝");
+ }else if(excelReapeat.containsKey(osLinkTypePO.getName())){//灞炴�у悕琛ㄦ牸涓垽閲�
+ throw new VciBaseException("绗��"+excelReapeat.get(osLinkTypePO.getName())+"銆戣鍜岀銆�"+osLinkTypePO.getRowIndex()+"銆戣鏁版嵁锛屽睘鎬у悕閲嶅");
+ }
+ try {
+ LinkType historyLink = platformClientUtil.getLinkTypeService().getLinkType(osLinkTypePO.getName());
+ //宸叉湁姝ゆ暟鎹繘琛屽垹闄よ鐩�
+ if(historyLink != null && !historyLink.name.equals("")){
+ platformClientUtil.getLinkTypeService().deleteLinkType(historyLink);
+ }
+ } catch (PLException e) {
+ throw new RuntimeException(e);
+ }
+
+ //灞炴�у悕excel涓垽閲嶅鐞�
+ excelReapeat.put(osLinkTypePO.getName(),osLinkTypePO.getRowIndex());
+ LinkType linkType = new LinkType();
+ linkType.name = osLinkTypePO.getName();
+ linkType.attributes = osLinkTypePO.getAttributes().split(",");
+ linkType.btmItemsFrom = osLinkTypePO.getBtmItemsFrom().split(",");
+ linkType.primitivesFrom = osLinkTypePO.getPrimitivesFrom();
+ linkType.relationFrom = osLinkTypePO.getRelationFrom();
+ linkType.btmItemsTo = osLinkTypePO.getBtmItemsTo().split(",");
+ linkType.primitivesTo = osLinkTypePO.getPrimitivesTo();
+ linkType.relationTo = osLinkTypePO.getRelationTo();
+ linkType.relation = osLinkTypePO.getRelationFrom() + ":" + osLinkTypePO.getRelationTo();
+ linkType.description = osLinkTypePO.getDescription();
+ linkType.tag = osLinkTypePO.getTag();
+ linkType.shape = osLinkTypePO.getShape();
+ linkType.implClass = osLinkTypePO.getImplClass();
+ linkType.modifier = WebUtil.getCurrentUserId();
+ linkType.creator = WebUtil.getCurrentUserId();
+ try {
+ platformClientUtil.getLinkTypeService().addLinkType(linkType);
+ } catch (PLException e) {
+ throw new RuntimeException(e);
+ }
+
+ });
+ }catch (Exception e){
+ if(logger.isErrorEnabled()){
+ logger.error("璇诲彇excel鍐呭鏃舵垨淇濆瓨鐢ㄦ埛淇℃伅鏃跺嚭鐜颁簡閿欒锛屽叿浣撳師鍥狅細",VciBaseUtil.getExceptionMessage(e));
+ }
+ e.printStackTrace();
+ return BaseResult.fail(VciBaseUtil.getExceptionMessage(e),new String[]{},e);
+ }
+ //鍒犻櫎涓婁紶鐨勬枃浠跺す
+ FileUtil.del(defaultTempFolder + File.separator);
+ return BaseResult.success("閾炬帴绫诲瀷瀵煎叆鎴愬姛锛�");
+ }
/**
* 淇閾炬帴绫诲瀷鐨剎ml鏂囦欢
--
Gitblit v1.9.3