sinake
2 天以前 49120f2b9db33455756a911e56cfefd7c3120a14
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
package com.ruoyi.web.controller.project;
 
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.project.domain.SpStatExpense;
import com.ruoyi.project.domain.SpStatExpenseDept;
import com.ruoyi.project.domain.SpStatExpenseReq;
import com.ruoyi.project.service.SpstatExpenseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
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.RestController;
 
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 报销统计
 *
 * @author ruoyi
 * @date 2022-01-24
 */
@Slf4j
@Api("报销统计")
@RestController
@RequestMapping("/project/spstatexpense")
public class SpStatExpenseController extends BaseController {
 
    @Autowired
    SpstatExpenseService spstatExpenseService;
 
    /**
     * 查询费用统计
     */
    @ApiOperation("查询报销统计")
    @PostMapping("/spStatExpenselist")
    public TableDataInfo spStatExpenselist(@RequestBody SpStatExpenseReq spStatExpenseReq) {
        startPage();
        return getDataTable(spstatExpenseService.getListBySpstatExpense(spStatExpenseReq));
    }
 
    /**
     * 导出费用统计
     */
    @ApiOperation("导出费用统计")
    @Log(title = "费用统计", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SpStatExpenseReq spStatExpenseReq) {
        List<SpStatExpense> list = spstatExpenseService.getListBySpstatExpense(spStatExpenseReq);
        // 金额保留 2 位小数;0.00 不显示(置空)
        for (SpStatExpense row : list) {
            row.setAmount(blankZero(row.getAmount()));
            row.setExpertfee(blankZero(row.getExpertfee()));
            row.setEthicalistfee(blankZero(row.getEthicalistfee()));
            row.setMedicalcost(blankZero(row.getMedicalcost()));
            row.setOfficecost(blankZero(row.getOfficecost()));
            row.setReimcost(blankZero(row.getReimcost()));
        }
        ExcelUtil<SpStatExpense> util = new ExcelUtil<SpStatExpense>(SpStatExpense.class);
        return util.exportExcel(list, "费用统计数据");
    }
 
    /**
     * 导出费用统计(按业务组)
     */
    @ApiOperation("导出费用统计(按业务组)")
    @Log(title = "费用统计", businessType = BusinessType.EXPORT)
    @GetMapping("/exportDept")
    public AjaxResult exportDept(SpStatExpenseReq spStatExpenseReq) {
        List<SpStatExpense> list = spstatExpenseService.getListBySpstatExpense(spStatExpenseReq);
        Map<String, SpStatExpenseDept> grouped = new LinkedHashMap<String, SpStatExpenseDept>();
        for (SpStatExpense row : list) {
            String key = row.getDeptmentno() != null ? row.getDeptmentno() : row.getDeptmentName();
            if (key == null) {
                key = "";
            }
            SpStatExpenseDept dept = grouped.get(key);
            if (dept == null) {
                dept = new SpStatExpenseDept();
                dept.setDeptname(row.getDeptmentName() == null ? "未分组" : row.getDeptmentName());
                dept.setAmount(BigDecimal.ZERO);
                dept.setExpertfee(BigDecimal.ZERO);
                dept.setEthicalistfee(BigDecimal.ZERO);
                dept.setMedicalcost(BigDecimal.ZERO);
                dept.setOfficecost(BigDecimal.ZERO);
                dept.setReimcost(BigDecimal.ZERO);
                grouped.put(key, dept);
            }
            dept.setAmount(dept.getAmount().add(nz(row.getAmount())));
            dept.setExpertfee(dept.getExpertfee().add(nz(row.getExpertfee())));
            dept.setEthicalistfee(dept.getEthicalistfee().add(nz(row.getEthicalistfee())));
            dept.setMedicalcost(dept.getMedicalcost().add(nz(row.getMedicalcost())));
            dept.setOfficecost(dept.getOfficecost().add(nz(row.getOfficecost())));
            dept.setReimcost(dept.getReimcost().add(nz(row.getReimcost())));
        }
        List<SpStatExpenseDept> result = new ArrayList<SpStatExpenseDept>(grouped.values());
        for (SpStatExpenseDept dept : result) {
            dept.setAmount(blankZero(dept.getAmount()));
            dept.setExpertfee(blankZero(dept.getExpertfee()));
            dept.setEthicalistfee(blankZero(dept.getEthicalistfee()));
            dept.setMedicalcost(blankZero(dept.getMedicalcost()));
            dept.setOfficecost(blankZero(dept.getOfficecost()));
            dept.setReimcost(blankZero(dept.getReimcost()));
        }
        ExcelUtil<SpStatExpenseDept> util = new ExcelUtil<SpStatExpenseDept>(SpStatExpenseDept.class);
        return util.exportExcel(result, "费用统计(按业务组)");
    }
 
    private BigDecimal nz(BigDecimal value) {
        return value == null ? BigDecimal.ZERO : value;
    }
 
    private BigDecimal blankZero(BigDecimal value) {
        return (value == null || value.compareTo(BigDecimal.ZERO) == 0) ? null : value;
    }
 
}