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.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.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;
|
|
/**
|
* 集团属性池映射服务层
|
*
|
* @author ludc
|
* @date 2024/4/15 16:52
|
*/
|
@Service
|
@RequiredArgsConstructor
|
@Slf4j
|
public class GroupAttrPoolMappingServiceImpl extends ServiceImpl<GroupAttrPoolMappingMapper, GroupAttrPoolMapping> implements IGroupAttrPoolMappingService {
|
|
private final GroupAttrPoolMappingMapper groupAttrPoolMappingMapper;
|
|
private final ICodeClassifyClient codeClassifyClient;
|
|
private final IDockingPreAttrMappingService dockingPreAttrMappingService;
|
|
private final IEnumClient enumClient;
|
|
/**
|
* 查询全部集团属性池映射的属性
|
* @param bladeQueryObject
|
* @return
|
* @throws SerialException
|
*/
|
@Override
|
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);
|
}
|
|
/**
|
* 根据集团属性编号查询集团属性池映射
|
*
|
* @param groupAttrPoolMappingVO
|
* @return
|
*/
|
@Override
|
public List<GroupAttrPoolMappingVO> getByGroupAttrKeyList(GroupAttrPoolMappingVO groupAttrPoolMappingVO) {
|
// 查询条件为空
|
if (Func.isEmpty(groupAttrPoolMappingVO.getGroupAttrKeyList())) {
|
throw new ServiceException("查询条件,要查询的集团编号列表不能为空!");
|
}
|
if (Func.isBlank(groupAttrPoolMappingVO.getClassifyId())) {
|
throw new ServiceException("查询条件中,分类id不能为空!");
|
}
|
//集团属性池数据
|
List<GroupAttrPoolMapping> groupAttrPoolMappings = groupAttrPoolMappingMapper.selectList(
|
Wrappers.<GroupAttrPoolMapping>query()
|
.lambda().in(GroupAttrPoolMapping::getGroupAttrKey, groupAttrPoolMappingVO.getGroupAttrKeyList())
|
);
|
//根据分类id查询出,对应的模板上配置的属性
|
List<CodeClassifyTemplateAttrVO> attrVOS = codeClassifyClient.listCodeAttributeByClassId(groupAttrPoolMappingVO.getClassifyId());
|
List<GroupAttrPoolMappingVO> groupAttrPoolMappingVOS = GroupAttrPoolMappingWrapper.build().entityVOs(groupAttrPoolMappings);
|
|
List<GroupAttrPoolMappingVO> finalGroupAttrPoolMappingVOS;
|
//根据集团属性池中配置id元数据属性id找到当前所属分类下的模板属性中对应属性的oid
|
finalGroupAttrPoolMappingVOS = groupAttrPoolMappingVOS.stream().map(item -> {
|
CodeClassifyTemplateAttrVO codeClassifyTemplateAttrVO = attrVOS.stream().filter(attr -> attr.getId().equals(item.getCodeMetaAttrKey())).findFirst().orElse(new CodeClassifyTemplateAttrVO());
|
item.setTargetAttrId(codeClassifyTemplateAttrVO.getOid());
|
return item;
|
}).collect(Collectors.toList());
|
|
return finalGroupAttrPoolMappingVOS;
|
}
|
|
/**
|
* 点击同步模型时调用该方法,
|
* 实现将集团获取的属性去重放到集团属性池映射表中
|
* @param dockingPreMetaAttrList
|
* @return
|
* @throws SerialException
|
*/
|
@Override
|
public boolean saveDistinctGroupAttr(List<DockingPreMetaAttr> dockingPreMetaAttrList) throws ServiceException {
|
// 为空直接返回
|
if(Func.isEmpty(dockingPreMetaAttrList)){
|
return true;
|
}
|
List<GroupAttrPoolMapping> groupAttrPoolMappings = new ArrayList<>();
|
Map<String,String> distinctMap = new HashMap<>();
|
log.info("开始将集团属性同步到集团属性池中");
|
// 将dockingPreMetaAttrList集合转换为集团属性池属性对象
|
dockingPreMetaAttrList.stream().forEach(item->{
|
GroupAttrPoolMapping groupAttrPoolMapping = new GroupAttrPoolMapping();
|
groupAttrPoolMapping.setGroupAttrKey(item.getEnglishName());
|
groupAttrPoolMapping.setGroupAttrName(item.getChineseName());
|
groupAttrPoolMappings.add(groupAttrPoolMapping);
|
// 去重查询条件集团属性英文名称
|
distinctMap.put(item.getEnglishName(),item.getChineseName());
|
});
|
// 构造查重sql(根据集团属性中文和英文作为一组查询条件)
|
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(lambdaQueryWrapper);
|
List<GroupAttrPoolMapping> newGroupAttrPoolMappings = null;
|
// 将已存在的集团属性从groupAttrPoolMappings中移除
|
if(Func.isNotEmpty(dbGroupAttrPoolMappings)){
|
newGroupAttrPoolMappings = groupAttrPoolMappings.stream()
|
.filter(mapping -> !dbGroupAttrPoolMappings.stream()
|
.map(GroupAttrPoolMapping::getGroupAttrKey)
|
.collect(Collectors.toList())
|
.contains(mapping.getGroupAttrKey()))
|
.collect(Collectors.toList());
|
}else{
|
newGroupAttrPoolMappings = groupAttrPoolMappings;
|
}
|
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());
|
}
|
}
|
|
/**
|
* 集团属性映射界面修改的映射配置保存
|
* @param groupAttrPoolMappingVO
|
* @return
|
* @throws SerialException
|
*/
|
@Override
|
public boolean editGroupAttr(List<GroupAttrPoolMappingVO> groupAttrPoolMappingVO) throws ServiceException {
|
if(Func.isEmpty(groupAttrPoolMappingVO)){
|
return true;
|
}
|
List<GroupAttrPoolMapping> groupAttrPoolMappings = GroupAttrPoolMappingWrapper.build().VOsEntity(groupAttrPoolMappingVO);
|
List<GroupAttrPoolMapping> finalGroupAttrPoolMappings = groupAttrPoolMappings.stream().map(item -> {
|
DefaultAttrAssimtUtil.updateDefaultAttrAssimt(item);
|
return item;
|
}).collect(Collectors.toList());
|
return this.updateBatchById(finalGroupAttrPoolMappings);
|
}
|
|
/**
|
* 同步集团属性池中的映射配置到,所有应用了该集团属性的具体某个分类上去
|
* @param groupAttrPoolMappingVOS
|
* @return
|
* @throws SerialException
|
*/
|
@Override
|
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获取到模板再根据属性id获取到模板下的属性id的enum值,然后查询出枚举
|
* @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("必传参数,模板属性id不能为空");
|
}
|
// 根据分类oid查询所使用的模板和模板属性
|
List<CodeClassifyTemplateAttrVO> attrVOS = codeClassifyClient.listCodeAttributeByClassId(groupAttrPoolMappingVOS.getClassifyId());
|
// 筛选出模板属性中id等于codeMetaAttrKey的,并取出enumId
|
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();
|
}
|
|
}
|