From 04b4676f4f8f2674a0fdd52624c417d600f6f06b Mon Sep 17 00:00:00 2001
From: 田源 <lastanimals@163.com>
Date: 星期二, 05 十二月 2023 16:19:30 +0800
Subject: [PATCH] 整合代码
---
Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/CodeRuleServiceImpl.java | 140 +++++++++++++++++++++++++++++++++++++---------
1 files changed, 112 insertions(+), 28 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 be398aa..6b963c6 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,6 +17,7 @@
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;
@@ -48,6 +49,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 +70,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 +117,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 +133,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 +166,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 +176,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 +232,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);
@@ -319,7 +343,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;
@@ -335,7 +359,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);
}
@@ -364,7 +388,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);
}
/**
@@ -378,8 +402,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);
}
/**
@@ -388,12 +412,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);
}
@@ -422,7 +469,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);
@@ -465,14 +512,21 @@
*/
@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())) {
@@ -480,13 +534,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);
}
/**
@@ -496,7 +580,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