From c0025985707e90ef01e4a178691c2609ba0459e5 Mon Sep 17 00:00:00 2001
From: ludc
Date: 星期五, 07 七月 2023 10:01:51 +0800
Subject: [PATCH] Merge branch 'master' of http://dev.vci-tech.com:1065/r/ubcs
---
Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/BtmTypeServiceImpl.java | 848 ++++++++++++++++++++++++++++++++++++++++----------------
1 files changed, 601 insertions(+), 247 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 bd51b5c..a75265e 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,25 +1,31 @@
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.conditions.query.LambdaQueryWrapper;
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.*;
+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;
import com.vci.ubcs.omd.dto.BtmTypeDTO;
import com.vci.ubcs.omd.dto.BtmTypeLinkAttributesDTO;
import com.vci.ubcs.omd.entity.BtmType;
import com.vci.ubcs.omd.entity.BtmTypeAttribute;
-import com.vci.ubcs.omd.entity.ModifyAttributeInfoDO;
+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;
import org.springblade.core.log.exception.ServiceException;
@@ -27,16 +33,19 @@
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
+import org.springblade.core.tool.utils.StringPool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
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 javax.validation.constraints.NotEmpty;
import java.util.*;
+import java.util.stream.Collectors;
/**
* Description: 涓氬姟绫诲瀷鏈嶅姟鐨勫疄鐜扮被
@@ -60,6 +69,29 @@
private IBtmTypeAttributeService btmTypeAttributeService;
/**
+ * 瀛楁淇敼淇℃伅鐨勬湇鍔�
+ */
+ @Autowired
+ private IModifyAttributeService modifyAttributeService;
+
+ /**
+ * 鐗堟湰瑙勫垯鐨勬湇鍔�
+ */
+ @Autowired
+ private IRevisionRuleService revisionRuleService;
+
+ /**
+ * 灞炴�х殑鏈嶅姟
+ */
+ @Autowired
+ private IAttributeService attributeService;
+
+ /**
+ * 琛ㄥ悕鍓嶇紑
+ */
+ public static final String PL = "PLBT";
+
+ /**
* 璁剧疆骞冲彴鏈韩鐨勪笟鍔$被鍨�
*
* @param platformBtmType 骞冲彴鏈韩鐨勪笟鍔$被鍨�
@@ -79,7 +111,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;
}
@@ -93,7 +129,10 @@
*/
@Override
public List<BtmTypeVO> listBtmTypeByOids(String pkBtmTypes) throws ServiceException {
- return null;
+ VciBaseUtil.alertNotNull(pkBtmTypes, "涓氬姟绫诲瀷鐨勪富閿�");
+ List<String> pkList = new ArrayList<>();
+ Collections.addAll(pkList, pkBtmTypes.split(","));
+ return listBtmTypeByOidCollection(pkList);
}
/**
@@ -105,6 +144,12 @@
*/
@Override
public List<BtmTypeVO> listBtmTypeByOidCollection(Collection<String> pkBtmTypeCollection) throws ServiceException {
+ if (!CollectionUtils.isEmpty(pkBtmTypeCollection)) {
+ List<BtmType> btmTypeDOList = listBtmTypeDOByOidCollection(pkBtmTypeCollection);
+ if (!CollectionUtils.isEmpty(btmTypeDOList)) {
+ return BtmTypeWrapper.build().listEntityVO(btmTypeDOList);
+ }
+ }
return null;
}
@@ -117,6 +162,11 @@
*/
@Override
public BtmTypeVO getBtmTypeById(String id) throws ServiceException {
+ VciBaseUtil.alertNotNull(id, "涓氬姟绫诲瀷鐨勮嫳鏂囧悕绉�");
+ List<BtmTypeVO> btmTypeVOList = listBtmTypeByIds(id);
+ if (!CollectionUtils.isEmpty(btmTypeVOList)) {
+ return btmTypeVOList.get(0);
+ }
return null;
}
@@ -129,7 +179,8 @@
*/
@Override
public List<BtmTypeVO> listBtmTypeByIds(String ids) throws ServiceException {
- return null;
+ Func.requireNotNull(ids,"鑻辨枃鍚嶇О涓嶈兘涓虹┖");
+ return listBtmTypeByIdCollection(Func.toStrList(",",ids));
}
/**
@@ -141,7 +192,7 @@
*/
@Override
public List<BtmTypeVO> listBtmTypeByIdCollection(Collection<String> idCollection) throws ServiceException {
- return null;
+ return CollectionUtils.isEmpty(idCollection) ? null : BtmTypeWrapper.build().listEntityVO(baseMapper.selectList(Wrappers.<BtmType>query().lambda().in(BtmType::getId,idCollection)));
}
/**
@@ -153,7 +204,7 @@
*/
@Override
public List<BtmType> listBtmTypeDOByIdCollection(Collection<String> idCollection) throws ServiceException {
- return null;
+ return CollectionUtils.isEmpty(idCollection) ? null : baseMapper.selectList(Wrappers.<BtmType>query().lambda().in(BtmType::getId, idCollection));
}
/**
@@ -165,6 +216,9 @@
*/
@Override
public List<BtmType> listBtmTypeDOByOidCollection(Collection<String> oidCollection) throws ServiceException {
+ if (!CollectionUtils.isEmpty(oidCollection)) {
+ return baseMapper.selectList(Wrappers.<BtmType>query().lambda().in(BtmType::getOid, oidCollection));
+ }
return null;
}
@@ -177,7 +231,7 @@
*/
@Override
public String getNameByOid(String oid) throws ServiceException {
- return null;
+ return Objects.requireNonNull(baseMapper.selectOne(Wrappers.<BtmType>query().lambda().eq(BtmType::getOid,oid))).getName();
}
/**
@@ -189,7 +243,7 @@
*/
@Override
public String getNameById(String id) throws ServiceException {
- return null;
+ return Objects.requireNonNull(baseMapper.selectOne(Wrappers.<BtmType>query().lambda().eq(BtmType::getId,id))).getName();
}
/**
@@ -213,6 +267,16 @@
*/
@Override
public List<BtmTypeAttributeVO> listHasAttributeById(String id) throws ServiceException {
+ VciBaseUtil.alertNotNull(id,"涓氬姟绫诲瀷鑻辨枃鍚嶇О");
+ List<String> ids = Func.toStrList(",", id);
+ Map<String, List<BtmTypeAttributeVO>> attributeMap = batchListHasAttributesByIdCollection(ids);
+ if (!CollectionUtils.isEmpty(attributeMap)) {
+ List<BtmTypeAttributeVO> attributeVOList = new ArrayList<>();
+ attributeMap.forEach((k, v) -> {
+ attributeVOList.addAll(v);
+ });
+ return attributeVOList;
+ }
return null;
}
@@ -225,7 +289,7 @@
*/
@Override
public Map<String, List<BtmTypeAttributeVO>> batchListHasAttributesByOidCollection(Collection<String> oidCollection) throws ServiceException {
- return null;
+ return btmTypeAttributeService.batchListHasAttributesByBtmTypeOidCollection(oidCollection).stream().collect(Collectors.groupingBy(BtmTypeAttributeVO::getPkBtmType));
}
/**
@@ -237,7 +301,8 @@
*/
@Override
public Map<String, List<BtmTypeAttributeVO>> batchListHasAttributesByIdCollection(Collection<String> idCollection) throws ServiceException {
- return null;
+ List<String> btmTypeOidList = baseMapper.selectList(Wrappers.<BtmType>query().lambda().in(BtmType::getId, idCollection)).stream().map(BtmType::getOid).collect(Collectors.toList());
+ return btmTypeAttributeService.batchListHasAttributesByBtmTypeOidCollection(btmTypeOidList).stream().collect(Collectors.groupingBy(BtmTypeAttributeVO::getPkBtmType));
}
/**
@@ -261,7 +326,8 @@
*/
@Override
public boolean checkBtmTypeUsed(String pkBtmType) throws ServiceException {
- return false;
+ VciBaseUtil.alertNotNull(pkBtmType, "涓氬姟绫诲瀷涓婚敭");
+ return checkBtmTypeUseds(VciBaseUtil.str2List(pkBtmType));
}
/**
@@ -273,113 +339,41 @@
*/
@Override
public boolean checkBtmTypeUseds(Collection<String> oidCollection) throws ServiceException {
+ VciBaseUtil.alertCollectionNotNull("鏍¢獙鏄惁寮曠敤鐨勪笟鍔$被鍨嬪璞$殑涓婚敭", oidCollection);
+ //妫�鏌ラ摼鎺ョ被鍨�
+ //鍥犱负閾炬帴绫诲瀷涓璮romBtmType鍜宼oBtmType閮芥槸閫楀彿鍒嗛殧鐨勶紝鎵�浠ョ洿鎺ユ煡璇㈡墍鏈夌殑閾炬帴绫诲瀷涓殑浣跨敤鐨勪笟鍔$被鍨嬪悕绉�
+ List<BtmType> btmTypeDOList = listBtmTypeDOByOidCollection(oidCollection);
+ if (CollectionUtils.isEmpty(btmTypeDOList)) {
+ return false;
+ }
+ /*Set<String> usedBtmTypeSet = linkTypeServiceI.listUsedBtmType();
+ if (btmTypeDOList.stream().anyMatch(s -> usedBtmTypeSet.contains(s.getId().trim().toLowerCase()))) {
+ return true;
+ }*/
return false;
}
/**
- * 娣诲姞涓氬姟绫诲瀷
- *
- * @param btmTypeDTO 涓氬姟绫诲瀷鏁版嵁浼犺緭瀵硅薄
- * @param autoCreateTable 鏄惁鑷姩鍒涘缓琛ㄦ牸
- * @return 娣诲姞鍚庣殑涓氬姟绫诲瀷
- * @throws ServiceException 娣诲姞鍑洪敊鐨勬椂鍊欎細鎶涘嚭寮傚父
+ * 娣诲姞榛樿鐨勫瓧娈�
+ * @param attributes 瀛楁闆�
+ * @param fieldMap 榛樿瀛楁闆�
+ * @return 娣诲姞鍚庣殑瀛楁闆�
*/
- @Override
- public BtmTypeDTO addSave(BtmTypeDTO btmTypeDTO, boolean autoCreateTable) throws ServiceException {
- TransactionStatus transaction = null;
- DefaultTransactionDefinition def = null;
- if (autoCreateTable) {
- def = new DefaultTransactionDefinition();
- def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
- // 浜嬬墿闅旂绾у埆锛屽紑鍚柊浜嬪姟锛岃繖鏍蜂細姣旇緝瀹夊叏浜涖��
- transaction = dataSourceTransactionManager.getTransaction(def);
- // 鑾峰緱浜嬪姟鐘舵��
- }
- BtmType btmTypeDO = new BtmType();
- try {
- VciBaseUtil.alertNotNull(btmTypeDTO, "瑕佹坊鍔犵殑涓氬姟绫诲瀷", btmTypeDTO.getId(), "涓氬姟绫诲瀷鐨勮嫳鏂囧悕绉�", btmTypeDTO.getName(), "涓氬姟绫诲瀷涓枃鍚嶇О");
- if (btmTypeDTO.isViewFlag() && (StringUtils.isBlank(btmTypeDTO.getViewCreateSql())
- || StringUtils.isBlank(btmTypeDTO.getTableName()))) {
- throw new VciBaseException("濡傛灉褰撳墠鏄笟鍔$被鍨嬫槸瑙嗗浘鐨勬椂鍊欙紝璇峰繀椤昏緭鍏ヨ鍥剧殑鍒涘缓璇彞鍜岃鍥惧悕绉�");
+ private List<BtmTypeLinkAttributesDTO> addAttributeByFieldMap(List<BtmTypeLinkAttributesDTO> attributes, Map<String, String> fieldMap) {
+ Map<String, BtmTypeLinkAttributesDTO> existFieldMap = attributes.stream().collect(Collectors.toMap(BtmTypeLinkAttributesDTO::getId, t -> t, (o1, o2) -> o1));
+ fieldMap.forEach((k,v) -> {
+ 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);
+ attr.setDescription(v);
+ attributes.add(attr);
}
- if (!btmTypeDTO.isViewFlag()) {
- VciBaseUtil.alertCollectionNotNull("灞炴��", btmTypeDTO.getAttributesDTOList());
- }
- if (!btmTypeDTO.getId().matches(OmdRegExpConstant.LETTER)) {
- throw new VciBaseException("涓氬姟绫诲瀷鑻辨枃鍚嶇О鍙兘鏄函鑻辨枃锛岀洰鍓嶄负{0}", new Object[]{btmTypeDTO.getId()});
- }
- if (btmTypeDTO.getId().length() > 24) {
- throw new VciBaseException("涓氬姟绫诲瀷鑻辨枃鍚嶇О涓嶈兘瓒呰繃18锛岀洰鍓嶉暱搴︿负{0}", new Object[]{btmTypeDTO.getId().length()});
- }
- List<BtmType> btmTypeDOList = listBtmTypeDOByIdCollection(VciBaseUtil.str2List(btmTypeDTO.getId()));
- if (!CollectionUtils.isEmpty(btmTypeDOList) && btmTypeDOList.size() > 0) {
- BtmType existBtmType = btmTypeDOList.get(0);
- throw new VciBaseException("涓氬姟绫诲瀷鑻辨枃鍚嶇О宸茬粡瀛樺湪锛堜笉鍖哄垎澶у皬鍐欙級锛岃繖涓嫳鏂囧悕绉板搴旂殑涓枃鍚嶇О涓簕0},鍒涘缓浜簕1},鍒涘缓鏃堕棿{2}"
- , new Object[]{existBtmType.getName(), existBtmType.getCreator(), VciDateUtil.date2Str(existBtmType.getCreateTime(), VciDateUtil.DateFormat)});
- }
- /*
- //妫�鏌ヤ娇鐢ㄧ殑鐗堟湰瑙勫垯鏄惁瀛樺湪
- 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.getLifeCycleId())
- && !FrameWorkLcStatusConstant.EMTYPE_LIFE_CYCLE.equalsIgnoreCase(btmTypeDTO.getLifeCycleId())) {
- if (lifeCycleServiceI.checkLifeCycleExist(btmTypeDTO.getLifeCycleId())) {
- throw new VciBaseException("鐢熷懡鍛ㄦ湡{0}[{1}]鍦ㄧ郴缁熶腑涓嶅瓨鍦紝璇峰厛鏌ヨ瘉",
- new Object[]{btmTypeDTO.getLifeCycleId(), btmTypeDTO.getLifeCycleName()});
- }
- }
- if (StringUtils.isNotBlank(btmTypeDTO.getSubLifeCycleId())) {
- if (lifeCycleServiceI.checkLifeCycleExist(btmTypeDTO.getSubLifeCycleId())) {
- throw new VciBaseException("澶囩敤鐢熷懡鍛ㄦ湡{0}[{1}]涓叾涓湁鏌愪簺鍦ㄧ郴缁熶腑涓嶅瓨鍦紝璇峰厛鏌ヨ瘉",
- new Object[]{btmTypeDTO.getSubLifeCycleId(), btmTypeDTO.getSubLifeCycleName()});
- }
- }
- */
- if (StringUtils.isBlank(btmTypeDTO.getOid())) {
- btmTypeDTO.setOid(VciBaseUtil.getPk());
- }
-
- BeanUtil.copy(btmTypeDTO, btmTypeDO);
- String creator = AuthUtil.getUserAccount();
- Date now = new Date();
- btmTypeDO.setCreator(creator);
- btmTypeDO.setCreateTime(now);
- btmTypeDO.setOwner(creator);
- btmTypeDO.setBtmname(BtmTypeConstant.OMD_BTMTYPE);
- btmTypeDO.setTs(now);
- if (StringUtils.isBlank(btmTypeDO.getTableName())) {
- btmTypeDO.setTableName(getTableName(btmTypeDO.getId()));
- }
-
- //澶勭悊灞炴��
- addAttributeForBtm(btmTypeDTO, creator, now);
-
- baseMapper.insert(btmTypeDO);
- if (autoCreateTable) {
- dataSourceTransactionManager.commit(transaction);
- }
- } catch (ServiceException e) {
- if (autoCreateTable) {
- dataSourceTransactionManager.rollback(transaction);
- }
- throw e;
- } catch (Throwable e) {
- if (autoCreateTable) {
- dataSourceTransactionManager.rollback(transaction);
- }
- throw e;
- }
- if (autoCreateTable) {
- BtmTypeVO btmTypeVO = BtmTypeWrapper.build().entityVO(btmTypeDO);
- btmTypeVO.setAttributes(listHasAttributesByOid(btmTypeDO.getOid()));
- checkTableSame(btmTypeVO);
- }
- return btmTypeDTO;
+ });
+ return attributes;
}
/**
@@ -388,43 +382,44 @@
* @param btmTypeVO 涓氬姟绫诲瀷鐨勬樉绀哄璞�
*/
private void checkTableSame(BtmTypeVO btmTypeVO) {
- /*List<OmdBtmTypeVO> btmTypeVOList = new ArrayList<>();
+ List<BtmTypeVO> btmTypeVOList = new ArrayList<>();
btmTypeVOList.add(btmTypeVO);
- List<OsModifyAttributeInfoDO> modifyAttributeInfoDOList = ddlServiceI.checkDifferent(btmTypeVOList, null);
+ BtmAndLinkTypeDdlDTO ddlDTO = new BtmAndLinkTypeDdlDTO();
+ ddlDTO.setBtmTypeList(btmTypeVOList);
try {
- modifyAttributeServiceI.batchAddSave(modifyAttributeInfoDOList);
- } catch (Throwable e) {
- if (logger.isErrorEnabled()) {
- logger.error("淇濆瓨銆愪慨鏀瑰睘鎬с�戞暟鎹�", e);
+ // 灏嗕互鍓嶇殑checkDifferent鍜宺eflexDifferent缁撳悎浜�
+ R result = DomainRepeater.checkDifferent(ddlDTO,btmTypeVO.getBizDomain());
+ if (result.isSuccess()){
+ List<ModifyAttributeInfo> infoList = new ArrayList<>();
+ Object data = result.getData();
+ if (data instanceof List){
+ List dataList = (List) data;
+ dataList.forEach(s -> {
+ if (s instanceof ModifyAttributeInfo){
+ ModifyAttributeInfo info = (ModifyAttributeInfo) s;
+ infoList.add(info);
+ }
+ });
+ modifyAttributeService.saveBatch(ModifyAttributeWrapper.build().listEntityBeforeSave(infoList));
+ }
}
+ } catch (NacosException e) {
+ if (log.isDebugEnabled()) {
+ log.error("淇濆瓨銆愪慨鏀瑰睘鎬с�戞暟鎹�", e);
+ }
+ throw new RuntimeException(e);
}
- ddlServiceI.reflexDifferent(modifyAttributeInfoDOList);
- modifyAttributeServiceI.finishModify(modifyAttributeInfoDOList);*/
+// modifyAttributeServiceI.finishModify(modifyAttributeInfoList);
}
/**
* 娣诲姞灞炴�у埌涓氬姟绫诲瀷涓�
*
* @param btmTypeDTO 涓氬姟绫诲瀷鐨勬暟鎹紶杈撳璞�
- * @param creator 鍒涘缓浜�
- * @param now 褰撳墠鏃堕棿
*/
- private void addAttributeForBtm(BtmTypeDTO btmTypeDTO, String creator, Date now) throws VciBaseException{
- List<BtmTypeLinkAttributesDTO> attributesDTOList = btmTypeDTO.getAttributesDTOList();
- btmTypeAttributeService.checkAndInsert(btmTypeDTO.getOid(),attributesDTOList,creator,now);
- }
-
- /**
- * 淇敼涓氬姟绫诲瀷
- *
- * @param btmTypeDTO 涓氬姟绫诲瀷鏁版嵁浼犺緭瀵硅薄
- * @param autoEditTable 鏄惁鑷姩鏇存柊琛ㄦ牸
- * @return 淇敼鍚庣殑涓氬姟绫诲瀷
- * @throws ServiceException 淇敼鍑洪敊鐨勬椂鍊欎細鎶涘嚭寮傚父
- */
- @Override
- public BtmTypeDTO editSave(BtmTypeDTO btmTypeDTO, boolean autoEditTable) throws ServiceException {
- return null;
+ private List<BtmTypeAttributeVO> addAttributeForBtm(BtmTypeDTO btmTypeDTO) throws VciBaseException{
+ List<BtmTypeLinkAttributesDTO> attributesDTOList = btmTypeDTO.getAttributes();
+ return btmTypeAttributeService.checkAndInsert(btmTypeDTO.getOid(),attributesDTOList,AuthUtil.getUserAccount(),new Date());
}
/**
@@ -459,7 +454,7 @@
* @throws ServiceException 鍙傛暟涓虹┖鎴栬�呮煡璇㈠嚭閿欐椂浼氭姏鍑哄紓甯�
*/
@Override
- public List<ModifyAttributeInfoDO> checkDbTableSame(String pkBtmType) throws ServiceException {
+ public List<ModifyAttributeInfo> checkDbTableSame(String pkBtmType) throws ServiceException {
return null;
}
@@ -471,102 +466,14 @@
* @throws ServiceException 鍙傛暟涓虹┖鐨勬椂鍊欎細鎶涘嚭寮傚父
*/
@Override
- public String getTableName(String id) throws ServiceException {
- return null;
- }
-
- /**
- * 灏嗕笟鍔$被鍨嬩娇鐢ㄧ殑灞炴�х殑浼犺緭瀵硅薄杞崲涓烘暟鎹璞�
- *
- * @param attributesDTO 灞炴�х殑鏁版嵁浼犺緭瀵硅薄
- * @param pkBtmType 涓氬姟绫诲瀷鐨勪富閿�
- * @param creator 鍒涘缓浜�
- * @param now 褰撳墠鏃堕棿
- * @return 灞炴�х殑鏁版嵁瀵硅薄
- */
- @Override
- public BtmTypeAttribute btmTypeAttributeDTO2DO(BtmTypeLinkAttributesDTO attributesDTO, String pkBtmType, String creator, Date now) {
- return null;
- }
-
- /**
- * 涓氬姟绫诲瀷鐨勫睘鎬ф樉绀哄璞¤浆鎹负鏁版嵁瀵硅薄
- *
- * @param thisBtmTypeHasAttributeVOList 涓氬姟绫诲瀷灞炴�ф樉绀哄璞�
- * @return 鏁版嵁瀵硅薄
- */
- @Override
- public List<BtmTypeAttribute> btmTypeAttributeVO2DO(List<BtmTypeAttributeVO> thisBtmTypeHasAttributeVOList) {
- return null;
- }
-
- /**
- * 鎵归噺灏嗕笟鍔$被鍨嬬殑鏁版嵁瀵硅薄杞崲涓烘樉绀哄璞�
- *
- * @param attributeDOList 灞炴�х殑鏁版嵁瀵硅薄鍒楄〃
- * @return 灞炴�х殑鏄剧ず瀵硅薄鍒楄〃
- */
- @Override
- public List<BtmTypeAttributeVO> batchBtmTypeAttributeDO2VO(List<BtmTypeAttribute> attributeDOList) {
- return null;
- }
-
- /**
- * 鎵归噺灏嗕笟鍔$被鍨嬬殑鏁版嵁瀵硅薄杞崲涓烘樉绀哄璞�
- *
- * @param attributesDO 灞炴�х殑鏁版嵁瀵硅薄
- * @return 灞炴�х殑鏄剧ず瀵硅薄鍒楄〃
- */
- @Override
- public BtmTypeAttributeVO btmTypeAttributeDO2VO(BtmTypeAttribute attributesDO) {
- return null;
- }
-
- /**
- * 鑾峰彇涓氬姟绫诲瀷鐨勬寚瀹氬睘鎬�
- *
- * @param id 閾炬帴绫诲瀷鐨勮嫳鏂囧悕绉�
- * @param attributeIdCollection 灞炴�х殑闆嗗悎锛屽鏋滀负绌哄垯鑾峰彇鍏ㄩ儴
- * @return 灞炴�х殑鏄剧ず瀵硅薄
- */
- @Override
- public List<BtmTypeAttribute> listAttributeDOByIdsForBtm(String id, Collection<String> attributeIdCollection) {
- return null;
- }
-
- /**
- * 鏍规嵁涓氬姟绫诲瀷鐨勭紪鍙疯幏鍙栧睘鎬�
- *
- * @param id 涓氬姟绫诲瀷鐨勭紪鍙�
- * @return 灞炴�х殑鏄剧ず瀵硅薄
- */
- @Override
- public List<BtmTypeAttributeVO> listAttributeByBtmTypeId(String id) {
- return null;
- }
-
- /**
- * 鏍规嵁涓氬姟绫诲瀷鐨勪富閿幏鍙栧睘鎬�
- *
- * @param oid 涓氬姟绫诲瀷鐨勪富閿�
- * @return 灞炴�х殑鏄剧ず瀵硅薄
- */
- @Override
- public List<BtmTypeAttributeVO> listAttributeByBtmTypeOid(String oid) {
- return null;
- }
-
- /**
- * 鎵归噺鏍规嵁涓氬姟绫诲瀷缂栧彿鎴栬�呬富閿幏鍙栧寘鍚殑灞炴��
- *
- * @param oidsOrIds 涓婚敭鎴栬�呯紪鍙烽泦鍚�
- * @param queryById 鏄惁浣跨敤缂栧彿鏌ヨ
- * @return key鏄笟鍔$被鍨嬬殑涓婚敭鎴栬�呯紪鍙凤紝鍊兼槸鍖呭惈鐨勫睘鎬х殑淇℃伅
- * @throws ServiceException 鍙傛暟涓虹┖鎴栬�呮煡璇㈠嚭閿欎細鎶涘嚭寮傚父
- */
- @Override
- public List<BtmTypeAttributeVO> batchListAttributeByBtmType(Collection<String> oidsOrIds, boolean queryById) throws ServiceException {
- return null;
+ public String getTableName(String id,String domain) throws ServiceException {
+ VciBaseUtil.alertNotNull(id,"涓氬姟绫诲瀷鑻辨枃鍚嶇О",domain,"棰嗗煙鍚嶇О");
+ if (domain.contains("ubcs-")){
+ domain = domain.split("ubcs-")[1];
+ }else {
+ throw new VciBaseException("棰嗗煙鍚嶇О涓嶇鍚堣鍒�");
+ }
+ return PL + StringPool.UNDERSCORE + domain + StringPool.UNDERSCORE + id;
}
/**
@@ -576,16 +483,155 @@
* @return 鎵ц缁撴灉
*/
@Override
- public boolean submit(BtmTypeDTO btmTypeDTO) {
- addSave(btmTypeDTO,false);
- try {
- R result = DomainRepeater.submitBtmType(btmTypeDTO.getDomain(), Objects.requireNonNull(BeanUtil.copy(btmTypeDTO, BtmTypeVO.class)));
- return result.isSuccess();
- } catch (NacosException e) {
- throw new RuntimeException(e);
+ public R submit(BtmTypeDTO btmTypeDTO, boolean autoCreateTable) {
+ TransactionStatus transaction = null;
+ DefaultTransactionDefinition def = null;
+ if (autoCreateTable) {
+ def = new DefaultTransactionDefinition();
+ def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
+ // 浜嬬墿闅旂绾у埆锛屽紑鍚柊浜嬪姟锛岃繖鏍蜂細姣旇緝瀹夊叏浜涖��
+ transaction = dataSourceTransactionManager.getTransaction(def);
+ // 鑾峰緱浜嬪姟鐘舵��
}
+ 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.getBizDomain()));
+ }
+ // 娣诲姞灞炴��
+ btmTypeDTO.setOid(btmTypeDO.getOid());
+ afterAttributes = addAttributeForBtm(btmTypeDTO);
+ baseMapper.insert(btmTypeDO);
+ }else {
+ BtmTypeVO btmTypeByOid = getBtmTypeByOid(btmTypeDO.getOid());
+ List<BtmTypeAttributeVO> beforeAttributes = btmTypeByOid.getAttributes();
+ // 澶勭悊灞炴�э紝澶氫綑鐨勫垹闄わ紝涓嶅瓨鍦ㄧ殑娣诲姞
+ 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);
+ R result = DomainRepeater.submitBtmType(btmTypeDTO.getDomain(), btmTypeVO);
+ if (result.isSuccess()){
+ List<ModifyAttributeInfo> infoList = new ArrayList<>();
+ Object data = result.getData();
+ if (data instanceof List){
+ List dataList = (List) data;
+ dataList.forEach(s -> {
+ if (s instanceof ModifyAttributeInfo){
+ ModifyAttributeInfo info = (ModifyAttributeInfo) s;
+ infoList.add(info);
+ }
+ });
+ modifyAttributeService.saveBatch(ModifyAttributeWrapper.build().listEntityBeforeSave(infoList));
+ }
+ 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);
}
+ /**
+ * 鏇存柊涓氬姟绫诲瀷鐨勫睘鎬�
+ * @param oid 閫愭笎
+ * @param beforeAttr 鏇存柊鍓嶇殑灞炴��
+ * @param afterAttr 鏇存柊鍚庣殑灞炴��
+ */
+ private List<BtmTypeAttributeVO> updateAttributeForBtm(String oid, List<BtmTypeAttributeVO> beforeAttr, List<BtmTypeLinkAttributesDTO> afterAttr) {
+ List<BtmTypeAttributeVO> deleteList = beforeAttr.stream().filter(before -> afterAttr.stream().noneMatch(after -> StringUtils.equals(before.getId(), after.getId()))).collect(Collectors.toList());
+ List<BtmTypeLinkAttributesDTO> addList = afterAttr.stream().filter(after -> beforeAttr.stream().noneMatch(before -> StringUtils.equals(before.getId(), after.getId()))).collect(Collectors.toList());
+ List<BtmTypeLinkAttributesDTO> modifyList = new ArrayList<>();
+ Map<String, BtmTypeAttributeVO> beforeAttrMap = beforeAttr.stream().collect(Collectors.toMap(BtmTypeAttributeVO::getId, t -> t, (o1, o2) -> o1));
+ Map<String, BtmTypeLinkAttributesDTO> afterAttrMap = afterAttr.stream().collect(Collectors.toMap(BtmTypeLinkAttributesDTO::getId, t -> t, (o1, o2) -> o1));
+ afterAttrMap.forEach((k,v) -> {
+ if (beforeAttrMap.containsKey(k)){
+ modifyList.add(v);
+ }
+ });
+ btmTypeAttributeService.checkAndRemove(deleteList.stream().map(BtmTypeAttributeVO::getOid).collect(Collectors.toList()));
+ List<BtmTypeAttributeVO> voListAdd = btmTypeAttributeService.checkAndInsert(oid, addList, AuthUtil.getUserAccount(), new Date());
+ List<BtmTypeAttributeVO> voListUpdate = btmTypeAttributeService.checkAndUpdate(oid, modifyList, AuthUtil.getUserAccount(), new Date());
+ List<BtmTypeAttributeVO> returnList = new ArrayList<>();
+ returnList.addAll(Objects.requireNonNull(voListAdd));
+ returnList.addAll(Objects.requireNonNull(voListUpdate));
+ return returnList;
+ }
+
+ /**
+ * 妫�鏌ヤ笟鍔$被鍨嬬鍚堣鑼�
+ * @param btmTypeDTO 涓氬姟绫诲瀷椤甸潰浼犺緭瀵硅薄
+ */
+ private void checkBtmTypeBeforeSave(BtmTypeDTO btmTypeDTO) {
+ VciBaseUtil.alertNotNull(btmTypeDTO, "瑕佹坊鍔犵殑涓氬姟绫诲瀷", btmTypeDTO.getId(), "涓氬姟绫诲瀷鐨勮嫳鏂囧悕绉�", btmTypeDTO.getName(), "涓氬姟绫诲瀷涓枃鍚嶇О");
+ if (btmTypeDTO.isViewFlag() && (StringUtils.isBlank(btmTypeDTO.getViewCreateSql())
+ || StringUtils.isBlank(btmTypeDTO.getTableName()))) {
+ throw new VciBaseException("濡傛灉褰撳墠鏄笟鍔$被鍨嬫槸瑙嗗浘鐨勬椂鍊欙紝璇峰繀椤昏緭鍏ヨ鍥剧殑鍒涘缓璇彞鍜岃鍥惧悕绉�");
+ }
+ if (!btmTypeDTO.isViewFlag()) {
+ VciBaseUtil.alertCollectionNotNull("灞炴��", btmTypeDTO.getAttributes());
+ }
+ if (!btmTypeDTO.getId().matches(OmdRegExpConstant.LETTER)) {
+ throw new VciBaseException("涓氬姟绫诲瀷鑻辨枃鍚嶇О鍙兘鏄函鑻辨枃锛岀洰鍓嶄负{0}", new Object[]{btmTypeDTO.getId()});
+ }
+ if (btmTypeDTO.getId().length() > 24) {
+ throw new VciBaseException("涓氬姟绫诲瀷鑻辨枃鍚嶇О涓嶈兘瓒呰繃18锛岀洰鍓嶉暱搴︿负{0}", new Object[]{btmTypeDTO.getId().length()});
+ }
+ List<BtmType> btmTypeDOList = listBtmTypeDOByIdCollection(VciBaseUtil.str2List(btmTypeDTO.getId()));
+ if (!CollectionUtils.isEmpty(btmTypeDOList) && btmTypeDOList.size() > 0) {
+ BtmType existBtmType = btmTypeDOList.get(0);
+ throw new VciBaseException("涓氬姟绫诲瀷鑻辨枃鍚嶇О宸茬粡瀛樺湪锛堜笉鍖哄垎澶у皬鍐欙級锛岃繖涓嫳鏂囧悕绉板搴旂殑涓枃鍚嶇О涓簕0},鍒涘缓浜簕1},鍒涘缓鏃堕棿{2}"
+ , new Object[]{existBtmType.getName(), existBtmType.getCreator(), VciDateUtil.date2Str(existBtmType.getCreateTime(), VciDateUtil.DateFormat)});
+ }
+ if (btmTypeDTO.isRevisionFlag()){
+ // 闇�瑕佹帶鍒剁増鏈�
+ // 妫�鏌ヤ娇鐢ㄧ殑鐗堟湰瑙勫垯鏄惁瀛樺湪
+ if (StringUtils.isNotBlank(btmTypeDTO.getRevisionRuleId())) {
+ if (!revisionRuleService.checkRevisionRuleExist(btmTypeDTO.getRevisionRuleId())) {
+ throw new VciBaseException("鐗堟湰瑙勫垯{0}[{1}]鍦ㄧ郴缁熶腑涓嶅瓨鍦紝璇峰厛鏌ヨ瘉",
+ new Object[]{btmTypeDTO.getRevisionRuleId(), btmTypeDTO.getRevisionRuleName()});
+ }
+ }
+ }
+ if (btmTypeDTO.isLifeCycleFlag()){
+ // 闇�瑕佹帶鍒剁敓鍛藉懆鏈�
+ //妫�鏌ヤ娇鐢ㄧ殑鐢熷懡鍛ㄦ湡鏄惁瀛樺湪
+// if (StringUtils.isNotBlank(btmTypeDTO.getLifeCycleId())
+// && !FrameWorkLcStatusConstant.EMTYPE_LIFE_CYCLE.equalsIgnoreCase(btmTypeDTO.getLifeCycleId())) {
+// if (lifeCycleServiceI.checkLifeCycleExist(btmTypeDTO.getLifeCycleId())) {
+// throw new VciBaseException("鐢熷懡鍛ㄦ湡{0}[{1}]鍦ㄧ郴缁熶腑涓嶅瓨鍦紝璇峰厛鏌ヨ瘉",
+// new Object[]{btmTypeDTO.getLifeCycleId(), btmTypeDTO.getLifeCycleName()});
+// }
+// }
+// if (StringUtils.isNotBlank(btmTypeDTO.getSubLifeCycleId())) {
+// if (lifeCycleServiceI.checkLifeCycleExist(btmTypeDTO.getSubLifeCycleId())) {
+// throw new VciBaseException("澶囩敤鐢熷懡鍛ㄦ湡{0}[{1}]涓叾涓湁鏌愪簺鍦ㄧ郴缁熶腑涓嶅瓨鍦紝璇峰厛鏌ヨ瘉",
+// new Object[]{btmTypeDTO.getSubLifeCycleId(), btmTypeDTO.getSubLifeCycleName()});
+// }
+// }
+ }
+ if (btmTypeDTO.isSecretFlag()){
+ // 闇�瑕佹帶鍒跺瘑绾�
+ }
+ }
@Override
public boolean deleteLogic(@NotEmpty List<Long> ids) {
return false;
@@ -595,4 +641,312 @@
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;
+ }
+
+ /**
+ * 鑾峰彇寮曠敤鏌愪釜鐢熷懡鍛ㄦ湡鐨勪笟鍔$被鍨�
+ *
+ * @param lifeId 鐢熷懡鍛ㄦ湡鐨勭紪鍙�
+ * @return 涓氬姟绫诲瀷鏄剧ず瀵硅薄
+ */
+ @Override
+ public List<BtmTypeVO> selectByLifeId(String lifeId) {
+ if(StringUtils.isBlank(lifeId)){
+ return new ArrayList<>();
+ }
+ LambdaQueryWrapper<BtmType> query = new LambdaQueryWrapper<BtmType>();
+ query.eq(BtmType::getLifeCycleId,lifeId);
+ return BtmTypeWrapper.build().listEntityVO(getBaseMapper().selectList(query));
+ }
+
+ /**
+ * 鑾峰彇寮曠敤鏌愪簺鐢熷懡鍛ㄦ湡鐨勪笟鍔$被鍨�
+ *
+ * @param lifeIds 鐢熷懡鍛ㄦ湡鐨勭紪鍙烽泦鍚�
+ * @return 涓氬姟绫诲瀷鏄剧ず瀵硅薄
+ */
+ @Override
+ public List<BtmTypeVO> selectByLifeIds(Collection<String> lifeIds) {
+ if(CollectionUtils.isEmpty(lifeIds)){
+ return new ArrayList<>();
+ }
+ List<BtmType> btmTypeList = new ArrayList<>();
+ VciBaseUtil.switchCollectionForOracleIn(lifeIds).stream().forEach(ids->{
+ LambdaQueryWrapper<BtmType> query = new LambdaQueryWrapper<BtmType>();
+ ids.stream().forEach(id->{
+ query.eq(BtmType::getLifeCycleId,id);
+ query.or();
+ });
+ query.eq(BtmType::getLifeCycleId,"-1");
+ btmTypeList.addAll(baseMapper.selectList(query));
+ });
+ return BtmTypeWrapper.build().listEntityVO(btmTypeList);
+ }
+
+ /**
+ * 缁熻寮曠敤鏌愪釜鐢熷懡鍛ㄦ湡鐨勪笟鍔$被鍨�
+ *
+ * @param lifeId 鐢熷懡鍛ㄦ湡鐨勭紪鍙�
+ * @return 涓暟
+ */
+ @Override
+ public Integer countByLifeId(String lifeId) {
+ if(StringUtils.isBlank(lifeId)){
+ return 0;
+ }
+ LambdaQueryWrapper<BtmType> query = new LambdaQueryWrapper<BtmType>();
+ query.eq(BtmType::getLifeCycleId,lifeId);
+ return baseMapper.selectCount(query).intValue();
+ }
+
+ /**
+ * 缁熻寮曠敤鏌愪簺鐢熷懡鍛ㄦ湡鐨勪笟鍔$被鍨�
+ *
+ * @param lifeIds 鐢熷懡鍛ㄦ湡鐨勭紪鍙烽泦鍚�
+ * @return 涓暟
+ */
+ @Override
+ public Integer countByLifeIds(Collection<String> lifeIds) {
+ if(CollectionUtils.isEmpty(lifeIds)){
+ return 0;
+ }
+ final Integer[] total = {0};
+ VciBaseUtil.switchCollectionForOracleIn(lifeIds).stream().forEach(ids->{
+ LambdaQueryWrapper<BtmType> query = new LambdaQueryWrapper<BtmType>();
+ ids.stream().forEach(id->{
+ query.eq(BtmType::getLifeCycleId,id);
+ query.or();
+ });
+ query.eq(BtmType::getLifeCycleId,"-1");
+ total[0] += baseMapper.selectCount(query).intValue();
+ });
+ return total[0];
+ }
}
--
Gitblit v1.9.3