|
|
@@ -1,6 +1,7 @@
|
|
|
package org.jeecg.ctop.material.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
@@ -18,7 +19,6 @@ import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.Comparator;
|
|
|
import java.util.Date;
|
|
|
-import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
@@ -137,15 +137,16 @@ public class AdqAdvertiserReportServiceImpl implements IAdqAdvertiserReportServi
|
|
|
|
|
|
List<JSONObject> data;
|
|
|
if (startTime.equals(endTime) && today.equals(startTime)) {
|
|
|
- data = buildTodayProjectReport(category, projectId, startTime, startTimeInt, nowHour, sortCode, order);
|
|
|
+ PageHelper.startPage(pageNo, pageSize, false);
|
|
|
+ data = adqAdvertiserReportMapper.getProjectToDayReport(category, projectId, startTimeInt, nowHour, sortCode, order);
|
|
|
} else {
|
|
|
int days = DateUtils.dateDiff(startTime, endTime) + 1;
|
|
|
Integer lastStart = DateUtils.getDateInteger(DateUtils.getLastDay(startTime, days));
|
|
|
Integer lastEnd = DateUtils.getDateInteger(DateUtils.getLastDay(endTime, days));
|
|
|
+ PageHelper.startPage(pageNo, pageSize, false);
|
|
|
data = adqAdvertiserReportMapper.getProjectMoreDaysReport(projectId, startTimeInt, endTimeInt, lastStart, lastEnd, sortCode, order);
|
|
|
}
|
|
|
- PageInfo<JSONObject> page = new PageInfo<>();
|
|
|
- page.setList(data);
|
|
|
+ PageInfo<JSONObject> page = new PageInfo<>(data);
|
|
|
return Result.OK(page);
|
|
|
}
|
|
|
|
|
|
@@ -177,75 +178,6 @@ public class AdqAdvertiserReportServiceImpl implements IAdqAdvertiserReportServi
|
|
|
return Result.errorMsg("查询失败了。");
|
|
|
}
|
|
|
|
|
|
- private List<JSONObject> buildTodayProjectReport(String category, Long projectId, String startTime, Integer startTimeInt, Integer nowHour, String sortCode, String order) {
|
|
|
- List<JSONObject> baseRows = adqAdvertiserReportMapper.getProjectTodayBase(projectId, startTimeInt);
|
|
|
- if (baseRows == null || baseRows.isEmpty()) {
|
|
|
- return new ArrayList<>();
|
|
|
- }
|
|
|
- List<Long> projectIds = baseRows.stream()
|
|
|
- .map(item -> item.getLong("projectId"))
|
|
|
- .filter(id -> id != null)
|
|
|
- .collect(Collectors.toList());
|
|
|
- if (projectIds.isEmpty()) {
|
|
|
- return new ArrayList<>();
|
|
|
- }
|
|
|
-
|
|
|
- Integer yesterday = DateUtils.getDateInteger(DateUtils.getLastDay(startTime, 1));
|
|
|
- Map<Long, JSONObject> metaMap = toLongKeyMap(adqAdvertiserReportMapper.getProjectMetaByIds(projectIds));
|
|
|
- Map<Long, JSONObject> prevCostMap = toLongKeyMap(adqAdvertiserReportMapper.getProjectPrevHourlyCostByDayAndIds(yesterday, nowHour, projectIds));
|
|
|
-
|
|
|
- List<JSONObject> rows = new ArrayList<>();
|
|
|
- for (JSONObject baseRow : baseRows) {
|
|
|
- Long projectIdValue = baseRow.getLong("projectId");
|
|
|
- if (projectIdValue == null) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- JSONObject row = new JSONObject(new LinkedHashMap<>());
|
|
|
- JSONObject meta = metaMap.get(projectIdValue);
|
|
|
- JSONObject prevCost = prevCostMap.get(projectIdValue);
|
|
|
-
|
|
|
- double cost = getDouble(baseRow, "cost");
|
|
|
- double lastCost = getDouble(prevCost, "cost");
|
|
|
- row.put("projectId", projectIdValue);
|
|
|
- row.put("projectName", getString(meta, "projectName"));
|
|
|
- row.put("productName", getString(meta, "productName"));
|
|
|
- row.put("companyName", getString(baseRow, "companyName"));
|
|
|
- row.put("saler", getString(meta, "saler"));
|
|
|
- row.put("operater", getString(meta, "operater"));
|
|
|
- row.put("cost", cost);
|
|
|
- row.put("aclick", getLong(baseRow, "aclick"));
|
|
|
- row.put("bclick", getLong(baseRow, "bclick"));
|
|
|
- row.put("num", null);
|
|
|
- row.put("ssAd", "-");
|
|
|
- row.put("sxhAd", "-");
|
|
|
- row.put("lmAd", "-");
|
|
|
- row.put("xxlAd", "-");
|
|
|
- row.put("jlAd", "-");
|
|
|
- row.put("kpAd", "-");
|
|
|
- row.put("accountNum", getLong(baseRow, "accountNum"));
|
|
|
- row.put("operaterNum", getLong(baseRow, "operaterNum"));
|
|
|
- row.put("materialUploadMediaNum", null);
|
|
|
- if (lastCost == 0D) {
|
|
|
- row.put("rio", "-");
|
|
|
- row.put("rioValue", null);
|
|
|
- } else {
|
|
|
- double rioValue = new BigDecimal((cost - lastCost) / lastCost * 100)
|
|
|
- .setScale(2, BigDecimal.ROUND_HALF_UP)
|
|
|
- .doubleValue();
|
|
|
- row.put("rioValue", rioValue);
|
|
|
- row.put("rio", new BigDecimal(rioValue).setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "%");
|
|
|
- }
|
|
|
- rows.add(row);
|
|
|
- }
|
|
|
- if ("1".equals(category)) {
|
|
|
- rows = rows.stream()
|
|
|
- .filter(item -> item.getDouble("rioValue") != null && item.getDouble("rioValue") <= -10D)
|
|
|
- .collect(Collectors.toList());
|
|
|
- }
|
|
|
- sortProjectRows(rows, sortCode, order);
|
|
|
- return rows;
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public Result<Object> getOperateGroupInfo(String startTime, String endTime) {
|
|
|
try {
|
|
|
@@ -262,6 +194,7 @@ public class AdqAdvertiserReportServiceImpl implements IAdqAdvertiserReportServi
|
|
|
List<JSONObject> list = new ArrayList<>();
|
|
|
List<KuaiShouOperateGroupVo> operationManagerList = dashboardQuerySupport.getTencentOperationManagers();
|
|
|
List<String> managerIds = operationManagerList.stream().map(KuaiShouOperateGroupVo::getUserId).collect(Collectors.toList());
|
|
|
+ Map<String, String> managerNameMap = operationManagerList.stream().collect(Collectors.toMap(KuaiShouOperateGroupVo::getUserId, KuaiShouOperateGroupVo::getRealname, (left, right) -> left));
|
|
|
if (managerIds.isEmpty()) {
|
|
|
return Result.successMsg("查询成功。", new PageInfo<>(list));
|
|
|
}
|
|
|
@@ -270,15 +203,17 @@ public class AdqAdvertiserReportServiceImpl implements IAdqAdvertiserReportServi
|
|
|
if (allUserIds.isEmpty()) {
|
|
|
return Result.successMsg("查询成功。", new PageInfo<>(list));
|
|
|
}
|
|
|
- Map<String, JSONObject> currentMap;
|
|
|
- Map<String, JSONObject> previousMap;
|
|
|
+ CompletableFuture<Map<String, JSONObject>> currentFuture;
|
|
|
+ CompletableFuture<Map<String, JSONObject>> previousFuture;
|
|
|
if (startTime.equals(endTime) && startTime.equals(nowDateStr)) {
|
|
|
- currentMap = toMetricMap(adqAdvertiserReportMapper.getOperateGroupCurrentHourlyByUsers(hour, startDate, entDate, allUserIds));
|
|
|
- previousMap = toMetricMap(adqAdvertiserReportMapper.getOperateGroupPreviousHourlyByUsers(hour, lastTimeStart, lastTimeEnd, allUserIds));
|
|
|
+ currentFuture = CompletableFuture.supplyAsync(() -> toMetricMap(adqAdvertiserReportMapper.getOperateGroupCurrentHourlyByUsers(hour, startDate, entDate, allUserIds)));
|
|
|
+ previousFuture = CompletableFuture.supplyAsync(() -> toMetricMap(adqAdvertiserReportMapper.getOperateGroupPreviousHourlyByUsers(hour, lastTimeStart, lastTimeEnd, allUserIds)));
|
|
|
} else {
|
|
|
- currentMap = toMetricMap(adqAdvertiserReportMapper.getOperateGroupCurrentByUsers(startDate, entDate, allUserIds));
|
|
|
- previousMap = toMetricMap(adqAdvertiserReportMapper.getOperateGroupPreviousByUsers(lastTimeStart, lastTimeEnd, allUserIds));
|
|
|
+ currentFuture = CompletableFuture.supplyAsync(() -> toMetricMap(adqAdvertiserReportMapper.getOperateGroupCurrentByUsers(startDate, entDate, allUserIds)));
|
|
|
+ previousFuture = CompletableFuture.supplyAsync(() -> toMetricMap(adqAdvertiserReportMapper.getOperateGroupPreviousByUsers(lastTimeStart, lastTimeEnd, allUserIds)));
|
|
|
}
|
|
|
+ Map<String, JSONObject> currentMap = currentFuture.join();
|
|
|
+ Map<String, JSONObject> previousMap = previousFuture.join();
|
|
|
for (KuaiShouOperateGroupVo groupVo : operationManagerList) {
|
|
|
Set<String> memberIds = teamMembers.get(groupVo.getUserId());
|
|
|
if (memberIds == null || memberIds.isEmpty()) {
|
|
|
@@ -288,10 +223,10 @@ public class AdqAdvertiserReportServiceImpl implements IAdqAdvertiserReportServi
|
|
|
if (activeMemberIds.isEmpty()) {
|
|
|
continue;
|
|
|
}
|
|
|
- JSONObject vo = new JSONObject();
|
|
|
- vo.put("userId", groupVo.getUserId());
|
|
|
- vo.put("realname", groupVo.getRealname());
|
|
|
- vo.put("operationNum", activeMemberIds.size());
|
|
|
+ JSONObject row = new JSONObject();
|
|
|
+ row.put("userId", groupVo.getUserId());
|
|
|
+ row.put("realname", managerNameMap.get(groupVo.getUserId()));
|
|
|
+ row.put("operationNum", activeMemberIds.size());
|
|
|
long accountNum = 0L;
|
|
|
long projectNums = 0L;
|
|
|
double totalCost = 0D;
|
|
|
@@ -308,23 +243,16 @@ public class AdqAdvertiserReportServiceImpl implements IAdqAdvertiserReportServi
|
|
|
lastCost += getDouble(previous, "lastCost");
|
|
|
}
|
|
|
}
|
|
|
- vo.put("accountNum", accountNum);
|
|
|
- vo.put("projectNums", projectNums);
|
|
|
- vo.put("totalCost", totalCost);
|
|
|
- vo.put("lastCost", lastCost);
|
|
|
- if (lastCost == 0D) {
|
|
|
- vo.put("yearOnYearCost", "0%");
|
|
|
- } else {
|
|
|
- vo.put("yearOnYearCost", new BigDecimal((totalCost - lastCost) / lastCost * 100).setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "%");
|
|
|
- }
|
|
|
- Integer operationNum = vo.getInteger("operationNum");
|
|
|
- Double aveDay = totalCost / (days + 1);
|
|
|
- vo.put("averageDayCost", new BigDecimal(aveDay).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
|
- Double avePeople = operationNum == 0 ? 0D : totalCost / operationNum;
|
|
|
- vo.put("averagePeopleCost", new BigDecimal(avePeople).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
|
- Double aveAccount = accountNum == 0 ? 0D : totalCost / accountNum;
|
|
|
- vo.put("averageAccountCost", new BigDecimal(aveAccount).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
|
- list.add(vo);
|
|
|
+ int operationNum = activeMemberIds.size();
|
|
|
+ row.put("accountNum", accountNum);
|
|
|
+ row.put("projectNums", projectNums);
|
|
|
+ row.put("totalCost", totalCost);
|
|
|
+ row.put("lastCost", lastCost);
|
|
|
+ row.put("yearOnYearCost", lastCost == 0D ? "0%" : new BigDecimal((totalCost - lastCost) / lastCost * 100).setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "%");
|
|
|
+ row.put("averageDayCost", new BigDecimal(totalCost / (days + 1)).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
|
+ row.put("averagePeopleCost", new BigDecimal(operationNum == 0 ? 0D : totalCost / operationNum).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
|
+ row.put("averageAccountCost", new BigDecimal(accountNum == 0 ? 0D : totalCost / accountNum).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
|
+ list.add(row);
|
|
|
}
|
|
|
if (!Check.isNull(list)) {
|
|
|
Collections.sort(list, new Comparator<JSONObject>() {
|
|
|
@@ -351,15 +279,6 @@ public class AdqAdvertiserReportServiceImpl implements IAdqAdvertiserReportServi
|
|
|
.collect(Collectors.toMap(item -> item.getString("userId"), item -> item, (left, right) -> left));
|
|
|
}
|
|
|
|
|
|
- private Map<Long, JSONObject> toLongKeyMap(List<JSONObject> rows) {
|
|
|
- if (rows == null || rows.isEmpty()) {
|
|
|
- return Collections.emptyMap();
|
|
|
- }
|
|
|
- return rows.stream()
|
|
|
- .filter(item -> item != null && item.getLong("projectId") != null)
|
|
|
- .collect(Collectors.toMap(item -> item.getLong("projectId"), item -> item, (left, right) -> left));
|
|
|
- }
|
|
|
-
|
|
|
private void sortProjectRows(List<JSONObject> rows, String sortCode, String order) {
|
|
|
if (rows == null || rows.isEmpty()) {
|
|
|
return;
|