فهرست منبع

订单统计导出接口

tianyunperfect 3 سال پیش
والد
کامیت
94f8f00a77

+ 112 - 9
book-server/src/main/java/com/book/server/controller/SunDataController.java

@@ -1,10 +1,8 @@
 package com.book.server.controller;
 
 import com.book.dao.VO.SunVO;
-import com.book.dao.polardb.entity.SunChannel;
-import com.book.dao.polardb.entity.SunOrder;
-import com.book.dao.polardb.entity.SunOrderCollect;
-import com.book.dao.polardb.entity.SunUserCollect;
+import com.book.dao.polardb.entity.*;
+import com.book.dao.utils.TimeUtil;
 import com.book.server.common.entity.PageResult;
 import com.book.server.common.entity.Result;
 import com.book.server.config.SunTypeEnum;
@@ -13,10 +11,16 @@ import com.book.server.vo.SunNotifyRequest;
 import com.book.server.vo.SunRequest;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
 import javax.websocket.server.PathParam;
+import java.io.BufferedOutputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.List;
 import java.util.UUID;
 
 /**
@@ -36,6 +40,7 @@ public class SunDataController extends BaseController {
 
     /**
      * getData
+     *
      * @param type
      * @param request
      * @return
@@ -49,6 +54,7 @@ public class SunDataController extends BaseController {
 
     /**
      * pullData
+     *
      * @param request
      * @return
      */
@@ -106,6 +112,7 @@ public class SunDataController extends BaseController {
 
     /**
      * 统计某天的订单
+     *
      * @param date
      * @return
      */
@@ -117,6 +124,7 @@ public class SunDataController extends BaseController {
 
     /**
      * 获取今天订单统计
+     *
      * @return
      */
     @GetMapping("/getTodayOrderStatic")
@@ -126,6 +134,7 @@ public class SunDataController extends BaseController {
 
     /**
      * 获取今天订单统计按渠道
+     *
      * @return
      */
     @GetMapping("/getTodayOrderStaticByChannel")
@@ -133,8 +142,98 @@ public class SunDataController extends BaseController {
         return Result.success(sunDataService.getTodayOrderStaticByChannel());
     }
 
+    @GetMapping("/exportTodayOrderStaticByChannel")
+    public void exportTodayOrderStaticByChannel(HttpServletResponse response) throws UnsupportedEncodingException {
+        List<SunStaticOrderDayChannel> list = sunDataService.getTodayOrderStaticByChannel();
+
+        /**
+         * 导出
+         */
+        response.setContentType("text/plain");
+        String fileName = TimeUtil.getTodayStr() + UUID.randomUUID() + ".csv";
+        response.setHeader("Content-Disposition", "attachment; filename=" + java.net.URLEncoder.encode(fileName, "UTF-8"));
+
+        BufferedOutputStream buff = null;
+        StringBuffer write = new StringBuffer();
+        String enter = "\r\n";
+        ServletOutputStream outSTr = null;
+        try {
+            outSTr = response.getOutputStream();
+            buff = new BufferedOutputStream(outSTr);
+            // 把内容写入文件
+            if (list.size() > 0) {
+                // 添加表头
+                write.append("日期,渠道 Id,渠道名称,活跃用户数,充值用户数,充值金额,充值笔数,充值人均");
+                write.append(enter);
+
+                for (int i = 0; i < list.size(); i++) {
+                    SunStaticOrderDayChannel text = list.get(i);
+                    write.append(text.getStaticDate() + "," + text.getChannelId() + ","+ text.getChannelName() + ","+ text.getActiveCount() + "," + text.getRechargeUserCount() + "," + text.getRechargeSum() + "," + text.getRechargeCount() + "," + text.getRechargeAvg());
+                    write.append(enter);
+                }
+            }
+            buff.write(write.toString().getBytes("UTF-8"));
+            buff.flush();
+            buff.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                buff.close();
+                outSTr.close();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    @GetMapping("/exportOrderStaticAll")
+    public void exportTodayOrderStatic(HttpServletResponse response) throws UnsupportedEncodingException {
+        List<SunStaticOrderDay> list = sunDataService.getOrderStaticsAll();
+        /**
+         * 导出
+         */
+        response.setContentType("text/plain");
+        String fileName = TimeUtil.getTodayStr() + UUID.randomUUID() + ".csv";
+        response.setHeader("Content-Disposition", "attachment; filename=" + java.net.URLEncoder.encode(fileName, "UTF-8"));
+
+        BufferedOutputStream buff = null;
+        StringBuffer write = new StringBuffer();
+        String enter = "\r\n";
+        ServletOutputStream outSTr = null;
+        try {
+            outSTr = response.getOutputStream();
+            buff = new BufferedOutputStream(outSTr);
+            // 把内容写入文件
+            if (list.size() > 0) {
+                // 添加表头
+                write.append("日期,活跃用户数,充值用户数,充值金额,充值笔数,充值人均");
+                write.append(enter);
+
+                for (int i = 0; i < list.size(); i++) {
+                    SunStaticOrderDay text = list.get(i);
+                    write.append(text.getStaticDate() + "," + text.getActiveCount() + "," + text.getRechargeUserCount() + "," + text.getRechargeSum() + "," + text.getRechargeCount() + "," + text.getRechargeAvg());
+                    write.append(enter);
+                }
+            }
+            buff.write(write.toString().getBytes("UTF-8"));
+            buff.flush();
+            buff.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                buff.close();
+                outSTr.close();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
     /**
      * 获取昨天订单统计
+     *
      * @return
      */
     @GetMapping("/getYesterdayOrderStatic")
@@ -144,6 +243,7 @@ public class SunDataController extends BaseController {
 
     /**
      * 获取历史订单统计
+     *
      * @return
      */
     @GetMapping("/getHistoryOrderStatic")
@@ -153,19 +253,22 @@ public class SunDataController extends BaseController {
 
     /**
      * 订单统计-按天排序
+     *
      * @return
      */
     @GetMapping("/getOrderStatics")
-    public Result getOrderStatics(int page,int size) {
-        return Result.success(sunDataService.getOrderStatics(page,size));
+    public Result getOrderStatics(int page, int size) {
+        return Result.success(sunDataService.getOrderStatics(page, size));
     }
+
     /**
-     * 订单统计-渠道-按天查询
+     * 订单统计-按天查询
+     *
      * @return
      */
     @GetMapping("/getOrderStaticByDateAndChannel")
-    public Result getOrderStaticByDateAndChannel(String date,String channelId) {
-        return Result.success(sunDataService.getOrderStaticByDateAndChannel(date,channelId));
+    public Result getOrderStaticByDateAndChannel(String date) {
+        return Result.success(sunDataService.getOrderStaticByDateAndChannel(date));
     }
 
 

+ 3 - 1
book-server/src/main/java/com/book/server/service/SunDataService.java

@@ -49,5 +49,7 @@ public interface SunDataService {
 
     PageResult<SunStaticOrderDay> getOrderStatics(int page,int size);
 
-    List<SunStaticOrderDayChannel> getOrderStaticByDateAndChannel(String date, String channelId);
+    List<SunStaticOrderDay> getOrderStaticsAll();
+
+    List<SunStaticOrderDayChannel> getOrderStaticByDateAndChannel(String date);
 }

+ 8 - 2
book-server/src/main/java/com/book/server/service/impl/SunDataServiceImpl.java

@@ -405,11 +405,17 @@ public class SunDataServiceImpl implements SunDataService {
     }
 
     @Override
-    public List<SunStaticOrderDayChannel> getOrderStaticByDateAndChannel(String date, String channelId) {
+    public List<SunStaticOrderDay> getOrderStaticsAll() {
+        SunStaticOrderDayExample example = SunStaticOrderDayExample.newAndCreateCriteria().example();
+        List<SunStaticOrderDay> sunStaticOrderDays = sunStaticOrderDayMapper.selectByExample(example);
+        return sunStaticOrderDays;
+    }
+
+    @Override
+    public List<SunStaticOrderDayChannel> getOrderStaticByDateAndChannel(String date) {
         return sunStaticOrderDayChannelMapper.selectByExample(
                 SunStaticOrderDayChannelExample.newAndCreateCriteria()
                         .andStaticDateEqualTo(date)
-                        .andChannelIdEqualTo(channelId)
                         .example()
         );
     }