فهرست منبع

日志,上传清表bug

DengLinLang 3 هفته پیش
والد
کامیت
c621c1aebe

+ 1 - 1
blade-service-api/blade-business-api/src/main/java/org/springblade/business/entity/ContractLog.java

@@ -79,7 +79,7 @@ public class ContractLog extends BaseEntity {
     /**
      * 数据ID
      */
-    private Long dataId;
+    private String dataId;
 
     @ApiModelProperty("填报人姓名")
     private String createUserName;

+ 5 - 0
blade-service-api/blade-business-api/src/main/java/org/springblade/business/feign/ContractLogClient.java

@@ -57,5 +57,10 @@ public interface ContractLogClient {
      */
     @PostMapping(API_PREFIX + "/saveContractLog")
     String saveContractLog(@RequestBody SaveContractLogVO saveContractLogVO);
+    /**
+     * 保存表关联的工序节点信息
+     */
+    @PostMapping(API_PREFIX + "/saveLogWbsList")
+    String saveLogWbsList(@RequestBody SaveContractLogVO saveContractLogVO);
 
 }

+ 2 - 2
blade-service-api/blade-business-api/src/main/java/org/springblade/business/vo/SaveContractLogVO.java

@@ -10,7 +10,7 @@ import java.util.List;
 public class SaveContractLogVO {
 
     @ApiModelProperty("列表数据主键")
-    private Long dataId;
+    private String dataId;
 
     @ApiModelProperty("项目ID")
     private Long projectId;
@@ -35,7 +35,7 @@ public class SaveContractLogVO {
     @ApiModelProperty("源数据的日志id")
     private  String oldDataId;
 
-    public SaveContractLogVO(Long businessId, String projectId, String contractId, Long wbsNodeId, Long tableId, Integer wbsNodeType, String recordTime, List<JSONObject> correlationIds, String oldDataId) {
+    public SaveContractLogVO(String businessId, String projectId, String contractId, Long wbsNodeId, Long tableId, Integer wbsNodeType, String recordTime, List<JSONObject> correlationIds, String oldDataId) {
         this.dataId = businessId;
         this.projectId = Long.parseLong(projectId);
         this.contractId = Long.parseLong(contractId);

+ 14 - 0
blade-service/blade-business/src/main/java/org/springblade/business/feignClient/ContractLogClientImpl.java

@@ -13,6 +13,7 @@ import org.springblade.business.vo.SaveContractLogVO;
 import org.springblade.common.utils.SnowFlakeUtil;
 import org.springblade.core.secure.utils.AuthUtil;
 import org.springblade.core.tenant.annotation.NonDS;
+import org.springblade.core.tool.utils.BeanUtil;
 import org.springblade.core.tool.utils.Func;
 import org.springblade.manager.entity.WbsTreePrivate;
 import org.springblade.manager.feign.WbsTreePrivateClient;
@@ -163,6 +164,19 @@ public class ContractLogClientImpl implements ContractLogClient {
         return contractLog.getId().toString();
     }
 
+    @Override
+    public String saveLogWbsList(SaveContractLogVO saveContractLogVO) {
+        ContractLog contractLog = new ContractLog();
+        List<JSONObject> logWbsList = saveContractLogVO.getCorrelationIds();
+        BeanUtil.copyProperties(saveContractLogVO, contractLog);
+        contractLog.setId(saveContractLogVO.getContractId());
+        List<ContractLogWbs> newLogWbsList = new ArrayList<>();
+        //处理数据
+        logWbsList.forEach(json -> newLogWbsList.add(this.createContractLogWbs(json, contractLog)));
+        this.contractLogWbsService.saveBatch(newLogWbsList);
+        return "success";
+    }
+
     private ContractLogWbs createContractLogWbs(JSONObject json, ContractLog contractLog) {
         ContractLogWbs newLogWbs = new ContractLogWbs();
         newLogWbs.setId(SnowFlakeUtil.getId());

+ 82 - 30
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/ExcelTabController.java

@@ -1038,9 +1038,18 @@ public class ExcelTabController extends BladeController {
                     //判断高度
                     String style = data.attr("style");
                     if (StringUtils.isNotBlank(style)) {
-                        String substring = style.substring(style.lastIndexOf(":") + 1);
+                        int index = style.lastIndexOf(":");
+                        String substring = style.substring( index+ 1);
                         String height = substring.substring(0, substring.length() - 3);
-                        if (Integer.parseInt(height) > 90) {
+                        int i1 = 0;
+                        try {
+                             i1 = Integer.parseInt(height);
+                        } catch (NumberFormatException e) {
+                             substring = style.substring(style.lastIndexOf(":",index-1) + 1);
+                             height = substring.substring(0,substring.indexOf("px;"));
+                             i1 = Integer.parseInt(height);
+                        }
+                        if (i1 > 90) {
                             isText = true;
                         }
                     }
@@ -2553,7 +2562,6 @@ public class ExcelTabController extends BladeController {
         return R.data(null);
     }
 
-
     /**
      * 获取当前用户当前日期的填报记录
      */
@@ -2933,6 +2941,7 @@ public class ExcelTabController extends BladeController {
     })
     public R<List<Map<String, Object>>> copyTheLogBusinessData(@RequestParam String theLogId, @RequestParam String nodePrimaryKeyId, @RequestParam String currentTime, @RequestParam String contractId) {
         if (StringUtils.isNotEmpty(theLogId) && StringUtils.isNotEmpty(currentTime)) {
+
             //复制出来的新日志记录logIds
             List<String> logIds = new ArrayList<>();
             //复制出来的新增表的实体表SQL集合
@@ -2941,6 +2950,7 @@ public class ExcelTabController extends BladeController {
             List<JSONObject> logWbsList = new ArrayList<>();
             //记录第一组
             List<JSONObject> oneGroupLogWbsList = new ArrayList<>();
+            ArrayList<String> dataIdList = new ArrayList<>();
 
             //获取所有选择的日志表的数据信息
             List<ContractLog> contractLogList = jdbcTemplate.query("select * from u_contract_log where id in(" + theLogId + ")", new BeanPropertyRowMapper<>(ContractLog.class));
@@ -2954,7 +2964,7 @@ public class ExcelTabController extends BladeController {
             for (ContractLog objLog : contractLogList) {
                 long dataId = 0;
                 //获取目标数据
-                String queryTargetDataSql = "SELECT * FROM " + tableTemp.getInitTableName() + " WHERE id = " + objLog.getDataId();
+                String queryTargetDataSql = "SELECT * FROM " + tableTemp.getInitTableName() + " WHERE id in( " + objLog.getDataId()+")";
                 List<Map<String, Object>> targetData = this.jdbcTemplate.queryForList(queryTargetDataSql);
 
                 //只需要替换group_id和id即可
@@ -2980,11 +2990,11 @@ public class ExcelTabController extends BladeController {
                             value = SnowFlakeUtil.getId();
 
                             //赋值给log的dataId,也就是businessId要与实体表数据id对应
-                            dataId = Long.parseLong(String.valueOf(value));
+                            dataIdList.add(String.valueOf(value));
 
                             //后续关联工序节点businessId赋值,businessId=实体表数据的id
                             for (JSONObject json : wbsJsonList) {
-                                json.put("businessId", dataId);
+                                json.put("businessId", Long.parseLong(String.valueOf(value)));
                             }
                             logWbsList.addAll(wbsJsonList);
                         }
@@ -3007,26 +3017,51 @@ public class ExcelTabController extends BladeController {
                     insertSql.append(" VALUES(").append(valueSql.substring(1)).append(")");
                     insertSqlList.add(insertSql.toString());
                 }
-
-                if (dataId != 0) {
-                    //处理log当前表的记录数据
-                    String id = this.contractLogClient.saveContractLog(new SaveContractLogVO(
-                            dataId,
-                            String.valueOf(objLog.getProjectId()),
-                            String.valueOf(objLog.getContractId()),
-                            objLog.getWbsNodeId(),
-                            objLog.getTableId(),
-                            objLog.getWbsNodeType(),
-                            currentTime,
-                            logWbsList,
-                            theLogId
-                    ));
-                    //log记录id
-                    if (StringUtils.isNotEmpty(id)) {
+                String dataIds= dataIdList.stream().collect(Collectors.joining(","));
+                if(ObjectUtil.isEmpty(dataIdList)){
+                    return fail("没有数据可复制");
+                }else {
+                    //查询当前所在日期日志记录
+                    List<ContractLog> contractLogs = this.contractLogClient.queryContractLogByPrimaryKeyIdAndRecordTimeList(nodePrimaryKeyId, currentTime, contractId);
+                    if(ObjectUtil.isEmpty(contractLogs)){
+                        String id = this.contractLogClient.saveContractLog(new SaveContractLogVO(
+                                dataIds,
+                                String.valueOf(objLog.getProjectId()),
+                                String.valueOf(objLog.getContractId()),
+                                objLog.getWbsNodeId(),
+                                objLog.getTableId(),
+                                objLog.getWbsNodeType(),
+                                currentTime,
+                                logWbsList,
+                                theLogId
+                        ));
                         logIds.add(id);
+                    }else {
+                        //关联dataIds
+                        ContractLog contractLog = contractLogs.get(0);
+                        String oldDataId = contractLog.getDataId();
+                        ArrayList<String> OldDataIdList =new ArrayList<>(Arrays.asList(oldDataId.split(",")));
+                        OldDataIdList.addAll(dataIdList);
+                        // 将列表重新组合为字符串
+                        String updatedDataId = String.join(",", OldDataIdList);
+                        jdbcTemplate.execute("update u_contract_log set data_id = '" + updatedDataId + "'  where id = " + contractLog.getId());
+                        //新增表关联工序节点集合
+                        if(ObjectUtil.isNotEmpty(logWbsList)){
+                            SaveContractLogVO saveContractLogVO = new SaveContractLogVO(
+                                    updatedDataId,
+                                    String.valueOf(contractLog.getProjectId()),
+                                    String.valueOf(contractLog.getContractId()),
+                                    contractLog.getWbsNodeId(),
+                                    contractLog.getTableId(),
+                                    contractLog.getWbsNodeType(),
+                                    currentTime,
+                                    logWbsList,
+                                    theLogId
+                            );
+                            this.contractLogClient.saveLogWbsList(saveContractLogVO);
+                        }
+                        logIds.add(contractLog.getId().toString());
                     }
-                } else {
-                    var = false;
                 }
             }
 
@@ -3038,7 +3073,6 @@ public class ExcelTabController extends BladeController {
             } else {
                 throw new ServiceException("数据构造失败");
             }
-
             //返回当前复制的表数据
             return this.getTheLogBusinessData(StringUtils.join(logIds, ","), nodePrimaryKeyId, currentTime, contractId);
         }
@@ -3878,16 +3912,34 @@ public class ExcelTabController extends BladeController {
     @ApiOperation(value = "删除施工日志对应的表数据记录信息等", notes = "传入get-the-log-business-data接口返回的内部id")
     @Transactional
     public R<Object> removeLogTab(@RequestParam String id) {
+        //todo  这里前端需要改一下 多传一个日志id参数 避免like查询影响性能
         if (StringUtils.isNotEmpty(id)) {
-            Map<String, Object> obj = jdbcTemplate.queryForMap("select * from u_contract_log where data_id =" + id + " ");
-            if (obj!=null && Func.isNotEmpty(obj)) {
+            ContractLog contractLog = jdbcTemplate.queryForObject("select * from u_contract_log where data_id like '%" + id + "%'"
+                    , new BeanPropertyRowMapper<>(ContractLog.class));
+            if (contractLog!=null && Func.isNotEmpty(contractLog)) {
                 //删除施工日志记录信息
-                jdbcTemplate.execute("delete from u_contract_log where data_id = " + id);
+                String dataId = contractLog.getDataId();
+                // 将字符串拆分为列表
+                List<String> dataIdList = Arrays.asList(dataId.split(","));
+                if(dataIdList.size() == 1){
+                    //删除整条日志
+                    jdbcTemplate.execute("delete from u_contract_log where id = " + contractLog.getId());
+                }else {
+                   if(dataIdList.size()>1){
+                       // 移除指定值
+                       List<String> updatedDataIdList = dataIdList.stream()
+                               .filter(data -> !data.equals(id))
+                               .collect(Collectors.toList());
+                       // 将列表重新组合为字符串
+                       String updatedDataId = String.join(",", updatedDataIdList);
+                       jdbcTemplate.execute("update u_contract_log set data_id = '" + updatedDataId + "' where id = " + contractLog.getId());
+                   }
+                }
                 //删除关联的工序wbs信息
-                jdbcTemplate.execute("delete from u_contract_log_wbs where business_id = " + id + " and contract_log_id = " + obj.get("id").toString());
+                jdbcTemplate.execute("delete from u_contract_log_wbs where business_id = " + id + " and contract_log_id = " + contractLog.getId().toString());
 
                 //获取对应表信息
-                WbsTreePrivate tableTemp = wbsTreePrivateService.getOne(Wrappers.<WbsTreePrivate>lambdaQuery().eq(WbsTreePrivate::getPKeyId, obj.get("table_id")));
+                WbsTreePrivate tableTemp = wbsTreePrivateService.getOne(Wrappers.<WbsTreePrivate>lambdaQuery().eq(WbsTreePrivate::getPKeyId, contractLog.getTableId()));
                 if (tableTemp != null && StringUtils.isNotEmpty(tableTemp.getInitTableName())) {
                     //删除实体表对应的数据信息
                     jdbcTemplate.execute("delete from " + tableTemp.getInitTableName() + " where id = " + id);

+ 44 - 28
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/ExcelTabServiceImpl.java

@@ -664,6 +664,17 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
             List<ContractLog> contractLogList = jdbcTemplate.query("select id from u_contract_log where data_id in(" + businessIds + ")", new BeanPropertyRowMapper<>(ContractLog.class));
             ids = contractLogList.stream().map(ContractLog::getId).map(String::valueOf).collect(Collectors.joining(","));
         }
+        String oldDataId = null;
+        if(ObjectUtil.isNotEmpty(ids)){
+            List<ContractLog> contractLogList = jdbcTemplate.query("select * from u_contract_log where id in (" + ids + ")", new BeanPropertyRowMapper<>(ContractLog.class));
+            ContractLog contractLog = contractLogList.get(0);
+            String oldDataId1 = contractLog.getOldDataId();
+            if (ObjectUtil.isNotEmpty(oldDataId1)){
+                oldDataId = oldDataId1+","+ids;
+            }else {
+                oldDataId = ids;
+            }
+        }
 
         //删除旧数据
         if (StringUtils.isNotEmpty(businessIds)) {
@@ -690,6 +701,8 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
         }
 
         List<String> dataIds = new LinkedList<>();
+        List<JSONObject> logWbsList = new ArrayList<>();
+        ArrayList<String> insterTataSqls = new ArrayList<>();
         for (TableInfo tableInfo : tableInfoList) {
             //获取数据id
             if (StringUtils.isEmpty(tableInfo.getBusinessId())) {
@@ -715,19 +728,7 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
             //新增数据
             try {
                 this.jdbcTemplate.execute(sql.toString());
-                //添加操作日志
-                String delSqlNew = sql.toString().replace("\"", "'");
-                String sqlNew = sql.toString().replace("\"", "'");
-                StringBuffer sb = new StringBuffer();
-                sb.append("insert into blade_log_sql (p_key_id,contract_log_id,user_id,create_time,sql_info) VALUES ");
-                sb.append("("+tableNode.getPKeyId());
-                sb.append(","+tableInfo.getBusinessId());
-                sb.append(","+AuthUtil.getUserId());
-                sb.append(",SYSDATE()");
-                sb.append(",\"");
-                sb.append(delSqlNew);
-                sb.append("\")");
-                jdbcTemplate.execute(sb.toString());
+                insterTataSqls.add(sql.toString());
             } catch (Exception e) {
                 String errorKeyName = null;
                 String errorMessage = e.getMessage();
@@ -755,7 +756,7 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
             }
 
             List<Object> linkTabIds = tableInfo.getLinkTabIds();
-            List<JSONObject> logWbsList = new ArrayList<>();
+
             if (linkTabIds != null && linkTabIds.size() > 0) {
                 //处理每个表格的关联情况
                 List<JSONObject> jsonLinkTabIds = JSONArray.parseArray(JSONObject.toJSONString(linkTabIds), JSONObject.class);
@@ -765,21 +766,36 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
                 List<JSONObject> collect = jsonLinkTabIds.stream().distinct().collect(Collectors.toList()); //去重,每个businessId不一样
                 logWbsList.addAll(collect);
             }
-            //保存日志记录
-            String dataId = this.contractLogClient.saveContractLog(new SaveContractLogVO(
-                    Long.parseLong(tableInfo.getBusinessId()),
-                    tableInfoList.get(0).getProjectId(),
-                    tableInfoList.get(0).getContractId(),
-                    parentNode.getPKeyId(),
-                    tableNode.getPKeyId(),
-                    parentNode.getMajorDataType(),
-                    recordTime,
-                    logWbsList,
-                    ids
-            ));
-            if (StringUtils.isNotEmpty(dataId)) {
-                dataIds.add(dataId);
+        }
+        String dataIdListStr = tableInfoList.stream().map(TableInfo::getBusinessId).collect(Collectors.joining(","));
+        //保存日志记录
+        String dataId = this.contractLogClient.saveContractLog(new SaveContractLogVO(
+                dataIdListStr,
+                tableInfoList.get(0).getProjectId(),
+                tableInfoList.get(0).getContractId(),
+                parentNode.getPKeyId(),
+                tableNode.getPKeyId(),
+                parentNode.getMajorDataType(),
+                recordTime,
+                logWbsList,
+                oldDataId
+        ));
+        if (StringUtils.isNotEmpty(dataId)) {
+            for (String insterTataSql : insterTataSqls) {
+                //添加操作日志
+                String sqlNew = insterTataSql.toString().replace("\"", "'");
+                StringBuffer sb = new StringBuffer();
+                sb.append("insert into blade_log_sql (p_key_id,contract_log_id,user_id,create_time,sql_info) VALUES ");
+                sb.append("("+tableNode.getPKeyId());
+                sb.append(","+dataId);
+                sb.append(","+AuthUtil.getUserId());
+                sb.append(",SYSDATE()");
+                sb.append(",\"");
+                sb.append(sqlNew);
+                sb.append("\")");
+                jdbcTemplate.execute(sb.toString());
             }
+            dataIds.add(dataId);
         }
         return String.join(",", dataIds);
     }