lifuquan 1 年之前
父節點
當前提交
86522253e3

+ 50 - 0
doc/sql/sql备份.sql

@@ -0,0 +1,50 @@
+
+select acct_date, count(1)
+from tsl_data.high_quality_count_day
+group by acct_date
+order by acct_date;
+
+select month_id, day_id, count(1)
+from tsl_data.high_quality_list_day
+group by month_id, day_id
+order by month_id, day_id;
+
+select month_id, day_id, count(1)
+from tsl_data.mobile_complaint_day
+group by month_id, day_id
+order by month_id, day_id;
+
+select day_id, count(1)
+from tsl_data.high_quality_data
+group by day_id
+order by day_id;
+
+select month_id, city_name, management_target_ts_ratio, target_ts_ratio
+from report_auto.target_ts_ratio
+where month_id = '202312'
+order by city_name;
+
+update report_auto.target_ts_ratio
+set management_target_ts_ratio = 4.10, target_ts_ratio =4.1
+where month_id = '202312'
+  and city_name in ('保定', '秦皇岛', '唐山');
+update report_auto.target_ts_ratio
+set management_target_ts_ratio = 3.90, target_ts_ratio =3.9
+where month_id = '202312'
+  and city_name in ('沧州', '承德', '邯郸', '邢台');
+update report_auto.target_ts_ratio
+set management_target_ts_ratio = 3.40, target_ts_ratio =3.4
+where month_id = '202312'
+  and city_name = '衡水';
+update report_auto.target_ts_ratio
+set management_target_ts_ratio = 4.20, target_ts_ratio =4.2
+where month_id = '202312'
+  and city_name = '廊坊';
+update report_auto.target_ts_ratio
+set management_target_ts_ratio = 4.00, target_ts_ratio =4.0
+where month_id = '202312'
+  and city_name in ('石家庄', '张家口', '全省');
+update report_auto.target_ts_ratio
+set management_target_ts_ratio = 4.90, target_ts_ratio =4.9
+where month_id = '202312'
+  and city_name = '雄安';

+ 3 - 3
doc/接口测试.http

@@ -12,7 +12,7 @@ Content-Type: application/json
 POST http://192.168.10.7:22222/tsl_data/warehouse/mobile_complaint
 Content-Type: application/json
 
-20231105
+20231126
 
 ### 删除 mobile_complaint 数据
 POST http://192.168.10.7:22222/tsl_data/delete/mobile_complaint
@@ -24,7 +24,7 @@ Content-Type: application/json
 POST http://192.168.10.7:22222/tsl_data/warehouse/high_quality_count
 Content-Type: application/json
 
-20231105
+20231126
 
 ### 删除 high_quality_count 数据
 POST http://192.168.10.7:22222/tsl_data/delete/high_quality_count
@@ -36,7 +36,7 @@ Content-Type: application/json
 POST http://192.168.10.7:22222/tsl_data/warehouse/high_quality_list
 Content-Type: application/json
 
-20231105
+20231126
 
 ### 删除 high_quality_list 数据
 POST http://192.168.10.7:22222/tsl_data/delete/high_quality_list

+ 5 - 6
pom.xml

@@ -36,18 +36,17 @@
     </properties>
 
     <dependencies>
-        <!-- spring-context-holder-starter -->
-        <dependency>
-            <groupId>com.nokia</groupId>
-            <artifactId>spring-context-holder-starter</artifactId>
-            <version>1.0.0</version>
-        </dependency>
         <!-- push-message-starter -->
         <dependency>
             <groupId>com.nokia</groupId>
             <artifactId>push-message-starter</artifactId>
             <version>1.1.0</version>
         </dependency>
+        <dependency>
+            <groupId>com.nokia</groupId>
+            <artifactId>scheduling-starter</artifactId>
+            <version>1.0.0-SNAPSHOT</version>
+        </dependency>
         <!-- common-utils -->
         <dependency>
             <groupId>com.nokia</groupId>

+ 2 - 0
src/main/java/com/nokia/tsl_data/TslDataApplication.java

@@ -1,11 +1,13 @@
 package com.nokia.tsl_data;
 
+import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
 
 @SpringBootApplication
 @EnableJpaAuditing
+@MapperScan("com.nokia.tsl_data.dao")
 public class TslDataApplication {
 
     public static void main(String[] args) {

+ 33 - 0
src/main/java/com/nokia/tsl_data/config/RequestLogConfig.java

@@ -0,0 +1,33 @@
+package com.nokia.tsl_data.config;
+
+import com.nokia.common.http.logging.RequestLogDispatcherServlet;
+import com.nokia.common.http.logging.RequestLogHandlerInterceptor;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.DispatcherServlet;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+@Configuration
+public class RequestLogConfig implements WebMvcConfigurer {
+
+    /**
+     * 添加拦截器
+     */
+    @Override
+    public void addInterceptors(InterceptorRegistry registry) {
+        // 添加日志拦截器
+        registry.addInterceptor(new RequestLogHandlerInterceptor()).addPathPatterns("/**");
+    }
+
+    /**
+     * 注入自定义的RequestLogDispatcherServlet替代默认的DispatcherServlet
+     */
+    @Bean
+    @Qualifier(DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_BEAN_NAME)
+    public DispatcherServlet dispatcherServlet() {
+        return new RequestLogDispatcherServlet();
+    }
+}

+ 0 - 35
src/main/java/com/nokia/tsl_data/controller/TaskSchedulingController.java

@@ -1,35 +0,0 @@
-package com.nokia.tsl_data.controller;
-
-import com.nokia.common.http.vo.R;
-import com.nokia.tsl_data.entity.ScheduledTask;
-import com.nokia.tsl_data.service.SchedulingTaskService;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import java.util.List;
-
-@Slf4j
-@RestController
-@RequestMapping("tsl_data/scheduling")
-public class TaskSchedulingController {
-
-    private final SchedulingTaskService schedulingTaskService;
-
-    public TaskSchedulingController(SchedulingTaskService schedulingTaskService) {
-        this.schedulingTaskService = schedulingTaskService;
-    }
-
-    @PostMapping("task/list")
-    public R listTasksScheduled() {
-        List<ScheduledTask> scheduledTasks = schedulingTaskService.listTasksScheduled();
-        return R.ok().data(scheduledTasks);
-    }
-
-    public R addTask(ScheduledTask scheduledTask) {
-        log.info("{}", scheduledTask);
-
-        return R.ok();
-    }
-}

+ 2 - 2
src/main/java/com/nokia/tsl_data/dao/HighQualityCountMapper.java

@@ -29,8 +29,8 @@ public interface HighQualityCountMapper {
             "       complaint_response_count::float8 + complaint::float8                                     as denominator,\n" +
             "       complaint_response_list::float8 / (complaint_response_count::float8 + complaint::float8) as rate\n" +
             "from tsl_data.high_quality_count_day\n" +
-            "where month_id = substring('20231105' from 1 for 6)\n" +
-            "  and day_id = substring('20231105' from 7 for 2)\n" +
+            "where month_id = substring(#{day_id} from 1 for 6)\n" +
+            "  and day_id = substring(#{day_id} from 7 for 2)\n" +
             "  and profes_dep = '网络质量'\n" +
             "  and big_type_name = '移网网络体验'\n" +
             "  and small_type_name = '--'")

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

@@ -22,7 +22,7 @@ public interface HighQualityDataMapper {
      */
     @Select("select checked_region as region, count(1) as count " +
             "from tsl_data.high_quality_data hqd " +
-            "where day_id = '20231105' and (cp_is_ok  = '未解决' or no_visit_tag = '未回访') " +
+            "where day_id = #{day_id} and (cp_is_ok  = '未解决' or no_visit_tag = '未回访') " +
             "group by checked_region ")
     List<Map<String, Object>> selectCountOfCpNotOkOfRegion(@Param("day_id") String day);
 

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

@@ -41,7 +41,7 @@ public interface MobileComplaintMapper {
             "          - extract('epoch' from to_timestamp(accept_time, 'YYYY-MM-DD HH24:MI:SS'))) / 3600 " +
             "     end as duration from tsl_data.mobile_complaint_day " +
             "where month_id = substring(#{day} from 1 for 6) and day_id = substring(#{day} from 7 for 2)) " +
-            "select compl_area_local, avg(duration) as avg_duration from t1 group by compl_area_local")
+            "select compl_area_local, avg(duration)::float8 as avg_duration from t1 group by compl_area_local")
     List<Map<String, Object>> selectTsDurationForDay(String day);
 
     /**

+ 0 - 22
src/main/java/com/nokia/tsl_data/dao/ScheduledTaskMapper.java

@@ -1,22 +0,0 @@
-package com.nokia.tsl_data.dao;
-
-import com.nokia.tsl_data.entity.ScheduledTask;
-import org.apache.ibatis.annotations.Mapper;
-import org.apache.ibatis.annotations.Select;
-
-import java.util.List;
-
-/**
- * 存储任务调度数据
- */
-@Mapper
-public interface ScheduledTaskMapper {
-
-    /**
-     * 查找启动的任务
-     * TODO sql
-     */
-    @Select("")
-    List<ScheduledTask> selectTasksIsOn();
-
-}

+ 0 - 41
src/main/java/com/nokia/tsl_data/entity/ScheduledTask.java

@@ -1,41 +0,0 @@
-package com.nokia.tsl_data.entity;
-
-import com.nokia.tsl_data.entity._enum.ScheduledType;
-import com.nokia.tsl_data.entity.pojo.ScheduledParameter;
-import lombok.Data;
-
-import java.time.Instant;
-
-/**
- * 已注册的任务 对应表`scheduled_task`
- */
-@Data
-public class ScheduledTask {
-
-    /**
-     * id 唯一
-     */
-    private Long id;
-
-    private String name;
-
-    /**
-     * 任务状态 true 启动 false 关闭
-     * 对于 定时调度和周期调度 启动和关闭表示
-     */
-    private Boolean status;
-
-    private String beanName;
-
-    private String methodName;
-
-    private String methodParameter;
-
-    private ScheduledType scheduledType;
-
-    private ScheduledParameter scheduledParameter;
-
-    private Instant createTime;
-
-    private Instant lastModify;
-}

+ 0 - 21
src/main/java/com/nokia/tsl_data/entity/_enum/ScheduledType.java

@@ -1,21 +0,0 @@
-package com.nokia.tsl_data.entity._enum;
-
-/**
- * 任务调度类型
- * IMMEDIATELY 立即调度
- * ONCE 按指定的时间或者延时调度一次
- * CRON 定时调度
- * INTERVAL 周期调度
- */
-public enum ScheduledType {
-    IMMEDIATELY, ONCE, CRON, INTERVAL;
-
-    public static ScheduledType ofValue(String value) {
-        for (ScheduledType type : values()) {
-            if (type.toString().equalsIgnoreCase(value)) {
-                return type;
-            }
-        }
-        throw new RuntimeException("不存在 " + value + " 对应的ScheduledType, 允许的type有:IMMEDIATELY、ONCE、CRON、INTERVAL");
-    }
-}

+ 0 - 56
src/main/java/com/nokia/tsl_data/entity/pojo/RunnableTask.java

@@ -1,56 +0,0 @@
-package com.nokia.tsl_data.entity.pojo;
-
-import com.nokia.common.spring.context.SpringContextHolder;
-import com.nokia.tsl_data.entity.ScheduledTask;
-import lombok.Data;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.NoSuchBeanDefinitionException;
-import org.springframework.util.ReflectionUtils;
-import org.springframework.util.StringUtils;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-/**
- * 执行任务的实体类
- */
-@Slf4j
-@Data
-public class RunnableTask implements Runnable{
-
-    private final SpringContextHolder springContextHolder;
-    private final ScheduledTask scheduledTask;
-
-    public RunnableTask(SpringContextHolder springContextHolder, ScheduledTask scheduledTask) {
-        this.springContextHolder = springContextHolder;
-        this.scheduledTask = scheduledTask;
-    }
-
-    @Override
-    public void run() {
-        try {
-            Object bean = springContextHolder.getBean(scheduledTask.getBeanName());
-            Method method;
-            if (!StringUtils.hasLength(scheduledTask.getMethodParameter())) {
-                method = bean.getClass().getDeclaredMethod(scheduledTask.getMethodName());
-                ReflectionUtils.makeAccessible(method);
-                method.invoke(bean);
-            } else {
-                method = bean.getClass().getDeclaredMethod(scheduledTask.getMethodName(), String.class);
-                method.invoke(bean, scheduledTask.getMethodParameter());
-            }
-        } catch (NoSuchBeanDefinitionException e) {
-            e.printStackTrace();
-            log.error("未找到任务--任务:{}", scheduledTask);
-        } catch (NoSuchMethodException e) {
-            e.printStackTrace();
-            log.error("未找到方法--任务:{}", scheduledTask);
-        } catch (IllegalAccessException e) {
-            e.printStackTrace();
-            log.error("方法不允许访问--任务:{}", scheduledTask);
-        } catch (InvocationTargetException e) {
-            e.printStackTrace();
-            log.error("方法执行出错--任务:{}", scheduledTask);
-        }
-    }
-}

+ 0 - 29
src/main/java/com/nokia/tsl_data/entity/pojo/ScheduledParameter.java

@@ -1,29 +0,0 @@
-package com.nokia.tsl_data.entity.pojo;
-
-import com.fasterxml.jackson.annotation.JsonFormat;
-import lombok.Data;
-
-import java.util.Date;
-
-/**
- * 调度参数
- */
-@Data
-public class ScheduledParameter {
-
-    /**
-     * 定时任务表达式
-     */
-    private String cronExpression;
-
-    /**
-     * 启动时间
-     */
-    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
-    private Date startTime;
-
-    /**
-     * 以秒计算的数字
-     */
-    private Long periodOfSeconds;
-}

+ 0 - 19
src/main/java/com/nokia/tsl_data/service/DemoService.java

@@ -1,19 +0,0 @@
-package com.nokia.tsl_data.service;
-
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Service;
-
-@Slf4j
-@Service
-public class DemoService {
-
-    public void test() {
-        log.info("=======test start=======");
-        try {
-            Thread.sleep(1000 * 10L);
-        } catch (InterruptedException e) {
-            e.printStackTrace();
-        }
-        log.info("=======test end=======");
-    }
-}

+ 0 - 179
src/main/java/com/nokia/tsl_data/service/SchedulingTaskService.java

@@ -1,179 +0,0 @@
-package com.nokia.tsl_data.service;
-
-import com.nokia.common.spring.context.SpringContextHolder;
-import com.nokia.tsl_data.dao.ScheduledTaskMapper;
-import com.nokia.tsl_data.entity.ScheduledTask;
-import com.nokia.tsl_data.entity.pojo.RunnableTask;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.scheduling.Trigger;
-import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
-import org.springframework.scheduling.support.CronTrigger;
-import org.springframework.stereotype.Service;
-
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.nio.file.StandardOpenOption;
-import java.time.Duration;
-import java.time.Instant;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ScheduledFuture;
-
-/**
- * 任务注册服务
- * 1. 启动时初始化任务
- * 2. 关闭时保存未完成任务
- * 3. 任务调度
- * 4. 任务取消
- * 5. 任务列表
- */
-@Slf4j
-@Service
-public class SchedulingTaskService {
-
-    // 使用id作为任务唯一标识
-    private final ConcurrentHashMap<ScheduledTask, ScheduledFuture<?>> tasksScheduled = new ConcurrentHashMap<>();
-    private final ThreadPoolTaskScheduler taskScheduler;
-    private final ScheduledTaskMapper scheduledTaskMapper;
-    private final SpringContextHolder springContextHolder;
-
-    public SchedulingTaskService(ThreadPoolTaskScheduler taskScheduler, ScheduledTaskMapper scheduledTaskMapper, SpringContextHolder springContextHolder) {
-        this.taskScheduler = taskScheduler;
-        this.scheduledTaskMapper = scheduledTaskMapper;
-        this.springContextHolder = springContextHolder;
-    }
-
-    /**
-     * 增加任务
-     */
-    public void addTask(ScheduledTask scheduledTask) {
-
-    }
-
-    /**
-     * 更新任务
-     */
-    public void updateTask(ScheduledTask scheduledTask) {
-
-    }
-
-    /**
-     * 删除任务
-     */
-    public void deleteTask(ScheduledTask scheduledTask) {
-
-    }
-
-    /**
-     * 调度任务
-     */
-    private void scheduleTask(ScheduledTask scheduledTask) {
-        if (tasksScheduled.containsKey(scheduledTask)) {
-            throw new RuntimeException("已存在相同任务,请勿重复调度...");
-        }
-        Runnable runnable = new RunnableTask(springContextHolder, scheduledTask);
-        if (scheduledTask.getStatus()) {
-            ScheduledFuture<?> future = null;
-            switch (scheduledTask.getScheduledType()) {
-                case CRON:
-                    // 调度定时任务
-                    Trigger trigger = new CronTrigger(scheduledTask.getScheduledParameter().getCronExpression());
-                    future = taskScheduler.schedule(runnable, trigger);
-                    break;
-                case INTERVAL:
-                    // 周期任务
-                    Date startTime = scheduledTask.getScheduledParameter().getStartTime();
-                    Duration period = Duration.ofSeconds(scheduledTask.getScheduledParameter().getPeriodOfSeconds());
-                    if (startTime == null || startTime.getTime() <= System.currentTimeMillis()) {
-                        //
-                        future = taskScheduler.scheduleAtFixedRate(runnable, period);
-                    } else {
-                        future = taskScheduler.scheduleAtFixedRate(runnable, startTime.toInstant(), period);
-                    }
-                    break;
-                case ONCE:
-                    // 单次任务
-                    Date startTimeForOnceTask = scheduledTask.getScheduledParameter().getStartTime();
-                    if (startTimeForOnceTask.getTime() >= System.currentTimeMillis()) {
-                        // 单次任务只有在启动时间大于等于当前时间时才启动调度
-                        future = taskScheduler.schedule(runnable, startTimeForOnceTask);
-                    } else {
-                        // 当启动时间早于当前时间时,直接报错
-                        throw new RuntimeException("单次任务(ONCE)调度时间不能早于当前时间...");
-                    }
-                    break;
-                case IMMEDIATELY:
-                    // 马上执行的任务
-                default:
-                    future = taskScheduler.schedule(runnable, Instant.now());
-                    break;
-            }
-            if (future != null) {
-                tasksScheduled.put(scheduledTask, future);
-            }
-        }
-    }
-
-    /**
-     * 列出已注册调度任务的列表
-     */
-    public List<ScheduledTask> listTasksScheduled() {
-        List<ScheduledTask> result = new ArrayList<>();
-        // 遍历所有正在调度的任务
-        for (Map.Entry<ScheduledTask, ScheduledFuture<?>> entry : tasksScheduled.entrySet()) {
-            ScheduledFuture<?> future = entry.getValue();
-            if (future.isDone()) {
-                tasksScheduled.remove(entry.getKey());
-            } else {
-                result.add(entry.getKey());
-            }
-        }
-        return result;
-    }
-
-    /**
-     * 取消任务
-     */
-    public void cancelTask(ScheduledTask scheduledTask) {
-        ScheduledFuture<?> future = tasksScheduled.remove(scheduledTask);
-        if (future != null) {
-            future.cancel(true);
-        }
-    }
-
-    /**
-     * 在启动时获取需要调度的任务并进行调度
-     */
-    @PostConstruct
-    public void postConstruct() {
-        log.info("启动时初始化任务...");
-        List<ScheduledTask> scheduledTasks = scheduledTaskMapper.selectTasksIsOn();
-        for (ScheduledTask scheduledTask : scheduledTasks) {
-            try {
-                scheduleTask(scheduledTask);
-            }catch (Exception e) {
-                log.info("初始化任务 {} 出错: {}", scheduledTask, e.getMessage());
-            }
-        }
-    }
-
-    /**
-     * 在退出程序前保存程序调度的状态
-     */
-    @PreDestroy
-    public void preDestroy() throws IOException {
-        // TODO
-        log.info("============preDestroy===========");
-        List<String> lines = new ArrayList<>();
-        lines.add("=======preDestroy========");
-        lines.add(String.valueOf(System.currentTimeMillis()));
-        log.info(Paths.get("./output/aaa.text").toAbsolutePath().toString());
-        Files.write(Paths.get("./output/aaa.text"), lines, StandardOpenOption.APPEND);
-    }
-}

+ 13 - 14
src/main/resources/application.yml

@@ -3,15 +3,10 @@ server:
 
 Spring:
   profiles:
-    active: pro
+    active: dev
   jpa:
     hibernate:
       ddl-auto: update
-  datasource:
-    driver-class-name: org.postgresql.Driver
-    url: jdbc:postgresql://192.168.10.9:5432/sqmmt
-    username: postgres
-    password: Richr00t#
 
 mybatis:
   mapper-locations: classpath:mapper/**.xml
@@ -20,24 +15,28 @@ logging:
   level:
     org:
       hibernate:
-        SQL: DEBUG  # 开启SQL的log 这里需要设置为DEBUG
+        SQL: INFO  # 开启SQL的log 这里需要设置为DEBUG
         type:
           descriptor:
             sql:
-              BasicBinder: TRACE  # 开启SQL的参数记录 这里需要设置为TRACE
+              BasicBinder: INFO  # 开启SQL的参数记录 这里需要设置为TRACE
     com:
       nokia: DEBUG
 
 ---
 spring:
   profiles: pro
+  datasource:
+    driver-class-name: org.postgresql.Driver
+    url: jdbc:postgresql://192.168.10.9:5432/sqmmt
+    username: postgres
+    password: Richr00t#
 
 ---
 spring:
   profiles: dev
-
-tsl:
-  source:
-    dirOfHighQualityListDay: D:/src/20231028
-    dirOfHighQualityCountDay: D:/src/20231028
-    dirOfMobileComplaint: D:/src/20231028
+  datasource:
+    driver-class-name: org.postgresql.Driver
+    url: jdbc:postgresql://localhost:5432/tsl_data
+    username: postgres
+    password: fantuan1985

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

@@ -1,5 +1,6 @@
 package com.nokia.tsl_data;
 
+import com.nokia.common.scheduling.service.DemoService;
 import com.nokia.tsl_data.service.TslReportService;
 import com.nokia.tsl_data.service.UserCountService;
 import org.junit.jupiter.api.Test;
@@ -50,6 +51,15 @@ class TslDataApplicationTest {
 
     @Test
     void test() {
-        tslReportService.screenShot("20231105");
+        tslReportService.generateReport("20231126");
+        tslReportService.screenShot("20231126");
+    }
+
+    @Autowired
+    private DemoService demoService;
+
+    @Test
+    void test3() {
+        demoService.test1();
     }
 }