Browse Source

后管关联清表保留原有配置

lvy 1 ngày trước cách đây
mục cha
commit
15a61fb80c

+ 3 - 3
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/entity/TextdictInfo.java

@@ -85,12 +85,12 @@ public class TextdictInfo implements Serializable {
     /**
      * 偏移坐标X
      */
-    private double pyzbx;
+    private Double pyzbx;
 
     /**
      * 偏移坐标Y
      */
-    private double pyzby;
+    private Double pyzby;
 
     /**
      * excelId
@@ -120,5 +120,5 @@ public class TextdictInfo implements Serializable {
     /**
      * 是否需要时间 1需要 0不需要
      */
-    private int timeState;
+    private Integer timeState;
 }

+ 3 - 0
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/TextdictInfoVO.java

@@ -38,4 +38,7 @@ public class TextdictInfoVO extends TextdictInfo {
 
     @ApiModelProperty("是否引用系统级电签配置,1 系统级,0 项目级")
     private Integer isSystem = 0;
+
+    @ApiModelProperty("元素是否匹配, 1:匹配, 0:不匹配")
+    private Integer isMatch = 1;
 }

+ 110 - 1
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/ExcelTabController.java

@@ -11,6 +11,7 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import com.google.gson.Gson;
 import com.spire.xls.*;
@@ -669,7 +670,7 @@ public class ExcelTabController extends BladeController {
                 }
             }
         }
-
+        saveOldHtmlConfig(aPrivate, doc);
         File writefile = new File(thmlUrl);
         FileUtil.writeToFile(writefile, doc.html(), Boolean.parseBoolean("UTF-8"));
 
@@ -715,6 +716,114 @@ public class ExcelTabController extends BladeController {
         return R.success("关联成功");
     }
 
+    public void saveOldHtmlConfig(WbsTreePrivate wbsTreePrivate, Document doc){
+        // 获取原默认值配置
+        List<TextdictInfoVO> defaultConfigs = new ArrayList<>();
+        {
+            IPage<TextdictInfoVO> result = textdictInfoService.analysisHtmlDefault(wbsTreePrivate.getPKeyId() + "");
+            if (result != null && result.getRecords() != null && !result.getRecords().isEmpty()) {
+                defaultConfigs.addAll(result.getRecords());
+            }
+        }
+        // 将原配置信息写入到新的html中,先通过colKey匹配,再通过colName匹配。如果匹配不上,则保存到数据库。后续手动配置、修改
+        defaultConfigs.removeIf(config -> {
+            String colKey = config.getColKey();
+            Element element = null;
+            String colName = config.getColName();
+            if (colKey != null && !colKey.isEmpty()) {
+                element = doc.select("[keyname='" + config.getColKey() + "']").first();
+                if (element != null && colName != null) {
+                    String placeholder = element.attr("placeholder");
+                    if (!StringCNUtils.compareStringIgnoreSpaceAndSymbols(placeholder, colName)) {
+                        element = null;
+                    }
+                }
+            }
+            if (element != null) {
+                element.removeAttr("defText");
+                element.attr("defText", config.getSigRoleName());
+                return true;
+            }
+            return config.getId() != null && config.getId() > 0;
+        });
+        if (!defaultConfigs.isEmpty()) {
+            List<TextdictInfo> saves = new ArrayList<>();
+            defaultConfigs.forEach(config -> {
+                TextdictInfo info = new TextdictInfo();
+                info.setId(SnowFlakeUtil.getId());
+                info.setTabId(wbsTreePrivate.getPKeyId() + "");
+                info.setExcelId(wbsTreePrivate.getExcelId() == null ? null : wbsTreePrivate.getExcelId() + "");
+                info.setType(config.getType());
+                info.setColKey(config.getColKey());
+                info.setColName(config.getColName());
+                info.setSigRoleName(config.getSigRoleName());
+                info.setProjectId(wbsTreePrivate.getProjectId());
+                info.setName("编辑默认值");
+                saves.add( info);
+            });
+            textdictInfoService.saveOrUpdateBatch(saves);
+        }
+        // 获取原电签配置
+        TextdictInfoVO textdictInfo = new TextdictInfoVO();
+        textdictInfo.setProjectId(wbsTreePrivate.getProjectId());
+        textdictInfo.setTabId(wbsTreePrivate.getPKeyId() + "");
+        textdictInfo.setShowType(1);
+        textdictInfo.setType(2);
+        IPage<TextdictInfoVO> signConfigs = textdictInfoService.selectTextdictInfoPage(new Page<>(1, 1000), textdictInfo);
+        if (signConfigs != null && signConfigs.getRecords() != null && !signConfigs.getRecords().isEmpty()) {
+            List<TextdictInfoVO> signConfigList = signConfigs.getRecords();
+            signConfigList.removeIf(config -> {
+                String colKey = config.getColKey();
+                Element element = null;
+                if (colKey != null && !colKey.isEmpty()) {
+                    element = doc.select("[keyname='" + config.getColKey() + "']").first();
+                    if (element == null && colKey.contains("__")) {
+                        element = doc.select("[keyname*='" + colKey.split("__")[0] + "']").first();
+                        String point = colKey.split("__")[1];
+                        if (element == null && point.contains("_")) {
+                            String[] split = point.split("_");
+                            element = doc.select("[trindex='" + split[0] + "'],[tdindex='" + split[1] + "']").first();
+                        }
+                    }
+                }
+                if (element == null) {
+                    element = doc.select("[placeholder='" + config.getColName() + "']").first();
+                }
+                if (element != null) {
+                    int i = 5;
+                    Element parent = element.parent();
+                    while (i > 0 && parent != null) {
+                        if (parent.hasAttr("title") || parent.hasAttr("dqid")) {
+                            String dqid = element.attr("dqid");
+                            if (dqid != null && !dqid.isEmpty()) {
+                                element.attr("dqid", dqid + "||" + config.getId());
+                            } else {
+                                element.attr("dqid", config.getId() + "");
+                            }
+                            return true;
+                        }
+                        parent = parent.parent();
+                        i--;
+                    }
+                }
+                return false;
+            });
+            if (!signConfigList.isEmpty()) {
+                String ids = signConfigList.stream().map(config -> config.getId() + "").collect(Collectors.joining("||"));
+                Element table = doc.select("table").first();
+                if (table != null) {
+                    Element tr = table.select("tr").last();
+                    if (tr != null) {
+                        Element td = tr.select("td").last();
+                        if (td != null) {
+                            td.attr("dqid", ids);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
 
     /**
      * 质检 获取html接口

+ 105 - 55
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/TextdictInfoController.java

@@ -21,6 +21,7 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import io.swagger.annotations.*;
 import lombok.AllArgsConstructor;
@@ -165,6 +166,21 @@ public class TextdictInfoController extends BladeController {
                     String colKey,
                     Integer type) throws FileNotFoundException {
         if(type != null && type == 4){
+            if (ids != null && !ids.isEmpty()) {
+                String[] split = ids.split(",");
+                List<Long> removeIds = new ArrayList<>();
+                for (String id : split) {
+                    if (StringUtil.isNumeric(id)) {
+                        long lid = Long.parseLong(id);
+                        if (lid > 0) {
+                            removeIds.add(lid);
+                        }
+                    }
+                }
+                if (!removeIds.isEmpty()) {
+                    textdictInfoService.remove(Wrappers.<TextdictInfo>lambdaQuery().in(TextdictInfo::getId, removeIds).eq(TextdictInfo::getTabId, tabId).eq(TextdictInfo::getType, 4));
+                }
+            }
             textdictInfoService.removeHtmlDefault(tabId,colKey);
             return R.success("删除成功");
         }
@@ -247,8 +263,10 @@ public class TextdictInfoController extends BladeController {
             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.update(Wrappers.<TextdictInfo>lambdaUpdate().in(TextdictInfo::getId, delIds).eq(TextdictInfo::getProjectId, wbsTreePrivate.getProjectId()).set(TextdictInfo::getIsDeleted, 1));
+        } else {
+            textdictInfoService.getBaseMapper().deleteBatchIds(delIds);
         }
-        textdictInfoService.getBaseMapper().deleteBatchIds(delIds);
 
         return R.success("删除成功");
     }
@@ -436,6 +454,9 @@ public class TextdictInfoController extends BladeController {
             throw new ServiceException("请勿重复提交,请3秒后再尝试");
         }
         JSONArray jsonArray = dataInfo.getJSONArray("dataInfo");
+        if (jsonArray == null || jsonArray.isEmpty()) {
+            return R.success("操作成功");
+        }
 
         // -------- 移除所有html 的dqid -----
         Long tableId = dataInfo.getLong("tabId"); //节点pkid
@@ -446,101 +467,104 @@ public class TextdictInfoController extends BladeController {
         // 样式集合
         Document doc = Jsoup.parse(htmlString);
         //解析
-        Element table = doc.select("table").first();
-        Elements trs = table.select("tr");
-        //解析
         Elements onlyInfo = doc.select("[:readonly]");
-        if (onlyInfo != null && onlyInfo.size() >= 1) {
+        if (onlyInfo != null && !onlyInfo.isEmpty()) {
             for (Element element : onlyInfo) {
                 element.removeAttr(":readonly");
             }
         }
         Elements tryInfo = doc.select("td[dqid]");
-        if (tryInfo != null && tryInfo.size() >= 1) {
+        if (tryInfo != null && !tryInfo.isEmpty()) {
             for (Element element : tryInfo) {
                 element.removeAttr("dqid");
             }
         }
-        if (jsonArray == null || jsonArray.size() == 0) {
-            return R.success("操作成功");
-        }
-
-        List<WbsTreePrivate> wbsTreePrivatesEqual = wbsTreePrivateMapper.selectList(Wrappers.<WbsTreePrivate>lambdaQuery()
-                .eq(WbsTreePrivate::getProjectId, wbsTreePrivate.getProjectId())
-                .eq(WbsTreePrivate::getIsDeleted, 0)
-                .eq(WbsTreePrivate::getExcelId, wbsTreePrivate.getExcelId()));
-        List<Long> pKeyIds = wbsTreePrivatesEqual.stream().map(WbsTreePrivate::getPKeyId).collect(Collectors.toList());
-        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);
 
+        // 查询历史数据
+        Map<String, TextdictInfo> oldTextDictInfoMap = new HashMap<>();
+        List<TextdictInfoVO> oldTextDictInfos = new ArrayList<>();
+        TextdictInfoVO param = new TextdictInfoVO();
+        param.setProjectId(wbsTreePrivate.getProjectId());
+        param.setTabId(wbsTreePrivate.getPKeyId() + "");
+        param.setShowType(1);
+        param.setType(2);
+        IPage<TextdictInfoVO> signConfigs = textdictInfoService.selectTextdictInfoPage(new Page<>(1, 1000), param);
+        if (signConfigs != null && signConfigs.getRecords() != null && !signConfigs.getRecords().isEmpty()) {
+            oldTextDictInfos = signConfigs.getRecords();
+            oldTextDictInfoMap = oldTextDictInfos.stream().collect(Collectors.toMap(item -> item.getProjectId() + item.getId(), textdictInfo -> textdictInfo));
+        }
         // 由于要实现电签 一对多(1个key 对应多个电签Id)
         Map<String,String> keyMap = new HashMap<>();
+        //解析
+        Element table = doc.select("table").first();
+        Elements trs = table.select("tr");
 
         // ------- 查询数据库是否存在 该该电签信息 ---------
         StringBuilder dqIds = new StringBuilder();
         List<TextdictInfo> newTextDictInfos = new ArrayList<>();
+        List<TextdictInfo> updateList = new ArrayList<>();
+        List<TextdictInfo> addList = new ArrayList<>();
         for (int i = 0; i < jsonArray.size(); i++) {
             JSONObject jsonObject = jsonArray.getJSONObject(i);
-            TextdictInfo textdictInfo = new TextdictInfo();
-            String keky = jsonObject.getString("colKey");
-
-            String[] trtd = keky.split("__")[1].split("_");
-            Element element = trs.get(Integer.parseInt(trtd[0])).select("td").get(Integer.parseInt(trtd[1]));
+            String key = jsonObject.getString("colKey");
+            String sigRoleId = jsonObject.getString("sigRoleId");
 
-            String id = element.children().get(0).attr("keyname");
-            if (jsonObject.containsKey("id")) {
-                textdictInfo.setId(jsonObject.getLong("id"));
+            TextdictInfo textdictInfo = new TextdictInfo();
+            Long id = jsonObject.getLong("id");
+            if (id != null && id > 0) {
+                textdictInfo.setId(id);
             } else {
                 textdictInfo.setId(SnowFlakeUtil.getId());
                 textdictInfo.setIsDeleted(0);
             }
             textdictInfo.setName("电签位置配置");
             textdictInfo.setType(jsonObject.getInteger("type"));
-            textdictInfo.setColKey(id);
-            textdictInfo.setSigRoleId(jsonObject.getString("sigRoleId"));
-
+            textdictInfo.setSigRoleId(sigRoleId);
             textdictInfo.setTabId(tableId.toString());
             textdictInfo.setExcelId(wbsTreePrivate.getExcelId() + "");
-
             textdictInfo.setColName(jsonObject.getString("colName"));
             textdictInfo.setSigRoleName(jsonObject.getString("sigRoleName"));
             textdictInfo.setPyzbx(jsonObject.getDouble("pyzbx"));
             textdictInfo.setPyzby(jsonObject.getDouble("pyzby"));
             Integer timeState = jsonObject.getInteger("timeState");
             textdictInfo.setTimeState(timeState);
-            if(timeState!=null && timeState==1){
+            if(timeState == 1){
                 textdictInfo.setTimeColKey(jsonObject.getString("timeColKey"));
                 textdictInfo.setTimeName(jsonObject.getString("timeName"));
             }else{
                 textdictInfo.setTimeColKey("");
                 textdictInfo.setTimeName("");
             }
-
             textdictInfo.setProjectId(wbsTreePrivate.getProjectId());
 
-            //由于使用联合主键
-            TextdictInfo one = textdictInfoService.selectTextdictInfoOne(textdictInfo.getId()+"",textdictInfo.getSigRoleId(),textdictInfo.getProjectId());
-            if(ObjectUtil.isNotEmpty(one)){
-                textdictInfoService.saveOrUpdate(textdictInfo);
-            }else{
-                textdictInfoService.save(textdictInfo);
+            String[] trtd = key.split("__")[1].split("_");
+            Element element;
+            String colKey;
+            try {
+                element = trs.get(Integer.parseInt(trtd[0])).select("td").get(Integer.parseInt(trtd[1]));
+                colKey = element.children().get(0).attr("keyname");
+            } catch (Exception e) {
+                throw new ServiceException(String.format("【%s】元素位置与表单不匹配,请重新编辑后保存", textdictInfo.getColName()));
+            }
+            textdictInfo.setColKey(colKey);
+
+            TextdictInfo info = oldTextDictInfoMap.get(wbsTreePrivate.getProjectId() + id);
+            if (info != null) {
+                updateList.add(textdictInfo);
+            } else {
+                addList.add(textdictInfo);
             }
             newTextDictInfos.add(textdictInfo);
             dqIds.append(textdictInfo.getId()).append( ",");
             String dqId = "";
-            if(keyMap.containsKey(keky)){
-                dqId = keyMap.get(keky)+"||"+textdictInfo.getId();
+            if(keyMap.containsKey(key)){
+                dqId = keyMap.get(key)+"||"+textdictInfo.getId();
             }else{
                 dqId=textdictInfo.getId()+"";
             }
-            keyMap.put(keky,dqId);
+            keyMap.put(key,dqId);
             element.removeAttr("dqId");
-            element.attr("dqId", keyMap.get(keky));
+            element.attr("dqId", keyMap.get(key));
             if (jsonObject.getInteger("type") == 2) { //个人签字 不能用户输入
                 if (element.html().indexOf("el-tooltip") >= 0) {
                     element.children().get(0).children().get(0).attr(":readonly", "true");
@@ -550,25 +574,54 @@ public class TextdictInfoController extends BladeController {
             }
         }
         File writeFile = new File(wbsTreePrivate.getHtmlUrl());
-//        File writeFile = new File("D:\\file\\downfile\\1792757075013533696.html");
         FileUtil.writeToFile(writeFile, doc.html(), Boolean.parseBoolean("UTF-8"));
-
         String str1 = wbsTreePrivate.getHtmlUrl().replace("Desktop//privateUrl", "Desktop/privateUrl");
         String replace = str1.replace("\\", "\\\\");
+        if (!oldTextDictInfos.isEmpty()) {
+            Set<Long> set = oldTextDictInfos.stream().map(TextdictInfoVO::getId).collect(Collectors.toSet());
+            // 先逻辑删除然后修改
+            this.textdictInfoService.update(Wrappers.<TextdictInfo>lambdaUpdate().eq(TextdictInfo::getProjectId, wbsTreePrivate.getProjectId())
+                    .eq(TextdictInfo::getExcelId, wbsTreePrivate.getExcelId()).in(TextdictInfo::getType, 2, 6).in(TextdictInfo::getId, set).set(TextdictInfo::getIsDeleted, 1));
+        }
+        if (!updateList.isEmpty()) {
+            for (TextdictInfo info : updateList) {
+                this.textdictInfoService.update(Wrappers.<TextdictInfo>lambdaUpdate().eq(TextdictInfo::getId, info.getId()).eq(TextdictInfo::getProjectId, info.getProjectId())
+                        .set(info.getExcelId() != null ,TextdictInfo::getExcelId, info.getExcelId()).set(info.getSigRoleId() != null ,TextdictInfo::getSigRoleId, info.getSigRoleId())
+                        .set(info.getName() != null ,TextdictInfo::getName, info.getName())
+                        .set(info.getType() != null ,TextdictInfo::getType, info.getType())
+                        .set(info.getColName() != null, TextdictInfo::getColName, info.getColName())
+                        .set(info.getSigRoleName() != null, TextdictInfo::getSigRoleName, info.getSigRoleName())
+                        .set(info.getPyzbx() != null, TextdictInfo::getPyzbx, info.getPyzbx())
+                        .set(info.getPyzby() != null, TextdictInfo::getPyzby, info.getPyzby())
+                        .set(info.getTimeColKey() != null, TextdictInfo::getTimeColKey, info.getTimeColKey())
+                        .set(info.getTimeName() != null, TextdictInfo::getTimeName, info.getTimeName())
+                        .set(info.getColKey() != null, TextdictInfo::getColKey, info.getColKey())
+                        .set(info.getTabId() != null,TextdictInfo::getTabId, info.getTabId())
+                        .set(info.getTimeState() != null ,TextdictInfo::getTimeState, info.getTimeState()).set(TextdictInfo::getIsDeleted, 0));
+            }
+        }
+        if (!addList.isEmpty()) {
+            this.textdictInfoService.saveBatch(addList);
+        }
 
         //修改同几点的数据
+        List<WbsTreePrivate> wbsTreePrivatesEqual = wbsTreePrivateMapper.selectList(Wrappers.<WbsTreePrivate>lambdaQuery()
+                .eq(WbsTreePrivate::getProjectId, wbsTreePrivate.getProjectId())
+                .eq(WbsTreePrivate::getIsDeleted, 0)
+                .eq(WbsTreePrivate::getExcelId, wbsTreePrivate.getExcelId()).eq(WbsTreePrivate::getHtmlUrl, wbsTreePrivate.getHtmlUrl()));
+        List<Long> pKeyIds = wbsTreePrivatesEqual.stream().map(WbsTreePrivate::getPKeyId).collect(Collectors.toList());
+        String ids = StringUtils.join(pKeyIds, ",");
         if(StringUtils.isNotBlank(ids)){
             String updateSqlP = "update m_wbs_tree_private set html_url = '" + replace + "' where p_key_id in ("+ids+") and project_id="+wbsTreePrivate.getProjectId()+"";
             jdbcTemplate.execute(updateSqlP);
         }
 
         //修改对应合同段的htmlUrl,当前项目下对应合同段的节点
-        List<Long> cIdsList = wbsTreePrivatesEqual.stream().map(WbsTreePrivate::getId).distinct().collect(Collectors.toList());
-
+        List<Long> cIdsList = wbsTreePrivatesEqual.stream().map(WbsTreePrivate::getPKeyId).distinct().collect(Collectors.toList());
         List<Long> cPkeyIds = wbsTreeContractService.getBaseMapper().selectList(Wrappers.<WbsTreeContract>lambdaQuery()
                 .eq(WbsTreeContract::getProjectId, wbsTreePrivate.getProjectId())
                 .eq(WbsTreeContract::getExcelId, wbsTreePrivate.getExcelId())
-                .in(WbsTreeContract::getId, cIdsList)).stream().map(WbsTreeContract::getPKeyId).collect(Collectors.toList());
+                .in(WbsTreeContract::getIsTypePrivatePid, cIdsList)).stream().map(WbsTreeContract::getPKeyId).collect(Collectors.toList());
         String cPkeyIdsStr = StringUtils.join(cPkeyIds, ",");
 
         if (StringUtils.isNotEmpty(cPkeyIdsStr)) {
@@ -576,18 +629,15 @@ public class TextdictInfoController extends BladeController {
             jdbcTemplate.execute(updateSqlC);
         }
         BladeUser user = AuthUtil.getUser();
-        DqOperationLog log = new DqOperationLog(wbsTreePrivate, user, "", 1, dataInfo.toJSONString(), JSON.toJSONString(oldTextdictInfos), JSON.toJSONString(newTextDictInfos));
+        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);
-
         return R.success("操作成功");
     }
-
-
     /**
      * 保存默认值
      */

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

@@ -16,13 +16,16 @@
  */
 package org.springblade.manager.mapper;
 
+import org.apache.ibatis.annotations.Select;
 import org.springblade.manager.entity.TextdictInfo;
+import org.springblade.manager.entity.WbsTreePrivate;
 import org.springblade.manager.injector.EasyBaseMapper;
 import org.springblade.manager.vo.TextdictInfoVO;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import org.springframework.data.repository.query.Param;
 
+import java.util.Collection;
 import java.util.List;
 
 /**
@@ -54,4 +57,9 @@ public interface TextdictInfoMapper extends EasyBaseMapper<TextdictInfo> {
     //通过表单Id 获取电签信息
     List<TextdictInfoVO> getTextdictListInfoByPkeyId(@Param("tabId") String tabId,@Param("projectId") String projectId);
 
+    @Select("select * from m_textdict_info where project_id = #{treePrivate.projectId} and tab_id = #{treePrivate.pKeyId} and type in (2,6) and is_deleted = 0")
+    List<TextdictInfoVO> selectTextDictInfoByProjectIdAndTabId(IPage<TextdictInfoVO> page, @Param("treePrivate") WbsTreePrivate treePrivate);
+
+    @Select("SELECT * from m_textdict_info WHERE project_id = #{treePrivate.projectId} and excel_id = #{treePrivate.excelId} and type in (2,6) and is_deleted = 0 and (SELECT 1 from m_wbs_tree_private WHERE p_key_id = tab_id and html_url = #{treePrivate.htmlUrl}) = 1")
+    List<TextdictInfoVO> selectTextdictInfoByExcelIdAndProjectIdAndHtmlUrl(IPage<TextdictInfoVO> page,@Param("treePrivate") WbsTreePrivate treePrivate);
 }

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

@@ -52,7 +52,7 @@
 
     <select id="selectTextdictBYIds" resultMap="textdictInfoVoResultMap">
         SELECT a.* from m_textdict_info a
-        where project_id=#{projectId} and  id in
+        where is_deleted = 0 and project_id=#{projectId} and  id in
         <foreach collection="ids" item="id" open="(" close=")" separator=",">
             #{id}
         </foreach>

+ 48 - 37
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/TextdictInfoServiceImpl.java

@@ -16,20 +16,32 @@
  */
 package org.springblade.manager.service.impl;
 
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.apache.commons.lang.StringUtils;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 import org.jsoup.Jsoup;
 import org.jsoup.nodes.Document;
 import org.jsoup.nodes.Element;
 import org.jsoup.select.Elements;
 import org.springblade.common.constant.CommonConstant;
 import org.springblade.common.utils.CommonUtil;
+import org.springblade.common.utils.SnowFlakeUtil;
+import org.springblade.common.utils.SystemUtils;
+import org.springblade.core.tool.utils.*;
+import org.springblade.common.constant.CommonConstant;
+import org.springblade.common.utils.CommonUtil;
 import org.springblade.core.tool.utils.FileUtil;
 import org.springblade.core.tool.utils.Func;
 import org.springblade.core.tool.utils.IoUtil;
 import org.springblade.core.tool.utils.ResourceUtil;
 import org.springblade.manager.entity.TextdictInfo;
+import org.springblade.manager.entity.WbsTreeContract;
 import org.springblade.manager.entity.WbsTreePrivate;
 import org.springblade.manager.mapper.TextdictInfoMapper;
 import org.springblade.manager.mapper.WbsTreePrivateMapper;
@@ -48,7 +60,9 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.InputStream;
+import java.io.*;
 import java.util.*;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.stream.Collectors;
 
 /**
@@ -61,9 +75,6 @@ import java.util.stream.Collectors;
 public class TextdictInfoServiceImpl extends ServiceImpl<TextdictInfoMapper, TextdictInfo> implements ITextdictInfoService {
     @Resource
     private WbsTreePrivateMapper wbsTreePrivateMapper;
-
-    @Resource
-    private ISignConfigService iSignConfigService;
     @Override
     public IPage<TextdictInfoVO> selectTextdictInfoPage(IPage<TextdictInfoVO> page, TextdictInfoVO textdictInfo) {
         List<TextdictInfoVO> textdict = new ArrayList<>();
@@ -76,48 +87,36 @@ public class TextdictInfoServiceImpl extends ServiceImpl<TextdictInfoMapper, Tex
                 Document doc = Jsoup.parse(htmlString);
                 Elements table = doc.getElementsByAttribute("dqid");
                 List<String> dqid = new ArrayList<>();
-                List<String> keys = new ArrayList<>();
                 for(Element ek:table){
                     dqid.addAll(Func.toStrList("\\|\\|",ek.attr("dqid")));
-                    Elements keyNames = ek.getElementsByAttribute("keyname");
-                    if(Func.isNotEmpty(keyNames)){
-                        for(Element keyName:keyNames){
-                            keys.addAll(Func.toStrList("\\|\\|",keyName.attr("keyname")));
-                        }
-                    }
                 }
                 if(Func.isNotEmpty(textdictInfo.getShowType()) && textdictInfo.getShowType() == 1){
-                    if(Func.isNotEmpty(dqid) && dqid.size() > 0){
+                    if (!dqid.isEmpty()) {
                         textdict = baseMapper.selectTextdictBYIds(dqid,privateInfo.getProjectId());
-                    }else {
-                        textdict = new ArrayList<>();
                     }
-                    if (!keys.isEmpty()) {
-                        // 查询系统级电签配置
-                        TextdictInfoVO temp = null;
-                        if (textdict != null && !textdict.isEmpty()) {
-                            temp = textdict.get(0);
-                        }
-                        if (temp == null) {
-                            temp = new TextdictInfoVO();
-                            temp.setProjectId(privateInfo.getProjectId());
-                            temp.setExcelId(privateInfo.getExcelId() + "");
-                            temp.setTabId(privateInfo.getPKeyId() + "");
-                            temp.setType(2);
-                        }
-                        List<TextdictInfoVO> textdictList = iSignConfigService.hasSignConfig(privateInfo.getInitTableName(), keys, temp);
+                    if (textdict == null || textdict.isEmpty()) {
+                        textdict = baseMapper.selectTextDictInfoByProjectIdAndTabId(page, privateInfo);
                         if (textdict == null || textdict.isEmpty()) {
-                            textdict = textdictList;
-                        } else {
-                            Map<String, Map<String, TextdictInfoVO>> map = textdict.stream().collect(Collectors.groupingBy(TextdictInfoVO::getColKey, Collectors.toMap(TextdictInfoVO::getSigRoleId, v -> v, (v1, v2) -> v1)));
-                            List<TextdictInfoVO> collect = textdictList.stream().filter(textdictInfoVO -> {
-                                Map<String, TextdictInfoVO> voMap = map.get(textdictInfoVO.getColKey());
-                                if (voMap != null && !voMap.isEmpty() ) {
-                                    return voMap.get(textdictInfoVO.getSigRoleId()) == null;
+                            textdict = baseMapper.selectTextdictInfoByExcelIdAndProjectIdAndHtmlUrl(page, privateInfo);
+                        }
+                    }
+                    if (textdict != null && !textdict.isEmpty()) {
+                        Map<String, TextdictInfoVO> map = textdict.stream().collect(Collectors.toMap(item -> item.getProjectId() + item.getTabId() + item.getColKey() + item.getColName(), item -> item, (v1, v2) -> dqid.contains(v2.getId() + "") ? v2 : v1));
+                        textdict = new ArrayList<>(map.values());
+                        for (TextdictInfoVO vo : textdict) {
+                            Elements keyName = doc.getElementsByAttributeValue("keyname", vo.getColKey());
+                            if (keyName ==  null || keyName.isEmpty()) {
+                                vo.setIsMatch(0);
+                            } else {
+                                for (Element ek : keyName) {
+                                    Elements placeholder = ek.getElementsByAttributeValue("placeholder", vo.getColName());
+                                    if (placeholder != null && !placeholder.isEmpty()) {
+                                        vo.setIsMatch(1);
+                                        break;
+                                    }
+                                    vo.setIsMatch(0);
                                 }
-                                return true;
-                            }).collect(Collectors.toList());
-                            textdict.addAll(collect);
+                            }
                         }
                     }
                 }else{
@@ -271,6 +270,18 @@ public class TextdictInfoServiceImpl extends ServiceImpl<TextdictInfoMapper, Tex
                 textdictInfo.setId(-1L);
                 textdictInfos.add(textdictInfo);
             }
+            List<TextdictInfo> list = this.list(Wrappers.<TextdictInfo>lambdaQuery().eq(TextdictInfo::getTabId, tabId).eq(TextdictInfo::getType, 4));
+            Map<String, TextdictInfoVO> map = textdictInfos.stream().collect(Collectors.toMap(vo -> vo.getColKey() + vo.getColName() + vo.getSigRoleName(), vo -> vo, (vo1, vo2) -> vo1));
+            list.forEach(textdictInfo -> {
+                if (!map.containsKey(textdictInfo.getColKey() + textdictInfo.getColName() + textdictInfo.getSigRoleName())) {
+                    TextdictInfoVO vo = new TextdictInfoVO();
+                    BeanUtil.copyProperties(textdictInfo, vo);
+                    map.put(textdictInfo.getColKey() + textdictInfo.getColName() + textdictInfo.getSigRoleName(), vo);
+                    textdictInfos.add(vo);
+                } else {
+                    baseMapper.delete(Wrappers.<TextdictInfo>lambdaQuery().eq(TextdictInfo::getId, textdictInfo.getId()).eq(TextdictInfo::getProjectId, textdictInfo.getProjectId()).eq(TextdictInfo::getType, 4));
+                }
+            });
             textdictInfoPage.setRecords(textdictInfos);
             return textdictInfoPage;
         } catch (FileNotFoundException e) {