| | |
| | | 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.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.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; |
| | |
| | | */ |
| | | @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()}); |
| | | 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("属性名已存在!"); |
| | | throw new ServiceException("属性编号已存在!"); |
| | | } |
| | | Attribute attribute = AttributeWrapper.build().copyBeforeSave(dto); |
| | | CacheUtil.clear(OmdCacheConstant.ATTR_CACHE); |
| | |
| | | /** |
| | | * 删除 |
| | | * |
| | | * @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; |
| | | } |
| | | |
| | | /** |
| | |
| | | @Override |
| | | 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()); |
| | | if (CollectionUtils.isEmpty(btmTypes)){ |
| | | return null; |
| | | } |
| | | return null; |
| | | return BtmTypeWrapper.build().listEntityVO(btmTypes); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | 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("该属性已被使用,不允许删除"); |
| | | } |
| | | } |
| | | } |