ludc
2023-06-30 e146bc181625aee75624f8364654721cfd886254
Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/BtmTypeServiceImpl.java
@@ -6,14 +6,12 @@
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;
import com.vci.ubcs.omd.repeater.DomainRepeater;
import com.vci.ubcs.omd.service.IAttributeService;
import com.vci.ubcs.omd.service.IBtmTypeAttributeService;
import com.vci.ubcs.omd.service.IModifyAttributeService;
import com.vci.ubcs.omd.service.*;
import com.vci.ubcs.omd.vo.*;
import com.vci.ubcs.omd.wrapper.BtmTypeWrapper;
import com.vci.ubcs.omd.wrapper.ModifyAttributeWrapper;
@@ -24,7 +22,6 @@
import com.vci.ubcs.omd.entity.BtmTypeAttribute;
import com.vci.ubcs.omd.entity.ModifyAttributeInfo;
import com.vci.ubcs.omd.mapper.BtmTypeMapper;
import com.vci.ubcs.omd.service.IBtmTypeService;
import com.vci.ubcs.starter.exception.VciBaseException;
import com.vci.ubcs.starter.web.enumpck.BooleanEnum;
import com.vci.ubcs.starter.web.enumpck.VciFieldTypeEnum;
@@ -77,6 +74,12 @@
   private IModifyAttributeService modifyAttributeService;
   /**
    * 版本规则的服务
    */
   @Autowired
   private IRevisionRuleService revisionRuleService;
   /**
    * 属性的服务
    */
   @Autowired
@@ -85,7 +88,7 @@
   /**
    * 表名前缀
    */
   public static final String PL = "PL";
   public static final String PL = "PLBT";
   /**
    * 设置平台本身的业务类型
@@ -107,7 +110,11 @@
   @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;
   }
@@ -357,6 +364,7 @@
         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);
@@ -504,10 +512,13 @@
         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<>();
@@ -589,13 +600,13 @@
      if (btmTypeDTO.isRevisionFlag()){
         // 需要控制版本
         // 检查使用的版本规则是否存在
//            if (StringUtils.isNotBlank(btmTypeDTO.getRevisionRuleId())) {
//               if (revisionRuleServiceI.checkRevisionRuleExist(btmTypeDTO.getRevisionRuleId())) {
//                  throw new VciBaseException("版本规则{0}[{1}]在系统中不存在,请先查证",
//                     new Object[]{btmTypeDTO.getRevisionRuleId(), btmTypeDTO.getRevisionRuleName()});
//               }
//            }
         btmTypeDTO.setAttributes(addAttributeByFieldMap(btmTypeDTO.getAttributes(),BtmTypeFieldConstant.REVISION_MANAGE_FIELD_MAP));
            if (StringUtils.isNotBlank(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));
      }
      if (btmTypeDTO.isLifeCycleFlag()){
         // 需要控制生命周期
@@ -613,11 +624,11 @@
//                     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
@@ -636,23 +647,25 @@
    * @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);
@@ -719,7 +732,7 @@
         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);
@@ -734,8 +747,8 @@
         }).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());
@@ -748,10 +761,14 @@
            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);
            // 在这里给业务类型设置版本控制、生命周期控制、密级控制相关的信息
            // 添加业务类型和属性的关系
@@ -761,7 +778,6 @@
            btmTypeAttribute.setCreateTime(now);
            btmTypeAttribute.setLastModifier(user);
            btmTypeAttribute.setLastModifyTime(now);
//            btmTypeAttribute.setBtmName("btmTypeAttribute");
            btmTypeAttribute.setOid(VciBaseUtil.getPk());
            btmTypeAttribute.setBtmName(btmType.getId());
            btmTypeAttribute.setOwner(user);
@@ -775,7 +791,7 @@
         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);
      }
@@ -797,11 +813,59 @@
      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());
         if (CollectionUtils.isEmpty(addList)) {
         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;
   }
}