baoshiwei
2025-04-23 c2375c2bcc0bf9e6a3af7f9776d5a0eb14370b40
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.zhitan.engine.controller;
 
import com.zhitan.engine.scheduler.DataCleaningScheduler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
 
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
 
/**
 * 数据清洗控制器
 * 提供手动触发数据清洗任务的API接口
 */
@Slf4j
@RestController
@RequestMapping("/api/data-cleaning")
public class DataCleaningController {
 
    @Autowired
    private DataCleaningScheduler dataCleaningScheduler;
 
    /**
     * 手动触发数据清洗任务
     *
     * @param timeType 时间类型:HOUR, DAY, MONTH, YEAR
     * @param dateTime 统计时间点
     * @return 处理结果
     */
    @PostMapping("/trigger")
    public ResponseEntity<Map<String, Object>> triggerDataCleaning(
            @RequestParam("timeType") String timeType,
            @RequestParam("dateTime") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime dateTime) {
        log.info("收到手动触发数据清洗请求,时间类型:{},时间点:{}", timeType, dateTime);
        
        Map<String, Object> result = new HashMap<>();
        try {
            // 验证时间类型
            if (!"HOUR".equals(timeType) && !"DAY".equals(timeType) 
                    && !"MONTH".equals(timeType) && !"YEAR".equals(timeType)) {
                result.put("success", false);
                result.put("message", "不支持的时间类型:" + timeType);
                return ResponseEntity.badRequest().body(result);
            }
            
            // 触发任务
            dataCleaningScheduler.manualTrigger(timeType, dateTime);
            
            result.put("success", true);
            result.put("message", "任务已触发,请查看日志了解执行情况");
            return ResponseEntity.ok(result);
        } catch (Exception e) {
            log.error("触发数据清洗任务失败:{}", e.getMessage(), e);
            result.put("success", false);
            result.put("message", "触发任务失败:" + e.getMessage());
            return ResponseEntity.internalServerError().body(result);
        }
    }
}