|
@@ -0,0 +1,191 @@
|
|
|
+package cn.efunbox.audio.controller;
|
|
|
+
|
|
|
+import cn.efunbox.audio.service.StatisticsService;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.poi.hssf.usermodel.*;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.OutputStream;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * StatisticsController
|
|
|
+ * Created by xusq on 2018/7/10.
|
|
|
+ */
|
|
|
+@Controller
|
|
|
+@RequestMapping("/statistics")
|
|
|
+public class StatisticsController {
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StatisticsService statisticsService;
|
|
|
+
|
|
|
+ @ResponseBody
|
|
|
+ @RequestMapping
|
|
|
+ public void statistics(String beginDate, String endDate, HttpServletResponse response) throws IOException {
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(beginDate) || StringUtils.isBlank(endDate)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ beginDate += " 00:00:00";
|
|
|
+ endDate += " 23:59:59";
|
|
|
+
|
|
|
+ HSSFWorkbook workbook = new HSSFWorkbook();
|
|
|
+ //设置为居中
|
|
|
+ HSSFCellStyle style = workbook.createCellStyle();
|
|
|
+ HSSFFont font = workbook.createFont();
|
|
|
+ style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
|
|
|
+ style.setFont(font);
|
|
|
+ style.setWrapText(true);
|
|
|
+
|
|
|
+ HSSFSheet registerSheet = workbook.createSheet("注册数量统计");
|
|
|
+
|
|
|
+ createRegisterTitle(registerSheet, style);
|
|
|
+
|
|
|
+ List<Map<String, Object>> registerCount = statisticsService.registerCount(beginDate, endDate);
|
|
|
+
|
|
|
+ if (!CollectionUtils.isEmpty(registerCount)) {
|
|
|
+ int rowNum = 1;
|
|
|
+ for (Map<String, Object> data : registerCount) {
|
|
|
+ HSSFRow dataRow = registerSheet.createRow(rowNum);
|
|
|
+ dataRow.createCell(0).setCellValue(data.get("channel") + "");
|
|
|
+ dataRow.createCell(1).setCellValue(data.get("date") + "");
|
|
|
+ HSSFCell cell = dataRow.createCell(2);
|
|
|
+ cell.setCellValue(data.get("count") + "");
|
|
|
+ rowNum++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ HSSFSheet viewSheet = workbook.createSheet("播放量统计");
|
|
|
+ createViewTitle(viewSheet, style);
|
|
|
+ List<Map<String, Object>> viewCount = statisticsService.viewCount(beginDate, endDate);
|
|
|
+
|
|
|
+ if (!CollectionUtils.isEmpty(viewCount)) {
|
|
|
+ int rowNum = 1;
|
|
|
+ for (Map<String, Object> data : viewCount) {
|
|
|
+ HSSFRow dataRow = viewSheet.createRow(rowNum);
|
|
|
+ dataRow.createCell(0).setCellValue(data.get("channel") + "");
|
|
|
+ dataRow.createCell(1).setCellValue(data.get("date") + "");
|
|
|
+ dataRow.createCell(2).setCellValue(data.get("count") + "");
|
|
|
+ rowNum++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ HSSFSheet resourcesSheet = workbook.createSheet("音频播放统计");
|
|
|
+ createResourcesTitle(resourcesSheet, style);
|
|
|
+
|
|
|
+ List<Map<String, Object>> resourcesCount = statisticsService.resourcesCount(beginDate, endDate);
|
|
|
+ if (!CollectionUtils.isEmpty(resourcesCount)) {
|
|
|
+ int rowNum = 1;
|
|
|
+ for (Map<String, Object> data : resourcesCount) {
|
|
|
+ HSSFRow dataRow = resourcesSheet.createRow(rowNum);
|
|
|
+ dataRow.createCell(0).setCellValue(data.get("channel") + "");
|
|
|
+ dataRow.createCell(1).setCellValue( data.get("date") + "");
|
|
|
+ dataRow.createCell(2).setCellValue(data.get("audio") + "");
|
|
|
+ dataRow.createCell(3).setCellValue(data.get("count") + "");
|
|
|
+ rowNum++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String outName = String.format("attachment;filename=\"%s.xls\"", new String("智能语音统计报表".getBytes(),"ISO-8859-1"));
|
|
|
+ response.setContentType("application/vnd.ms-excel");
|
|
|
+ response.setHeader("Content-disposition", outName);
|
|
|
+ OutputStream out = null;
|
|
|
+ try {
|
|
|
+ out = response.getOutputStream();
|
|
|
+ workbook.write(out);
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }finally {
|
|
|
+ if (out != null) {
|
|
|
+ out.close();
|
|
|
+ out.flush();
|
|
|
+ }
|
|
|
+ workbook.close();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void createRegisterTitle(HSSFSheet hssfSheet, HSSFCellStyle style) {
|
|
|
+
|
|
|
+
|
|
|
+ HSSFRow row = hssfSheet.createRow(0);
|
|
|
+
|
|
|
+ int columnNum = 3;
|
|
|
+ for (int i = 0; i < columnNum; i++) {
|
|
|
+ hssfSheet.setColumnWidth(i, 26 * 256);
|
|
|
+ }
|
|
|
+
|
|
|
+ HSSFCell cell;
|
|
|
+ cell = row.createCell(0);
|
|
|
+ cell.setCellValue("渠道名称");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row.createCell(1);
|
|
|
+ cell.setCellValue("日期");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row.createCell(2);
|
|
|
+ cell.setCellValue("注册用户数");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void createViewTitle(HSSFSheet hssfSheet, HSSFCellStyle style) {
|
|
|
+
|
|
|
+
|
|
|
+ HSSFRow row = hssfSheet.createRow(0);
|
|
|
+
|
|
|
+ int columnNum = 3;
|
|
|
+ for (int i = 0; i < columnNum; i++) {
|
|
|
+ hssfSheet.setColumnWidth(i, 26 * 256);
|
|
|
+ }
|
|
|
+
|
|
|
+ HSSFCell cell;
|
|
|
+ cell = row.createCell(0);
|
|
|
+ cell.setCellValue("渠道名称");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row.createCell(1);
|
|
|
+ cell.setCellValue("日期");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row.createCell(2);
|
|
|
+ cell.setCellValue("播放数量");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void createResourcesTitle(HSSFSheet hssfSheet, HSSFCellStyle style) {
|
|
|
+
|
|
|
+
|
|
|
+ HSSFRow row = hssfSheet.createRow(0);
|
|
|
+
|
|
|
+ int columnNum = 4;
|
|
|
+ for (int i = 0; i < columnNum; i++) {
|
|
|
+ hssfSheet.setColumnWidth(i, 26 * 256);
|
|
|
+ }
|
|
|
+
|
|
|
+ HSSFCell cell;
|
|
|
+ cell = row.createCell(0);
|
|
|
+ cell.setCellValue("渠道名称");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row.createCell(1);
|
|
|
+ cell.setCellValue("日期");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row.createCell(2);
|
|
|
+ cell.setCellValue("音频名称");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row.createCell(3);
|
|
|
+ cell.setCellValue("播放数量");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+ }
|
|
|
+}
|