Bläddra i källkod

添加消消消日报导出

syh 5 år sedan
förälder
incheckning
a11172f276

+ 68 - 45
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/AdvertiserController.java

@@ -1,8 +1,15 @@
 package org.jeecg.modules.ctop.controller;
 
 import cn.com.ctop.bytedance.mapper.MaterialReportMapper;
+import cn.com.ctop.common.module.entity.UserAllocation;
+import cn.com.ctop.common.module.service.IUserAllocationService;
 import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.ResultMapUtils;
+import cn.com.ctop.common.module.utils.StatusCode;
 import cn.com.ctop.common.module.utils.StringUtils;
+import com.alibaba.excel.EasyExcelFactory;
+import com.alibaba.excel.ExcelWriter;
+import com.alibaba.excel.metadata.Sheet;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -14,6 +21,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.aspect.annotation.AutoLog;
 import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.common.util.DateUtils;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.modules.ctop.entity.Advertiser;
 import org.jeecg.modules.ctop.entity.Project;
@@ -21,6 +29,8 @@ import org.jeecg.modules.ctop.mapper.ProjectMapper;
 import org.jeecg.modules.ctop.mapper.ProjectMemberMapper;
 import org.jeecg.modules.ctop.service.IAdvertiserService;
 import org.jeecg.modules.ctop.service.IProjectService;
+import org.jeecg.modules.ctop.vo.SheetInfoVo;
+import org.jeecg.modules.excelutil.entity.KuaishouXxlEntity;
 import org.jeecg.modules.system.entity.SysCategory;
 import org.jeecg.modules.system.entity.SysUser;
 import org.jeecg.modules.system.entity.UserCompany;
@@ -41,6 +51,7 @@ import org.springframework.web.servlet.ModelAndView;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
+import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
 import java.util.*;
@@ -381,6 +392,39 @@ public class AdvertiserController {
         return Result.ok("文件导入失败!");
     }
 
+    @Autowired
+    private IUserAllocationService userAllocationService;
+
+    /**
+     * 导出报表
+     *
+     * @return
+     */
+    @RequestMapping(value = "/xxlDailyReportList")
+    @ResponseBody
+    public Map<String, Object> xxlReportList(HttpServletRequest request, HttpServletResponse response, @RequestBody JSONObject data) throws Exception {
+        Map<String, Object> result = new HashMap<>();
+        List<SheetInfoVo> sheets = new ArrayList<>();
+        //查询总的消耗信息
+        Long projectId = data.getLong("projectId");
+        String systemType = data.getString("systemType");
+        if (null == systemType || systemType.trim().equals("")) {
+            systemType = null;
+        }
+        SheetInfoVo totalSheetVo = advertiserService.getXxlStatisticInfo(projectId, systemType, null, null, "汇总表");
+        sheets.add(totalSheetVo);
+        List<UserAllocation> allocations = userAllocationService.getByProjectId(projectId, systemType);
+        if (null != allocations && allocations.size() > 0) {
+            for (UserAllocation allocation : allocations) {
+                SheetInfoVo vo = advertiserService.getXxlStatisticInfo(projectId, systemType, allocation.getAccountId(), "state_date", allocation.getAuthName());
+                sheets.add(vo);
+            }
+        }
+        result.put("data", sheets);
+        ResultMapUtils.setResultMap(result, StatusCode.COMMON_SUCCESS);
+        return result;
+    }
+
     /**
      * 导出报表
      *
@@ -388,52 +432,31 @@ public class AdvertiserController {
      */
     @RequestMapping(value = "/exportXxlDailyReport")
     @ResponseBody
-    public void exportXxl(HttpServletRequest request, HttpServletResponse response, @RequestBody JSONObject requestJson) throws Exception {
+    public void exportXxl(HttpServletRequest request, HttpServletResponse response, Long projectId, String systemType) throws Exception {
+        List<SheetInfoVo> sheets = new ArrayList<>();
+        //查询总的消耗信息
+        SheetInfoVo totalSheetVo = advertiserService.getXxlStatisticInfo(projectId, systemType, null, null, "汇总表");
+        sheets.add(totalSheetVo);
+        List<UserAllocation> allocations = userAllocationService.getByProjectId(projectId, systemType);
+        if (null != allocations && allocations.size() > 0) {
+            for (UserAllocation allocation : allocations) {
+                SheetInfoVo vo = advertiserService.getXxlStatisticInfo(projectId, systemType, allocation.getAccountId(), "state_date", allocation.getAuthName());
+                sheets.add(vo);
+            }
+        }
 
-//        List<SheetInfoVo> sheets = new ArrayList<SheetInfoVo>();
-//        List<KuaishouXxlEntity> entities = advertiserService.getXxlStatisticInfo();
-//
-//        List<List<Object>> group = new ArrayList<>();
-//        List<DailyGroupReportVO> dailyGroupReport = dailyReport.getDailyGroupReport();
-//        if (!Check.isNull(dailyGroupReport)) {
-//            for (DailyGroupReportVO groupReportVO : dailyGroupReport) {
-//                List<Object> dailyGroup = new ArrayList();
-//                dailyGroup.add(groupReportVO.getAccountId());
-//                dailyGroup.add(groupReportVO.getAuthName());
-//                dailyGroup.add(groupReportVO.getStatDate());
-//                dailyGroup.add(groupReportVO.getCampaignName());
-//                dailyGroup.add(groupReportVO.getUnitName());
-//                dailyGroup.add(groupReportVO.getCost()); // 花费
-//                dailyGroup.add(groupReportVO.getDisCountCost()); // 折后花费
-//                dailyGroup.add(groupReportVO.getPhotoShow()); // 展示数
-//                dailyGroup.add(groupReportVO.getPhotoClick()); // 点击数
-//                dailyGroup.add(groupReportVO.getBclick());   // 行为数
-//                dailyGroup.add(RateUtil.getRate(groupReportVO.getPhotoClickRatio())); // 点击率
-//                dailyGroup.add(RateUtil.getRate(groupReportVO.getActionRatio())); // 行为率
-//
-//                dailyGroup.add(groupReportVO.getImpression1kCost()); // 平均千次展现花费
-//                dailyGroup.add(groupReportVO.getPhotoClickCost()); // 平均点击花费
-//                dailyGroup.add(groupReportVO.getConversions()); // 转化数
-//                //  dailyGroup.add(groupReportVO.getConversionPrice()); // 转化单价
-//                dailyGroup.add(groupReportVO.getDiscountConversionPrice()); // 折后转化成本
-//                dailyGroup.add(RateUtil.getRate(groupReportVO.getClickConversionRate())); // 点击转化率
-//
-//                group.add(dailyGroup);
-//            }
-//
-//        }
-//
-//        String[] accountHeaders = {"时间", "消耗(元)", "激励花费(元)", "实际消耗(元)", "展示数", "素材曝光数", "点击数", "点击率", "平均点击花费(元)", "行为数", "行为率", "平均千次展现花费(元)", "转化数(元)", "转化单价", "转化率", "折后转化成本(元)"};
-//        String[] groupHeaders = {"账号", "账号名称", "日期", "计划名称", "广告组名称", "消耗(元)", "折后消耗(元)", "展现", "点击数", "行为数", "点击率", "行为率", "平均千次展现费用(元)", "平均点击费用(元)", "转化数", "折后转化成本(元)", "点击转化率"};
-//        OutputStream os = response.getOutputStream();
-//        ExportExcelUtils eeu = new ExportExcelUtils();
-//        XSSFWorkbook workbook = new XSSFWorkbook();
-//        eeu.exportExcel(workbook, 0, "分日数据", accountHeaders, accountData);
-//        eeu.exportExcel(workbook, 1, "分组数据", groupHeaders, group);
-//        this.setResponseHeader(response, "日报.xls");
-//        workbook.write(os);
-//        os.flush();
-//        os.close();
+        OutputStream outputStream = response.getOutputStream();
+        String date = DateUtils.formatDate(new Date());
+        this.setResponseHeader(response, "爱上消消消日报" + date + ".xls");
+        ExcelWriter excelWriter = EasyExcelFactory.getWriter(outputStream);
+        for (int i = 0; i < sheets.size(); i++) {
+            Sheet sheet = new Sheet(i + 1, 0, KuaishouXxlEntity.class);
+            sheet.setSheetName(sheets.get(i).getSheetName());
+            excelWriter.write(sheets.get(i).getDetails(), sheet);
+        }
+        excelWriter.finish();
+        outputStream.flush();
+        outputStream.close();
     }
 
     //发送响应流方法

+ 1 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/mapper/AdvertiserMapper.java

@@ -15,6 +15,6 @@ import java.util.List;
  */
 public interface AdvertiserMapper extends BaseMapper<Advertiser> {
 
-    List<KuaishouXxlEntity> getXXlStatisticInfo(@Param(value = "accountId") String accountId, @Param(value = "groupBy") String groupBy);
+    List<KuaishouXxlEntity> getXXlStatisticInfo(@Param(value = "projectId") Long projectId, @Param(value = "systemType") String systemType, @Param(value = "accountId") Long accountId, @Param(value = "groupBy") String groupBy);
 
 }

+ 35 - 13
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/mapper/xml/AdvertiserMapper.xml

@@ -3,20 +3,28 @@
 <mapper namespace="org.jeecg.modules.ctop.mapper.AdvertiserMapper">
 
     <select id="getXXlStatisticInfo" resultType="org.jeecg.modules.excelutil.entity.KuaishouXxlEntity">
-        select report.stat_date as date,
-        sum(report.charge) as cost,
-        sum(case
+        select
+        report.stat_date as date,
+        round(sum(report.charge),2) as cost,
+        round(sum(
+        case
         when g.deep_conversion_bid != 0
         then report.charge
         else 0
-        end) as doubleBid,
-        sum(case
+        end),2) as doubleBid,
+        round(sum(
+        case
         when g.deep_conversion_bid = 0
         then report.charge
         else 0
-        end) as singleBid,
+        end),2) as singleBid,
         sum(activation) as active,
-        round(sum(report.charge) / sum(activation), 2) as activeCost,
+        (case
+        when sum(report.charge)!=0 and sum(activation)!=0
+        then round(sum(report.charge) / sum(activation), 2)
+        else 0
+        end
+        ) as activeCost,
         (
         select
         count(1)
@@ -24,20 +32,34 @@
         ctop_kuaishou_group g2
         left join ctop_user_allocation allocation2 on g2.account_id = allocation2.account_id
         where
-        allocation2.project_id = 285
+        1=1
+        <if test="projectId != null">
+            and allocation2.project_id = #{projectId}
+        </if>
+        <if test="systemType != null">
+            and allocation2.system_type = #{systemType}
+        </if>
         <if test="accountId != null">
             and allocation2.account_id = #{accountId}
         </if>
         and
-        date_format(g2.group_create_time, '%Y-%m-%d') = report.stat_date)
-        as planNum,
+        date_format(g2.group_create_time, '%Y-%m-%d') = report.stat_date
+        ) as planNum,
         '' as mat
-        from ctop_kuaishou_report_daily_group report
+        from
+        ctop_kuaishou_report_daily_group report
         left join ctop_kuaishou_group g on g.unit_id = report.unit_id
         left join ctop_user_allocation allocation on allocation.account_id = report.account_id
-        where allocation.project_id = 285
+        where
+        1=1
+        <if test="projectId != null">
+            and allocation.project_id = #{projectId}
+        </if>
+        <if test="systemType != null">
+            and allocation.system_type = #{systemType}
+        </if>
         <if test="accountId != null">
-            and allocation2.account_id = #{accountId}
+            and allocation.account_id = #{accountId}
         </if>
         <if test="groupBy != null">
             group by report.stat_date;

+ 3 - 3
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/IAdvertiserService.java

@@ -1,8 +1,8 @@
 package org.jeecg.modules.ctop.service;
 
-import org.jeecg.modules.ctop.entity.Advertiser;
 import com.baomidou.mybatisplus.extension.service.IService;
-import org.jeecg.modules.excelutil.entity.KuaishouXxlEntity;
+import org.jeecg.modules.ctop.entity.Advertiser;
+import org.jeecg.modules.ctop.vo.SheetInfoVo;
 
 import java.util.List;
 
@@ -16,6 +16,6 @@ public interface IAdvertiserService extends IService<Advertiser> {
 
     List<Advertiser> getBySaleId(String saleId);
 
-    List<KuaishouXxlEntity> getXxlStatisticInfo();
+    SheetInfoVo getXxlStatisticInfo(Long projectId, String systemType, Long accountId, String groupBy, String sheetName);
 
 }

+ 14 - 4
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/AdvertiserServiceImpl.java

@@ -1,15 +1,16 @@
 package org.jeecg.modules.ctop.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.jeecg.modules.ctop.entity.Advertiser;
 import org.jeecg.modules.ctop.mapper.AdvertiserMapper;
 import org.jeecg.modules.ctop.service.IAdvertiserService;
+import org.jeecg.modules.ctop.vo.SheetInfoVo;
 import org.jeecg.modules.excelutil.entity.KuaishouXxlEntity;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -31,7 +32,16 @@ public class AdvertiserServiceImpl extends ServiceImpl<AdvertiserMapper, Adverti
     }
 
     @Override
-    public List<KuaishouXxlEntity> getXxlStatisticInfo() {
-        return advertiserMapper.getXXlStatisticInfo(null, null);
+    public SheetInfoVo getXxlStatisticInfo(Long projectId, String systemType, Long accountId, String groupBy, String sheetName) {
+        SheetInfoVo vo = new SheetInfoVo();
+        List<KuaishouXxlEntity> details = new ArrayList<>();
+        vo.setSheetName(sheetName);
+        List<KuaishouXxlEntity> totalList = advertiserMapper.getXXlStatisticInfo(projectId, systemType, accountId, null);
+        KuaishouXxlEntity totalEntity = totalList.get(0);
+        totalEntity.setDate("汇总");
+        details.add(totalEntity);
+        details.addAll(advertiserMapper.getXXlStatisticInfo(projectId, systemType, accountId, "state_date"));
+        vo.setDetails(details);
+        return vo;
     }
 }

+ 5 - 3
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/vo/SheetInfoVo.java

@@ -1,5 +1,7 @@
 package org.jeecg.modules.ctop.vo;
 
+import org.jeecg.modules.excelutil.entity.KuaishouXxlEntity;
+
 import java.util.List;
 
 /**
@@ -7,13 +9,13 @@ import java.util.List;
  */
 public class SheetInfoVo {
     private String sheetName;
-    List<Object> details;
+    List<KuaishouXxlEntity> details;
 
-    public List<Object> getDetails() {
+    public List<KuaishouXxlEntity> getDetails() {
         return details;
     }
 
-    public void setDetails(List<Object> details) {
+    public void setDetails(List<KuaishouXxlEntity> details) {
         this.details = details;
     }
 

+ 4 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/IUserAllocationService.java

@@ -3,6 +3,8 @@ package cn.com.ctop.common.module.service;
 import cn.com.ctop.common.module.entity.UserAllocation;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.List;
+
 /**
  * @Description: 用户分配
  * @Author: jeecg-boot
@@ -12,4 +14,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
 public interface IUserAllocationService extends IService<UserAllocation> {
 
     UserAllocation getByAccountId(Long accountId);
+
+    List<UserAllocation> getByProjectId(long projectId, String systemType);
 }

+ 13 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/impl/UserAllocationServiceImpl.java

@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 /**
  * @Description: 用户分配
  * @Author: jeecg-boot
@@ -22,4 +24,15 @@ public class UserAllocationServiceImpl extends ServiceImpl<UserAllocationMapper,
         queryWrapper.eq("account_id", accountId + "").orderByDesc("id").last("limit 1");
         return this.getOne(queryWrapper);
     }
+
+    @Override
+    public List<UserAllocation> getByProjectId(long projectId, String systemType) {
+        QueryWrapper<UserAllocation> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("project_id", projectId);
+        if (null != systemType && !systemType.trim().equals("")) {
+            queryWrapper.eq("system_type", systemType);
+        }
+        queryWrapper.orderByDesc("id");
+        return this.list(queryWrapper);
+    }
 }