| | |
| | | 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; |
| | |
| | | import com.vci.ubcs.omd.repeater.DomainRepeater; |
| | | 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.LinkTypeAttributeWrapper; |
| | | import com.vci.ubcs.omd.wrapper.LinkTypeWrapper; |
| | | import com.vci.ubcs.starter.exception.VciBaseException; |
| | |
| | | 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 java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | 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; |
| | |
| | | linkTypeDOList.addAll(linkTypeDOS); |
| | | } |
| | | }); |
| | | return linkTypeDOList; |
| | | } |
| | | return null; |
| | | } |
| | |
| | | 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; |
| | |
| | | * @throws VciBaseException 添加出错的时候会抛出异常 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public LinkTypeVO addSave(LinkTypeVO linkTypeVO, boolean autoCreateTable) throws VciBaseException { |
| | | TransactionStatus transaction = null; |
| | | if(autoCreateTable) { |
| | |
| | | } |
| | | LinkType linkTypeDO = new LinkType(); |
| | | BeanUtil.copy(linkTypeVO, linkTypeDO); |
| | | if (StringUtils.isBlank(linkTypeDO.getTableName())){ |
| | | linkTypeDO.setTableName(getTableName(linkTypeDO.getId(),linkTypeDO.getDomain())); |
| | | } |
| | | 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.getDomain(), typeVO); |
| | | if (!r.isSuccess()){ |
| | | dataSourceTransactionManager.rollback(transaction); |
| | | }else { |
| | | dataSourceTransactionManager.commit(transaction); |
| | | } |
| | | } |
| | | }catch (VciBaseException e){ |
| | | if(autoCreateTable) { |
| | |
| | | } |
| | | throw e; |
| | | } |
| | | if(autoCreateTable) { |
| | | /*if(autoCreateTable) { |
| | | checkTableSame(linkTypeVO); |
| | | } |
| | | }*/ |
| | | return linkTypeVO; |
| | | } |
| | | |
| | |
| | | * @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()); |
| | |
| | | //检查属性是否都存在 |
| | | attributeService.checkAttributeExists(attributeIdList); |
| | | linkTypeAttributeService.saveOrUpdateBatch(linkTypeAttributeDOList,10000); |
| | | return LinkTypeAttributeWrapper.build().listEntityVO(linkTypeAttributeDOList); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | if (!CollectionUtils.isEmpty(modifyAttributeInfoDOList)) { |
| | | modifyAttributeService.saveOrUpdateBatch(modifyAttributeInfoDOList); |
| | | modifyAttributeService.finishModify(modifyAttributeInfoDOList); |
| | | } |
| | | modifyAttributeService.finishModify(modifyAttributeInfoDOList); |
| | | } |
| | | |
| | | /** |
| | |
| | | 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()); |
| | | |
| | | //先查询这个链接类型包含多少属性 |
| | |
| | | } |
| | | 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.getDomain()); |
| | | 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; |
| | | } |
| | | |
| | |
| | | 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); |
| | |
| | | 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()); |
| | | List<LinkTypeVO> vos = LinkTypeWrapper.build().listEntityVO(baseMapper.selectAll(), null); |
| | | Map<String, List<LinkTypeVO>> domainMap = vos.stream().collect(Collectors.groupingBy(LinkTypeVO::getDomain)); |
| | | List<BtmTreeVO> treeList = new ArrayList<>(); |
| | | domainMap.forEach((k,v)-> { |
| | |
| | | BtmTreeVO parent = new BtmTreeVO(); |
| | | parent.setName(label); |
| | | parent.setId(k); |
| | | parent.setLabel(label); |
| | | parent.setChildList(v.stream().map(s -> { |
| | | BtmTreeVO child = new BtmTreeVO(); |
| | | child.setOid(s.getOid()); |
| | | child.setName(s.getId() + " " + (s.getName() == null ? "" : s.getName())); |
| | | child.setLabel(s.getId() + (s.getName() == null ? "" : "(" + s.getName() + ")")); |
| | | child.setId(s.getId()); |
| | | child.setName(s.getName()); |
| | | return child; |
| | | }).collect(Collectors.toList())); |
| | | treeList.add(parent); |