mitao
2025-03-20 733264ad003542e110056b40b680101f1694b05f
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
package com.ruoyi.web.controller.api;
 
 
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.WebUtils;
import com.ruoyi.system.importExcel.TBankFlowImportExcel;
import com.ruoyi.system.model.TBankFlow;
import com.ruoyi.system.query.TBankFlowQuery;
import com.ruoyi.system.service.TBankFlowService;
import com.ruoyi.system.vo.TBankFlowStatisticsVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import java.util.concurrent.atomic.AtomicInteger;
 
/**
 * <p>
 * 流水管理 前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2025-02-07
 */
@RestController
@RequestMapping("/t-bank-flow")
public class TBankFlowController {
    @Autowired
    private TBankFlowService flowService;
 
    /**
     * 获取流水列表
     */
    @PreAuthorize("@ss.hasPermi('flow:bank:detail:list')")
    @ApiOperation(value = "获取银行流水列表")
    @PostMapping("/list")
    public R<PageInfo<TBankFlow>> list(@RequestBody TBankFlowQuery query) {
        return R.ok(flowService.pageList(query));
    }
 
    @ApiOperation(value = "根据支付方式统计流水金额")
    @PostMapping("/getPaymentStats")
    public R<TBankFlowStatisticsVo> getPaymentStats(@RequestBody TBankFlowQuery query) {
        return R.ok(flowService.getPaymentStats(query));
    }
 
    @PostMapping("importBankFlow")
    public void importElectronic(@RequestBody MultipartFile file) {
        try (
                InputStream is = file.getInputStream();
        ) {
            List<TBankFlowImportExcel> failList = new Vector<>();
            EasyExcel.read(is, TBankFlowImportExcel.class, new AnalysisEventListener<TBankFlowImportExcel>() {
                private final List<TBankFlowImportExcel> list = new ArrayList<>();
                final AtomicInteger all = new AtomicInteger();
 
                @Override
                public void invoke(TBankFlowImportExcel data, AnalysisContext context) {
                    all.addAndGet(1);
                    boolean isok = data.validate();
                    if (!isok) {
                        failList.add(data);
                        return;
                    }
                    list.add(data);
                    int size = list.size();
                    if (size >= 100) {
                        flowService.saveImportBatch(list, failList);
                        list.clear();
                    }
                }
                @Override
                public void doAfterAllAnalysed(AnalysisContext context) {
                    int size = list.size();
                    if (size > 0) {
                        flowService.saveImportBatch(list, failList);
                    }
                }
            }).sheet().doRead();
            // 导出导入结果
            HttpServletResponse response = WebUtils.response();
            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
            response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
            response.setHeader("Pragma", "no-cache");
            if (failList.size() > 0) {
                EasyExcel.write(response.getOutputStream(), TBankFlowImportExcel.class).sheet("Sheet1").doWrite(failList);
            } else {
                TBankFlowImportExcel result = new TBankFlowImportExcel();
                result.setResult("全部成功");
                failList.add(result);
                EasyExcel.write(response.getOutputStream(), TBankFlowImportExcel.class).sheet("Sheet1").doWrite(failList);
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println("银行流水返回结果导出失败");
        }
    }
 
    @GetMapping("getByBankSerialNumber")
    public  R<List<TBankFlow>> searchByBankSerialNumber(@RequestParam String bankSerialNumber){
        List<TBankFlow> tBankFlows = flowService.searchByBankSerialNumber(bankSerialNumber);
        return R.ok(tBankFlows);
    }
 
 
}