| | |
| | | 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; |
| | |
| | | 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; |
| | | |
| | | |
| | |
| | | */ |
| | | @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) { |
| | |
| | | */ |
| | | @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); |
| | |
| | | /** |
| | | * 查看应用范围 |
| | | * |
| | | * @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 不存在的时候会抛出异常 |
| | | */ |
| | |
| | | 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}); |
| | | } |
| | | }); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 根据英文名称集合批量获取属性对象 |
| | | * 根据编号集合批量获取属性对象 |
| | | * |
| | | * @param attributeIdCollection 英文名称集合 |
| | | * @param attributeIdCollection 编号集合 |
| | | * @return 属性对象列表,如果有不存在的不会返回,全部不存在的则返回空列表 |
| | | * @throws VciBaseException 参数为空或者查询出错时会抛出错误 |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * 根据英文名称集合获取属性数据对象 |
| | | * @param attributeIdCollection 属性的英文名称集合 |
| | | * 根据编号集合获取属性数据对象 |
| | | * @param attributeIdCollection 属性的编号集合 |
| | | * @return 属性数据对象列表,如果有不存在的不会返回,全部不存在的则返回空列表 |
| | | * @throws VciBaseException mybatis查询出错的时候会抛出异常 |
| | | */ |
| | |
| | | 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); |
| | | } |
| | |
| | | /** |
| | | * 判断属性的内容是否符合要求 |
| | | * |
| | | * @param id 属性的主键 |
| | | * @param id 属性的编号 |
| | | * @param attrDataType 属性的类型 |
| | | * @param attributeLength 属性的长度 |
| | | * @param defaultValue 默认值 |
| | |
| | | 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; |
| | |
| | | */ |
| | | @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){ |