| | |
| | | package com.vci.ubcs.code.service.impl; |
| | | |
| | | import com.alibaba.cloud.commons.lang.StringUtils; |
| | | 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.vci.ubcs.starter.web.util.BeanUtilForVCI; |
| | | import com.vci.ubcs.starter.web.util.VciBaseUtil; |
| | | import com.vci.ubcs.starter.web.util.WebUtil; |
| | | import com.vci.ubcs.system.cache.NacosConfigCache; |
| | | import com.vci.ubcs.system.entity.Strategy; |
| | | import com.vci.ubcs.system.feign.ISysClient; |
| | | import com.vci.ubcs.system.user.entity.User; |
| | | import com.vci.ubcs.system.user.feign.IUserClient; |
| | | import org.springblade.core.mp.support.Condition; |
| | | import org.springblade.core.mp.support.Query; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.rmi.ServerException; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | |
| | | @Resource |
| | | private RevisionModelUtil revisionModelUtil; |
| | | |
| | | @Value("${user-info.tenant-id}") |
| | | private String tenantId; |
| | | @Value("${user-info.id}") |
| | | private String userId; |
| | | @Resource |
| | | private ICodeFixedValueService codeFixedValueService; |
| | | |
| | | /** |
| | | * 系统服务 |
| | | */ |
| | | @Resource |
| | | private IUserClient userClient; |
| | | |
| | | /** |
| | | * 分页查询 |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public IPage<CodeRuleVO> gridCodeRule(Query query, Map<String,Object> conidtionMap) { |
| | | public IPage<CodeRuleVO> gridCodeRule(Query query, Map<String,Object> conidtionMap) throws VciBaseException { |
| | | //如果等于自己配置的管理组租户id和管理组超管账号,就不需要按照规则所有者来进行查询 |
| | | if(!(AuthUtil.getTenantId().equals(this.tenantId) && AuthUtil.getUserId().toString().equals(this.userId))){ |
| | | /*if(!(AuthUtil.getTenantId().equals(NacosConfigCache.getAdminUserInfo().getTenantId()) |
| | | && AuthUtil.getUserId().toString().equals(NacosConfigCache.getAdminUserInfo().getUserId().toString())) |
| | | ){ |
| | | // 按照规则所有者来查询 |
| | | conidtionMap.put("owner",AuthUtil.getUserId()); |
| | | } |
| | | conidtionMap.put("owner",AuthUtil.getUserId().toString()); |
| | | }*/ |
| | | IPage<CodeRule> codeRuleIPage = this.codeRuleMapper.selectPage(Condition.getPage(query), UBCSCondition.getQueryWrapper(conidtionMap, CodeRule.class)); |
| | | //do转vo同时setLcStatusText生命周期值,并包装成分页对象返回 |
| | | return CodeRuleWrapper.build().pageVO(codeRuleIPage); |
| | |
| | | DefaultAttrAssimtUtil.addDefaultAttrAssimt(codeRule, MdmBtmTypeConstant.CODE_RULE); |
| | | codeRule.setLctid(CODE_RULE_LC); |
| | | codeRule.setLcStatus(FRAMEWORK_RELEASE_EDITING); |
| | | codeRule.setOwnerText(AuthUtil.getUserAccount()+"("+AuthUtil.getNickName()+")"); |
| | | return R.status(codeRuleMapper.insert(codeRule)>0); |
| | | } |
| | | |
| | |
| | | * @return 返回false表示未重复 |
| | | */ |
| | | @Override |
| | | public boolean checkCodeRuleRepeat(CodeRuleDTO codeRuleDTO){ |
| | | public boolean checkCodeRuleRepeat(CodeRuleDTO codeRuleDTO)throws VciBaseException { |
| | | LambdaQueryWrapper<CodeRule> wrapper = Wrappers.<CodeRule>query() |
| | | .lambda().eq(CodeRule::getId, codeRuleDTO.getId()); |
| | | if(AuthUtil.getTenantId().equals(NacosConfigCache.getAdminUserInfo().getTenantId())){ |
| | | wrapper.eq(CodeRule::getTenantId,AuthUtil.getTenantId()); |
| | | } |
| | | // 根据规则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())); |
| | | List<CodeRule> codeRulesList = this.codeRuleMapper.selectList(wrapper); |
| | | if(!codeRulesList.isEmpty()){ |
| | | return codeRulesList.parallelStream().anyMatch(codeRule -> { |
| | | if(StringUtils.isNotBlank(codeRuleDTO.getOid())){ |
| | | // 代表是修改,不是将编号修改相同的编号 |
| | | // 代表是修改规则,不是将编号修改为已存在的的编号 |
| | | return !codeRule.getOid().equals(codeRuleDTO.getOid()); |
| | | }else { |
| | | return true; |
| | |
| | | revisionModelUtil.copyFromDTOIgnore(codeRuleDTO, codeRule); |
| | | if(!codeRule.getOwner().equals(codeRuleDTO.getOwner())){ |
| | | codeRule.setOwner(codeRuleDTO.getOwner()); |
| | | R<User> userR = userClient.userInfoById(Func.toLong(codeRuleDTO.getOwner())); |
| | | if(!userR.isSuccess() || Func.isEmpty(userR.getData())){ |
| | | codeRule.setOwnerText(codeRuleDTO.getOwner()); |
| | | }else{ |
| | | codeRule.setOwnerText(userR.getData().getAccount()+"("+userR.getData().getRealName()+")"); |
| | | } |
| | | } |
| | | DefaultAttrAssimtUtil.updateDefaultAttrAssimt(codeRule); |
| | | return R.status(codeRuleMapper.updateById(codeRule)>0); |
| | |
| | | return R.fail("编码规则已被引用,不允许编辑或删除!"); |
| | | } |
| | | } |
| | | |
| | | List<CodeAllCode> codeDOList = codeAllcodeService.selectByWrapper(Wrappers.<CodeAllCode>query().lambda().eq(CodeAllCode::getCodeRuleOid, codeRuleDTO.getOid())); |
| | | if (!CollectionUtils.isEmpty(codeDOList)) { |
| | | return R.fail("编码规则已生成编码,不允许删除"); |
| | |
| | | * @return true表示已经使用,false表示未被使用 |
| | | */ |
| | | @Override |
| | | public boolean isAlreadyInUse(String oid) { |
| | | public boolean isAlreadyInUse(String oid) throws VciBaseException { |
| | | Collection<CodeClassifyVO> codeClassifyVOS = listUseRangeInCodeClassify(oid); |
| | | if (codeClassifyVOS.size() > 0) { |
| | | return true; |
| | |
| | | * @return 主题库分类使用到该编码规则的所有集合 |
| | | */ |
| | | @Override |
| | | public Collection<CodeClassifyVO> listUseRangeInCodeClassify(String oid) { |
| | | public Collection<CodeClassifyVO> listUseRangeInCodeClassify(String oid) throws VciBaseException { |
| | | List<CodeClassify> codeClassifies = codeClassifyServcie.selectByWrapper(Wrappers.<CodeClassify>query().lambda().eq(CodeClassify::getCodeRuleOid, oid)); |
| | | return CodeClassifyWrapper.build().listVO(codeClassifies); |
| | | } |
| | |
| | | * @param oidCollections 主键的集合 |
| | | * @return 数据对象列表 |
| | | */ |
| | | private List<CodeRule> listCodeRuleDOByOidCollections(Collection<String> oidCollections) { |
| | | private List<CodeRule> listCodeRuleDOByOidCollections(Collection<String> oidCollections) throws VciBaseException { |
| | | List<CodeRule> codeRuleDOList = new ArrayList<CodeRule>(); |
| | | if (!CollectionUtils.isEmpty(oidCollections)) { |
| | | Collection<Collection<String>> oidCollectionsList = VciBaseUtil.switchCollectionForOracleIn(oidCollections); |
| | |
| | | * @return 执行结果 |
| | | */ |
| | | @Override |
| | | public R updateStatus(String oid, String update) { |
| | | public R updateStatus(String oid, String update) throws VciBaseException { |
| | | int count = 0; |
| | | //先查询对象 |
| | | CodeRule codeRuleDO = selectByOid(oid); |
| | |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R cloneCodeRule(CodeRuleDTO codeRuleDTO) { |
| | | public R cloneCodeRule(CodeRuleDTO codeRuleDTO) throws ServerException { |
| | | if(checkCodeRuleRepeat(codeRuleDTO)){ |
| | | return R.fail("规则编号已存在!"); |
| | | } |
| | | VciBaseUtil.alertNotNull(codeRuleDTO, "需要添加的数据对象"); |
| | | CodeRule codeRuleDO = new CodeRule(); |
| | | DefaultAttrAssimtUtil.addDefaultAttrAssimt(codeRuleDO,MdmBtmTypeConstant.CODE_RULE); |
| | | BeanUtilForVCI.copyPropertiesIgnoreCase(codeRuleDTO, codeRuleDO); |
| | | boolean exFlag = codeRuleMapper.insert(codeRuleDO)>0; |
| | | List<CodeBasicSecDTO> secList = codeRuleDTO.getElements(); |
| | | List<CodeBasicSec> codeBasicSecs = new ArrayList<>(); |
| | | secList.forEach(codeBasicSecDTO -> { |
| | | List<CodeBasicSec> codeClassifySec = new ArrayList<>(); |
| | | // 固定码值映射关系 |
| | | Map<String,List<CodeFixedValue>> codeFixedValueMaps = new HashMap<>(); |
| | | for (CodeBasicSecDTO codeBasicSecDTO : secList) { |
| | | codeBasicSecDTO.setPkCodeRule(codeRuleDO.getOid()); |
| | | KeyValue attrKv = codeBasicSecService.checkAttrNullableBySecType(codeBasicSecDTO); |
| | | if (!"success".equals(attrKv.getKey())) { |
| | |
| | | } |
| | | CodeBasicSec codeBasicSecDO = new CodeBasicSec(); |
| | | BeanUtilForVCI.copyPropertiesIgnoreCase(codeBasicSecDTO, codeBasicSecDO); |
| | | codeBasicSecDO.setOid(""); |
| | | codeBasicSecDO.setRevisionOid(""); |
| | | codeBasicSecDO.setNameOid(""); |
| | | String oldBasicOid = codeBasicSecDO.getOid(); //被克隆的码段的oid |
| | | // 判断是否是分类码段 |
| | | if(codeBasicSecDO.getSecType().equals(CodeSecTypeEnum.CODE_CLASSIFY_SEC.getValue())){ |
| | | // 存储旧的码段oid和新的码段的oid的关联关系 |
| | | codeClassifySec.add(codeBasicSecDO); |
| | | continue; |
| | | } |
| | | // 更改创建时间,修改时间等默认值 |
| | | DefaultAttrAssimtUtil.addDefaultAttrAssimt(codeBasicSecDO,MdmBtmTypeConstant.CODE_BASIC_SEC); |
| | | // 固定码段 |
| | | if(codeBasicSecDO.getSecType().equals(CodeSecTypeEnum.CODE_FIXED_SEC.getValue())){ |
| | | // 固定码段存储好oid和码值的关联关系 |
| | | codeFixedValueMaps.put(codeBasicSecDO.getOid(),codeFixedValueService.list(Wrappers.<CodeFixedValue>query() |
| | | .lambda().eq(CodeFixedValue::getCodeFixedSecOid, oldBasicOid) |
| | | )); |
| | | } |
| | | codeBasicSecs.add(codeBasicSecDO); |
| | | }); |
| | | } |
| | | // 处理分类码段的oid,因为oid关联parentClassifyOid,与码值codeClassifyOid,码值又需要通过旧的码段oid来查询,所以不能直接改变oid |
| | | boolean resChangeAssn = codeBasicSecService.changeParentOidAssnOid(codeClassifySec); |
| | | // 将处理过的分类码段也添加进要做新增处理的码段集合中 |
| | | codeBasicSecs.addAll(codeClassifySec); |
| | | // 新增码段 |
| | | boolean exFlag1 = this.codeBasicSecService.saveBatch(codeBasicSecs); |
| | | return R.data(exFlag&&exFlag1); |
| | | // 最终要存入码值表中的,码值对象 |
| | | List<CodeFixedValue> codeFixedDOValues = new ArrayList<>(); |
| | | // 构造码值对象,与码段主键关联关系,以及改变码值的oid |
| | | codeFixedValueMaps.forEach((key, value) -> { |
| | | value.stream().forEach(item -> { |
| | | item.setOid(""); |
| | | item.setCodeFixedSecOid(key); |
| | | DefaultAttrAssimtUtil.updateDefaultAttrAssimt(item); |
| | | codeFixedDOValues.add(item); |
| | | }); |
| | | }); |
| | | boolean exFlag2 = codeFixedValueService.saveBatch(codeFixedDOValues) && resChangeAssn; |
| | | return R.data(exFlag&&exFlag1&&exFlag2); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return 规则的显示对象 |
| | | */ |
| | | @Override |
| | | public CodeRuleVO getObjectHasSecByOid(String oid) { |
| | | public CodeRuleVO getObjectHasSecByOid(String oid) throws VciBaseException { |
| | | CodeRule ruleDO = selectByOid(oid); |
| | | return codeRuleDO2VO(ruleDO, true); |
| | | } |