From fb1856cd8c814dc635e663c82e445489219db31c Mon Sep 17 00:00:00 2001 From: lihang <lihang@vci-tech.com> Date: 星期四, 13 七月 2023 15:59:49 +0800 Subject: [PATCH] 业务类型、链接类型细节修正 --- Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/LinkTypeServiceImpl.java | 202 +++++++++++++++++++++++++++++++++++++------------- 1 files changed, 148 insertions(+), 54 deletions(-) diff --git a/Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/LinkTypeServiceImpl.java b/Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/LinkTypeServiceImpl.java index 80820f9..77ee224 100644 --- a/Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/LinkTypeServiceImpl.java +++ b/Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/LinkTypeServiceImpl.java @@ -4,15 +4,8 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.alibaba.nacos.api.exception.NacosException; -import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; -import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper; -import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; -import com.baomidou.mybatisplus.extension.conditions.update.UpdateChainWrapper; -import com.baomidou.mybatisplus.extension.kotlin.KtQueryChainWrapper; -import com.baomidou.mybatisplus.extension.kotlin.KtUpdateChainWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.vci.ubcs.omd.constant.BtmTypeConstant; import com.vci.ubcs.omd.dto.BtmAndLinkTypeDdlDTO; @@ -26,8 +19,7 @@ import com.vci.ubcs.omd.mapper.LinkTypeMapper; import com.vci.ubcs.omd.repeater.DomainRepeater; import com.vci.ubcs.omd.service.*; -import com.vci.ubcs.omd.vo.LinkTypeAttributeVO; -import com.vci.ubcs.omd.vo.LinkTypeVO; +import com.vci.ubcs.omd.vo.*; import com.vci.ubcs.omd.wrapper.LinkTypeAttributeWrapper; import com.vci.ubcs.omd.wrapper.LinkTypeWrapper; import com.vci.ubcs.starter.exception.VciBaseException; @@ -49,12 +41,12 @@ 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; -import java.io.Serializable; +import javax.validation.constraints.NotEmpty; import java.util.*; -import java.util.function.Function; import java.util.stream.Collectors; /** @@ -95,12 +87,10 @@ @Autowired private IModifyAttributeService modifyAttributeService; - public final String BTM_NAME = "linkType"; - /** * 琛ㄥ悕鍓嶇紑 */ - public static final String PL = "PL"; + public static final String PL = "PLLT"; /** @@ -171,7 +161,8 @@ if(!CollectionUtils.isEmpty(pkLinkTypeCollection)){ List<LinkType> linkTypeDOList = listLinkTypeDOByOidCollection(pkLinkTypeCollection); if(!CollectionUtils.isEmpty(linkTypeDOList)) { - return LinkTypeWrapper.build().listEntityVO(linkTypeDOList); + Map<String,List<LinkTypeAttributeVO>> pkLinkTypeAndAttributeMap = linkTypeAttributeService.batchGetAttributesNoDefault(linkTypeDOList); + return LinkTypeWrapper.build().listEntityVO(linkTypeDOList,pkLinkTypeAndAttributeMap); } } return null; @@ -196,6 +187,7 @@ linkTypeDOList.addAll(linkTypeDOS); } }); + return linkTypeDOList; } return null; } @@ -243,7 +235,8 @@ if(!CollectionUtils.isEmpty(linkTypeIdCollection)){ List<LinkType> linkTypeDOList = listLinkTypeDOByIdCollection(linkTypeIdCollection); if(!CollectionUtils.isEmpty(linkTypeDOList)) { - return LinkTypeWrapper.build().listEntityVO(linkTypeDOList); + Map<String,List<LinkTypeAttributeVO>> pkLinkTypeAndAttributeMap = linkTypeAttributeService.batchGetAttributesNoDefault(linkTypeDOList); + return LinkTypeWrapper.build().listEntityVO(linkTypeDOList, pkLinkTypeAndAttributeMap); } } return null; @@ -354,6 +347,7 @@ * @throws VciBaseException 娣诲姞鍑洪敊鐨勬椂鍊欎細鎶涘嚭寮傚父 */ @Override + @Transactional public LinkTypeVO addSave(LinkTypeVO linkTypeVO, boolean autoCreateTable) throws VciBaseException { TransactionStatus transaction = null; if(autoCreateTable) { @@ -400,20 +394,29 @@ } LinkType linkTypeDO = new LinkType(); BeanUtil.copy(linkTypeVO, linkTypeDO); + if (StringUtils.isBlank(linkTypeDO.getTableName())){ + linkTypeDO.setTableName(getTableName(linkTypeDO.getId(),linkTypeDO.getBizDomain())); + } String creator = AuthUtil.getUserAccount(); Date now = new Date(); - linkTypeDO.setCreator(creator); - linkTypeDO.setCreateTime(now); - linkTypeDO.setOwner(creator); - linkTypeDO.setBtmName(BtmTypeConstant.LINK_TYPE); - linkTypeDO.setTs(now); + LinkTypeWrapper.build().setBeforeInsert(linkTypeDO,creator,now); //澶勭悊灞炴�� - addAttributeForLink(linkTypeVO.getAttributes(),linkTypeDO.getOid(),creator,now); + List<LinkTypeAttributeVO> attributeVOList = addAttributeForLink(linkTypeVO.getAttributes(), linkTypeDO.getOid(), creator, now); baseMapper.insert(linkTypeDO); if(autoCreateTable) { - dataSourceTransactionManager.commit(transaction); + LinkTypeVO typeVO = LinkTypeWrapper.build().entityVO(linkTypeDO); + typeVO.setAttributes(attributeVOList); + List<LinkTypeAttributeVO> attributes = typeVO.getAttributes(); + attributes.addAll(linkTypeAttributeService.getDefaultAttributes(typeVO)); + typeVO.setAttributes(attributes); + R r = DomainRepeater.submitLinkType(typeVO.getBizDomain(), typeVO); + if (!r.isSuccess()){ + dataSourceTransactionManager.rollback(transaction); + }else { + dataSourceTransactionManager.commit(transaction); + } } }catch (VciBaseException e){ if(autoCreateTable) { @@ -426,9 +429,9 @@ } throw e; } - if(autoCreateTable) { + /*if(autoCreateTable) { checkTableSame(linkTypeVO); - } + }*/ return linkTypeVO; } @@ -439,11 +442,11 @@ * @param creator 鍒涘缓浜� * @param now 褰撳墠鏃堕棿 */ - private void addAttributeForLink(List<LinkTypeAttributeVO> attributesVOList,String pkLinkType,String creator,Date now){ + private List<LinkTypeAttributeVO> addAttributeForLink(List<LinkTypeAttributeVO> attributesVOList,String pkLinkType,String creator,Date now){ List<LinkTypeAttribute> linkTypeAttributeDOList = new ArrayList<>(); if(!CollectionUtils.isEmpty(attributesVOList)) { List<String> attributeIdList = new ArrayList<>(); - attributesVOList.stream().forEachOrdered(s -> { + attributesVOList.forEach(s -> { linkTypeAttributeService.checkAttribute(s); linkTypeAttributeDOList.add(LinkTypeAttributeWrapper.build().copyVO2DO(s, pkLinkType, creator, now)); attributeIdList.add(s.getId().toLowerCase().trim()); @@ -451,7 +454,9 @@ //妫�鏌ュ睘鎬ф槸鍚﹂兘瀛樺湪 attributeService.checkAttributeExists(attributeIdList); linkTypeAttributeService.saveOrUpdateBatch(linkTypeAttributeDOList,10000); + return LinkTypeAttributeWrapper.build().listEntityVO(linkTypeAttributeDOList); } + return null; } /** @@ -480,8 +485,8 @@ } if (!CollectionUtils.isEmpty(modifyAttributeInfoDOList)) { modifyAttributeService.saveOrUpdateBatch(modifyAttributeInfoDOList); + modifyAttributeService.finishModify(modifyAttributeInfoDOList); } - modifyAttributeService.finishModify(modifyAttributeInfoDOList); } /** @@ -544,15 +549,10 @@ if(StringUtils.isNotBlank(unExistBtmTypeId)){ throw new VciBaseException("閾炬帴绫诲瀷浣跨敤鐨勪笟鍔$被鍨媨0}涓嶅瓨鍦紝璇锋煡璇�",new Object[]{unExistBtmTypeId}); } - String creator = AuthUtil.getUserAccount(); Date now = new Date(); - linkTypeDO.setLastModifier(creator); - linkTypeDO.setLastModifyTime(now); - linkTypeDO.setTs(now); + linkTypeDO = LinkTypeWrapper.build().setBeforeUpdate(linkTypeDO,creator,now); //澶勭悊灞炴�� - - LinkTypeWrapper.build().copyLinkTypeVO2DO(linkTypeVO,linkTypeDO,creator,new Date()); //鍏堟煡璇㈣繖涓摼鎺ョ被鍨嬪寘鍚灏戝睘鎬� @@ -566,22 +566,23 @@ } saveOrUpdate(linkTypeDO); if(autoCreateTable) { + List<LinkTypeAttributeVO> defaultAttributes = linkTypeAttributeService.getDefaultAttributes(linkTypeVO); + List<LinkTypeAttributeVO> attributes = linkTypeVO.getAttributes(); + attributes.addAll(defaultAttributes); + linkTypeVO.setAttributes(attributes); + BtmAndLinkTypeDdlDTO ddlDTO = new BtmAndLinkTypeDdlDTO(); + DomainRepeater.checkDifferent(ddlDTO,linkTypeVO.getBizDomain()); dataSourceTransactionManager.commit(transaction); } - }catch (VciBaseException e){ + } catch (Throwable e){ if(autoCreateTable) { dataSourceTransactionManager.rollback(transaction); } - throw e; - }catch (Throwable e) { - if(autoCreateTable) { - dataSourceTransactionManager.rollback(transaction); - } - throw e; + throw new VciBaseException(e.getMessage()); } - if(autoCreateTable) { + /*if(autoCreateTable) { checkTableSame(linkTypeVO); - } + }*/ return linkTypeVO; } @@ -624,10 +625,10 @@ List<TableCheckDTO> checkList = linkTypeDOList.stream().map(linkType -> { TableCheckDTO tableCheckDTO = new TableCheckDTO(); tableCheckDTO.setBtmName(linkType.getId()); - tableCheckDTO.setTableName(getTableName(linkType.getId(),linkType.getDomain())); + tableCheckDTO.setTableName(getTableName(linkType.getId(),linkType.getBizDomain())); tableCheckDTO.setCheckTableHasData(true); tableCheckDTO.setNeedDelete(true); - tableCheckDTO.setDomain(linkType.getDomain()); + tableCheckDTO.setDomain(linkType.getBizDomain()); return tableCheckDTO; }).collect(Collectors.toList()); R result = DomainRepeater.checkTableHasDataByTableNameThenDrop(checkList); @@ -809,19 +810,19 @@ attributeVO.setLastModifier(creator); attributeVO.setLastModifyTime(now); attributeVO.setTs(now); - //鏌ヨ閾炬帴绫诲瀷鏄惁瀛樺湪 linkTypeAttributeService.saveOrUpdate(attributeDO); if (autoEdit2Table) { BtmAndLinkTypeDdlDTO ddlDTO = new BtmAndLinkTypeDdlDTO(); -// ddlDTO.setLinkTypeList(); -// DomainRepeater.checkDifferent(,domain); + LinkTypeVO linkTypeVO = LinkTypeWrapper.build().entityVO(linkTypeDO); + ddlDTO.setLinkTypeList(Collections.singletonList(linkTypeVO)); + DomainRepeater.checkDifferent(ddlDTO,domain); dataSourceTransactionManager.commit(transaction); } -// }catch (NacosException e){ -// if(autoEdit2Table) { -// dataSourceTransactionManager.rollback(transaction); -// } -// throw new RuntimeException(e); + }catch (NacosException e){ + if(autoEdit2Table) { + dataSourceTransactionManager.rollback(transaction); + } + throw new RuntimeException(e); }catch (Throwable e){ if(autoEdit2Table) { dataSourceTransactionManager.rollback(transaction); @@ -845,7 +846,7 @@ }else { throw new VciBaseException("棰嗗煙鍚嶇О涓嶇鍚堣鍒�"); } - return PL + StringPool.UNDERSCORE + domain + StringPool.UNDERSCORE + id; + return PL + StringPool.UNDERSCORE + domain.toUpperCase(Locale.ROOT) + StringPool.UNDERSCORE + id.toUpperCase(Locale.ROOT); } /** @@ -865,4 +866,97 @@ } return btmTypeSet; } + + /** + * 鎸塪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<LinkTypeVO> vos = LinkTypeWrapper.build().listEntityVO(baseMapper.selectAll(), null); + if (CollectionUtils.isEmpty(vos)){ + return new ArrayList<>(); + } + Map<String, List<LinkTypeVO>> domainMap = Optional.ofNullable(vos).orElseGet(ArrayList::new).stream().collect(Collectors.groupingBy(LinkTypeVO::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.setId(k); + parent.setLevel(1); + parent.setLabel(label); + parent.setChildList(v.stream().map(s -> { + BtmTreeVO child = new BtmTreeVO(); + child.setOid(s.getOid()); + child.setLabel(s.getId() + (s.getName() == null ? "" : "(" + s.getName() + ")")); + child.setId(s.getId()); + child.setName(s.getName()); + child.setLevel(2); + return child; + }).collect(Collectors.toList())); + treeList.add(parent); + } + }); + return treeList; + } catch (NacosException e) { + throw new RuntimeException(e); + } + } + + @Override + public boolean deleteLogic(@NotEmpty List<Long> ids) { + return false; + } + + @Override + public boolean changeStatus(@NotEmpty List<Long> ids, Integer status) { + return false; + } + + /** + * 鑾峰彇閾炬帴绫诲瀷锛屽彧鏈夐粯璁ゅ瓧娈� + * + * @param linkTypeId 閾炬帴绫诲瀷id + * @return 榛樿瀛楁灞炴�� + */ + @Override + public LinkTypeVO getLinkTypeDefaultAttrById(String linkTypeId) { + LinkTypeVO vo = getLinkTypeById(linkTypeId); + List<LinkTypeAttributeVO> attributes = linkTypeAttributeService.getDefaultAttributes(vo); + vo.setAttributes(attributes); + return vo; + } + + /** + * 鑾峰彇閾炬帴绫诲瀷锛屾湁鎵�鏈夌殑瀛楁 + * + * @param linkTypeId 閾炬帴绫诲瀷id + * @return 鎵�鏈夊瓧娈� + */ + @Override + public LinkTypeVO getLinkTypeAllAttrById(String linkTypeId) { + LinkTypeVO vo = getLinkTypeById(linkTypeId); + List<LinkTypeAttributeVO> attributes = linkTypeAttributeService.getAllAttributes(vo); + vo.setAttributes(attributes); + return vo; + } + + /** + * 鑾峰彇閾炬帴绫诲瀷锛屾湁鎵�鏈夌殑瀛楁 + * + * @param linkTypeOid 閾炬帴绫诲瀷涓婚敭 + * @return 鎵�鏈夊瓧娈� + */ + @Override + public LinkTypeVO getLinkTypeAllAttrByOid(String linkTypeOid) { + LinkTypeVO vo = getLinkTypeByOid(linkTypeOid); + List<LinkTypeAttributeVO> attributes = linkTypeAttributeService.getAllAttributes(vo); + vo.setAttributes(attributes); + return vo; + } } -- Gitblit v1.9.3