소스 검색

修正了处理时长的问题

“lifuquan” 1 년 전
부모
커밋
bf2e6d66a3

+ 3 - 3
doc/开发环境/2023年适配/2024年适配.md

@@ -195,7 +195,7 @@ Content-Type: application/json
 POST http://192.168.10.7:22222/tsl_data/source/warehouse/complaint_details_fix_ywd
 Content-Type: application/json
 
-20240105
+20240107
 ```
 
 ### 2.5 management_detail
@@ -204,7 +204,7 @@ Content-Type: application/json
 POST http://192.168.10.7:22222/tsl_data/source/update/management_detail
 Content-Type: application/json
 
-20240105
+20240107
 ```
 
 ### 2.6 highQualityData
@@ -230,7 +230,7 @@ Content-Type: application/json
 POST http://192.168.10.7:22222/tsl_data/source/warehouse/cem_mobile_experience_list
 Content-Type: application/json
 
-20240108
+20240107
 ```
 
 ## 取消sheet2客户端考核, 新增 服务请求压降

+ 22 - 23
src/main/java/com/nokia/tsl_data/dao/TslDataDao.java

@@ -28,9 +28,9 @@ public class TslDataDao {
      */
     public void batchInsertWorkFlowBasicData(List<WorkFlowBasicData> data, String tableName) {
         String sqlFormat = "INSERT INTO %s " +
-                "(order_no, 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(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+                "(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);
@@ -38,11 +38,12 @@ public class TslDataDao {
                 Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
                 Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
                 Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
-                Types.TIMESTAMP, Types.TIMESTAMP
+                Types.VARCHAR, Types.TIMESTAMP, Types.TIMESTAMP
         });
         for (WorkFlowBasicData item : data) {
             batchSqlUpdate.update(
                     item.getOrderNo(),
+                    item.getIsEffctive(),
                     item.getKfsn(),
                     item.getCityId(),
                     item.getRegionId(),
@@ -58,13 +59,12 @@ public class TslDataDao {
     }
 
     /**
-     * 创建临时表,并返回临时表表名
+     * 创建临时表
      */
-    public String createTempTableOfWorkFlowBasicData() {
-        // 临时表添加一个时间戳
-        String tempTableName = "tsl_data.work_flow_basic_data_temp_" + System.currentTimeMillis();
+    public void createTempTableOfWorkFlowBasicData(String tempTableName) {
         String sql = "CREATE TABLE %s (  " + //
                 " order_no varchar(50) not null,  " + //
+                " is_effctive varchar(50) not null,  " + //
                 " kfsn varchar(50) NOT NULL,  " + //
                 " city_id varchar(50) NULL,  " + //
                 " region_id varchar(50) NULL,  " + //
@@ -77,7 +77,6 @@ public class TslDataDao {
                 " work_flow_update_time timestamp NULL " + //
                 ");";
         jdbcTemplate.update(String.format(sql, tempTableName));
-        return tempTableName;
     }
 
     /**
@@ -107,14 +106,14 @@ public class TslDataDao {
      */
     public int insertWorkFlowBasicDataFromTempTable(String tempTableName) {
         String sqlFormat = "insert into tsl_data.work_flow_basic_data" +
-                " (order_no, 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)" +
-                " select t.order_no, t.kfsn, t.city_id, t.region_id, t.kd_accept_time, t.kd_request_reply_time," +
-                " t.re_is_status_id, t.kf_file_time, t.kf_file_type, t.work_flow_create_time, t.work_flow_update_time" +
-                " from %s t " +
+                " (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)" +
+                " select t.order_no, t.is_effctive, t.kfsn, t.city_id, t.region_id, t.kd_accept_time, t.kd_request_reply_time,"
+                + " t.re_is_status_id, t.kf_file_time, t.kf_file_type, t.work_flow_create_time, t.work_flow_update_time"
+                + " from %s t " +
                 " left join tsl_data.work_flow_basic_data b" +
-                " on t.kfsn = b.kfsn" +
-                " where b.kfsn is null";
+                " on t.order_no = b.order_no" +
+                " where b.order_no is null";
         return jdbcTemplate.update(String.format(sqlFormat, tempTableName));
     }
 
@@ -123,15 +122,15 @@ public class TslDataDao {
      */
     public int updateWorkFlowBasicDataFromTempTable(String tempTableName) {
         String sqlFormat = "update tsl_data.work_flow_basic_data b\n" +
-                "set order_no = t.order_no, city_id = t.city_id, region_id = t.region_id, " +
-                " kd_accept_time = t.kd_accept_time, kd_request_reply_time = t.kd_request_reply_time, " +
+                "set kfsn = t.kfsn, is_effctive = t.is_effctive, city_id = t.city_id, region_id = t.region_id, "
+                + " kd_accept_time = t.kd_accept_time, kd_request_reply_time = t.kd_request_reply_time, " +
                 " re_is_status_id = t.re_is_status_id, kf_file_time = t.kf_file_time, " +
                 " kf_file_type = t.kf_file_type, work_flow_create_time = t.work_flow_create_time, " +
                 " work_flow_update_time = t.work_flow_update_time " +
-                " from (select order_no, 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 " +
+                " from (select 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 " +
                 " from %s ) t" +
-                " where b.kfsn = t.kfsn and (b.city_id != t.city_id or b.region_id != t.region_id)";
+                " where b.order_no = t.order_no";
         return jdbcTemplate.update(String.format(sqlFormat, tempTableName));
     }
 
@@ -234,8 +233,8 @@ public class TslDataDao {
      */
     public void batchInsertCemMobileExperienceList(List<Object[]> data) {
         String sql = "INSERT INTO tsl_data.cem_mobile_experience_list " + //
-                "(month_id, day_id, service_id, contact_id, create_time, mobile_no, service_type_name1,"+
-                " pro_name, code_cust_area, zyx, lwly_name, big_type_name, small_type_name, acct_month,"+
+                "(month_id, day_id, service_id, contact_id, create_time, mobile_no, service_type_name1," +
+                " pro_name, code_cust_area, zyx, lwly_name, big_type_name, small_type_name, acct_month," +
                 " day_id1, sheet_no, compl_city_local) " + //
                 "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
         jdbcTemplate.batchUpdate(sql, data);

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

@@ -18,14 +18,14 @@ public interface WorkFlowBasicDataMapper {
                         " - to_timestamp(kd_accept_time, 'yyyy-mm-dd hh24:mi:ss') > make_interval(hours => #{target}) as is_timeout\n"
                         + "from tsl_data.work_flow_basic_data wfbd, tsl_data.sys_data_dictionary sdd \n" + //
                         "where kf_file_time is not null and re_is_status_id != '06678b79185349b5bf0c24490a978fbb'\n" + //
-                        "and wfbd.city_id = sdd.nick_code and" +
-                        " to_timestamp(kf_file_time, 'yyyy-mm-dd hh24:mi:ss') >= #{start}"
+                        "and wfbd.city_id = sdd.nick_code and is_effctive = '1' " +
+                        " and to_timestamp(kf_file_time, 'yyyy-mm-dd hh24:mi:ss') >= #{start}"
                         + " and to_timestamp(kf_file_time, 'yyyy-mm-dd hh24:mi:ss') <= #{end})," +
                         "t2 as (select '全省' as city, count(1) as total_num, count(is_timeout or null) as timeout_num, "
                         + " count(is_timeout or null)::float8 / count(1) as timeout_ratio from t1),"
                         + " t3 as (select city, count(1) as total_num, count(is_timeout or null) as timeout_num, " +
                         " count(is_timeout or null)::float8 / count(1) as timeout_ratio from t1 group by city) " +
-                        " select * from t2 union select* from t3")
+                        " select * from t2 union select * from t3 ")
         List<Map<String, Object>> selectTimeoutTsCountForDay(@Param("start") Date start, @Param("end") Date end, @Param("target") int target);
 
         /**
@@ -35,12 +35,12 @@ public interface WorkFlowBasicDataMapper {
                         + " - 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" + //
                         " where wfbd.city_id = sdd.nick_code and kf_file_time is not null" +
-                        " and re_is_status_id != '06678b79185349b5bf0c24490a978fbb'\n"
+                        " and re_is_status_id != '06678b79185349b5bf0c24490a978fbb' and is_effctive = '1' "
                         + "and to_timestamp(wfbd.kf_file_time, 'yyyy-mm-dd hh24:mi:ss') >= #{start}" +
                         " and to_timestamp(wfbd.kf_file_time, 'yyyy-mm-dd hh24:mi:ss') <= #{end})," +
                         " t2 as (select real_name as city, avg(cost_time) as avg_duration\n" + //
                         " from t1 group by real_name order by real_name), " +
                         " t3 as (select '全省' as city, avg(cost_time) as avg_duration from t1)\n" + //
-                        " select * from t2 union select * from t3")
+                        " select * from t2 union select * from t3 ")
         List<Map<String, Object>> selectTsDurationForDay(@Param("start") Date start, @Param("end") Date end);
 }

+ 4 - 1
src/main/java/com/nokia/tsl_data/dao/WorkFlowDao.java

@@ -57,10 +57,12 @@ public class WorkFlowDao {
 
     // 获取update_time在两个范围之间的全部工单信息
     public List<WorkFlowBasicData> findWorkFlowBasicDataByUpdateTime(Instant start, Instant end) {
+        // 20240112 修改 使用 serv_order 替换了kfsn
         String sql = "select order_no, " + //
                 "city as city_id, " + //
+                "is_effctive as is_effctive, " + //
                 "form_basic_data->>'yh_region' as region_id, " + //
-                "form_basic_data->>'kd_kfsn' as kfsn, " + //
+                "form_basic_data->>'serv_order' as kfsn, " + //
                 "form_basic_data->>'kd_accepttime' as kd_accepttime, " + //
                 "form_basic_data->>'kd_requestreplytime' as kd_requestreplytime, " + //
                 "form_basic_data->>'re_is_status' as re_is_status_id, " + //
@@ -79,6 +81,7 @@ public class WorkFlowDao {
                 (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"));

+ 3 - 0
src/main/java/com/nokia/tsl_data/entity/WorkFlowBasicData.java

@@ -13,6 +13,9 @@ public class WorkFlowBasicData {
     private Long id;
     // 流程系统内工单号 唯一
     private String orderNo;
+    // is_effctive = '1' 
+    // 1 表示有效工单,0表示无效工单
+    private String isEffctive;
     // 客服工单号 理论上不应有重复,但是实际上会出现重复
     private String kfsn;
     // 归属地市

+ 1 - 1
src/main/java/com/nokia/tsl_data/service/CemMobileExperienceListService.java

@@ -112,7 +112,7 @@ public class CemMobileExperienceListService {
     public void checkStatDayCount(String day) {
         int count = cemMobileExperienceListMapper.countForDay(day);
         if (count == 0) {
-            throw new LackOfDataRuntimeException(String.format("management_detail 表缺少账期 %s 数据", day));
+            throw new LackOfDataRuntimeException(String.format("cemMobileExperienceList 表缺少账期 %s 数据", day));
         }
     }
 }

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

@@ -123,9 +123,9 @@ public class TaskService {
 
     /**
      * 从工单系统定时更新数据
-     * 调度周期每小时的10分调度一次
+     * 调度周期每小时的10分调度一次
      */
-    @Scheduled(cron = "0 10 * * * *")
+    @Scheduled(cron = "0 10 0/3 * * *")
     public void updateWorkFlowBasicDataTask() {
         log.info("从工单系统定时更新数据 任务开始...");
         Instant start = taskRecordRepository.findLastSuccessUpdateWorkFlowBasicDataTaskEndInstant();

+ 5 - 1
src/main/java/com/nokia/tsl_data/service/WorkFlowService.java

@@ -65,9 +65,13 @@ public class WorkFlowService {
         record.setStartTime(Instant.ofEpochMilli(System.currentTimeMillis()));
         try {
             List<WorkFlowBasicData> workFlowBasicDataList = workFlowDao.findWorkFlowBasicDataByUpdateTime(start, end);
-            String tempTableName = tslDataDao.createTempTableOfWorkFlowBasicData();
+            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("已完成工作流数据更新, 插入 {} 项, 更新 {} 项, 起: {} 止: {}",

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

@@ -1,10 +1,15 @@
 package com.nokia.tsl_data;
 
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+
 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.service.TaskService;
+import com.nokia.tsl_data.service.WorkFlowService;
 
 @SpringBootTest
 class TslDataApplicationTest {
@@ -14,7 +19,17 @@ class TslDataApplicationTest {
 
     @Test
     void test() {
-        taskService.generateReportV3("20240108");
+        taskService.generateReportV3("20240107");
     }
 
+    @Autowired
+    private WorkFlowService workFlowService;
+
+    @Test
+    void test1() {
+        DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
+                .withZone(ZoneId.of("Asia/Shanghai"));
+        Instant start = Instant.from(dateFormat.parse("2023-12-01 00:00:00"));
+        workFlowService.updateWorkFlowBasicData(start, Instant.now());
+    }
 }