Răsfoiți Sursa

电签位置配置日志记录

lvy 3 săptămâni în urmă
părinte
comite
bfcdcfbf72

+ 79 - 0
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/entity/DqOperationLog.java

@@ -0,0 +1,79 @@
+package org.springblade.manager.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+
+import io.swagger.annotations.ApiModelProperty;
+import org.springblade.core.mp.base.BaseEntity;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.springblade.core.secure.BladeUser;
+import org.springblade.core.secure.utils.AuthUtil;
+
+import java.util.Date;
+
+
+@Data
+@TableName("u_dq_operation_log")
+@EqualsAndHashCode(callSuper = true)
+public class DqOperationLog extends BaseEntity {
+
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty("项目id")
+    private Long projectId;
+
+    @ApiModelProperty("节点pKeyId")
+    private Long nodeId;
+
+    /**
+     * 操作类型
+     */
+    @ApiModelProperty("操作类型, 1:保存,2:删除")
+    private Integer operationType;
+
+    /**
+     * 参数
+     */
+    @ApiModelProperty("参数")
+    private String operationContent;
+
+    /**
+     * 旧内容
+     */
+    @ApiModelProperty("旧内容")
+    private String oldContent;
+
+    /**
+     * 新内容
+     */
+    @ApiModelProperty("新内容")
+    private String newContent;
+
+    /**
+     * textdict_info ids
+     */
+    @ApiModelProperty("textdict_info ids")
+    private String businessId;
+
+    @ApiModelProperty("操作人")
+    private String createUserName;
+
+
+
+    public DqOperationLog() {
+    }
+
+    public DqOperationLog(WbsTreePrivate wbsTreePrivate, BladeUser user, String businessId, Integer type, String param, String oldContent, String newContent) {
+        this.projectId = Long.parseLong(wbsTreePrivate.getProjectId());
+        this.nodeId = wbsTreePrivate.getPKeyId();
+        this.operationType = type;
+        this.operationContent = param;
+        this.createUserName = user.getUserName();
+        this.businessId = businessId;
+        this.oldContent = oldContent;
+        this.newContent = newContent;
+        this.setCreateTime(new Date());
+        this.setCreateUser(user.getUserId());
+        this.setCreateUserName(user.getUserName());
+    }
+}

+ 25 - 6
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/TextdictInfoController.java

@@ -35,14 +35,19 @@ 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.redis.cache.BladeRedis;
+import org.springblade.core.secure.BladeUser;
+import org.springblade.core.secure.utils.AuthUtil;
 import org.springblade.core.secure.utils.SecureUtil;
 import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.utils.*;
+import org.springblade.manager.entity.DqOperationLog;
 import org.springblade.manager.entity.TextdictInfo;
 import org.springblade.manager.entity.WbsTreeContract;
 import org.springblade.manager.entity.WbsTreePrivate;
 import org.springblade.manager.mapper.WbsTreePrivateMapper;
+import org.springblade.manager.service.IDqOperationLogService;
 import org.springblade.manager.service.ITextdictInfoService;
+import org.springblade.manager.service.impl.DqOperationLogServiceImpl;
 import org.springblade.manager.service.impl.WbsTreeContractServiceImpl;
 import org.springblade.manager.utils.ExcelInfoUtils;
 import org.springblade.manager.utils.FileUtils;
@@ -58,10 +63,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -81,6 +83,7 @@ public class TextdictInfoController extends BladeController {
     private final WbsTreeContractServiceImpl wbsTreeContractService;
     private final BladeRedis bladeRedis;
     private final JdbcTemplate jdbcTemplate;
+    private final IDqOperationLogService dqOperationLogService;
 
     /**
      * 详情
@@ -237,9 +240,14 @@ public class TextdictInfoController extends BladeController {
             File writeFile = new File(wbsTreePrivate.getHtmlUrl());
             FileUtil.writeToFile(writeFile, doc.html(), Boolean.parseBoolean("UTF-8"));
         }
-
         //批量删除
         delIds.add(ids);
+        if (textdictInfo.getType() == 6 || textdictInfo.getType() == 2) {
+            JSONObject param = new JSONObject();
+            param.put("ids", ids);
+            param.put("tabId", tabId);
+            dqOperationLogService.save(new DqOperationLog(wbsTreePrivate, AuthUtil.getUser(), String.join( ",", delIds), 2,param.toJSONString(), JSON.toJSONString(query), ""));
+        }
         textdictInfoService.getBaseMapper().deleteBatchIds(delIds);
 
         return R.success("删除成功");
@@ -461,6 +469,8 @@ public class TextdictInfoController extends BladeController {
         String ids = StringUtils.join(pKeyIds, ",");
 
         //删除历史数据
+        String querySql = "select * from m_textdict_info where (tab_id in(SELECT p_key_id from m_wbs_tree_private where project_id='"+wbsTreePrivate.getProjectId()+"' and excel_id='"+wbsTreePrivate.getExcelId()+"' and type=2 and is_deleted=0) or (excel_id="+wbsTreePrivate.getExcelId()+" AND project_id='"+wbsTreePrivate.getProjectId()+"')) and project_id="+wbsTreePrivate.getProjectId()+" and type in(2,6) ";
+        List<TextdictInfo> oldTextdictInfos = jdbcTemplate.query(querySql, new BeanPropertyRowMapper<>(TextdictInfo.class));
         String delSql = "delete from m_textdict_info where (tab_id in(SELECT p_key_id from m_wbs_tree_private where project_id='"+wbsTreePrivate.getProjectId()+"' and excel_id='"+wbsTreePrivate.getExcelId()+"' and type=2 and is_deleted=0) or (excel_id="+wbsTreePrivate.getExcelId()+" AND project_id='"+wbsTreePrivate.getProjectId()+"')) and project_id="+wbsTreePrivate.getProjectId()+" and type in(2,6) ";
         jdbcTemplate.execute(delSql);
 
@@ -468,6 +478,8 @@ public class TextdictInfoController extends BladeController {
         Map<String,String> keyMap = new HashMap<>();
 
         // ------- 查询数据库是否存在 该该电签信息 ---------
+        StringBuilder dqIds = new StringBuilder();
+        List<TextdictInfo> newTextDictInfos = new ArrayList<>();
         for (int i = 0; i < jsonArray.size(); i++) {
             JSONObject jsonObject = jsonArray.getJSONObject(i);
             TextdictInfo textdictInfo = new TextdictInfo();
@@ -514,6 +526,8 @@ public class TextdictInfoController extends BladeController {
             }else{
                 textdictInfoService.save(textdictInfo);
             }
+            newTextDictInfos.add(textdictInfo);
+            dqIds.append(textdictInfo.getId()).append( ",");
             String dqId = "";
             if(keyMap.containsKey(keky)){
                 dqId = keyMap.get(keky)+"||"+textdictInfo.getId();
@@ -557,7 +571,12 @@ public class TextdictInfoController extends BladeController {
             String updateSqlC = "update m_wbs_tree_contract set html_url = '" + replace + "' where p_key_id in (" + cPkeyIdsStr + ") and project_id="+wbsTreePrivate.getProjectId()+"";
             jdbcTemplate.execute(updateSqlC);
         }
-
+        BladeUser user = AuthUtil.getUser();
+        DqOperationLog log = new DqOperationLog(wbsTreePrivate, user, "", 1, dataInfo.toJSONString(), JSON.toJSONString(oldTextdictInfos), JSON.toJSONString(newTextDictInfos));
+        if (dqIds.length() > 1) {
+            log.setBusinessId(dqIds.deleteCharAt(dqIds.length() - 1).toString());
+        }
+        dqOperationLogService.save(log);
         bladeRedis.set("save-eVis-lock:" + SecureUtil.getUserId(), "1");
         bladeRedis.expire("save-eVis-lock:" + SecureUtil.getUserId(), 3);
 

+ 8 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/DqOperationLogMapper.java

@@ -0,0 +1,8 @@
+package org.springblade.manager.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.springblade.manager.entity.DqOperationLog;
+import org.springblade.manager.entity.FormulaBase;
+
+public interface DqOperationLogMapper extends BaseMapper<DqOperationLog> {
+}

+ 25 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/DqOperationLogMapper.xml

@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.springblade.manager.mapper.DqOperationLogMapper">
+
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="resultMap" type="org.springblade.manager.entity.DqOperationLog">
+        <result column="id" property="id"/>
+        <result column="create_time" property="createTime"/>
+        <result column="create_user" property="createUser"/>
+        <result column="create_dept" property="createDept"/>
+        <result column="update_user" property="updateUser"/>
+        <result column="update_time" property="updateTime"/>
+        <result column="status" property="status"/>
+        <result column="is_deleted" property="isDeleted"/>
+        <result column="project_id" property="projectId"/>
+        <result column="node_id" property="nodeId"/>
+        <result column="operation_type" property="operationType"/>
+        <result column="operation_content" property="operationContent"/>
+        <result column="business_id" property="businessId"/>
+        <result column="old_content" property="oldContent"/>
+        <result column="new_content" property="newContent"/>
+    </resultMap>
+
+</mapper>

+ 2 - 2
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/TextdictInfoMapper.xml

@@ -73,8 +73,8 @@
     </select>
     <select id="selectTextDictInfoByIdAndColKeyAndColName" resultMap="textdictInfoVoResultMap">
         select * from m_textdict_info where is_deleted = 0
-        <foreach collection="list" item="item" separator="," open=" and (id,col_key,col_name) in ( " close=")">
-            (#{item.id},#{item.colKey},#{item.colName})
+        <foreach collection="list" item="item" separator="," open=" and (id,col_key) in ( " close=")">
+            (#{item.id},#{item.colKey})
         </foreach>
     </select>
     <update id="updateHtmlUrl">

+ 12 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/service/IDqOperationLogService.java

@@ -0,0 +1,12 @@
+package org.springblade.manager.service;
+
+import org.springblade.core.mp.base.BaseService;
+import org.springblade.manager.entity.*;
+
+
+/**
+ * @author yangyj
+ */
+public interface IDqOperationLogService extends BaseService<DqOperationLog> {
+
+}

+ 13 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/DqOperationLogServiceImpl.java

@@ -0,0 +1,13 @@
+package org.springblade.manager.service.impl;
+
+import org.springblade.core.mp.base.BaseServiceImpl;
+import org.springblade.manager.entity.DqOperationLog;
+import org.springblade.manager.mapper.DqOperationLogMapper;
+import org.springblade.manager.service.IDqOperationLogService;
+import org.springframework.stereotype.Service;
+
+
+@Service
+public class DqOperationLogServiceImpl extends BaseServiceImpl<DqOperationLogMapper, DqOperationLog> implements IDqOperationLogService {
+
+}

+ 54 - 23
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/TextdictInfoServiceImpl.java

@@ -101,12 +101,13 @@ public class TextdictInfoServiceImpl extends ServiceImpl<TextdictInfoMapper, Tex
                     List<TextdictInfo> textdictInfos = new ArrayList<>();
                     if(Func.isNotEmpty(dqid) && dqid.size() > 0){
                         textdict = baseMapper.selectTextdictBYIds(dqid,privateInfo.getProjectId());
+                        // 系统推荐方案一:根据dqId、col_key和col_name查询
                         textdict = getTextdictInfoByDqIdAndKeyName(textdict, dqIdMap, keys, textdictInfos);
                     }else {
-                        textdict = new ArrayList<>();
+                        // 系统推荐方法二:根据excel_id, col_key, col_name查询
+                        textdict = getTextDictInfoBySystem(textdictInfo, keys, textdict, doc, privateInfo, dqid);
                     }
                     if (!keys.isEmpty()) {
-                        textdict = getTextDictInfoBySystem(textdictInfo, keys, textdictInfos, textdict, doc, privateInfo, dqid);
                         TextdictInfoVO temp = null;
                         if (textdict != null && !textdict.isEmpty()) {
                             temp = textdict.get(0);
@@ -120,6 +121,7 @@ public class TextdictInfoServiceImpl extends ServiceImpl<TextdictInfoMapper, Tex
                         }
                         // 查询电签库配置
                         List<TextdictInfoVO> textdictConfigList = iSignConfigService.hasSignConfig(privateInfo.getInitTableName(), keys.keySet(), temp);
+                        saveSignTextDictInfo(textdictInfos, textdictConfigList, keys);
                         if (textdict == null || textdict.isEmpty()) {
                             textdict = textdictConfigList;
                         } else {
@@ -157,31 +159,39 @@ public class TextdictInfoServiceImpl extends ServiceImpl<TextdictInfoMapper, Tex
         return page.setRecords(textdict);
     }
 
-    /**
-     * 系统推荐
-     */
-    @Nullable
-    private List<TextdictInfoVO> getTextDictInfoBySystem(TextdictInfoVO textdictInfo, Map<String, String> keys, List<TextdictInfo> textdictInfos, List<TextdictInfoVO> textdict, Document doc, WbsTreePrivate privateInfo, List<String> dqid) {
-        // 根据excel_id 和col_key 查询
-        List<TextdictInfoVO> textdictList= baseMapper.selectTextdictInfoByExcelIdAndColKey(textdictInfo.getExcelId(), keys.keySet());
-        if (textdictList != null) {
-            Map<String, TextdictInfoVO> map = textdictList.stream().filter(vo -> vo.getColName() != null && vo.getColName().equals(keys.get(vo.getColKey()))).collect(Collectors.toMap(vo -> vo.getColKey() + vo.getSigRoleId(), v -> v, (v1, v2) -> v1));
-            textdictList = new ArrayList<>(map.values());
-            if (!textdictInfos.isEmpty()) {
-                // 保存到数据库,从系统推荐中获取roleId
+    private void saveSignTextDictInfo(List<TextdictInfo> textdictInfos, List<TextdictInfoVO> textdictRecommendedList, Map<String, String> keys) {
+        if (!textdictInfos.isEmpty()) {
+            // 保存到数据库,从系统推荐中获取roleId
+            if (textdictRecommendedList != null && !textdictRecommendedList.isEmpty()) {
+                Map<String, TextdictInfoVO> map = textdictRecommendedList.stream().filter(vo -> vo.getColName() != null && vo.getColName().equals(keys.get(vo.getColKey()))).collect(Collectors.toMap(vo -> vo.getColKey() + vo.getSigRoleId(), v -> v, (v1, v2) -> v1));
+                Collection<TextdictInfoVO> values = map.values();
                 Map<String, TextdictInfo> collect = textdictInfos.stream().collect(Collectors.toMap(info -> info.getColKey() + info.getColName(), v -> v, (v1, v2) -> v1));
-                for (TextdictInfoVO vo : textdictList) {
+                for (TextdictInfoVO vo : values) {
                     TextdictInfo info = collect.get(vo.getColKey() + vo.getColName());
                     if (info != null) {
                         vo.setId(info.getId());
                         vo.setProjectId("0");
                         BeanUtil.copyProperties(vo, info);
+                        vo.setIsSystem(2);
                     }
                 }
                 List<TextdictInfo> list = textdictInfos.stream().filter(info -> StringUtil.hasText(info.getSigRoleId())).collect(Collectors.toList());
                 this.saveBatch( list);
             }
         }
+    }
+
+    /**
+     * 系统推荐
+     */
+    @Nullable
+    private List<TextdictInfoVO> getTextDictInfoBySystem(TextdictInfoVO textdictInfo, Map<String, String> keys,  List<TextdictInfoVO> textdict, Document doc, WbsTreePrivate privateInfo, List<String> dqid) {
+        // 根据excel_id 和col_key 查询
+        List<TextdictInfoVO> textdictList= baseMapper.selectTextdictInfoByExcelIdAndColKey(textdictInfo.getExcelId(), keys.keySet());
+        if (textdictList != null) {
+            Map<String, TextdictInfoVO> map = textdictList.stream().filter(vo -> vo.getColName() != null && vo.getColName().equals(keys.get(vo.getColKey()))).collect(Collectors.toMap(vo -> vo.getColKey() + vo.getSigRoleId(), v -> v, (v1, v2) -> v1));
+            textdictList = new ArrayList<>(map.values());
+        }
         if (textdict.isEmpty()) {
             textdict = textdictList;
             if (textdict != null) {
@@ -212,9 +222,10 @@ public class TextdictInfoServiceImpl extends ServiceImpl<TextdictInfoMapper, Tex
         if (textdict == null) {
             textdict = new ArrayList<>();
         }
-        Map<String, TextdictInfoVO> map = textdict.stream().collect(Collectors.toMap(item -> item.getId() + "", v -> v, (v1, v2) -> v2));
+        Map<String, TextdictInfoVO> idsMap = textdict.stream().collect(Collectors.toMap(item -> item.getId() + "", v -> v, (v1, v2) -> v2));
+        Map<String, TextdictInfoVO> colKeyMap = textdict.stream().collect(Collectors.toMap(item -> item.getId() + "", v -> v, (v1, v2) -> v2));
         dqIdMap.forEach((k, v) -> {
-            if (map.containsKey(k)) {
+            if (idsMap.containsKey(k) || colKeyMap.containsKey(v)) {
                 return;
             }
             Long id = null;
@@ -230,16 +241,36 @@ public class TextdictInfoServiceImpl extends ServiceImpl<TextdictInfoMapper, Tex
             TextdictInfo info = new TextdictInfo();
             info.setId(id);
             info.setColKey(v);
-            info.setColName(colName);
             textdictInfos.add(info);
         });
         if (!textdictInfos.isEmpty()) {
             List<TextdictInfoVO> list = baseMapper.selectTextDictInfoByIdAndColKeyAndColName(textdictInfos);
-            Map<String, TextdictInfoVO> voMap = list.stream().collect(Collectors.toMap(item -> item.getId() + item.getColKey() + item.getColName(), item -> item, (v1, v2) -> v1));
-            Collection<TextdictInfoVO> values = voMap.values();
-            values.forEach(item -> item.setIsSystem(2));
-            textdict.addAll(values);
-            textdictInfos.removeIf(item -> voMap.containsKey(item.getId() + item.getColKey() + item.getColName()));
+            Map<String, List<TextdictInfoVO>> voMap = list.stream().collect(Collectors.groupingBy(item -> item.getId() + item.getColKey()));
+            List<TextdictInfoVO> tempList = new ArrayList<>();
+            voMap.forEach((key, values) -> {
+                TextdictInfoVO temp = null;
+                if (values.size() == 1) {
+                    temp = values.get(0);
+                } else {
+                    for (TextdictInfoVO value : values) {
+                        String colName = keys.get(value.getColKey());
+                        if (colName == null || colName.equals(value.getColName())) {
+                            temp = value;
+                            break;
+                        }
+                    }
+                    if (temp == null) {
+                        // 出现次数最多
+                        Map<String, List<TextdictInfoVO>> collect = values.stream().collect(Collectors.groupingBy(TextdictInfoVO::getColName));
+                        temp = collect.entrySet().stream().max(Comparator.comparingInt(entry -> entry.getValue().size())).get().getValue().get(0);
+                    }
+                }
+                temp.setIsSystem(2);
+                tempList.add(temp);
+                colKeyMap.put(temp.getColKey(), temp);
+            });
+            textdict.addAll(tempList);
+            textdictInfos.removeIf(item -> voMap.containsKey(item.getId() + item.getColKey()) || colKeyMap.containsKey(item.getColKey()));
         }
         return textdict;
     }