|
@@ -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;
|
|
|
}
|
|
|
}
|