|
@@ -1,18 +1,36 @@
|
|
|
package org.jeecg.ctop.material.service.impl;
|
|
|
|
|
|
|
|
|
+import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
|
|
+import cn.afterturn.easypoi.excel.entity.ExportParams;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
+import com.google.gson.JsonObject;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
+import org.jeecg.common.util.DateUtils;
|
|
|
+import org.jeecg.ctop.material.constants.Check;
|
|
|
import org.jeecg.ctop.material.constants.CtopAdConstant;
|
|
|
+import org.jeecg.ctop.material.entity.vo.KuaiShouAccountPieVo;
|
|
|
+import org.jeecg.ctop.material.entity.vo.KuaiShouOperateAccountVo;
|
|
|
+import org.jeecg.ctop.material.entity.vo.KuaiShouOperateProjectVo;
|
|
|
+import org.jeecg.ctop.material.entity.vo.KuaiShouOperateVo;
|
|
|
import org.jeecg.ctop.material.mapper.MaterialStareMapper;
|
|
|
import org.jeecg.ctop.material.service.MaterialStareService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.text.DecimalFormat;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 盯盘接口
|
|
@@ -25,103 +43,83 @@ public class MaterialStareServiceImpl implements MaterialStareService {
|
|
|
MaterialStareMapper materialStareMapper;
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
- * 数据总览
|
|
|
+ *
|
|
|
+ * @description:数据总览-快手
|
|
|
+ *
|
|
|
+ * @param mediaType 媒体类型 1-头条 2-快手
|
|
|
+ * @param type 查询类型 1-汇总 2-运营个人
|
|
|
+ * @param userId
|
|
|
+ * @param startTime
|
|
|
+ * @param startTime
|
|
|
+ * @author: zianY
|
|
|
+ * @time: 2022/2/15
|
|
|
*/
|
|
|
@Override
|
|
|
- public Result<JSONObject> sumData(Integer mediaId, Integer userType, String userId, String startDate, String endDate, Integer type) {
|
|
|
- Result result = new Result();
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
|
|
- Long start = Long.parseLong(startDate.replace("-", ""));
|
|
|
- Long end = Long.parseLong(endDate.replace("-", ""));
|
|
|
-
|
|
|
- if (mediaId == CtopAdConstant.PLATFORM_TYPE_BYTEDANCE_INT) {
|
|
|
- //头条
|
|
|
- //功能待完善
|
|
|
- } else if (mediaId == CtopAdConstant.PLATFORM_TYPE_KUAISHOU_INT) {
|
|
|
- //快手
|
|
|
- if (userType == 1) { //运营经理界面
|
|
|
- //查询当前人员所有下级
|
|
|
- Set<String> operatorUserIds = getAffiliateId(userId);
|
|
|
- if (type == 1) { //汇总查看
|
|
|
- if (start.equals(end)) { //查看当日
|
|
|
- Long beforeDay = dayBefore(start);
|
|
|
- //查询账户时报表当日数据
|
|
|
- List<Map> list = materialStareMapper.getCostByUserIdList(start, beforeDay, operatorUserIds);
|
|
|
- result.setResult(list);
|
|
|
- result.setSuccess(true);
|
|
|
- return result;
|
|
|
- } else { //查看多日
|
|
|
- //查询账户日报表当日数据
|
|
|
- List<Map> list = materialStareMapper.getCostByUserIdListMoreDay(start, end, operatorUserIds);
|
|
|
- result.setResult(list);
|
|
|
- result.setSuccess(true);
|
|
|
- return result;
|
|
|
- }
|
|
|
+ public Result kuaiShousumData(String mediaType, String type, String startTime, String endTime, String userId) {
|
|
|
+ long stratDate = DateUtils.getDateInteger(startTime);
|
|
|
+ long endDate = DateUtils.getDateInteger(endTime);
|
|
|
+ //查询当前人员所有下级
|
|
|
+ Set<String> operatorUserIds = getAffiliateId(userId);
|
|
|
+ //头条
|
|
|
+ if (StringUtils.equals(mediaType,"1")){
|
|
|
+ return Result.successMsg("暂无头条数据。",null);
|
|
|
+ }
|
|
|
+ //快手
|
|
|
+ if (StringUtils.equals(mediaType,"2")){
|
|
|
+ //汇总
|
|
|
+ if (StringUtils.equals(type,"1")){
|
|
|
+ //查询一天数据时 查询时报
|
|
|
+ if (stratDate == endDate){
|
|
|
+ Map resultMap = new HashMap<>();
|
|
|
+ //时报
|
|
|
+ List<Map> todayList = materialStareMapper.getKuaiShouCostHourlyByUserIdList(stratDate, endDate, operatorUserIds);
|
|
|
+ long time = DateUtils.getDateInteger(DateUtils.addDayParse(Long.toString(endDate), -1));
|
|
|
+ List<Map> yesterdayList = materialStareMapper.getKuaiShouCostHourlyByUserIdList(time,time , operatorUserIds);
|
|
|
+ resultMap.put("todayList",todayList);
|
|
|
+ resultMap.put("yesterdayList",yesterdayList);
|
|
|
+ return Result.successMsg("查询-时报-汇总。",resultMap);
|
|
|
+ }
|
|
|
+ //多天 数据
|
|
|
+ // 日报
|
|
|
+ List<Map> dailyList = materialStareMapper.getKuaiShouCostDailyByUserIdList(stratDate, endDate, operatorUserIds);
|
|
|
+ return Result.successMsg("查询-日报-汇总成功。",dailyList);
|
|
|
|
|
|
- } else if (type == 2) { //运营个人查看
|
|
|
- if (start.equals(end)) { //查看当日
|
|
|
- //查询个人top5当日时报
|
|
|
- List<JSONObject> resultList = new ArrayList<>();
|
|
|
- List<JSONObject> list = materialStareMapper.getCostByTop5List(start, operatorUserIds);
|
|
|
- int size = 0;
|
|
|
- int firstHour = list.get(0).getInteger("hour");
|
|
|
- //判断每个小时取出几条
|
|
|
- for (JSONObject jsonObject : list) {
|
|
|
- //判断每个小时取出几条
|
|
|
- Integer hour = jsonObject.getInteger("hour");
|
|
|
- if (hour == firstHour) {
|
|
|
- size++;
|
|
|
- }
|
|
|
- }
|
|
|
- for (int i = 0; i < list.size() / size; i++) {
|
|
|
- //没top条数据切割出来封装
|
|
|
- List<JSONObject> objects = list.subList(i * size, (i + 1) * size);
|
|
|
- JSONObject resultObj = new JSONObject();
|
|
|
- int j = 1;
|
|
|
- for (JSONObject object : objects) {
|
|
|
- resultObj.put("hours", object.getInteger("hour"));
|
|
|
- resultObj.put("top" + j, object.getBigDecimal("cost"));
|
|
|
- j++;
|
|
|
- }
|
|
|
- resultList.add(resultObj);
|
|
|
- }
|
|
|
- result.setResult(resultList);
|
|
|
- result.setSuccess(true);
|
|
|
- return result;
|
|
|
- } else { //查看多日
|
|
|
- List<JSONObject> resultList = new ArrayList<>();
|
|
|
- //查询个人top5当日日报
|
|
|
- List<JSONObject> list = materialStareMapper.getCostByTop5ListMoreDay(start, end, operatorUserIds);
|
|
|
- int size = 0;
|
|
|
- int firstDate = list.get(0).getInteger("statDate");
|
|
|
- //判断每个小时取出几条
|
|
|
- for (JSONObject jsonObject : list) {
|
|
|
- //判断每个小时取出几条
|
|
|
- Integer hour = jsonObject.getInteger("statDate");
|
|
|
- if (hour == firstDate) {
|
|
|
- size++;
|
|
|
- }
|
|
|
- }
|
|
|
- for (int i = 0; i < list.size() / size; i++) {
|
|
|
- //没top条数据切割出来封装
|
|
|
- List<JSONObject> objects = list.subList(i * size, (i + 1) * size);
|
|
|
- JSONObject resultObj = new JSONObject();
|
|
|
- int j = 1;
|
|
|
- for (JSONObject object : objects) {
|
|
|
- resultObj.put("date", object.getInteger("statDate"));
|
|
|
- resultObj.put("top" + j, object.getBigDecimal("cost"));
|
|
|
- j++;
|
|
|
- }
|
|
|
- resultList.add(resultObj);
|
|
|
- }
|
|
|
- result.setResult(resultList);
|
|
|
- result.setSuccess(true);
|
|
|
- return result;
|
|
|
+ //运营个人
|
|
|
+ }else if (StringUtils.equals(type,"2")){
|
|
|
+ if (stratDate == endDate){
|
|
|
+ //时报 消耗前5
|
|
|
+ List<JSONObject> userList = materialStareMapper.getKuaiShouCostByTop5HourList(stratDate, endDate, operatorUserIds);
|
|
|
+ List<Map> resultList = new ArrayList<>();
|
|
|
+ for (JSONObject jsonObject : userList) {
|
|
|
+ Map map = new HashMap();
|
|
|
+ Set<String> userSet = new HashSet<String>(){{
|
|
|
+ add(jsonObject.getString("user_id"));
|
|
|
+ }};
|
|
|
+ List<Map> usertopList = materialStareMapper.getKuaiShouCostHourlyByUserIdList(stratDate, endDate, userSet);
|
|
|
+ map.put("userName",jsonObject.getString("userName"));
|
|
|
+ map.put("data",usertopList);
|
|
|
+ resultList.add(map);
|
|
|
}
|
|
|
+ return Result.successMsg("查询-时报-运营个人消耗top5成功。",resultList);
|
|
|
+ }
|
|
|
+
|
|
|
+ //日报 消耗前5
|
|
|
+ List<JSONObject> userList = materialStareMapper.getKuaiShouCostByTop5DailyList(stratDate,endDate, operatorUserIds);
|
|
|
+ List<Map> resultList = new ArrayList<>();
|
|
|
+ for (JSONObject jsonObject : userList) {
|
|
|
+ Map map = new HashMap();
|
|
|
+ Set<String> userSet = new HashSet<String>(){{
|
|
|
+ add(jsonObject.getString("user_id"));
|
|
|
+ }};
|
|
|
+ List<Map> usertopList = materialStareMapper.getKuaiShouCostDailyByUserIdList(stratDate, endDate, userSet);
|
|
|
+ map.put("userName",jsonObject.getString("userName"));
|
|
|
+ map.put("data",usertopList);
|
|
|
+ resultList.add(map);
|
|
|
}
|
|
|
- } else if (userType == 2) {
|
|
|
- //运营个人界面
|
|
|
+ return Result.successMsg("查询-日报-运营个人消耗top5成功。",resultList);
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
@@ -129,50 +127,461 @@ public class MaterialStareServiceImpl implements MaterialStareService {
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 获取指定日期前一日 LONG类型
|
|
|
+ *
|
|
|
+ * @description: 快手-运营组数据
|
|
|
+ *
|
|
|
+ * @param mediaType 媒体类型 1-头条 2-快手
|
|
|
+ * @param startTime
|
|
|
+ * @param endTime
|
|
|
+ * @param userId
|
|
|
+ * @return: org.jeecg.common.api.vo.Result
|
|
|
+ * @author: zianY
|
|
|
+ * @time: 2022/2/15
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result kuaiShouOperateDateTotal(String mediaType, String startTime, String endTime, String userId) {
|
|
|
+ Map resultMap = new HashMap();
|
|
|
+ DecimalFormat decimalFormat = new DecimalFormat("0.00%");
|
|
|
+ try {
|
|
|
+ //查询当前人员所有下级
|
|
|
+ Set<String> operatorUserIds = getAffiliateId(userId);
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
|
|
+ // ==>> 20220202
|
|
|
+ String now = sdf.format(new Date());
|
|
|
+ long nowDate = Long.valueOf(now);
|
|
|
+ int nowHour = DateUtils.getNowHour();
|
|
|
+ //昨天时间
|
|
|
+ long time = DateUtils.getDateInteger(DateUtils.addDayParse(now, -1));
|
|
|
+
|
|
|
+ //当天总消耗
|
|
|
+ JSONObject jsonObjectNow = materialStareMapper.getKuaiShouTotalCost(nowDate,nowDate,nowHour,operatorUserIds);
|
|
|
+ resultMap.put("todayCost",jsonObjectNow.getString("totalCost"));
|
|
|
+ //昨天总消耗
|
|
|
+ JSONObject jsonObjectYesterday = materialStareMapper.getKuaiShouTotalCost(time,time,nowHour,operatorUserIds);
|
|
|
+ //今日同比 = (今天总消耗 - 昨天总消耗 ) / 昨天总消耗
|
|
|
+ Double d = (Double.valueOf(jsonObjectNow.getString("totalCost")) - Double.valueOf(jsonObjectYesterday.getString("totalCost"))) / Double.valueOf(jsonObjectYesterday.getString("totalCost"));
|
|
|
+ resultMap.put("compare",decimalFormat.format(d));
|
|
|
+
|
|
|
+ //时间段内 总消耗 及 账户数量
|
|
|
+ JSONObject totalCost = materialStareMapper.getKuaiShouTotalCost(Long.valueOf(DateUtils.getDateInteger(startTime)),
|
|
|
+ Long.valueOf(DateUtils.getDateInteger(endTime)),
|
|
|
+ 0,
|
|
|
+ operatorUserIds);
|
|
|
+ resultMap.put("sectionCost",totalCost.getDoubleValue("totalCost"));
|
|
|
+ // 人均账户数量 = 时间段内 账户总数量 / 人数
|
|
|
+ Double userAverageAccount = Double.valueOf(totalCost.getString("accountNum")) / operatorUserIds.size();
|
|
|
+ // 人均消耗 = 时间段内 总消耗 / 人数
|
|
|
+ Double userAveragecost = Double.valueOf(totalCost.getString("totalCost")) / operatorUserIds.size();
|
|
|
+ DecimalFormat df = new DecimalFormat("#.00");
|
|
|
+ resultMap.put("userAverageAccount",df.format(userAverageAccount));
|
|
|
+ resultMap.put("userAveragecost",df.format(userAveragecost));
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return Result.successMsg("查询成功",resultMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @description: 运营数据详情
|
|
|
+ *
|
|
|
+ * @param pageNum
|
|
|
+ * @param pageSize
|
|
|
+ * @param startTime
|
|
|
+ * @param endTime
|
|
|
+ * @param userId
|
|
|
+ * @return: org.jeecg.common.api.vo.Result
|
|
|
+ * @author: zianY
|
|
|
+ * @time: 2022/2/16
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result getKuaiShouOperateInfo(Integer pageNum, int pageSize, String startTime, String endTime, String userId) {
|
|
|
+ try {
|
|
|
+ //查询当前人员所有下级
|
|
|
+ Set<String> operatorUserIds = getAffiliateId(userId);
|
|
|
+ //2022-02-15 ==>> 20220215
|
|
|
+ long startDate = Long.valueOf(DateUtils.getDateInteger(startTime));
|
|
|
+ long entDate = Long.valueOf(DateUtils.getDateInteger(endTime));
|
|
|
+ //上阶段时间
|
|
|
+ Map<String,String> lastTime = DateUtils.getStartEndTime(startTime,endTime);
|
|
|
+ long lastTimeStart = Long.valueOf(DateUtils.getDateInteger(lastTime.get("lastTimeStart")));
|
|
|
+ long lastTimeEnd = Long.valueOf(DateUtils.getDateInteger(lastTime.get("lastTimeEnd")));
|
|
|
+
|
|
|
+ PageHelper.startPage(pageNum,pageSize);
|
|
|
+ //查询运营数据
|
|
|
+ List<KuaiShouOperateVo> listOperate = materialStareMapper.getKuaiShouOperateInfo(startDate,entDate,operatorUserIds);
|
|
|
+ for (KuaiShouOperateVo operate : listOperate) {
|
|
|
+ Set<String> userSet = new HashSet<String>(){{
|
|
|
+ add(operate.getUserId());
|
|
|
+ }};
|
|
|
+ List<KuaiShouOperateVo> userOperate = materialStareMapper.getKuaiShouOperateInfo(lastTimeStart,lastTimeEnd,userSet);
|
|
|
+ Double rate = new Double(0);
|
|
|
+ if (!Check.isNull(userOperate)){
|
|
|
+ //环比
|
|
|
+ rate = (operate.getTotalCost() - userOperate.get(0).getTotalCost()) / userOperate.get(0).getTotalCost() * 100;
|
|
|
+ rate = Double.valueOf(String.format("%.3f", rate));
|
|
|
+ }
|
|
|
+ operate.setRate(rate);
|
|
|
+ }
|
|
|
+ PageInfo<KuaiShouOperateVo> pageInfo = new PageInfo<>(listOperate);
|
|
|
+ return Result.successMsg("运营数据查询成功。",pageInfo);
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return Result.errorMsg("哎呀,查询失败了。");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result exportKuaiShouOperateInfo(String startTime, String endTime, String userId, HttpServletResponse response) {
|
|
|
+ try {
|
|
|
+ //查询当前人员所有下级
|
|
|
+ Set<String> operatorUserIds = getAffiliateId(userId);
|
|
|
+ //2022-02-15 ==>> 20220215
|
|
|
+ long startDate = Long.valueOf(DateUtils.getDateInteger(startTime));
|
|
|
+ long entDate = Long.valueOf(DateUtils.getDateInteger(endTime));
|
|
|
+ //上阶段时间
|
|
|
+ Map<String,String> lastTime = DateUtils.getStartEndTime(startTime,endTime);
|
|
|
+ long lastTimeStart = Long.valueOf(DateUtils.getDateInteger(lastTime.get("lastTimeStart")));
|
|
|
+ long lastTimeEnd = Long.valueOf(DateUtils.getDateInteger(lastTime.get("lastTimeEnd")));
|
|
|
+
|
|
|
+ //查询运营数据
|
|
|
+ List<KuaiShouOperateVo> listOperate = materialStareMapper.getKuaiShouOperateInfo(startDate,entDate,operatorUserIds);
|
|
|
+ for (KuaiShouOperateVo operate : listOperate) {
|
|
|
+ Set<String> userSet = new HashSet<String>(){{
|
|
|
+ add(operate.getUserId());
|
|
|
+ }};
|
|
|
+ List<KuaiShouOperateVo> userOperate = materialStareMapper.getKuaiShouOperateInfo(lastTimeStart,lastTimeEnd,userSet);
|
|
|
+ Double rate = new Double(0);
|
|
|
+ if (!Check.isNull(userOperate)){
|
|
|
+ //环比 = (当前 - 上阶段 ) / 上阶段
|
|
|
+ rate = (operate.getTotalCost() - userOperate.get(0).getTotalCost() ) / userOperate.get(0).getTotalCost() * 100;
|
|
|
+ rate = Double.valueOf(String.format("%.3f", rate));
|
|
|
+ }
|
|
|
+ operate.setRate(rate);
|
|
|
+ }
|
|
|
+ Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("运营数据详情", "运营数据"), KuaiShouOperateVo.class, listOperate);
|
|
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
+ response.setHeader("content-Type", "application/vnd.ms-excel");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("运营数据详情.xlsx", "UTF-8"));
|
|
|
+ workbook.write(response.getOutputStream());
|
|
|
+ return null;
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return Result.errorMsg("哎呀,查询失败了。");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @description: 运营数据-项目列表
|
|
|
+ *
|
|
|
+ * @param pageNum
|
|
|
+ * @param pageSize
|
|
|
+ * @param startTime
|
|
|
+ * @param endTime
|
|
|
+ * @param userId
|
|
|
+ * @return: org.jeecg.common.api.vo.Result
|
|
|
+ * @author: zianY
|
|
|
+ * @time: 2022/2/17
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result getKuaiShouOperateProjectInfo(Integer pageNum, int pageSize, String startTime, String endTime, String userId) {
|
|
|
+ try {
|
|
|
+ //查询当前人员所有下级
|
|
|
+ Set<String> operatorUserIds = getAffiliateId(userId);
|
|
|
+ //2022-02-15 ==>> 20220215
|
|
|
+ long startDate = Long.valueOf(DateUtils.getDateInteger(startTime));
|
|
|
+ long entDate = Long.valueOf(DateUtils.getDateInteger(endTime));
|
|
|
+
|
|
|
+ //计算环比 时间值 上阶段时间 以及 两个日期之间的 间隔天数
|
|
|
+ Map<String,String> lastTime = DateUtils.getStartEndTime(startTime,endTime);
|
|
|
+ long lastTimeStart = Long.valueOf(DateUtils.getDateInteger(lastTime.get("lastTimeStart")));
|
|
|
+ long lastTimeEnd = Long.valueOf(DateUtils.getDateInteger(lastTime.get("lastTimeEnd")));
|
|
|
+ Integer daysBetween = Integer.valueOf(lastTime.get("daysBetween"));
|
|
|
+
|
|
|
+ //计算同比 时间值 只支持7天
|
|
|
+ long startEqually = new Long("0");
|
|
|
+ long endEqually = new Long("0");
|
|
|
+ if (daysBetween <= 7) {
|
|
|
+ startEqually = DateUtils.getDateInteger(DateUtils.addDayParse(String.valueOf(DateUtils.getDateInteger(startTime)), -7));
|
|
|
+ endEqually = DateUtils.getDateInteger(DateUtils.addDayParse(String.valueOf(DateUtils.getDateInteger(endTime)), -7));
|
|
|
+ }
|
|
|
+
|
|
|
+ PageHelper.startPage(pageNum,pageSize);
|
|
|
+ //查询运营数据-项目维度
|
|
|
+ List<KuaiShouOperateProjectVo> listOperate = materialStareMapper.getKuaiShouOperateProjectInfo(startDate,entDate,null,operatorUserIds);
|
|
|
+ for (KuaiShouOperateProjectVo projectInfo : listOperate) {
|
|
|
+ String projectId = projectInfo.getProjectId();
|
|
|
+ List<KuaiShouOperateProjectVo> projectYearOnYearInfo = materialStareMapper.getKuaiShouOperateProjectInfo(lastTimeStart,lastTimeEnd,projectId,operatorUserIds);
|
|
|
+ //环比 = (当前 - 上阶段 ) / 上阶段
|
|
|
+ Double yearOnYear = new Double(0);
|
|
|
+ if (!Check.isNull(projectYearOnYearInfo)){
|
|
|
+ yearOnYear = (projectInfo.getTotalCost() - projectYearOnYearInfo.get(0).getTotalCost()) / projectYearOnYearInfo.get(0).getTotalCost() * 100;
|
|
|
+ yearOnYear = Double.valueOf(String.format("%.2f", yearOnYear));
|
|
|
+ }
|
|
|
+ projectInfo.setYearOnYear(yearOnYear);
|
|
|
+
|
|
|
+ //同比 日期超过 7 天 则不显示
|
|
|
+ Double equallyRate = new Double(0);
|
|
|
+ if (daysBetween <= 7){
|
|
|
+ List<KuaiShouOperateProjectVo> projectEquallyInfo = materialStareMapper.getKuaiShouOperateProjectInfo(startEqually,endEqually,projectId,operatorUserIds);
|
|
|
+ if (!Check.isNull(projectEquallyInfo)){
|
|
|
+ equallyRate = (projectInfo.getTotalCost() - projectEquallyInfo.get(0).getTotalCost()) / projectEquallyInfo.get(0).getTotalCost() * 100;
|
|
|
+ equallyRate = Double.valueOf(String.format("%.2f", equallyRate));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ projectInfo.setEquallyRate(equallyRate);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ PageInfo<KuaiShouOperateProjectVo> pageInfo = new PageInfo<>(listOperate);
|
|
|
+ return Result.successMsg("运营项目列表数据查询成功。",pageInfo);
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return Result.errorMsg("哎呀,查询失败了。");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @description: 运营数据-账户列表
|
|
|
+ *
|
|
|
+ * @param pageNum
|
|
|
+ * @param pageSize
|
|
|
+ * @param startTime
|
|
|
+ * @param endTime
|
|
|
+ * @param userId
|
|
|
+ * @return: org.jeecg.common.api.vo.Result
|
|
|
+ * @author: zianY
|
|
|
+ * @time: 2022/2/18
|
|
|
*/
|
|
|
- public Long dayBefore(Long date) {
|
|
|
+ @Override
|
|
|
+ public Result getKuaiShouOperateAccountInfo(Integer pageNum, int pageSize, String startTime, String endTime,String projectId, String userId) {
|
|
|
+ try {
|
|
|
+ //查询当前人员所有下级
|
|
|
+ Set<String> operatorUserIds = getAffiliateId(userId);
|
|
|
+ //2022-02-15 ==>> 20220215
|
|
|
+ long startDate = Long.valueOf(DateUtils.getDateInteger(startTime));
|
|
|
+ long entDate = Long.valueOf(DateUtils.getDateInteger(endTime));
|
|
|
+
|
|
|
+ //计算环比 时间值 上阶段时间 以及 两个日期之间的 间隔天数
|
|
|
+ Map<String,String> lastTime = DateUtils.getStartEndTime(startTime,endTime);
|
|
|
+ long lastTimeStart = Long.valueOf(DateUtils.getDateInteger(lastTime.get("lastTimeStart")));
|
|
|
+ long lastTimeEnd = Long.valueOf(DateUtils.getDateInteger(lastTime.get("lastTimeEnd")));
|
|
|
+ Integer daysBetween = Integer.valueOf(lastTime.get("daysBetween"));
|
|
|
+
|
|
|
+ //计算同比 时间值 只支持7天
|
|
|
+ long startEqually = new Long("0");
|
|
|
+ long endEqually = new Long("0");
|
|
|
+ if (daysBetween <= 7) {
|
|
|
+ startEqually = DateUtils.getDateInteger(DateUtils.addDayParse(String.valueOf(DateUtils.getDateInteger(startTime)), -7));
|
|
|
+ endEqually = DateUtils.getDateInteger(DateUtils.addDayParse(String.valueOf(DateUtils.getDateInteger(endTime)), -7));
|
|
|
+ }
|
|
|
+
|
|
|
+ PageHelper.startPage(pageNum,pageSize);
|
|
|
+ //查询运营数据-账户 维度
|
|
|
+ List<KuaiShouOperateAccountVo> listOperate = materialStareMapper.getKuaiShouOperateAccountInfo(startDate,entDate,projectId,null,operatorUserIds);
|
|
|
+ for (KuaiShouOperateAccountVo accountInfo : listOperate) {
|
|
|
+ long accountId = accountInfo.getAccountId();
|
|
|
+ List<KuaiShouOperateAccountVo> accountYearOnYearInfo = materialStareMapper.getKuaiShouOperateAccountInfo(lastTimeStart,lastTimeEnd,projectId,accountId,operatorUserIds);
|
|
|
+ //环比 = (当前 - 上阶段 ) / 上阶段
|
|
|
+ Double yearOnYear = new Double(0);
|
|
|
+ if (!Check.isNull(accountYearOnYearInfo)){
|
|
|
+ yearOnYear = (accountInfo.getTotalCost() - accountYearOnYearInfo.get(0).getTotalCost()) / accountYearOnYearInfo.get(0).getTotalCost() * 100;
|
|
|
+ yearOnYear = Double.valueOf(String.format("%.2f", yearOnYear));
|
|
|
+ }
|
|
|
+ accountInfo.setYearOnYear(yearOnYear);
|
|
|
+
|
|
|
+ //同比 日期超过 7 天 则不显示
|
|
|
+ Double equallyRate = new Double(0);
|
|
|
+ if (daysBetween <= 7){
|
|
|
+ List<KuaiShouOperateAccountVo> accountEquallyInfo = materialStareMapper.getKuaiShouOperateAccountInfo(startEqually,endEqually,projectId,accountId,operatorUserIds);
|
|
|
+ if (!Check.isNull(accountEquallyInfo)){
|
|
|
+ equallyRate = (accountInfo.getTotalCost() - accountEquallyInfo.get(0).getTotalCost()) / accountEquallyInfo.get(0).getTotalCost() * 100;
|
|
|
+ equallyRate = Double.valueOf(String.format("%.2f", equallyRate));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ accountInfo.setEquallyRate(equallyRate);
|
|
|
+ }
|
|
|
+
|
|
|
+ PageInfo<KuaiShouOperateAccountVo> pageInfo = new PageInfo<>(listOperate);
|
|
|
+ return Result.successMsg("运营账户列表数据查询成功。",pageInfo);
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return Result.errorMsg("哎呀,查询失败了。");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @description: 查询账户余额 以及 账户状态 和 消耗
|
|
|
+ *
|
|
|
+ * @param accountId
|
|
|
+ * @return: org.jeecg.common.api.vo.Result
|
|
|
+ * @author: zianY
|
|
|
+ * @time: 2022/2/21
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result getKuaiShouAccountInfo(long accountId) {
|
|
|
+ Map resultMap = new HashMap();
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
|
|
- Long beforeDay = null;
|
|
|
+ // ==>> 20220202
|
|
|
+ String now = sdf.format(new Date());
|
|
|
+ long nowDate = Long.valueOf(now);
|
|
|
+
|
|
|
+ //账户余额
|
|
|
+ JSONObject balance = materialStareMapper.getKuaiShouAccountBalance(accountId, nowDate);
|
|
|
+ resultMap.put("balance",Check.isNull(balance) ? "0" : balance.getString("balance"));
|
|
|
+ //账户今日消耗 以及状态
|
|
|
+ JSONObject totalCost = materialStareMapper.getKuaiShouAccountTotalCost(accountId, nowDate);
|
|
|
+
|
|
|
+ resultMap.put("accountId",Check.isNull(totalCost) ? "-" : totalCost.getString("accountId"));
|
|
|
+ resultMap.put("accountName",Check.isNull(totalCost) ? "0" : totalCost.getString("accountName"));
|
|
|
+
|
|
|
+ resultMap.put("totalCost",Check.isNull(totalCost) ? "0" : totalCost.getString("todayCost"));
|
|
|
+ //0-开 1-关
|
|
|
+ resultMap.put("state", Check.isNull(totalCost) ? "1" : totalCost.getString("accountStatus"));
|
|
|
+ return Result.successMsg("账户查询成功",resultMap);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @description: 账户 折线图 查询时间为当天查询时报;查询时间为多天 查询日报
|
|
|
+ *
|
|
|
+ * @param accountId
|
|
|
+ * @param startTime
|
|
|
+ * @param endTime
|
|
|
+ * @return: org.jeecg.common.api.vo.Result
|
|
|
+ * @author: zianY
|
|
|
+ * @time: 2022/2/21
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result getKuaiShouAccountInfoBrokenLine(long accountId, String startTime, String endTime) {
|
|
|
+
|
|
|
+ List<JSONObject> resultList = new ArrayList<>();
|
|
|
try {
|
|
|
- Date parse = sdf.parse(date.toString());
|
|
|
- Calendar c = Calendar.getInstance();
|
|
|
- c.setTime(parse);
|
|
|
- int day1 = c.get(Calendar.DATE);
|
|
|
- c.set(Calendar.DATE, day1 - 1);
|
|
|
- beforeDay = Long.parseLong(sdf.format(c.getTime()));
|
|
|
- } catch (ParseException e) {
|
|
|
+ //2022-02-15 ==>> 20220215
|
|
|
+ long startDate = Long.valueOf(DateUtils.getDateInteger(startTime));
|
|
|
+ long entDate = Long.valueOf(DateUtils.getDateInteger(endTime));
|
|
|
+
|
|
|
+ //两个日期之间的 间隔天数
|
|
|
+ Map<String,String> lastTime = DateUtils.getStartEndTime(startTime,endTime);
|
|
|
+ Integer daysBetween = Integer.valueOf(lastTime.get("daysBetween"));
|
|
|
+
|
|
|
+ if (daysBetween == 0){
|
|
|
+ //昨天
|
|
|
+ long yesterday = DateUtils.getDateInteger(DateUtils.addDayParse(String.valueOf(entDate), -1));
|
|
|
+ resultList = materialStareMapper.getKuaiShouAccountInfoBrokenLineHour(accountId,startDate,yesterday);
|
|
|
+ return Result.successMsg("账户时报报折线图查询成功",resultList);
|
|
|
+ }
|
|
|
+ resultList = materialStareMapper.getKuaiShouAccountInfoBrokenLineDaily(accountId,startDate,entDate);
|
|
|
+ return Result.successMsg("账户日报折线图查询成功",resultList);
|
|
|
+
|
|
|
+ }catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- return beforeDay;
|
|
|
+ return Result.errorMsg("账户折线图查询异常");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @description: 快手 账户 素材上新-有效-爆款
|
|
|
+ *
|
|
|
+ * @param accountId
|
|
|
+ * @param searchType searchType:查询类型 0-全部 1-上新 2-有效 3-爆款
|
|
|
+ * @param startTime
|
|
|
+ * @param endTime
|
|
|
+ * @return: org.jeecg.common.api.vo.Result
|
|
|
+ * @author: zianY
|
|
|
+ * @time: 2022/2/21
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result getKuaiShouAccountMaterialNewAndEffectAndFaddish(long accountId, String searchType, String startTime, String endTime,Integer pageNum,Integer pageSize) {
|
|
|
+ //2022-02-15 ==>> 20220215
|
|
|
+ long startDate = Long.valueOf(DateUtils.getDateInteger(startTime));
|
|
|
+ long entDate = Long.valueOf(DateUtils.getDateInteger(endTime));
|
|
|
+ PageHelper.startPage(pageNum,pageSize);
|
|
|
+ List<JSONObject> resultList = materialStareMapper.getKuaiShouAccountMaterialNewAndEffectAndFaddish(accountId,searchType,startDate,entDate);
|
|
|
+ PageInfo<JSONObject> pageInfo = new PageInfo<>(resultList);
|
|
|
+ return Result.successMsg("查询账户素材信息成功。",pageInfo);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 查询当前人员所有下级 返回自己和下属id
|
|
|
+ *
|
|
|
+ * @description: 查询账户饼图数据信息
|
|
|
+ *
|
|
|
+ * @param accountId
|
|
|
+ * @param startTime
|
|
|
+ * @param endTime
|
|
|
+ * @return: org.jeecg.common.api.vo.Result
|
|
|
+ * @author: zianY
|
|
|
+ * @time: 2022/2/22
|
|
|
*/
|
|
|
+ @Override
|
|
|
+ public Result getKuaiShouAccountPieChar(long accountId, String startTime, String endTime,String type) {
|
|
|
+ Map resultMap = new HashMap();
|
|
|
+ //2022-02-15 ==>> 20220215
|
|
|
+ long startDate = Long.valueOf(DateUtils.getDateInteger(startTime));
|
|
|
+ long entDate = Long.valueOf(DateUtils.getDateInteger(endTime));
|
|
|
+ //版位
|
|
|
+ List<KuaiShouAccountPieVo> sceneList = materialStareMapper.getKuaiShouAccountPieScene(accountId,startDate,entDate,type);
|
|
|
+ //年龄
|
|
|
+ List<KuaiShouAccountPieVo> ageList = materialStareMapper.getKuaiShouAccountPieAge(accountId,startDate,entDate,type);
|
|
|
+ //性别
|
|
|
+ List<KuaiShouAccountPieVo> genderList = materialStareMapper.getKuaiShouAccountPieGender(accountId,startDate,entDate,type);
|
|
|
+ resultMap.put("scene",sceneList);
|
|
|
+ resultMap.put("age",ageList);
|
|
|
+ resultMap.put("gender",genderList);
|
|
|
+ return Result.successMsg("查询饼图数据成功。",resultMap);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+//===========================================查询下级员工========================
|
|
|
+
|
|
|
+ public Result getCompanyAllSubordinateByUserId(String userId){
|
|
|
+ Set<String> operatorUserIds = getAffiliateId(userId);
|
|
|
+ return Result.successMsg("查询该用户所有下级userId",operatorUserIds);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询当前人员 所属公司 返回自己和下属id
|
|
|
+ */
|
|
|
public Set<String> getAffiliateId(String userId) {
|
|
|
+ //查询用户所属公司
|
|
|
+ String companyId = materialStareMapper.getUserCompanyByUserId(userId);
|
|
|
Set<String> result;
|
|
|
//查询当前用户是否存在下级
|
|
|
- Set<String> subordinate = materialStareMapper.getAffiliateId(userId);
|
|
|
+ Set<String> subordinate = materialStareMapper.getAffiliateId(userId,companyId);
|
|
|
if (subordinate.isEmpty()) {
|
|
|
subordinate.add(userId);
|
|
|
return subordinate;
|
|
|
} else {
|
|
|
- result = querySubordinate(subordinate, subordinate);
|
|
|
+ result = querySubordinate(subordinate, subordinate,companyId);
|
|
|
result.add(userId);
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
//递归查询
|
|
|
- private Set<String> querySubordinate(Set<String> leaderIds, Set<String> result) {
|
|
|
+ private Set<String> querySubordinate(Set<String> leaderIds, Set<String> result,String companyId) {
|
|
|
if (leaderIds.isEmpty()) {
|
|
|
return result;
|
|
|
}
|
|
|
- Set<String> temp = materialStareMapper.querySubordinateRecursive(leaderIds);
|
|
|
+ Set<String> temp = materialStareMapper.querySubordinateRecursive(companyId,leaderIds);
|
|
|
result.addAll(temp);
|
|
|
- querySubordinate(temp, result);
|
|
|
+ querySubordinate(temp, result,companyId);
|
|
|
return result;
|
|
|
}
|
|
|
+//===========================================查询下级员工========================
|
|
|
+
|
|
|
}
|