فهرست منبع

红德堂-看课流量统计增加导出

Long 5 روز پیش
والد
کامیت
e38838c0ec

+ 22 - 14
fs-admin/src/main/java/com/fs/course/controller/FsCourseTrafficLogController.java

@@ -1,16 +1,14 @@
 package com.fs.course.controller;
 
-import java.text.SimpleDateFormat;
-import java.time.format.DateTimeFormatter;
-import java.util.ArrayList;
 import java.util.List;
+import java.util.stream.Collectors;
 
 import com.fs.common.core.domain.R;
-import com.fs.common.exception.CustomException;
+import com.fs.common.utils.StringUtils;
+import com.fs.common.utils.bean.BeanUtils;
 import com.fs.course.param.FsCourseTrafficLogParam;
 import com.fs.course.param.InternetTrafficParam;
 import com.fs.course.vo.FsCourseTrafficLogListVO;
-import com.fs.qw.param.QwWatchLogStatisticsListParam;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -63,18 +61,28 @@ public class FsCourseTrafficLogController extends BaseController
     @GetMapping("/export")
     public AjaxResult export(FsCourseTrafficLogParam param)
     {
-        if (param.getTime() != null) {
-            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
-            String formattedDate = sdf.format(param.getTime());
-            String[] parts = formattedDate.split("-");
-            param.setYear(Integer.parseInt(parts[0]));
-            param.setMonth(Integer.parseInt(parts[1]));
-        }
-        List<FsCourseTrafficLogListVO> list = fsCourseTrafficLogService.selectTrafficByCompany(param);
-        ExcelUtil<FsCourseTrafficLogListVO> util = new ExcelUtil<FsCourseTrafficLogListVO>(FsCourseTrafficLogListVO.class);
+        List<FsCourseTrafficLogListVO> list = fsCourseTrafficLogService.selectTrafficNew(param);
+        list.forEach(vo -> {
+            // 流量转换
+            vo.setTotalInternetTrafficFormat(formatTraffic(vo.getTotalInternetTraffic()));
+        });
+        ExcelUtil<FsCourseTrafficLogListVO> util = new ExcelUtil<>(FsCourseTrafficLogListVO.class);
         return util.exportExcel(list, "短链课程流量记录数据");
     }
 
+    /**
+     * 流量转换
+     */
+    private static String formatTraffic(long bytes) {
+        if (bytes < 1024) return bytes + " B";
+        double kb = bytes / 1024.0;
+        if (kb < 1024) return String.format("%.2f KB", kb);
+        double mb = kb / 1024.0;
+        if (mb < 1024) return String.format("%.2f MB", mb);
+        double gb = mb / 1024.0;
+        return String.format("%.2f GB", gb);
+    }
+
     /**
      * 获取短链课程流量记录详细信息
      */

+ 8 - 5
fs-service/src/main/java/com/fs/course/vo/FsCourseTrafficLogListVO.java

@@ -1,7 +1,6 @@
 package com.fs.course.vo;
 
 import com.fs.common.annotation.Excel;
-import com.fs.common.core.domain.BaseEntity;
 import lombok.Data;
 
 import java.io.Serializable;
@@ -15,15 +14,19 @@ import java.io.Serializable;
 @Data
 public class FsCourseTrafficLogListVO implements Serializable
 {
+    @Excel(name = "公司")
     private String companyName;
     private Long companyId;
+    @Excel(name = "项目")
+    private String projectName;
+    @Excel(name = "课程")
     private String courseName;
     private Long courseId;
-    private String projectName;
     private Long project;
-
-    private Long totalInternetTraffic;
-
+    @Excel(name = "日期")
     private String month;
+    private Long totalInternetTraffic;
+    @Excel(name = "使用流量")
+    private String totalInternetTrafficFormat;
 
 }