| | |
| | | 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.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 org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | 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> |
| | |
| | | public class TBankFlowController { |
| | | @Autowired |
| | | private TBankFlowService flowService; |
| | | |
| | | /** |
| | | * 获取流水列表 |
| | | */ |
| | |
| | | |
| | | @ApiOperation(value = "根据支付方式统计流水金额") |
| | | @PostMapping("/getPaymentStats") |
| | | public R<TBankFlowStatisticsVo> getPaymentStats(@RequestBody TBankFlowQuery query){ |
| | | 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("Content-Length","1"); |
| | | 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("银行流水返回结果导出失败"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |