From 236f6d2efa60de99eb3fad3e473e490788759b50 Mon Sep 17 00:00:00 2001 From: Raod <1130305001@qq.com> Date: Fri, 21 Jan 2022 10:48:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=A5=E8=A1=A8=E5=A2=9E=E5=8A=A0=E4=BD=9C?= =?UTF-8?q?=E8=80=85=E5=92=8C=E4=B8=8B=E8=BD=BD=E6=AC=A1=E6=95=B0=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/ReportDashboardServiceImpl.java | 13 +++++ .../report/controller/dto/ReportDto.java | 8 ++- .../modules/report/dao/entity/Report.java | 6 +++ .../modules/report/service/ReportService.java | 7 ++- .../service/impl/ReportServiceImpl.java | 21 ++++++++ .../gaea/business/util/RequestUtil.java | 50 +++++++++++++++++++ 6 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 report-core/src/main/java/com/anjiplus/template/gaea/business/util/RequestUtil.java diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dashboard/service/impl/ReportDashboardServiceImpl.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dashboard/service/impl/ReportDashboardServiceImpl.java index a14a69ac..fd3f2117 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dashboard/service/impl/ReportDashboardServiceImpl.java +++ b/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; } diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/report/controller/dto/ReportDto.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/report/controller/dto/ReportDto.java index 6849eba0..84e8d1c3 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/report/controller/dto/ReportDto.java +++ b/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; + } diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/report/dao/entity/Report.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/report/dao/entity/Report.java index 628255c8..09ed5f6f 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/report/dao/entity/Report.java +++ b/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; diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/report/service/ReportService.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/report/service/ReportService.java index 2abc8122..a09efd08 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/report/service/ReportService.java +++ b/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 { void delReport(ReportDto reportDto); + + /** + * 下载次数+1 + * @param reportCode + */ + void downloadStatistics(String reportCode); } diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/report/service/impl/ReportServiceImpl.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/report/service/impl/ReportServiceImpl.java index f0cfd30a..e5b32704 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/report/service/impl/ReportServiceImpl.java +++ b/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 { diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/util/RequestUtil.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/util/RequestUtil.java new file mode 100644 index 00000000..dda02739 --- /dev/null +++ b/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; + } +}