zhizhijie
12 小时以前 91d7eee872986f3aaa6e04edf843dd3a0526ba8f
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package com.trafficaudit.auditengine.controller;
 
import com.trafficaudit.auditengine.entity.AuditResult;
import com.trafficaudit.auditengine.service.AuditEngineService;
import com.trafficaudit.common.Result;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.List;
 
@RestController
@RequestMapping("/api/audit")
public class AuditController {
 
    @Resource
    private AuditEngineService auditService;
 
    @PostMapping("/execute")
    public Result<List<AuditResult>> executeAudit(@RequestParam("period") String period,
                                                  @RequestParam(value = "reportType", defaultValue = "H2032") String reportType) {
        List<AuditResult> results;
        if ("H2031".equals(reportType)) {
            results = auditService.executePassengerAudit(period);
        } else if ("H204".equals(reportType)) {
            results = auditService.executeEnergyAudit(period);
        } else if ("INVEST".equals(reportType)) {
            results = auditService.executeInvestmentAudit(period);
        } else if ("CITY_BUS".equals(reportType)) {
            results = auditService.executeCityBusAudit(period);
        } else if ("CITY_TAXI".equals(reportType)) {
            results = auditService.executeCityTaxiAudit(period);
        } else {
            results = auditService.executeAudit(period);
        }
        return Result.ok(results);
    }
 
    /** 标记该报表期+类型为「已审核」(线下审核通过的数据;先审核再出表的依据,导出前不再提示未审核) */
    @PostMapping("/markAudited")
    public Result<Boolean> markAudited(@RequestParam("period") String period,
                                       @RequestParam("reportType") String reportType) {
        return Result.ok(auditService.markAudited(reportType, period));
    }
 
    @GetMapping("/ruleStats")
    public Result<java.util.List<java.util.Map<String, Object>>> ruleStats(@RequestParam("period") String period,
                                                                           @RequestParam(value = "reportType", defaultValue = "H2032") String reportType) {
        return Result.ok(auditService.ruleStats(period, reportType));
    }
 
    @GetMapping("/latestPeriod")
    public Result<String> latestPeriod(@RequestParam(value = "reportType", defaultValue = "H2032") String reportType) {
        return Result.ok(auditService.latestPeriod(reportType));
    }
 
    @GetMapping("/export")
    public ResponseEntity<byte[]> exportResults(@RequestParam("period") String period,
                                                @RequestParam(value = "reportType", defaultValue = "H2032") String reportType) throws Exception {
        byte[] bytes = auditService.exportResults(period, reportType);
        String name = java.net.URLEncoder.encode("审核结果_" + period + ".xlsx", "UTF-8");
        return ResponseEntity.ok()
            .header("Content-Disposition", "attachment; filename*=UTF-8''" + name)
            .contentType(org.springframework.http.MediaType.APPLICATION_OCTET_STREAM)
            .body(bytes);
    }
 
    @GetMapping("/results")
    public Result<List<AuditResult>> getResults(@RequestParam("period") String period,
                                                @RequestParam(value = "reportType", defaultValue = "H2032") String reportType) {
        List<AuditResult> results = auditService.queryResults(period, reportType);
        return Result.ok(results);
    }
 
    @PostMapping("/review")
    public Result<String> review(@RequestParam("id") Long id,
                                 @RequestParam("status") String status,
                                 @RequestParam(value = "comment", required = false) String comment) {
        auditService.reviewResult(id, status, comment);
        return Result.ok("已处理");
    }
}