|
@@ -44,23 +44,29 @@ public class BytedanceHomepageReportServiceImpl implements IBytedanceHomepageRep
|
|
|
top.put("top7", costTop);
|
|
|
//周明细环比数据拼接
|
|
|
JSONObject costWeekData = new JSONObject();
|
|
|
+ JSONObject costWeekLink = new JSONObject();
|
|
|
JSONObject clickWeekData = new JSONObject();
|
|
|
+ JSONObject clickWeekLink = new JSONObject();
|
|
|
JSONObject showNumWeekData = new JSONObject();
|
|
|
+ JSONObject showNumWeekLink = new JSONObject();
|
|
|
weekDetailData.forEach(day -> {
|
|
|
costWeekData.put((String) day.get("statDate"), day.get("cost"));
|
|
|
clickWeekData.put((String) day.get("statDate"), day.get("click"));
|
|
|
showNumWeekData.put((String) day.get("statDate"), day.get("showNum"));
|
|
|
});
|
|
|
- costWeekData.put("weekCostSum", weekSumData.get("cost"));
|
|
|
- costWeekData.put("weekCostSumLink", countLink(weekSumData.getBigDecimal("cost"), weekBeforeSumData.getBigDecimal("cost")));
|
|
|
- clickWeekData.put("weekClickSum", weekSumData.get("click"));
|
|
|
- clickWeekData.put("weekClickSumLink", countLink(BigDecimal.valueOf(weekSumData.getLongValue("click")), BigDecimal.valueOf(weekBeforeSumData.getLong("click"))));
|
|
|
- showNumWeekData.put("weekCostSum", weekSumData.get("showNum"));
|
|
|
- showNumWeekData.put("weekShowNumSumLink", countLink(BigDecimal.valueOf(weekSumData.getLongValue("showNum")), BigDecimal.valueOf(weekBeforeSumData.getLong("showNum"))));
|
|
|
+ costWeekLink.put("weekCostSum", weekSumData.get("cost"));
|
|
|
+ costWeekLink.put("weekCostSumLink", countLink(weekSumData.getBigDecimal("cost"), weekBeforeSumData.getBigDecimal("cost")));
|
|
|
+ clickWeekLink.put("weekClickSum", weekSumData.get("click"));
|
|
|
+ clickWeekLink.put("weekClickSumLink", countLink(BigDecimal.valueOf(weekSumData.getLongValue("click")), BigDecimal.valueOf(weekBeforeSumData.getLong("click"))));
|
|
|
+ showNumWeekLink.put("weekShowNumSum", weekSumData.get("showNum"));
|
|
|
+ showNumWeekLink.put("weekShowNumSumLink", countLink(BigDecimal.valueOf(weekSumData.getLongValue("showNum")), BigDecimal.valueOf(weekBeforeSumData.getLong("showNum"))));
|
|
|
|
|
|
result.put("costWeek", costWeekData);
|
|
|
+ result.put("costWeekLink", costWeekLink);
|
|
|
result.put("clickWeek", clickWeekData);
|
|
|
+ result.put("clickWeekLink", clickWeekLink);
|
|
|
result.put("showNumWeek", showNumWeekData);
|
|
|
+ result.put("showNumWeekLink", showNumWeekLink);
|
|
|
result.put("top", top);
|
|
|
|
|
|
return result;
|
|
@@ -70,12 +76,14 @@ public class BytedanceHomepageReportServiceImpl implements IBytedanceHomepageRep
|
|
|
* timeType :1,2,3,4,5,6,7,8,9 前端约束入参类型
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<JSONObject> getChartByDate(JSONObject requestBody) {
|
|
|
+ public Map<String,List<JSONObject>> getChartByDate(JSONObject requestBody) {
|
|
|
int timeType = requestBody.getInteger("type");
|
|
|
- List<JSONObject> resultBody = new ArrayList<>();
|
|
|
+ Map<String,List<JSONObject>> resultBody=new HashMap<>();
|
|
|
if (requestBody.isEmpty()) {
|
|
|
return resultBody;
|
|
|
}
|
|
|
+ List<JSONObject> resultChart = new ArrayList<>();
|
|
|
+ List<JSONObject> resultList = new ArrayList<>();
|
|
|
//当天日期
|
|
|
String nowDate = DateUtils.getNowDate(SystemDateConstant.yyyy_MM_dd);
|
|
|
//startTime 为取什么时间段数据的开始时间,默认昨天
|
|
@@ -83,69 +91,128 @@ public class BytedanceHomepageReportServiceImpl implements IBytedanceHomepageRep
|
|
|
switch (timeType) {
|
|
|
//今天
|
|
|
case 1:
|
|
|
- resultBody = getCompareGroupByHour(nowDate, anotherDay);
|
|
|
+ resultChart = getCompareGroupByHour(nowDate, anotherDay);
|
|
|
+ resultList = getFormDetailByDate(nowDate,nowDate,"hour");
|
|
|
break;
|
|
|
//昨天
|
|
|
case 2:
|
|
|
- resultBody = bytedanceHomepageMapper.queryTodayDetailReportBy(anotherDay);
|
|
|
+ resultChart = getCompareGroupByHour(anotherDay, DateUtils.getAnotherDay(SystemDateConstant.yyyy_MM_dd, anotherDay, -1));
|
|
|
+ resultList = getFormDetailByDate(anotherDay,anotherDay,"hour");
|
|
|
break;
|
|
|
//近一周
|
|
|
case 3:
|
|
|
- resultBody = bytedanceHomepageMapper.queryDetailByStartEndDate(nowDate,
|
|
|
+ resultChart = bytedanceHomepageMapper.queryDetailByStartEndDate(nowDate,
|
|
|
DateUtils.getAnotherDay(SystemDateConstant.yyyy_MM_dd, anotherDay, -6));
|
|
|
+ resultList = getFormDetailByDate(nowDate, DateUtils.getAnotherDay(SystemDateConstant.yyyy_MM_dd, anotherDay, -6),"day");
|
|
|
break;
|
|
|
//近半个月(15天)
|
|
|
case 4:
|
|
|
- resultBody = bytedanceHomepageMapper.queryDetailByStartEndDate(nowDate,
|
|
|
+ resultChart = bytedanceHomepageMapper.queryDetailByStartEndDate(nowDate,
|
|
|
DateUtils.getAnotherDay(SystemDateConstant.yyyy_MM_dd, anotherDay, -14));
|
|
|
+ resultList = getFormDetailByDate(nowDate, DateUtils.getAnotherDay(SystemDateConstant.yyyy_MM_dd, anotherDay, -14),"day");
|
|
|
break;
|
|
|
//近一个月
|
|
|
case 5:
|
|
|
- resultBody = bytedanceHomepageMapper.queryDetailByStartEndDate(nowDate,
|
|
|
+ resultChart = bytedanceHomepageMapper.queryDetailByStartEndDate(nowDate,
|
|
|
DateUtils.getMonthBefore(SystemDateConstant.yyyy_MM_dd, anotherDay, -1));
|
|
|
+ resultList = getFormDetailByDate(nowDate, DateUtils.getMonthBefore(SystemDateConstant.yyyy_MM_dd, anotherDay, -1),"day");
|
|
|
break;
|
|
|
//近三个月
|
|
|
case 6:
|
|
|
- resultBody = bytedanceHomepageMapper.queryDetailByStartEndDate(nowDate,
|
|
|
+ resultChart = bytedanceHomepageMapper.queryDetailByStartEndDate(nowDate,
|
|
|
DateUtils.getMonthBefore(SystemDateConstant.yyyy_MM_dd, anotherDay, -3));
|
|
|
+ resultList = getFormDetailByDate(nowDate, DateUtils.getMonthBefore(SystemDateConstant.yyyy_MM_dd, anotherDay, -3),"day");
|
|
|
break;
|
|
|
//近半年
|
|
|
case 7:
|
|
|
- resultBody = bytedanceHomepageMapper.queryDetailByStartEndDate(nowDate,
|
|
|
+ resultChart = bytedanceHomepageMapper.queryDetailByStartEndDate(nowDate,
|
|
|
DateUtils.getMonthBefore(SystemDateConstant.yyyy_MM_dd, anotherDay, -6));
|
|
|
+ resultList = getFormDetailByDate(nowDate, DateUtils.getMonthBefore(SystemDateConstant.yyyy_MM_dd, anotherDay, -6),"day");
|
|
|
break;
|
|
|
- //全部数据
|
|
|
+ //近一年
|
|
|
case 8:
|
|
|
- resultBody = bytedanceHomepageMapper.queryDetailGroupMonthByDate(SystemDateConstant.BEGIN_TIME, nowDate);
|
|
|
+ resultChart = bytedanceHomepageMapper.queryDetailGroupMonthByDate( nowDate, SystemDateConstant.BEGIN_TIME);
|
|
|
+ resultList = getFormDetailByDate(nowDate, SystemDateConstant.BEGIN_TIME,"day");
|
|
|
break;
|
|
|
//自定义起始时间
|
|
|
case 9:
|
|
|
- resultBody = bytedanceHomepageMapper.queryDetailByStartEndDate(requestBody.getString("startDate"), requestBody.getString("endDate"));
|
|
|
- break;
|
|
|
- //对比
|
|
|
- case 10:
|
|
|
- resultBody = getChartByType_10(requestBody.getString("sign"), requestBody.getString("smallDate"), requestBody.getString("bigDate"));
|
|
|
+ resultChart = bytedanceHomepageMapper.queryDetailByStartEndDate(requestBody.getString("endDate"), requestBody.getString("startDate"));
|
|
|
+ resultList = getFormDetailByDate(requestBody.getString("endDate"), requestBody.getString("startDate"),"day");
|
|
|
break;
|
|
|
default:
|
|
|
}
|
|
|
+ resultBody.put("chart",resultChart);
|
|
|
+ resultBody.put("list",resultList);
|
|
|
return resultBody;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public JSONObject getTopCostByDate(JSONObject requestBody) {
|
|
|
- return null;
|
|
|
+ public Map<String, JSONObject> getCompareByDate(JSONObject requestBody) {
|
|
|
+ Map<String,JSONObject> resultBody=new HashMap<>();
|
|
|
+ if (requestBody.isEmpty()) {
|
|
|
+ return resultBody;
|
|
|
+ }
|
|
|
+ String sign= requestBody.getString("sign");
|
|
|
+ String smallDate= requestBody.getString("smallDate");
|
|
|
+ String bigDate= requestBody.getString("bigDate");
|
|
|
+ resultBody.put("chart",this.getCompareChart(sign,smallDate,bigDate));
|
|
|
+ resultBody.put("list",this.getCompareList(sign,smallDate,bigDate));
|
|
|
+
|
|
|
+ return resultBody;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //表格数据查询
|
|
|
+ private List<JSONObject> getFormDetailByDate(String endDate, String startDate, String group){
|
|
|
+ List<JSONObject> result =null;
|
|
|
+ if("day".equals(group)){
|
|
|
+ result= bytedanceHomepageMapper.queryDetailByStartEndDate(endDate,startDate);
|
|
|
+ }else {
|
|
|
+ result= bytedanceHomepageMapper.queryTodayDetailReportBy(endDate);
|
|
|
+ }
|
|
|
+ return getListLink(result);
|
|
|
}
|
|
|
|
|
|
//自定义日期对比(日对比,月对比)
|
|
|
- private List<JSONObject> getChartByType_10(String sign, String smallDate, String bigDate) {
|
|
|
- List<JSONObject> result = new ArrayList<>();
|
|
|
+ private JSONObject getCompareChart(String sign, String smallDate, String bigDate) {
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
if (!sign.isEmpty() && sign.equals("month")) {
|
|
|
- result = this.getCompareGroupByDay(smallDate, bigDate);
|
|
|
+ result.put("compare",this.getCompareGroupByDay(smallDate, bigDate));
|
|
|
} else if (!sign.isEmpty() && sign.equals("day")) {
|
|
|
- result = this.getCompareGroupByHour(bigDate, smallDate);
|
|
|
+ result.put("compare",this.getCompareGroupByHour(bigDate, smallDate));
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ private JSONObject getCompareList(String sign, String smallDate, String bigDate){
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ if (!sign.isEmpty() && sign.equals("month")) {
|
|
|
+ result.put("smallDate",getListLink(bytedanceHomepageMapper.queryDetailGroupDayByMonth(smallDate)));
|
|
|
+ result.put("bigDate",getListLink(bytedanceHomepageMapper.queryDetailGroupDayByMonth(bigDate)));
|
|
|
+ } else if (!sign.isEmpty() && sign.equals("day")) {
|
|
|
+ result.put("smallDate",getListLink(bytedanceHomepageMapper.queryTodayDetailReportBy(smallDate)));
|
|
|
+ result.put("bigDate",getListLink(bytedanceHomepageMapper.queryTodayDetailReportBy(bigDate)));
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
+ //List环比计算
|
|
|
+ private List<JSONObject> getListLink(List<JSONObject> result){
|
|
|
+ if(result.size()>1){
|
|
|
+ for(int i=1;i<result.size();i++){
|
|
|
+ if(i==1){result.get(i).put("costProportion",BigDecimal.ZERO);}
|
|
|
+ result.get(i).put("costProportion",countLink((BigDecimal) result.get(i).get("cost"),(BigDecimal) result.get(i-1).get("cost")));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ /*private JSONObject getCompareSum(String sign, String smallDate, String bigDate){
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ if (!sign.isEmpty() && sign.equals("month")) {
|
|
|
+ bytedanceHomepageMapper.querySumByStartEndDate()
|
|
|
+ } else if (!sign.isEmpty() && sign.equals("day")) {
|
|
|
+ result = this.getCompareGroupByHour(bigDate, smallDate);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }*/
|
|
|
|
|
|
//两个月份的数据对比
|
|
|
private List<JSONObject> getCompareGroupByDay(String smallDate, String bigDate) {
|
|
@@ -153,15 +220,8 @@ public class BytedanceHomepageReportServiceImpl implements IBytedanceHomepageRep
|
|
|
List<JSONObject> afterDetail = bytedanceHomepageMapper.queryDetailGroupDayByMonth(bigDate);
|
|
|
//小月份数据
|
|
|
List<JSONObject> beforeDetail = bytedanceHomepageMapper.queryDetailGroupDayByMonth(smallDate);
|
|
|
- List<JSONObject> beforeData;List<JSONObject> afterData;
|
|
|
- if (afterDetail.size() >= beforeDetail.size()) {
|
|
|
- beforeData = afterDetail;
|
|
|
- afterData = beforeData;
|
|
|
- } else {
|
|
|
- beforeData = beforeDetail;
|
|
|
- afterData = afterDetail;
|
|
|
- }
|
|
|
- return this.getCompareDate(beforeData,afterData,"day");
|
|
|
+
|
|
|
+ return this.getCompareDate(beforeDetail,afterDetail,"day");
|
|
|
}
|
|
|
|
|
|
//今天昨天数据对比
|
|
@@ -175,9 +235,9 @@ public class BytedanceHomepageReportServiceImpl implements IBytedanceHomepageRep
|
|
|
private List<JSONObject> getCompareDate(List<JSONObject> beforeData, List<JSONObject> AfterData, String standard) {
|
|
|
List<JSONObject> result = new ArrayList<>();
|
|
|
beforeData.forEach(before -> {
|
|
|
- String yesStatHour = String.valueOf(before.get(standard));
|
|
|
+ String yesStat = String.valueOf(before.get(standard));
|
|
|
AfterData.forEach(after -> {
|
|
|
- if ((String.valueOf(after.get(standard))).equals(yesStatHour)) {
|
|
|
+ if ((String.valueOf(after.get(standard))).equals(yesStat)) {
|
|
|
//消耗较昨日环比
|
|
|
after.put("costProportion", countLink(after.getBigDecimal("cost"), before.getBigDecimal("cost")));
|
|
|
//展示量较昨日环比
|
|
@@ -201,5 +261,4 @@ public class BytedanceHomepageReportServiceImpl implements IBytedanceHomepageRep
|
|
|
return link;
|
|
|
}
|
|
|
|
|
|
-}
|
|
|
-
|
|
|
+}
|