From d2570148ec3884de3af721bd99c4b7acbbdee075 Mon Sep 17 00:00:00 2001 From: 田源 <lastanimals@163.com> Date: 星期二, 09 五月 2023 17:07:26 +0800 Subject: [PATCH] 前端代码提交 --- Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/BtmTypeServiceImpl.java | 624 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 624 insertions(+), 0 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 new file mode 100644 index 0000000..994199f --- /dev/null +++ b/Source/UBCS/ubcs-service/ubcs-omd/src/main/java/com/vci/ubcs/omd/service/impl/BtmTypeServiceImpl.java @@ -0,0 +1,624 @@ +package com.vci.ubcs.omd.service.impl; + +import com.alibaba.cloud.commons.lang.StringUtils; +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.BtmTypeFieldConstant; +import com.vci.ubcs.omd.dto.BtmAndLinkTypeDdlDTO; +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.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.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.VciFieldTypeEnum; +import com.vci.ubcs.starter.web.util.VciBaseUtil; +import com.vci.ubcs.starter.web.util.VciDateUtil; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.secure.utils.AuthUtil; +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.support.DefaultTransactionDefinition; +import org.springframework.util.CollectionUtils; + +import javax.validation.constraints.NotEmpty; +import java.util.*; +import java.util.stream.Collectors; + +/** + * Description: 涓氬姟绫诲瀷鏈嶅姟鐨勫疄鐜扮被 + * + * @author LiHang + * @date 2023/4/23 + */ +@Service +public class BtmTypeServiceImpl extends ServiceImpl<BtmTypeMapper, BtmType> implements IBtmTypeService { + + /** + * 浜嬪姟绠$悊 + */ + @Autowired + private DataSourceTransactionManager dataSourceTransactionManager; + + /** + * 涓氬姟绫诲瀷鍏宠仈灞炴�ф湇鍔� + */ + @Autowired + private IBtmTypeAttributeService btmTypeAttributeService; + + /** + * 瀛楁淇敼淇℃伅鐨勬湇鍔� + */ + @Autowired + private IModifyAttributeService modifyAttributeService; + + /** + * 琛ㄥ悕鍓嶇紑 + */ + public static final String PL = "PL"; + + /** + * 璁剧疆骞冲彴鏈韩鐨勪笟鍔$被鍨� + * + * @param platformBtmType 骞冲彴鏈韩鐨勪笟鍔$被鍨� + */ + @Override + public void setPlatformBtmType(Collection<String> platformBtmType) { + + } + + /** + * 鏍规嵁涓婚敭鑾峰彇涓氬姟绫诲瀷 + * + * @param pkBtmType 涓氬姟绫诲瀷涓婚敭 + * @return 涓氬姟绫诲瀷锛屽鏋滀笉瀛樺湪浼氳繑鍥瀗ull + * @throws ServiceException 鍙傛暟涓虹┖鎴栬�呮煡璇㈠嚭閿欐椂浼氭姏鍑洪敊璇� + */ + @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))); + btmTypeVO.setAttributes(btmTypeAttributeService.getAttributeByBtmTypeOid(pkBtmType)); + return btmTypeVO; + } + + /** + * 鏍规嵁涓婚敭鎵归噺鑾峰彇涓氬姟绫诲瀷 + * + * @param pkBtmTypes 涓氬姟绫诲瀷涓婚敭锛岀敤閫楀彿鍒嗛殧 + * @return 涓氬姟绫诲瀷鍒楄〃锛屽鏋滄湁涓嶅瓨鍦ㄧ殑涓嶄細杩斿洖锛屽叏閮ㄤ笉瀛樺湪鐨勫垯杩斿洖绌哄垪琛� + * @throws ServiceException 鍙傛暟涓虹┖鎴栬�呮煡璇㈠嚭閿欐椂浼氭姏鍑洪敊璇� + */ + @Override + public List<BtmTypeVO> listBtmTypeByOids(String pkBtmTypes) throws ServiceException { + VciBaseUtil.alertNotNull(pkBtmTypes, "涓氬姟绫诲瀷鐨勪富閿�"); + List<String> pkList = new ArrayList<>(); + Collections.addAll(pkList, pkBtmTypes.split(",")); + return listBtmTypeByOidCollection(pkList); + } + + /** + * 鎵归噺鏍规嵁涓婚敭鑾峰彇涓氬姟绫诲瀷 + * + * @param pkBtmTypeCollection 涓氬姟绫诲瀷涓婚敭闆嗗悎 + * @return 涓氬姟绫诲瀷鍒楄〃锛屽鏋滄湁涓嶅瓨鍦ㄧ殑涓嶄細杩斿洖锛屽叏閮ㄤ笉瀛樺湪鐨勫垯杩斿洖绌哄垪琛� + * @throws ServiceException 鍙傛暟涓虹┖鎴栬�呮煡璇㈠嚭閿欐椂浼氭姏鍑洪敊璇� + */ + @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; + } + + /** + * 鏍规嵁鑻辨枃鍚嶇О鑾峰彇涓氬姟绫诲瀷 + * + * @param id 鑻辨枃鍚嶇О + * @return 涓氬姟绫诲瀷锛屽鏋滀笉瀛樺湪浼氳繑鍥瀗ull + * @throws ServiceException 鍙傛暟涓虹┖鎴栬�呮煡璇㈠嚭閿欐椂浼氭姏鍑洪敊璇� + */ + @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; + } + + /** + * 鏍规嵁鑻辨枃鍚嶇О鎵归噺鑾峰彇涓氬姟绫诲瀷 + * + * @param ids 鑻辨枃鍚嶇О锛屼娇鐢ㄩ�楀彿鍒嗛殧 + * @return 涓氬姟绫诲瀷鍒楄〃锛屽鏋滄湁涓嶅瓨鍦ㄧ殑涓嶄細杩斿洖锛屽叏閮ㄤ笉瀛樺湪鐨勫垯杩斿洖绌哄垪琛� + * @throws ServiceException 鍙傛暟涓虹┖鎴栬�呮煡璇㈠嚭閿欐椂浼氭姏鍑洪敊璇� + */ + @Override + public List<BtmTypeVO> listBtmTypeByIds(String ids) throws ServiceException { + Func.requireNotNull(ids,"鑻辨枃鍚嶇О涓嶈兘涓虹┖"); + return listBtmTypeByIdCollection(Func.toStrList(",",ids)); + } + + /** + * 鏍规嵁鑻辨枃鍚嶇О闆嗗悎鎵归噺鑾峰彇涓氬姟绫诲瀷 + * + * @param idCollection 鑻辨枃鍚嶇О闆嗗悎 + * @return 涓氬姟绫诲瀷鍒楄〃锛屽鏋滄湁涓嶅瓨鍦ㄧ殑涓嶄細杩斿洖锛屽叏閮ㄤ笉瀛樺湪鐨勫垯杩斿洖绌哄垪琛� + * @throws ServiceException 鍙傛暟涓虹┖鎴栬�呮煡璇㈠嚭閿欐椂浼氭姏鍑洪敊璇� + */ + @Override + public List<BtmTypeVO> listBtmTypeByIdCollection(Collection<String> idCollection) throws ServiceException { + return CollectionUtils.isEmpty(idCollection) ? null : BtmTypeWrapper.build().listEntityVO(baseMapper.selectList(Wrappers.<BtmType>query().lambda().in(BtmType::getId,idCollection))); + } + + /** + * 鏍规嵁鑻辨枃鍚嶇О闆嗗悎鎵归噺鑾峰彇涓氬姟绫诲瀷鐨勬暟鎹璞� + * + * @param idCollection 鑻辨枃鍚嶇О闆嗗悎 + * @return 涓氬姟绫诲瀷鍒楄〃锛屽鏋滄湁涓嶅瓨鍦ㄧ殑涓嶄細杩斿洖锛屽叏閮ㄤ笉瀛樺湪鐨勫垯杩斿洖绌哄垪琛� + * @throws ServiceException 鍙傛暟涓虹┖鎴栬�呮煡璇㈠嚭閿欐椂浼氭姏鍑洪敊璇� + */ + @Override + public List<BtmType> listBtmTypeDOByIdCollection(Collection<String> idCollection) throws ServiceException { + return CollectionUtils.isEmpty(idCollection) ? null : baseMapper.selectList(Wrappers.<BtmType>query().lambda().in(BtmType::getId, idCollection)); + } + + /** + * 鏍规嵁涓婚敭闆嗗悎鎵归噺鑾峰彇涓氬姟绫诲瀷鐨勬暟鎹璞� + * + * @param oidCollection 涓婚敭 + * @return 涓氬姟绫诲瀷鍒楄〃锛屽鏋滄湁涓嶅瓨鍦ㄧ殑涓嶄細杩斿洖锛屽叏閮ㄤ笉瀛樺湪鐨勫垯杩斿洖绌哄垪琛� + * @throws ServiceException 鍙傛暟涓虹┖鎴栬�呮煡璇㈠嚭閿欐椂浼氭姏鍑洪敊璇� + */ + @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; + } + + /** + * 鏍规嵁涓氬姟绫诲瀷涓婚敭鑾峰彇涓枃鍚嶇О + * + * @param oid 涓氬姟绫诲瀷涓婚敭锛屽涓娇鐢ㄩ�楀彿鍒嗛殧 + * @return 涓枃鍚嶇О锛屽鏋滀笉瀛樺湪浼氳繑鍥瀗ull;澶氫釜浼氫互閫楀彿鍒嗛殧 + * @throws ServiceException 鍙傛暟涓虹┖鎴栬�呮煡璇㈠嚭閿欐椂浼氭姏鍑洪敊璇� + */ + @Override + public String getNameByOid(String oid) throws ServiceException { + return Objects.requireNonNull(baseMapper.selectOne(Wrappers.<BtmType>query().lambda().eq(BtmType::getOid,oid))).getName(); + } + + /** + * 鏍规嵁涓氬姟绫诲瀷鑻辨枃鍚嶇О鑾峰彇涓枃鍚嶇О + * + * @param id 涓氬姟绫诲瀷鑻辨枃鍚嶇О + * @return 涓枃鍚嶇О锛屽鏋滀笉瀛樺湪浼氳繑鍥瀗ull;澶氫釜浼氫互閫楀彿鍒嗛殧 + * @throws ServiceException 鍙傛暟涓虹┖鎴栬�呮煡璇㈠嚭閿欐椂浼氭姏鍑洪敊璇� + */ + @Override + public String getNameById(String id) throws ServiceException { + return Objects.requireNonNull(baseMapper.selectOne(Wrappers.<BtmType>query().lambda().eq(BtmType::getId,id))).getName(); + } + + /** + * 鏍规嵁涓氬姟绫诲瀷涓婚敭鑾峰彇鍏宠仈鐨勬墍鏈夊睘鎬у璞� + * + * @param oid 涓氬姟绫诲瀷涓婚敭 + * @return 鎵�鏈夌殑灞炴�у璞★紝鍖呮嫭绯荤粺灞炴�� + * @throws ServiceException 涓氬姟绫诲瀷涓嶅瓨鍦紝鍙傛暟涓虹┖鎴栨煡璇㈠嚭閿欐椂浼氭姏鍑洪敊璇� + */ + @Override + public List<BtmTypeAttributeVO> listHasAttributesByOid(String oid) throws ServiceException { + return null; + } + + /** + * 鏍规嵁涓氬姟绫诲瀷鑻辨枃鍚嶇О鑾峰彇鍏宠仈鐨勬墍鏈夊睘鎬у璞� + * + * @param id 涓氬姟绫诲瀷鑻辨枃鍚嶇О + * @return 鎵�鏈夌殑灞炴�у璞★紝鍖呮嫭绯荤粺鍐呯疆灞炴�� + * @throws ServiceException 涓氬姟绫诲瀷涓嶅瓨鍦紝鍙傛暟涓虹┖鎴栬�呮煡璇㈠嚭閿欐椂浼氭姏鍑哄紓甯� + */ + @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; + } + + /** + * 鏍规嵁涓氬姟绫诲瀷涓婚敭鑾峰彇鍏宠仈鐨勬墍鏈夊睘鎬у璞� + * + * @param oidCollection 涓氬姟绫诲瀷涓婚敭闆嗗悎 + * @return 鎵�鏈夌殑灞炴�у璞★紝鍖呮嫭绯荤粺鍐呯疆灞炴�э紝key鏄笟鍔$被鍨嬩富閿紝value鏄寘鍚殑灞炴�� + * @throws ServiceException 涓氬姟绫诲瀷涓嶅瓨鍦紝鍙傛暟涓虹┖鎴栬�呮煡璇㈠嚭閿欐椂浼氭姏鍑哄紓甯� + */ + @Override + public Map<String, List<BtmTypeAttributeVO>> batchListHasAttributesByOidCollection(Collection<String> oidCollection) throws ServiceException { + return btmTypeAttributeService.batchListHasAttributesByBtmTypeOidCollection(oidCollection).stream().collect(Collectors.groupingBy(BtmTypeAttributeVO::getPkBtmType)); + } + + /** + * 鏍规嵁涓氬姟绫诲瀷鑻辨枃鍚嶇О鑾峰彇鍏宠仈鐨勬墍鏈夊睘鎬у璞� + * + * @param idCollection 涓氬姟绫诲瀷鑻辨枃鍚嶇О闆嗗悎 + * @return 鎵�鏈夌殑灞炴�у璞★紝鍖呮嫭绯荤粺鍐呯疆灞炴�э紝key鏄笟鍔$被鍨嬩富閿紝value鏄寘鍚殑灞炴�� + * @throws ServiceException 涓氬姟绫诲瀷涓嶅瓨鍦紝鍙傛暟涓虹┖鎴栬�呮煡璇㈠嚭閿欐椂浼氭姏鍑哄紓甯� + */ + @Override + public Map<String, List<BtmTypeAttributeVO>> batchListHasAttributesByIdCollection(Collection<String> idCollection) throws ServiceException { + 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)); + } + + /** + * 鑾峰彇浣跨敤涓氬姟绫诲瀷鐨勯摼鎺ョ被鍨� + * + * @param pkBtmType 涓氬姟绫诲瀷涓婚敭 + * @return 寮曠敤鐨勯摼鎺ョ被鍨� + * @throws ServiceException 鍙傛暟涓虹┖鎴栬�呮煡璇㈠嚭閿欐椂浼氭姏鍑哄紓甯� + */ + @Override + public List<LinkTypeVO> listLinkTypeForUsedBtmType(String pkBtmType) throws ServiceException { + return null; + } + + /** + * 鏍¢獙涓氬姟绫诲瀷鏄惁琚紩鐢� + * + * @param pkBtmType 涓氬姟绫诲瀷鐨勪富閿� + * @return true琛ㄧず琚紩鐢紝 false琛ㄧず娌℃湁琚紩鐢� + * @throws ServiceException 鍙傛暟涓虹┖鎴栬�呮煡璇㈠嚭閿欐椂浼氭姏鍑洪敊璇� + */ + @Override + public boolean checkBtmTypeUsed(String pkBtmType) throws ServiceException { + VciBaseUtil.alertNotNull(pkBtmType, "涓氬姟绫诲瀷涓婚敭"); + return checkBtmTypeUseds(VciBaseUtil.str2List(pkBtmType)); + } + + /** + * 鏍¢獙涓氬姟绫诲瀷鏄惁琚紩鐢� + * + * @param oidCollection 涓氬姟绫诲瀷鐨勪富閿泦鍚� + * @return true琛ㄧず琚紩鐢紝 false琛ㄧず娌℃湁琚紩鐢� + * @throws ServiceException 鍙傛暟涓虹┖鎴栬�呮煡璇㈠嚭閿欐椂浼氭姏鍑洪敊璇� + */ + @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 attributes 瀛楁闆� + * @param fieldMap 榛樿瀛楁闆� + * @return 娣诲姞鍚庣殑瀛楁闆� + */ + 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.setAttrDataType(VciFieldTypeEnum.VTString.name()); + attr.setAttributeLength(50); + attr.setNullableFlag(false); + attr.setDescription(v); + attributes.add(attr); + } + }); + return attributes; + } + + /** + * 妫�鏌ヤ笟鍔$被鍨嬬殑灞炴�ф槸鍚﹀拰鏁版嵁搴撲腑鐩稿悓 + * + * @param btmTypeVO 涓氬姟绫诲瀷鐨勬樉绀哄璞� + */ + private void checkTableSame(BtmTypeVO btmTypeVO) { + List<BtmTypeVO> btmTypeVOList = new ArrayList<>(); + btmTypeVOList.add(btmTypeVO); + BtmAndLinkTypeDdlDTO ddlDTO = new BtmAndLinkTypeDdlDTO(); + ddlDTO.setBtmTypeList(btmTypeVOList); + try { + // 灏嗕互鍓嶇殑checkDifferent鍜宺eflexDifferent缁撳悎浜� + R result = DomainRepeater.checkDifferent(ddlDTO,btmTypeVO.getDomain()); + 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); + } +// modifyAttributeServiceI.finishModify(modifyAttributeInfoList); + } + + /** + * 娣诲姞灞炴�у埌涓氬姟绫诲瀷涓� + * + * @param btmTypeDTO 涓氬姟绫诲瀷鐨勬暟鎹紶杈撳璞� + */ + private List<BtmTypeAttributeVO> addAttributeForBtm(BtmTypeDTO btmTypeDTO) throws VciBaseException{ + List<BtmTypeLinkAttributesDTO> attributesDTOList = btmTypeDTO.getAttributes(); + return btmTypeAttributeService.checkAndInsert(btmTypeDTO.getOid(),attributesDTOList,AuthUtil.getUserAccount(),new Date()); + } + + /** + * 鍒犻櫎涓氬姟绫诲瀷 + * + * @param btmTypeVO 涓氬姟绫诲瀷鏄剧ず瀵硅薄 + * @param autoDeleteTable 鑷姩鍒犻櫎琛ㄦ牸 + * @throws ServiceException 濡傛灉涓氬姟绫诲瀷琚紩鐢紝鎴栬�呭垹闄ゅ嚭閿欐椂浼氭姏鍑哄紓甯� + */ + @Override + public void delete(BtmTypeVO btmTypeVO, boolean autoDeleteTable) throws ServiceException { + + } + + /** + * 鎵归噺鍒犻櫎涓氬姟绫诲瀷 + * + * @param btmTypeVOList 瑕佸垹闄ょ殑涓氬姟绫诲瀷鏄剧ず瀵硅薄鍒楄〃 + * @param autoDeleteTable 鑷姩鍒犻櫎琛ㄦ牸 + * @throws ServiceException 濡傛灉涓氬姟绫诲瀷琚紩鐢紝鎴栬�呭垹闄ゅ嚭閿欐椂浼氭姏鍑哄紓甯� + */ + @Override + public void batchDelete(List<BtmTypeVO> btmTypeVOList, boolean autoDeleteTable) throws ServiceException { + + } + + /** + * 妫�鏌ヤ笟鍔$被鍨嬩笌鏁版嵁搴撹〃鏄惁涓�鑷� + * + * @param pkBtmType 涓氬姟绫诲瀷涓婚敭 + * @return 涓嶅悓鐨勫睘鎬т俊鎭� + * @throws ServiceException 鍙傛暟涓虹┖鎴栬�呮煡璇㈠嚭閿欐椂浼氭姏鍑哄紓甯� + */ + @Override + public List<ModifyAttributeInfo> checkDbTableSame(String pkBtmType) throws ServiceException { + return null; + } + + /** + * 鑾峰彇鏁版嵁搴撹〃锛屾敮鎸佷笟鍔$被鍨嬪拰瑙嗗浘 + * + * @param id 涓氬姟绫诲瀷鐨勫悕绉� + * @return 鏁版嵁搴撹〃鐨勫悕绉� + * @throws ServiceException 鍙傛暟涓虹┖鐨勬椂鍊欎細鎶涘嚭寮傚父 + */ + @Override + 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; + } + + /** + * 鏂板鎴栦慨鏀逛笟鍔$被鍨� + * + * @param btmTypeDTO 涓氬姟绫诲瀷椤甸潰浼犺緭瀵硅薄 + * @return 鎵ц缁撴灉 + */ + @Override + 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); + 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())); + } + // 娣诲姞灞炴�� + 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); + 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); + } + } + } catch (Throwable e) { + if (autoCreateTable) { + dataSourceTransactionManager.rollback(transaction); + } + } + 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 (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 (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()}); +// } +// } + 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 + public boolean deleteLogic(@NotEmpty List<Long> ids) { + return false; + } + + @Override + public boolean changeStatus(@NotEmpty List<Long> ids, Integer status) { + return false; + } +} -- Gitblit v1.9.3