| | |
| | | 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.*; |
| | | import java.util.regex.Pattern; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | @Override |
| | | public boolean submit(AttributeDTO dto) { |
| | | 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()}); |
| | | } |
| | | 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("属性编号已存在!"); |
| | | String msg = checkAttributeId(dto.getId(),dto.getOid()); |
| | | if (StringUtils.isNotBlank(msg)){ |
| | | throw new VciBaseException(msg); |
| | | } |
| | | Attribute attribute = AttributeWrapper.build().copyBeforeSave(dto); |
| | | CacheUtil.clear(OmdCacheConstant.ATTR_CACHE); |
| | | return saveOrUpdate(attribute); |
| | | } |
| | | |
| | | /** |
| | | * 元数据的ID校验 |
| | | * @param id 编号值 |
| | | * @param oid 数据主键 |
| | | * @return 校验结果 |
| | | */ |
| | | private String checkAttributeId(String id, String oid) { |
| | | if (!Pattern.compile(REGEXP).matcher(id).matches()){ |
| | | return "属性编号"+id+"只能是英文"; |
| | | } |
| | | Long count = baseMapper.checkIdExist(id.toLowerCase(Locale.ROOT),oid); |
| | | if (count > 0L) { |
| | | return "属性编号"+id+"(不区分大小写)已存在!"; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | |
| | | if (CollectionUtils.isEmpty(existAttributeVOList)) { |
| | | throw new VciBaseException("使用的属性都在系统中不存在,请先查证"); |
| | | } else { |
| | | Set<String> existAttributeOidSet = (existAttributeVOList.stream().collect(Collectors.toMap(s -> s.getId().toLowerCase().trim(), t -> t))).keySet(); |
| | | Set<String> existAttributeOidSet = (existAttributeVOList.stream().collect(Collectors.toMap(s -> s.getId().trim(), t -> t))).keySet(); |
| | | keyCollections.stream().forEach(s -> { |
| | | if (!existAttributeOidSet.contains(s)) { |
| | | throw new VciBaseException("使用的属性{0}在系统中不存在,请先查证", new Object[]{s}); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 根据编号集合获取属性数据对象 |
| | | * 根据编号集合获取属性数据对象,其中默认的属性应当剔除 |
| | | * @param attributeIdCollection 属性的编号集合 |
| | | * @return 属性数据对象列表,如果有不存在的不会返回,全部不存在的则返回空列表 |
| | | * @throws VciBaseException mybatis查询出错的时候会抛出异常 |