|
@@ -1,10 +1,13 @@
|
|
|
package com.fs.company.controller.course;
|
|
package com.fs.company.controller.course;
|
|
|
|
|
|
|
|
import com.fs.common.annotation.Log;
|
|
import com.fs.common.annotation.Log;
|
|
|
|
|
+import com.fs.common.constant.HttpStatus;
|
|
|
import com.fs.common.core.controller.BaseController;
|
|
import com.fs.common.core.controller.BaseController;
|
|
|
import com.fs.common.core.domain.AjaxResult;
|
|
import com.fs.common.core.domain.AjaxResult;
|
|
|
import com.fs.common.core.domain.R;
|
|
import com.fs.common.core.domain.R;
|
|
|
|
|
+import com.fs.common.core.page.PageDomain;
|
|
|
import com.fs.common.core.page.TableDataInfo;
|
|
import com.fs.common.core.page.TableDataInfo;
|
|
|
|
|
+import com.fs.common.core.page.TableSupport;
|
|
|
import com.fs.common.enums.BusinessType;
|
|
import com.fs.common.enums.BusinessType;
|
|
|
import com.fs.common.utils.poi.ExcelUtil;
|
|
import com.fs.common.utils.poi.ExcelUtil;
|
|
|
import com.fs.course.domain.FsCourseTrafficLog;
|
|
import com.fs.course.domain.FsCourseTrafficLog;
|
|
@@ -21,6 +24,7 @@ import org.springframework.web.bind.annotation.*;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.YearMonth;
|
|
import java.time.YearMonth;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
@@ -44,14 +48,65 @@ public class FsCourseTrafficLogController extends BaseController
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 查询短链课程流量记录列表
|
|
* 查询短链课程流量记录列表
|
|
|
|
|
+ * 每个公司只能查看自己公司的数据
|
|
|
*/
|
|
*/
|
|
|
@PreAuthorize("@ss.hasPermi('course:courseTrafficLog:list')")
|
|
@PreAuthorize("@ss.hasPermi('course:courseTrafficLog:list')")
|
|
|
@GetMapping("/list")
|
|
@GetMapping("/list")
|
|
|
public TableDataInfo list(FsCourseTrafficLogParam param)
|
|
public TableDataInfo list(FsCourseTrafficLogParam param)
|
|
|
{
|
|
{
|
|
|
- startPage();
|
|
|
|
|
|
|
+ // 获取当前登录用户的公司ID
|
|
|
|
|
+ Long companyId = tokenService.getLoginUser(com.fs.common.utils.ServletUtils.getRequest())
|
|
|
|
|
+ .getCompany().getCompanyId();
|
|
|
|
|
+
|
|
|
|
|
+ // 强制设置查询条件为当前公司ID,确保只能查看自己公司的数据
|
|
|
|
|
+ param.setCompanyId(companyId);
|
|
|
|
|
+
|
|
|
List<FsCourseTrafficLogListVO> list = fsCourseTrafficLogService.selectTrafficNew(param);
|
|
List<FsCourseTrafficLogListVO> list = fsCourseTrafficLogService.selectTrafficNew(param);
|
|
|
- return getDataTable(list);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 为每条记录计算流量和金额
|
|
|
|
|
+ for (FsCourseTrafficLogListVO vo : list) {
|
|
|
|
|
+ vo.formatTraffic();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 计算总和
|
|
|
|
|
+ FsCourseTrafficLogListVO sumTotal = new FsCourseTrafficLogListVO();
|
|
|
|
|
+ sumTotal.setCompanyName("合计");
|
|
|
|
|
+ Long totalTrafficSum = list.stream()
|
|
|
|
|
+ .filter(item -> item.getTotalInternetTraffic() != null)
|
|
|
|
|
+ .mapToLong(FsCourseTrafficLogListVO::getTotalInternetTraffic)
|
|
|
|
|
+ .sum();
|
|
|
|
|
+ sumTotal.setTotalInternetTraffic(totalTrafficSum);
|
|
|
|
|
+ // 为合计行计算流量和金额
|
|
|
|
|
+ sumTotal.formatTraffic();
|
|
|
|
|
+
|
|
|
|
|
+ // 获取分页参数
|
|
|
|
|
+ PageDomain pageDomain = TableSupport.buildPageRequest();
|
|
|
|
|
+ Integer pageNum = pageDomain.getPageNum();
|
|
|
|
|
+ Integer pageSize = pageDomain.getPageSize();
|
|
|
|
|
+
|
|
|
|
|
+ int total = list.size();
|
|
|
|
|
+ // 在内存中进行分页处理
|
|
|
|
|
+ if (pageNum != null && pageSize != null) {
|
|
|
|
|
+ int fromIndex = (pageNum - 1) * pageSize;
|
|
|
|
|
+ int toIndex = Math.min(fromIndex + pageSize, total);
|
|
|
|
|
+
|
|
|
|
|
+ // 确保索引不越界
|
|
|
|
|
+ if (fromIndex < total) {
|
|
|
|
|
+ list = list.subList(fromIndex, toIndex);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ list = new ArrayList<>(); // 返回空列表
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ list.add(sumTotal); // 将合计行添加到列表末尾
|
|
|
|
|
+
|
|
|
|
|
+ // 构造返回结果
|
|
|
|
|
+ TableDataInfo rspData = new TableDataInfo();
|
|
|
|
|
+ rspData.setCode(HttpStatus.SUCCESS);
|
|
|
|
|
+ rspData.setMsg("查询成功");
|
|
|
|
|
+ rspData.setRows(list);
|
|
|
|
|
+ rspData.setTotal(total);
|
|
|
|
|
+ return rspData;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|