瀏覽代碼

月度金额排行报表

jz.kai 1 年之前
父節點
當前提交
eb33db45b7

+ 3 - 0
common/src/main/java/com/jpsoft/printing/modules/base/dao/AccountDAO.java

@@ -2,6 +2,8 @@ package com.jpsoft.printing.modules.base.dao;
 
 import java.math.BigDecimal;
 import java.util.List;
+
+import com.jpsoft.printing.modules.base.dto.NameValueDTO;
 import org.springframework.stereotype.Repository;
 import com.jpsoft.printing.modules.base.entity.Account;
 import java.util.Map;
@@ -18,4 +20,5 @@ public interface AccountDAO {
 	List<Account> search(Map<String,Object> searchParams,List<Sort> sortList);
 	BigDecimal getBalance(String customerId, String deadline);
 	Account getByWorkId(String workId);
+	List<NameValueDTO> findTransactionRanking(String startDay, String endDay, Integer limit);
 }

+ 2 - 0
common/src/main/java/com/jpsoft/printing/modules/base/dao/WorkDAO.java

@@ -1,6 +1,8 @@
 package com.jpsoft.printing.modules.base.dao;
 
 import java.util.List;
+
+import com.jpsoft.printing.modules.base.dto.NameValueDTO;
 import org.springframework.stereotype.Repository;
 import com.jpsoft.printing.modules.base.entity.Work;
 import java.util.Map;

+ 12 - 0
common/src/main/java/com/jpsoft/printing/modules/base/dto/NameValueDTO.java

@@ -0,0 +1,12 @@
+package com.jpsoft.printing.modules.base.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+public class NameValueDTO {
+    @ApiModelProperty(value = "名称")
+    private String name;
+    @ApiModelProperty(value = "值")
+    private Object value;
+}

+ 3 - 0
common/src/main/java/com/jpsoft/printing/modules/base/service/AccountService.java

@@ -3,6 +3,8 @@ package com.jpsoft.printing.modules.base.service;
 import java.math.BigDecimal;
 import java.util.List;
 import java.util.Map;
+
+import com.jpsoft.printing.modules.base.dto.NameValueDTO;
 import com.jpsoft.printing.modules.base.entity.Account;
 import com.github.pagehelper.Page;
 import com.jpsoft.printing.modules.common.dto.Sort;
@@ -17,4 +19,5 @@ public interface AccountService {
 	Page<Account> pageSearch(Map<String, Object> searchParams,int pageNum,int pageSize,boolean count,List<Sort> sortList);
 	BigDecimal getBalance(String customerId, String deadline);
 	Account getByWorkId(String workId);
+	List<NameValueDTO> findTransactionRanking(String startDay, String endDay, Integer limit);
 }

+ 2 - 0
common/src/main/java/com/jpsoft/printing/modules/base/service/WorkService.java

@@ -2,6 +2,8 @@ package com.jpsoft.printing.modules.base.service;
 
 import java.util.List;
 import java.util.Map;
+
+import com.jpsoft.printing.modules.base.dto.NameValueDTO;
 import com.jpsoft.printing.modules.base.entity.Work;
 import com.github.pagehelper.Page;
 import com.jpsoft.printing.modules.common.dto.Sort;

+ 7 - 0
common/src/main/java/com/jpsoft/printing/modules/base/service/impl/AccountServiceImpl.java

@@ -5,6 +5,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 import javax.annotation.Resource;
+
+import com.jpsoft.printing.modules.base.dto.NameValueDTO;
 import org.springframework.stereotype.Component;
 import org.springframework.transaction.annotation.Transactional;
 import com.jpsoft.printing.modules.base.dao.AccountDAO;
@@ -78,4 +80,9 @@ public class AccountServiceImpl implements AccountService {
 	public Account getByWorkId(String workId) {
 		return accountDAO.getByWorkId(workId);
 	}
+
+	@Override
+	public List<NameValueDTO> findTransactionRanking(String startDay, String endDay, Integer limit) {
+		return accountDAO.findTransactionRanking(startDay, endDay, limit);
+	}
 }

+ 2 - 0
common/src/main/java/com/jpsoft/printing/modules/base/service/impl/WorkServiceImpl.java

@@ -4,6 +4,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 import javax.annotation.Resource;
+
+import com.jpsoft.printing.modules.base.dto.NameValueDTO;
 import org.springframework.stereotype.Component;
 import org.springframework.transaction.annotation.Transactional;
 import com.jpsoft.printing.modules.base.dao.WorkDAO;

+ 16 - 0
common/src/main/resources/mapper/base/Account.xml

@@ -137,4 +137,20 @@ id_,customer_id,work_id,type_,plan_number,actual_amount,cloth_amount,roll_amount
 		select * from base_account
 		where work_id = #{0}
 	</select>
+	<resultMap id="NameValueDTOMap" type="com.jpsoft.printing.modules.base.dto.NameValueDTO">
+		<result property="name" column="name_" />
+		<result property="value" column="value_" />
+	</resultMap>
+	<select id="findTransactionRanking" parameterType="string" resultMap="NameValueDTOMap">
+		<![CDATA[
+			SELECT customer_id AS name_, ABS(SUM(total_amount)) AS value_ FROM base_account
+			WHERE del_flag = 0
+			AND type_ = 0
+			AND create_time >= #{startDay}
+			AND create_time < #{endDay}
+			GROUP BY customer_id
+			ORDER BY value_ DESC
+			LIMIT ${limit}
+		]]>
+	</select>
 </mapper>

+ 4 - 0
web/src/main/java/com/jpsoft/printing/modules/HomeController.java

@@ -1,6 +1,8 @@
 package com.jpsoft.printing.modules;
 
+import com.jpsoft.printing.modules.base.dto.NameValueDTO;
 import com.jpsoft.printing.modules.base.entity.Work;
+import com.jpsoft.printing.modules.base.service.AccountService;
 import com.jpsoft.printing.modules.base.service.WorkService;
 import com.jpsoft.printing.modules.common.dto.MessageResult;
 import io.swagger.annotations.Api;
@@ -21,6 +23,8 @@ public class HomeController {
 
     @Autowired
     private WorkService workService;
+    @Autowired
+    private AccountService accountService;
 
     @ApiOperation(value="月度数据")
     @RequestMapping(value = "monthlyData",method = RequestMethod.POST)

+ 135 - 0
web/src/main/java/com/jpsoft/printing/modules/ReportController.java

@@ -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;
+    }
+}

二進制
web/src/main/resources/static/transactionRanking.xls