/* * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the dreamlu.net developer nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: Chill 庄骞 (smallchill@163.com) */ package com.vci.ubcs.code.service.impl; import com.alibaba.nacos.common.utils.StringUtils; import com.baomidou.mybatisplus.extension.toolkit.SqlHelper; import com.vci.ubcs.code.bo.CodeClassifyFullInfoBO; import com.vci.ubcs.code.entity.CodeKeyAttrRepeat; import com.vci.ubcs.code.enumpack.FrameworkDataLCStatus; import com.vci.ubcs.code.vo.CodeKeyAttrRepeatVO; import com.vci.ubcs.code.mapper.CodeKeyAttrRepeatMapper; import com.vci.ubcs.code.service.ICodeKeyAttrRepeatService; import com.vci.ubcs.code.vo.pagemodel.CodeClassifyVO; import com.vci.ubcs.code.vo.pagemodel.CodeKeyAttrRepeatRuleVO; import com.vci.ubcs.starter.exception.VciBaseException; import com.vci.ubcs.starter.util.DefaultAttrAssimtUtil; import com.vci.ubcs.starter.util.MdmBtmTypeConstant; import com.vci.ubcs.starter.web.util.BeanUtilForVCI; import com.vci.ubcs.starter.web.util.VciBaseUtil; import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.utils.Func; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.core.metadata.IPage; import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.List; import java.util.stream.Collectors; import static com.vci.ubcs.code.constant.FrameWorkLangCodeConstant.DATA_OID_NOT_EXIST; /** * 关键属性查重规则 服务实现类 * * @author yuxc * @since 2023-04-03 */ @Service public class CodeKeyAttrRepeatServiceImpl implements ICodeKeyAttrRepeatService { @Resource CodeKeyAttrRepeatMapper codeKeyAttrRepeatMapper; @Override public IPage selectPlCodeKeyattrrepeatPage(IPage page, CodeKeyAttrRepeatVO plCodeKeyattrrepeat) { return page.setRecords(codeKeyAttrRepeatMapper.selectPlCodeKeyattrrepeatPage(page, plCodeKeyattrrepeat)); } /** * 主键批量获取关键数据查重规则 * * @param oidCollections 主键集合,但是受性能影响,建议一次查询不超过10000个 * @return 关键数据查重规则显示对象 */ @Override public List listCodeKeyAttrRepeatRuleByOids(Collection oidCollections) { VciBaseUtil.alertNotNull(oidCollections,"数据对象主键集合"); List codeKeyAttrRepeatRuleDOList = listCodeKeyAttrRepeatRuleDOByOidCollections(oidCollections); return codeKeyAttrRepeatRuleDO2VOs(codeKeyAttrRepeatRuleDOList); } /** * 批量数据对象转换为显示对象 * @param codeKeyAttrRepeats 数据对象列表 * @return 显示对象 */ @Override public List codeKeyAttrRepeatRuleDO2VOs(Collection codeKeyAttrRepeats){ List voList = new ArrayList(); if(!CollectionUtils.isEmpty(codeKeyAttrRepeats)){ for(CodeKeyAttrRepeat s: codeKeyAttrRepeats){ CodeKeyAttrRepeatRuleVO vo = codeKeyAttrRepeatRuleDO2VO(s); if(vo != null){ voList.add(vo); } } } return voList; } /** * 使用主键集合查询数据对象 * @param oidCollections 主键的集合 * @return 数据对象列表 */ private List listCodeKeyAttrRepeatRuleDOByOidCollections(Collection oidCollections){ List codeKeyAttrRepeatRuleDOList = new ArrayList(); if(!CollectionUtils.isEmpty(oidCollections)){ Collection> oidCollectionsList = VciBaseUtil.switchCollectionForOracleIn(oidCollections); for(Collection oids: oidCollectionsList){ List tempDOList = codeKeyAttrRepeatMapper.selectBatchIds(oids); if(!CollectionUtils.isEmpty(tempDOList)){ codeKeyAttrRepeatRuleDOList.addAll(tempDOList); } } } return codeKeyAttrRepeatRuleDOList; } /** * 数据对象转换为显示对象 * @param codeKeyAttrRepeat 数据对象 * @return 显示对象 */ @Override public CodeKeyAttrRepeatRuleVO codeKeyAttrRepeatRuleDO2VO(CodeKeyAttrRepeat codeKeyAttrRepeat) { CodeKeyAttrRepeatRuleVO vo = new CodeKeyAttrRepeatRuleVO(); if(codeKeyAttrRepeat != null) { BeanUtilForVCI.copyPropertiesIgnoreCase(codeKeyAttrRepeat, vo); //如果有lcstatus的类的话 vo.setLcStatusText(FrameworkDataLCStatus.getTextByValue(vo.getLcStatus())); } return vo; } /** * 使用分类的全部信息来获取关键属性判断规则的内容 * * @param classifyFullInfo 主题库分类的全部信息 * @return 规则的显示对象 */ @Override public CodeKeyAttrRepeatVO getRuleByClassifyFullInfo(CodeClassifyFullInfoBO classifyFullInfo) { VciBaseUtil.alertNotNull(classifyFullInfo,"主题库分类的信息"); String keyAttrRuleOid = classifyFullInfo.getCurrentClassifyVO().getCodeKeyAttrRepeatOid(); if(StringUtils.isBlank(keyAttrRuleOid)){ //我们根据上级的分类,按照层级倒序排列 if(!CollectionUtils.isEmpty(classifyFullInfo.getParentClassifyVOs())){ //有上级分类的情况下才去查询 List sortedClassifyVO = classifyFullInfo.getParentClassifyVOs().stream().sorted(((o1, o2) -> o1.getDataLevel().compareTo(o2.getDataLevel()))).collect(Collectors.toList()); for(int i = sortedClassifyVO.size() -1;i>=0;i--){ CodeClassifyVO record = sortedClassifyVO.get(i); if(StringUtils.isNotBlank(record.getCodeKeyAttrRepeatOid())){ keyAttrRuleOid = record.getCodeKeyAttrRepeatOid(); break; } } } } if(StringUtils.isNotBlank(keyAttrRuleOid)){ CodeKeyAttrRepeatRuleVO objectByOid = getObjectByOid(keyAttrRuleOid); CodeKeyAttrRepeatVO codeKeyattrrepeatVO = new CodeKeyAttrRepeatVO(); BeanUtils.copyProperties(objectByOid,codeKeyattrrepeatVO); return codeKeyattrrepeatVO; } //关键属性的规则可以为空,为空的时候就代表不控制, return null; } /** * 主键获取关键数据查重规则 * @param oid 主键 * @return 关键数据查重规则显示对象 */ @Override public CodeKeyAttrRepeatRuleVO getObjectByOid(String oid){ CodeKeyAttrRepeatRuleVO codeKeyAttrRepeatRuleVO = codeKeyAttrRepeatRuleDO2VO(selectByOid(oid)); CodeKeyAttrRepeatVO codeKeyattrrepeatVO = new CodeKeyAttrRepeatVO(); BeanUtils.copyProperties(codeKeyAttrRepeatRuleVO,codeKeyattrrepeatVO); return codeKeyAttrRepeatRuleVO; } /** * 修改关键属性查重规则 * @param codeKeyattrrepeat * @return */ @Override public boolean addSave(CodeKeyAttrRepeat codeKeyattrrepeat) { // 设置默认值 codeKeyattrrepeat.setCreator(AuthUtil.getUserAccount()); codeKeyattrrepeat.setCreatetime(new Date()); codeKeyattrrepeat.setLastmodifier(AuthUtil.getUserAccount()); codeKeyattrrepeat.setLastmodifytime(new Date()); codeKeyattrrepeat.setBtmname(MdmBtmTypeConstant.CODE_KEY_ATTR_REPEAT_RULE); codeKeyattrrepeat.setFirstr("1"); codeKeyattrrepeat.setFirstv("1"); codeKeyattrrepeat.setLastr("1"); codeKeyattrrepeat.setLastv("1"); codeKeyattrrepeat.setLcstatus("Enabled"); codeKeyattrrepeat.setRevisionseq(1); codeKeyattrrepeat.setRevisionoid(VciBaseUtil.getPk()); codeKeyattrrepeat.setRevisionvalue("1"); codeKeyattrrepeat.setRevisionrule("1"); codeKeyattrrepeat.setVersionseq(1); codeKeyattrrepeat.setVersionrule("0"); codeKeyattrrepeat.setVersionvalue("1"); return SqlHelper.retBool(codeKeyAttrRepeatMapper.insert(codeKeyattrrepeat)); } /** * 新增关键属性查重规则 * @param codeKeyattrrepeat * @return */ @Override public boolean update(CodeKeyAttrRepeat codeKeyattrrepeat) { // 设置默认值 codeKeyattrrepeat.setLastmodifier(AuthUtil.getUserAccount()); codeKeyattrrepeat.setLastmodifytime(new Date()); return SqlHelper.retBool(codeKeyAttrRepeatMapper.updateById(codeKeyattrrepeat)); } /** * 删除关键属性查重规则 * @param oids * @return */ @Override public boolean deleteByOids(String oids) { return SqlHelper.retBool(codeKeyAttrRepeatMapper.deleteById(oids)); } /** * 主键查询数据对象 * @param oid 主键 * @return 数据对象 * @throws VciBaseException 参数为空,并且数据不存在的时候会抛出异常 */ private CodeKeyAttrRepeat selectByOid(String oid) { VciBaseUtil.alertNotNull(oid,"主键"); CodeKeyAttrRepeat codeKeyAttrRepeatRuleDO = codeKeyAttrRepeatMapper.selectById(oid.trim()); // .selectByPrimaryKey(oid.trim()); if(codeKeyAttrRepeatRuleDO == null || StringUtils.isBlank(codeKeyAttrRepeatRuleDO.getOid())){ throw new VciBaseException(DATA_OID_NOT_EXIST); } return codeKeyAttrRepeatRuleDO; } }