From 3534b13391b2a6152d0f91b72fda343b13a947cb Mon Sep 17 00:00:00 2001 From: ludc <ludc@vci-tech.com> Date: 星期三, 22 一月 2025 15:55:27 +0800 Subject: [PATCH] 分类码段码值管理查询去除null的情况,分类码段生成编码时去除码值为null的情况 --- Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeRuleServiceImpl.java | 145 ++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 115 insertions(+), 30 deletions(-) diff --git a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeRuleServiceImpl.java b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeRuleServiceImpl.java index 286e404..6381134 100644 --- a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeRuleServiceImpl.java +++ b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeRuleServiceImpl.java @@ -17,11 +17,13 @@ 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.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.baomidou.mybatisplus.extension.toolkit.SqlHelper; import com.vci.ubcs.code.constant.FrameWorkDefaultValueConstant; import com.vci.ubcs.code.dto.CodeBasicSecDTO; @@ -48,6 +50,11 @@ 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; @@ -64,6 +71,7 @@ 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; @@ -110,10 +118,14 @@ @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; /** * 鍒嗛〉鏌ヨ @@ -122,12 +134,15 @@ * @return */ @Override - public IPage<CodeRuleVO> gridCodeRule(Query query, Map<String,Object> conidtionMap) { + public IPage<CodeRuleVO> gridCodeRule(Query query, Map<String,Object> conidtionMap) throws VciBaseException { + //int i = 1 / 0; //濡傛灉绛変簬鑷繁閰嶇疆鐨勭鐞嗙粍绉熸埛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杞瑅o鍚屾椂setLcStatusText鐢熷懡鍛ㄦ湡鍊硷紝骞跺寘瑁呮垚鍒嗛〉瀵硅薄杩斿洖 return CodeRuleWrapper.build().pageVO(codeRuleIPage); @@ -152,6 +167,7 @@ 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); } @@ -161,15 +177,18 @@ * @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())){ - // 浠h〃鏄慨鏀癸紝涓嶆槸灏嗙紪鍙蜂慨鏀圭浉鍚岀殑缂栧彿 + // 浠h〃鏄慨鏀硅鍒欙紝涓嶆槸灏嗙紪鍙蜂慨鏀逛负宸插瓨鍦ㄧ殑鐨勭紪鍙� return !codeRule.getOid().equals(codeRuleDTO.getOid()); }else { return true; @@ -214,6 +233,12 @@ 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); @@ -238,7 +263,6 @@ return R.fail("缂栫爜瑙勫垯宸茶寮曠敤锛屼笉鍏佽缂栬緫鎴栧垹闄わ紒"); } } - List<CodeAllCode> codeDOList = codeAllcodeService.selectByWrapper(Wrappers.<CodeAllCode>query().lambda().eq(CodeAllCode::getCodeRuleOid, codeRuleDTO.getOid())); if (!CollectionUtils.isEmpty(codeDOList)) { return R.fail("缂栫爜瑙勫垯宸茬敓鎴愮紪鐮侊紝涓嶅厑璁稿垹闄�"); @@ -320,7 +344,7 @@ * @return true琛ㄧず宸茬粡浣跨敤锛宖alse琛ㄧず鏈浣跨敤 */ @Override - public boolean isAlreadyInUse(String oid) { + public boolean isAlreadyInUse(String oid) throws VciBaseException { Collection<CodeClassifyVO> codeClassifyVOS = listUseRangeInCodeClassify(oid); if (codeClassifyVOS.size() > 0) { return true; @@ -336,7 +360,7 @@ * @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); } @@ -365,7 +389,7 @@ public Collection<CodeRuleVO> listCodeRuleByOids(Collection<String> oidCollections) throws VciBaseException { VciBaseUtil.alertNotNull(oidCollections, "鏁版嵁瀵硅薄涓婚敭闆嗗悎"); List<CodeRule> codeRuleDOList = listCodeRuleDOByOidCollections(oidCollections); - return CodeRuleWrapper.build().listVO(codeRuleDOList); + return codeRuleDO2VOs(codeRuleDOList,true); } /** @@ -379,8 +403,8 @@ @Override public Collection<CodeRuleVO> listCodeRuleByIds(Collection<String> oidCollections, boolean hasSec) throws VciBaseException { VciBaseUtil.alertNotNull(oidCollections, "鏁版嵁瀵硅薄涓婚敭闆嗗悎"); - List<CodeRule> codeRuleDOList = listCodeRuleDOByOidCollections(oidCollections); - return codeRuleDO2VOs(codeRuleDOList, true); + List<CodeRule> codeRuleDOList = listCodeRuleDOByIdCollections(oidCollections); + return codeRuleDO2VOs(codeRuleDOList, hasSec); } /** @@ -389,12 +413,35 @@ * @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); for (Collection<String> oids : oidCollectionsList) { List<CodeRule> tempDOList = codeRuleMapper.selectBatchIds(oids); + if (!CollectionUtils.isEmpty(tempDOList)) { + codeRuleDOList.addAll(tempDOList); + } + } + } + return codeRuleDOList; + } + + /** + * 浣跨敤瑙勫垯id闆嗗悎鏌ヨ鏁版嵁瀵硅薄 + * + * @param idCollections id鐨勯泦鍚� + * @return 鏁版嵁瀵硅薄鍒楄〃 + */ + private List<CodeRule> listCodeRuleDOByIdCollections(Collection<String> idCollections) throws VciBaseException { + List<CodeRule> codeRuleDOList = new ArrayList<CodeRule>(); + if (!CollectionUtils.isEmpty(idCollections)) { + Collection<Collection<String>> idCollectionsList = VciBaseUtil.switchCollectionForOracleIn(idCollections); + for (Collection<String> ids : idCollectionsList) { + List<CodeRule> tempDOList = codeRuleMapper.selectList( + Wrappers.<CodeRule>query() + .lambda().in(CodeRule::getId,ids) + ); if (!CollectionUtils.isEmpty(tempDOList)) { codeRuleDOList.addAll(tempDOList); } @@ -423,7 +470,7 @@ * @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); @@ -466,14 +513,22 @@ */ @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(); BeanUtilForVCI.copyPropertiesIgnoreCase(codeRuleDTO, codeRuleDO); - boolean exFlag = codeRuleMapper.insert(codeRuleDO)>0; + DefaultAttrAssimtUtil.addDefaultAttrAssimt(codeRuleDO,MdmBtmTypeConstant.CODE_RULE); + boolean exFlag = SqlHelper.retBool(codeRuleMapper.insert(codeRuleDO)); + 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())) { @@ -481,13 +536,43 @@ } CodeBasicSec codeBasicSecDO = new CodeBasicSec(); BeanUtilForVCI.copyPropertiesIgnoreCase(codeBasicSecDTO, codeBasicSecDO); - codeBasicSecDO.setOid(""); - codeBasicSecDO.setRevisionOid(""); - codeBasicSecDO.setNameOid(""); + String oldBasicOid = codeBasicSecDO.getOid(); //琚厠闅嗙殑鐮佹鐨刼id + // 鍒ゆ柇鏄惁鏄垎绫荤爜娈� + 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())){ + // 鍥哄畾鐮佹瀛樺偍濂給id鍜岀爜鍊肩殑鍏宠仈鍏崇郴 + codeFixedValueMaps.put(codeBasicSecDO.getOid(),codeFixedValueService.list(Wrappers.<CodeFixedValue>query() + .lambda().eq(CodeFixedValue::getCodeFixedSecOid, oldBasicOid) + )); + } codeBasicSecs.add(codeBasicSecDO); - }); + } + // 澶勭悊鍒嗙被鐮佹鐨刼id锛屽洜涓簅id鍏宠仈parentClassifyOid锛屼笌鐮佸�糲odeClassifyOid锛岀爜鍊煎張闇�瑕侀�氳繃鏃х殑鐮佹oid鏉ユ煡璇紝鎵�浠ヤ笉鑳界洿鎺ユ敼鍙榦id + 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); } /** @@ -497,7 +582,7 @@ * @return 瑙勫垯鐨勬樉绀哄璞� */ @Override - public CodeRuleVO getObjectHasSecByOid(String oid) { + public CodeRuleVO getObjectHasSecByOid(String oid) throws VciBaseException { CodeRule ruleDO = selectByOid(oid); return codeRuleDO2VO(ruleDO, true); } -- Gitblit v1.9.3