From 6c391d600182930913b43e2f63b7d3cfa131cfc2 Mon Sep 17 00:00:00 2001
From: ludc
Date: 星期三, 14 八月 2024 16:27:58 +0800
Subject: [PATCH] 业务类型创建索引、导出、导入等接口,属性池导入接口调整上传。

---
 Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsAttributeServiceImpl.java |  157 ++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 110 insertions(+), 47 deletions(-)

diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsAttributeServiceImpl.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsAttributeServiceImpl.java
index 7a4ac81..302d878 100644
--- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsAttributeServiceImpl.java
+++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/OsAttributeServiceImpl.java
@@ -7,6 +7,7 @@
 import com.vci.client.mw.ClientSessionUtility;
 import com.vci.corba.common.PLException;
 import com.vci.corba.omd.atm.AttributeDef;
+import com.vci.corba.omd.vrm.VersionRule;
 import com.vci.dto.OsAttributeDTO;
 import com.vci.dto.OsEnumDTO;
 import com.vci.dto.OsEnumItemDTO;
@@ -33,6 +34,7 @@
 import com.vci.web.properties.UsedNames;
 import com.vci.web.service.OsAttributeServiceI;
 import com.vci.web.service.OsBaseServiceI;
+import com.vci.web.service.OsEnumServiceI;
 import com.vci.web.service.OsLinkTypeServiceI;
 import com.vci.web.util.Func;
 import com.vci.web.util.PlatformClientUtil;
@@ -111,6 +113,13 @@
 	@Autowired(required = false)
 	@Lazy
 	private OsBtmServiceImpl osBtmService;
+
+	/**
+	 * 鏋氫妇鐨勬湇鍔�
+	 */
+	@Autowired
+	@Lazy
+	private OsEnumServiceI  enumService;
 
 	/**
 	 *  蹇呭~鍒�
@@ -198,14 +207,10 @@
 	public List<OsAttributeVO> getByAttributeNames(String[] attrNames) throws PLException {
 		VciBaseUtil.alertNotNull(attrNames,"灞炴�у悕");
 		List<OsAttributeVO> osAttributeVOS = new ArrayList<>();
-		for (int i = 0; i < attrNames.length; i++) {
-			AttributeDef[] attributeDefs = platformClientUtil.getAttributeService().getAttributeDefs(attrNames[i].toLowerCase(Locale.ROOT),1,1);
-			if(Func.isNotEmpty(attributeDefs)){
-				Arrays.stream(attributeDefs).forEach(attributeDef -> {
-					osAttributeVOS.add(attributeDO2VO(attributeDef));
-				});
-			}
-		}
+		AttributeDef[] attributeDefs = platformClientUtil.getAttributeService().getAttributeDefsByNames(attrNames);
+		Arrays.stream(attributeDefs).forEach(attr->{
+			osAttributeVOS.add(attributeDO2VO(attr));
+		});
 		return osAttributeVOS;
 	}
 
@@ -474,10 +479,13 @@
 		);
 		//灞炴�ц嫳鏂囧悕绉版牎楠岋紙鍒ょ┖銆佺郴缁熶腑鍒ら噸銆佹槸鍚﹀叧閿瓧銆佹槸鍚﹀悎瑙勭瓑锛�
 		checkName(osAttributeDTO.getId());
+		//妫�鏌ュ睘鎬у悕鏄惁宸插瓨鍦ㄤ笌绯荤粺涓�
+		if(platformClientUtil.getAttributeService().checkRowIsExists(osAttributeDTO.getId())){
+			throw new PLException("500",new String[]{"灞炴�у悕绉般��" + osAttributeDTO.getId() + "銆戝湪绯荤粺涓凡瀛樺湪!"});
+		}
 		//妫�鏌ラ粯璁ゅ�间笌灞炴�х被鍨嬫槸鍚﹀尮閰�
 		checkDefValue(osAttributeDTO);
-		//dto瀵硅薄杞崲涓哄瓨鍌ㄦ墍闇�瀵硅薄
-		osAttributeDTO.setOid(VciBaseUtil.getPk().toUpperCase(Locale.ROOT));
+		//osAttributeDTO.setOid(VciBaseUtil.getPk().toUpperCase(Locale.ROOT));
 		AttributeDef attributeDef = this.osAttributeDTO2AttributeDef(osAttributeDTO);
 		return platformClientUtil.getAttributeService().addAttributeDef(attributeDef);
 	}
@@ -600,6 +608,7 @@
 				if(StringUtils.isNotBlank(osAttributeDTO.getLinkTypeName())){
 					//鍙傜収閾炬帴绫诲瀷
 					sb.append(LINKTYPENAME).append(" = ").append(osAttributeDTO.getLinkTypeName()).append(";");
+					sb.append(VERSION).append(" = ").append(osAttributeDTO.getVersion()).append(";");
 				}
 				sb.append(LENGTH).append(" = ").append(length > osAttributeDTO.getAttrLength()?length:osAttributeDTO.getAttrLength()).append(";");
 				if (StringUtils.isNotBlank(osAttributeDTO.getEnumId())) {
@@ -688,9 +697,9 @@
 			throw new PLException("500",new String[]{"灞炴�у悕鏃犳晥,鍘熷洜锛氬睘鎬у悕鏄暟鎹簱鍏抽敭瀛�!"});
 		}
 		//妫�鏌ュ睘鎬у悕鏄惁宸插瓨鍦ㄤ笌绯荤粺涓�
-		if(platformClientUtil.getAttributeService().checkRowIsExists(abName)){
-			throw new PLException("500",new String[]{"灞炴�у悕绉板湪绯荤粺涓凡瀛樺湪!"});
-		}
+		/*if(platformClientUtil.getAttributeService().checkRowIsExists(abName)){
+			throw new PLException("500",new String[]{"灞炴�у悕绉般��" + abName + "銆戝湪绯荤粺涓凡瀛樺湪!"});
+		}*/
 	}
 
 	/**
@@ -812,7 +821,7 @@
 			if(Func.isBlank(oid) || Func.isBlank(name) || Func.isEmpty(ts)){
 				throw new PLException("500",new String[]{"寰呭垹闄ょ殑灞炴�у垪琛ㄤ腑涓婚敭銆恛id銆戙�佽皟鏁存椂闂淬�恡s銆戙�佸睘鎬у悕銆恘ame銆戜笉鑳戒负绌猴紒"});
 			}
-			//鍒ゆ柇鏋氫妇鏄惁鏈夎寮曠敤
+			//鍒ゆ柇灞炴�ф槸鍚︽湁琚紩鐢�
 			List<Map<String, String>> usedAttrList = this.getUsedAttributeList(name);
 			if(Func.isNotEmpty(usedAttrList)){
 				throw new PLException("500",new String[]{"鍒犻櫎鐨勫睘鎬т腑锛屽睘鎬у悕绉颁负锛氥��" + name + "銆�,宸茶寮曠敤锛�"});
@@ -857,22 +866,18 @@
 	 * 瀵煎嚭閫変腑鐨勫睘鎬�
 	 * @param exportFileName 瀵煎嚭鐨勬枃浠跺悕
 	 * @param attrNames 闇�瑕佸鍑虹殑灞炴�у悕绉�
+	 * @param flag 鎺у埗瀵煎嚭鐨勫垪鍚嶆槸鍚﹀拰瀵煎叆妯℃澘涓�鑷�
 	 * @return
 	 */
 	@Override
-	public String exportAttributes(String exportFileName, String attrNames) throws PLException {
+	public String exportAttributes(String exportFileName, String attrNames,boolean flag/*鎺у埗瀵煎嚭鐨勫垪鍚嶆槸鍚﹀拰瀵煎叆妯℃澘涓�鑷�*/) throws PLException {
 		if(Func.isBlank(attrNames)){
 			throw new PLException("500",new String[]{"璇峰嬀閫夎瀵煎嚭鐨勫睘鎬�!"});
 		}
 		//鐣岄潰娌′紶鍚嶇О锛屼娇鐢ㄩ粯璁ゅ鍑哄悕绉�
 		exportFileName = Func.isBlank(exportFileName) ?  "灞炴�ф睜涓睘鎬у鍑篲" + Func.format(new Date(),"yyyy-MM-dd HHmmss.sss"):exportFileName;
 		//璁剧疆鍒楀悕
-		List<String> columns = new ArrayList<>(
-				Arrays.asList("灞炴�у悕", "鏍囩", "鎻忚堪",
-						"灞炴�х被鍨�", "鍏佽涓虹┖", "榛樿鍊�", "浣跨敤鐨勬灇涓捐嫳鏂囧悕绉�(鏋氫妇鍚�)",
-						"浣跨敤鐨勬灇涓句腑鏂囧悕绉�(鏍囩)", "鍙傜収鐨勪笟鍔$被鍨嬬紪鍙�", "鍙傜収鐨勪笟鍔$被鍨嬪悕绉�",
-						"鍙傜収鐨勯摼鎺ョ被鍨嬪悕绉�","鐗堟湰鐗堟","灞炴�ч暱搴�", "灏忔暟绮惧害浣嶆暟","灏忔暟鍒诲害浣嶆暟","鍙栧�艰寖鍥�","鍒涘缓鏃堕棿")
-		);
+		List<String> columns = this.getCloumns(flag);
 
 		//鍐檈xcel
 		String excelPath = LocalFileUtil.getDefaultTempFolder() + File.separator + exportFileName +  ".xls";
@@ -888,8 +893,8 @@
 			excelDataList.add(new WriteExcelData(0,index, columns.get(index)));
 		}
 		//鎸夌収灞炴�у悕鏌ヨ灞炴�э紝鐒跺悗澶勭悊灞炴�у鍑�
-		List<String> enumNameList = Func.toStrList(attrNames);
-		List<OsAttributeVO> osAttributeVOS = this.listAttrByIds(enumNameList);
+		List<String> attrameList = Func.toStrList(attrNames);
+		List<OsAttributeVO> osAttributeVOS = this.listAttrByIds(attrameList);
 		if(Func.isEmpty(osAttributeVOS)){
 			excelDataList.add(new WriteExcelData(1,1, "鏍规嵁灞炴�у悕绉版湭鏌ヨ鍒板睘鎬т俊鎭紝璇峰埛鏂板悗灏濊瘯閲嶆柊瀵煎嚭锛�"));
 		}else{
@@ -900,25 +905,54 @@
 				excelDataList.add(new WriteExcelData(i+1,0, osAttributeVO.getId()));
 				excelDataList.add(new WriteExcelData(i+1,1, osAttributeVO.getName()));
 				excelDataList.add(new WriteExcelData(i+1,2, osAttributeVO.getDescription()));
-				excelDataList.add(new WriteExcelData(i+1,3, osAttributeVO.getAttributeDataTypeText()+"("+osAttributeVO.getAttributeDataType()+")"));
+				if(flag){
+					excelDataList.add(new WriteExcelData(i+1,3, osAttributeVO.getAttributeDataType()));
+				}else{
+					excelDataList.add(new WriteExcelData(i+1,3, osAttributeVO.getAttributeDataType()+"("+osAttributeVO.getAttributeDataTypeText()+")"));
+				}
 				excelDataList.add(new WriteExcelData(i+1,4, osAttributeVO.isNullableFlag()));
 				excelDataList.add(new WriteExcelData(i+1,5, osAttributeVO.getDefaultValue()));
 				excelDataList.add(new WriteExcelData(i+1,6, osAttributeVO.getEnumId()));
-				excelDataList.add(new WriteExcelData(i+1,7, osAttributeVO.getEnumName()));
-				excelDataList.add(new WriteExcelData(i+1,8, osAttributeVO.getBtmTypeId()));
-				excelDataList.add(new WriteExcelData(i+1,9, osAttributeVO.getBtmTypeName()));
-				excelDataList.add(new WriteExcelData(i+1,10, osAttributeVO.getAttrLength()));
-				excelDataList.add(new WriteExcelData(i+1,11, osAttributeVO.getLinkTypeName()));
-				excelDataList.add(new WriteExcelData(i+1,12, osAttributeVO.getVersion()));
-				excelDataList.add(new WriteExcelData(i+1,13, osAttributeVO.getPrecisionLength()));
-				excelDataList.add(new WriteExcelData(i+1,14, osAttributeVO.getScaleLength()));
-				excelDataList.add(new WriteExcelData(i+1,15, osAttributeVO.getRange()));
-				excelDataList.add(new WriteExcelData(i+1,16, osAttributeVO.getCreateTime()));
+				//excelDataList.add(new WriteExcelData(i+1,7, osAttributeVO.getEnumName()));
+				excelDataList.add(new WriteExcelData(i+1,7, osAttributeVO.getBtmTypeId()));
+				//excelDataList.add(new WriteExcelData(i+1,9, osAttributeVO.getBtmTypeName()));
+				excelDataList.add(new WriteExcelData(i+1,8, osAttributeVO.getAttrLength()));
+				excelDataList.add(new WriteExcelData(i+1,9, osAttributeVO.getLinkTypeName()));
+				excelDataList.add(new WriteExcelData(i+1,10, osAttributeVO.getVersion()));
+				excelDataList.add(new WriteExcelData(i+1,11, osAttributeVO.getPrecisionLength()));
+				excelDataList.add(new WriteExcelData(i+1,12, osAttributeVO.getScaleLength()));
+				excelDataList.add(new WriteExcelData(i+1,13, osAttributeVO.getRange()));
+				if(!flag){
+					excelDataList.add(new WriteExcelData(i+1,14, Func.format(osAttributeVO.getCreateTime(),"yyyy骞碝M鏈坉d鏃� hh:mm:ss")));
+				}
 			}
 		}
 		WriteExcelOption excelOption = new WriteExcelOption(excelDataList);
 		ExcelUtil.writeDataToFile(excelPath, excelOption);
 		return excelPath;
+	}
+
+	/**
+	 * 鑾峰彇瀵煎嚭鎴栧鍏ユā鏉跨殑鍒楀悕
+	 * @param flag 鏄惁鑾峰彇瀵煎叆妯℃澘鍒楀悕
+	 * @return
+	 */
+	private List<String> getCloumns(boolean flag){
+		if(flag){
+			return new ArrayList<>(
+					Arrays.asList("灞炴�у悕", "鏍囩", "鎻忚堪",
+							"灞炴�х被鍨�(鍙傜収鏂板鐣岄潰鐨勫睘鎬х被鍨嬪VTString)", "鍏佽涓虹┖(鏄�/鍚�)", "榛樿鍊�", "浣跨敤鐨勬灇涓捐嫳鏂囧悕绉�"
+							, "鍙傜収鐨勪笟鍔$被鍨嬬紪鍙�","鍙傜収鐨勯摼鎺ョ被鍨嬬紪鍙�","鐗堟湰鐗堟","灞炴�ч暱搴�", "灏忔暟绮惧害浣嶆暟","灏忔暟鍒诲害浣嶆暟"
+							,"鍙栧�艰寖鍥�"
+					)
+			);
+		}
+		return new ArrayList<>(
+				Arrays.asList("灞炴�у悕", "鏍囩", "鎻忚堪",
+						"灞炴�х被鍨�", "鍏佽涓虹┖", "榛樿鍊�", "浣跨敤鐨勬灇涓捐嫳鏂囧悕绉�(鏋氫妇鍚�)",
+						"鍙傜収鐨勪笟鍔$被鍨嬬紪鍙�", "鍙傜収鐨勯摼鎺ョ被鍨嬬紪鍙�","鐗堟湰鐗堟","灞炴�ч暱搴�",
+						"灏忔暟绮惧害浣嶆暟","灏忔暟鍒诲害浣嶆暟","鍙栧�艰寖鍥�","鍒涘缓鏃堕棿")
+		);
 	}
 
 	/**
@@ -932,11 +966,7 @@
 		//鐣岄潰娌′紶鍚嶇О锛屼娇鐢ㄩ粯璁ゅ鍑哄悕绉�
 		exportFileName = Func.isBlank(exportFileName) ?  "灞炴�ф睜瀵煎叆妯℃澘_" + Func.format(new Date(),"yyyy-MM-dd HHmmss.sss"):exportFileName;
 		//璁剧疆鍒楀悕
-		List<String> columns = new ArrayList<>(
-				Arrays.asList("灞炴�у悕", "鏍囩", "鎻忚堪",
-						"灞炴�х被鍨�", "鍏佽涓虹┖(鏄�/鍚�)", "榛樿鍊�", "浣跨敤鐨勬灇涓捐嫳鏂囧悕绉�", "鍙傜収鐨勪笟鍔$被鍨嬬紪鍙�",
-						"鍙傜収鐨勯摼鎺ョ被鍨嬬紪鍙�","鐗堟湰鐗堟","灞炴�ч暱搴�", "灏忔暟绮惧害浣嶆暟","灏忔暟鍒诲害浣嶆暟","鍙栧�艰寖鍥�")
-		);
+		List<String> columns = this.getCloumns(true);
 		//璁剧疆蹇呭~鍒�
 		ColumnNameisRed.clear();
 		ColumnNameisRed.add(0);
@@ -971,10 +1001,12 @@
 	/**
 	 * 瀵煎叆灞炴��
 	 * @param file
+	 * @param isContinue 绯荤粺涓嚭鐜伴噸澶嶆槸鍚﹁烦杩囨姤閿欑户缁墽琛�
 	 * @return
+	 * @throws Exception
 	 */
 	@Override
-	public BaseResult importAttributes(File file) throws Exception{
+	public BaseResult importAttributes(File file, boolean isContinue) throws Exception{
 		VciBaseUtil.alertNotNull(file,"excel鏂囦欢");
 		if(!file.exists()){
 			throw new VciBaseException("瀵煎叆鐨別xcel鏂囦欢涓嶅瓨鍦�,{0}",new String[]{file.getPath()});
@@ -991,14 +1023,29 @@
 			List<OsAttributeDTO> dtoList = new ArrayList<>();
 			//褰撳墠excel涓槸鍚﹂噸澶嶇敤鐨勫垽閲峂ap:锛坘ey锛氬垽閲嶅睘鎬э紝value锛氳鍙凤級
 			Map<String, String> excelReapeat = new HashMap<>();
-			//鍒ゆ柇蹇呭~灞炴�ф槸鍚︿负绌猴紝鐢ㄦ埛鏄惁宸插瓨鍦紝浠ュ強閮ㄩ棬鏄惁濉敊绛夋牎楠岄�昏緫
-			poList.stream().forEach(osAttributePO -> {
+			for (int i = 0; i < poList.size(); i++) {
+				OsAttributePO osAttributePO = poList.get(i);
 				if(Func.isBlank(osAttributePO.getId())){//灞炴�у悕鍒ょ┖
-					throw new VciBaseException("绗��"+osAttributePO.getRowIndex()+"銆戣锛宔numnameerror");
+					throw new VciBaseException("绗��"+osAttributePO.getRowIndex()+"銆戣锛宎ttrnameerror");
 				}else if(Func.isBlank(osAttributePO.getAttributeDataType())){
 					throw new VciBaseException("绗��"+osAttributePO.getRowIndex()+"銆戣锛宼ypeerror");
 				}else if(excelReapeat.containsKey(osAttributePO.getId())){//灞炴�у悕琛ㄦ牸涓垽閲�
 					throw new VciBaseException("绗��"+excelReapeat.get(osAttributePO.getId())+"銆戣鍜岀銆�"+osAttributePO.getRowIndex()+"銆戣鏁版嵁锛屽睘鎬у悕閲嶅");
+				}else {
+					try {
+						if(platformClientUtil.getAttributeService().checkRowIsExists(osAttributePO.getId())){
+							throw new PLException("500",new String[]{"灞炴�у悕绉般��" + osAttributePO.getId() + "銆戝湪绯荤粺涓凡瀛樺湪!"});
+						}
+					} catch (PLException e) {
+						e.printStackTrace();
+						String errorMsg = "涓庣郴缁熶腑灞炴�у悕鏌ラ噸鏃跺嚭鐜伴敊璇�,鍘熷洜锛�" + VciBaseUtil.getExceptionMessage(e);
+						logger.error(errorMsg);
+						//鏄惁璺宠繃褰撴湡閲嶅鏁版嵁
+						if(isContinue){
+							continue;
+						}
+						throw new VciBaseException(errorMsg);
+					}
 				}
 				//灞炴�у悕鏍¢獙
 				try {
@@ -1010,6 +1057,22 @@
 				//灞炴�у悕excel涓垽閲嶅鐞�
 				excelReapeat.put(osAttributePO.getId(),osAttributePO.getRowIndex());
 				OsAttributeDTO osAttributeDTO = new OsAttributeDTO();
+				//鏌ヨ灞炴�ф槸鍚﹀瓨鍦紝濉啓浜嗘灇涓句絾娌″~鍐欏彇鍊艰寖鍥达紝杩欐椂鍊欑洿鎺ヤ娇鐢ㄦ灇涓鹃」鍊间綔涓洪粯璁ょ殑range
+				if(Func.isNotBlank(osAttributePO.getEnumId()) && Func.isBlank(osAttributePO.getRange())){
+					try {
+						OsEnumVO enumVO = enumService.getEnumTypeById(osAttributePO.getEnumId());
+						if(Func.isEmpty(enumVO)){
+							throw new VciBaseException("绗��" + osAttributePO.getRowIndex() + "銆戣鏁版嵁,閫氳繃鏋氫妇鍚嶇О銆�" + osAttributePO.getEnumId()
+									+ "銆戞湭鑾峰彇鍒版灇涓句俊鎭�!");
+						}
+						String itemValues = enumVO.getItemMaps().values().stream().collect(Collectors.joining(";"));
+						osAttributeDTO.setRange(itemValues);
+					} catch (PLException e) {
+						e.printStackTrace();
+						throw new VciBaseException("鏋氫妇鏌ヨ澶辫触锛屽師鍥狅細"+e.getMessage());
+					}
+					osAttributeDTO.setBtmTypeId(osAttributePO.getEnumId());
+				}
 				osAttributeDTO.setOid(VciBaseUtil.getPk().toUpperCase(Locale.ROOT));
 				osAttributeDTO.setId(osAttributePO.getId());
 				osAttributeDTO.setName(osAttributePO.getName());
@@ -1032,10 +1095,10 @@
 					checkDefValue(osAttributeDTO);
 				} catch (PLException e) {
 					e.printStackTrace();
-					throw new VciBaseException(e.getMessage());
+					throw new VciBaseException(VciBaseUtil.getExceptionMessage(e));
 				}
 				dtoList.add(osAttributeDTO);
-			});
+			}
 			//鎵ц淇濆瓨鎿嶄綔
 			dtoList.stream().forEach(dto->{
 				try {
@@ -1050,12 +1113,12 @@
 			});
 		}catch (Exception e){
 			if(logger.isErrorEnabled()){
-				logger.error("璇诲彇excel鍐呭鏃舵垨淇濆瓨鐢ㄦ埛淇℃伅鏃跺嚭鐜颁簡閿欒锛屽叿浣撳師鍥狅細",VciBaseUtil.getExceptionMessage(e));
+				logger.error("璇诲彇excel鍐呭鏃舵垨淇濆瓨灞炴�ф椂鍑虹幇浜嗛敊璇紝鍏蜂綋鍘熷洜锛�",VciBaseUtil.getExceptionMessage(e));
 			}
 			e.printStackTrace();
 			return BaseResult.fail(VciBaseUtil.getExceptionMessage(e),new String[]{},e);
 		}
-		return BaseResult.success("鏋氫妇瀵煎叆鎴愬姛锛�");
+		return BaseResult.success("灞炴�у鍏ユ垚鍔燂紒");
 	}
 
 	/**

--
Gitblit v1.9.3