yumeng пре 2 година
родитељ
комит
b30df80c1a

+ 139 - 4
ruixuan-live/src/main/java/com/ruixuan/isc/controller/SupplyChainController.java

@@ -1,19 +1,24 @@
 package com.ruixuan.isc.controller;
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.ruixuan.common.core.controller.BaseController;
 import com.ruixuan.common.core.page.TableDataInfo;
 import com.ruixuan.common.utils.Check;
 import com.ruixuan.common.utils.DateUtils;
+import com.ruixuan.data.utils.ExportExcelUtils;
 import com.ruixuan.isc.service.ISupplyChainService;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -559,4 +564,134 @@ public class SupplyChainController extends BaseController {
 
     }
 
+
+    @RequestMapping(value = "/exportPromoter")
+    @ResponseBody
+    public void exportPromoter(HttpServletRequest request, HttpServletResponse response, @RequestBody JSONObject requestJson) throws Exception {
+        Map<String, Object> requestMap = new HashMap<>();
+        if (!Check.isNull(requestJson.getString("orderStartDate"))) {
+            Long start = DateUtils.getStartLongTime(requestJson.getString("orderStartDate"));
+            requestMap.put("start", start);
+        }
+        if (!Check.isNull(requestJson.getString("orderEndDate"))) {
+            Long end = DateUtils.getEndLongTime(requestJson.getString("orderEndDate"));
+            requestMap.put("end", end);
+        }
+        if (!Check.isNull(requestJson.getString("promoterNickName"))) {
+            requestMap.put("promoterNickName", requestJson.getString("promoterNickName"));
+        }
+        if (!Check.isNull(requestJson.getLong("promoterId"))) {
+            requestMap.put("promoterId", requestJson.getLong("promoterId"));
+        }
+        if (!Check.isNull(requestJson.getLong("itemId"))) {
+            requestMap.put("itemId", requestJson.getLong("itemId"));
+        }
+        if (!Check.isNull(requestJson.getString("itemTitle"))) {
+            requestMap.put("itemTitle", requestJson.getString("itemTitle"));
+        }
+        List<JSONObject> list = supplyChainService.exportPromoter(requestMap);
+        List<List<Object>> exportList = new ArrayList<>();
+        if (!Check.isNull(list)) {
+            for (int i = 0; i < list.size(); i++) {
+                JSONObject date = list.get(i);
+                List<Object> export = new ArrayList();
+                export.add(date.getLong("promoterId"));
+                export.add(date.getString("promoterNickName"));
+                export.add(date.getLong("itemId"));
+                export.add(date.getString("itemTitle"));
+                export.add(date.getString("imageUrl"));
+                export.add(date.getInteger("orderNum"));
+                export.add(date.getInteger("validOrderNUm"));
+                export.add(date.getString("validRadio"));
+                export.add(date.getString("deliveryNum"));
+                export.add(date.getString("deliveryRadio"));
+                exportList.add(export);
+            }
+        }
+
+        String[] headers = {"达人ID", "达人名称", "商品ID", "商品名称", "商品封面", "订单数", "有效订单数", "有效订单率", "发货数", "发货率"};
+        OutputStream os = response.getOutputStream();
+        ExportExcelUtils eeu = new ExportExcelUtils();
+        XSSFWorkbook workbook = new XSSFWorkbook();
+        eeu.exportExcel(workbook, 0, "达人信息", headers, exportList);
+        this.setResponseHeader(response, "达人信息.xls");
+        workbook.write(os);
+        os.flush();
+        os.close();
+    }
+
+
+    @RequestMapping(value = "/exportOrder")
+    @ResponseBody
+    public void exportOrder(HttpServletRequest request, HttpServletResponse response, @RequestBody JSONObject requestJson) throws Exception {
+        Map<String, Object> requestMap = new HashMap<>();
+        if (!Check.isNull(requestJson.getString("orderStartDate"))) {
+            Long start = DateUtils.getStartLongTime(requestJson.getString("orderStartDate"));
+            requestMap.put("start", start);
+        }
+        if (!Check.isNull(requestJson.getString("orderEndDate"))) {
+            Long end = DateUtils.getEndLongTime(requestJson.getString("orderEndDate"));
+            requestMap.put("end", end);
+        }
+        if (!Check.isNull(requestJson.getString("promoterNickName"))) {
+            requestMap.put("promoterNickName", requestJson.getString("promoterNickName"));
+        }
+        if (!Check.isNull(requestJson.getLong("promoterId"))) {
+            requestMap.put("promoterId", requestJson.getLong("promoterId"));
+        }
+        if (!Check.isNull(requestJson.getLong("itemId"))) {
+            requestMap.put("itemId", requestJson.getLong("itemId"));
+        }
+        if (!Check.isNull(requestJson.getString("itemTitle"))) {
+            requestMap.put("itemTitle", requestJson.getString("itemTitle"));
+        }
+        List<JSONObject> list = supplyChainService.exportOrder(requestMap);
+        List<List<Object>> exportList = new ArrayList<>();
+        if (!Check.isNull(list)) {
+            for (int i = 0; i < list.size(); i++) {
+                JSONObject date = list.get(i);
+                List<Object> export = new ArrayList();
+                export.add(date.getLong("itemId"));
+                export.add(date.getString("itemTitle"));
+                export.add(date.getString("imageUrl"));
+                export.add(date.getLong("promoterId"));
+                export.add(date.getString("promoterNickName"));
+                export.add(date.getInteger("orderNum"));
+                export.add(date.getInteger("validOrderNUm"));
+                export.add(date.getString("validRadio"));
+                export.add(date.getString("deliveryNum"));
+                export.add(date.getString("deliveryRadio"));
+                exportList.add(export);
+            }
+        }
+        String[] headers = {"商品ID", "商品名称", "商品封面", "达人ID", "达人名称", "订单数", "有效订单数", "有效订单率", "发货数", "发货率"};
+        OutputStream os = response.getOutputStream();
+        ExportExcelUtils eeu = new ExportExcelUtils();
+        XSSFWorkbook workbook = new XSSFWorkbook();
+        eeu.exportExcel(workbook, 0, "订单信息", headers, exportList);
+        this.setResponseHeader(response, "订单信息.xls");
+        workbook.write(os);
+        os.flush();
+        os.close();
+    }
+
+
+    //发送响应流方法
+    public void setResponseHeader(HttpServletResponse response, String fileName) {
+        try {
+            try {
+                fileName = new String(fileName.getBytes(), "ISO8859-1");
+            } catch (UnsupportedEncodingException e) {
+                e.printStackTrace();
+            }
+            response.setContentType("application/octet-stream;charset=ISO8859-1");
+            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
+            response.addHeader("Pargam", "no-cache");
+            response.addHeader("Cache-Control", "no-cache");
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        }
+    }
+
+
 }

+ 4 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/mapper/SupplyChainMapper.java

@@ -40,4 +40,8 @@ public interface SupplyChainMapper {
     List<JSONObject> getPromoterRankRatioList(Map<String, Object> requestMap);
 
     List<JSONObject> getPromoterRatioList(Map<String, Object> requestMap);
+
+    List<JSONObject> exportPromoter(Map<String, Object> requestMap);
+
+    List<JSONObject> exportOrder(Map<String, Object> requestMap);
 }

+ 6 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/service/ISupplyChainService.java

@@ -50,4 +50,10 @@ public interface ISupplyChainService {
 
     //首页-达人排行(无环比)
     List<JSONObject> getPromoterRatioList(Map<String, Object> requestMap);
+
+    // 达人数据导出
+    List<JSONObject> exportPromoter(Map<String, Object> requestMap);
+
+    //订单数据导出
+    List<JSONObject> exportOrder(Map<String, Object> requestMap);
 }

+ 10 - 0
ruixuan-live/src/main/java/com/ruixuan/isc/service/impl/SupplyChainServiceImpl.java

@@ -113,4 +113,14 @@ public class SupplyChainServiceImpl implements ISupplyChainService {
     public List<JSONObject> getPromoterRatioList(Map<String, Object> requestMap) {
         return supplyChainMapper.getPromoterRatioList(requestMap);
     }
+
+    @Override
+    public List<JSONObject> exportPromoter(Map<String, Object> requestMap) {
+        return supplyChainMapper.exportPromoter(requestMap);
+    }
+
+    @Override
+    public List<JSONObject> exportOrder(Map<String, Object> requestMap) {
+        return supplyChainMapper.exportOrder(requestMap);
+    }
 }

+ 110 - 9
ruixuan-live/src/main/resources/mapper/isc/SupplyChainMapper.xml

@@ -10,7 +10,12 @@
         from (select promoter_id as 'promoterId',
         promoter_nick_name as 'promoterNickName',
         count(oid) as 'orderNum',
-        sum(case when order_status != 80 then 1 else 0 end) as 'validOrderNUm'
+        sum(case when order_status != 80 then 1 else 0 end) as 'validOrderNUm',
+        round(sum(case when order_status != 80 then 1 else 0 end) / count(oid),4) as 'validRadio',
+        sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) as 'deliveryNum',
+        round(sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) / sum(case when order_status != 80
+        then 1 else 0 end),4) as 'deliveryRadio'
+
         from kuaishou_supply_chain
         where 1= 1
         <if test="start != null and start != ''">
@@ -54,8 +59,13 @@
         image_url 'imageUrl',
         count(oid) as 'orderNum',
         sum(case when order_status != 80 then 1 else 0 end) as 'validOrderNUm',
+        round(sum(case when order_status != 80 then 1 else 0 end) / count(oid),4) as 'validRadio',
         sum(case when order_status != 80 then pay_amount else 0 end) as 'payAmount',
-        regimental_promotion_rate as 'regimentalPromotionRate'
+        regimental_promotion_rate as 'regimentalPromotionRate',
+        sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) as 'deliveryNum',
+        round(sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) / sum(case when order_status != 80
+        then 1 else 0 end),4) as 'deliveryRadio'
+
         from kuaishou_supply_chain
         where 1= 1
         <if test="promoterId != null and promoterId != ''">
@@ -105,7 +115,11 @@
         item_title as 'itemTitle',
         image_url as 'imageUrl',
         count(oid) as 'orderNum',
-        sum(case when order_status != 80 then 1 else 0 end) as 'validOrderNUm'
+        sum(case when order_status != 80 then 1 else 0 end) as 'validOrderNUm',
+        round(sum(case when order_status != 80 then 1 else 0 end) / count(oid),4) as 'validRadio',
+        sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) as 'deliveryNum',
+        round(sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) / sum(case when order_status != 80
+        then 1 else 0 end),4) as 'deliveryRadio'
         from kuaishou_supply_chain
         where 1= 1
         <if test="start != null and start != ''">
@@ -148,9 +162,13 @@
         promoter_nick_name as 'promoterNickName',
         promoter_id as 'promoterId',
         count(oid) as 'orderNum',
-        sum(case when order_status != 80 then 1 else 0 end) as 'validOrderNUm',
         sum(case when order_status != 80 then pay_amount else 0 end) as 'payAmount',
-        regimental_promotion_rate as 'regimentalPromotionRate'
+        regimental_promotion_rate as 'regimentalPromotionRate',
+        sum(case when order_status != 80 then 1 else 0 end) as 'validOrderNUm',
+        round(sum(case when order_status != 80 then 1 else 0 end) / count(oid),4) as 'validRadio',
+        sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) as 'deliveryNum',
+        round(sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) / sum(case when order_status != 80
+        then 1 else 0 end),4) as 'deliveryRadio'
         from kuaishou_supply_chain
         where 1= 1
         <if test="itemId != null and itemId != ''">
@@ -180,6 +198,10 @@
         image_url as 'imageUrl',
         count(oid) as 'orderNum',
         sum(case when order_status != 80 then 1 else 0 end) as 'validOrderNUm',
+        round(sum(case when order_status != 80 then 1 else 0 end) / count(oid),4) as 'validRadio',
+        sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) as 'deliveryNum',
+        round(sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) / sum(case when order_status != 80
+        then 1 else 0 end),4) as 'deliveryRadio',
         sum(case when order_status = 80 then 1 else 0 end) as 'invalidOrderNUm',
         regimental_promotion_rate as 'regimentalPromotionRate',
         sum(case when order_status != 80 then pay_amount else 0 end) as 'payAmount',
@@ -303,8 +325,8 @@
         sum(case when order_status != 80 then 1 else 0 end) as 'validOrderNUm',
         round(sum(case when order_status != 80 then 1 else 0 end) / count(oid),4) as 'validRadio',
         sum(case when send_status = 1 then 1 else 0 end) as 'deliveryNum',
-        round(sum(case when send_status = 1 then 1 else 0 end) / sum(case when order_status != 80 then 1 else 0 end),4) as 'deliveryRadio'
-
+        round(sum(case when send_status = 1 then 1 else 0 end) / sum(case when order_status != 80 then 1 else 0 end),4)
+        as 'deliveryRadio'
         from kuaishou_supply_chain
         where 1= 1
         <if test="nowStartHourTemp != null and nowStartHourTemp != ''">
@@ -340,7 +362,8 @@
         sum(case when order_status != 80 then 1 else 0 end) as 'validOrderNUm',
         round(sum(case when order_status != 80 then 1 else 0 end) / count(oid),4) as 'validRadio',
         sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) as 'deliveryNum',
-        round(sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) / sum(case when order_status != 80 then 1 else 0 end),4) as 'deliveryRadio'
+        round(sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) / sum(case when order_status != 80
+        then 1 else 0 end),4) as 'deliveryRadio'
         from kuaishou_supply_chain
         where 1= 1
         <if test="start != null and start != ''">
@@ -356,7 +379,8 @@
         select
         t1.*,
         round((t1.orderNum - t2.orderNum) / t2.orderNum,4) as 'radio'
-        from (select
+        from (
+        select
         promoter_id as 'promoterId',
         promoter_nick_name as 'promoterNickName',
         count(oid) as 'orderNum',
@@ -406,4 +430,81 @@
         group by promoter_id) t
         order by t.orderNum desc
     </select>
+    <select id="exportPromoter" resultType="com.alibaba.fastjson.JSONObject">
+        select *
+        from (
+        select
+        promoter_id as 'promoterId',
+        promoter_nick_name as 'promoterNickName',
+        item_id as 'itemId',
+        item_title as 'itemTitle',
+        image_url as 'imageUrl',
+        count(oid) as 'orderNum',
+        sum(case when order_status != 80 then 1 else 0 end) as 'validOrderNUm',
+        round(sum(case when order_status != 80 then 1 else 0 end) / count(oid) * 100,2) as 'validRadio',
+        sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) as 'deliveryNum',
+        round(sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) / sum(case when order_status != 80
+        then 1 else 0 end) * 100,2) as 'deliveryRadio'
+        from kuaishou_supply_chain
+        where 1= 1
+        <if test="start != null and start != ''">
+            and order_create_time &gt;= #{start}
+        </if>
+        <if test="end != null and end != ''">
+            and order_create_time &lt;= #{end}
+        </if>
+        <if test="promoterId != null and promoterId != ''">
+            and promoter_id = #{promoterId}
+        </if>
+        <if test="promoterNickName != null and promoterNickName != ''">
+            and promoter_nick_name like concat(concat('%',#{promoterNickName}),'%')
+        </if>
+        <if test="itemId != null and itemId != ''">
+            and item_id = #{itemId}
+        </if>
+        <if test="itemTitle != null and itemTitle != ''">
+            and item_title like concat(concat('%',#{itemTitle}),'%')
+        </if>
+        group by promoter_id,item_id) t
+        order by t.promoterId,t.orderNum desc
+
+    </select>
+    <select id="exportOrder" resultType="com.alibaba.fastjson.JSONObject">
+        select *
+        from (
+        select
+        item_id as 'itemId',
+        item_title as 'itemTitle',
+        image_url as 'imageUrl',
+        promoter_id as 'promoterId',
+        promoter_nick_name as 'promoterNickName',
+        count(oid) as 'orderNum',
+        sum(case when order_status != 80 then 1 else 0 end) as 'validOrderNUm',
+        round(sum(case when order_status != 80 then 1 else 0 end) / count(oid) * 100,2) as 'validRadio',
+        sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) as 'deliveryNum',
+        round(sum(case when send_status = 1 and order_status != 80 then 1 else 0 end) / sum(case when order_status != 80
+        then 1 else 0 end) * 100,2) as 'deliveryRadio'
+        from kuaishou_supply_chain
+        where 1= 1
+        <if test="start != null and start != ''">
+            and order_create_time &gt;= #{start}
+        </if>
+        <if test="end != null and end != ''">
+            and order_create_time &lt;= #{end}
+        </if>
+        <if test="promoterId != null and promoterId != ''">
+            and promoter_id = #{promoterId}
+        </if>
+        <if test="promoterNickName != null and promoterNickName != ''">
+            and promoter_nick_name like concat(concat('%',#{promoterNickName}),'%')
+        </if>
+        <if test="itemId != null and itemId != ''">
+            and item_id = #{itemId}
+        </if>
+        <if test="itemTitle != null and itemTitle != ''">
+            and item_title like concat(concat('%',#{itemTitle}),'%')
+        </if>
+        group by item_id,promoter_id) t
+        order by t.itemId,t.orderNum desc
+    </select>
 </mapper>