From bce3fcf05020405e33199706c3d91e9b9a71bd39 Mon Sep 17 00:00:00 2001
From: ludc
Date: 星期五, 01 十二月 2023 12:42:05 +0800
Subject: [PATCH] 关键属性查重特殊字符转义添加

---
 Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmEngineServiceImpl.java |  126 ++++++++++++++++++++++++++---------------
 1 files changed, 80 insertions(+), 46 deletions(-)

diff --git a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmEngineServiceImpl.java b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmEngineServiceImpl.java
index 76d26b5..094677d 100644
--- a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmEngineServiceImpl.java
+++ b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmEngineServiceImpl.java
@@ -1,5 +1,6 @@
 package com.vci.ubcs.code.service.impl;
 
+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;
@@ -42,6 +43,8 @@
 import com.vci.ubcs.starter.revision.model.TreeWrapperOptions;
 import com.vci.ubcs.starter.revision.service.RevisionModelUtil;
 import com.vci.ubcs.starter.util.MdmBtmTypeConstant;
+import com.vci.ubcs.starter.util.SaveLogUtil;
+import com.vci.ubcs.starter.util.SpecialCharacterConverter;
 import com.vci.ubcs.starter.util.UBCSSqlKeyword;
 import com.vci.ubcs.starter.web.constant.QueryOptionConstant;
 import com.vci.ubcs.starter.web.constant.RegExpConstant;
@@ -62,12 +65,14 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springblade.core.cache.utils.CacheUtil;
+import org.springblade.core.log.annotation.OperateLog;
 import org.springblade.core.log.exception.ServiceException;
 import org.springblade.core.secure.utils.AuthUtil;
 import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.utils.DateUtil;
 import org.springblade.core.tool.utils.Func;
 import org.springblade.core.tool.utils.StringPool;
+import org.springblade.core.tool.utils.StringUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.cache.Cache;
@@ -346,8 +351,15 @@
 	 */
 	@Autowired
 	private IMDMIFlowAttrClient imdmiFlowAttrClient;
-//	@Autowired
-//	private CodeOsbtmtypeMapper codeOsbtmtypeMapper;----
+
+	//	@Autowired
+	//	private CodeOsbtmtypeMapper codeOsbtmtypeMapper;
+
+	/**
+	 * 鏃ュ織淇濆瓨宸ュ叿绫�
+	 */
+	@Autowired
+	private SaveLogUtil saveLogUtil;
 
 
     /**
@@ -410,39 +422,52 @@
     @Transactional
     @Override
     public void changeStatus(BaseModelDTO baseModelDTO) {
-        VciBaseUtil.alertNotNull(baseModelDTO, "鏁版嵁淇℃伅", baseModelDTO.getOid(), "涓婚敭", baseModelDTO.getBtmname(), "涓氬姟绫诲瀷", baseModelDTO.getLcStatus(), "鐩爣鐘舵��");
-        List<String> oids = VciBaseUtil.str2List(baseModelDTO.getOid());
-        List<BaseModel> baseModels = new ArrayList<>();
-        baseModels = selectByTypeAndOid(baseModelDTO.getBtmname(), baseModelDTO.getOid());
-        if (baseModels.size() == 0) {
-            throw new VciBaseException("鏈煡璇㈠埌鐩稿叧鏁版嵁銆�");
-        }
-        //杩橀渶瑕佷慨鏀筧llCode鐨勭敓鍛藉懆鏈�
-        QueryWrapper<CodeAllCode> allCodeWrapper = new QueryWrapper<>();
-        allCodeWrapper.eq("createcodebtm", baseModelDTO.getBtmname());
-        allCodeWrapper.in("createcodeoid", oids);
-        List<CodeAllCode> codeCbos = codeAllCodeService.selectByWrapper(allCodeWrapper);// 鍥炴敹闇�瑕佷笟鍔℃暟鎹垹闄�
-        if (CodeDefaultLC.TASK_BACK.getValue().equals(baseModelDTO.getLcStatus())) {
-            R<List<BtmTypeVO>> listR = btmTypeClient.selectByIdCollection(Collections.singletonList(baseModelDTO.getBtmname()));
-            if (!listR.isSuccess() || listR.getData().size() == 0) {
-                throw new VciBaseException("浼犲叆涓氬姟绫诲瀷鏈煡璇㈠埌鐩稿簲琛ㄥ崟锛岃妫�鏌ワ紒");
-            }
-			// 鐩存帴鍒犻櫎锛屼笉缁欑姸鎬�
-			commonsMapper.deleteByTaleAndOid(listR.getData().get(0).getTableName(), VciBaseUtil.toInSql(baseModelDTO.getOid()));
-			// commonsMapper.updateByTaleAndOid(listR.getData().get(0).getTableName(), VciBaseUtil.toInSql(baseModelDTO.getOid()),CodeDefaultLC.TASK_BACK.getValue());
-        } else {
-            for (BaseModel baseModel : baseModels) {
-                baseModel.setLcStatus(baseModelDTO.getLcStatus());
-            }
-			R r = updateBatchByBaseModel(baseModelDTO.getBtmname(), baseModels);
-			if(!r.isSuccess()){
-				throw new VciBaseException("鏇存柊鏁版嵁鍑洪敊锛岄噸璇曪紒"+r.getMsg());
+		try {
+			VciBaseUtil.alertNotNull(baseModelDTO, "鏁版嵁淇℃伅", baseModelDTO.getOid(), "涓婚敭", baseModelDTO.getBtmname(), "涓氬姟绫诲瀷", baseModelDTO.getLcStatus(), "鐩爣鐘舵��");
+			List<String> oids = VciBaseUtil.str2List(baseModelDTO.getOid());
+			List<BaseModel> baseModels = new ArrayList<>();
+			baseModels = selectByTypeAndOid(baseModelDTO.getBtmname(), baseModelDTO.getOid());
+			if (baseModels.size() == 0) {
+				throw new VciBaseException("鏈煡璇㈠埌鐩稿叧鏁版嵁銆�");
 			}
+			//杩橀渶瑕佷慨鏀筧llCode鐨勭敓鍛藉懆鏈�
+			QueryWrapper<CodeAllCode> allCodeWrapper = new QueryWrapper<>();
+			allCodeWrapper.eq("createcodebtm", baseModelDTO.getBtmname());
+			allCodeWrapper.in("createcodeoid", oids);
+			List<CodeAllCode> codeCbos = codeAllCodeService.selectByWrapper(allCodeWrapper);// 鍥炴敹闇�瑕佷笟鍔℃暟鎹垹闄�
+			if (CodeDefaultLC.TASK_BACK.getValue().equals(baseModelDTO.getLcStatus())) {
+				R<List<BtmTypeVO>> listR = btmTypeClient.selectByIdCollection(Collections.singletonList(baseModelDTO.getBtmname()));
+				if (!listR.isSuccess() || listR.getData().size() == 0) {
+					throw new VciBaseException("浼犲叆涓氬姟绫诲瀷鏈煡璇㈠埌鐩稿簲琛ㄥ崟锛岃妫�鏌ワ紒");
+				}
+				// 鐩存帴鍒犻櫎锛屼笉缁欑姸鎬�
+				commonsMapper.deleteByTaleAndOid(listR.getData().get(0).getTableName(), VciBaseUtil.toInSql(baseModelDTO.getOid()));
+				// commonsMapper.updateByTaleAndOid(listR.getData().get(0).getTableName(), VciBaseUtil.toInSql(baseModelDTO.getOid()),CodeDefaultLC.TASK_BACK.getValue());
+			} else {
+				for (BaseModel baseModel : baseModels) {
+					baseModel.setLcStatus(baseModelDTO.getLcStatus());
+				}
+				R r = updateBatchByBaseModel(baseModelDTO.getBtmname(), baseModels);
+				if(!r.isSuccess()){
+					throw new VciBaseException("鏇存柊鏁版嵁鍑洪敊锛岄噸璇曪紒"+r.getMsg());
+				}
+			}
+			for (CodeAllCode codeCbo : codeCbos) {
+				codeCbo.setLcStatus(baseModelDTO.getLcStatus());
+			}
+			codeAllCodeService.updateBatchById(codeCbos);
+
+			//璁板綍鏃ュ織淇℃伅
+			saveLogUtil.operateLog(
+				CodeDefaultLC.getTextByValue(baseModelDTO.getLcStatus()),
+				false,
+				JSON.toJSONString(baseModels)
+			);
+		}catch (Exception e){
+			// 鎻掑叆鏇存敼鏃ュ織璁板綍
+			saveLogUtil.operateLog(CodeDefaultLC.getTextByValue(baseModelDTO.getLcStatus()),true,e.getMessage());
+			throw e;
 		}
-        for (CodeAllCode codeCbo : codeCbos) {
-            codeCbo.setLcStatus(baseModelDTO.getLcStatus());
-        }
-        codeAllCodeService.updateBatchById(codeCbos);
     }
 
 	/**
@@ -767,6 +792,7 @@
                 sql[0] += " and oid != '" + orderDTO.getCopyFromVersion() + "'";
             }
             sql[0] += " and lastR = '1' and lastV = '1' ";
+			// 鑾峰彇涓嶅弬涓庢牎楠岀殑鍒嗙被oid
 			String isParticipateCheckOids = classifyService.selectLeafByParentClassifyOid(classifyFullInfo.getTopClassifyVO().getOid(), classifyFullInfo.getCurrentClassifyVO().getOid());
 			if(Func.isNotEmpty(isParticipateCheckOids)){
 				sql[0] += " and codeclsfid not in(" + isParticipateCheckOids + ")";
@@ -886,7 +912,7 @@
 	 * @param authUser
 	 * @return
 	 */
-	private String addSaveBZCode(CodeBZApplyDTO codeBZApplyDTO, boolean authUser) throws Exception {
+	public String addSaveBZCode(CodeBZApplyDTO codeBZApplyDTO, boolean authUser) throws Exception {
 		String code="";
 		VciBaseUtil.alertNotNull(codeBZApplyDTO.getCodeClassifyOid(), "涓婚搴撳垎绫荤殑涓婚敭",
 			codeBZApplyDTO.getTemplateOid(), "妯℃澘鐨勪富閿�", codeBZApplyDTO.getCodeRuleOid(), "缂栫爜瑙勫垯鐨勪富閿�");
@@ -961,21 +987,20 @@
 		LinkedList<CodeOrderSecDTO> newSecDTOList=new LinkedList<>();
 		changeCodeOrderSecDTO(ruleVO,secDTOS,oldCode,newSecDTOList);//鏍规嵁瑕佹眰閲嶆柊绠楃爜娈电爜鍊�
 		if(!codeBZApplyDTO.isEditSeries()){//鍙樻洿涓烘爣鍑�
-			if(!codeBZApplyDTO.isSeries()){//濡傛灉鏄〃鍑嗭紝鍒欓渶瑕佸皢绯诲垪濂芥祦姘寸疆涓簄ull
+			//if(!codeBZApplyDTO.isSeries()){//濡傛灉鏄〃鍑嗭紝鍒欓渶瑕佸皢绯诲垪濂芥祦姘寸疆涓簄ull
 				//鍥犱负鏄爣鍑嗗垯鎺у埗鐮佹涓殑绯诲垪娴佹按鐮佹鍊间负绌�
 				newSecDTOList.stream().forEach(codeOrderSecDTO -> {
 					if(codeCodeBasicSecMap.containsKey(codeOrderSecDTO.getSecOid())&&codeCodeBasicSecMap.get(codeOrderSecDTO.getSecOid()).getName().equals(secName)){
 						codeOrderSecDTO.setSecValue("");
 					}
 				});
-			}
+			//}
 			orderDTO.setSecDTOList(newSecDTOList);
 			return createDataBZ(orderDTO,ruleVO,authUser);
 		}else{//鍙樻洿涓虹郴鍒�.鍒欐寜鐓ч�昏緫鍘诲鐞�
-
-
+			orderDTO.setSecDTOList(newSecDTOList);
+			return createDataBZ(orderDTO,ruleVO,authUser);
 		}
-		return "";
 	}
 	private String createDataBZ(CodeOrderDTO orderDTO,	CodeRuleVO ruleVO,boolean authUser) throws Exception {
 		CodeClassifyFullInfoBO classifyFullInfo = classifyService.getClassifyFullInfo(orderDTO.getCodeClassifyOid());
@@ -1113,6 +1138,7 @@
 	 * @return
 	 * @throws Exception
 	 */
+	@Override
 	public String addSaveBZCodeNotauthUser(CodeBZApplyDTO codeBZApplyDTO, boolean authUser) throws Exception {
 		return	addSaveBZCode(codeBZApplyDTO,authUser);
 	}
@@ -1169,12 +1195,12 @@
                     temp = "%s";
                 }
                 queryKey = String.format(temp, "nvl("+ "t." + attrId +",'/')");
-                queryValue = String.format(temp, "'" + (trim ? value.trim() : value) + "'");
+                queryValue = String.format(temp, "'" + (trim ? SpecialCharacterConverter.escapeSpecialCharacters(value.trim()):SpecialCharacterConverter.escapeSpecialCharacters(value)) + "'");
                 conditionMap.put(queryKey, queryValue);
             } else {
 				if(StringUtils.isNotBlank(value)) {
 					//涓虹┖鐨勬椂鍊欎笉浠h〃涓嶆牎楠岋紝鍙槸涓嶅幓闄ょ浉鍏崇殑淇℃伅
-					conditionMap.put("nvl("+ "t." + attrId+",'/')", "'" + value + "'");
+					conditionMap.put("nvl("+ "t." + attrId+",'/')", "'" + SpecialCharacterConverter.escapeSpecialCharacters(value) + "'");
 				}else{
 					conditionMap.put("t." + attrId, QueryOptionConstant.ISNULL);
 				}
@@ -2448,7 +2474,6 @@
 				return getSqlByValue(key, value, attrVOMap,btmType);
 			}
 		}*/
-
     }
 
     /**
@@ -2705,6 +2730,7 @@
         cbo.setLastModifyTime(new Date());
         cbo.setLastModifier(String.valueOf(AuthUtil.getUser().getAccount()));
 		R r = updateBatchByBaseModel(classifyFullInfo.getTopClassifyVO().getBtmTypeId(), Collections.singletonList(cbo));
+
 		if(!r.isSuccess()){
 			throw new ServiceException(r.getMsg());
 		}
@@ -3079,11 +3105,18 @@
 		oldCbo.setLastModifier(String.valueOf(AuthUtil.getUser().getAccount()));
 		oldCbo.setLastModifyTime(new Date());
         try {
+			// 淇敼鐗堟鍙�
 			updateBatchByBaseModel(oldCbo.getBtmname(), Collections.singletonList(oldCbo));
+			// 鎻掑叆鏂扮殑鏁版嵁
             insertBatchByType(cbo.getBtmname(), Collections.singletonList(cbo));
-        } catch (Exception vciError) {
-            throw new VciBaseException("鏁版嵁鏇存敼淇濆瓨鍑洪敊浜�", new String[0], vciError);
-        }
+			// 璁板綍鏁版嵁鏇存敼鏃ュ織
+			saveLogUtil.operateLog("鏁版嵁鏇存敼",false, StringUtil.format("{}\n淇敼涓�:\n{}",JSON.toJSONString(Collections.singletonList(oldCbo)),JSON.toJSONString(Collections.singletonList(cbo))));
+		} catch (Exception vciError) {
+			// 璁板綍鏁版嵁鏇存敼鎶ラ敊鏃剁殑鏃ュ織
+			saveLogUtil.operateLog("鏁版嵁鏇存敼",true,vciError.getMessage());
+			throw new VciBaseException("鏁版嵁鏇存敼淇濆瓨鍑洪敊浜�", new String[0], vciError);
+		}
+
         batchSaveSelectChar(templateVO, Collections.singletonList(cbo));
     }
 
@@ -4520,7 +4553,8 @@
         toBo.setVersionSeq(Integer.valueOf(nextRevision.get("VERSIONSEQ").toString()));
         toBo.setVersionValue(nextRevision.get("VERSIONVAL").toString());
         toBo.setLctid(fromBo.getLctid());
-        toBo.setLcStatus("Editing");
+        //toBo.setLcStatus("Editing");
+		toBo.setLcStatus(CodeDefaultLC.RELEASED.getValue());
         toBo.setId(fromBo.getId());
         toBo.setName(fromBo.getName());
         toBo.setDescription(fromBo.getDescription());

--
Gitblit v1.9.3