mitao
2024-08-23 3a6f2b349aaac3fd9f895c16f7d833252a2158ab
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
package com.finance.web.controller.api;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.finance.common.annotation.FinancialLog;
import com.finance.common.annotation.HistoryGroup;
import com.finance.common.basic.PageDTO;
import com.finance.common.core.domain.R;
import com.finance.common.enums.BusinessType;
import com.finance.common.exception.ServiceException;
import com.finance.system.domain.TbBasicData;
import com.finance.system.dto.update.BasicDataUpdDTO;
import com.finance.system.query.CurrentFieldsQuery;
import com.finance.system.query.HistoryDataQuery;
import com.finance.system.query.QuestionQuery;
import com.finance.system.query.ScoreCalculateDetailQuery;
import com.finance.system.query.ScoreCalculateQuery;
import com.finance.system.service.TbBasicDataService;
import com.finance.system.service.TbQuestionService;
import com.finance.system.service.TbScoreService;
import com.finance.system.vo.BasicDataVO;
import com.finance.system.vo.CurrentFieldsAllVO;
import com.finance.system.vo.CurrentFieldsDetailVO;
import com.finance.system.vo.CurrentFieldsVO;
import com.finance.system.vo.QuestionVO;
import com.finance.system.vo.ScoreCalculateDetailVO;
import com.finance.system.vo.ScoreCalculateVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
 
/**
 * @author mitao
 * @date 2024/4/8
 */
@Slf4j
@RestController
@RequestMapping("/history-data")
@RequiredArgsConstructor
@Api(tags = "历史数据相关接口")
public class HistoryDataController {
 
    private final TbBasicDataService tbBasicDataService;
    private final TbScoreService tbScoreService;
    private final TbQuestionService tbQuestionService;
 
    /**
     * 历史数据分页查询
     *
     * @param dto 历史数据查询传输对象
     * @return R<PageDTO < BasicDataVO>>
     */
    @PostMapping("/page-data")
    @ApiOperation("历史数据分页查询")
    public R<PageDTO<BasicDataVO>> pageData(@Validated @RequestBody HistoryDataQuery dto) {
        Date startTime = dto.getStartTime();
        Date endTime = dto.getEndTime();
        boolean flag = Objects.nonNull(startTime) && Objects.nonNull(endTime);
        Page<TbBasicData> page =
                tbBasicDataService
                        .lambdaQuery()
                        // .eq(TbBasicData::getStatus, ReportingStatusEnum.FILLED)
                        .between(flag, TbBasicData::getReportingTime, startTime, endTime)
                        .groupBy(TbBasicData::getQuarter)
                        .orderByDesc(TbBasicData::getReportingTime)
                        .page(new Page<>(dto.getPageNum(), dto.getPageSize()));
        return R.ok(PageDTO.of(page, BasicDataVO.class));
    }
 
    /**
     * 字段统计
     *
     * @return R<PageDTO < CurrentFieldsVO>>
     */
    @ApiOperation(value = "字段统计", notes = "字段统计")
    @PostMapping("/fields-statics")
    public R<PageDTO<CurrentFieldsVO>> historyFieldsStatics(
            @Validated({HistoryGroup.class}) @RequestBody CurrentFieldsQuery dto) {
        try {
            return tbBasicDataService.historyFieldsStatics(dto);
        } catch (Exception e) {
            log.error("获取字段统计相关信息异常", e);
            return R.fail();
        }
    }
 
    /**
     * 查看详情
     *
     * @param id 基础数据id
     * @return R<CurrentFieldsDetailVO>
     */
    @GetMapping("/fields-details")
    @ApiOperation(value = "字段统计-查看详情", notes = "字段统计")
    @ApiImplicitParam(
            name = "id",
            value = "基础数据id",
            required = true,
            dataType = "int",
            paramType = "query",
            dataTypeClass = Long.class)
    public R<CurrentFieldsDetailVO> fieldsDetails(@RequestParam("id") Long id) {
        try {
            return tbBasicDataService.fieldsDetails(id);
        } catch (Exception e) {
            if (e instanceof ServiceException) {
                return R.fail(e.getMessage());
            }
            log.error("保存当前季度数据异常", e);
            return R.fail();
        }
    }
 
    @PostMapping("/save-basic-data")
    @ApiOperation("字段统计-保存数据")
    public R<Void> editBasicData(@RequestBody BasicDataUpdDTO dto) {
        try {
            tbBasicDataService.editBasicData(dto);
        } catch (Exception e) {
            if (e instanceof ServiceException) {
                return R.fail(e.getMessage());
            }
            log.error("保存数据异常", e);
            return R.fail();
        }
        return R.ok();
    }
 
    /**
     * 查看全部
     *
     * @return R<CurrentFieldsAllVO>
     */
    @GetMapping("/fields-statics-all")
    @ApiOperation(value = "查看全部", notes = "字段统计")
    @ApiImplicitParam(
            name = "quarter",
            value = "季度",
            required = true,
            dataType = "string",
            paramType = "query",
            dataTypeClass = String.class)
    public R<CurrentFieldsAllVO> fieldsStaticsAll(@RequestParam("quarter") String quarter) {
        try {
            return R.ok(tbBasicDataService.fieldsStaticsAll(quarter));
        } catch (Exception e) {
            if (e instanceof ServiceException) {
                return R.fail(e.getMessage());
            }
            log.error("查看全部异常", e);
            return R.fail();
        }
    }
 
    /**
     * 得分计算
     *
     * @param query 得分计算条件查询对象
     * @return R<PageDTO < ScoreVO>>
     */
    @PostMapping("/score-calculate")
    @ApiOperation("得分计算")
    public R<PageDTO<ScoreCalculateVO>> scoreCalculate(
            @Validated({HistoryGroup.class}) @RequestBody ScoreCalculateQuery query) {
        return R.ok(tbBasicDataService.scoreCalculatePage(query));
    }
 
    /**
     * 得分计算查看详情
     *
     * @param query 得分计算详情条件查询对象
     * @return R<ScoreCalculateDetailVO>
     */
    @PostMapping("/score-calculate-detail")
    @ApiOperation("得分计算-查看详情")
    public R<ScoreCalculateDetailVO> scoreCalculateDetail(
            @Validated @RequestBody ScoreCalculateDetailQuery query) {
        try {
            return R.ok(tbScoreService.scoreCalculateHistoryDetail(query));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
 
    /**
     * 分页查询问题
     *
     * @param dto 发现问题分页数据传输对象
     * @return R<PageDTO < QuestionVO>>
     */
    @PostMapping("/page-question")
    @ApiOperation(value = "问题查看-分页查询问题", notes = "问题查看")
    public R<PageDTO<QuestionVO>> pageQuestion(
            @Validated({HistoryGroup.class}) @RequestBody QuestionQuery dto) {
        return R.ok(tbQuestionService.pageQuestion(dto));
    }
 
    @PostMapping("/import")
    @ApiOperation("导入历史数据")
    @FinancialLog(title = "导入数据", businessType = BusinessType.IMPORT)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "文件", required = true, dataType = "file", paramType = "form"),
            @ApiImplicitParam(name = "quarter", value = "季度 e.g. 2024年一季度", required = true, dataType = "string", paramType = "query", dataTypeClass = String.class)
    })
    public R<Void> importData(@RequestPart("file") MultipartFile file,
            @RequestParam("quarter") String quarter) {
        try {
            tbBasicDataService.importData(file, quarter);
        } catch (Exception e) {
            if (e instanceof ServiceException) {
                return R.fail(e.getMessage());
            }
            log.error("导入历史数据异常", e);
            return R.fail();
        }
        return R.ok();
    }
 
    @PostMapping("/export")
    @ApiOperation("导出")
    @FinancialLog(title = "导出数据", businessType = BusinessType.EXPORT)
    @ApiImplicitParam(name = "quarterList", value = "quarterList", allowMultiple = true, dataTypeClass = List.class, paramType = "query")
    public void exportData(@RequestParam("quarterList") List<String> quarterList) {
        try {
            tbBasicDataService.exportData(quarterList);
        } catch (Exception e) {
            log.error("导出历史数据异常", e);
        }
    }
}