|
@@ -11,12 +11,10 @@ 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.system.entity.SysUser;
|
|
|
import org.jeecg.common.util.DateUtils;
|
|
|
import org.jeecg.ctop.material.constants.Check;
|
|
|
-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.entity.vo.*;
|
|
|
import org.jeecg.ctop.material.mapper.MaterialStareMapper;
|
|
|
import org.jeecg.ctop.material.service.MaterialStareService;
|
|
|
import org.jeecg.ctop.material.utils.FeidNotNullUtils;
|
|
@@ -25,10 +23,13 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.text.DecimalFormat;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.DoubleStream;
|
|
|
+import java.util.stream.IntStream;
|
|
|
|
|
|
/**
|
|
|
* 盯盘接口
|
|
@@ -196,6 +197,9 @@ public class MaterialStareServiceImpl implements MaterialStareService {
|
|
|
//有消耗的账户
|
|
|
operatorUserIds = materialStareMapper.getKuaiShouAllOperators(companyId,DateUtils.getDateInteger(startTime).longValue(),DateUtils.getDateInteger(endTime).longValue(),operatorUserIds);
|
|
|
|
|
|
+ //快手-在投项目数量
|
|
|
+ String projectNum = materialStareMapper.getKuaiShouOperatorProjectNum(DateUtils.getDateInteger(startTime).longValue(),DateUtils.getDateInteger(endTime).longValue(),operatorUserIds);
|
|
|
+
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
|
|
// ==>> 20220202
|
|
|
String now = sdf.format(new Date());
|
|
@@ -225,6 +229,7 @@ public class MaterialStareServiceImpl implements MaterialStareService {
|
|
|
DecimalFormat df = new DecimalFormat("#.000");
|
|
|
resultMap.put("userAverageAccount",new Double(Math.ceil(userAverageAccount)).intValue());
|
|
|
resultMap.put("userAveragecost",df.format(userAveragecost));
|
|
|
+ resultMap.put("projectNum",projectNum);
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@@ -352,6 +357,8 @@ public class MaterialStareServiceImpl implements MaterialStareService {
|
|
|
public Result getKuaiShouOperateInfo(Integer pageNum, int pageSize, String startTime, String endTime, String userId) {
|
|
|
DecimalFormat decimalFormat = new DecimalFormat("0.00%");
|
|
|
|
|
|
+
|
|
|
+
|
|
|
try {
|
|
|
//查询当前人员所有下级
|
|
|
Set<String> operatorUserIds = getAffiliateId(userId);
|
|
@@ -363,16 +370,30 @@ public class MaterialStareServiceImpl implements MaterialStareService {
|
|
|
long lastTimeStart = Long.valueOf(DateUtils.getDateInteger(lastTime.get("lastTimeStart")));
|
|
|
long lastTimeEnd = Long.valueOf(DateUtils.getDateInteger(lastTime.get("lastTimeEnd")));
|
|
|
|
|
|
+ long now = Long.valueOf(DateUtils.getDateInteger(DateUtils.getDate("yyyy-MM-dd")));
|
|
|
+
|
|
|
PageHelper.startPage(pageNum,pageSize);
|
|
|
//查询运营数据
|
|
|
List<KuaiShouOperateVo> listOperate = materialStareMapper.getKuaiShouOperateInfo(startDate,entDate,operatorUserIds);
|
|
|
for (KuaiShouOperateVo operate : listOperate) {
|
|
|
|
|
|
+ Set<String> ids = new HashSet<String>(){{
|
|
|
+ add(operate.getUserId());
|
|
|
+ }};
|
|
|
+
|
|
|
+ //当天
|
|
|
+ int newUnitNumNow = 0;
|
|
|
+ if (startDate == now || entDate == now){
|
|
|
+ //查询 当天有效 上新计划 上新组
|
|
|
+ JSONObject newEffect = materialStareMapper.getKuaiShouAccountNowBaseByUserId(ids,null,null,now,now);
|
|
|
+ newUnitNumNow = Check.isNull(newEffect) ? 0 : newEffect.getInteger("newUnitNum");//组
|
|
|
+ }
|
|
|
+
|
|
|
//查询 有效 上新计划 上新组
|
|
|
- JSONObject newEffect = materialStareMapper.getKuaiShouAccountBaseByUserId(operate.getUserId(),null,null,startDate,entDate);
|
|
|
- operate.setNewEffectNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newEffectNum"));//有效
|
|
|
+ JSONObject newEffect = materialStareMapper.getKuaiShouAccountBaseByUserId(ids,null,null,startDate,entDate);
|
|
|
+ //operate.setNewEffectNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newEffectNum"));//有效
|
|
|
operate.setNewCampaignNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newCampaignNum"));//计划
|
|
|
- operate.setNewUnitNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newUnitNum"));//组
|
|
|
+ operate.setNewUnitNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newUnitNum")+newUnitNumNow);//组
|
|
|
|
|
|
Set<String> userSet = new HashSet<String>(){{
|
|
|
add(operate.getUserId());
|
|
@@ -408,15 +429,30 @@ public class MaterialStareServiceImpl implements MaterialStareService {
|
|
|
long lastTimeStart = Long.valueOf(DateUtils.getDateInteger(lastTime.get("lastTimeStart")));
|
|
|
long lastTimeEnd = Long.valueOf(DateUtils.getDateInteger(lastTime.get("lastTimeEnd")));
|
|
|
|
|
|
- //查询运营数据
|
|
|
+ long now = Long.valueOf(DateUtils.getDateInteger(DateUtils.getDate("yyyy-MM-dd")));
|
|
|
+
|
|
|
+ //查询运营数据
|
|
|
List<KuaiShouOperateVo> listOperate = materialStareMapper.getKuaiShouOperateInfo(startDate,entDate,operatorUserIds);
|
|
|
for (KuaiShouOperateVo operate : listOperate) {
|
|
|
|
|
|
- //查询 有效 上新计划 上新组
|
|
|
- JSONObject newEffect = materialStareMapper.getKuaiShouAccountBaseByUserId(operate.getUserId(),null,null,startDate,entDate);
|
|
|
- operate.setNewEffectNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newEffectNum"));//有效
|
|
|
- operate.setNewCampaignNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newCampaignNum"));//计划
|
|
|
- operate.setNewUnitNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newUnitNum"));//组
|
|
|
+ Set<String> ids = new HashSet<String>(){{
|
|
|
+ add(operate.getUserId());
|
|
|
+ }};
|
|
|
+
|
|
|
+ //当天
|
|
|
+ int effect = 0;
|
|
|
+ if (startDate == now || entDate == now){
|
|
|
+ //查询 当天有效 上新计划 上新组
|
|
|
+ JSONObject newEffect = materialStareMapper.getKuaiShouAccountNowBaseByUserId(ids,null,null,startDate,entDate);
|
|
|
+ effect = Check.isNull(newEffect) ? 0 : newEffect.getInteger("newUnitNum");//组
|
|
|
+ }
|
|
|
+ //查询 有效 上新计划 上新组
|
|
|
+ JSONObject newEffect = materialStareMapper.getKuaiShouAccountBaseByUserId(ids,null,null,startDate,entDate);
|
|
|
+ //operate.setNewEffectNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newEffectNum"));//有效
|
|
|
+ operate.setNewCampaignNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newCampaignNum"));//计划
|
|
|
+ operate.setNewUnitNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newUnitNum")+effect);//组
|
|
|
+
|
|
|
+
|
|
|
|
|
|
Set<String> userSet = new HashSet<String>(){{
|
|
|
add(operate.getUserId());
|
|
@@ -459,6 +495,7 @@ public class MaterialStareServiceImpl implements MaterialStareService {
|
|
|
@Override
|
|
|
public Result getKuaiShouOperateProjectInfo(Integer pageNum, int pageSize, String startTime, String endTime, String userId) {
|
|
|
DecimalFormat decimalFormat = new DecimalFormat("0.00%");
|
|
|
+ long now = Long.valueOf(DateUtils.getDateInteger(DateUtils.getDate("yyyy-MM-dd")));
|
|
|
try {
|
|
|
//查询当前人员所有下级
|
|
|
Set<String> operatorUserIds = getAffiliateId(userId);
|
|
@@ -485,12 +522,35 @@ public class MaterialStareServiceImpl implements MaterialStareService {
|
|
|
List<KuaiShouOperateProjectVo> listOperate = materialStareMapper.getKuaiShouOperateProjectInfo(startDate,entDate,null,operatorUserIds);
|
|
|
for (KuaiShouOperateProjectVo projectInfo : listOperate) {
|
|
|
|
|
|
+ //当天
|
|
|
+ int newUnitNumNow = 0;
|
|
|
+ int trustUnitNum = 0;
|
|
|
+ if (startDate == now || entDate == now){
|
|
|
+ //查询 当天有效 上新计划 上新组
|
|
|
+ JSONObject newEffect = materialStareMapper.getKuaiShouAccountNowBaseByUserId(null,projectInfo.getProjectId(),null,now,now);
|
|
|
+ newUnitNumNow = Check.isNull(newEffect) ? 0 : newEffect.getInteger("newUnitNum");//组
|
|
|
+ trustUnitNum = Check.isNull(newEffect) ? 0 : newEffect.getInteger("trustUnitNum");//智能托管
|
|
|
+ }
|
|
|
+
|
|
|
//查询 有效 上新视频 爆款视频
|
|
|
JSONObject newEffect = materialStareMapper.getKuaiShouAccountBaseByUserId(null,projectInfo.getProjectId(),null,startDate,entDate);
|
|
|
projectInfo.setNewEffectNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newEffectNum"));//有效
|
|
|
projectInfo.setNewVideoNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newVideoNum"));//上新
|
|
|
projectInfo.setNewHotNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newHotNum"));//爆款
|
|
|
|
|
|
+ projectInfo.setNewUnitNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newUnitNum")+newUnitNumNow);//基建数
|
|
|
+ projectInfo.setTrustUnitNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("trustUnitNum")+trustUnitNum);//智能托管
|
|
|
+
|
|
|
+ //查看 上传到助手、媒体的素材数量 分版位花费
|
|
|
+ List<JSONObject> materailUpload = materialStareMapper.getKuaiShouMaterailUploadType(projectInfo.getProjectId(),startDate,entDate);
|
|
|
+
|
|
|
+ projectInfo.setAdspNum(Check.isNull(materailUpload) ? 0L : JSONObject.parseObject(materailUpload.get(0)+"").getLong("num"));//上传到助手
|
|
|
+ projectInfo.setMediaNum(Check.isNull(materailUpload) ? 0L : JSONObject.parseObject(materailUpload.get(1)+"").getLong("num"));//上传到媒体
|
|
|
+
|
|
|
+ //分版位
|
|
|
+ List<JSONObject> adSceneDate = materialStareMapper.getKuaiShouAdSceneData(projectInfo.getProjectId(),startDate,entDate);
|
|
|
+ projectInfo.setAdSceneDate(adSceneDate);
|
|
|
+
|
|
|
|
|
|
String projectId = projectInfo.getProjectId();
|
|
|
List<KuaiShouOperateProjectVo> projectYearOnYearInfo = materialStareMapper.getKuaiShouOperateProjectInfo(lastTimeStart,lastTimeEnd,projectId,operatorUserIds);
|
|
@@ -527,6 +587,7 @@ public class MaterialStareServiceImpl implements MaterialStareService {
|
|
|
|
|
|
public List<KuaiShouOperateProjectVo> exportKuaiShouOperateProjectInfo(String startTime, String endTime, String userId) {
|
|
|
DecimalFormat decimalFormat = new DecimalFormat("0.00%");
|
|
|
+ long now = Long.valueOf(DateUtils.getDateInteger(DateUtils.getDate("yyyy-MM-dd")));
|
|
|
try {
|
|
|
//查询当前人员所有下级
|
|
|
Set<String> operatorUserIds = getAffiliateId(userId);
|
|
@@ -552,12 +613,34 @@ public class MaterialStareServiceImpl implements MaterialStareService {
|
|
|
List<KuaiShouOperateProjectVo> listOperate = materialStareMapper.getKuaiShouOperateProjectInfo(startDate,entDate,null,operatorUserIds);
|
|
|
for (KuaiShouOperateProjectVo projectInfo : listOperate) {
|
|
|
|
|
|
+ //当天
|
|
|
+ int newUnitNumNow = 0;
|
|
|
+ int trustUnitNum = 0;
|
|
|
+ if (startDate == now || entDate == now){
|
|
|
+ //查询 当天有效 上新计划 上新组
|
|
|
+ JSONObject newEffect = materialStareMapper.getKuaiShouAccountNowBaseByUserId(null,projectInfo.getProjectId(),null,now,now);
|
|
|
+ newUnitNumNow = Check.isNull(newEffect) ? 0 : newEffect.getInteger("newUnitNum");//组
|
|
|
+ trustUnitNum = Check.isNull(newEffect) ? 0 : newEffect.getInteger("trustUnitNum");//智能托管
|
|
|
+ }
|
|
|
+
|
|
|
//查询 有效 上新视频 爆款视频
|
|
|
JSONObject newEffect = materialStareMapper.getKuaiShouAccountBaseByUserId(null,projectInfo.getProjectId(),null,startDate,entDate);
|
|
|
projectInfo.setNewEffectNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newEffectNum"));//有效
|
|
|
projectInfo.setNewVideoNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newVideoNum"));//上新
|
|
|
projectInfo.setNewHotNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newHotNum"));//爆款
|
|
|
|
|
|
+ projectInfo.setNewUnitNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newUnitNum")+newUnitNumNow);//基建数
|
|
|
+ projectInfo.setTrustUnitNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("trustUnitNum")+trustUnitNum);//智能托管
|
|
|
+
|
|
|
+ //查看 上传到助手、媒体的素材数量 分版位花费
|
|
|
+ List<JSONObject> materailUpload = materialStareMapper.getKuaiShouMaterailUploadType(projectInfo.getProjectId(),startDate,entDate);
|
|
|
+
|
|
|
+ projectInfo.setAdspNum(Check.isNull(materailUpload) ? 0L : JSONObject.parseObject(materailUpload.get(0)+"").getLong("num"));//上传到助手
|
|
|
+ projectInfo.setMediaNum(Check.isNull(materailUpload) ? 0L : JSONObject.parseObject(materailUpload.get(1)+"").getLong("num"));//上传到媒体
|
|
|
+
|
|
|
+ //分版位
|
|
|
+ List<JSONObject> adSceneDate = materialStareMapper.getKuaiShouAdSceneData(projectInfo.getProjectId(),startDate,entDate);
|
|
|
+ projectInfo.setAdSceneDate(adSceneDate);
|
|
|
|
|
|
String projectId = projectInfo.getProjectId();
|
|
|
List<KuaiShouOperateProjectVo> projectYearOnYearInfo = materialStareMapper.getKuaiShouOperateProjectInfo(lastTimeStart,lastTimeEnd,projectId,operatorUserIds);
|
|
@@ -989,6 +1072,225 @@ public class MaterialStareServiceImpl implements MaterialStareService {
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @description: 运营组列表数据
|
|
|
+ *
|
|
|
+ * @param startTime
|
|
|
+ * @param endTime
|
|
|
+ * @param pageNum
|
|
|
+ * @param pageSize
|
|
|
+ * @return: org.jeecg.common.api.vo.Result
|
|
|
+ * @author: zianY
|
|
|
+ * @time: 2022/8/31 15:16
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result getOperationGroupData(String userId,String startTime,String endTime,Integer pageNum,Integer pageSize) {
|
|
|
+ DecimalFormat decimalFormat = new DecimalFormat("0.00%");
|
|
|
+ try {
|
|
|
+ long nowDate = Long.valueOf(DateUtils.getDateInteger(DateUtils.getDate("yyyy-MM-dd")));
|
|
|
+
|
|
|
+ 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"))+1;
|
|
|
+
|
|
|
+ //查询用户角色
|
|
|
+ String roleCode = materialStareMapper.getRoleCodeByUserId(userId);
|
|
|
+ JSONObject userName = materialStareMapper.getKuaiShouUserByUserId(userId);
|
|
|
+
|
|
|
+ List<KuaiShouOperateGroupVo> operationManagerList = new ArrayList<>();
|
|
|
+ if ("admin".equals(roleCode)) {
|
|
|
+ PageHelper.startPage(pageNum,pageSize);
|
|
|
+ //查询运营经理
|
|
|
+ operationManagerList = materialStareMapper.getOperationManagerUser();
|
|
|
+ }else if (roleCode.contains("OperationManager")){
|
|
|
+ operationManagerList.add(new KuaiShouOperateGroupVo(userId,userName.getString("userName")));
|
|
|
+ }else {
|
|
|
+ Result.successMsg("运营组列表数据查询成功。",null);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (KuaiShouOperateGroupVo groupVo : operationManagerList) {
|
|
|
+
|
|
|
+ //下级员工
|
|
|
+ Set<String> operatorUserIds = getAffiliateId(groupVo.getUserId());
|
|
|
+ //运营数量
|
|
|
+ int operationNum = Check.isNull(operatorUserIds) ? 0 : operatorUserIds.size();
|
|
|
+ groupVo.setOperationNum(operationNum);
|
|
|
+
|
|
|
+ //查询账户数据
|
|
|
+ List<KuaiShouOperateVo> listOperate= new ArrayList<>();
|
|
|
+ if (daysBetween < 0){
|
|
|
+ //时报
|
|
|
+ listOperate= materialStareMapper.getKuaiShouOperateInfoHourly(startDate,entDate,operatorUserIds);
|
|
|
+ }else {
|
|
|
+ listOperate = materialStareMapper.getKuaiShouOperateInfo(startDate,entDate,operatorUserIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ //总花费
|
|
|
+ Double totalCost = Check.isNull(listOperate) ? 0 : listOperate.stream().mapToDouble(KuaiShouOperateVo::getTotalCost).sum();
|
|
|
+ groupVo.setTotalCost(new BigDecimal(totalCost).setScale(3,BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
|
+
|
|
|
+ //日均消耗 总花费/天数
|
|
|
+ Double aveDay = daysBetween == 0 ? 0 : totalCost/daysBetween;
|
|
|
+ groupVo.setAverageDayCost(new BigDecimal(aveDay).setScale(3,BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
|
+ //人均消耗
|
|
|
+ Double avePeople = totalCost/operationNum;
|
|
|
+ groupVo.setAveragePeopleCost(new BigDecimal(avePeople).setScale(3,BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
|
+
|
|
|
+ //项目数量
|
|
|
+ Double projectNum = Check.isNull(listOperate) ? 0 : listOperate.stream().mapToDouble(KuaiShouOperateVo::getProjectNum).sum();
|
|
|
+ groupVo.setProjectNum(projectNum.longValue());
|
|
|
+ //账户数量
|
|
|
+ Double accountNum = Check.isNull(listOperate) ? 0 : listOperate.stream().mapToDouble(KuaiShouOperateVo::getAccountNum).sum();
|
|
|
+ groupVo.setAccountNum(accountNum.longValue());
|
|
|
+ //平均账户消耗 总花费/账户数量
|
|
|
+ Double aveAccount = accountNum.intValue() == 0 ? 0 : totalCost/accountNum;
|
|
|
+ groupVo.setAverageAccountCost(new BigDecimal(aveAccount).setScale(3,BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
|
+ //环比 = (当前 - 上阶段 ) / 上阶段
|
|
|
+ List<KuaiShouOperateVo> yearOnYearInfo = materialStareMapper.getKuaiShouOperateInfo(lastTimeStart,lastTimeEnd,operatorUserIds);
|
|
|
+ String yearOnYear = "0";
|
|
|
+ if (!Check.isNull(yearOnYearInfo)){
|
|
|
+ Double lastTotalCost = Check.isNull(yearOnYearInfo) ? 0 : yearOnYearInfo.stream().mapToDouble(KuaiShouOperateVo::getTotalCost).sum();
|
|
|
+ Double yearOnYearD = (totalCost - lastTotalCost) / lastTotalCost;
|
|
|
+ yearOnYear = decimalFormat.format(yearOnYearD);
|
|
|
+ }
|
|
|
+ //花费环比
|
|
|
+ groupVo.setYearOnYearCost(yearOnYear);
|
|
|
+
|
|
|
+
|
|
|
+ //当天
|
|
|
+ int newUnitNumNow = 0;
|
|
|
+ if (startDate == nowDate || entDate == nowDate){
|
|
|
+ //查询 当天有效 上新计划 上新组
|
|
|
+ JSONObject newEffect = materialStareMapper.getKuaiShouAccountNowBaseByUserId(operatorUserIds,null,null,nowDate,nowDate);
|
|
|
+ newUnitNumNow = Check.isNull(newEffect) ? 0 : newEffect.getInteger("newUnitNum");//组
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询 历史上新组
|
|
|
+ JSONObject newEffect = materialStareMapper.getKuaiShouAccountBaseByUserId(operatorUserIds,null,null,startDate,entDate);
|
|
|
+ //基建数量
|
|
|
+ groupVo.setUnitNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newUnitNum")+newUnitNumNow);//组
|
|
|
+ }
|
|
|
+
|
|
|
+ PageInfo<KuaiShouOperateGroupVo> pageInfo = new PageInfo<>(operationManagerList);
|
|
|
+ return Result.successMsg("运营组列表数据查询成功。",pageInfo);
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return Result.errorMsg("哎呀,查询失败了。");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public Result exportOperationGroupData(String userId,String startTime,String endTime, HttpServletResponse response) {
|
|
|
+ DecimalFormat decimalFormat = new DecimalFormat("0.00%");
|
|
|
+ try {
|
|
|
+ long nowDate = Long.valueOf(DateUtils.getDateInteger(DateUtils.getDate("yyyy-MM-dd")));
|
|
|
+
|
|
|
+ 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"))+1;
|
|
|
+
|
|
|
+ //查询用户角色
|
|
|
+ String roleCode = materialStareMapper.getRoleCodeByUserId(userId);
|
|
|
+ JSONObject userName = materialStareMapper.getKuaiShouUserByUserId(userId);
|
|
|
+
|
|
|
+ List<KuaiShouOperateGroupVo> operationManagerList = new ArrayList<>();
|
|
|
+ if ("admin".equals(roleCode)) {
|
|
|
+ //查询运营经理
|
|
|
+ operationManagerList = materialStareMapper.getOperationManagerUser();
|
|
|
+ }else if (roleCode.contains("OperationManager")){
|
|
|
+ operationManagerList.add(new KuaiShouOperateGroupVo(userId,userName.getString("userName")));
|
|
|
+ }else {
|
|
|
+ Result.successMsg("运营组列表数据查询成功。",null);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (KuaiShouOperateGroupVo groupVo : operationManagerList) {
|
|
|
+
|
|
|
+ //下级员工
|
|
|
+ Set<String> operatorUserIds = getAffiliateId(groupVo.getUserId());
|
|
|
+ //运营数量
|
|
|
+ int operationNum = Check.isNull(operatorUserIds) ? 0 : operatorUserIds.size();
|
|
|
+ groupVo.setOperationNum(operationNum);
|
|
|
+ //查询账户数据
|
|
|
+ List<KuaiShouOperateVo> listOperate= new ArrayList<>();
|
|
|
+ if (daysBetween < 0){
|
|
|
+ //时报
|
|
|
+ listOperate= materialStareMapper.getKuaiShouOperateInfoHourly(startDate,entDate,operatorUserIds);
|
|
|
+ }else {
|
|
|
+ listOperate = materialStareMapper.getKuaiShouOperateInfo(startDate,entDate,operatorUserIds);
|
|
|
+ }
|
|
|
+ //总花费
|
|
|
+ Double totalCost = Check.isNull(listOperate) ? 0 : listOperate.stream().mapToDouble(KuaiShouOperateVo::getTotalCost).sum();
|
|
|
+ groupVo.setTotalCost(new BigDecimal(totalCost).setScale(3,BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
|
+ //日均消耗 总花费/天数
|
|
|
+ Double aveDay = daysBetween == 0 ? 0 : totalCost/daysBetween;
|
|
|
+ groupVo.setAverageDayCost(new BigDecimal(aveDay).setScale(3,BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
|
+ //人均消耗
|
|
|
+ Double avePeople = totalCost/operationNum;
|
|
|
+ groupVo.setAveragePeopleCost(avePeople);
|
|
|
+ //项目数量
|
|
|
+ Double projectNum = Check.isNull(listOperate) ? 0 : listOperate.stream().mapToDouble(KuaiShouOperateVo::getProjectNum).sum();
|
|
|
+ groupVo.setProjectNum(projectNum.longValue());
|
|
|
+ //账户数量
|
|
|
+ Double accountNum = Check.isNull(listOperate) ? 0 : listOperate.stream().mapToDouble(KuaiShouOperateVo::getAccountNum).sum();
|
|
|
+ groupVo.setAccountNum(accountNum.longValue());
|
|
|
+ //平均账户消耗 总花费/账户数量
|
|
|
+ Double aveAccount = accountNum.intValue() == 0 ? 0 : totalCost/accountNum;
|
|
|
+ groupVo.setAverageAccountCost(new BigDecimal(aveAccount).setScale(3,BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
|
+ //环比 = (当前 - 上阶段 ) / 上阶段
|
|
|
+ List<KuaiShouOperateVo> yearOnYearInfo = materialStareMapper.getKuaiShouOperateInfo(lastTimeStart,lastTimeEnd,operatorUserIds);
|
|
|
+ String yearOnYear = "0";
|
|
|
+ if (!Check.isNull(yearOnYearInfo)){
|
|
|
+ Double lastTotalCost = Check.isNull(yearOnYearInfo) ? 0 : yearOnYearInfo.stream().mapToDouble(KuaiShouOperateVo::getTotalCost).sum();
|
|
|
+ Double yearOnYearD = (totalCost - lastTotalCost) / lastTotalCost;
|
|
|
+ yearOnYear = decimalFormat.format(yearOnYearD);
|
|
|
+ }
|
|
|
+ //花费环比
|
|
|
+ groupVo.setYearOnYearCost(yearOnYear);
|
|
|
+ //当天
|
|
|
+ int newUnitNumNow = 0;
|
|
|
+ if (startDate == nowDate || entDate == nowDate){
|
|
|
+ //查询 当天有效 上新计划 上新组
|
|
|
+ JSONObject newEffect = materialStareMapper.getKuaiShouAccountNowBaseByUserId(operatorUserIds,null,null,nowDate,nowDate);
|
|
|
+ newUnitNumNow = Check.isNull(newEffect) ? 0 : newEffect.getInteger("newUnitNum");//组
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询 历史上新组
|
|
|
+ JSONObject newEffect = materialStareMapper.getKuaiShouAccountBaseByUserId(operatorUserIds,null,null,startDate,entDate);
|
|
|
+ //基建数量
|
|
|
+ groupVo.setUnitNum(Check.isNull(newEffect) ? 0 : newEffect.getInteger("newUnitNum")+newUnitNumNow);//组
|
|
|
+ }
|
|
|
+ Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("运营组数据详情", "运营组数据"), KuaiShouOperateGroupVo.class, operationManagerList);
|
|
|
+ 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("哎呀,查询失败了。");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
//===========================================查询下级员工========================
|
|
|
|
|
|
public Result getCompanyAllSubordinateByUserId(String userId){
|