package com.vci.ubcs.code.applyjtcodeservice.service.impl;
|
|
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 lombok.RequiredArgsConstructor;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springblade.core.log.exception.ServiceException;
|
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.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;
|
|
/**
|
* 查询全部集团属性池映射的属性
|
*
|
* @param GroupAttrPoolMappingVO
|
* @return
|
*/
|
@Override
|
public List<GroupAttrPoolMappingVO> getGroupAttrPoolALlList(GroupAttrPoolMappingVO GroupAttrPoolMappingVO) throws SerialException {
|
List<GroupAttrPoolMapping> groupAttrPoolMappings = groupAttrPoolMappingMapper.selectList(null);
|
return GroupAttrPoolMappingWrapper.build().entityVOs(groupAttrPoolMappings);
|
}
|
|
/**
|
* 根据集团属性编号查询集团属性池映射
|
*
|
* @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 SerialException {
|
// 为空直接返回
|
if(Func.isEmpty(dockingPreMetaAttrList)){
|
return true;
|
}
|
List<GroupAttrPoolMapping> groupAttrPoolMappings = new ArrayList<>();
|
List<String> distinctListEnglishName = new ArrayList<>();
|
List<String> distinctListChineseName = new ArrayList<>();
|
log.info("开始将集团属性同步到集团属性池中");
|
// 将dockingPreMetaAttrList集合转换为集团属性池属性对象
|
dockingPreMetaAttrList.stream().forEach(item->{
|
GroupAttrPoolMapping groupAttrPoolMapping = new GroupAttrPoolMapping();
|
groupAttrPoolMapping.setGroupAttrKey(item.getEnglishName());
|
groupAttrPoolMapping.setGroupAttrName(item.getChineseName());
|
groupAttrPoolMappings.add(groupAttrPoolMapping);
|
// 去重查询条件集团属性英文名称
|
distinctListEnglishName.add(item.getEnglishName());
|
// 去重查询条件集团属性中文名称
|
distinctListChineseName.add(item.getName());
|
});
|
// 去重查询结果
|
List<GroupAttrPoolMapping> dbGroupAttrPoolMappings = groupAttrPoolMappingMapper.selectList(
|
Wrappers.<GroupAttrPoolMapping>query()
|
.lambda().in(GroupAttrPoolMapping::getGroupAttrKey, distinctListEnglishName)
|
.in(GroupAttrPoolMapping::getGroupAttrName, distinctListChineseName)
|
);
|
List<GroupAttrPoolMapping> finalGroupAttrPoolMappings = null;
|
// 将已存在的集团属性从groupAttrPoolMappings中移除
|
if(Func.isNotEmpty(dbGroupAttrPoolMappings)){
|
finalGroupAttrPoolMappings = groupAttrPoolMappings.stream()
|
.filter(mapping -> !dbGroupAttrPoolMappings.stream()
|
.map(GroupAttrPoolMapping::getGroupAttrKey)
|
.collect(Collectors.toList())
|
.contains(mapping.getGroupAttrKey()))
|
.collect(Collectors.toList());
|
}
|
boolean resBoolean = this.saveBatch(finalGroupAttrPoolMappings);
|
log.info("集团属性同步到集团属性池,同步完毕");
|
return resBoolean;
|
}
|
|
/**
|
* 集团属性映射界面修改的映射配置保存
|
* @param groupAttrPoolMappingVO
|
* @return
|
* @throws SerialException
|
*/
|
@Override
|
public boolean editGroupAttr(List<GroupAttrPoolMappingVO> groupAttrPoolMappingVO) throws SerialException {
|
if(Func.isEmpty(groupAttrPoolMappingVO)){
|
return true;
|
}
|
List<GroupAttrPoolMapping> groupAttrPoolMappings = GroupAttrPoolMappingWrapper.build().VOsEntity(groupAttrPoolMappingVO);
|
return this.updateBatchById(groupAttrPoolMappings);
|
}
|
|
/**
|
* 同步集团属性池中的映射配置到,所有应用了该集团属性的具体某个分类上去
|
* @param groupAttrPoolMappingVOS
|
* @return
|
* @throws SerialException
|
*/
|
@Override
|
public boolean syncGroupAttrMapping(List<GroupAttrPoolMappingVO> groupAttrPoolMappingVOS) throws SerialException {
|
return dockingPreAttrMappingService.syncGroupAttrMapping(groupAttrPoolMappingVOS);
|
}
|
|
}
|