mitao
2024-08-30 6af08bad1986a72fa196afeb04c389c005fab673
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
package com.finance.web.controller.api;
 
import com.finance.common.basic.PageDTO;
import com.finance.common.core.domain.R;
import com.finance.common.exception.ServiceException;
import com.finance.common.utils.BeanUtils;
import com.finance.common.utils.DateUtils;
import com.finance.system.domain.TbQuestion;
import com.finance.system.dto.QuestionDTO;
import com.finance.system.dto.update.BasicDataUpdDTO;
import com.finance.system.dto.update.QuestionUpdDTO;
import com.finance.system.query.CurrentFieldsQuery;
import com.finance.system.query.QuestionQuery;
import com.finance.system.query.ScoreCalculateDetailQuery;
import com.finance.system.query.ScoreCalculateQuery;
import com.finance.system.service.ISysUserService;
import com.finance.system.service.TbBasicDataService;
import com.finance.system.service.TbQuestionService;
import com.finance.system.service.TbScoreService;
import com.finance.system.vo.CurrentFieldsAllVO;
import com.finance.system.vo.CurrentFieldsDetailVO;
import com.finance.system.vo.CurrentFieldsVO;
import com.finance.system.vo.DeptVO;
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.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
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.RestController;
 
/**
 * @author mitao
 * @date 2024/3/19
 */
@Slf4j
@RestController
@RequestMapping("/current-quarter")
@RequiredArgsConstructor
@Api(tags = "当前季度数据相关接口")
public class CurrentQuarterController {
 
    private final TbBasicDataService tbBasicDataService;
    private final TbQuestionService tbQuestionService;
    private final TbScoreService tbScoreService;
    private final ISysUserService sysUserService;
 
    /**
     * 字段统计
     *
     * @return R<PageDTO < CurrentFieldsVO>>
     */
    @ApiOperation(value = "字段统计", notes = "字段统计")
    @PostMapping("/fields-statics")
    public R<PageDTO<CurrentFieldsVO>> fieldsStatics(
            @Validated @RequestBody CurrentFieldsQuery dto) {
        try {
            String previousQuarter = DateUtils.getPreviousQuarter();
            // previousQuarter = "2024年一季度";
            dto.setQuarter(previousQuarter);
            return tbBasicDataService.fieldsStatics(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();
        }
    }
 
    /**
     * 字段统计-保存数据
     *
     * @param dto
     * @return
     */
    @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 = "字段统计")
    public R<CurrentFieldsAllVO> fieldsStaticsAll() {
        try {
            return R.ok(tbBasicDataService.fieldsStaticsAll());
        } catch (Exception e) {
            if (e instanceof ServiceException) {
                return R.fail(e.getMessage());
            }
            log.error("查看全部异常", e);
            return R.fail();
        }
    }
 
    /**
     * 得分计算
     *
     * @param query 当前季度/历史 数据 得分计算条件查询对象
     * @return R<PageDTO < ScoreCalculateVO>>
     */
    @PostMapping("/score-calculate")
    @ApiOperation("得分计算")
    public R<PageDTO<ScoreCalculateVO>> scoreCalculate(
            @Validated @RequestBody ScoreCalculateQuery query) {
        try {
            String previousQuarter = DateUtils.getPreviousQuarter();
            // previousQuarter = "2024年一季度";
            query.setQuarter(previousQuarter);
            return R.ok(tbBasicDataService.scoreCalculatePage(query));
        } catch (Exception e) {
            log.error("获取得分计算异常", e);
            return R.fail();
        }
    }
 
    /**
     * 得分计算查看详情
     *
     * @param query 得分计算详情条件查询对象
     * @return R<ScoreCalculateDetailVO>
     */
    @PostMapping("/score-calculate-detail")
    @ApiOperation("得分计算-查看详情")
    public R<ScoreCalculateDetailVO> scoreCalculateDetail(
            @Validated @RequestBody ScoreCalculateDetailQuery query) {
        try {
            return R.ok(tbScoreService.scoreCalculateDetail(query));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
 
    /**
     * 添加问题
     *
     * @param dto 发现问题数据传输对象
     * @return R<Void>
     */
    @PostMapping("add-question")
    @ApiOperation(value = "发现问题-添加问题", notes = "发现问题")
    public R<Void> addQuestion(@Validated @RequestBody QuestionDTO dto) {
        try {
            tbQuestionService.addQuestion(dto);
            return R.ok();
        } catch (Exception e) {
            if (e instanceof ServiceException) {
                return R.fail(e.getMessage());
            }
            log.error("添加问题异常", e);
            return R.fail();
        }
    }
 
    /**
     * 编辑问题
     *
     * @param dto 发现问题编辑数据传输对象
     * @return R<Void>
     */
    @PostMapping("/edit-question")
    @ApiOperation(value = "发现问题-编辑问题", notes = "发现问题")
    public R<Void> editQuestion(@Validated @RequestBody QuestionUpdDTO dto) {
        try {
            tbQuestionService.editQuestion(dto);
            return R.ok();
        } catch (Exception e) {
            if (e instanceof ServiceException) {
                return R.fail(e.getMessage());
            }
            log.error("编辑问题异常", e);
            return R.fail();
        }
    }
 
    /**
     * 分页查询问题
     *
     * @param dto 发现问题分页数据传输对象
     * @return R<PageDTO < QuestionVO>>
     */
    @PostMapping("/page-question")
    @ApiOperation(value = "发现问题-分页查询问题", notes = "发现问题")
    public R<PageDTO<QuestionVO>> pageQuestion(@Validated @RequestBody QuestionQuery dto) {
        return R.ok(tbQuestionService.pageQuestion(dto));
    }
 
    /**
     * 问题详情
     *
     * @param id id
     * @return R<QuestionDTO>
     */
    @GetMapping("/detail-question")
    @ApiOperation(value = "发现问题-问题详情", notes = "发现问题")
    public R<QuestionVO> detailQuestion(@RequestParam("id") Long id) {
        TbQuestion question = tbQuestionService.getById(id);
        return R.ok(BeanUtils.copyBean(question, QuestionVO.class));
    }
 
    /**
     * 删除问题
     *
     * @param id 问题id
     * @return R<Void>
     */
    @DeleteMapping("/delete")
    @ApiOperation(value = "发现问题-删除问题", notes = "发现问题")
    public R<Void> delete(@RequestParam("id") Long id) {
        tbQuestionService.delete(id);
        return R.ok();
    }
 
    @GetMapping(value = {"/dept/list/{deptName}", "/dept/list"})
    @ApiOperation(value = "发现问题-获取部门列表", notes = "发现问题")
    public R<List<DeptVO>> deptList(
            @ApiParam(value = "部门名称", required = false) @PathVariable(value = "deptName", required = false) String deptName) {
        return R.ok(sysUserService.queryDeptListByName(deptName));
    }
 
}