| | |
| | | import com.alibaba.nacos.api.exception.NacosException; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.vci.ubcs.omd.cache.EnumCache; |
| | | import com.vci.ubcs.omd.constant.BtmTypeConstant; |
| | | import com.vci.ubcs.omd.constant.BtmTypeFieldConstant; |
| | | import com.vci.ubcs.omd.dto.BtmAndLinkTypeDdlDTO; |
| | | import com.vci.ubcs.omd.entity.Attribute; |
| | |
| | | /** |
| | | * 表名前缀 |
| | | */ |
| | | public static final String PL = "PL"; |
| | | public static final String PL = "PLBT"; |
| | | |
| | | /** |
| | | * 设置平台本身的业务类型 |
| | |
| | | @Override |
| | | public BtmTypeVO getBtmTypeByOid(String pkBtmType) throws ServiceException { |
| | | Func.requireNotNull(pkBtmType,"业务类型主键不能为空"); |
| | | BtmTypeVO btmTypeVO = BtmTypeWrapper.build().entityVO(baseMapper.selectOne(Wrappers.<BtmType>query().lambda().eq(BtmType::getOid, pkBtmType))); |
| | | BtmType queryBtmType = baseMapper.selectOne(Wrappers.<BtmType>query().lambda().eq(BtmType::getOid, pkBtmType)); |
| | | if (queryBtmType == null){ |
| | | return null; |
| | | } |
| | | BtmTypeVO btmTypeVO = BtmTypeWrapper.build().entityVO(queryBtmType); |
| | | btmTypeVO.setAttributes(btmTypeAttributeService.getAttributeByBtmTypeOid(pkBtmType)); |
| | | return btmTypeVO; |
| | | } |
| | |
| | | if (!existFieldMap.containsKey(k)){ |
| | | BtmTypeLinkAttributesDTO attr = new BtmTypeLinkAttributesDTO(); |
| | | attr.setId(k); |
| | | attr.setName(v); |
| | | attr.setAttrDataType(VciFieldTypeEnum.VTString.name()); |
| | | attr.setAttributeLength(50); |
| | | attr.setNullableFlag(false); |
| | |
| | | afterAttributes = updateAttributeForBtm(btmTypeByOid.getOid(),beforeAttributes, attributes); |
| | | } |
| | | BtmTypeVO btmTypeVO = BtmTypeWrapper.build().entityVO(btmTypeDO); |
| | | //在创建表的时候还需要把默认的字段带上。 |
| | | List<BtmTypeAttributeVO> defaultAttribute = btmTypeAttributeService.getDefaultAttribute(btmTypeVO); |
| | | afterAttributes.addAll(defaultAttribute); |
| | | btmTypeVO.setAttributes(afterAttributes); |
| | | try { |
| | | if (autoCreateTable) { |
| | | checkTableSame(btmTypeVO); |
| | | // checkTableSame(btmTypeVO); |
| | | R result = DomainRepeater.submitBtmType(btmTypeDTO.getDomain(), btmTypeVO); |
| | | if (result.isSuccess()){ |
| | | List<ModifyAttributeInfo> infoList = new ArrayList<>(); |
| | |
| | | // 需要控制版本 |
| | | // 检查使用的版本规则是否存在 |
| | | if (StringUtils.isNotBlank(btmTypeDTO.getRevisionRuleId())) { |
| | | if (revisionRuleService.checkRevisionRuleExist(btmTypeDTO.getRevisionRuleId())) { |
| | | if (!revisionRuleService.checkRevisionRuleExist(btmTypeDTO.getRevisionRuleId())) { |
| | | throw new VciBaseException("版本规则{0}[{1}]在系统中不存在,请先查证", |
| | | new Object[]{btmTypeDTO.getRevisionRuleId(), btmTypeDTO.getRevisionRuleName()}); |
| | | } |
| | | } |
| | | btmTypeDTO.setAttributes(addAttributeByFieldMap(btmTypeDTO.getAttributes(),BtmTypeFieldConstant.REVISION_MANAGE_FIELD_MAP)); |
| | | // btmTypeDTO.setAttributes(addAttributeByFieldMap(btmTypeDTO.getAttributes(),BtmTypeFieldConstant.REVISION_MANAGE_FIELD_MAP)); |
| | | } |
| | | if (btmTypeDTO.isLifeCycleFlag()){ |
| | | // 需要控制生命周期 |
| | |
| | | // new Object[]{btmTypeDTO.getSubLifeCycleId(), btmTypeDTO.getSubLifeCycleName()}); |
| | | // } |
| | | // } |
| | | btmTypeDTO.setAttributes(addAttributeByFieldMap(btmTypeDTO.getAttributes(),BtmTypeFieldConstant.LIFECYCLE_MANAGE_FIELD_MAP)); |
| | | // btmTypeDTO.setAttributes(addAttributeByFieldMap(btmTypeDTO.getAttributes(),BtmTypeFieldConstant.LIFECYCLE_MANAGE_FIELD_MAP)); |
| | | } |
| | | if (btmTypeDTO.isSecretFlag()){ |
| | | // 需要控制密级 |
| | | btmTypeDTO.setAttributes(addAttributeByFieldMap(btmTypeDTO.getAttributes(),BtmTypeFieldConstant.SECRET_MANAGE_FIELD_MAP)); |
| | | // btmTypeDTO.setAttributes(addAttributeByFieldMap(btmTypeDTO.getAttributes(),BtmTypeFieldConstant.SECRET_MANAGE_FIELD_MAP)); |
| | | } |
| | | } |
| | | @Override |
| | |
| | | * @return 查询结果 |
| | | */ |
| | | @Override |
| | | public List<BtmTypeTreeVO> treeDomain() { |
| | | public List<BtmTreeVO> treeDomain() { |
| | | try { |
| | | Map<String, String> domain = Optional.ofNullable(DomainRepeater.getDomain()).orElseGet(ArrayList::new).stream().collect(Collectors.toMap(s -> s.getValue(), t -> t.getLabel())); |
| | | List<BtmTypeVO> vos = BtmTypeWrapper.build().listEntityVO(baseMapper.selectAll()); |
| | | Map<String, List<BtmTypeVO>> domainMap = vos.stream().collect(Collectors.groupingBy(BtmTypeVO::getDomain)); |
| | | List<BtmTypeTreeVO> treeList = new ArrayList<>(); |
| | | List<BtmTreeVO> treeList = new ArrayList<>(); |
| | | domainMap.forEach((k,v)-> { |
| | | if (domain.containsKey(k)){ |
| | | String label = domain.get(k); |
| | | BtmTypeTreeVO parent = new BtmTypeTreeVO(); |
| | | BtmTreeVO parent = new BtmTreeVO(); |
| | | parent.setName(label); |
| | | parent.setLabel(label); |
| | | parent.setId(k); |
| | | parent.setChildList(v.stream().map(s -> { |
| | | BtmTypeTreeVO child = new BtmTypeTreeVO(); |
| | | BtmTreeVO child = new BtmTreeVO(); |
| | | child.setOid(s.getOid()); |
| | | child.setName(s.getId() + " " + (s.getName() == null ? "" : s.getName())); |
| | | child.setName(s.getName()); |
| | | child.setId(s.getId()); |
| | | child.setLabel(s.getId() + (s.getName() == null ? "" : "(" + s.getName() + ")")); |
| | | return child; |
| | | }).collect(Collectors.toList())); |
| | | treeList.add(parent); |
| | |
| | | btmType.setOid(VciBaseUtil.getPk()); |
| | | btmType.setTs(now); |
| | | btmType.setCreator(user); |
| | | btmType.setBtmName("btmType"); |
| | | btmType.setBtmName(BtmTypeConstant.BTMTYPE); |
| | | btmType.setCreateTime(now); |
| | | btmType.setDomain(domain); |
| | | btmType.setLastModifyTime(now); |
| | |
| | | }).map(attr -> { |
| | | // 添加属性,1是校验,2是添加 |
| | | Attribute attribute = new Attribute(); |
| | | attribute.setKey(attr.getId()); |
| | | attribute.setLabel(attr.getName()); |
| | | attribute.setId(attr.getId()); |
| | | attribute.setName(attr.getName()); |
| | | attribute.setTypeCode("attributeType"); |
| | | attribute.setTypeKey(attr.getAttrDataType()); |
| | | // attribute.setDictKey(attr.getAttrDataType()); |
| | |
| | | attribute.setReferToId(attr.getReferBtmTypeId()); |
| | | attribute.setReferToName(attr.getReferBtmTypeName()); |
| | | attribute.setTs(now); |
| | | attribute.setOwner(user); |
| | | attribute.setCreateTime(now); |
| | | attribute.setIsDeleted(0); |
| | | attribute.setCreateUser(AuthUtil.getUserId()); |
| | | idAttrMap.put(attribute.getKey(),attribute); |
| | | attribute.setLastModifier(user); |
| | | attribute.setLastModifyTime(now); |
| | | attribute.setBtmName(BtmTypeConstant.ATTRIBUTE); |
| | | attribute.setCreator(user); |
| | | attribute.setOid(VciBaseUtil.getPk()); |
| | | idAttrMap.put(attribute.getId(),attribute); |
| | | // 在这里给业务类型设置版本控制、生命周期控制、密级控制相关的信息 |
| | | |
| | | // 添加业务类型和属性的关系 |
| | |
| | | btmTypeAttribute.setCreateTime(now); |
| | | btmTypeAttribute.setLastModifier(user); |
| | | btmTypeAttribute.setLastModifyTime(now); |
| | | // btmTypeAttribute.setBtmName("btmTypeAttribute"); |
| | | btmTypeAttribute.setOid(VciBaseUtil.getPk()); |
| | | btmTypeAttribute.setBtmName(btmType.getId()); |
| | | btmTypeAttribute.setOwner(user); |
| | |
| | | btmType.setConsistence(BooleanEnum.TRUE.getValue()); |
| | | btmList.add(btmType); |
| | | }); |
| | | List<Attribute> existAttr = attributeService.list(Wrappers.<Attribute>query().lambda().in(Attribute::getKey, attributeIds)); |
| | | List<Attribute> existAttr = attributeService.list(Wrappers.<Attribute>query().lambda().in(Attribute::getId, attributeIds)); |
| | | if (!CollectionUtils.isEmpty(btmList)){ |
| | | baseMapper.batchInsert(btmList); |
| | | } |
| | |
| | | if (CollectionUtils.isEmpty(existAttr)){ |
| | | attributeService.saveBatch(idAttrMap.values()); |
| | | }else { |
| | | List<Attribute> addList = idAttrMap.values().stream().filter(a -> existAttr.stream().noneMatch(b -> StringUtils.equals(a.getKey(), b.getKey()))).collect(Collectors.toList()); |
| | | List<Attribute> addList = idAttrMap.values().stream().filter(a -> existAttr.stream().noneMatch(b -> StringUtils.equals(a.getId(), b.getId()))).collect(Collectors.toList()); |
| | | if (!CollectionUtils.isEmpty(addList)) { |
| | | attributeService.saveBatch(addList); |
| | | } |
| | | } |
| | | return BtmTypeWrapper.build().listEntityVO(btmList); |
| | | } |
| | | |
| | | /** |
| | | * 按照业务类型id获取默认属性 |
| | | * |
| | | * @param btmTypeId 业务类型id |
| | | * @return 业务类型 |
| | | */ |
| | | @Override |
| | | public BtmTypeVO getDefaultAttrByBtmId(String btmTypeId) { |
| | | BtmTypeVO btmType = getBtmTypeById(btmTypeId); |
| | | if (btmType == null){ |
| | | return null; |
| | | } |
| | | btmType.setAttributes(btmTypeAttributeService.getDefaultAttribute(btmType)); |
| | | return btmType; |
| | | } |
| | | |
| | | /** |
| | | * 按照业务类型id获取所有的属性 |
| | | * |
| | | * @param btmTypeId 业务类型id |
| | | * @return 业务类型 |
| | | */ |
| | | @Override |
| | | public BtmTypeVO getAllAttributeByBtmId(String btmTypeId) { |
| | | BtmTypeVO btmType = getBtmTypeById(btmTypeId); |
| | | if (btmType == null){ |
| | | return null; |
| | | } |
| | | btmType.setAttributes(btmTypeAttributeService.getAllAttribute(btmType)); |
| | | return btmType; |
| | | } |
| | | |
| | | /** |
| | | * 按照业务类型主键获取所有的属性 |
| | | * |
| | | * @param btmTypeOid 业务类型主键 |
| | | * @return 业务类型 |
| | | */ |
| | | @Override |
| | | public BtmTypeVO getAllAttributeByBtmOid(String btmTypeOid) { |
| | | BtmTypeVO btmType = getBtmTypeByOid(btmTypeOid); |
| | | if (btmType == null){ |
| | | return null; |
| | | } |
| | | btmType.setAttributes(btmTypeAttributeService.getAllAttribute(btmType)); |
| | | return btmType; |
| | | } |
| | | } |