|
|
@@ -1,23 +1,35 @@
|
|
|
package com.fs.course.service.impl;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
+import com.fs.common.core.controller.BaseController;
|
|
|
+import com.fs.common.core.page.PageDomain;
|
|
|
+import com.fs.common.core.page.TableSupport;
|
|
|
import com.fs.common.exception.CustomException;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
import com.fs.common.utils.DictUtils;
|
|
|
import com.fs.common.utils.date.DateUtil;
|
|
|
+import com.fs.common.utils.sql.SqlUtil;
|
|
|
import com.fs.company.cache.ICompanyCacheService;
|
|
|
+import com.fs.company.mapper.CompanyDeptMapper;
|
|
|
import com.fs.course.param.FsCourseTrafficLogParam;
|
|
|
import com.fs.course.param.InternetTrafficParam;
|
|
|
+import com.fs.course.param.StatisticsSummaryParam;
|
|
|
import com.fs.course.param.TrafficRecord;
|
|
|
+import com.fs.course.vo.DeptFullPathVO;
|
|
|
import com.fs.course.vo.FsCourseTrafficLogListVO;
|
|
|
+import com.fs.course.vo.StatisticsSummaryVO;
|
|
|
import com.fs.store.service.cache.IFsUserCourseCacheService;
|
|
|
import com.fs.system.domain.SysConfig;
|
|
|
import com.fs.system.service.ISysConfigService;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
import com.hc.openapi.tool.util.StringUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -47,6 +59,9 @@ public class FsCourseTrafficLogServiceImpl implements IFsCourseTrafficLogService
|
|
|
@Autowired
|
|
|
private IFsUserCourseCacheService fsUserCourseCacheService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ CompanyDeptMapper companyDeptMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 查询短链课程流量记录
|
|
|
*
|
|
|
@@ -402,4 +417,108 @@ public class FsCourseTrafficLogServiceImpl implements IFsCourseTrafficLogService
|
|
|
minutes % 60,
|
|
|
seconds % 60);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 流量统计汇总
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<StatisticsSummaryVO> getStatisticsSummaryList(StatisticsSummaryParam param){
|
|
|
+
|
|
|
+ if(StringUtils.isBlank(param.getStartDate()) && StringUtils.isBlank(param.getEndDate())){
|
|
|
+ throw new CustomException("搜索必须要一个时间范围!");
|
|
|
+ }
|
|
|
+ param.setEndDateQueryValue(addOneDay(param.getEndDate()));
|
|
|
+ if(null == param.getStatisticsType()){
|
|
|
+ throw new CustomException("请选择统计类型");
|
|
|
+ }
|
|
|
+ Map<Long,DeptFullPathVO> deptMp = new HashMap<>();
|
|
|
+ boolean byDept = param.getStatisticsType().equals(2);
|
|
|
+ //按照部门方式汇总
|
|
|
+ if(byDept){
|
|
|
+ if(null == param.getCompanyId()){
|
|
|
+ throw new CustomException("请选择公司");
|
|
|
+ }
|
|
|
+ List<DeptFullPathVO> deptInfoList = companyDeptMapper.getDeptFullPathList(param.getCompanyId());
|
|
|
+ deptMp = deptInfoList.stream().collect(Collectors.toMap(DeptFullPathVO::getDeptId, item -> item));
|
|
|
+ if(CollectionUtils.isEmpty(deptInfoList)){
|
|
|
+ throw new CustomException("该公司下没有部门");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ functionStartPage();
|
|
|
+ List<StatisticsSummaryVO> res = fsCourseTrafficLogMapper.getStatisticsSummaryList(param);
|
|
|
+ //获取配置流量比例
|
|
|
+ SysConfig config = iSysConfigService.selectConfigByConfigKey("statis.config");
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(config.getConfigValue());
|
|
|
+ float trafficPrice = jsonObject.getFloatValue("trafficPrice");
|
|
|
+
|
|
|
+ for (StatisticsSummaryVO item : res) {
|
|
|
+ item.formatTraffic();
|
|
|
+ item.calculateAmount(new BigDecimal(trafficPrice));
|
|
|
+ if(byDept){
|
|
|
+ item.setDeptName(deptMp.get(item.getDeptId()).getFullPath());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ public static String addOneDay(String dateStr) {
|
|
|
+ // 将字符串解析为LocalDate对象
|
|
|
+ LocalDate date = LocalDate.parse(dateStr);
|
|
|
+
|
|
|
+ // 加一天
|
|
|
+ LocalDate newDate = date.plusDays(1);
|
|
|
+
|
|
|
+ // 转换回字符串
|
|
|
+ return newDate.toString();
|
|
|
+ }
|
|
|
+ protected void functionStartPage()
|
|
|
+ {
|
|
|
+ PageDomain pageDomain = TableSupport.buildPageRequest();
|
|
|
+ Integer pageNum = pageDomain.getPageNum();
|
|
|
+ Integer pageSize = pageDomain.getPageSize();
|
|
|
+ if (com.fs.common.utils.StringUtils.isNotNull(pageNum) && com.fs.common.utils.StringUtils.isNotNull(pageSize))
|
|
|
+ {
|
|
|
+ String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy());
|
|
|
+ Boolean reasonable = pageDomain.getReasonable();
|
|
|
+ PageHelper.startPage(pageNum, pageSize, orderBy).setReasonable(reasonable);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<StatisticsSummaryVO> getStatisticsSummaryListNotPage(StatisticsSummaryParam param){
|
|
|
+ if(StringUtils.isBlank(param.getStartDate()) && StringUtils.isBlank(param.getEndDate())){
|
|
|
+ throw new CustomException("必须要一个时间范围!");
|
|
|
+ }
|
|
|
+ param.setEndDateQueryValue(addOneDay(param.getEndDate()));
|
|
|
+ if(null == param.getStatisticsType()){
|
|
|
+ throw new CustomException("请选择统计类型");
|
|
|
+ }
|
|
|
+ Map<Long,DeptFullPathVO> deptMp = new HashMap<>();
|
|
|
+ boolean byDept = param.getStatisticsType().equals(2);
|
|
|
+ //按照部门方式汇总
|
|
|
+ if(byDept){
|
|
|
+ if(null == param.getCompanyId()){
|
|
|
+ throw new CustomException("请选择公司");
|
|
|
+ }
|
|
|
+ List<DeptFullPathVO> deptInfoList = companyDeptMapper.getDeptFullPathList(param.getCompanyId());
|
|
|
+ deptMp = deptInfoList.stream().collect(Collectors.toMap(DeptFullPathVO::getDeptId, item -> item));
|
|
|
+ if(CollectionUtils.isEmpty(deptInfoList)){
|
|
|
+ throw new CustomException("该公司下没有部门");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<StatisticsSummaryVO> res = fsCourseTrafficLogMapper.getStatisticsSummaryList(param);
|
|
|
+ //获取配置流量比例
|
|
|
+ SysConfig config = iSysConfigService.selectConfigByConfigKey("statis.config");
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(config.getConfigValue());
|
|
|
+ float trafficPrice = jsonObject.getFloatValue("trafficPrice");
|
|
|
+
|
|
|
+ for (StatisticsSummaryVO item : res) {
|
|
|
+ item.formatTraffic();
|
|
|
+ item.calculateAmount(new BigDecimal(trafficPrice));
|
|
|
+ if(byDept){
|
|
|
+ item.setDeptName(deptMp.get(item.getDeptId()).getFullPath());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
}
|