From aedc56b3c034ef33811ca873debee68d6f963a88 Mon Sep 17 00:00:00 2001 From: lihang <lihang@vci-tech.com> Date: 星期二, 04 七月 2023 10:12:57 +0800 Subject: [PATCH] 更改领域值字段为bizDomain --- Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/BtmTypeServiceImpl.java | 295 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 271 insertions(+), 24 deletions(-) diff --git a/Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/BtmTypeServiceImpl.java b/Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/BtmTypeServiceImpl.java index 994199f..f947641 100644 --- a/Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/BtmTypeServiceImpl.java +++ b/Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/BtmTypeServiceImpl.java @@ -1,15 +1,18 @@ package com.vci.ubcs.omd.service.impl; import com.alibaba.cloud.commons.lang.StringUtils; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; 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.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.IBtmTypeAttributeService; -import com.vci.ubcs.omd.service.IModifyAttributeService; -import com.vci.ubcs.omd.wrapper.BtmTypeAttributeWrapper; +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; import com.vci.ubcs.starter.web.constant.OmdRegExpConstant; @@ -19,11 +22,8 @@ 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.omd.vo.BtmTypeVO; -import com.vci.ubcs.omd.vo.BtmTypeAttributeVO; -import com.vci.ubcs.omd.vo.LinkTypeVO; import com.vci.ubcs.starter.exception.VciBaseException; +import com.vci.ubcs.starter.web.enumpck.BooleanEnum; import com.vci.ubcs.starter.web.enumpck.VciFieldTypeEnum; import com.vci.ubcs.starter.web.util.VciBaseUtil; import com.vci.ubcs.starter.web.util.VciDateUtil; @@ -38,6 +38,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionStatus; +import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.support.DefaultTransactionDefinition; import org.springframework.util.CollectionUtils; @@ -73,9 +74,21 @@ private IModifyAttributeService modifyAttributeService; /** + * 鐗堟湰瑙勫垯鐨勬湇鍔� + */ + @Autowired + private IRevisionRuleService revisionRuleService; + + /** + * 灞炴�х殑鏈嶅姟 + */ + @Autowired + private IAttributeService attributeService; + + /** * 琛ㄥ悕鍓嶇紑 */ - public static final String PL = "PL"; + public static final String PL = "PLBT"; /** * 璁剧疆骞冲彴鏈韩鐨勪笟鍔$被鍨� @@ -97,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; } @@ -347,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); @@ -369,7 +387,7 @@ ddlDTO.setBtmTypeList(btmTypeVOList); try { // 灏嗕互鍓嶇殑checkDifferent鍜宺eflexDifferent缁撳悎浜� - R result = DomainRepeater.checkDifferent(ddlDTO,btmTypeVO.getDomain()); + R result = DomainRepeater.checkDifferent(ddlDTO,btmTypeVO.getBizDomain()); if (result.isSuccess()){ List<ModifyAttributeInfo> infoList = new ArrayList<>(); Object data = result.getData(); @@ -476,14 +494,16 @@ } checkBtmTypeBeforeSave(btmTypeDTO); BtmType btmTypeDO = Optional.ofNullable(BeanUtil.copy(btmTypeDTO, BtmType.class)).orElseGet(BtmType::new); + btmTypeDO.setBizDomain(btmTypeDTO.getDomain()); List<BtmTypeLinkAttributesDTO> attributes = btmTypeDTO.getAttributes(); List<BtmTypeAttributeVO> afterAttributes; if (StringUtils.isBlank(btmTypeDO.getOid())){ btmTypeDO = BtmTypeWrapper.build().entityBeforeInsert(btmTypeDO); if (StringUtils.isBlank(btmTypeDO.getTableName())) { - btmTypeDO.setTableName(getTableName(btmTypeDO.getId(),btmTypeDO.getDomain())); + btmTypeDO.setTableName(getTableName(btmTypeDO.getId(),btmTypeDO.getBizDomain())); } // 娣诲姞灞炴�� + btmTypeDTO.setOid(btmTypeDO.getOid()); afterAttributes = addAttributeForBtm(btmTypeDTO); baseMapper.insert(btmTypeDO); }else { @@ -493,10 +513,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<>(); @@ -514,11 +537,13 @@ dataSourceTransactionManager.commit(transaction); }else { dataSourceTransactionManager.rollback(transaction); + return R.fail(result.getMsg()); } } } catch (Throwable e) { if (autoCreateTable) { dataSourceTransactionManager.rollback(transaction); + throw new VciBaseException(e.getMessage()); } } return R.data(btmTypeVO); @@ -578,13 +603,12 @@ 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()}); + } + } } if (btmTypeDTO.isLifeCycleFlag()){ // 闇�瑕佹帶鍒剁敓鍛藉懆鏈� @@ -602,14 +626,9 @@ // new Object[]{btmTypeDTO.getSubLifeCycleId(), btmTypeDTO.getSubLifeCycleName()}); // } // } - btmTypeDTO.setAttributes(addAttributeByFieldMap(btmTypeDTO.getAttributes(),BtmTypeFieldConstant.LIFECYCLE_MANAGE_FIELD_MAP)); } if (btmTypeDTO.isSecretFlag()){ // 闇�瑕佹帶鍒跺瘑绾� - btmTypeDTO.setAttributes(addAttributeByFieldMap(btmTypeDTO.getAttributes(),BtmTypeFieldConstant.SECRET_MANAGE_FIELD_MAP)); - } - if (StringUtils.isBlank(btmTypeDTO.getOid())) { - btmTypeDTO.setOid(VciBaseUtil.getPk()); } } @Override @@ -621,4 +640,232 @@ public boolean changeStatus(@NotEmpty List<Long> ids, Integer status) { return false; } + + /** + * 鎸塪omain鍒嗙粍锛屾煡璇笟鍔$被鍨嬪睘鎬х粨鏋� + * + * @return 鏌ヨ缁撴灉 + */ + @Override + public List<BtmTreeVO> treeDomain() { + try { + Map<String, String> domain = Optional.ofNullable(DomainRepeater.getDomain()).orElseGet(ArrayList::new).stream().collect(Collectors.toMap(DomainVO::getValue, DomainVO::getLabel)); + List<BtmTypeVO> vos = BtmTypeWrapper.build().listEntityVO(baseMapper.selectAll()); + Map<String, List<BtmTypeVO>> domainMap = vos.stream().sorted(Comparator.comparing(BtmTypeVO::getId)).collect(Collectors.groupingBy(BtmTypeVO::getBizDomain)); + List<BtmTreeVO> treeList = new ArrayList<>(); + domainMap.forEach((k,v)-> { + if (domain.containsKey(k)){ + String label = domain.get(k); + BtmTreeVO parent = new BtmTreeVO(); + parent.setName(label); + parent.setLabel(label); + parent.setId(k); + parent.setChildList(v.stream().map(s -> { + BtmTreeVO child = new BtmTreeVO(); + child.setOid(s.getOid()); + 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); + } + }); + return treeList; + } catch (NacosException e) { + throw new RuntimeException(e); + } + } + + /** + * 浠庢暟鎹簱琛ㄤ腑鑾峰彇 + * + * @param domain 棰嗗煙鍊� + * @return 璇诲彇缁撴灉 + */ + @Override + public List<BtmTypeVO> getFromTable(String domain) { + VciBaseUtil.alertNotNull(domain,"棰嗗煙鍊�"); + try { + if (!DomainRepeater.getDomain().stream().collect(Collectors.toMap(DomainVO::getValue, DomainVO::getLabel)).containsKey(domain)){ + return null; + } + R result = DomainRepeater.getFromTable(domain); + if (result.isSuccess()){ + List<BtmTypeVO> list = new ArrayList<>(); + Object dataList = result.getData(); + if (dataList instanceof List){ + ((List<?>) dataList).forEach(data -> { + JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(data)); + list.add(BeanUtil.copy(jsonObject,BtmTypeVO.class)); + }); + } + return list; + }else { + return new ArrayList<>(); + } + } catch (NacosException e) { + throw new RuntimeException(e); + } + } + + /** + * 閫夋嫨鏁版嵁搴撹〃淇濆瓨涓轰笟鍔$被鍨� + * + * @param btmTypeDTOList 椤甸潰浼犺緭瀵硅薄 + * @param domain 棰嗗煙 + * @return 鎵ц缁撴灉 + */ + @Override + @Transactional + public List<BtmTypeVO> saveFromTable(List<BtmTypeDTO> btmTypeDTOList,String domain) { + // 涔嬪墠宸茬粡鍋氳繃閲嶅鏍¢獙浜嗭紝杩欒竟鐩存帴鎵ц淇濆瓨閫昏緫鍗冲彲 + List<BtmType> btmList = new ArrayList<>(); + List<BtmTypeAttribute> btmTypeAttributes = new ArrayList<>(); + Map<String,Attribute> idAttrMap = new HashMap<>(); + // 鏍¢獙灞炴�ф槸鍚﹀瓨鍦� + Set<String> attributeIds = new HashSet<>(); + Date now = new Date(); + String user = AuthUtil.getUserAccount(); + btmTypeDTOList.stream().forEach(dto -> { + BtmType btmType = Objects.requireNonNull(BeanUtil.copy(dto, BtmType.class)); + btmType.setOid(VciBaseUtil.getPk()); + btmType.setTs(now); + btmType.setCreator(user); + btmType.setBtmName(BtmTypeConstant.BTMTYPE); + btmType.setCreateTime(now); + btmType.setBizDomain(domain); + btmType.setLastModifyTime(now); + btmType.setLastModifier(user); + btmType.setName(dto.getDescription()); + Set<String> ids = dto.getAttributes().stream().filter(s -> { + return ! (BtmTypeFieldConstant.BASIC_FIELD_MAP.containsKey(s.getId()) + || BtmTypeFieldConstant.LIFECYCLE_MANAGE_FIELD_MAP.containsKey(s.getId()) + || BtmTypeFieldConstant.SECRET_MANAGE_FIELD_MAP.containsKey(s.getId()) + || BtmTypeFieldConstant.REVISION_MANAGE_FIELD_MAP.containsKey(s.getId()) + ); + }).map(attr -> { + // 娣诲姞灞炴�э紝1鏄牎楠岋紝2鏄坊鍔� + Attribute attribute = new Attribute(); + attribute.setId(attr.getId()); + attribute.setName(attr.getName()); + attribute.setTypeCode("attributeType"); + attribute.setTypeKey(attr.getAttrDataType()); +// attribute.setDictKey(attr.getAttrDataType()); + attribute.setMaxLength(attr.getAttributeLength()); + attribute.setPrecision(attr.getPrecisionLength()); + attribute.setDescription(attr.getDescription()); + attribute.setDefaultValue(attr.getDefaultValue()); + attribute.setNullable(String.valueOf(attr.isNullableFlag())); + attribute.setHashtag(attr.getDescription()); + attribute.setReferToId(attr.getReferBtmTypeId()); + attribute.setReferToName(attr.getReferBtmTypeName()); + attribute.setTs(now); + attribute.setOwner(user); + attribute.setCreateTime(now); + attribute.setLastModifier(user); + attribute.setLastModifyTime(now); + attribute.setBtmName(BtmTypeConstant.ATTRIBUTE); + attribute.setCreator(user); + attribute.setOid(VciBaseUtil.getPk()); + idAttrMap.put(attribute.getId(),attribute); + // 鍦ㄨ繖閲岀粰涓氬姟绫诲瀷璁剧疆鐗堟湰鎺у埗銆佺敓鍛藉懆鏈熸帶鍒躲�佸瘑绾ф帶鍒剁浉鍏崇殑淇℃伅 + + // 娣诲姞涓氬姟绫诲瀷鍜屽睘鎬х殑鍏崇郴 + BtmTypeAttribute btmTypeAttribute = Objects.requireNonNull(BeanUtil.copy(attr, BtmTypeAttribute.class)); + btmTypeAttribute.setPkBtmType(btmType.getOid()); + btmTypeAttribute.setCreator(user); + btmTypeAttribute.setCreateTime(now); + btmTypeAttribute.setLastModifier(user); + btmTypeAttribute.setLastModifyTime(now); + btmTypeAttribute.setOid(VciBaseUtil.getPk()); + btmTypeAttribute.setBtmName(btmType.getId()); + btmTypeAttribute.setOwner(user); + btmTypeAttributes.add(btmTypeAttribute); + return attr; + }).map(BtmTypeLinkAttributesDTO::getId).collect(Collectors.toSet()); + attributeIds.addAll(ids); + btmType.setLifeCycleFlag(String.valueOf(ids.stream().anyMatch(BtmTypeFieldConstant.LIFECYCLE_MANAGE_FIELD_MAP::containsKey))); + btmType.setRevisionFlag(String.valueOf(ids.stream().anyMatch(BtmTypeFieldConstant.REVISION_MANAGE_FIELD_MAP::containsKey))); + btmType.setSecretFlag(String.valueOf(ids.stream().anyMatch(BtmTypeFieldConstant.SECRET_MANAGE_FIELD_MAP::containsKey))); + btmType.setConsistence(BooleanEnum.TRUE.getValue()); + btmList.add(btmType); + }); + List<Attribute> existAttr = attributeService.list(Wrappers.<Attribute>query().lambda().in(Attribute::getId, attributeIds)); + if (!CollectionUtils.isEmpty(btmList)){ + baseMapper.batchInsert(btmList); + } + if (!CollectionUtils.isEmpty(btmTypeAttributes)){ + btmTypeAttributeService.saveBatch(btmTypeAttributes); + } + BtmTypeFieldConstant.BASIC_FIELD_MAP.forEach((k,v) -> { + idAttrMap.remove(k); + }); + BtmTypeFieldConstant.LIFECYCLE_MANAGE_FIELD_MAP.forEach((k,v) -> { + idAttrMap.remove(k); + }); + BtmTypeFieldConstant.SECRET_MANAGE_FIELD_MAP.forEach((k,v) -> { + idAttrMap.remove(k); + }); + BtmTypeFieldConstant.REVISION_MANAGE_FIELD_MAP.forEach((k,v) -> { + idAttrMap.remove(k); + }); + if (CollectionUtils.isEmpty(existAttr)){ + attributeService.saveBatch(idAttrMap.values()); + }else { + 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; + } } -- Gitblit v1.9.3