From 1a07db181c732729abc1d6ec71ae206ecffca86d Mon Sep 17 00:00:00 2001
From: lihang <lihang@vci-tech.com>
Date: 星期三, 24 五月 2023 18:33:45 +0800
Subject: [PATCH] 迁移链接类型后台接口,修正属性字段,增加元数据查找应用范围功能

---
 Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/AttributeServiceImpl.java |   68 +++++++++++++++++++++++----------
 1 files changed, 47 insertions(+), 21 deletions(-)

diff --git a/Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/AttributeServiceImpl.java b/Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/AttributeServiceImpl.java
index 6e02f0d..03f8eaf 100644
--- a/Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/AttributeServiceImpl.java
+++ b/Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/AttributeServiceImpl.java
@@ -4,15 +4,22 @@
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
 import com.vci.ubcs.omd.constant.OmdCacheConstant;
 import com.vci.ubcs.omd.dto.AttributeDTO;
 import com.vci.ubcs.omd.dto.BtmTypeLinkAttributesDTO;
 import com.vci.ubcs.omd.entity.Attribute;
+import com.vci.ubcs.omd.entity.BtmType;
+import com.vci.ubcs.omd.entity.BtmTypeAttribute;
 import com.vci.ubcs.omd.mapper.AttributeMapper;
+import com.vci.ubcs.omd.mapper.BtmTypeMapper;
 import com.vci.ubcs.omd.service.IAttributeService;
 import com.vci.ubcs.omd.vo.AttributeVO;
+import com.vci.ubcs.omd.vo.BtmTypeVO;
 import com.vci.ubcs.omd.wrapper.AttributeWrapper;
+import com.vci.ubcs.omd.wrapper.BtmTypeWrapper;
 import com.vci.ubcs.starter.exception.VciBaseException;
+import com.vci.ubcs.starter.util.Map2MPJLambdaUtil;
 import com.vci.ubcs.starter.web.constant.OmdRegExpConstant;
 import com.vci.ubcs.starter.web.enumpck.VciFieldTypeEnum;
 import com.vci.ubcs.starter.web.util.VciBaseUtil;
@@ -21,14 +28,17 @@
 import org.springblade.core.tool.constant.BladeConstant;
 import org.springblade.core.tool.utils.BeanUtil;
 import org.springblade.core.tool.utils.Func;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
+import javax.annotation.Resource;
 import javax.validation.constraints.NotEmpty;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.Set;
+import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
 
@@ -40,6 +50,11 @@
  */
 @Service
 public class AttributeServiceImpl extends ServiceImpl<AttributeMapper, Attribute>  implements IAttributeService {
+
+	private final String REGEXP = "^[A-Za-z]+$";
+
+	@Resource
+	private BtmTypeMapper btmTypeMapper;
 
 	@Override
 	public boolean deleteLogic(@NotEmpty List<Long> ids) {
@@ -71,12 +86,14 @@
 	 */
 	@Override
 	public boolean submit(AttributeDTO dto) {
-		LambdaQueryWrapper<Attribute> wrapper = Wrappers.<Attribute>query().lambda().eq(Attribute::getKey, dto.getKey());
+		if (Pattern.compile(REGEXP).matcher(dto.getId()).matches()){
+			throw new VciBaseException("灞炴�у悕绉皗0}鍙兘鏄嫳鏂�",new Object[]{dto.getId()});
+		}
+		LambdaQueryWrapper<Attribute> wrapper = Wrappers.<Attribute>query().lambda().eq(Attribute::getId, dto.getId());
 		Long count = baseMapper.selectCount((Func.isEmpty(dto.getId())) ? wrapper : wrapper.notIn(Attribute::getId, dto.getId()));
 		if (count > 0L) {
 			throw new ServiceException("灞炴�у悕宸插瓨鍦�!");
 		}
-		dto.setIsDeleted(BladeConstant.DB_NOT_DELETED);
 		Attribute omdAttribute = BeanUtil.copy(dto, Attribute.class);
 		CacheUtil.clear(OmdCacheConstant.ATTR_CACHE);
 		return saveOrUpdate(omdAttribute);
@@ -97,18 +114,27 @@
 	/**
 	 * 鏌ョ湅搴旂敤鑼冨洿
 	 *
-	 * @param id 涓婚敭
+	 * @param oid 涓婚敭
 	 * @return 鏌ヨ宸插簲鐢ㄧ殑涓氬姟绫诲瀷鍚嶇О
 	 */
 	@Override
-	public List<String> applyRange(Long id) {
-		return new ArrayList<>();
+	public List<BtmTypeVO> applyRange(String oid) {
+		List<BtmType> btmTypes = baseMapper.selectApplyRange(oid);
+		if (!CollectionUtils.isEmpty(btmTypes)){
+			return btmTypes.stream().map(btm -> {
+				BtmTypeVO vo = new BtmTypeVO();
+				vo.setId(btm.getId());
+				vo.setName(btm.getName());
+				return vo;
+			}).collect(Collectors.toList());
+		}
+		return null;
 	}
 
 	/**
 	 * 妫�鏌ュ睘鎬ф槸鍚﹀瓨鍦�
 	 *
-	 * @param keyCollections 鑻辨枃鍚嶇О闆嗗悎
+	 * @param keyCollections 缂栧彿闆嗗悎
 	 * @return true琛ㄧず閮藉瓨鍦紝false琛ㄧず涓嶅瓨鍦紝涓嶅瓨鍦ㄧ殑鏃跺�欎細鎶涘嚭寮傚父
 	 * @throws VciBaseException 涓嶅瓨鍦ㄧ殑鏃跺�欎細鎶涘嚭寮傚父
 	 */
@@ -118,9 +144,9 @@
 		if (CollectionUtils.isEmpty(existAttributeVOList)) {
 			throw new VciBaseException("浣跨敤鐨勫睘鎬ч兘鍦ㄧ郴缁熶腑涓嶅瓨鍦紝璇峰厛鏌ヨ瘉");
 		} else {
-			Set<String> existAttributeIdSet = (existAttributeVOList.stream().collect(Collectors.toMap(s -> s.getKey().toLowerCase().trim(), t -> t))).keySet();
+			Set<String> existAttributeOidSet = (existAttributeVOList.stream().collect(Collectors.toMap(s -> s.getId().toLowerCase().trim(), t -> t))).keySet();
 			keyCollections.stream().forEach(s -> {
-				if (!existAttributeIdSet.contains(s)) {
+				if (!existAttributeOidSet.contains(s)) {
 					throw new VciBaseException("浣跨敤鐨勫睘鎬0}鍦ㄧ郴缁熶腑涓嶅瓨鍦紝璇峰厛鏌ヨ瘉", new Object[]{s});
 				}
 			});
@@ -129,9 +155,9 @@
 	}
 
 	/**
-	 * 鏍规嵁鑻辨枃鍚嶇О闆嗗悎鎵归噺鑾峰彇灞炴�у璞�
+	 * 鏍规嵁缂栧彿闆嗗悎鎵归噺鑾峰彇灞炴�у璞�
 	 *
-	 * @param attributeIdCollection 鑻辨枃鍚嶇О闆嗗悎
+	 * @param attributeIdCollection 缂栧彿闆嗗悎
 	 * @return 灞炴�у璞″垪琛紝濡傛灉鏈変笉瀛樺湪鐨勪笉浼氳繑鍥烇紝鍏ㄩ儴涓嶅瓨鍦ㄧ殑鍒欒繑鍥炵┖鍒楄〃
 	 * @throws VciBaseException 鍙傛暟涓虹┖鎴栬�呮煡璇㈠嚭閿欐椂浼氭姏鍑洪敊璇�
 	 */
@@ -147,8 +173,8 @@
 	}
 
 	/**
-	 * 鏍规嵁鑻辨枃鍚嶇О闆嗗悎鑾峰彇灞炴�ф暟鎹璞�
-	 * @param attributeIdCollection 灞炴�х殑鑻辨枃鍚嶇О闆嗗悎
+	 * 鏍规嵁缂栧彿闆嗗悎鑾峰彇灞炴�ф暟鎹璞�
+	 * @param attributeIdCollection 灞炴�х殑缂栧彿闆嗗悎
 	 * @return 灞炴�ф暟鎹璞″垪琛紝濡傛灉鏈変笉瀛樺湪鐨勪笉浼氳繑鍥烇紝鍏ㄩ儴涓嶅瓨鍦ㄧ殑鍒欒繑鍥炵┖鍒楄〃
 	 * @throws VciBaseException mybatis鏌ヨ鍑洪敊鐨勬椂鍊欎細鎶涘嚭寮傚父
 	 */
@@ -159,7 +185,7 @@
 			Collection<Collection<String>> idCollections = VciBaseUtil.switchCollectionForOracleIn(distAttributeIdCollection);
 			if(!CollectionUtils.isEmpty(idCollections)) {
 				idCollections.stream().forEach(s -> {
-					List<Attribute> attributeDOS = baseMapper.selectList(Wrappers.<Attribute>query().lambda().in(Attribute::getKey, s));
+					List<Attribute> attributeDOS = baseMapper.selectList(Wrappers.<Attribute>query().lambda().in(Attribute::getId, s));
 					if(!CollectionUtils.isEmpty(attributeDOS)){
 						attributeDOList.addAll(attributeDOS);
 					}
@@ -173,7 +199,7 @@
 	/**
 	 * 鍒ゆ柇灞炴�х殑鍐呭鏄惁绗﹀悎瑕佹眰
 	 *
-	 * @param id              灞炴�х殑涓婚敭
+	 * @param id              灞炴�х殑缂栧彿
 	 * @param attrDataType    灞炴�х殑绫诲瀷
 	 * @param attributeLength 灞炴�х殑闀垮害
 	 * @param defaultValue    榛樿鍊�
@@ -184,26 +210,26 @@
 	public boolean checkAttributePass(String id, String attrDataType, Integer attributeLength, String defaultValue) throws VciBaseException {
 		String attributeDataTypeText = VciFieldTypeEnum.getTextByValue(attrDataType);
 		if(StringUtils.isBlank(attributeDataTypeText)){
-			throw new VciBaseException("鑻辨枃鍚嶇О涓簕0}鐨勫睘鎬х殑绫诲瀷涓嶇鍚堣姹�",new Object[]{id});
+			throw new VciBaseException("缂栧彿涓簕0}鐨勫睘鎬х殑绫诲瀷涓嶇鍚堣姹�",new Object[]{id});
 		}
 		//蹇呴』瑕佽緭鍏ラ暱搴�
-		if( VciBaseUtil.inArray(new String[] {VciFieldTypeEnum.VTString.name()},attrDataType)
+		if(VciBaseUtil.inArray(new String[] {VciFieldTypeEnum.VTString.name()},attrDataType)
 			&& (attributeLength == null ||attributeLength < 1)){
-			throw new VciBaseException("鑻辨枃鍚嶇О涓簕0}鐨勫睘鎬х殑涓簕1}绫诲瀷鏃讹紝蹇呴』瑕佽緭鍏ラ暱搴︾殑鍊�",new Object[]{id,attributeDataTypeText});
+			throw new VciBaseException("缂栧彿涓簕0}鐨勫睘鎬х殑涓簕1}绫诲瀷鏃讹紝蹇呴』瑕佽緭鍏ラ暱搴︾殑鍊�",new Object[]{id,attributeDataTypeText});
 		}
 		//鍒ゆ柇榛樿鍊�
 		if(StringUtils.isNotBlank(defaultValue)){
 			if(VciFieldTypeEnum.VTDouble.name().equalsIgnoreCase(attrDataType)
 				&& !defaultValue.matches(OmdRegExpConstant.DOUBLE)){
-				throw new VciBaseException("鑻辨枃鍚嶇О涓簕0}鐨勫睘鎬х殑榛樿鍊间笉鏄弻绮惧害绫诲瀷",new Object[]{id});
+				throw new VciBaseException("缂栧彿涓簕0}鐨勫睘鎬х殑榛樿鍊间笉鏄弻绮惧害绫诲瀷",new Object[]{id});
 			}
 			if(VciFieldTypeEnum.VTInteger.name().equalsIgnoreCase(defaultValue)
 				&& !defaultValue.matches(OmdRegExpConstant.INT)){
-				throw new VciBaseException("鑻辨枃鍚嶇О涓簕0}鐨勫睘鎬х殑榛樿鍊间笉鏄暣鏁板瀷",new Object[]{id});
+				throw new VciBaseException("缂栧彿涓簕0}鐨勫睘鎬х殑榛樿鍊间笉鏄暣鏁板瀷",new Object[]{id});
 			}
 			if(VciFieldTypeEnum.VTLong.name().equalsIgnoreCase(defaultValue)
 				&& !defaultValue.matches(OmdRegExpConstant.LONG)){
-				throw new VciBaseException("鑻辨枃鍚嶇О涓簕0}鐨勫睘鎬х殑榛樿鍊间笉鏄暱鏁村舰",new Object[]{id});
+				throw new VciBaseException("缂栧彿涓簕0}鐨勫睘鎬х殑榛樿鍊间笉鏄暱鏁村舰",new Object[]{id});
 			}
 		}
 		return true;
@@ -218,7 +244,7 @@
 	 */
 	@Override
 	public boolean checkAttribute(BtmTypeLinkAttributesDTO attributesDTO) throws VciBaseException {
-		VciBaseUtil.alertNotNull(attributesDTO.getId(), "灞炴�х殑鑻辨枃鍚嶇О", attributesDTO.getName(), "灞炴�х殑涓枃鍚嶇О",
+		VciBaseUtil.alertNotNull(attributesDTO.getId(), "灞炴�х殑缂栧彿", attributesDTO.getName(), "灞炴�х殑鍚嶇О",
 			attributesDTO.getAttrDataType(), "灞炴�х殑鏁版嵁绫诲瀷");
 		boolean pass = checkAttributePass(attributesDTO.getId(), attributesDTO.getAttrDataType(), attributesDTO.getAttributeLength(), attributesDTO.getDefaultValue());
 		if (!pass){

--
Gitblit v1.9.3