燕山石化溯源三维电子沙盘-【后端】-服务
1
13693261870
2024-11-13 2f55cebbad3dea187a5f91d16ec80a9677dab699
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package com.yssh.controller;
 
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yssh.entity.xls.XlsReport;
import com.yssh.mapper.XlsReportMapper;
import com.yssh.service.XlsReportService;
import com.yssh.utils.DateUtils;
import com.yssh.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
 
@Api(tags="Excel报告")
@RestController
@RequestMapping("/xlsReport")
@SuppressWarnings("rawtypes")
public class XlsReportController {
    @Resource
    XlsReportMapper xlsReportMapper;
 
    @Resource
    XlsReportService xlsReportService;
 
    private static final List<String> TYPES = new ArrayList<>(Arrays.asList("day", "week", "month"));
 
    @ApiOperationSupport(order = 1)
    @GetMapping("/selectByPage")
    @ApiOperation(value = "分页查询", notes = "分页查询")
    public Result selectByPage(@RequestParam(value = "type", required = false) String type,
                               @RequestParam(value = "start", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date start,
                               @RequestParam(value = "end", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date end,
                               @RequestParam(value = "pageSize", required = false) Integer pageSize,
                               @RequestParam(value = "pageIndex", required = false) Integer pageIndex) {
        if (null == type || !TYPES.contains(type)) return Result.error("类型只能为:day,week,month。");
 
        if (null != start && null != end && start.getTime() > end.getTime()) {
            Date tmp = start;
            start = end;
            end = tmp;
        }
        String strStart = null == start ? null : DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, start);
        String strEnd = null == end ? null : DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, end);
 
        pageSize = null == pageSize || pageSize < 1 ? 10 : pageSize;
        pageIndex = null == pageIndex || pageIndex < 1 ? 1 : pageIndex;
        Integer offset = pageSize * (pageIndex - 1);
 
        Integer count = xlsReportMapper.selectReportCount(type, strStart, strEnd, pageSize, offset);
        List<XlsReport> list = 0 == count ? null : xlsReportMapper.selectReportByPage(type, strStart, strEnd, pageSize, offset);
 
        return Result.OK(count, list);
    }
 
    @ApiOperationSupport(order = 2)
    @GetMapping("/downloadById")
    @ApiOperation(value = "根据ID下载", notes = "根据ID下载")
    public void downloadById(@RequestParam(value = "id", required = true) int id, HttpServletResponse res) {
        xlsReportService.downloadById(id, res);
    }
 
    @ApiOperationSupport(order = 3)
    @GetMapping("/createDayReport")
    @ApiOperation(value = "创建日报", notes = "创建日报")
    public Result createDayReport(@RequestParam(value = "start", required = true) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date start,
                                  @RequestParam(value = "end", required = true) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date end) {
        if (null != start && null != end && start.getTime() > end.getTime()) {
            Date tmp = start;
            start = end;
            end = tmp;
        }
 
        Calendar cal = Calendar.getInstance();
        cal.setTime(start);
 
        while (cal.getTime().getTime() < end.getTime()) {
            xlsReportService.createDayReport(cal.getTime());
            cal.add(Calendar.DATE, 1);
        }
 
        return Result.OK("执行完毕!");
    }
 
    @ApiOperationSupport(order = 4)
    @GetMapping("/createWeekReport")
    @ApiOperation(value = "创建周报", notes = "创建周报")
    public Result createWeekReport(@RequestParam(value = "start", required = true) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date start,
                                   @RequestParam(value = "end", required = true) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date end) {
        if (null != start && null != end && start.getTime() > end.getTime()) {
            Date tmp = start;
            start = end;
            end = tmp;
        }
 
        Calendar cal = Calendar.getInstance();
        cal.setTime(start);
 
        while (cal.getTime().getTime() < end.getTime()) {
            xlsReportService.createWeekReport(cal.getTime());
            cal.add(Calendar.DATE, 7);
        }
 
        return Result.OK("执行完毕!");
    }
 
    @ApiOperationSupport(order = 5)
    @GetMapping("/createMonthReport")
    @ApiOperation(value = "创建月报", notes = "创建月报")
    public Result createMonthReport(@RequestParam(value = "start", required = true) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date start,
                                    @RequestParam(value = "end", required = true) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date end) {
        if (null != start && null != end && start.getTime() > end.getTime()) {
            Date tmp = start;
            start = end;
            end = tmp;
        }
 
        Calendar cal = Calendar.getInstance();
        cal.setTime(start);
 
        while (cal.getTime().getTime() < end.getTime()) {
            xlsReportService.createMonthReport(cal.getTime());
            cal.add(Calendar.MONTH, 1);
        }
 
        return Result.OK("执行完毕!");
    }
}