|
@@ -0,0 +1,178 @@
|
|
|
+package cn.com.ctop.bytedance.service.impl;
|
|
|
+
|
|
|
+import cn.com.ctop.bytedance.mapper.DailyReportMapper;
|
|
|
+import cn.com.ctop.bytedance.service.IDailyReportService;
|
|
|
+import cn.com.ctop.bytedance.vo.DailyAccountReportVO;
|
|
|
+import cn.com.ctop.bytedance.vo.DailyGroupReportVO;
|
|
|
+import cn.com.ctop.bytedance.vo.DailyReportVO;
|
|
|
+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 lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.OutputStream;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 日报报表
|
|
|
+ */
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class DailyReportServiceImpl implements IDailyReportService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DailyReportMapper dailyReportMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取日报数据
|
|
|
+ *
|
|
|
+ * @param requestJson
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public DailyReportVO getDailyReport(JSONObject requestJson) {
|
|
|
+ try {
|
|
|
+
|
|
|
+ System.err.println(requestJson);
|
|
|
+ log.info("日报开始统计");
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
+
|
|
|
+ JSONArray accountIds = requestJson.getJSONArray("accountIds");
|
|
|
+ BigDecimal discount = requestJson.getBigDecimal("discount");
|
|
|
+ Map<String, Object> requestMap = new HashMap<>();
|
|
|
+ requestMap.put("accountIds", accountIds);
|
|
|
+ requestMap.put("discount", discount);
|
|
|
+ requestMap.put("date", requestJson.getString("date"));
|
|
|
+ DailyAccountReportVO dailyAccountReport = dailyReportMapper.getDailyReport(requestMap);
|
|
|
+ if (!Check.isNull(dailyAccountReport)) {
|
|
|
+ BigDecimal cost = dailyAccountReport.getCost();
|
|
|
+ BigDecimal contractRebateRealCharged = dailyAccountReport.getContractRebateRealCharged();
|
|
|
+ if (Check.isNull(cost) && Check.isNull(contractRebateRealCharged)) {
|
|
|
+ BigDecimal actualCost = (cost.subtract(contractRebateRealCharged)).divide(discount, 2, RoundingMode.HALF_UP);
|
|
|
+ dailyAccountReport.setActualCost(actualCost);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ List<DailyGroupReportVO> dailyGroupReport = dailyReportMapper.getDailyGroupReport(requestMap);
|
|
|
+
|
|
|
+ DailyReportVO dailyReport = new DailyReportVO();
|
|
|
+ dailyReport.setDailyAccountReport(dailyAccountReport);
|
|
|
+ dailyReport.setDailyGroupReport(dailyGroupReport);
|
|
|
+
|
|
|
+
|
|
|
+ System.err.println(dailyAccountReport);
|
|
|
+
|
|
|
+ System.err.println("------------------");
|
|
|
+ System.err.println(dailyGroupReport);
|
|
|
+ log.info("日报统计完成,用时: " + ((System.currentTimeMillis() - startTime) / 1000) + " s");
|
|
|
+ return dailyReport;
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数据导出
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ * @param requestJson
|
|
|
+ */
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void exportDailyReport(HttpServletRequest request, HttpServletResponse response, JSONObject requestJson) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ OutputStream outStream = new FileOutputStream("D:\\file");
|
|
|
+ DailyReportVO dailyReport = this.getDailyReport(requestJson);
|
|
|
+ List<List<String>> accountData = new ArrayList<List<String>>();
|
|
|
+ if (!Check.isNull(dailyReport)) {
|
|
|
+ DailyAccountReportVO dailyAccountReport = dailyReport.getDailyAccountReport();
|
|
|
+ if (!Check.isNull(dailyAccountReport)) {
|
|
|
+ List rowData = new ArrayList();
|
|
|
+ rowData.add(requestJson.getString("date")); // 时间
|
|
|
+ rowData.add(String.valueOf(dailyAccountReport.getCost())); // 消耗
|
|
|
+ rowData.add(String.valueOf(dailyAccountReport.getContractRebateRealCharged())); // 激励花费
|
|
|
+ rowData.add(String.valueOf(dailyAccountReport.getActualCost())); // 实际花费
|
|
|
+ rowData.add(String.valueOf(dailyAccountReport.getPhotoShow())); // 展示数
|
|
|
+ rowData.add(String.valueOf(dailyAccountReport.getPhotoClick())); // 点击数
|
|
|
+ rowData.add(String.valueOf(dailyAccountReport.getPhotoClickRatio())); // 点击率
|
|
|
+ rowData.add(String.valueOf(dailyAccountReport.getPhotoClickCost())); // 平均点击花费
|
|
|
+ rowData.add(String.valueOf(dailyAccountReport.getBclick())); // 行为数
|
|
|
+ rowData.add(String.valueOf(dailyAccountReport.getActionRatio())); // 行为率
|
|
|
+ rowData.add(String.valueOf(dailyAccountReport.getImpression1kCost())); // 平均千次展现花费
|
|
|
+ rowData.add(String.valueOf(dailyAccountReport.getConversions())); // 转化数
|
|
|
+ rowData.add(String.valueOf(dailyAccountReport.getConversionPrice())); // 转化单价
|
|
|
+ rowData.add(String.valueOf(dailyAccountReport.getConversionRate())); // 转化率
|
|
|
+ rowData.add(String.valueOf(dailyAccountReport.getDiscountConversionPrice())); // 折后转化成本
|
|
|
+
|
|
|
+ accountData.add(rowData);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ List<List<String>> groupReport = new ArrayList<List<String>>();
|
|
|
+
|
|
|
+ List<DailyGroupReportVO> dailyGroupReport = dailyReport.getDailyGroupReport();
|
|
|
+ /* if(!Check.isNull(dailyGroupReport)){
|
|
|
+ for (DailyGroupReportVO groupReport : dailyGroupReport) {
|
|
|
+ List rowData = new ArrayList();
|
|
|
+ rowData.add(tIndexDetailDto.getAllyId());
|
|
|
+ rowData.add(tIndexDetailDto.getProvince());
|
|
|
+ rowData.add(tIndexDetailDto.getCity());
|
|
|
+ rowData.add(tIndexDetailDto.getCounty());
|
|
|
+ rowData.add(tIndexDetailDto.getBureau() + "");
|
|
|
+ rowData.add(tIndexDetailDto.getFirstTenderYear());
|
|
|
+ rowData.add(String.valueOf(tIndexDetailDto.getMonthInterestRateScore()));
|
|
|
+ rowData.add(String.valueOf(tIndexDetailDto.getCapitalRateScore()));
|
|
|
+ rowData.add(String.valueOf(tIndexDetailDto.getmTwoRateScore()));
|
|
|
+ rowData.add(String.valueOf(tIndexDetailDto.getYqtzRateScore()));
|
|
|
+ rowData.add(String.valueOf(tIndexDetailDto.getYearInterestRateScore()));
|
|
|
+ rowData.add(String.valueOf(tIndexDetailDto.getYearCapitalRateScore()));
|
|
|
+ rowData.add(String.valueOf(tIndexDetailDto.getYearMTwoRateScore()));
|
|
|
+ rowData.add(String.valueOf(tIndexDetailDto.getYearYqtzRateScore()));
|
|
|
+ rowData.add(String.valueOf(tIndexDetailDto.getYearSumScore()));
|
|
|
+ data1.add(rowData);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+*/
|
|
|
+
|
|
|
+
|
|
|
+ String[] headers0 = {"时间", "消耗", "激励花费", "实际消耗", "展示数", "点击数", "点击率", "平均点击花费", "行为数", "行为率", "平均千次展现花费", "转化数", "转化单价", "转化率", "折后转化成本"};
|
|
|
+
|
|
|
+ ExportExcelUtils eeu = new ExportExcelUtils();
|
|
|
+ XSSFWorkbook workbook = new XSSFWorkbook();
|
|
|
+ eeu.exportExcel(workbook, 0, "分日数据", headers0, accountData, outStream);
|
|
|
+
|
|
|
+ //原理就是将所有的数据一起写入,然后再关闭输入流。
|
|
|
+ workbook.write(outStream);
|
|
|
+ outStream.close();
|
|
|
+ } catch (
|
|
|
+ Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|