Browse Source

修改超时工单为从工作流直接获取数据

lifuquan 11 months ago
parent
commit
8b5a43262f

+ 0 - 15
src/main/java/com/nokia/tsl_data/controller/DataWarehouseController.java

@@ -3,7 +3,6 @@ package com.nokia.tsl_data.controller;
 import com.nokia.tsl_data.entity.vo.R;
 import com.nokia.tsl_data.service.DataWarehouseService;
 import com.nokia.tsl_data.service.HighQualityDataService;
-import com.nokia.tsl_data.service.TaskService;
 import lombok.extern.slf4j.Slf4j;
 
 import org.springframework.beans.factory.annotation.Autowired;
@@ -20,8 +19,6 @@ public class DataWarehouseController {
     @Autowired
     private DataWarehouseService dataWarehouseService;
     @Autowired
-    private TaskService taskService;
-    @Autowired
     private HighQualityDataService highQualityDataService;
 
     @PostMapping("highQualityData/generate")
@@ -120,18 +117,6 @@ public class DataWarehouseController {
         }
     }
 
-    @PostMapping("update/work_flow_basic_data")
-    public R updateWorkFlowBasicData() {
-        try {
-            taskService.updateWorkFlowBasicDataTask();
-            return R.ok().message("工作流基础数据更新成功...");
-        } catch (Exception e) {
-            log.error(e.getMessage());
-            e.printStackTrace();
-            return R.error().message(String.format("工作流基础数据更新失败: %s", e.getMessage()));
-        }
-    }
-
     @PostMapping("warehouse/complaint_details_fix_ywd")
     public R warehouseComplaintDetailsFixYwdDay(@RequestBody String day) {
         try {

+ 1 - 0
src/main/java/com/nokia/tsl_data/dao/AvgDurationMapper.java

@@ -7,6 +7,7 @@ import org.apache.ibatis.annotations.Select;
 import java.util.List;
 import java.util.Map;
 
+/* cspell: disable */
 @Mapper
 public interface AvgDurationMapper {
 

+ 6 - 0
src/main/java/com/nokia/tsl_data/dao/AvgDurationMapperV3.java

@@ -10,12 +10,14 @@ import org.apache.ibatis.annotations.Select;
 /**
  * tsl_data.avg_duration_v3 表
  */
+/* cspell: disable */
 @Mapper
 public interface AvgDurationMapperV3 {
 
     /**
      * 插入上月的平均处理时长
      */
+    @Deprecated
     @Insert("with t1 as (select sdd.real_name,kfsn, (extract(epoch from to_timestamp(kf_file_time, 'YYYY-MM-DD HH24:MI:SS'))"
             + " - extract(epoch from to_timestamp(kd_accept_time, 'YYYY-MM-DD HH24:MI:SS'))) / 3600 as cost_time\n"
             + "from tsl_data.work_flow_basic_data wfbd, tsl_data.sys_data_dictionary sdd \n" + //
@@ -32,6 +34,10 @@ public interface AvgDurationMapperV3 {
             " union select #{month_id} as month_id, city as city_name, avg_duration from t3")
     void insertOldTsDurationForMonth(String monthId);
 
+    @Insert("insert into tsl_data.avg_duration_v3 (month_id, city_name, avg_duration) " +
+            "values (#{month_id}, #{city}, #{avg_duration})")
+    void insertOne(Map<String, Object> map);
+
     /**
      * 查询历史处理时长
      */

+ 10 - 0
src/main/java/com/nokia/tsl_data/dao/SysDataDictionaryRepository.java

@@ -6,6 +6,7 @@ import org.springframework.stereotype.Repository;
 
 import java.util.*;
 
+/* cspell: disable */
 @Repository
 public interface SysDataDictionaryRepository extends JpaRepository<SysDataDictionary, Long> {
 
@@ -24,6 +25,15 @@ public interface SysDataDictionaryRepository extends JpaRepository<SysDataDictio
         return result;
     }
 
+    default Map<String, String> findWorkFlowCityMap() {
+        Map<String, String> result = new HashMap<>();
+        List<SysDataDictionary> dictionaries = findByTypeOrderByOrd("work_flow_city");
+        for (SysDataDictionary dictionary : dictionaries) {
+            result.put(dictionary.getNickCode(), dictionary.getRealName());
+        }
+        return result;
+    }
+
     default Set<String> findAllServTypeNames() {
         Set<String> result = new HashSet<>();
         List<SysDataDictionary> dictionaries = findByTypeOrderByOrd("serv_type_name");

+ 0 - 43
src/main/java/com/nokia/tsl_data/dao/TslDataDao.java

@@ -1,15 +1,9 @@
 package com.nokia.tsl_data.dao;
 
-import com.nokia.tsl_data.entity.WorkFlowBasicData;
-
 import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.jdbc.object.BatchSqlUpdate;
 import org.springframework.stereotype.Component;
 
-import java.sql.Timestamp;
-import java.sql.Types;
 import java.util.List;
-import java.util.Objects;
 
 /**
  * tslData 直接使用jdbcTemplate完成的操作
@@ -24,43 +18,6 @@ public class TslDataDao {
         this.jdbcTemplate = jdbcTemplate;
     }
 
-    /**
-     * 采用BatchSqlUpdate的方法批量insert到表tableName(可以是临时表)
-     * 20240205 不再使用
-     */
-    @Deprecated
-    public void batchInsertWorkFlowBasicData(List<WorkFlowBasicData> data, String tableName) {
-        String sqlFormat = "INSERT INTO %s " +
-                "(order_no,is_effctive, kfsn, city_id, region_id, kd_accept_time, kd_request_reply_time, re_is_status_id, "
-                + " kf_file_time, kf_file_type, work_flow_create_time, work_flow_update_time) " +
-                "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
-        BatchSqlUpdate batchSqlUpdate = new BatchSqlUpdate(Objects.requireNonNull(jdbcTemplate.getDataSource()),
-                String.format(sqlFormat, tableName));
-        batchSqlUpdate.setBatchSize(1000);
-        batchSqlUpdate.setTypes(new int[] {
-                Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
-                Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
-                Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
-                Types.VARCHAR, Types.TIMESTAMP, Types.TIMESTAMP
-        });
-        for (WorkFlowBasicData item : data) {
-            batchSqlUpdate.update(
-                    item.getOrderNo(),
-                    item.getIsEffctive(),
-                    item.getKfsn(),
-                    item.getCityId(),
-                    item.getRegionId(),
-                    item.getKdAcceptTime(),
-                    item.getKdRequestReplyTime(),
-                    item.getReIsStatusId(),
-                    item.getKfFileTime(),
-                    item.getKfFileType(),
-                    item.getWorkFlowCreateTime() == null ? null : Timestamp.from(item.getWorkFlowCreateTime()),
-                    item.getWorkFlowUpdateTime() == null ? null : Timestamp.from(item.getWorkFlowUpdateTime()));
-        }
-        batchSqlUpdate.flush();
-    }
-
     /**
      * 创建临时表
      * 20240205 不再使用

+ 6 - 1
src/main/java/com/nokia/tsl_data/dao/WorkFlowBasicDataMapper.java

@@ -8,6 +8,11 @@ import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 
+/*
+ * 20240205删除
+ */
+/* cspell: disable */
+@Deprecated
 @Mapper
 public interface WorkFlowBasicDataMapper {
 
@@ -32,7 +37,7 @@ public interface WorkFlowBasicDataMapper {
          * 处理时长统计
          */
         @Select("with t1 as (select sdd.real_name,kfsn, (extract(epoch from to_timestamp(kf_file_time, 'YYYY-MM-DD HH24:MI:SS'))"
-                        + " - extract(epoch from to_timestamp(kd_accept_time, 'YYYY-MM-DD HH24:MI:SS'))) / 3600 as cost_time\n"
+                        + " - extract(epoch from to_timestamp(kd_accept_time, 'YYYY-MM-DD HH24:MI:SS'))) / 3600 as cost_time "
                         + "from tsl_data.work_flow_basic_data wfbd, tsl_data.sys_data_dictionary sdd \n" + //
                         " where wfbd.city_id = sdd.nick_code and kf_file_time is not null" +
                         " and re_is_status_id != '06678b79185349b5bf0c24490a978fbb' and is_effctive = '1' "

+ 120 - 28
src/main/java/com/nokia/tsl_data/dao/WorkFlowDao.java

@@ -1,7 +1,9 @@
 package com.nokia.tsl_data.dao;
 
 import com.nokia.tsl_data.entity.SysDataDictionary;
-import com.nokia.tsl_data.entity.WorkFlowBasicData;
+
+import lombok.extern.slf4j.Slf4j;
+
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.stereotype.Component;
@@ -11,11 +13,13 @@ import java.time.Instant;
 import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 从 工作流数据库 读取
  */
 /* cSpell: disable */
+@Slf4j
 @Component
 public class WorkFlowDao {
 
@@ -51,17 +55,10 @@ public class WorkFlowDao {
                 });
     }
 
-    // 获取update_time在start之后的全部工单信息
-    // 20240205 不再使用
-    @Deprecated
-    public List<WorkFlowBasicData> findWorkFlowBasicDataByUpdateTime(Instant start) {
-        return findWorkFlowBasicDataByUpdateTime(start, Instant.now());
-    }
-
     // 获取update_time在两个范围之间的全部工单信息
     // 20240205 不再使用
     @Deprecated
-    public List<WorkFlowBasicData> findWorkFlowBasicDataByUpdateTime(Instant start, Instant end) {
+    public List<Map<String, Object>> findWorkFlowBasicDataByUpdateTime(Instant start, Instant end) {
         // 20240112 修改 使用 serv_order 替换了kfsn
         String sql = "select order_no, " + //
                 "city as city_id, " + //
@@ -82,24 +79,119 @@ public class WorkFlowDao {
                 .withZone(ZoneId.of("Asia/Shanghai"));
         Object[] objects = new Object[] { dateFormat.format(start), dateFormat.format(end) };
         int[] argTypes = new int[] { Types.TIMESTAMP, Types.TIMESTAMP };
-        return jdbcTemplate.query(sql, objects, argTypes,
-                (rs, rowNum) -> {
-                    WorkFlowBasicData basicData = new WorkFlowBasicData();
-                    basicData.setOrderNo(rs.getString("order_no"));
-                    basicData.setIsEffctive(rs.getString("is_effctive"));
-                    basicData.setCityId(rs.getString("city_id"));
-                    basicData.setRegionId(rs.getString("region_id"));
-                    basicData.setKfsn(rs.getString("kfsn"));
-                    basicData.setKdAcceptTime(rs.getString("kd_accepttime"));
-                    basicData.setKdRequestReplyTime(rs.getString("kd_requestreplytime"));
-                    basicData.setReIsStatusId(rs.getString("re_is_status_id"));
-                    basicData.setKfFileTime(rs.getString("kf_file_time"));
-                    basicData.setKfFileType(rs.getString("kf_file_type"));
-                    basicData.setWorkFlowCreateTime(
-                            Instant.ofEpochMilli(rs.getTimestamp("work_flow_create_time").getTime()));
-                    basicData.setWorkFlowUpdateTime(
-                            Instant.ofEpochMilli(rs.getTimestamp("work_flow_update_time").getTime()));
-                    return basicData;
-                });
+        return jdbcTemplate.queryForList(sql, objects, argTypes);
+    }
+
+    /**
+     * 直接从工作流读取处理时长数据
+     */
+    public List<Map<String, Object>> selectTsDurationBasicData(Instant start, Instant end) {
+        String sql = "explain with t1 as (select city as city_id, \r\n" + //
+                "form_basic_data->>'serv_order' as kfsn,\r\n" + //
+                "(extract(epoch from to_timestamp(form_basic_data->>'kf_file_time', 'YYYY-MM-DD HH24:MI:SS')) -\r\n" + //
+                "extract(epoch from to_timestamp(form_basic_data->>'kd_accepttime', 'YYYY-MM-DD HH24:MI:SS'))) /\r\n" + //
+                "3600 as cost_time \r\n" + //
+                "from flow_form_basic\r\n" + //
+                "where form_basic_data->>'re_is_status' != '06678b79185349b5bf0c24490a978fbb' \r\n" + //
+                "and form_basic_data->>'kf_file_time' is not null \r\n" + //
+                "and is_effctive = '1'\r\n" + //
+                "and to_timestamp(form_basic_data->>'kf_file_time', 'yyyy-mm-dd hh24:mi:ss') >= ? \r\n" + //
+                "and to_timestamp(form_basic_data->>'kf_file_time', 'yyyy-mm-dd hh24:mi:ss') < ? \r\n" + //
+                "select city_id, kfsn, min(cost_time) as cost_time from t1 group by city_id, kfsn";
+        DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
+                .withZone(ZoneId.of("Asia/Shanghai"));
+        Object[] objects = new Object[] { dateFormat.format(start), dateFormat.format(end) };
+        int[] argTypes = new int[] { Types.TIMESTAMP, Types.TIMESTAMP };
+        Long startLong = System.currentTimeMillis();
+        List<Map<String, Object>> result = jdbcTemplate.queryForList(sql, objects, argTypes);
+        log.debug("从工作流读取处理时长数据, 耗时 {} ms...", System.currentTimeMillis() - startLong);
+        return result;
+    }
+
+    public List<Map<String, Object>> selectTsDurationForDay(Instant start, Instant end) {
+        String sql = "with t1 as (select city as city_id, \r\n" + //
+                "form_basic_data->>'serv_order' as kfsn,\r\n" + //
+                "(extract(epoch from to_timestamp(form_basic_data->>'kf_file_time', 'YYYY-MM-DD HH24:MI:SS'))\r\n" + //
+                "- extract(epoch from to_timestamp(form_basic_data->>'kd_accepttime', 'YYYY-MM-DD HH24:MI:SS')))\r\n" + //
+                "/ 3600 as cost_time \r\n" + //
+                "from flow_form_basic\r\n" + //
+                "where form_basic_data->>'re_is_status' != '06678b79185349b5bf0c24490a978fbb'\r\n" + //
+                "and form_basic_data->>'kf_file_time' is not null \r\n" + //
+                "and is_effctive = '1'\r\n" + //
+                "and to_timestamp(form_basic_data->>'kf_file_time', 'yyyy-mm-dd hh24:mi:ss') >= ?\r\n" + //
+                "and to_timestamp(form_basic_data->>'kf_file_time', 'yyyy-mm-dd hh24:mi:ss') < ?),\r\n" + //
+                "t2 as (select city_id, kfsn, min(cost_time) as cost_time from t1 group by city_id, kfsn),\r\n" + //
+                "t3 as (select city_id, avg(cost_time)::float8 as avg_duration from t2 group by city_id),\r\n" + //
+                "t4 as (select '全省' as city_id, avg(cost_time)::float8 as avg_duration from t2)\r\n" + //
+                "select * from  t3 union select * from t4";
+        DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
+                .withZone(ZoneId.of("Asia/Shanghai"));
+        Object[] objects = new Object[] { dateFormat.format(start), dateFormat.format(end) };
+        int[] argTypes = new int[] { Types.TIMESTAMP, Types.TIMESTAMP };
+        Long startLong = System.currentTimeMillis();
+        List<Map<String, Object>> result = jdbcTemplate.queryForList(sql, objects, argTypes);
+        log.debug("从工作流读取{}-{}平均处理时长数据, 耗时 {} ms...",
+                start,
+                end,
+                System.currentTimeMillis() - startLong);
+        return result;
+    }
+
+    public List<Map<String, Object>> selectTimeoutTsCountForDay(Instant start, Instant end, int target) {
+        String sql = "with t1 as (select distinct city as city_id, \r\n" + //
+                "form_basic_data->>'serv_order' as kfsn,\r\n" + //
+                "to_timestamp(form_basic_data->>'kf_file_time', 'yyyy-mm-dd hh24:mi:ss') - \r\n" + //
+                "to_timestamp(form_basic_data->>'kd_accepttime', 'yyyy-mm-dd hh24:mi:ss') \r\n" + //
+                "> make_interval(hours => ?) as is_timeout \r\n" + //
+                "from flow_form_basic\r\n" + //
+                "where form_basic_data->>'re_is_status' != '06678b79185349b5bf0c24490a978fbb'\r\n" + //
+                "and form_basic_data->>'kf_file_time' is not null \r\n" + //
+                "and is_effctive = '1'\r\n" + //
+                "and to_timestamp(form_basic_data->>'kf_file_time', 'yyyy-mm-dd hh24:mi:ss') >= ?\r\n" + //
+                "and to_timestamp(form_basic_data->>'kf_file_time', 'yyyy-mm-dd hh24:mi:ss') <= ?),\r\n" + //
+                "t2 as (select '全省' as city_id, count(1) as total_num, count(is_timeout or null) as timeout_num,\r\n" + //
+                "count(is_timeout or null)::float8 / count(1) as timeout_ratio from t1),\r\n" + //
+                "t3 as (select city_id, count(1) as total_num, count(is_timeout or null) as timeout_num,\r\n" + //
+                "count(is_timeout or null)::float8 / count(1) as timeout_ratio from t1 group by city_id)\r\n" + //
+                "select * from  t2 union select * from t3";
+        DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
+                .withZone(ZoneId.of("Asia/Shanghai"));
+        Object[] objects = new Object[] { target, dateFormat.format(start), dateFormat.format(end) };
+        int[] argTypes = new int[] { Types.INTEGER, Types.TIMESTAMP, Types.TIMESTAMP };
+        Long startLong = System.currentTimeMillis();
+        List<Map<String, Object>> result = jdbcTemplate.queryForList(sql, objects, argTypes);
+        log.debug("从工作流读取{}-{}超时工单数据, 耗时 {} ms...",
+                start,
+                end,
+                System.currentTimeMillis() - startLong);
+        return result;
+    }
+
+    public List<Map<String, Object>> selectTsDurationForMonth(String month) {
+        String sql = "with t1 as (select city as city_id, \r\n" + //
+                "form_basic_data->>'serv_order' as kfsn,\r\n" + //
+                "(extract(epoch from to_timestamp(form_basic_data->>'kf_file_time', 'YYYY-MM-DD HH24:MI:SS'))\r\n" + //
+                "- extract(epoch from to_timestamp(form_basic_data->>'kd_accepttime', 'YYYY-MM-DD HH24:MI:SS')))\r\n" + //
+                "/ 3600 as cost_time \r\n" + //
+                "from flow_form_basic\r\n" + //
+                "where form_basic_data->>'re_is_status' != '06678b79185349b5bf0c24490a978fbb'\r\n" + //
+                "and form_basic_data->>'kf_file_time' is not null \r\n" + //
+                "and is_effctive = '1'\r\n" + //
+                "and to_timestamp(form_basic_data->>'kf_file_time', 'yyyy-mm-dd hh24:mi:ss') >= " +
+                "to_timestamp(concat(?, '01000000'), 'yyyymmddhh24miss') " +
+                "and to_timestamp(form_basic_data->>'kf_file_time', 'yyyy-mm-dd hh24:mi:ss') < " +
+                "(to_timestamp(concat(?, '01000000'), 'yyyymmddhh24miss') + interval '1 month'))," +
+                "t2 as (select city_id, kfsn, min(cost_time) as cost_time from t1 group by city_id, kfsn),\r\n" + //
+                "t3 as (select ? as month_id, city_id, avg(cost_time)::float8 as avg_duration from t2 group by city_id),"
+                + "t4 as (select ? as month_id, '全省' as city_id, avg(cost_time)::float8 as avg_duration from t2)" +
+                "select * from  t3 union select * from t4";
+        Object[] objects = new Object[] { month, month, month, month };
+        int[] argTypes = new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR };
+        Long startLong = System.currentTimeMillis();
+        List<Map<String, Object>> result = jdbcTemplate.queryForList(sql, objects, argTypes);
+        log.debug("从工作流读取{}月平均处理时长数据, 耗时 {} ms...",
+                month,
+                System.currentTimeMillis() - startLong);
+        return result;
     }
 }

+ 3 - 2
src/main/java/com/nokia/tsl_data/service/ReportServiceV3.java

@@ -385,10 +385,11 @@ public class ReportServiceV3 {
             cell.setCellValue(((double) list.get(6)));
             cell.setCellStyle(workbookWrapper.getCellStyle2());
         }
+        // 20240204 修正着色方式
         // 添加条件格式F4-F15
-        PoiUtil.setConditionalFormattingRedToGreen(sheet, 3, 14, 5, 5);
+        PoiUtil.setConditionalFormattingGreenToRed(sheet, 3, 14, 5, 5);
         // 添加条件格式G4-G15
-        PoiUtil.setConditionalFormattingRedToGreen(sheet, 3, 14, 6, 6);
+        PoiUtil.setConditionalFormattingGreenToRed(sheet, 3, 14, 6, 6);
         // 设置列宽2048
         for (int i = 0; i <= 6; i++) {
             sheet.setColumnWidth(i, 2848);

+ 0 - 62
src/main/java/com/nokia/tsl_data/service/TaskService.java

@@ -1,10 +1,5 @@
 package com.nokia.tsl_data.service;
 
-import com.alibaba.fastjson2.JSONArray;
-import com.alibaba.fastjson2.JSONObject;
-import com.nokia.tsl_data.dao.TaskRecordRepository;
-import com.nokia.tsl_data.dao.TslDataDao;
-import com.nokia.tsl_data.entity.TaskRecord;
 import com.nokia.tsl_data.properties.TslDataProperties;
 import com.nokia.tsl_data.scheduling.entity.RunnableTask;
 import com.nokia.tsl_data.scheduling.service.TaskScheduleService;
@@ -21,7 +16,6 @@ import java.io.File;
 import java.nio.file.Paths;
 import java.time.Instant;
 import java.time.temporal.ChronoUnit;
-import java.util.List;
 
 /**
  * 定时任务
@@ -30,12 +24,6 @@ import java.util.List;
 @Service
 public class TaskService {
 
-    @Autowired
-    private TslDataDao tslDataDao;
-    @Autowired
-    private TaskRecordRepository taskRecordRepository;
-    @Autowired
-    private WorkFlowService workFlowService;
     @Autowired
     private DataWarehouseService dataWarehouseService;
     @Autowired
@@ -124,54 +112,4 @@ public class TaskService {
         log.info("V3报表 {} 已生成总结...");
     }
 
-    /**
-     * 从工单系统定时更新数据
-     * 调度周期每三小时的10分调度一次
-     * 20240205开始不再执行
-     */
-    @Deprecated
-    // @Scheduled(cron = "0 10 0/3 * * *")
-    public void updateWorkFlowBasicDataTask() {
-        log.info("从工单系统定时更新数据 任务开始...");
-        Instant start = taskRecordRepository.findLastSuccessUpdateWorkFlowBasicDataTaskEndInstant();
-        Instant end = Instant.now();
-        TaskRecord taskRecord = workFlowService.updateWorkFlowBasicData(start, end);
-        taskRecordRepository.save(taskRecord);
-        log.info("从工单系统定时更新数据 任务完成...");
-    }
-
-    /**
-     * 定时删除过期的临时表
-     * 调度周期,每天凌晨1点调度一次
-     * 20240205后不再执行
-     */
-    @Deprecated
-    // @Scheduled(cron = "0 0 1 * * *")
-    public void tempTableCleanCronTask() {
-        log.info("定时删除过期的临时表 任务开始...");
-        TaskRecord taskRecord = new TaskRecord();
-        taskRecord.setTaskName("临时表清理");
-        taskRecord.setStartTime(Instant.now());
-        List<String> tempTableNames = tslDataDao.selectTempTableNames();
-        long zeroClockToday = DateFormatUtil.zeroClockTodayLong();
-        JSONObject jsonObject = new JSONObject();
-        JSONArray jsonArray = new JSONArray();
-        taskRecord.setTaskInfo(jsonObject);
-        for (String tempTableName : tempTableNames) {
-            // 保留当天的临时表不删除
-            long createTimestamp = Long.parseLong(tempTableName.substring(tempTableName.indexOf("_temp_") + 6));
-            if (createTimestamp < zeroClockToday) {
-                tslDataDao.dropTempTable(tempTableName);
-                jsonArray.add(tempTableName);
-            }
-        }
-        if (!jsonArray.isEmpty()) {
-            jsonObject.put("tempTableNames", jsonArray);
-        }
-        taskRecord.setEndStatus(0);
-        taskRecord.setEndTime(Instant.now());
-        taskRecord.setTimeCost(taskRecord.getEndTime().toEpochMilli() - taskRecord.getStartTime().toEpochMilli());
-        taskRecordRepository.save(taskRecord);
-        log.info("定时删除过期的临时表 任务完成...");
-    }
 }

+ 55 - 74
src/main/java/com/nokia/tsl_data/service/WorkFlowService.java

@@ -1,17 +1,10 @@
 package com.nokia.tsl_data.service;
 
-import com.alibaba.fastjson2.JSONObject;
 import com.nokia.tsl_data.dao.AvgDurationMapperV3;
 import com.nokia.tsl_data.dao.SysDataDictionaryRepository;
-import com.nokia.tsl_data.dao.TslDataDao;
-import com.nokia.tsl_data.dao.WorkFlowBasicDataMapper;
 import com.nokia.tsl_data.dao.WorkFlowDao;
-import com.nokia.tsl_data.entity.TaskRecord;
-import com.nokia.tsl_data.entity.WorkFlowBasicData;
 import com.nokia.tsl_data.properties.TslDataProperties;
 
-import lombok.extern.slf4j.Slf4j;
-
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -20,10 +13,8 @@ import java.text.SimpleDateFormat;
 import java.time.Instant;
 import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
-import java.time.temporal.ChronoUnit;
 import java.util.ArrayList;
 import java.util.Calendar;
-import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
@@ -32,77 +23,29 @@ import java.util.Map;
 /**
  * 用于所有查询工单流程的任务
  */
-@Slf4j
 @Service
 public class WorkFlowService {
 
     @Autowired
     private WorkFlowDao workFlowDao;
     @Autowired
-    private TslDataDao tslDataDao;
-    @Autowired
-    private WorkFlowBasicDataMapper workFlowBasicDataMapper;
-    @Autowired
     private SysDataDictionaryRepository sysDataDictionaryRepository;
     @Autowired
     private AvgDurationMapperV3 avgDurationMapperV3;
     @Autowired
     private TslDataProperties tslDataProperties;
 
-    private final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
+    private final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss")
             .withZone(ZoneId.of("Asia/Shanghai"));
 
-    /**
-     * 任务名称:更新工作流数据
-     */
-    @Deprecated
-    public TaskRecord updateWorkFlowBasicData(Instant start, Instant end) {
-        TaskRecord record = new TaskRecord();
-        record.setTaskName("更新工作流数据");
-        JSONObject jsonObject = new JSONObject();
-        record.setTaskInfo(jsonObject);
-        jsonObject.put("start", dateFormat.format(start));
-        jsonObject.put("end", dateFormat.format(end));
-        record.setStartTime(Instant.ofEpochMilli(System.currentTimeMillis()));
-        try {
-            List<WorkFlowBasicData> workFlowBasicDataList = workFlowDao.findWorkFlowBasicDataByUpdateTime(start, end);
-            log.debug("从工作流读取到 {} 条数据...", workFlowBasicDataList.size());
-            String tempTableName = "tsl_data.work_flow_basic_data_temp_" + System.currentTimeMillis();
-            tslDataDao.createTempTableOfWorkFlowBasicData(tempTableName);
-            log.debug("创建临时表: {} ...", tempTableName);
-            jsonObject.put("tempTableName", tempTableName);
-            tslDataDao.batchInsertWorkFlowBasicData(workFlowBasicDataList, tempTableName);
-            log.debug("数据已插入临时表 {} ...", tempTableName);
-            int insertCount = tslDataDao.insertWorkFlowBasicDataFromTempTable(tempTableName);
-            int updateCount = tslDataDao.updateWorkFlowBasicDataFromTempTable(tempTableName);
-            log.info("已完成工作流数据更新, 插入 {} 项, 更新 {} 项, 起: {} 止: {}",
-                    insertCount, updateCount, dateFormat.format(start), dateFormat.format(end));
-            record.setEndStatus(0);
-            record.setEndTime(Instant.ofEpochMilli(System.currentTimeMillis()));
-        } catch (Exception e) {
-            e.printStackTrace();
-            record.setEndStatus(-1);
-            record.setEndTime(Instant.ofEpochMilli(System.currentTimeMillis()));
-        } finally {
-            record.setTimeCost(ChronoUnit.MILLIS.between(record.getStartTime(), record.getEndTime()));
-        }
-        return record;
-    }
-
     /**
      * 超时工单情况
+     * 20240205更新
      */
     public List<List<Object>> getTimeoutCountInfo(String day) {
-        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
-        Date start, end;
-        try {
-            start = dateFormat.parse(day.substring(0, 6) + "01000000");
-            end = dateFormat.parse(day+"235959");
-        } catch (ParseException e) {
-            e.printStackTrace();
-            throw new RuntimeException(e.getMessage());
-        }
-        List<Map<String, Object>> data = workFlowBasicDataMapper.selectTimeoutTsCountForDay(start, end, tslDataProperties.getDuration());
+        Instant start = Instant.from(dateTimeFormatter.parse(day.substring(0, 6) + "01000000"));
+        Instant end = Instant.from(dateTimeFormatter.parse(day + "235959"));
+        List<Map<String, Object>> data = getTimeoutTsCountForDay(start, end);
         Map<String, Map<String, Object>> dayMap = new HashMap<>();
         for (Map<String, Object> map : data) {
             dayMap.put((String) map.get("city"), map);
@@ -160,20 +103,15 @@ public class WorkFlowService {
         List<Map<String, Object>> oldData = avgDurationMapperV3.selectOldTsDurationForMonth(oldMonthId);
         // 如果上月的平均处理时长数据不存在,需要插入
         if (oldData.size() == 0) {
-            avgDurationMapperV3.insertOldTsDurationForMonth(oldMonthId);
+            List<Map<String, Object>> tsDurationForMonth = getTsDurationForMonth(oldMonthId);
+            for (Map<String, Object> map : tsDurationForMonth) {
+                avgDurationMapperV3.insertOne(map);
+            }
             oldData = avgDurationMapperV3.selectOldTsDurationForMonth(oldMonthId);
         }
-        // 这里输入的参数格式应为 2014-01-01 00:00:00
-        SimpleDateFormat dateFormat2 = new SimpleDateFormat("yyyyMMddHHmmss");
-        Date start, end;
-        try {
-            start = dateFormat2.parse(day.substring(0, 6) + "01000000");
-            end = dateFormat2.parse(day+"235959");
-        } catch (ParseException e) {
-            e.printStackTrace();
-            throw new RuntimeException(e.getMessage());
-        }
-        List<Map<String, Object>> dayData = workFlowBasicDataMapper.selectTsDurationForDay(start, end);
+        Instant start = Instant.from(dateTimeFormatter.parse(day.substring(0, 6) + "01000000"));
+        Instant end = Instant.from(dateTimeFormatter.parse(day + "235959"));
+        List<Map<String, Object>> dayData = getTsDurationForDay(start, end);
         // 转化格式方便读取
         Map<String, Map<String, Object>> dayMap = new HashMap<>();
         Map<String, Map<String, Object>> preMap = new HashMap<>();
@@ -222,4 +160,47 @@ public class WorkFlowService {
         }
         return result;
     }
+
+    private List<Map<String, Object>> getTimeoutTsCountForDay(Instant start, Instant end) {
+        Map<String, String> workFlowCityMap = sysDataDictionaryRepository.findWorkFlowCityMap();
+        List<Map<String, Object>> selectTimeoutTsCountForDay = workFlowDao.selectTimeoutTsCountForDay(start, end,
+                tslDataProperties.getDuration());
+        for (Map<String, Object> map : selectTimeoutTsCountForDay) {
+            String city_id = (String) map.get("city_id");
+            if (city_id.equals("全省")) {
+                map.put("city", "全省");
+            } else {
+                map.put("city", workFlowCityMap.get(city_id));
+            }
+        }
+        return selectTimeoutTsCountForDay;
+    }
+
+    private List<Map<String, Object>> getTsDurationForDay(Instant start, Instant end) {
+        Map<String, String> workFlowCityMap = sysDataDictionaryRepository.findWorkFlowCityMap();
+        List<Map<String, Object>> selectTsDurationForDay = workFlowDao.selectTsDurationForDay(start, end);
+        for (Map<String, Object> map : selectTsDurationForDay) {
+            String city_id = (String) map.get("city_id");
+            if (city_id.equals("全省")) {
+                map.put("city", "全省");
+            } else {
+                map.put("city", workFlowCityMap.get(city_id));
+            }
+        }
+        return selectTsDurationForDay;
+    }
+
+    public List<Map<String, Object>> getTsDurationForMonth(String month) {
+        Map<String, String> workFlowCityMap = sysDataDictionaryRepository.findWorkFlowCityMap();
+        List<Map<String, Object>> result = workFlowDao.selectTsDurationForMonth(month);
+        for (Map<String, Object> map : result) {
+            String city_id = (String) map.get("city_id");
+            if (city_id.equals("全省")) {
+                map.put("city", "全省");
+            } else {
+                map.put("city", workFlowCityMap.get(city_id));
+            }
+        }
+        return result;
+    }
 }

+ 1 - 19
src/test/java/com/nokia/tsl_data/TslDataApplicationTest.java

@@ -1,17 +1,11 @@
 package com.nokia.tsl_data;
 
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
 import java.util.List;
-import java.util.Map;
-
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 
 import com.nokia.tsl_data.dao.TargetTsRatioMapper;
-import com.nokia.tsl_data.dao.WorkFlowBasicDataMapper;
 import com.nokia.tsl_data.service.TaskService;
 import com.nokia.tsl_data.util.TextUtil;
 
@@ -23,7 +17,7 @@ class TslDataApplicationTest {
 
     @Test
     void test() {
-        taskService.generateReportV3("20240120");
+        taskService.generateReportV3("20240203");
     }
 
     @Autowired
@@ -45,16 +39,4 @@ class TslDataApplicationTest {
         });
     }
 
-    @Autowired
-    private WorkFlowBasicDataMapper workFlowBasicDataMapper;
-
-    @Test
-    void test3() throws ParseException {
-        String day = "20240203";
-        SimpleDateFormat dateFormat2 = new SimpleDateFormat("yyyyMMddHHmmss");
-        Date start = dateFormat2.parse(day.substring(0, 6) + "01000000");
-        Date end = dateFormat2.parse(day+"235959");
-        List<Map<String, Object>> selectTsDurationForDay = workFlowBasicDataMapper.selectTsDurationForDay(start, end);
-        selectTsDurationForDay.forEach(System.out::println);
-    }
 }