瀏覽代碼

报表增加作者和下载次数功能

Raod 3 年之前
父節點
當前提交
236f6d2efa

+ 13 - 0
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dashboard/service/impl/ReportDashboardServiceImpl.java

@@ -16,6 +16,7 @@ import com.anjiplus.template.gaea.business.modules.dashboard.service.ReportDashb
 import com.anjiplus.template.gaea.business.modules.file.entity.GaeaFile;
 import com.anjiplus.template.gaea.business.modules.file.service.GaeaFileService;
 import com.anjiplus.template.gaea.business.modules.file.util.FileUtils;
+import com.anjiplus.template.gaea.business.modules.report.service.ReportService;
 import com.anjiplus.template.gaea.business.util.DateUtil;
 import com.anjiplus.template.gaea.business.modules.dashboardwidget.controller.dto.ReportDashboardWidgetDto;
 import com.anjiplus.template.gaea.business.modules.dashboardwidget.controller.dto.ReportDashboardWidgetValueDto;
@@ -26,6 +27,7 @@ import com.anjiplus.template.gaea.business.modules.dataset.controller.dto.DataSe
 import com.anjiplus.template.gaea.business.modules.dataset.controller.dto.OriginalDataDto;
 import com.anjiplus.template.gaea.business.modules.dataset.service.DataSetService;
 import com.anjiplus.template.gaea.business.util.FileUtil;
+import com.anjiplus.template.gaea.business.util.RequestUtil;
 import com.anjiplus.template.gaea.business.util.UuidUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -51,6 +53,7 @@ import java.io.File;
 import java.net.URLEncoder;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.concurrent.CompletableFuture;
 
 /**
  * @author Raod
@@ -74,6 +77,9 @@ public class ReportDashboardServiceImpl implements ReportDashboardService, Initi
     @Autowired
     private GaeaFileService gaeaFileService;
 
+    @Autowired
+    private ReportService reportService;
+
     @Value("${customer.file.downloadPath:''}")
     private String fileDownloadPath;
 
@@ -272,6 +278,13 @@ public class ReportDashboardServiceImpl implements ReportDashboardService, Initi
         FileUtil.delete(path);
         log.info("删除临时文件:{},{}", zipPath, path);
 
+        //异步统计下载次数
+        CompletableFuture.runAsync(() -> {
+            log.info("=======>ip:{} 下载模板:{}", RequestUtil.getIpAddr(request), reportCode);
+            reportService.downloadStatistics(reportCode);
+        });
+
+
         return body;
     }
 

+ 7 - 1
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/report/controller/dto/ReportDto.java

@@ -6,7 +6,6 @@ import lombok.Data;
 import java.io.Serializable;
 
 /**
- * TODO
  *
  * @author chenkening
  * @date 2021/3/26 10:34
@@ -50,4 +49,11 @@ public class ReportDto extends GaeaBaseDTO implements Serializable {
     /** 0--未删除 1--已删除 DIC_NAME=DELETE_FLAG */
     private Integer deleteFlag;
 
+
+    /** 报表作者 */
+    private String reportAuthor;
+
+    /** 下载次数 */
+    private Long downloadCount;
+
 }

+ 6 - 0
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/report/dao/entity/Report.java

@@ -36,6 +36,12 @@ public class Report extends GaeaBaseEntity {
     @ApiModelProperty(value = "报表缩略图")
     private String reportImage;
 
+    @ApiModelProperty(value = "报表作者")
+    private String reportAuthor;
+
+    @ApiModelProperty(value = "下载次数")
+    private Long downloadCount;
+
     @ApiModelProperty(value = "0--已禁用 1--已启用  DIC_NAME=ENABLE_FLAG")
     private Integer enableFlag;
 

+ 6 - 1
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/report/service/ReportService.java

@@ -6,7 +6,6 @@ import com.anjiplus.template.gaea.business.modules.report.controller.param.Repor
 import com.anjiplus.template.gaea.business.modules.report.dao.entity.Report;
 
 /**
- * TODO
  *
  * @author chenkening
  * @date 2021/3/26 10:35
@@ -14,4 +13,10 @@ import com.anjiplus.template.gaea.business.modules.report.dao.entity.Report;
 public interface ReportService extends GaeaBaseService<ReportParam, Report> {
 
     void delReport(ReportDto reportDto);
+
+    /**
+     * 下载次数+1
+     * @param reportCode
+     */
+    void downloadStatistics(String reportCode);
 }

+ 21 - 0
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/report/service/impl/ReportServiceImpl.java

@@ -34,6 +34,27 @@ public class ReportServiceImpl implements ReportService {
         //...
     }
 
+    /**
+     * 下载次数+1
+     *
+     * @param reportCode
+     */
+    @Override
+    public void downloadStatistics(String reportCode) {
+        Report report = selectOne("report_code", reportCode);
+        if (null != report) {
+            Long downloadCount = report.getDownloadCount();
+            if (null == downloadCount) {
+                downloadCount = 0L;
+            }else {
+                downloadCount++;
+            }
+            report.setDownloadCount(downloadCount);
+            update(report);
+        }
+
+    }
+
     @Override
     public void processBeforeOperation(Report entity, BaseOperationEnum operationEnum) throws BusinessException {
 

+ 50 - 0
report-core/src/main/java/com/anjiplus/template/gaea/business/util/RequestUtil.java

@@ -0,0 +1,50 @@
+package com.anjiplus.template.gaea.business.util;
+
+import org.apache.commons.lang3.StringUtils;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * @author: Raod
+ * @since: 2022-01-21
+ */
+public class RequestUtil {
+
+    /**获取ip地址
+     * @param request
+     * @return
+     */
+    public static String getIpAddr(HttpServletRequest request) {
+        String Xip = request.getHeader("X-Real-IP");
+        String XFor = request.getHeader("X-Forwarded-For");
+        if(StringUtils.isNotEmpty(XFor) && !"unKnown".equalsIgnoreCase(XFor)){
+            //多次反向代理后会有多个ip值,第一个ip才是真实ip
+            int index = XFor.indexOf(",");
+            if(index != -1){
+                return XFor.substring(0,index);
+            }else{
+                return XFor;
+            }
+        }
+        XFor = Xip;
+        if(StringUtils.isNotEmpty(XFor) && !"unKnown".equalsIgnoreCase(XFor)){
+            return XFor;
+        }
+        if (StringUtils.isBlank(XFor) || "unknown".equalsIgnoreCase(XFor)) {
+            XFor = request.getHeader("Proxy-Client-IP");
+        }
+        if (StringUtils.isBlank(XFor) || "unknown".equalsIgnoreCase(XFor)) {
+            XFor = request.getHeader("WL-Proxy-Client-IP");
+        }
+        if (StringUtils.isBlank(XFor) || "unknown".equalsIgnoreCase(XFor)) {
+            XFor = request.getHeader("HTTP_CLIENT_IP");
+        }
+        if (StringUtils.isBlank(XFor) || "unknown".equalsIgnoreCase(XFor)) {
+            XFor = request.getHeader("HTTP_X_FORWARDED_FOR");
+        }
+        if (StringUtils.isBlank(XFor) || "unknown".equalsIgnoreCase(XFor)) {
+            XFor = request.getRemoteAddr();
+        }
+        return XFor;
+    }
+}