| | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.vci.ubcs.omd.constant.OmdCacheConstant; |
| | | import com.vci.ubcs.omd.dto.OmdAttributeDTO; |
| | | import com.vci.ubcs.omd.dto.OmdBtmTypeLinkAttributesDTO; |
| | | import com.vci.ubcs.omd.entity.OmdAttribute; |
| | | import com.vci.ubcs.omd.mapper.OmdAttributeMapper; |
| | | import com.vci.ubcs.omd.service.IOmdAttributeService; |
| | | import com.vci.ubcs.omd.vo.OmdAttributeVO; |
| | | import com.vci.ubcs.omd.wrapper.OmdAttributeWrapper; |
| | | import com.vci.ubcs.starter.exception.VciBaseException; |
| | | 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.utils.Func; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import javax.validation.constraints.NotEmpty; |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | |
| | | /** |
| | |
| | | public List<String> applyRange(Long id) { |
| | | return new ArrayList<>(); |
| | | } |
| | | |
| | | /** |
| | | * 检查属性是否存在 |
| | | * |
| | | * @param keyCollections 英文名称集合 |
| | | * @return true表示都存在,false表示不存在,不存在的时候会抛出异常 |
| | | * @throws VciBaseException 不存在的时候会抛出异常 |
| | | */ |
| | | @Override |
| | | public boolean checkAttributeExists(Collection<String> keyCollections) throws VciBaseException { |
| | | List<OmdAttributeVO> existAttributeVOList = listAttributeByKeyCollection(keyCollections); |
| | | if (CollectionUtils.isEmpty(existAttributeVOList)) { |
| | | throw new VciBaseException("使用的属性都在系统中不存在,请先查证"); |
| | | } else { |
| | | Set<String> existAttributeIdSet = (existAttributeVOList.stream().collect(Collectors.toMap(s -> s.getKey().toLowerCase().trim(), t -> t))).keySet(); |
| | | keyCollections.stream().forEach(s -> { |
| | | if (!existAttributeIdSet.contains(s)) { |
| | | throw new VciBaseException("使用的属性{0}在系统中不存在,请先查证", new Object[]{s}); |
| | | } |
| | | }); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据英文名称集合批量获取属性对象 |
| | | * |
| | | * @param attributeIdCollection 英文名称集合 |
| | | * @return 属性对象列表,如果有不存在的不会返回,全部不存在的则返回空列表 |
| | | * @throws VciBaseException 参数为空或者查询出错时会抛出错误 |
| | | */ |
| | | @Override |
| | | public List<OmdAttributeVO> listAttributeByKeyCollection(Collection<String> attributeIdCollection) throws VciBaseException { |
| | | if(!CollectionUtils.isEmpty(attributeIdCollection)){ |
| | | List<OmdAttribute> attributeDOList = listAttributeByKeyCollectionDO(attributeIdCollection); |
| | | if(!CollectionUtils.isEmpty(attributeDOList)) { |
| | | return OmdAttributeWrapper.build().listEntityVO(attributeDOList); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 根据英文名称集合获取属性数据对象 |
| | | * @param attributeIdCollection 属性的英文名称集合 |
| | | * @return 属性数据对象列表,如果有不存在的不会返回,全部不存在的则返回空列表 |
| | | * @throws VciBaseException mybatis查询出错的时候会抛出异常 |
| | | */ |
| | | private List<OmdAttribute> listAttributeByKeyCollectionDO(Collection<String> attributeIdCollection) throws VciBaseException { |
| | | if(!CollectionUtils.isEmpty(attributeIdCollection)){ |
| | | List<OmdAttribute> attributeDOList = new ArrayList<>(); |
| | | Collection<String> distAttributeIdCollection = attributeIdCollection.stream().distinct().collect(Collectors.toList()); |
| | | Collection<Collection<String>> idCollections = VciBaseUtil.switchCollectionForOracleIn(distAttributeIdCollection); |
| | | if(!CollectionUtils.isEmpty(idCollections)) { |
| | | idCollections.stream().forEach(s -> { |
| | | List<OmdAttribute> attributeDOS = baseMapper.selectList(Wrappers.<OmdAttribute>query().lambda().in(OmdAttribute::getKey, s)); |
| | | if(!CollectionUtils.isEmpty(attributeDOS)){ |
| | | attributeDOList.addAll(attributeDOS); |
| | | } |
| | | }); |
| | | } |
| | | return attributeDOList; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 判断属性的内容是否符合要求 |
| | | * |
| | | * @param id 属性的主键 |
| | | * @param attrDataType 属性的类型 |
| | | * @param attributeLength 属性的长度 |
| | | * @param defaultValue 默认值 |
| | | * @return true表示符合要求,不符合要求会抛出异常 |
| | | * @throws VciBaseException 不符合要求会抛出异常 |
| | | */ |
| | | @Override |
| | | public boolean checkAttributePass(String id, String attrDataType, Integer attributeLength, String defaultValue) throws VciBaseException { |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 校验属性是否符合要求 |
| | | * |
| | | * @param attributesDTO 属性数据传输对象 |
| | | * @return true 符合 false 不符合 |
| | | * @throws VciBaseException 不符合时抛出异常 |
| | | */ |
| | | @Override |
| | | public boolean checkAttribute(OmdBtmTypeLinkAttributesDTO attributesDTO) throws VciBaseException { |
| | | VciBaseUtil.alertNotNull(attributesDTO.getId(), "属性的英文名称", attributesDTO.getName(), "属性的中文名称", |
| | | attributesDTO.getAttrDataType(), "属性的数据类型"); |
| | | boolean pass = checkAttributePass(attributesDTO.getId(), attributesDTO.getAttrDataType(), attributesDTO.getAttributeLength(), attributesDTO.getDefaultValue()); |
| | | if (!pass){ |
| | | throw new VciBaseException("属性不符合要求"); |
| | | } |
| | | return pass; |
| | | } |
| | | } |