xuhy
2025-07-17 ca41616d33308050c52612177e515115f543de1b
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
package com.ruoyi.web.controller.api;
 
 
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.WebUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.export.YcFinancialManagementExport;
import com.ruoyi.system.model.YcFinancialManagement;
import com.ruoyi.system.model.YcRevenueExpenditureType;
import com.ruoyi.system.query.YcFinancialManagementQuery;
import com.ruoyi.system.service.YcFinancialManagementService;
import com.ruoyi.system.service.YcRevenueExpenditureTypeService;
import com.ruoyi.system.vo.YcFinancialManagementVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;
import java.util.Objects;
 
/**
 * <p>
 * 财务管理 前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2025-07-15
 */
@Api(tags = "财务管理")
@RestController
@RequestMapping("/yc-financial-management")
public class YcFinancialManagementController {
 
 
    private final YcRevenueExpenditureTypeService ycRevenueExpenditureTypeService;
    private final YcFinancialManagementService ycFinancialManagementService;
    private final TokenService tokenService;
 
    @Autowired
    public YcFinancialManagementController(YcRevenueExpenditureTypeService ycRevenueExpenditureTypeService, YcFinancialManagementService ycFinancialManagementService, TokenService tokenService) {
        this.ycRevenueExpenditureTypeService = ycRevenueExpenditureTypeService;
        this.ycFinancialManagementService = ycFinancialManagementService;
        this.tokenService = tokenService;
    }
 
    /**
     * 查询财务管理列表
     */
    @ApiOperation( value = "查询财务管理分页列表")
    @PostMapping(value = "/pageList")
    public R<PageInfo<YcFinancialManagementVO>> pageList(@RequestBody YcFinancialManagementQuery query) {
        return R.ok(ycFinancialManagementService.pageList(query));
    }
 
    /**
     * 添加财务管理管理
     */
    @ApiOperation( value = "添加财务管理")
    @Log(title = "财务管理-添加", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public R<Boolean> add(@RequestBody YcFinancialManagement dto) {
        YcRevenueExpenditureType ycRevenueExpenditureType = ycRevenueExpenditureTypeService.getById(dto.getTypeId());
        if(Objects.nonNull(ycRevenueExpenditureType)){
            dto.setRevenueType(ycRevenueExpenditureType.getRevenueType());
        }
        return R.ok(ycFinancialManagementService.save(dto));
    }
 
    /**
     * 编辑财务管理
     */
    @ApiOperation( value = "编辑财务管理")
    @Log(title = "财务管理-编辑", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update")
    public R<Boolean> update(@RequestBody YcFinancialManagement dto) {
        return R.ok(ycFinancialManagementService.updateById(dto));
    }
 
    /**
     * 查看财务管理详情
     */
    @ApiOperation( value = "查看财务管理详情")
    @GetMapping(value = "/getDetailById")
    public R<YcFinancialManagementVO> getDetailById(@RequestParam("id") Long id) {
        YcFinancialManagement ycFinancialManagement = ycFinancialManagementService.getById(id);
        YcFinancialManagementVO ycFinancialManagementVO = new YcFinancialManagementVO();
        BeanUtils.copyProperties(ycFinancialManagement, ycFinancialManagementVO);
        YcRevenueExpenditureType ycRevenueExpenditureType = ycRevenueExpenditureTypeService.getById(ycFinancialManagement.getTypeId());
        if(Objects.nonNull(ycRevenueExpenditureType)){
            ycFinancialManagementVO.setRevenueType(ycRevenueExpenditureType.getRevenueType());
            ycFinancialManagementVO.setTypeName(ycRevenueExpenditureType.getTypeName());
        }
        return R.ok(ycFinancialManagementVO);
    }
 
    /**
     * 删除财务管理
     */
    @ApiOperation( value = "删除财务管理")
    @Log(title = "财务管理-删除", businessType = BusinessType.DELETE)
    @DeleteMapping(value = "/deleteById")
    public R<Boolean> deleteById(@RequestParam("id") Long id) {
        return R.ok(ycFinancialManagementService.removeById(id));
    }
 
    @ApiOperation(value = "财务管理导出")
    @Log(title = "财务管理导出", businessType = BusinessType.OTHER)
    @PostMapping(value = "/financialManagementExport")
    public void financialManagementExport(@RequestBody YcFinancialManagementQuery query) {
        String userPermission = tokenService.getLoginUser().getUser().getUserPermission();
        List<YcFinancialManagementExport> exports = ycFinancialManagementService.financialManagementExport(query);
        for (YcFinancialManagementExport export : exports) {
            export.setProvinceAndCityName(export.getProvinceName() + "·" + export.getCityName());
            export.setPayTimeStr(DateUtils.localDateTimeToString(export.getPayTime()));
            export.setUpdateTimeStr(DateUtils.localDateTimeToString(export.getUpdateTime()));
            if(export.getRevenueType() == 1){
                if(userPermission.contains("4")){
                    export.setPayMoneyStr("¥" + export.getPayMoney());
                }else {
                    export.setPayMoneyStr("¥****");
                }
            }else {
                if(userPermission.contains("3")){
                    export.setPayMoneyStr("¥" + export.getPayMoney());
                }else {
                    export.setPayMoneyStr("¥****");
                }
            }
        }
        //1.获取excel模板
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), YcFinancialManagementExport.class, exports);
        HttpServletResponse response = WebUtils.response();
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        ServletOutputStream outputStream = null;
        try {
            String fileName = URLEncoder.encode("财务管理列表.xls", "utf-8");
            response.setHeader("Content-dispodition", "attachment;filename=" + fileName);
            outputStream = response.getOutputStream();
            workbook.write(outputStream);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                outputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
 
}