package com.vci.ubcs.code.applyjtcodeservice.service.impl;
|
|
import com.alibaba.fastjson.JSON;
|
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.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.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.List;
|
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 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()), 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<>();
|
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> 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));
|
boolean resBoolean = this.saveBatch(finalGroupAttrPoolMappings);
|
log.info("集团属性同步到集团属性池,同步完毕");
|
return resBoolean;
|
}
|
|
/**
|
* 集团属性映射界面修改的映射配置保存
|
* @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);
|
}
|
|
}
|