|
@@ -0,0 +1,115 @@
|
|
|
|
+package cn.com.ctop.bytedance.controller;
|
|
|
|
+
|
|
|
|
+import cn.com.ctop.bytedance.service.IKuaiShouYiCheReportService;
|
|
|
|
+import cn.com.ctop.common.module.utils.Check;
|
|
|
|
+import cn.com.ctop.common.module.utils.ExportExcelUtils;
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+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.*;
|
|
|
|
+
|
|
|
|
+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.List;
|
|
|
|
+
|
|
|
|
+@RestController
|
|
|
|
+@RequestMapping("/ctop/yiche/report/")
|
|
|
|
+public class KuaiShouYiCheReportController {
|
|
|
|
+ @Autowired
|
|
|
|
+ private IKuaiShouYiCheReportService yiCheReportService;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @PostMapping("hourReport")
|
|
|
|
+ public Result<JSONObject> advertiserReport(@RequestBody JSONObject requestJson) {
|
|
|
|
+ Result<JSONObject> result = new Result<>();
|
|
|
|
+ JSONObject hourReport = yiCheReportService.getHourReport(requestJson);
|
|
|
|
+ result.setResult(hourReport);
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 导出报表
|
|
|
|
+ *
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @RequestMapping(value = "/exportHourReport")
|
|
|
|
+ @ResponseBody
|
|
|
|
+ public void export(HttpServletRequest request, HttpServletResponse response, @RequestBody JSONObject requestJson) throws Exception {
|
|
|
|
+
|
|
|
|
+ JSONObject hourReport = yiCheReportService.getHourReport(requestJson);
|
|
|
|
+ JSONArray androidArr = hourReport.getJSONArray("android");
|
|
|
|
+
|
|
|
|
+ // 安卓相关
|
|
|
|
+ List<List<Object>> androidList = new ArrayList<>();
|
|
|
|
+ if (!Check.isNull(androidArr)) {
|
|
|
|
+ for (int i = 0; i < androidArr.size(); i++) {
|
|
|
|
+ JSONObject jsonObject = androidArr.getJSONObject(i);
|
|
|
|
+
|
|
|
|
+ List<Object> android = new ArrayList();
|
|
|
|
+ android.add(jsonObject.getString("systemType"));
|
|
|
|
+ android.add(jsonObject.getString("authName"));
|
|
|
|
+ android.add(jsonObject.getBigDecimal("charge"));
|
|
|
|
+ android.add(jsonObject.getLong("activation"));
|
|
|
|
+ android.add(jsonObject.getBigDecimal("activationCost"));
|
|
|
|
+ android.add(jsonObject.getBigDecimal("estimatedCost"));
|
|
|
|
+ androidList.add(android);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // ios 相关
|
|
|
|
+ JSONArray iosArr = hourReport.getJSONArray("ios");
|
|
|
|
+ List<List<Object>> iosList = new ArrayList<>();
|
|
|
|
+ if (!Check.isNull(iosArr)) {
|
|
|
|
+ for (int i = 0; i < iosArr.size(); i++) {
|
|
|
|
+ JSONObject jsonObject = iosArr.getJSONObject(i);
|
|
|
|
+ List<Object> ios = new ArrayList();
|
|
|
|
+ ios.add(jsonObject.getString("systemType"));
|
|
|
|
+ ios.add(jsonObject.getString("authName"));
|
|
|
|
+ ios.add(jsonObject.getBigDecimal("charge"));
|
|
|
|
+ ios.add(jsonObject.getLong("activation"));
|
|
|
|
+ ios.add(jsonObject.getBigDecimal("activationCost"));
|
|
|
|
+ ios.add(jsonObject.getBigDecimal("estimatedCost"));
|
|
|
|
+ iosList.add(ios);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ String[] androidHeaders = {"投放设备", "分类", "现金花费", "账户激活量", "激活成本", "预估成本"};
|
|
|
|
+ String[] iosHeaders = {"投放设备", "分类", "现金花费", "账户激活量", "激活成本", "预估成本"};
|
|
|
|
+ OutputStream os = response.getOutputStream();
|
|
|
|
+ ExportExcelUtils eeu = new ExportExcelUtils();
|
|
|
|
+ XSSFWorkbook workbook = new XSSFWorkbook();
|
|
|
|
+ eeu.exportExcel(workbook, 0, "安卓时报统计", androidHeaders, androidList);
|
|
|
|
+ eeu.exportExcel(workbook, 1, "ios时报统计", iosHeaders, iosList);
|
|
|
|
+ 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();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|