mitao
2024-04-19 b21c37b7899b17dede7773db3c799aab1063ae1c
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
package com.finance.web.controller.api;
 
import com.finance.common.annotation.FinancialLog;
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.dto.BasicDataDTO;
import com.finance.system.query.ScoreQuery;
import com.finance.system.service.TbBasicDataService;
import com.finance.system.service.TbFieldService;
import com.finance.system.vo.BasicDataReportingVO;
import com.finance.system.vo.ScoreVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
 
/**
 * @author mitao
 * @date 2024/3/19
 */
@Slf4j
@RestController
@RequestMapping("/current-quarter-dept")
@RequiredArgsConstructor
@Api(tags = "当前季度数据相关接口")
public class CurrentQuarterController {
 
    private final TbBasicDataService tbBasicDataService;
    private final TbFieldService tbFieldService;
 
    /**
     * 获取基础数据填报相关信息
     *
     * @return R<BasicDataReportingVO>
     */
    @ApiOperation("获取基础数据填报相关信息")
    @GetMapping("/basic-fields")
    public R<BasicDataReportingVO> getBasicFields() {
        try {
            return tbBasicDataService.getBasicFields();
        } catch (Exception e) {
            if (e instanceof ServiceException) {
                return R.fail(e.getMessage());
            }
            log.error("获取基础数据填报相关信息异常", e);
            return R.fail();
        }
    }
 
    /**
     * 保存当前季度数据
     *
     * @param dto 当前季度基础数据数据传输对象
     * @return R<Void>
     */
    @PostMapping("/save-basic-data")
    @ApiOperation("保存当前季度数据")
    public R<Void> saveBasicData(@RequestBody BasicDataDTO dto) {
        try {
            tbBasicDataService.saveBasicData(dto);
        } catch (Exception e) {
            if (e instanceof ServiceException) {
                return R.fail(e.getMessage());
            }
            log.error("保存当前季度数据异常", e);
            return R.fail();
        }
        return R.ok();
    }
 
    /**
     * 导入模板下载
     */
    @FinancialLog(title = "下载导入模板", businessType = BusinessType.OTHER)
    @GetMapping("/download")
    @ApiOperation("模板下载")
    public void downloadImportTemplate() {
        try {
            tbFieldService.downloadImportTemplate();
        } catch (Exception e) {
            log.error("模板下载异常", e);
            throw new ServiceException("模板下载失败,请联系管理员!");
        }
    }
 
    /**
     * 基础数据导入
     *
     * @param file file
     * @return R<Void>
     */
    @PostMapping("/import")
    @ApiOperation("基础数据导入")
    @FinancialLog(title = "导入数据", businessType = BusinessType.IMPORT)
    public R<Void> importBasicData(@RequestPart("file") MultipartFile file) {
        try {
            tbBasicDataService.importBasicData(file);
        } catch (Exception e) {
            if (e instanceof ServiceException) {
                return R.fail(e.getMessage());
            }
            log.error("基础数据导入异常", e);
            return R.fail("基础数据导入失败,请联系管理员!");
        }
        return R.ok();
    }
 
    /**
     * 得分计算分页查询
     *
     * @param query 得分计算条件查询对象
     * @return R<PageDTO < ScoreVO>>
     */
    @PostMapping("/page-score")
    @ApiOperation("得分计算分页查询")
    public R<PageDTO<ScoreVO>> pageScore(@Validated @RequestBody ScoreQuery query) {
        try {
            return R.ok(tbBasicDataService.pageScore(query));
        } catch (Exception e) {
            if (e instanceof ServiceException) {
                return R.fail(e.getMessage());
            }
            log.error("查询得分计算异常", e);
            return R.fail();
        }
    }
}