|
@@ -2,15 +2,21 @@ package cn.com.ctop.kuaishou.modules.report.controller;
|
|
|
|
|
|
import cn.com.ctop.common.module.service.ISysUserService;
|
|
|
import cn.com.ctop.common.module.utils.Check;
|
|
|
+import cn.com.ctop.common.module.utils.ExportExcelUtils;
|
|
|
+import cn.com.ctop.common.module.utils.HttpUtils;
|
|
|
import cn.com.ctop.kuaishou.modules.report.service.ISalesBudgetService;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
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.RestController;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.OutputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
@@ -156,4 +162,137 @@ public class SalesBudgetController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @GetMapping("/exportReport")
|
|
|
+ public void exportReport(HttpServletResponse response, String userId, String mediaId, String date) {
|
|
|
+ try {
|
|
|
+ if (Check.isNull(date)) {
|
|
|
+ throw new Exception("请传入日期");
|
|
|
+ }
|
|
|
+ String roleCode = sysUserService.getRoleCodeByUserId(userId);
|
|
|
+ String saleId = null;
|
|
|
+ if (!"admin".equals(roleCode) && !"saleDirector".equals(roleCode)) {
|
|
|
+ saleId = userId;
|
|
|
+ }
|
|
|
+ Long statDate = Long.valueOf(date.replace("-", ""));
|
|
|
+ Result<Object> result = null;
|
|
|
+ if ("1".equals(mediaId)) {
|
|
|
+ result = salesBudgetService.bytedanceSalesReport(saleId, statDate, 1, 99999);
|
|
|
+ } else {
|
|
|
+ result = salesBudgetService.kuaiShouSalesReport(saleId, statDate, 1, 99999);
|
|
|
+ }
|
|
|
+ PageInfo<JSONObject> pageInfo = (PageInfo<JSONObject>) result.getResult();
|
|
|
+ List<JSONObject> list = pageInfo.getList();
|
|
|
+
|
|
|
+ List<List<Object>> excelList = new ArrayList<>();
|
|
|
+ List<List<Object>> excelYRList = new ArrayList<>();
|
|
|
+ List<List<Object>> overtimeExcelList = new ArrayList<>();
|
|
|
+ List<List<Object>> overtimeYRExcelList = new ArrayList<>();
|
|
|
+ if (!Check.isNull(list)) {
|
|
|
+ list.forEach(data -> {
|
|
|
+ List<Object> temp = new ArrayList<>();
|
|
|
+ temp.add(data.getString("projectName"));//项目
|
|
|
+ StringBuffer buffer1 = new StringBuffer();
|
|
|
+ buffer1.append("销售:").append(data.getString("saleName")).append(String.valueOf((char) 10))
|
|
|
+ .append("运营:").append(data.getString("responsibleName"));
|
|
|
+ temp.add(buffer1);//相关人
|
|
|
+ StringBuffer buffer2 = new StringBuffer();
|
|
|
+ JSONObject budgetJson = data.getJSONObject("budgetJson");
|
|
|
+ String actualBudget = null;
|
|
|
+ String setBudget = null;
|
|
|
+ String subtract = null;
|
|
|
+ if (!Check.isNull(budgetJson)) {
|
|
|
+ actualBudget = budgetJson.getString("actualBudget");
|
|
|
+ setBudget = budgetJson.getString("setBudget");
|
|
|
+ subtract = budgetJson.getString("subtract");
|
|
|
+ }
|
|
|
+ if (!Check.isNull(setBudget)) {
|
|
|
+ buffer2.append("预算:").append(setBudget);
|
|
|
+ }
|
|
|
+ if (!Check.isNull(actualBudget)) {
|
|
|
+ buffer2.append(String.valueOf((char) 10)).append("消耗:").append(actualBudget);
|
|
|
+ }
|
|
|
+ if (!Check.isNull(subtract)) {
|
|
|
+ buffer2.append(String.valueOf((char) 10)).append("差值:").append(subtract);
|
|
|
+ }
|
|
|
+ temp.add(buffer2);//预算情况
|
|
|
+ StringBuffer buffer3 = new StringBuffer();
|
|
|
+ JSONArray costArray = data.getJSONArray("costArray");
|
|
|
+ if (!Check.isNull(costArray)) {
|
|
|
+ for (int i = 0; i < costArray.size(); i++) {
|
|
|
+ JSONObject obj = costArray.getJSONObject(i);
|
|
|
+ if (i > 0) {
|
|
|
+ buffer3.append(String.valueOf((char) 10));
|
|
|
+ }
|
|
|
+ buffer3.append(obj.getString("name")).append(" 考核:").append(obj.getString("setCost"))
|
|
|
+ .append(" 实际:").append(obj.getString("cost"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ temp.add(buffer3);//成本情况
|
|
|
+ if ("1".equals(mediaId)) {
|
|
|
+ temp.add(data.getString("active"));//激活数
|
|
|
+ temp.add(data.getString("activeCost"));//激活成本
|
|
|
+ temp.add(data.getString("attributionNextDayOpenCnt"));//次留
|
|
|
+ temp.add(data.getString("attributionNextDayOpenRate"));//次留率
|
|
|
+ temp.add(data.getString("attributionNextDayOpenCost"));//次留成本
|
|
|
+ temp.add(data.getString("form"));//表单数
|
|
|
+ temp.add(data.getString("formCost"));//表单成本
|
|
|
+ temp.add(data.getString("payCount"));//付费数
|
|
|
+ temp.add(data.getString("payCost"));//付费成本
|
|
|
+ temp.add(data.getString("gameAddiction"));//关键行为数
|
|
|
+ temp.add(data.getString("gameAddictionCost"));//关键行为成本
|
|
|
+ temp.add(data.getString("register"));//注册数
|
|
|
+ temp.add(data.getString("registerCost"));//注册成本
|
|
|
+ temp.add(data.getString("loanCompletion"));//完件数
|
|
|
+ temp.add(data.getString("loanCompletionCost"));//完件成本
|
|
|
+ temp.add(data.getString("preLoanCredit"));//授信数
|
|
|
+ temp.add(data.getString("preLoanCreditCost"));//授信成本
|
|
|
+ temp.add(data.getString("inAppUv"));//app内访问数
|
|
|
+ temp.add(data.getString("inAppUvCost"));//app内访问成本
|
|
|
+ temp.add(data.getString("inAppPay"));//app内付费数
|
|
|
+ temp.add(data.getString("inAppPayCost"));//app内付费成本
|
|
|
+ temp.add(data.getString("statPayAmount"));//首日roi
|
|
|
+
|
|
|
+ } else {
|
|
|
+ temp.add(data.getString("activation"));//激活数
|
|
|
+ temp.add(data.getString("activationCost"));//激活成本
|
|
|
+ temp.add(data.getString("eventNextDayStay"));//次留
|
|
|
+ temp.add(data.getString("eventNextDayStayRate"));//次留率
|
|
|
+ temp.add(data.getString("eventNextDayStayCost"));//次留成本
|
|
|
+ temp.add(data.getString("formCount"));//表单数
|
|
|
+ temp.add(data.getString("formCountCost"));//表单成本
|
|
|
+ temp.add(data.getString("eventPay"));//付费数
|
|
|
+ temp.add(data.getString("eventCost"));//付费成本
|
|
|
+ temp.add(data.getString("keyAction"));//关键行为数
|
|
|
+ temp.add(data.getString("keyActionCost"));//关键行为成本
|
|
|
+ temp.add(data.getString("eventAppInvoked"));//唤起数
|
|
|
+ temp.add(data.getString("eventAppInvokedCost"));//唤起成本
|
|
|
+ temp.add(data.getString("eventPayPurchaseAmountFirstDayCost"));//roi
|
|
|
+ temp.add(data.getString("eventThreeDayStayByConversionCost"));//3留
|
|
|
+ temp.add(data.getString("eventWeekStayByConversionCost"));//7留
|
|
|
+ }
|
|
|
+ excelList.add(temp);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ OutputStream os = response.getOutputStream();
|
|
|
+ ExportExcelUtils eeu = new ExportExcelUtils();
|
|
|
+ XSSFWorkbook workbook = new XSSFWorkbook();
|
|
|
+ String[] titles = new String[]{};
|
|
|
+ if ("1".equals(mediaId)) {
|
|
|
+ titles = new String[]{"项目", "相关人", "预算情况", "成本情况", "激活数", "激活成本", "次留", "次留率", "次留成本"
|
|
|
+ , "表单数", "表单成本", "付费数", "付费成本", "关键行为数", "关键行为成本", "注册数", "注册成本", "完件数"
|
|
|
+ , "完件成本", "授信数", "授信成本", "app内访问数", "app内访问成本", "app内付费数", "app内付费成本", "首日roi"};
|
|
|
+ } else {
|
|
|
+ titles = new String[]{"项目", "相关人", "预算情况", "成本情况", "激活数", "激活成本", "次留", "次留率", "次留成本"
|
|
|
+ , "表单数", "表单成本", "付费数", "付费成本", "关键行为数", "关键行为成本", "唤起数", "唤起成本", "roi", "3留", "7留"};
|
|
|
+ }
|
|
|
+ eeu.exportExcel(workbook, 0, "销售成本报表", titles, excelList);
|
|
|
+ HttpUtils.setResponseHeader(response, "销售成本报表.xlsx");
|
|
|
+ workbook.write(os);
|
|
|
+ os.flush();
|
|
|
+ os.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|