From d9fb787c2eb0bc4058087b81bc5f01abbaf2ba65 Mon Sep 17 00:00:00 2001
From: ludc <pUXmgxCf6A>
Date: 星期六, 27 五月 2023 11:41:09 +0800
Subject: [PATCH] 集团集成从code服务里提出来,改造成服务
---
Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/BtmTypeServiceImpl.java | 221 +++++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 205 insertions(+), 16 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..266fe5a 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;
@@ -71,6 +72,18 @@
*/
@Autowired
private IModifyAttributeService modifyAttributeService;
+
+ /**
+ * 鐗堟湰瑙勫垯鐨勬湇鍔�
+ */
+ @Autowired
+ private IRevisionRuleService revisionRuleService;
+
+ /**
+ * 灞炴�х殑鏈嶅姟
+ */
+ @Autowired
+ private IAttributeService attributeService;
/**
* 琛ㄥ悕鍓嶇紑
@@ -484,6 +497,7 @@
btmTypeDO.setTableName(getTableName(btmTypeDO.getId(),btmTypeDO.getDomain()));
}
// 娣诲姞灞炴��
+ btmTypeDTO.setOid(btmTypeDO.getOid());
afterAttributes = addAttributeForBtm(btmTypeDTO);
baseMapper.insert(btmTypeDO);
}else {
@@ -578,12 +592,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()});
-// }
-// }
+ 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()){
@@ -608,9 +622,6 @@
// 闇�瑕佹帶鍒跺瘑绾�
btmTypeDTO.setAttributes(addAttributeByFieldMap(btmTypeDTO.getAttributes(),BtmTypeFieldConstant.SECRET_MANAGE_FIELD_MAP));
}
- if (StringUtils.isBlank(btmTypeDTO.getOid())) {
- btmTypeDTO.setOid(VciBaseUtil.getPk());
- }
}
@Override
public boolean deleteLogic(@NotEmpty List<Long> ids) {
@@ -621,4 +632,182 @@
public boolean changeStatus(@NotEmpty List<Long> ids, Integer status) {
return false;
}
+
+ /**
+ * 鎸塪omain鍒嗙粍锛屾煡璇笟鍔$被鍨嬪睘鎬х粨鏋�
+ *
+ * @return 鏌ヨ缁撴灉
+ */
+ @Override
+ public List<BtmTypeTreeVO> 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<>();
+ domainMap.forEach((k,v)-> {
+ if (domain.containsKey(k)){
+ String label = domain.get(k);
+ BtmTypeTreeVO parent = new BtmTypeTreeVO();
+ parent.setName(label);
+ parent.setId(k);
+ parent.setChildList(v.stream().map(s -> {
+ BtmTypeTreeVO child = new BtmTypeTreeVO();
+ child.setOid(s.getOid());
+ child.setName(s.getId() + " " + (s.getName() == null ? "" : s.getName()));
+ child.setId(s.getId());
+ 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.setDomain(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);
+ }
}
--
Gitblit v1.9.3