From 3aae81075a18a11d6b605c7583eb03b75366b466 Mon Sep 17 00:00:00 2001
From: 田源 <lastanimals@163.com>
Date: 星期四, 18 四月 2024 00:08:52 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 Source/UBCS/ubcs-service/ubcs-applyjtcodeservice/src/main/java/com/vci/ubcs/code/applyjtcodeservice/service/impl/GroupAttrPoolMappingServiceImpl.java |  118 +++++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 91 insertions(+), 27 deletions(-)

diff --git a/Source/UBCS/ubcs-service/ubcs-applyjtcodeservice/src/main/java/com/vci/ubcs/code/applyjtcodeservice/service/impl/GroupAttrPoolMappingServiceImpl.java b/Source/UBCS/ubcs-service/ubcs-applyjtcodeservice/src/main/java/com/vci/ubcs/code/applyjtcodeservice/service/impl/GroupAttrPoolMappingServiceImpl.java
index 6593e75..c144df3 100644
--- a/Source/UBCS/ubcs-service/ubcs-applyjtcodeservice/src/main/java/com/vci/ubcs/code/applyjtcodeservice/service/impl/GroupAttrPoolMappingServiceImpl.java
+++ b/Source/UBCS/ubcs-service/ubcs-applyjtcodeservice/src/main/java/com/vci/ubcs/code/applyjtcodeservice/service/impl/GroupAttrPoolMappingServiceImpl.java
@@ -1,27 +1,38 @@
 package com.vci.ubcs.code.applyjtcodeservice.service.impl;
 
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.vci.ubcs.code.applyjtcodeservice.entity.DockingPreAttrRange;
 import com.vci.ubcs.code.applyjtcodeservice.entity.DockingPreMetaAttr;
 import com.vci.ubcs.code.applyjtcodeservice.entity.GroupAttrPoolMapping;
 import com.vci.ubcs.code.applyjtcodeservice.mapper.GroupAttrPoolMappingMapper;
 import com.vci.ubcs.code.applyjtcodeservice.service.IDockingPreAttrMappingService;
 import com.vci.ubcs.code.applyjtcodeservice.service.IGroupAttrPoolMappingService;
-import com.vci.ubcs.code.applyjtcodeservice.service.IGroupMdmInterService;
 import com.vci.ubcs.code.applyjtcodeservice.vo.GroupAttrPoolMappingVO;
 import com.vci.ubcs.code.applyjtcodeservice.wrapper.GroupAttrPoolMappingWrapper;
 import com.vci.ubcs.code.feign.ICodeClassifyClient;
 import com.vci.ubcs.code.vo.pagemodel.CodeClassifyTemplateAttrVO;
+import com.vci.ubcs.omd.feign.IEnumClient;
+import com.vci.ubcs.omd.vo.EnumVO;
+import com.vci.ubcs.starter.util.DefaultAttrAssimtUtil;
+import com.vci.ubcs.starter.util.MdmBtmTypeConstant;
+import com.vci.ubcs.starter.util.UBCSCondition;
+import com.vci.ubcs.starter.web.pagemodel.BladeQueryObject;
 import lombok.RequiredArgsConstructor;
+import lombok.Value;
 import lombok.extern.slf4j.Slf4j;
 import org.springblade.core.log.exception.ServiceException;
+import org.springblade.core.mp.support.Condition;
 import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.utils.Func;
 import org.springframework.stereotype.Service;
 
 import javax.sql.rowset.serial.SerialException;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -43,16 +54,19 @@
 
 	private final IDockingPreAttrMappingService dockingPreAttrMappingService;
 
+	private final IEnumClient enumClient;
+
 	/**
 	 * 鏌ヨ鍏ㄩ儴闆嗗洟灞炴�ф睜鏄犲皠鐨勫睘鎬�
-	 *
-	 * @param GroupAttrPoolMappingVO
+	 * @param bladeQueryObject
 	 * @return
+	 * @throws SerialException
 	 */
 	@Override
-	public List<GroupAttrPoolMappingVO> getGroupAttrPoolALlList(GroupAttrPoolMappingVO GroupAttrPoolMappingVO) throws SerialException {
-		List<GroupAttrPoolMapping> groupAttrPoolMappings = groupAttrPoolMappingMapper.selectList(null);
-		return GroupAttrPoolMappingWrapper.build().entityVOs(groupAttrPoolMappings);
+	public IPage<GroupAttrPoolMappingVO> getGroupAttrPoolALlList(BladeQueryObject bladeQueryObject) throws ServiceException {
+		QueryWrapper<GroupAttrPoolMapping> queryWrapper = UBCSCondition.getQueryWrapper(bladeQueryObject.getConditionMap(), GroupAttrPoolMapping.class);
+		IPage<GroupAttrPoolMapping> groupAttrPoolMappingIPage = this.groupAttrPoolMappingMapper.selectPage(Condition.getPage(bladeQueryObject.getQuery().setDescs("groupAttrKey")), queryWrapper);
+		return GroupAttrPoolMappingWrapper.build().pageVO(groupAttrPoolMappingIPage);
 	}
 
 	/**
@@ -98,14 +112,13 @@
 	 * @throws SerialException
 	 */
 	@Override
-	public boolean saveDistinctGroupAttr(List<DockingPreMetaAttr> dockingPreMetaAttrList) throws SerialException {
+	public boolean saveDistinctGroupAttr(List<DockingPreMetaAttr> dockingPreMetaAttrList) throws ServiceException {
 		// 涓虹┖鐩存帴杩斿洖
 		if(Func.isEmpty(dockingPreMetaAttrList)){
 			return true;
 		}
 		List<GroupAttrPoolMapping> groupAttrPoolMappings = new ArrayList<>();
-		List<String> distinctListEnglishName = new ArrayList<>();
-		List<String> distinctListChineseName = new ArrayList<>();
+		Map<String,String> distinctMap = new HashMap<>();
 		log.info("寮�濮嬪皢闆嗗洟灞炴�у悓姝ュ埌闆嗗洟灞炴�ф睜涓�");
 		// 灏哾ockingPreMetaAttrList闆嗗悎杞崲涓洪泦鍥㈠睘鎬ф睜灞炴�у璞�
 		dockingPreMetaAttrList.stream().forEach(item->{
@@ -114,29 +127,40 @@
 			groupAttrPoolMapping.setGroupAttrName(item.getChineseName());
 			groupAttrPoolMappings.add(groupAttrPoolMapping);
 			// 鍘婚噸鏌ヨ鏉′欢闆嗗洟灞炴�ц嫳鏂囧悕绉�
-			distinctListEnglishName.add(item.getEnglishName());
-			// 鍘婚噸鏌ヨ鏉′欢闆嗗洟灞炴�т腑鏂囧悕绉�
-			distinctListChineseName.add(item.getName());
+			distinctMap.put(item.getEnglishName(),item.getChineseName());
+		});
+		// 鏋勯�犳煡閲峴ql锛堟牴鎹泦鍥㈠睘鎬т腑鏂囧拰鑻辨枃浣滀负涓�缁勬煡璇㈡潯浠讹級
+		LambdaQueryWrapper<GroupAttrPoolMapping> lambdaQueryWrapper = Wrappers.<GroupAttrPoolMapping>query().lambda();
+		distinctMap.forEach((key, value)->{
+			lambdaQueryWrapper.eq(GroupAttrPoolMapping::getGroupAttrKey,key).and(wrapper->wrapper.eq(GroupAttrPoolMapping::getGroupAttrName,value)).or(true);
 		});
 		// 鍘婚噸鏌ヨ缁撴灉
-		List<GroupAttrPoolMapping> dbGroupAttrPoolMappings = groupAttrPoolMappingMapper.selectList(
-			Wrappers.<GroupAttrPoolMapping>query()
-				.lambda().in(GroupAttrPoolMapping::getGroupAttrKey, distinctListEnglishName)
-				.in(GroupAttrPoolMapping::getGroupAttrName, distinctListChineseName)
-		);
-		List<GroupAttrPoolMapping> finalGroupAttrPoolMappings = null;
+		List<GroupAttrPoolMapping> dbGroupAttrPoolMappings = groupAttrPoolMappingMapper.selectList(lambdaQueryWrapper);
+		List<GroupAttrPoolMapping> newGroupAttrPoolMappings = null;
 		// 灏嗗凡瀛樺湪鐨勯泦鍥㈠睘鎬т粠groupAttrPoolMappings涓Щ闄�
 		if(Func.isNotEmpty(dbGroupAttrPoolMappings)){
-			finalGroupAttrPoolMappings = groupAttrPoolMappings.stream()
+			newGroupAttrPoolMappings = groupAttrPoolMappings.stream()
 				.filter(mapping -> !dbGroupAttrPoolMappings.stream()
 					.map(GroupAttrPoolMapping::getGroupAttrKey)
 					.collect(Collectors.toList())
 					.contains(mapping.getGroupAttrKey()))
 				.collect(Collectors.toList());
+		}else{
+			newGroupAttrPoolMappings = groupAttrPoolMappings;
 		}
-		boolean resBoolean = this.saveBatch(finalGroupAttrPoolMappings);
-		log.info("闆嗗洟灞炴�у悓姝ュ埌闆嗗洟灞炴�ф睜,鍚屾瀹屾瘯");
-		return resBoolean;
+		List<GroupAttrPoolMapping> finalGroupAttrPoolMappings = newGroupAttrPoolMappings.stream().map(item -> {
+			DefaultAttrAssimtUtil.addDefaultAttrAssimt(item, MdmBtmTypeConstant.GROUP_ATTR_POOL);
+			return item;
+		}).collect(Collectors.toList());
+		log.info("鏈鍚屾鐨勬暟鎹负锛�"+ JSON.toJSONString(finalGroupAttrPoolMappings));
+		try {
+			this.saveBatch(finalGroupAttrPoolMappings);
+			log.info("闆嗗洟灞炴�у悓姝ュ埌闆嗗洟灞炴�ф睜,鍚屾瀹屾瘯");
+			return true;
+		}catch (Exception e){
+			log.info("闆嗗洟灞炴�у悓姝ュ埌闆嗗洟灞炴�ф睜,鍚屾澶辫触锛侊紝鍘熷洜锛�"+e.getMessage());
+			throw new ServiceException("闆嗗洟灞炴�у悓姝ュ埌闆嗗洟灞炴�ф睜,鍚屾澶辫触锛侊紝鍘熷洜锛�"+e.getMessage());
+		}
 	}
 
 	/**
@@ -146,12 +170,16 @@
 	 * @throws SerialException
 	 */
 	@Override
-	public boolean editGroupAttr(List<GroupAttrPoolMappingVO> groupAttrPoolMappingVO) throws SerialException {
+	public boolean editGroupAttr(List<GroupAttrPoolMappingVO> groupAttrPoolMappingVO) throws ServiceException {
 		if(Func.isEmpty(groupAttrPoolMappingVO)){
 			return true;
 		}
 		List<GroupAttrPoolMapping> groupAttrPoolMappings = GroupAttrPoolMappingWrapper.build().VOsEntity(groupAttrPoolMappingVO);
-		return this.updateBatchById(groupAttrPoolMappings);
+		List<GroupAttrPoolMapping> finalGroupAttrPoolMappings = groupAttrPoolMappings.stream().map(item -> {
+			DefaultAttrAssimtUtil.updateDefaultAttrAssimt(item);
+			return item;
+		}).collect(Collectors.toList());
+		return this.updateBatchById(finalGroupAttrPoolMappings);
 	}
 
 	/**
@@ -161,8 +189,44 @@
 	 * @throws SerialException
 	 */
 	@Override
-	public boolean syncGroupAttrMapping(List<GroupAttrPoolMappingVO> groupAttrPoolMappingVOS) throws SerialException {
-		return dockingPreAttrMappingService.syncGroupAttrMapping(groupAttrPoolMappingVOS);
+	public R syncGroupAttrMapping(List<GroupAttrPoolMappingVO> groupAttrPoolMappingVOS) throws ServiceException {
+		List<String> groupKeyList = groupAttrPoolMappingVOS.stream().map(GroupAttrPoolMappingVO::getGroupAttrKey).collect(Collectors.toList());
+		List<GroupAttrPoolMapping> groupAttrPoolMappings = this.groupAttrPoolMappingMapper.selectList(
+			Wrappers.<GroupAttrPoolMapping>query().lambda().in(GroupAttrPoolMapping::getGroupAttrKey, groupKeyList)
+		);
+		if(Func.isEmpty(groupAttrPoolMappings) && groupKeyList.size() == groupAttrPoolMappings.size()){
+			return R.fail("鍕鹃�夌殑瑕佸悓姝ョ殑闆嗗洟灞炴�т腑鏈夊湪搴撲腑涓嶅瓨鍦ㄧ殑鏁版嵁锛岃鍒锋柊鍚庨噸璇曪紒");
+		}
+		return dockingPreAttrMappingService.syncGroupAttrMapping(groupAttrPoolMappings);
+	}
+
+	/**
+	 * 鏍规嵁鍒嗙被OID鑾峰彇鍒版ā鏉垮啀鏍规嵁灞炴�d鑾峰彇鍒版ā鏉夸笅鐨勫睘鎬d鐨別num鍊硷紝鐒跺悗鏌ヨ鍑烘灇涓�
+	 * @param groupAttrPoolMappingVOS
+	 * @return
+	 */
+	@Override
+	public List<EnumVO> getEnumAttrByClsOIdAndAttrId(GroupAttrPoolMappingVO groupAttrPoolMappingVOS) {
+		if(Func.isEmpty(groupAttrPoolMappingVOS.getClassifyId())){
+			throw new ServiceException("蹇呬紶鍙傛暟鍒嗙被oid涓嶈兘涓虹┖锛�");
+		}
+		if(Func.isEmpty(groupAttrPoolMappingVOS.getCodeMetaAttrKey())){
+			throw new ServiceException("蹇呬紶鍙傛暟锛屾ā鏉垮睘鎬d涓嶈兘涓虹┖");
+		}
+		// 鏍规嵁鍒嗙被oid鏌ヨ鎵�浣跨敤鐨勬ā鏉垮拰妯℃澘灞炴��
+		List<CodeClassifyTemplateAttrVO> attrVOS = codeClassifyClient.listCodeAttributeByClassId(groupAttrPoolMappingVOS.getClassifyId());
+		// 绛涢�夊嚭妯℃澘灞炴�т腑id绛変簬codeMetaAttrKey鐨勶紝骞跺彇鍑篹numId
+		if(attrVOS.isEmpty()){
+			return new ArrayList<>();
+		}
+		List<CodeClassifyTemplateAttrVO> codeClassifyTemplateAttrVOS = attrVOS.stream().filter(item -> item.getId().equalsIgnoreCase(groupAttrPoolMappingVOS.getCodeMetaAttrKey())).collect(Collectors.toList());
+		// 鏍规嵁涓婁竴姝ュ彇鍑虹殑enumId璋冪敤鏋氫妇鏈嶅姟鏌ヨ鍑烘灇涓惧苟杩斿洖
+		String enumId = codeClassifyTemplateAttrVOS.get(0).getEnumId();
+		if(Func.isBlank(enumId)){
+			return new ArrayList<>();
+		}
+		R<List<EnumVO>> list = enumClient.getList(enumId);
+		return list.getData();
 	}
 
 }

--
Gitblit v1.9.3