|
@@ -0,0 +1,135 @@
|
|
|
|
+package com.jpsoft.printing.modules;
|
|
|
|
+
|
|
|
|
+import com.github.pagehelper.Page;
|
|
|
|
+import com.jpsoft.printing.config.OSSConfig;
|
|
|
|
+import com.jpsoft.printing.modules.base.dto.NameValueDTO;
|
|
|
|
+import com.jpsoft.printing.modules.base.entity.Customer;
|
|
|
|
+import com.jpsoft.printing.modules.base.service.AccountService;
|
|
|
|
+import com.jpsoft.printing.modules.base.service.CustomerService;
|
|
|
|
+import com.jpsoft.printing.modules.base.service.WorkService;
|
|
|
|
+import com.jpsoft.printing.modules.common.dto.MessageResult;
|
|
|
|
+import com.jpsoft.printing.modules.common.utils.OSSUtil;
|
|
|
|
+import io.swagger.annotations.Api;
|
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
|
+import org.apache.poi.ss.usermodel.WorkbookFactory;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.core.io.ClassPathResource;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
+
|
|
|
|
+import java.io.*;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.*;
|
|
|
|
+
|
|
|
|
+@RestController
|
|
|
|
+@RequestMapping("/report")
|
|
|
|
+@Api(description = "report")
|
|
|
|
+public class ReportController {
|
|
|
|
+ private Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private OSSConfig ossConfig;
|
|
|
|
+ @Autowired
|
|
|
|
+ private AccountService accountService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private CustomerService customerService;
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="交易榜单")
|
|
|
|
+ @RequestMapping(value = "transactionRanking",method = RequestMethod.POST)
|
|
|
|
+ public MessageResult transactionRanking(String startDay, String endDay, Integer limit){
|
|
|
|
+ MessageResult msgResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ List<NameValueDTO> list = accountService.findTransactionRanking(startDay, endDay, limit);
|
|
|
|
+ for(NameValueDTO dto : list){
|
|
|
|
+ Customer customer = customerService.get(dto.getName());
|
|
|
|
+ if(customer != null) {
|
|
|
|
+ String allName = "";
|
|
|
|
+ if (StringUtils.isNotEmpty(customer.getCompany())) {
|
|
|
|
+ allName = customer.getName() + "(" + customer.getCompany() + ")";
|
|
|
|
+ } else {
|
|
|
|
+ allName = customer.getName();
|
|
|
|
+ }
|
|
|
|
+ dto.setName(allName);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ dto.setName(null);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+ msgResult.setData(list);
|
|
|
|
+
|
|
|
|
+ return msgResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="导出交易榜单")
|
|
|
|
+ @RequestMapping(value = "transactionRankingXls",method = RequestMethod.POST)
|
|
|
|
+ public MessageResult transactionRankingXls(String startDay, String endDay, Integer limit, String title) throws Exception {
|
|
|
|
+ MessageResult msgResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ List<NameValueDTO> list = accountService.findTransactionRanking(startDay, endDay, limit);
|
|
|
|
+ for(NameValueDTO dto : list){
|
|
|
|
+ Customer customer = customerService.get(dto.getName());
|
|
|
|
+ if(customer != null) {
|
|
|
|
+ String allName = "";
|
|
|
|
+ if (StringUtils.isNotEmpty(customer.getCompany())) {
|
|
|
|
+ allName = customer.getName() + "(" + customer.getCompany() + ")";
|
|
|
|
+ } else {
|
|
|
|
+ allName = customer.getName();
|
|
|
|
+ }
|
|
|
|
+ dto.setName(allName);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ dto.setName(null);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String xlsPath = "static/transactionRanking.xls";
|
|
|
|
+ ClassPathResource resource = new ClassPathResource(xlsPath);
|
|
|
|
+ Workbook wb = WorkbookFactory.create(resource.getInputStream());
|
|
|
|
+
|
|
|
|
+ //写入数据
|
|
|
|
+ Sheet sheet = wb.getSheetAt(0);
|
|
|
|
+ Row rowTitle = sheet.getRow(0);
|
|
|
|
+ rowTitle.getCell(0).setCellValue(title);
|
|
|
|
+ int rowNum = 2;
|
|
|
|
+
|
|
|
|
+ for(int i=0; i<list.size(); i++) {
|
|
|
|
+ NameValueDTO dto = list.get(i);
|
|
|
|
+
|
|
|
|
+ Row row = sheet.createRow(rowNum);
|
|
|
|
+ row.createCell(0).setCellValue(i+1);
|
|
|
|
+ row.createCell(1).setCellValue(dto.getName());
|
|
|
|
+ row.createCell(2).setCellValue(dto.getValue().toString());
|
|
|
|
+
|
|
|
|
+ rowNum++;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //保存到服务器,返回文件名
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
|
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
|
|
+ wb.write(output);
|
|
|
|
+ String fileName = title + "(" + sdf.format(new Date()) + ").xls";
|
|
|
|
+ String name = "D:\\" + fileName;
|
|
|
|
+ File file = new File(name);
|
|
|
|
+ FileOutputStream file1 = new FileOutputStream(file);
|
|
|
|
+ wb.write(file1);
|
|
|
|
+ file1.close();
|
|
|
|
+ wb.close();
|
|
|
|
+ output.close();
|
|
|
|
+
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+ msgResult.setData(name);
|
|
|
|
+
|
|
|
|
+ return msgResult;
|
|
|
|
+ }
|
|
|
|
+}
|