From b48356e1b39f8e812f85d1627c0fc18e1f4d58ba Mon Sep 17 00:00:00 2001 From: lihang <lihang@vci-tech.com> Date: 星期四, 15 六月 2023 16:42:41 +0800 Subject: [PATCH] 对象建模菜单相关的bug修正 --- Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/AttributeServiceImpl.java | 96 ++++++++++++++++++++++++++++++++---------------- 1 files changed, 64 insertions(+), 32 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..0ab7e08 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 @@ -8,18 +8,20 @@ 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.mapper.AttributeMapper; 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.web.constant.OmdRegExpConstant; import com.vci.ubcs.starter.web.enumpck.VciFieldTypeEnum; import com.vci.ubcs.starter.web.util.VciBaseUtil; import org.springblade.core.cache.utils.CacheUtil; import org.springblade.core.log.exception.ServiceException; -import org.springblade.core.tool.constant.BladeConstant; -import org.springblade.core.tool.utils.BeanUtil; +import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.Func; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; @@ -29,6 +31,7 @@ import java.util.Collection; import java.util.List; import java.util.Set; +import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -40,6 +43,8 @@ */ @Service public class AttributeServiceImpl extends ServiceImpl<AttributeMapper, Attribute> implements IAttributeService { + + private final String REGEXP = "^[A-Za-z]+$"; @Override public boolean deleteLogic(@NotEmpty List<Long> ids) { @@ -71,44 +76,55 @@ */ @Override public boolean submit(AttributeDTO dto) { - LambdaQueryWrapper<Attribute> wrapper = Wrappers.<Attribute>query().lambda().eq(Attribute::getKey, dto.getKey()); - Long count = baseMapper.selectCount((Func.isEmpty(dto.getId())) ? wrapper : wrapper.notIn(Attribute::getId, dto.getId())); - if (count > 0L) { - throw new ServiceException("灞炴�у悕宸插瓨鍦�!"); + VciBaseUtil.alertNotNull(dto.getId(),"灞炴�х紪鍙�",dto.getName(),"灞炴�у悕绉�",dto.getTypeKey(),"灞炴�х被鍨�",dto.getMaxLength(),"灞炴�ч暱搴�"); + if (!Pattern.compile(REGEXP).matcher(dto.getId()).matches()){ + throw new VciBaseException("灞炴�х紪鍙穥0}鍙兘鏄嫳鏂�",new Object[]{dto.getId()}); } - dto.setIsDeleted(BladeConstant.DB_NOT_DELETED); - Attribute omdAttribute = BeanUtil.copy(dto, Attribute.class); + LambdaQueryWrapper<Attribute> wrapper = Wrappers.<Attribute>query().lambda().eq(Attribute::getId, dto.getId()); + Long count = baseMapper.selectCount((Func.isEmpty(dto.getOid())) ? wrapper : wrapper.notIn(Attribute::getOid, dto.getOid())); + if (count > 0L) { + throw new ServiceException("灞炴�х紪鍙峰凡瀛樺湪!"); + } + Attribute attribute = AttributeWrapper.build().copyBeforeSave(dto); CacheUtil.clear(OmdCacheConstant.ATTR_CACHE); - return saveOrUpdate(omdAttribute); + return saveOrUpdate(attribute); } /** * 鍒犻櫎 * - * @param ids 涓婚敭闆嗗悎 + * @param oids 涓婚敭闆嗗悎 * @return 鎵ц缁撴灉 */ @Override - public boolean removeAttrs(String ids) { - List<Long> idList = Func.toLongList(ids); - return !deleteLogic(idList) && removeByIds(idList); + public boolean removeAttrs(String oids) { + List<String> oidList = Func.toStrList(",", oids); + List<Attribute> list = list(Wrappers.<Attribute>query().lambda().in(Attribute::getOid, oidList)); + if (!CollectionUtils.isEmpty(list)){ + baseMapper.delete(Wrappers.<Attribute>query().lambda().in(Attribute::getOid,list.stream().map(Attribute::getOid).collect(Collectors.toList()))); + } + return true; } /** * 鏌ョ湅搴旂敤鑼冨洿 * - * @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 null; + } + return BtmTypeWrapper.build().listEntityVO(btmTypes); } /** * 妫�鏌ュ睘鎬ф槸鍚﹀瓨鍦� * - * @param keyCollections 鑻辨枃鍚嶇О闆嗗悎 + * @param keyCollections 缂栧彿闆嗗悎 * @return true琛ㄧず閮藉瓨鍦紝false琛ㄧず涓嶅瓨鍦紝涓嶅瓨鍦ㄧ殑鏃跺�欎細鎶涘嚭寮傚父 * @throws VciBaseException 涓嶅瓨鍦ㄧ殑鏃跺�欎細鎶涘嚭寮傚父 */ @@ -118,9 +134,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 +145,9 @@ } /** - * 鏍规嵁鑻辨枃鍚嶇О闆嗗悎鎵归噺鑾峰彇灞炴�у璞� + * 鏍规嵁缂栧彿闆嗗悎鎵归噺鑾峰彇灞炴�у璞� * - * @param attributeIdCollection 鑻辨枃鍚嶇О闆嗗悎 + * @param attributeIdCollection 缂栧彿闆嗗悎 * @return 灞炴�у璞″垪琛紝濡傛灉鏈変笉瀛樺湪鐨勪笉浼氳繑鍥烇紝鍏ㄩ儴涓嶅瓨鍦ㄧ殑鍒欒繑鍥炵┖鍒楄〃 * @throws VciBaseException 鍙傛暟涓虹┖鎴栬�呮煡璇㈠嚭閿欐椂浼氭姏鍑洪敊璇� */ @@ -147,8 +163,8 @@ } /** - * 鏍规嵁鑻辨枃鍚嶇О闆嗗悎鑾峰彇灞炴�ф暟鎹璞� - * @param attributeIdCollection 灞炴�х殑鑻辨枃鍚嶇О闆嗗悎 + * 鏍规嵁缂栧彿闆嗗悎鑾峰彇灞炴�ф暟鎹璞� + * @param attributeIdCollection 灞炴�х殑缂栧彿闆嗗悎 * @return 灞炴�ф暟鎹璞″垪琛紝濡傛灉鏈変笉瀛樺湪鐨勪笉浼氳繑鍥烇紝鍏ㄩ儴涓嶅瓨鍦ㄧ殑鍒欒繑鍥炵┖鍒楄〃 * @throws VciBaseException mybatis鏌ヨ鍑洪敊鐨勬椂鍊欎細鎶涘嚭寮傚父 */ @@ -159,7 +175,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 +189,7 @@ /** * 鍒ゆ柇灞炴�х殑鍐呭鏄惁绗﹀悎瑕佹眰 * - * @param id 灞炴�х殑涓婚敭 + * @param id 灞炴�х殑缂栧彿 * @param attrDataType 灞炴�х殑绫诲瀷 * @param attributeLength 灞炴�х殑闀垮害 * @param defaultValue 榛樿鍊� @@ -184,26 +200,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 +234,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){ @@ -226,4 +242,20 @@ } return pass; } + + /** + * 鍗曚釜鍒犻櫎 + * + * @param oid 涓婚敭 + * @return 鎵ц缁撴灉 + */ + @Override + public R remove(String oid) { + List<BtmTypeVO> vos = applyRange(oid); + if (CollectionUtils.isEmpty(vos)){ + return R.status(removeAttrs(oid)); + }else { + return R.fail("璇ュ睘鎬у凡琚娇鐢紝涓嶅厑璁稿垹闄�"); + } + } } -- Gitblit v1.9.3