¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.vci.ubcs.omd.service.impl; |
| | | |
| | | import com.alibaba.cloud.commons.lang.StringUtils; |
| | | 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.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.mapper.AttributeMapper; |
| | | import com.vci.ubcs.omd.service.IAttributeService; |
| | | import com.vci.ubcs.omd.vo.AttributeVO; |
| | | import com.vci.ubcs.omd.wrapper.AttributeWrapper; |
| | | 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.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; |
| | | |
| | | |
| | | /** |
| | | * Description: å
æ°æ®(屿§)çæå¡ |
| | | * |
| | | * @author LiHang |
| | | * @date 2023/4/3 |
| | | */ |
| | | @Service |
| | | public class AttributeServiceImpl extends ServiceImpl<AttributeMapper, Attribute> implements IAttributeService { |
| | | |
| | | @Override |
| | | public boolean deleteLogic(@NotEmpty List<Long> ids) { |
| | | return false; |
| | | } |
| | | |
| | | @Override |
| | | public boolean changeStatus(@NotEmpty List<Long> ids, Integer status) { |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * è·åå
æ°æ®è¯¦æ
|
| | | * |
| | | * @param id ä¸»é® |
| | | * @return å
æ°æ®æ¾ç¤ºå¯¹è±¡ |
| | | */ |
| | | @Override |
| | | public AttributeVO getAttributeDetail(Long id) { |
| | | Func.requireNotNull(id,"主é®ä¸è½ä¸ºç©º"); |
| | | return AttributeWrapper.build().entityVO(baseMapper.selectByPrimaryKey(id)); |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢æä¿®æ¹ |
| | | * |
| | | * @param dto 页é¢ä¼ è¾å¯¹è±¡ |
| | | * @return æ§è¡ç»æ |
| | | */ |
| | | @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("屿§åå·²åå¨!"); |
| | | } |
| | | dto.setIsDeleted(BladeConstant.DB_NOT_DELETED); |
| | | Attribute omdAttribute = BeanUtil.copy(dto, Attribute.class); |
| | | CacheUtil.clear(OmdCacheConstant.ATTR_CACHE); |
| | | return saveOrUpdate(omdAttribute); |
| | | } |
| | | |
| | | /** |
| | | * å é¤ |
| | | * |
| | | * @param ids 主é®éå |
| | | * @return æ§è¡ç»æ |
| | | */ |
| | | @Override |
| | | public boolean removeAttrs(String ids) { |
| | | List<Long> idList = Func.toLongList(ids); |
| | | return !deleteLogic(idList) && removeByIds(idList); |
| | | } |
| | | |
| | | /** |
| | | * æ¥çåºç¨èå´ |
| | | * |
| | | * @param id ä¸»é® |
| | | * @return æ¥è¯¢å·²åºç¨çä¸å¡ç±»ååç§° |
| | | */ |
| | | @Override |
| | | 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<AttributeVO> 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<AttributeVO> listAttributeByKeyCollection(Collection<String> attributeIdCollection) throws VciBaseException { |
| | | if(!CollectionUtils.isEmpty(attributeIdCollection)){ |
| | | List<Attribute> attributeDOList = listAttributeByKeyCollectionDO(attributeIdCollection); |
| | | if(!CollectionUtils.isEmpty(attributeDOList)) { |
| | | return AttributeWrapper.build().listEntityVO(attributeDOList); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®è±æåç§°éåè·å屿§æ°æ®å¯¹è±¡ |
| | | * @param attributeIdCollection 屿§çè±æåç§°éå |
| | | * @return 屿§æ°æ®å¯¹è±¡å表ï¼å¦ææä¸åå¨çä¸ä¼è¿åï¼å
¨é¨ä¸åå¨çåè¿å空å表 |
| | | * @throws VciBaseException mybatisæ¥è¯¢åºéçæ¶å伿åºå¼å¸¸ |
| | | */ |
| | | private List<Attribute> listAttributeByKeyCollectionDO(Collection<String> attributeIdCollection) throws VciBaseException { |
| | | if(!CollectionUtils.isEmpty(attributeIdCollection)){ |
| | | List<Attribute> 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<Attribute> attributeDOS = baseMapper.selectList(Wrappers.<Attribute>query().lambda().in(Attribute::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 { |
| | | String attributeDataTypeText = VciFieldTypeEnum.getTextByValue(attrDataType); |
| | | if(StringUtils.isBlank(attributeDataTypeText)){ |
| | | throw new VciBaseException("è±æå称为{0}ç屿§çç±»åä¸ç¬¦åè¦æ±",new Object[]{id}); |
| | | } |
| | | //å¿
é¡»è¦è¾å
¥é¿åº¦ |
| | | if( VciBaseUtil.inArray(new String[] {VciFieldTypeEnum.VTString.name()},attrDataType) |
| | | && (attributeLength == null ||attributeLength < 1)){ |
| | | 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}); |
| | | } |
| | | if(VciFieldTypeEnum.VTInteger.name().equalsIgnoreCase(defaultValue) |
| | | && !defaultValue.matches(OmdRegExpConstant.INT)){ |
| | | throw new VciBaseException("è±æå称为{0}ç屿§çé»è®¤å¼ä¸æ¯æ´æ°å",new Object[]{id}); |
| | | } |
| | | if(VciFieldTypeEnum.VTLong.name().equalsIgnoreCase(defaultValue) |
| | | && !defaultValue.matches(OmdRegExpConstant.LONG)){ |
| | | throw new VciBaseException("è±æå称为{0}ç屿§çé»è®¤å¼ä¸æ¯é¿æ´å½¢",new Object[]{id}); |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªå±æ§æ¯å¦ç¬¦åè¦æ± |
| | | * |
| | | * @param attributesDTO 屿§æ°æ®ä¼ è¾å¯¹è±¡ |
| | | * @return true 符å false ä¸ç¬¦å |
| | | * @throws VciBaseException ä¸ç¬¦åæ¶æåºå¼å¸¸ |
| | | */ |
| | | @Override |
| | | public boolean checkAttribute(BtmTypeLinkAttributesDTO 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; |
| | | } |
| | | } |