|
@@ -21,6 +21,7 @@ import org.jeecg.modules.system.service.ISysRoleService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
@@ -29,12 +30,13 @@ import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.text.ParseException;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
public class MaterialReportOverViewServiceImpl implements IMaterialReportOverViewService {
|
|
|
|
|
|
- @Autowired
|
|
|
+ @Resource
|
|
|
private MaterialReportOverViewMapper materialReportOverViewMapper;
|
|
|
|
|
|
@Autowired
|
|
@@ -88,27 +90,149 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
|
|
|
projects = getProjectsByCurrentUser(mediaId);
|
|
|
}
|
|
|
if (mediaId == CtopAdConstant.PLATFORM_TYPE_BYTEDANCE_INT) {
|
|
|
+ //总消耗
|
|
|
BigDecimal cost = materialReportOverViewMapper.queryBytedanceCost(startDate, endDate, projects);
|
|
|
+ //上阶段消耗
|
|
|
BigDecimal lastCost = materialReportOverViewMapper.queryBytedanceCost(DateUtils.addDay(startDate, -DateUtils.dateDiff(startDate, endDate)-1), DateUtils.addDay(startDate, -1), projects);
|
|
|
- result.put("cost", cost);
|
|
|
- result.put("costLink", countLink(cost == null ? BigDecimal.ZERO : cost, lastCost == null ? BigDecimal.ZERO : lastCost));
|
|
|
- result.put("video", materialReportOverViewMapper.queryMaterialCount(startDate, endDate, projects));
|
|
|
- result.put("newVideo", materialReportOverViewMapper.queryNewMaterialCount(DateUtils.date2Str(), projects));
|
|
|
- result.put("hot", 0);
|
|
|
- result.put("valid", 0);
|
|
|
+ result.put("costTotal", cost);
|
|
|
+ //同比 (本阶段截止昨天消耗-上一个阶段截止和昨天对应日期的消耗)/上一个阶段截止和昨天对应日期的消耗 X 100%
|
|
|
+ result.put("yearOnYearCompare", countLink(cost,lastCost));
|
|
|
+ //昨日消耗
|
|
|
+ BigDecimal yesterdayCost = materialReportOverViewMapper.queryBytedanceCost(endDate, endDate, projects);
|
|
|
+ //前天消耗
|
|
|
+ BigDecimal beforeYesterdayCost = materialReportOverViewMapper.queryBytedanceCost(DateUtils.addDay(endDate, -1), DateUtils.addDay(endDate, -1), projects);
|
|
|
+ result.put("yesterdayCost", yesterdayCost);
|
|
|
+ //环比 (昨日消耗-前日消耗)/前日消耗 X 100%
|
|
|
+ result.put("chainCompare", countLink(yesterdayCost,beforeYesterdayCost));
|
|
|
+
|
|
|
} else if (mediaId == CtopAdConstant.PLATFORM_TYPE_KUAISHOU_INT) {
|
|
|
+ //总消耗
|
|
|
BigDecimal cost = materialReportOverViewMapper.queryKuaishouCost(startDate, endDate, projects);
|
|
|
+ //上阶段
|
|
|
BigDecimal lastCost = materialReportOverViewMapper.queryKuaishouCost(DateUtils.addDay(startDate, -DateUtils.dateDiff(startDate, endDate)-1), DateUtils.addDay(startDate, -1), projects);
|
|
|
- result.put("cost", cost);
|
|
|
- result.put("costLink", countLink(cost == null ? BigDecimal.ZERO : cost, lastCost == null ? BigDecimal.ZERO : lastCost));
|
|
|
- result.put("video", materialReportOverViewMapper.queryMaterialCount(startDate, endDate, projects));
|
|
|
- result.put("newVideo", materialReportOverViewMapper.queryNewMaterialCount(DateUtils.date2Str(), projects));
|
|
|
- result.put("hot", 0);
|
|
|
- result.put("valid", 0);
|
|
|
+ result.put("costTotal", cost);
|
|
|
+ //同比 (本阶段截止昨天消耗-上一个阶段截止和昨天对应日期的消耗)/上一个阶段截止和昨天对应日期的消耗 X 100%
|
|
|
+ result.put("yearOnYearCompare", countLink(cost,lastCost));
|
|
|
+ //昨日消耗
|
|
|
+ BigDecimal yesterdayCost = materialReportOverViewMapper.queryKuaishouCost(endDate, endDate, projects);
|
|
|
+ //前天消耗
|
|
|
+ BigDecimal beforeYesterdayCost = materialReportOverViewMapper.queryKuaishouCost(DateUtils.addDay(endDate, -1), DateUtils.addDay(endDate, -1), projects);
|
|
|
+ result.put("yesterdayCost", yesterdayCost);
|
|
|
+ //环比 (昨日消耗-前日消耗)/前日消耗 X 100%
|
|
|
+ result.put("chainCompare", countLink(yesterdayCost,beforeYesterdayCost));
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> sumDataVideoNewEffective(int mediaId, String startDate, String endDate, JSONArray projects) {
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ if (projects.isEmpty()) {
|
|
|
+ projects = getProjectsByCurrentUser(mediaId);
|
|
|
+ }
|
|
|
+ if (mediaId == CtopAdConstant.PLATFORM_TYPE_BYTEDANCE_INT) {
|
|
|
+ //视频上新
|
|
|
+ List<Map<String, String>> videoList = materialReportOverViewMapper.queryMaterialCountList(startDate+" 00:00:00", endDate+" 23:59:59", projects);
|
|
|
+ //总数
|
|
|
+ long videoTotal = videoList.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
|
|
|
+ result.put("videoList",videoList);
|
|
|
+ result.put("videoTotal",videoTotal);
|
|
|
+ //素材使用率 = 有消耗的素材 / 总数 * 100%
|
|
|
+ long videoCost = materialReportOverViewMapper.queryMaterialCostList(startDate+" 00:00:00", endDate+" 23:59:59", projects);
|
|
|
+ result.put("useCompare", Check.isNull(videoCost) ? 0: new BigDecimal(videoCost).divide(new BigDecimal(videoTotal),4, RoundingMode.HALF_UP));
|
|
|
+ //有效视频
|
|
|
+ List<Map<String, String>> effectiveList = materialReportOverViewMapper.selectEffectiveMaterialVideoBytedance(startDate,endDate, projects);
|
|
|
+ //总数
|
|
|
+ long effectiveTotal = effectiveList.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
|
|
|
+ result.put("effectiveList",effectiveList);
|
|
|
+ result.put("effectiveTotal",effectiveTotal);
|
|
|
+ //素材有效率 = 有效视频数量 / 视频总数 X 100%
|
|
|
+ result.put("effectiveCompare",Check.isNull(videoCost) ? 0: new BigDecimal(effectiveTotal).divide(new BigDecimal(videoTotal),4, RoundingMode.HALF_UP));
|
|
|
+
|
|
|
+ } else if (mediaId == CtopAdConstant.PLATFORM_TYPE_KUAISHOU_INT) {
|
|
|
+
|
|
|
+ //视频上新
|
|
|
+ List<Map<String, String>> videoList = materialReportOverViewMapper.queryMaterialCountListKs(startDate+" 00:00:00", endDate+" 23:59:59", projects);
|
|
|
+ //总数
|
|
|
+ long videoTotal = videoList.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
|
|
|
+ result.put("videoList",videoList);
|
|
|
+ result.put("videoTotal",videoTotal);
|
|
|
+ //素材使用率 = 有消耗的素材 / 总数 * 100%
|
|
|
+ long videoCost = materialReportOverViewMapper.queryMaterialCostListKs(startDate+" 00:00:00", endDate+" 23:59:59", projects);
|
|
|
+ result.put("useCompare", Check.isNull(videoCost) ? 0: new BigDecimal(videoCost).divide(new BigDecimal(videoTotal),4, RoundingMode.HALF_UP));
|
|
|
+ //有效视频
|
|
|
+ List<Map<String, String>> effectiveList = materialReportOverViewMapper.selectEffectiveMaterialVideoKs(startDate,endDate, projects);
|
|
|
+ //总数
|
|
|
+ long effectiveTotal = effectiveList.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
|
|
|
+ result.put("effectiveList",effectiveList);
|
|
|
+ result.put("effectiveTotal",effectiveTotal);
|
|
|
+ //素材有效率 = 有效视频数量 / 视频总数 X 100%
|
|
|
+ result.put("effectiveCompare",Check.isNull(videoTotal) ? 0 : new BigDecimal(effectiveTotal).divide(new BigDecimal(videoTotal),4, RoundingMode.HALF_UP));
|
|
|
+
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ //爆款视频
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> sumDataVideoHot(int mediaId, String startDate, String endDate, JSONArray projects) {
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ if (projects.isEmpty()) {
|
|
|
+ projects = getProjectsByCurrentUser(mediaId);
|
|
|
+ }
|
|
|
+ if (mediaId == CtopAdConstant.PLATFORM_TYPE_BYTEDANCE_INT) {
|
|
|
+ //爆款视频
|
|
|
+ List<Map<String, String>> hotList = materialReportOverViewMapper.selectHotMaterialVideoBytedance(startDate,endDate, projects);
|
|
|
+ //总数
|
|
|
+ long hotTotal = hotList.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
|
|
|
+ result.put("hotList",hotList);
|
|
|
+ result.put("hotTotal",hotTotal);
|
|
|
+ //上阶段
|
|
|
+ List<Map<String, String>> lastHostList = materialReportOverViewMapper.selectHotMaterialVideoBytedance(DateUtils.addDay(startDate, -DateUtils.dateDiff(startDate, endDate)-1), DateUtils.addDay(startDate, -1), projects);
|
|
|
+ long lastHotTotal = lastHostList.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
|
|
|
+ //同比 (本阶段截止昨天的爆款视频数量-上一个阶段截止和昨天对应日期的爆款视频数量)/上一个阶段截止和昨天对应日期的爆款视频数量X 100%
|
|
|
+ result.put("hotYearOnYearCompare", countLink(new BigDecimal(hotTotal),new BigDecimal(lastHotTotal)));
|
|
|
+ //昨日消耗
|
|
|
+ List<Map<String, String>> yesterdayHost = materialReportOverViewMapper.selectHotMaterialVideoBytedance(endDate,endDate, projects);
|
|
|
+ //前天消耗
|
|
|
+ List<Map<String, String>> beforeYesterdayHost = materialReportOverViewMapper.selectHotMaterialVideoBytedance(DateUtils.addDay(endDate, -1), DateUtils.addDay(endDate, -1), projects);
|
|
|
+ long yesterday = yesterdayHost.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
|
|
|
+ long before = beforeYesterdayHost.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
|
|
|
+ //环比 (昨日-前日)/前日消耗 X 100%
|
|
|
+ result.put("hostCompare", countLink(new BigDecimal(yesterday),new BigDecimal(before)));
|
|
|
+
|
|
|
+ } else if (mediaId == CtopAdConstant.PLATFORM_TYPE_KUAISHOU_INT) {
|
|
|
+ //爆款视频
|
|
|
+ List<Map<String, String>> hotList = materialReportOverViewMapper.selectHotMaterialVideoKs(startDate,endDate, projects);
|
|
|
+ //总数
|
|
|
+ long hotTotal = hotList.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
|
|
|
+ result.put("hotList",hotList);
|
|
|
+ result.put("hotTotal",hotTotal);
|
|
|
+ //上阶段
|
|
|
+ List<Map<String, String>> lastHostList = materialReportOverViewMapper.selectHotMaterialVideoKs(DateUtils.addDay(startDate, -DateUtils.dateDiff(startDate, endDate)-1), DateUtils.addDay(startDate, -1), projects);
|
|
|
+ long lastHotTotal = lastHostList.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
|
|
|
+ //同比 (本阶段截止昨天的爆款视频数量-上一个阶段截止和昨天对应日期的爆款视频数量)/上一个阶段截止和昨天对应日期的爆款视频数量X 100%
|
|
|
+ result.put("hotYearOnYearCompare", countLink(new BigDecimal(hotTotal),new BigDecimal(lastHotTotal)));
|
|
|
+ //昨日消耗
|
|
|
+ List<Map<String, String>> yesterdayHost = materialReportOverViewMapper.selectHotMaterialVideoKs(endDate,endDate, projects);
|
|
|
+ //前天消耗
|
|
|
+ List<Map<String, String>> beforeYesterdayHost = materialReportOverViewMapper.selectHotMaterialVideoKs(DateUtils.addDay(endDate, -1), DateUtils.addDay(endDate, -1), projects);
|
|
|
+ long yesterday = yesterdayHost.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
|
|
|
+ long before = beforeYesterdayHost.stream().collect(Collectors.summarizingInt(s->Integer.valueOf(String.valueOf(s.get("count"))))).getSum();
|
|
|
+ //环比 (昨日-前日)/前日消耗 X 100%
|
|
|
+ result.put("hostCompare", countLink(new BigDecimal(yesterday),new BigDecimal(before)));
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public List<JSONObject> getTotalChat(int mediaId, String startDate, String endDate, JSONArray projects) {
|
|
|
List<JSONObject> result = new ArrayList<>();
|
|
@@ -141,7 +265,7 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<JSONObject> getTopMaterialList(int mediaId, String startDate, String endDate, JSONArray projects) {
|
|
|
+ public List<JSONObject> getTopMaterialList(int mediaId, String startDate, String endDate, JSONArray projects, Integer channelType) {
|
|
|
List<JSONObject> result = new ArrayList<>();
|
|
|
if (projects.isEmpty()) {
|
|
|
projects = getProjectsByCurrentUser(mediaId);
|
|
@@ -150,7 +274,7 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
|
|
|
result = materialReportOverViewMapper.queryBytedanceTopMaterial(startDate, endDate, projects);
|
|
|
|
|
|
} else if (mediaId == CtopAdConstant.PLATFORM_TYPE_KUAISHOU_INT) {
|
|
|
- result = materialReportOverViewMapper.queryKuaishouTopMaterial(startDate, endDate, projects);
|
|
|
+ result = materialReportOverViewMapper.queryKuaishouTopMaterial(startDate, endDate, projects, channelType);
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
@@ -284,17 +408,17 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public PageInfo<JSONObject> getTopDesignList(String startDate, String endDate, String userId, String target, String order, int pageSize, int pageNo) {
|
|
|
- PageInfo<JSONObject> result = new PageInfo<>();
|
|
|
- Set<String> subordinate = this.recursiveQuerySubordinate(userId);
|
|
|
- if (subordinate.size()==1) {
|
|
|
- subordinate = materialReportOverViewMapper.recursiveQuerySubordinateByUserId(userId);
|
|
|
- }
|
|
|
- PageHelper.startPage(pageNo, pageSize, false);
|
|
|
- List<JSONObject> topDesign = materialReportOverViewMapper.queryTopDesign(startDate, endDate, subordinate, target, order);
|
|
|
- Long count = materialReportOverViewMapper.queryTopDesignCount(startDate, endDate, subordinate);
|
|
|
- result.setList(topDesign);
|
|
|
- result.setTotal(count);
|
|
|
+ public List<JSONObject> getTopDesignList(Integer mediaId, String startDate, String endDate, JSONArray projects, String type) {
|
|
|
+ List<JSONObject> result = new ArrayList<>();
|
|
|
+ if (projects.isEmpty()) {
|
|
|
+ projects = getProjectsByCurrentUser(mediaId);
|
|
|
+ }
|
|
|
+ if (mediaId == CtopAdConstant.PLATFORM_TYPE_BYTEDANCE_INT) {
|
|
|
+ result = materialReportOverViewMapper.queryBytedanceTopDesign(startDate, endDate, projects, type);
|
|
|
+
|
|
|
+ } else if (mediaId == CtopAdConstant.PLATFORM_TYPE_KUAISHOU_INT) {
|
|
|
+ result = materialReportOverViewMapper.queryKuaishouTopDesign(startDate, endDate, projects, type);
|
|
|
+ }
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -361,6 +485,7 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
|
|
|
//当项目为空的时候,根据当前登录人查询可查看的所有项目集合
|
|
|
private JSONArray getProjectsByCurrentUser(int mediaId) {
|
|
|
String currentUser = ((LoginUser) SecurityUtils.getSubject().getPrincipal()).getId();
|
|
|
+ //String currentUser = "e9ca23d68d884d4ebb19d07889727dae";
|
|
|
//TODO 为了解决管理员等角色初始化查全部项目查询效率慢的问题判断角色,待优化
|
|
|
String roleCode = roleService.getRoleCodeByUserId(currentUser);
|
|
|
if (roleCode.equals("admin")) {
|
|
@@ -386,11 +511,31 @@ public class MaterialReportOverViewServiceImpl implements IMaterialReportOverVie
|
|
|
|
|
|
//环比计算
|
|
|
private BigDecimal countLink(BigDecimal numA, BigDecimal numB) {
|
|
|
- BigDecimal link = new BigDecimal(0);
|
|
|
+ BigDecimal link = new BigDecimal("0");
|
|
|
+ if (Check.isNull(numA) || Check.isNull(numB)){
|
|
|
+ return link;
|
|
|
+ }
|
|
|
if (numB.compareTo(BigDecimal.ZERO)!=0) {
|
|
|
link = (numA.subtract(numB)).divide(numB, 4, RoundingMode.HALF_UP);
|
|
|
}
|
|
|
return link;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 同比 (当前 - 上阶段 ) / 上阶段
|
|
|
+ * @param current 当前阶段数值
|
|
|
+ * @param last 上阶段数值
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private BigDecimal yearOnYearCompare(BigDecimal current,BigDecimal last){
|
|
|
+ BigDecimal yearOnYear = new BigDecimal("0");
|
|
|
+ if (last.compareTo(BigDecimal.ZERO)!=0) {
|
|
|
+ // (当前 - 上阶段 ) / 上阶段
|
|
|
+ yearOnYear = (current.subtract(last)).divide(last,20,BigDecimal.ROUND_HALF_UP);
|
|
|
+ }
|
|
|
+ return yearOnYear;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|