| | |
| | | package com.vci.ubcs.code.service.impl; |
| | | |
| | | import com.alibaba.cloud.commons.lang.StringUtils; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import com.vci.ubcs.code.constant.MdmBtmTypeConstant; |
| | | import com.vci.ubcs.code.constant.FrameWorkDefaultValueConstant; |
| | | |
| | | import com.vci.ubcs.code.dto.CodeBasicSecDTO; |
| | | import com.vci.ubcs.code.dto.CodeRuleDTO; |
| | | import com.vci.ubcs.code.entity.*; |
| | |
| | | import com.vci.ubcs.code.mapper.CodeRuleMapper; |
| | | import com.vci.ubcs.code.mapper.CodeSerialValueMapper; |
| | | import com.vci.ubcs.code.mapper.CommonsMapper; |
| | | import com.vci.ubcs.code.service.ICodeAllCodeService; |
| | | import com.vci.ubcs.code.service.ICodeBasicSecService; |
| | | import com.vci.ubcs.code.service.ICodeClassifyService; |
| | | import com.vci.ubcs.code.service.ICodeRuleService; |
| | | import com.vci.ubcs.code.service.*; |
| | | import com.vci.ubcs.code.vo.pagemodel.CodeBasicSecVO; |
| | | import com.vci.ubcs.code.vo.pagemodel.CodeClassifyVO; |
| | | import com.vci.ubcs.code.vo.pagemodel.CodeFixedValueVO; |
| | | import com.vci.ubcs.code.vo.pagemodel.CodeRuleVO; |
| | | import com.vci.ubcs.code.wrapper.CodeClassifyWrapper; |
| | | import com.vci.ubcs.code.wrapper.CodeRuleWrapper; |
| | | import com.vci.ubcs.omd.cache.EnumCache; |
| | | import com.vci.ubcs.omd.enums.EnumEnum; |
| | | import com.vci.ubcs.starter.exception.VciBaseException; |
| | | import com.vci.ubcs.starter.revision.model.TreeQueryObject; |
| | | import com.vci.ubcs.starter.revision.service.RevisionModelUtil; |
| | | 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.*; |
| | | import com.vci.ubcs.starter.web.util.BeanUtilForVCI; |
| | | import com.vci.ubcs.starter.web.util.VciBaseUtil; |
| | | import com.vci.ubcs.starter.web.util.WebUtil; |
| | | import org.springblade.core.log.exception.ServiceException; |
| | | import org.springblade.core.mp.support.Condition; |
| | | import org.springblade.core.mp.support.Query; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.constant.BladeConstant; |
| | | import org.springblade.core.tool.utils.BeanUtil; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | | |
| | | import static com.vci.ubcs.code.constant.FrameWorkDefaultValueConstant.FRAMEWORK_RELEASE_EDITING; |
| | | import static com.vci.ubcs.code.constant.FrameWorkLangCodeConstant.DATA_OID_NOT_EXIST; |
| | |
| | | private ICodeAllCodeService codeAllcodeService; |
| | | @Resource |
| | | private ICodeBasicSecService codeBasicSecService; |
| | | @Resource |
| | | private ICodeClassifyValueService iCodeClassifyValueService; |
| | | |
| | | /** |
| | | * 对象的操作 |
| | | */ |
| | | @Resource |
| | | private RevisionModelUtil revisionModelUtil; |
| | | |
| | | @Value("${user-info.tenant-id}") |
| | | private String tenantId; |
| | | @Value("${user-info.id}") |
| | | private String userId; |
| | | |
| | | /** |
| | | * 分页查询 |
| | |
| | | */ |
| | | @Override |
| | | public IPage<CodeRuleVO> gridCodeRule(Query query, Map<String,Object> conidtionMap) { |
| | | //如果等于自己配置的管理组租户id和管理组超管账号,就不需要按照规则所有者来进行查询 |
| | | if(!(AuthUtil.getTenantId().equals(this.tenantId) && AuthUtil.getUserId().toString().equals(this.userId))){ |
| | | // 按照规则所有者来查询 |
| | | conidtionMap.put("owner",AuthUtil.getUserId()); |
| | | } |
| | | IPage<CodeRule> codeRuleIPage = this.codeRuleMapper.selectPage(Condition.getPage(query), UBCSCondition.getQueryWrapper(conidtionMap, CodeRule.class)); |
| | | //do转vo同时setLcStatusText生命周期值,并包装成分页对象返回 |
| | | return CodeRuleWrapper.build().pageVO(codeRuleIPage); |
| | |
| | | @Override |
| | | public R addSave(CodeRuleDTO codeRuleDTO) throws VciBaseException { |
| | | VciBaseUtil.alertNotNull(codeRuleDTO, "需要添加的数据对象"); |
| | | if(checkCodeRuleRepeat(codeRuleDTO.getId())){ |
| | | if(checkCodeRuleRepeat(codeRuleDTO)){ |
| | | return R.fail("规则编号已存在!"); |
| | | } |
| | | // 将DTO转换为DO |
| | |
| | | |
| | | /** |
| | | * 检查id编号是否重复 |
| | | * @param id 当前编号 |
| | | * @param codeRuleDTO 当前判断是否重复的对象 |
| | | * @return 返回false表示未重复 |
| | | */ |
| | | @Override |
| | | public boolean checkCodeRuleRepeat(String id){ |
| | | Long count = this.codeRuleMapper.selectCount(Wrappers.<CodeRule>query().lambda().eq(CodeRule::getId, id)); |
| | | if(count>0){ |
| | | return true; |
| | | public boolean checkCodeRuleRepeat(CodeRuleDTO codeRuleDTO){ |
| | | // 根据规则id查询编号 |
| | | List<CodeRule> codeRulesList = this.codeRuleMapper.selectList(Wrappers.<CodeRule>query() |
| | | .lambda().eq(CodeRule::getId, codeRuleDTO.getId()) |
| | | .eq(CodeRule::getTenantId,AuthUtil.getTenantId().equals(this.tenantId) ? "":codeRuleDTO.getTenantId())); |
| | | if(!codeRulesList.isEmpty()){ |
| | | return codeRulesList.parallelStream().anyMatch(codeRule -> { |
| | | if(StringUtils.isNotBlank(codeRuleDTO.getOid())){ |
| | | // 代表是修改,不是将编号修改相同的编号 |
| | | return !codeRule.getOid().equals(codeRuleDTO.getOid()); |
| | | }else { |
| | | return true; |
| | | } |
| | | }); |
| | | } |
| | | return false; |
| | | } |
| | |
| | | * @return true表示可以编辑或删除,false表示不可以 |
| | | */ |
| | | @Override |
| | | public boolean checkEditDelStatus(String lcStatus) { |
| | | public boolean checkEditDelStatus(String lcStatus) throws VciBaseException { |
| | | if (CodeRuleLC.RELEASED.getValue().equals(lcStatus) || CodeRuleLC.DISABLED.getValue().equals(lcStatus)) { |
| | | return false; |
| | | } |
| | |
| | | @Override |
| | | public R editSave(CodeRuleDTO codeRuleDTO) throws VciBaseException{ |
| | | VciBaseUtil.alertNotNull(codeRuleDTO, "数据对象", codeRuleDTO.getOid(), "主数据编码规则主键"); |
| | | if(checkCodeRuleRepeat(codeRuleDTO.getId())){ |
| | | if(checkCodeRuleRepeat(codeRuleDTO)){ |
| | | return R.fail("规则编号已存在!"); |
| | | } |
| | | if (!checkEditDelStatus(codeRuleDTO.getLcStatus())) { |
| | |
| | | //将DTO转换为DO |
| | | CodeRule codeRule = selectByOid(codeRuleDTO.getOid()); |
| | | revisionModelUtil.copyFromDTOIgnore(codeRuleDTO, codeRule); |
| | | if(!codeRule.getOwner().equals(codeRuleDTO.getOwner())){ |
| | | codeRule.setOwner(codeRuleDTO.getOwner()); |
| | | } |
| | | DefaultAttrAssimtUtil.updateDefaultAttrAssimt(codeRule); |
| | | return R.status(codeRuleMapper.updateById(codeRule)>0); |
| | | } |
| | |
| | | if (!CodeRuleLC.EDITING.getValue().equals(codeRuleDO.getLcStatus())) { |
| | | return R.fail("非编辑状态的编码规则无法发布"); |
| | | } |
| | | count = codeRuleMapper.update(null,wrapper.set(CodeRule::getLcStatus, CodeRuleLC.RELEASED.getValue())); |
| | | // 发布时将码段类型按照字符串分隔的形式拼接并存储 |
| | | String secTypeStr = codeBasicSecService.listCodeBasicSecByRuleOid(codeRuleDO.getOid()).stream().map(CodeBasicSecVO::getSecType).collect(Collectors.joining(",")); |
| | | count = codeRuleMapper.update(null,wrapper.set(CodeRule::getLcStatus, CodeRuleLC.RELEASED.getValue()).set(CodeRule::getBasicSecTypes,secTypeStr)); |
| | | } else { |
| | | return R.fail("暂不支持的操作类型"); |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 检查相似编码规则,并返回对应的结果 |
| | | * @param oid 主键 |
| | | * @return 执行结果 |
| | | */ |
| | | @Override |
| | | public R checkLikeCodeRule(String oid) throws VciBaseException { |
| | | // 1、查询出当前要发布的规则 |
| | | CodeRuleVO releaseCodeRule = getObjectHasSecByOid(oid); |
| | | // 当前发布的规则不存在码段信息,直接空信息返回 |
| | | if(Func.isEmpty(releaseCodeRule.getSecVOList())){ |
| | | return R.success(""); |
| | | } |
| | | // 2、找出与当前发布的规则码段顺序一致的规则 |
| | | String secTypes = releaseCodeRule.getSecVOList().stream().map(CodeBasicSecVO::getSecType).collect(Collectors.joining(",")); |
| | | // 查询出所有已发布的编码规则中码段类型顺序与当前要发布的规则顺序一致的编码规则,此时已近过滤掉大部分规则,运算量减小 |
| | | List<CodeRule> codeRuleList = codeRuleMapper.selectList(Wrappers.<CodeRule>query().lambda() |
| | | .eq(CodeRule::getLcStatus, CodeRuleLC.RELEASED.getValue()) |
| | | .eq(CodeRule::getBasicSecTypes,secTypes) |
| | | ); |
| | | // 为空,证明不存在类同的编码规则直接返回 |
| | | if(Func.isEmpty(codeRuleList)){ |
| | | return R.success(""); |
| | | } |
| | | // 查询出基础码段列表(按照orderNum升序排序) |
| | | List<CodeRuleVO> codeRuleVOS = codeRuleDO2VOs(codeRuleList, true); |
| | | // 3、各类码段分别进行比对 |
| | | List<CodeRuleVO> lastCodeRule = new ArrayList<>(); |
| | | codeRuleVOS.stream().forEach(item->{ |
| | | List<CodeBasicSecVO> secVOList = item.getSecVOList(); |
| | | boolean flag = true; |
| | | for (int index = 0; index < secVOList.size(); index++) { |
| | | // 当前要发布的规则包含的码段信息 |
| | | CodeBasicSecVO releaseBasicSec = releaseCodeRule.getSecVOList().get(index); |
| | | // 已发布的规则包含的码段信息 |
| | | CodeBasicSecVO releasedBasicSec = secVOList.get(index); |
| | | // 因为码段顺序都是按照OrderNum排序的,所以直接按照下标两两比较就可以了 |
| | | switch (releasedBasicSec.getSecType()){ |
| | | // 属性码段,比对属性和属性所在分类(referCodeClassifyOid) |
| | | case "codeattrsec": |
| | | if(!releasedBasicSec.getReferCodeClassifyOid().equals(releaseBasicSec.getReferCodeClassifyOid())){ |
| | | flag = false; |
| | | } |
| | | break; |
| | | // 可变码段,比对码段长度,编码补位方式和补位时的字符 |
| | | case "codevariablesec": |
| | | if(!(releasedBasicSec.getCodeSecLength().equals(releaseBasicSec.getCodeSecLength()) |
| | | && releasedBasicSec.getCodeFillType().equals(releaseBasicSec.getCodeFillType()) |
| | | && releasedBasicSec.getCodeFillSeparator().equals(releaseBasicSec.getCodeFillSeparator()))){ |
| | | flag = false; |
| | | } |
| | | break; |
| | | // 固定码段比对按升序排序的码值, |
| | | case "codefixedsec": |
| | | if(Func.isNotEmpty(releasedBasicSec.getFixedValueVOList()) && Func.isNotEmpty(releaseBasicSec.getFixedValueVOList())){ |
| | | // 将fixedValue按照逗号分隔拼接起来,以便比较,由于查询时已按照orderNum排过序了,所以不需要再次排序 |
| | | String reledFixedValues = releasedBasicSec.getFixedValueVOList().stream().map(CodeFixedValueVO::getId).collect(Collectors.joining(",")); |
| | | String releFixedValues = releaseBasicSec.getFixedValueVOList().stream().map(CodeFixedValueVO::getId).collect(Collectors.joining(",")); |
| | | if(reledFixedValues.equals(releFixedValues)){ |
| | | flag = false; |
| | | } |
| | | } |
| | | break; |
| | | // 分类码段比对按升序排序码值 |
| | | case "codeclassifysec": |
| | | String classifyValueStr = this.iCodeClassifyValueService.getClassifyValueStr(releasedBasicSec.getOid()); |
| | | String classifyValueStr1 = this.iCodeClassifyValueService.getClassifyValueStr(releaseBasicSec.getOid()); |
| | | if(classifyValueStr.equals(classifyValueStr1)){ |
| | | flag = false; |
| | | } |
| | | break; |
| | | // 日期码段比对日期格式 |
| | | case "codedatesec": |
| | | if(!releasedBasicSec.getCodeDateFormatStr().equals(releaseBasicSec.getCodeDateFormatStr())){ |
| | | flag = false; |
| | | } |
| | | break; |
| | | // 引用码段,比对参照引用的业务类型 |
| | | case "coderefersec": |
| | | if(!releasedBasicSec.getReferBtmId().equals(releaseBasicSec.getReferBtmId())){ |
| | | flag = false; |
| | | } |
| | | break; |
| | | // 层级码段,比对层级类型、层级的值、字符截取类型、取值类型 |
| | | case "codelevelsec": |
| | | if(!(releasedBasicSec.getCodeLevelType().equals(releaseBasicSec.getCodeLevelType()) |
| | | && releasedBasicSec.getCodeLevelValue().equals(releaseBasicSec.getCodeLevelValue()) |
| | | && releasedBasicSec.getValueCutType().equals(releaseBasicSec.getValueCutType()) |
| | | && releasedBasicSec.getCodeGetValueType().equals(releaseBasicSec.getCodeGetValueType()))){ |
| | | flag = false; |
| | | } |
| | | break; |
| | | // 流水码段比对码段的长度 |
| | | case "codeserialsec": |
| | | if(!releasedBasicSec.getCodeFillLength().equals(releaseBasicSec.getCodeFillLength())){ |
| | | flag = false; |
| | | } |
| | | break; |
| | | } |
| | | if (!flag) { |
| | | break; |
| | | } |
| | | } |
| | | // 满足所有码段类型比对条件的规则 |
| | | if (flag) { |
| | | lastCodeRule.add(item); |
| | | } |
| | | }); |
| | | StringBuffer resMsg = new StringBuffer(); |
| | | resMsg.append("存在如下相似规则,是否继续发布?\n"); |
| | | // 最后将结果进行处理并返回 |
| | | lastCodeRule.stream().forEach(item->{ |
| | | resMsg.append(item.getName()); |
| | | resMsg.append(item.getId()); |
| | | resMsg.append("编码规则;\n"); |
| | | }); |
| | | return R.fail(resMsg.toString()); |
| | | } |
| | | |
| | | /** |
| | | * 批量数据对象转换为显示对象 |
| | | * |
| | | * @param codeRules 数据对象列表 |