From ebd2750533ba5240f5873818d24f7aee041ab038 Mon Sep 17 00:00:00 2001 From: Mzaxd Date: Wed, 26 Apr 2023 10:40:56 +0800 Subject: [PATCH 01/16] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/resources/application-dev.properties | 48 +++++++++---------- .../controller/ReportManageConroller.java | 12 +++++ 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/adc-da-main/src/main/resources/application-dev.properties b/adc-da-main/src/main/resources/application-dev.properties index 4231dbe..858d3b9 100644 --- a/adc-da-main/src/main/resources/application-dev.properties +++ b/adc-da-main/src/main/resources/application-dev.properties @@ -18,7 +18,7 @@ #spring.datasource.password = adc_forecast -#kylin数据库 ds1 +#kylin\u6570\u636E\u5E93 ds1 #spring.datasource.kylin.name=PROJECT_MI #spring.datasource.kylin.driverClassName=org.apache.kylin.jdbc.Driver #spring.datasource.kylin.url=jdbc:kylin://10.64.23.8:7070/PROJECT_MI @@ -28,32 +28,32 @@ #spring.datasource.kylin.maxWaitTime=10000 #spring.datasource.kylin.poolSize=10 # -##mysql数据库 ds2 +##mysql\u6570\u636E\u5E93 ds2 #spring.datasource.mysql.driverClassName = com.mysql.jdbc.Driver #spring.datasource.mysql.url = jdbc:mysql://192.168.144.80:3306/cadata?characterEncoding=utf-8&&zeroDateTimeBehavior=convertToNull #spring.datasource.mysql.username = root #spring.datasource.mysql.password = root spring.datasource.driverClassName = com.mysql.cj.jdbc.Driver -spring.datasource.url = jdbc:mysql://121.36.69.172:3307/report-library?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true +spring.datasource.url = jdbc:mysql://121.36.69.172:3307/report-library?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai spring.datasource.username = root spring.datasource.password = hzwlsoft.com -#后端端口 +#\u540E\u7AEF\u7AEF\u53E3 server.port=7060 -#验证码后台模式,默认为1:1为不开启,2为开启,3为输错 用户名或密码 ${maxLoginErrorCount} 次 才开启 +#\u9A8C\u8BC1\u7801\u540E\u53F0\u6A21\u5F0F\uFF0C\u9ED8\u8BA4\u4E3A1\uFF1A1\u4E3A\u4E0D\u5F00\u542F\uFF0C2\u4E3A\u5F00\u542F\uFF0C3\u4E3A\u8F93\u9519 \u7528\u6237\u540D\u6216\u5BC6\u7801 ${maxLoginErrorCount} \u6B21 \u624D\u5F00\u542F verifyCodeMode=3 -#仅当验证码模式 ${verifyCodeMode} 为 3时生效,设置错误登录出现验证码的阈值,默认为3 +#\u4EC5\u5F53\u9A8C\u8BC1\u7801\u6A21\u5F0F ${verifyCodeMode} \u4E3A 3\u65F6\u751F\u6548\uFF0C\u8BBE\u7F6E\u9519\u8BEF\u767B\u5F55\u51FA\u73B0\u9A8C\u8BC1\u7801\u7684\u9608\u503C\uFF0C\u9ED8\u8BA4\u4E3A3 maxLoginErrorCount=3 -#密码Base64加密开关,true为开启,false为关闭 +#\u5BC6\u7801Base64\u52A0\u5BC6\u5F00\u5173,true\u4E3A\u5F00\u542F,false\u4E3A\u5173\u95ED isPassEncrypted=true #{ #"password": "YWJjMTIz", #"username": "YWRtaW4x" #} -#swagger 显示api,1为只显示${restPath:/api}前缀的api,0为显示所有api,其他为不显示api +#swagger \u663E\u793Aapi\uFF0C1\u4E3A\u53EA\u663E\u793A${restPath:/api}\u524D\u7F00\u7684api,0\u4E3A\u663E\u793A\u6240\u6709api\uFF0C\u5176\u4ED6\u4E3A\u4E0D\u663E\u793Aapi swaggerLevel=0 @@ -61,9 +61,9 @@ swaggerLevel=0 # #picPath=/EPR/file/home/pic/ -# 本地存储文件的磁盘地址 +# \u672C\u5730\u5B58\u50A8\u6587\u4EF6\u7684\u78C1\u76D8\u5730\u5740 uploadFile=D:\\work\\idea\\changan\\ -# 本地文件访问的url地址 +# \u672C\u5730\u6587\u4EF6\u8BBF\u95EE\u7684url\u5730\u5740 picPath=/api/home/pic/ @@ -89,42 +89,42 @@ MAIL_POP_PORT=110 IPANDPORT=http://localhost:7061/ #redis -#Redis服务器地址 +#Redis\u670D\u52A1\u5668\u5730\u5740 spring.redis.host=192.168.144.29 #spring.redis.host=localhost -## Redis服务器连接端口 +## Redis\u670D\u52A1\u5668\u8FDE\u63A5\u7AEF\u53E3 spring.redis.port=6379 -## Redis服务器连接密码(默认为空) +## Redis\u670D\u52A1\u5668\u8FDE\u63A5\u5BC6\u7801\uFF08\u9ED8\u8BA4\u4E3A\u7A7A\uFF09 spring.redis.password=123321 -## 连接超时时间(毫秒) +## \u8FDE\u63A5\u8D85\u65F6\u65F6\u95F4\uFF08\u6BEB\u79D2\uFF09 spring.redis.timeout=200000ms -## 连接池中的最大空闲连接,默认值是8。 +## \u8FDE\u63A5\u6C60\u4E2D\u7684\u6700\u5927\u7A7A\u95F2\u8FDE\u63A5\uFF0C\u9ED8\u8BA4\u503C\u662F8\u3002 spring.redis.jedis.pool.max-idle=50 -##连接池中的最小空闲连接,默认值是0。 +##\u8FDE\u63A5\u6C60\u4E2D\u7684\u6700\u5C0F\u7A7A\u95F2\u8FDE\u63A5\uFF0C\u9ED8\u8BA4\u503C\u662F0\u3002 spring.redis.jedis.pool.min-idle=10 -## 如果赋值为-1,则表示不限制;如果pool已经分配了maxActive个jedis实例,则此时pool的状态为exhausted(耗尽)。 +## \u5982\u679C\u8D4B\u503C\u4E3A-1\uFF0C\u5219\u8868\u793A\u4E0D\u9650\u5236\uFF1B\u5982\u679Cpool\u5DF2\u7ECF\u5206\u914D\u4E86maxActive\u4E2Ajedis\u5B9E\u4F8B\uFF0C\u5219\u6B64\u65F6pool\u7684\u72B6\u6001\u4E3Aexhausted(\u8017\u5C3D)\u3002 spring.redis.jedis.pool.max-active=2000 -## 等待可用连接的最大时间,单位毫秒,默认值为-1,表示永不超时。如果超过等待时间,则直接抛出JedisConnectionException +## \u7B49\u5F85\u53EF\u7528\u8FDE\u63A5\u7684\u6700\u5927\u65F6\u95F4\uFF0C\u5355\u4F4D\u6BEB\u79D2\uFF0C\u9ED8\u8BA4\u503C\u4E3A-1\uFF0C\u8868\u793A\u6C38\u4E0D\u8D85\u65F6\u3002\u5982\u679C\u8D85\u8FC7\u7B49\u5F85\u65F6\u95F4\uFF0C\u5219\u76F4\u63A5\u629B\u51FAJedisConnectionException spring.redis.jedis.pool.max-wait=2000ms spring.redis.database=6 -# 上传方式:阿里云:alioss 华为云:hwobs -uploadType: hwobs +# \u4E0A\u4F20\u65B9\u5F0F\uFF1A\u963F\u91CC\u4E91\uFF1Aalioss \u534E\u4E3A\u4E91\uFF1Ahwobs \u672C\u5730\uFF1Alocal +uploadType: local -# ======= 阿里OSS配置 ========= +# ======= \u963F\u91CCOSS\u914D\u7F6E ========= aliyun.OSS.endpoint=https://oss-cn-hangzhou.aliyuncs.com aliyun.OSS.accessKeyId= LTAI5tBmUfVF6Z8R6sHTdTG7 aliyun.OSS.accessKeySecret= mY6UvWv20Tg2R46ORe6uV5gL6TQloC aliyun.OSS.bucketName=qqxexamplebucket -aliyun.OSS.fileMaxSize=10 #文件上传最大M数 +aliyun.OSS.fileMaxSize=10 #\u6587\u4EF6\u4E0A\u4F20\u6700\u5927M\u6570 -# ======= 华为OBS配置 ========= +# ======= \u534E\u4E3AOBS\u914D\u7F6E ========= huawei.OBS.endPoint=https://obs.cn-north-4.myhuaweicloud.com huawei.OBS.accessKey=EEMAGYTHP9KKPF18TZCL huawei.OBS.secretKey=3NmFNf1uX3EV1LbCEzgw6gDv0tZ6WAVwG37BGq1p huawei.OBS.bucketName=gcpa -huawei.OBS.fileMaxSize=10 #文件上传最大M数 +huawei.OBS.fileMaxSize=10 #\u6587\u4EF6\u4E0A\u4F20\u6700\u5927M\u6570 logging.level.com.adc: debug diff --git a/adc-da-report/src/main/java/com/adc/da/report/controller/ReportManageConroller.java b/adc-da-report/src/main/java/com/adc/da/report/controller/ReportManageConroller.java index 407bb60..44eeec0 100644 --- a/adc-da-report/src/main/java/com/adc/da/report/controller/ReportManageConroller.java +++ b/adc-da-report/src/main/java/com/adc/da/report/controller/ReportManageConroller.java @@ -26,6 +26,7 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.*; +import java.net.URISyntaxException; import java.net.URLEncoder; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -189,6 +190,17 @@ public class ReportManageConroller { stringRedisTemplate.boundValueOps("1121212").set("1212"); } + @ApiOperation("testPath") + @GetMapping("/testPath") + public ResponseMessage testPath() throws URISyntaxException { + HashMap pathMap = new HashMap<>(); + String jarPath = new File(getClass().getProtectionDomain().getCodeSource().getLocation().toURI().getPath()).getParentFile().getPath(); + String property = System.getProperty("user.dir"); + pathMap.put("jarpath", jarPath); + pathMap.put("propertyPath", property); + return Result.success(pathMap); + } + /** From aed4b71395d0a4de449a6b8f8ed4c0157e0faff7 Mon Sep 17 00:00:00 2001 From: Mzaxd Date: Wed, 26 Apr 2023 11:51:10 +0800 Subject: [PATCH 02/16] =?UTF-8?q?feat:=20=E6=9C=AC=E5=9C=B0=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增本地上传功能,上传路径可配置 --- .../target/classes/application-dev.properties | 51 ++++++++++--------- .../controller/ReportManageConroller.java | 19 ++++--- 2 files changed, 41 insertions(+), 29 deletions(-) diff --git a/adc-da-main/target/classes/application-dev.properties b/adc-da-main/target/classes/application-dev.properties index 4231dbe..1d60734 100644 --- a/adc-da-main/target/classes/application-dev.properties +++ b/adc-da-main/target/classes/application-dev.properties @@ -18,7 +18,7 @@ #spring.datasource.password = adc_forecast -#kylin数据库 ds1 +#kylin\u6570\u636E\u5E93 ds1 #spring.datasource.kylin.name=PROJECT_MI #spring.datasource.kylin.driverClassName=org.apache.kylin.jdbc.Driver #spring.datasource.kylin.url=jdbc:kylin://10.64.23.8:7070/PROJECT_MI @@ -28,7 +28,7 @@ #spring.datasource.kylin.maxWaitTime=10000 #spring.datasource.kylin.poolSize=10 # -##mysql数据库 ds2 +##mysql\u6570\u636E\u5E93 ds2 #spring.datasource.mysql.driverClassName = com.mysql.jdbc.Driver #spring.datasource.mysql.url = jdbc:mysql://192.168.144.80:3306/cadata?characterEncoding=utf-8&&zeroDateTimeBehavior=convertToNull #spring.datasource.mysql.username = root @@ -39,21 +39,21 @@ spring.datasource.url = jdbc:mysql://121.36.69.172:3307/report-library?character spring.datasource.username = root spring.datasource.password = hzwlsoft.com -#后端端口 +#\u540E\u7AEF\u7AEF\u53E3 server.port=7060 -#验证码后台模式,默认为1:1为不开启,2为开启,3为输错 用户名或密码 ${maxLoginErrorCount} 次 才开启 +#\u9A8C\u8BC1\u7801\u540E\u53F0\u6A21\u5F0F\uFF0C\u9ED8\u8BA4\u4E3A1\uFF1A1\u4E3A\u4E0D\u5F00\u542F\uFF0C2\u4E3A\u5F00\u542F\uFF0C3\u4E3A\u8F93\u9519 \u7528\u6237\u540D\u6216\u5BC6\u7801 ${maxLoginErrorCount} \u6B21 \u624D\u5F00\u542F verifyCodeMode=3 -#仅当验证码模式 ${verifyCodeMode} 为 3时生效,设置错误登录出现验证码的阈值,默认为3 +#\u4EC5\u5F53\u9A8C\u8BC1\u7801\u6A21\u5F0F ${verifyCodeMode} \u4E3A 3\u65F6\u751F\u6548\uFF0C\u8BBE\u7F6E\u9519\u8BEF\u767B\u5F55\u51FA\u73B0\u9A8C\u8BC1\u7801\u7684\u9608\u503C\uFF0C\u9ED8\u8BA4\u4E3A3 maxLoginErrorCount=3 -#密码Base64加密开关,true为开启,false为关闭 +#\u5BC6\u7801Base64\u52A0\u5BC6\u5F00\u5173,true\u4E3A\u5F00\u542F,false\u4E3A\u5173\u95ED isPassEncrypted=true #{ #"password": "YWJjMTIz", #"username": "YWRtaW4x" #} -#swagger 显示api,1为只显示${restPath:/api}前缀的api,0为显示所有api,其他为不显示api +#swagger \u663E\u793Aapi\uFF0C1\u4E3A\u53EA\u663E\u793A${restPath:/api}\u524D\u7F00\u7684api,0\u4E3A\u663E\u793A\u6240\u6709api\uFF0C\u5176\u4ED6\u4E3A\u4E0D\u663E\u793Aapi swaggerLevel=0 @@ -61,9 +61,14 @@ swaggerLevel=0 # #picPath=/EPR/file/home/pic/ -# 本地存储文件的磁盘地址 -uploadFile=D:\\work\\idea\\changan\\ -# 本地文件访问的url地址 +# \u672C\u5730\u6587\u4EF6\u5B58\u50A8\u8DEF\u5F84\u65B9\u5F0F jar\u5305\u8DEF\u5F84\uFF1Ajar \u5DE5\u4F5C\u76EE\u5F55\uFF1Auserdir \u56FA\u5B9A\u76EE\u5F55\uFF1Asettled +localSaveFileType=settled +#localSaveFileType=userdir + +# \u672C\u5730\u5B58\u50A8\u6587\u4EF6\u7684\u78C1\u76D8\u5730\u5740 +#uploadFile=D:\\work\\idea\\changan\\ +uploadFile=/data/DeploymentPackage/report_library/uploadfile +# \u672C\u5730\u6587\u4EF6\u8BBF\u95EE\u7684url\u5730\u5740 picPath=/api/home/pic/ @@ -89,42 +94,42 @@ MAIL_POP_PORT=110 IPANDPORT=http://localhost:7061/ #redis -#Redis服务器地址 +#Redis\u670D\u52A1\u5668\u5730\u5740 spring.redis.host=192.168.144.29 #spring.redis.host=localhost -## Redis服务器连接端口 +## Redis\u670D\u52A1\u5668\u8FDE\u63A5\u7AEF\u53E3 spring.redis.port=6379 -## Redis服务器连接密码(默认为空) +## Redis\u670D\u52A1\u5668\u8FDE\u63A5\u5BC6\u7801\uFF08\u9ED8\u8BA4\u4E3A\u7A7A\uFF09 spring.redis.password=123321 -## 连接超时时间(毫秒) +## \u8FDE\u63A5\u8D85\u65F6\u65F6\u95F4\uFF08\u6BEB\u79D2\uFF09 spring.redis.timeout=200000ms -## 连接池中的最大空闲连接,默认值是8。 +## \u8FDE\u63A5\u6C60\u4E2D\u7684\u6700\u5927\u7A7A\u95F2\u8FDE\u63A5\uFF0C\u9ED8\u8BA4\u503C\u662F8\u3002 spring.redis.jedis.pool.max-idle=50 -##连接池中的最小空闲连接,默认值是0。 +##\u8FDE\u63A5\u6C60\u4E2D\u7684\u6700\u5C0F\u7A7A\u95F2\u8FDE\u63A5\uFF0C\u9ED8\u8BA4\u503C\u662F0\u3002 spring.redis.jedis.pool.min-idle=10 -## 如果赋值为-1,则表示不限制;如果pool已经分配了maxActive个jedis实例,则此时pool的状态为exhausted(耗尽)。 +## \u5982\u679C\u8D4B\u503C\u4E3A-1\uFF0C\u5219\u8868\u793A\u4E0D\u9650\u5236\uFF1B\u5982\u679Cpool\u5DF2\u7ECF\u5206\u914D\u4E86maxActive\u4E2Ajedis\u5B9E\u4F8B\uFF0C\u5219\u6B64\u65F6pool\u7684\u72B6\u6001\u4E3Aexhausted(\u8017\u5C3D)\u3002 spring.redis.jedis.pool.max-active=2000 -## 等待可用连接的最大时间,单位毫秒,默认值为-1,表示永不超时。如果超过等待时间,则直接抛出JedisConnectionException +## \u7B49\u5F85\u53EF\u7528\u8FDE\u63A5\u7684\u6700\u5927\u65F6\u95F4\uFF0C\u5355\u4F4D\u6BEB\u79D2\uFF0C\u9ED8\u8BA4\u503C\u4E3A-1\uFF0C\u8868\u793A\u6C38\u4E0D\u8D85\u65F6\u3002\u5982\u679C\u8D85\u8FC7\u7B49\u5F85\u65F6\u95F4\uFF0C\u5219\u76F4\u63A5\u629B\u51FAJedisConnectionException spring.redis.jedis.pool.max-wait=2000ms spring.redis.database=6 -# 上传方式:阿里云:alioss 华为云:hwobs +# \u4E0A\u4F20\u65B9\u5F0F\uFF1A\u963F\u91CC\u4E91\uFF1Aalioss \u534E\u4E3A\u4E91\uFF1Ahwobs \u672C\u5730\uFF1Alocal uploadType: hwobs -# ======= 阿里OSS配置 ========= +# ======= \u963F\u91CCOSS\u914D\u7F6E ========= aliyun.OSS.endpoint=https://oss-cn-hangzhou.aliyuncs.com aliyun.OSS.accessKeyId= LTAI5tBmUfVF6Z8R6sHTdTG7 aliyun.OSS.accessKeySecret= mY6UvWv20Tg2R46ORe6uV5gL6TQloC aliyun.OSS.bucketName=qqxexamplebucket -aliyun.OSS.fileMaxSize=10 #文件上传最大M数 +aliyun.OSS.fileMaxSize=10 #\u6587\u4EF6\u4E0A\u4F20\u6700\u5927M\u6570 -# ======= 华为OBS配置 ========= +# ======= \u534E\u4E3AOBS\u914D\u7F6E ========= huawei.OBS.endPoint=https://obs.cn-north-4.myhuaweicloud.com huawei.OBS.accessKey=EEMAGYTHP9KKPF18TZCL huawei.OBS.secretKey=3NmFNf1uX3EV1LbCEzgw6gDv0tZ6WAVwG37BGq1p huawei.OBS.bucketName=gcpa -huawei.OBS.fileMaxSize=10 #文件上传最大M数 +huawei.OBS.fileMaxSize=10 #\u6587\u4EF6\u4E0A\u4F20\u6700\u5927M\u6570 logging.level.com.adc: debug diff --git a/adc-da-report/src/main/java/com/adc/da/report/controller/ReportManageConroller.java b/adc-da-report/src/main/java/com/adc/da/report/controller/ReportManageConroller.java index 44eeec0..2dbb23b 100644 --- a/adc-da-report/src/main/java/com/adc/da/report/controller/ReportManageConroller.java +++ b/adc-da-report/src/main/java/com/adc/da/report/controller/ReportManageConroller.java @@ -5,6 +5,7 @@ import com.adc.da.report.eo.FileEntity; import com.adc.da.report.eo.ReportEntity; import com.adc.da.report.service.IFileService; import com.adc.da.report.service.IReportService; +import com.adc.da.report.util.LocalFileUtil; import com.adc.da.report.util.OSSClientUtil; import com.adc.da.report.util.ObsBootUtil; import com.adc.da.report.vo.ReportQueryVo; @@ -63,6 +64,9 @@ public class ReportManageConroller { @Autowired private ObsBootUtil obsBootUtil; + @Autowired + private LocalFileUtil localFileUtil; + @Value("${uploadType}") private String uploadType; @@ -192,6 +196,7 @@ public class ReportManageConroller { } @ApiOperation("testPath") @GetMapping("/testPath") + @Deprecated public ResponseMessage testPath() throws URISyntaxException { HashMap pathMap = new HashMap<>(); String jarPath = new File(getClass().getProtectionDomain().getCodeSource().getLocation().toURI().getPath()).getParentFile().getPath(); @@ -201,8 +206,6 @@ public class ReportManageConroller { return Result.success(pathMap); } - - /** * 上传文件 * @param file @@ -236,10 +239,12 @@ public class ReportManageConroller { try{ String result=""; // 上传方式:阿里云:alioss 华为云:hwobs - if (uploadType.equals("hwobs")){ + if ("hwobs".equals(uploadType)){ result = obsBootUtil.upload(file, fileName); - }else if (uploadType.equals("alioss")){ + }else if ("alioss".equals(uploadType)) { result = ossClientUtil.uploadFile2OSS(file.getInputStream(),fileName); + }else if ("local".equals(uploadType)) { + localFileUtil.saveFile(file.getInputStream(), fileName); } resultMap.put("key", date + num); resultMap.put("value", path + "//" + fileName); @@ -351,10 +356,12 @@ public class ReportManageConroller { response.setContentType("application/x-download"); // File file = new File(uploadFile, entity.getSavePath()); // 上传方式:阿里云:alioss 华为云:hwobs - if (uploadType.equals("hwobs")){ + if ("hwobs".equals(uploadType)){ obsBootUtil.downFile(entity.getSavePath(), response); - }else if (uploadType.equals("alioss")){ + }else if ("alioss".equals(uploadType)){ ossClientUtil.downloadFileFromOSS(entity.getSavePath(),response); + }else if ("local".equals(uploadType)){ + //do nothing } } catch (Exception ex) { From 189aaa42c61c1da7f8fcbef16c45253eee4295ee Mon Sep 17 00:00:00 2001 From: Mzaxd Date: Wed, 26 Apr 2023 10:00:10 +0800 Subject: [PATCH 03/16] =?UTF-8?q?=E5=90=88=E5=B9=B6master=E5=88=B0caihaoha?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adc-da-report/pom.xml | 12 + .../report/client/ElasticSearchDocModel.java | 44 ++ .../client/ElasticSearchRestApiClient.java | 500 ++++++++++++++++++ .../da/report/config/ElasticSearchConfig.java | 102 ++++ .../report/config/ElasticSearchProperty.java | 53 ++ .../ElasticSearchTestController.java | 52 ++ .../da/report/exception/BaseException.java | 27 + .../exception/ElasticSearchRunException.java | 19 + .../com/adc/da/report/model/ReportInfo.java | 27 + .../service/impl/IReportServiceImpl.java | 3 + .../com/adc/da/report/util/PageUtils.java | 72 +++ 11 files changed, 911 insertions(+) create mode 100644 adc-da-report/src/main/java/com/adc/da/report/client/ElasticSearchDocModel.java create mode 100644 adc-da-report/src/main/java/com/adc/da/report/client/ElasticSearchRestApiClient.java create mode 100644 adc-da-report/src/main/java/com/adc/da/report/config/ElasticSearchConfig.java create mode 100644 adc-da-report/src/main/java/com/adc/da/report/config/ElasticSearchProperty.java create mode 100644 adc-da-report/src/main/java/com/adc/da/report/controller/ElasticSearchTestController.java create mode 100644 adc-da-report/src/main/java/com/adc/da/report/exception/BaseException.java create mode 100644 adc-da-report/src/main/java/com/adc/da/report/exception/ElasticSearchRunException.java create mode 100644 adc-da-report/src/main/java/com/adc/da/report/model/ReportInfo.java create mode 100644 adc-da-report/src/main/java/com/adc/da/report/util/PageUtils.java diff --git a/adc-da-report/pom.xml b/adc-da-report/pom.xml index acde4b8..3adf21d 100644 --- a/adc-da-report/pom.xml +++ b/adc-da-report/pom.xml @@ -118,6 +118,18 @@ spring-boot-starter-data-redis + + org.elasticsearch + elasticsearch + 7.6.2 + + + + org.elasticsearch.client + elasticsearch-rest-high-level-client + 7.6.2 + + diff --git a/adc-da-report/src/main/java/com/adc/da/report/client/ElasticSearchDocModel.java b/adc-da-report/src/main/java/com/adc/da/report/client/ElasticSearchDocModel.java new file mode 100644 index 0000000..4b11d0c --- /dev/null +++ b/adc-da-report/src/main/java/com/adc/da/report/client/ElasticSearchDocModel.java @@ -0,0 +1,44 @@ +package com.adc.da.report.client; + +/** + * ElasticSearch 批量操作公共model + * + * @author 程序员小强 + */ +public class ElasticSearchDocModel { + + /** + * 文档ID + *

+ */ + private String id; + + /** + * 文档内容 + */ + private T data; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public Object getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } + + public ElasticSearchDocModel() { + } + + public ElasticSearchDocModel(String id, T data) { + this.id = id; + this.data = data; + } +} diff --git a/adc-da-report/src/main/java/com/adc/da/report/client/ElasticSearchRestApiClient.java b/adc-da-report/src/main/java/com/adc/da/report/client/ElasticSearchRestApiClient.java new file mode 100644 index 0000000..3c80299 --- /dev/null +++ b/adc-da-report/src/main/java/com/adc/da/report/client/ElasticSearchRestApiClient.java @@ -0,0 +1,500 @@ +package com.adc.da.report.client; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.adc.da.report.exception.ElasticSearchRunException; +import com.adc.da.report.util.PageUtils; +import lombok.extern.slf4j.Slf4j; +import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.ElasticsearchStatusException; +import org.elasticsearch.action.DocWriteResponse; +import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; +import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest; +import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse; +import org.elasticsearch.action.bulk.BulkRequest; +import org.elasticsearch.action.delete.DeleteRequest; +import org.elasticsearch.action.delete.DeleteResponse; +import org.elasticsearch.action.get.*; +import org.elasticsearch.action.index.IndexRequest; +import org.elasticsearch.action.index.IndexResponse; +import org.elasticsearch.action.search.SearchRequest; +import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.action.support.master.AcknowledgedResponse; +import org.elasticsearch.action.update.UpdateRequest; +import org.elasticsearch.action.update.UpdateResponse; +import org.elasticsearch.client.RequestOptions; +import org.elasticsearch.client.RestHighLevelClient; +import org.elasticsearch.client.indices.CreateIndexRequest; +import org.elasticsearch.client.indices.CreateIndexResponse; +import org.elasticsearch.client.indices.GetIndexRequest; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.index.query.QueryBuilder; +import org.elasticsearch.index.reindex.DeleteByQueryRequest; +import org.elasticsearch.rest.RestStatus; +import org.elasticsearch.search.SearchHit; +import org.elasticsearch.search.builder.SearchSourceBuilder; +import org.elasticsearch.search.fetch.subphase.FetchSourceContext; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * ElasticSearch 客户端 RestHighLevelClient Api接口封装 + *

+ * 官方Api地址:https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.x/java-rest-high.html + * + */ +@Slf4j +@Component +public class ElasticSearchRestApiClient { + + @Autowired + private RestHighLevelClient restHighLevelClient; + + /** + * 默认主分片数 + */ + private static final int DEFAULT_SHARDS = 3; + /** + * 默认副本分片数 + */ + private static final int DEFAULT_REPLICAS = 2; + + /** + * 判断索引是否存在 + * + * @param index 索引 + * @return 返回 true,表示存在 + */ + public boolean existsIndex(String index) { + try { + GetIndexRequest request = new GetIndexRequest(index); + request.local(false); + request.humanReadable(true); + request.includeDefaults(false); + + return restHighLevelClient.indices().exists(request, RequestOptions.DEFAULT); + } catch (IOException e) { + log.error("[ elasticsearch ] >> get index exists exception ,index:{} ", index, e); + throw new ElasticSearchRunException("[ elasticsearch ] >> get index exists exception {}", e); + } + } + + /** + * 创建 ES 索引 + * + * @param index 索引 + * @param properties 文档属性集合 + * @return 返回 true,表示创建成功 + */ + public boolean createIndex(String index, Map properties) { + try { + XContentBuilder builder = XContentFactory.jsonBuilder(); + // 注:ES 7.x 后的版本中,已经弃用 type + builder.startObject() + .startObject("mappings") + .field("properties", properties) + .endObject() + .startObject("settings") + //分片数 + .field("number_of_shards", DEFAULT_SHARDS) + //副本数 + .field("number_of_replicas", DEFAULT_REPLICAS) + .endObject() + .endObject(); + CreateIndexRequest request = new CreateIndexRequest(index).source(builder); + CreateIndexResponse response = restHighLevelClient.indices().create(request, RequestOptions.DEFAULT); + return response.isAcknowledged(); + } catch (IOException e) { + log.error("[ elasticsearch ] >> createIndex exception ,index:{},properties:{}", index, properties, e); + throw new ElasticSearchRunException("[ elasticsearch ] >> createIndex exception "); + } + } + + /** + * 删除索引 + * + * @param index 索引 + * @return 返回 true,表示删除成功 + */ + public boolean deleteIndex(String index) { + try { + DeleteIndexRequest request = new DeleteIndexRequest(index); + AcknowledgedResponse response = restHighLevelClient.indices().delete(request, RequestOptions.DEFAULT); + + return response.isAcknowledged(); + } catch (ElasticsearchException e) { + //索引不存在-无需删除 + if (e.status() == RestStatus.NOT_FOUND) { + log.error("[ elasticsearch ] >> deleteIndex >> index:{}, Not found ", index, e); + return false; + } + log.error("[ elasticsearch ] >> deleteIndex exception ,index:{}", index, e); + throw new ElasticSearchRunException("elasticsearch deleteIndex exception "); + } catch (IOException e) { + //其它未知异常 + log.error("[ elasticsearch ] >> deleteIndex exception ,index:{}", index, e); + throw new ElasticSearchRunException("[ elasticsearch ] >> deleteIndex exception {}", e); + } + } + + /** + * 获取索引配置 + * + * @param index 索引 + * @return 返回索引配置内容 + */ + public GetSettingsResponse getIndexSetting(String index) { + try { + GetSettingsRequest request = new GetSettingsRequest().indices(index); + return restHighLevelClient.indices().getSettings(request, RequestOptions.DEFAULT); + } catch (IOException e) { + //其它未知异常 + log.error("[ elasticsearch ] >> getIndexSetting exception ,index:{}", index, e); + throw new ElasticSearchRunException("[ elasticsearch ] >> getIndexSetting exception {}", e); + } + } + + + /** + * 判断文档是否存在 + * + * @param index 索引 + * @return 返回 true,表示存在 + */ + public boolean existsDocument(String index, String id) { + try { + GetRequest request = new GetRequest(index, id); + //禁用获取_source + request.fetchSourceContext(new FetchSourceContext(false)); + //禁用获取存储的字段。 + request.storedFields("_none_"); + + return restHighLevelClient.exists(request, RequestOptions.DEFAULT); + } catch (IOException e) { + log.error("[ elasticsearch ] >> get document exists exception ,index:{} ", index, e); + throw new ElasticSearchRunException("[ elasticsearch ] >> get document exists exception {}", e); + } + } + + /** + * 保存数据-随机生成数据ID + * + * @param index 索引 + * @param dataValue 数据内容 + */ + public IndexResponse save(String index, Object dataValue) { + try { + IndexRequest request = new IndexRequest(index); + request.source(JSON.toJSONString(dataValue), XContentType.JSON); + return restHighLevelClient.index(request, RequestOptions.DEFAULT); + } catch (IOException e) { + log.error("[ elasticsearch ] >> save exception ,index = {},dataValue={} ,stack={}", index, dataValue, e); + throw new ElasticSearchRunException("[ elasticsearch ] >> save exception {}", e); + } + } + + /** + * 保存文档-自定义数据ID + * + * @param index 索引 + * @param id 数据ID + * @param dataValue 数据内容 + */ + public IndexResponse save(String index, String id, Object dataValue) { + return this.saveOrUpdate(index, id, dataValue); + } + + /** + * 保存文档-自定义数据ID + *

+ * 如果文档存在,则更新文档;如果文档不存在,则保存文档。 + * + * @param index 索引 + * @param id 数据ID + * @param dataValue 数据内容 + */ + public IndexResponse saveOrUpdate(String index, String id, Object dataValue) { + try { + IndexRequest request = new IndexRequest(index); + request.id(id); + request.source(JSON.toJSONString(dataValue), XContentType.JSON); + return restHighLevelClient.index(request, RequestOptions.DEFAULT); + } catch (IOException e) { + log.error("[ elasticsearch ] >> save exception ,index = {},dataValue={} ,stack={}", index, dataValue, e); + throw new ElasticSearchRunException("[ elasticsearch ] >> save exception {}", e); + } + } + + /** + * 批量-新增或保存文档 + *

+ * 如果集合中有些文档已经存在,则更新文档;不存在,则保存文档。 + * + * @param index 索引 + * @param documentList 文档集合 + */ + public void batchSaveOrUpdate(String index, List> documentList) { + if (CollectionUtils.isEmpty(documentList)) { + return; + } + try { + // 批量请求 + BulkRequest bulkRequest = new BulkRequest(); + documentList.forEach(doc -> bulkRequest.add(new IndexRequest(index) + .id(doc.getId()) + .source(JSON.toJSONString(doc.getData()), XContentType.JSON))); + restHighLevelClient.bulk(bulkRequest, RequestOptions.DEFAULT); + } catch (IOException e) { + log.error("[ elasticsearch ] >> batchSave exception ,index = {},documentList={} ,stack={}", index, documentList, e); + throw new ElasticSearchRunException("[ elasticsearch ] >> batchSave exception {}", e); + } + } + + /** + * 根据ID修改 + * + * @param index 索引 + * @param id 数据ID + * @param dataValue 数据内容 + */ + public UpdateResponse updateById(String index, String id, Object dataValue) { + try { + UpdateRequest request = new UpdateRequest(index, id); + request.doc(JSON.toJSONString(dataValue), XContentType.JSON); + return restHighLevelClient.update(request, RequestOptions.DEFAULT); + } catch (IOException e) { + log.error("[ elasticsearch ] >> updateById exception ,index = {},dataValue={} ,stack={}", index, dataValue, e); + throw new ElasticSearchRunException("[ elasticsearch ] >> updateById exception {}", e); + } + } + + /** + * 部分修改() + * 注:1).可变更已有字段值,可新增字段,删除字段无效 + * 2).若当前ID数据不存在则新增 + * + * @param index 索引 + * @param id 数据ID + * @param dataValue 数据内容 + */ + public UpdateResponse updateByIdSelective(String index, String id, Object dataValue) { + try { + JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(dataValue)); + UpdateRequest request = new UpdateRequest(index, id) + .doc(jsonObject) + .upsert(jsonObject); + return restHighLevelClient.update(request, RequestOptions.DEFAULT); + } catch (IOException e) { + log.error("[ elasticsearch ] >> updateByIdSelective exception ,index = {},dataValue={} ,stack={}", index, dataValue, e); + throw new ElasticSearchRunException("[ elasticsearch ] >> updateByIdSelective exception {}", e); + } + } + + /** + * 根据id查询 + * + * @param index 索引 + * @param id 数据ID + * @return T + */ + public T getById(String index, String id, Class clazz) { + GetResponse getResponse = this.getById(index, id); + if (null == getResponse) { + return null; + } + return JSON.parseObject(getResponse.getSourceAsString(), clazz); + } + + /** + * 根据id集批量获取数据 + * + * @param index 索引 + * @param idList 数据ID集 + * @return T + */ + public List getByIdList(String index, List idList, Class clazz) { + MultiGetItemResponse[] responses = this.getByIdList(index, idList); + if (null == responses || responses.length == 0) { + return new ArrayList<>(0); + } + + List resultList = new ArrayList<>(responses.length); + for (MultiGetItemResponse response : responses) { + GetResponse getResponse = response.getResponse(); + if (!getResponse.isExists()) { + continue; + } + resultList.add(JSON.parseObject(getResponse.getSourceAsString(), clazz)); + } + + return resultList; + } + + /** + * 根据多条件查询--分页 + * 注:from-size -[ "浅"分页 ] + * + * @param index 索引 + * @param pageNo 页码(第几页) + * @param pageSize 页容量- Elasticsearch默认配置单次最大限制10000 + */ + public List searchPageByIndex(String index, Integer pageNo, Integer pageSize, Class clazz) { + SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); + searchSourceBuilder.from(PageUtils.getStartRow(pageNo, pageSize)); + searchSourceBuilder.size(pageSize); + + return this.searchByQuery(index, searchSourceBuilder, clazz); + } + + /** + * 条件查询 + * + * @param index 索引 + * @param sourceBuilder 条件查询构建起 + * @param 数据类型 + * @return T 类型的集合 + */ + public List searchByQuery(String index, SearchSourceBuilder sourceBuilder, Class clazz) { + try { + // 构建查询请求 + SearchRequest searchRequest = new SearchRequest(index).source(sourceBuilder); + // 获取返回值 + SearchResponse response = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT); + SearchHit[] hits = response.getHits().getHits(); + if (null == hits || hits.length == 0) { + return new ArrayList<>(0); + } + + List resultList = new ArrayList<>(hits.length); + for (SearchHit hit : hits) { + resultList.add(JSON.parseObject(hit.getSourceAsString(), clazz)); + } + return resultList; + } catch (ElasticsearchStatusException e) { + //索引不存在 + if (e.status() == RestStatus.NOT_FOUND) { + log.error("[ elasticsearch ] >> searchByQuery exception >> index:{}, Not found ", index, e); + return new ArrayList<>(0); + } + throw new ElasticSearchRunException("[ elasticsearch ] >> searchByQuery exception {}", e); + } catch (IOException e) { + log.error("[ elasticsearch ] >> searchByQuery exception ,index = {},sourceBuilder={} ,stack={}", index, sourceBuilder, e); + throw new ElasticSearchRunException("[ elasticsearch ] >> searchByQuery exception {}", e); + } + } + + + /** + * 根据ID删除文档 + * + * @param index 索引 + * @param id 文档ID + * @return 是否删除成功 + */ + public boolean deleteById(String index, String id) { + try { + DeleteRequest request = new DeleteRequest(index, id); + DeleteResponse response = restHighLevelClient.delete(request, RequestOptions.DEFAULT); + //未找到文件 + if (response.getResult() == DocWriteResponse.Result.NOT_FOUND) { + log.error("[ elasticsearch ] >> deleteById document is not found , index:{},id:{}", index, id); + return false; + } + return RestStatus.OK.equals(response.status()); + } catch (IOException e) { + log.error("[ elasticsearch ] >> deleteById exception ,index:{},id:{} ,stack:{}", index, id, e); + throw new ElasticSearchRunException("[ elasticsearch ] >> deleteById exception {}", e); + } + } + + /** + * 根据查询条件删除文档 + * + * @param index 索引 + * @param queryBuilder 查询条件构建器 + */ + public void deleteByQuery(String index, QueryBuilder queryBuilder) { + try { + DeleteByQueryRequest request = new DeleteByQueryRequest(index).setQuery(queryBuilder); + request.setConflicts("proceed"); + restHighLevelClient.deleteByQuery(request, RequestOptions.DEFAULT); + } catch (IOException e) { + log.error("[ elasticsearch ] >> deleteByQuery exception ,index = {},queryBuilder={} ,stack={}", index, queryBuilder, e); + throw new ElasticSearchRunException("[ elasticsearch ] >> deleteByQuery exception {}", e); + } + } + + /** + * 根据文档 ID 批量删除文档 + * + * @param index 索引 + * @param idList 文档 ID 集合 + */ + public void deleteByIdList(String index, List idList) { + if (CollectionUtils.isEmpty(idList)) { + return; + } + try { + BulkRequest bulkRequest = new BulkRequest(); + idList.forEach(id -> bulkRequest.add(new DeleteRequest(index, id))); + restHighLevelClient.bulk(bulkRequest, RequestOptions.DEFAULT); + } catch (IOException e) { + log.error("[ elasticsearch ] >> deleteByIdList exception ,index = {},idList={} ,stack={}", index, idList, e); + throw new ElasticSearchRunException("[ elasticsearch ] >> deleteByIdList exception {}", e); + } + } + + /** + * 根据id查询 + * + * @param index 索引 + * @param id 文档ID + * @return GetResponse + */ + private GetResponse getById(String index, String id) { + try { + GetRequest request = new GetRequest(index, id); + return restHighLevelClient.get(request, RequestOptions.DEFAULT); + } catch (ElasticsearchException e) { + if (e.status() == RestStatus.NOT_FOUND) { + log.error("[ elasticsearch ] >> getById document not found ,index = {},id={} ,stack={}", index, id, e); + return null; + } + throw new ElasticSearchRunException("[ elasticsearch ] >> getById exception {}", e); + } catch (IOException e) { + log.error("[ elasticsearch ] >> getById exception ,index = {},id={} ,stack={}", index, id, e); + throw new ElasticSearchRunException("[ elasticsearch ] >> getById exception {}", e); + } + } + + /** + * 根据id集-批量获取数据 + * + * @param index 索引 + * @param idList 数据文档ID集 + * @return MultiGetItemResponse[] + */ + private MultiGetItemResponse[] getByIdList(String index, List idList) { + try { + MultiGetRequest request = new MultiGetRequest(); + for (String id : idList) { + request.add(new MultiGetRequest.Item(index, id)); + } + + //同步执行 + MultiGetResponse responses = restHighLevelClient.mget(request, RequestOptions.DEFAULT); + return responses.getResponses(); + } catch (IOException e) { + log.error("[ elasticsearch ] >> getByIdList exception ,index = {},idList={} ,stack={}", index, idList, e); + throw new ElasticSearchRunException("[ elasticsearch ] >> getByIdList exception {}", e); + } + } +} diff --git a/adc-da-report/src/main/java/com/adc/da/report/config/ElasticSearchConfig.java b/adc-da-report/src/main/java/com/adc/da/report/config/ElasticSearchConfig.java new file mode 100644 index 0000000..9156cf5 --- /dev/null +++ b/adc-da-report/src/main/java/com/adc/da/report/config/ElasticSearchConfig.java @@ -0,0 +1,102 @@ +package com.adc.da.report.config; + +import org.apache.http.HttpHost; +import org.apache.http.auth.AuthScope; +import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.client.CredentialsProvider; +import org.apache.http.impl.client.BasicCredentialsProvider; +import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; +import org.elasticsearch.client.Node; +import org.elasticsearch.client.RestClient; +import org.elasticsearch.client.RestClientBuilder; +import org.elasticsearch.client.RestHighLevelClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.util.Assert; +import org.springframework.util.StringUtils; + +import javax.annotation.Resource; + + +/** + * ElasticSearch Rest client 配置 + * + * @author 程序员小强 + */ +@Configuration +public class ElasticSearchConfig { + private static final Logger log = LoggerFactory.getLogger(ElasticSearchConfig.class); + + @Resource + private ElasticSearchProperty elasticSearchProperty; + + @Bean + public RestClientBuilder restClientBuilder() { + Assert.notNull(elasticSearchProperty, "elasticSearchProperty cannot null "); + Assert.notNull(elasticSearchProperty.getAddress(), "address hosts cannot null "); + + //ElasticSearch 连接地址地址 + HttpHost[] httpHosts = this.getElasticSearchHttpHosts(); + + return RestClient.builder(httpHosts).setRequestConfigCallback(requestConfigBuilder -> { + //设置连接超时时间 + requestConfigBuilder.setConnectTimeout(elasticSearchProperty.getConnectTimeout()); + requestConfigBuilder.setSocketTimeout(elasticSearchProperty.getSocketTimeout()); + requestConfigBuilder.setConnectionRequestTimeout(elasticSearchProperty.getConnectionRequestTimeout()); + return requestConfigBuilder; + }).setFailureListener(new RestClient.FailureListener() { + //某节点失败,这里可以添加一些异常告警 + @Override + public void onFailure(Node node) { + log.error("[ ElasticSearchClient ] >> node :{}, host:{}, fail ", node.getName(), node.getHost()); + } + }).setHttpClientConfigCallback(httpClientBuilder -> { + httpClientBuilder.disableAuthCaching(); + //设置账密 + return getHttpAsyncClientBuilder(httpClientBuilder); + }); + } + + /** + * ElasticSearch Rest client 配置 + * + * @return RestHighLevelClient + */ + @Bean + public RestHighLevelClient restHighLevelClient(@Qualifier("restClientBuilder") RestClientBuilder restClientBuilder) { + return new RestHighLevelClient(restClientBuilder); + } + + /** + * ElasticSearch 连接地址 + * 多个逗号分隔 + * 示例:127.0.0.1:9201,127.0.0.1:9202,127.0.0.1:9203 + */ + private HttpHost[] getElasticSearchHttpHosts() { + String[] hosts = elasticSearchProperty.getAddress().split(","); + HttpHost[] httpHosts = new HttpHost[hosts.length]; + for (int i = 0; i < httpHosts.length; i++) { + String host = hosts[i]; + host = host.replaceAll("http://", "").replaceAll("https://", ""); + Assert.isTrue(host.contains(":"), String.format("your host %s format error , Please refer to [ 127.0.0.1:9200 ] ", host)); + httpHosts[i] = new HttpHost(host.split(":")[0], Integer.parseInt(host.split(":")[1]), "http"); + } + return httpHosts; + } + + private HttpAsyncClientBuilder getHttpAsyncClientBuilder(HttpAsyncClientBuilder httpClientBuilder) { + if (StringUtils.isEmpty(elasticSearchProperty.getUserName()) || StringUtils.isEmpty(elasticSearchProperty.getPassword())) { + return httpClientBuilder; + } + //账密设置 + CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); + //es账号密码(一般使用,用户elastic) + credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(elasticSearchProperty.getUserName(), elasticSearchProperty.getPassword())); + httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); + return httpClientBuilder; + } +} + diff --git a/adc-da-report/src/main/java/com/adc/da/report/config/ElasticSearchProperty.java b/adc-da-report/src/main/java/com/adc/da/report/config/ElasticSearchProperty.java new file mode 100644 index 0000000..1b01c85 --- /dev/null +++ b/adc-da-report/src/main/java/com/adc/da/report/config/ElasticSearchProperty.java @@ -0,0 +1,53 @@ +package com.adc.da.report.config; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +/** + * ElasticSearch配置 + * + * @author 程序员小强 + */ +@Data +@Configuration +@ConfigurationProperties(prefix = "elasticsearch") +public class ElasticSearchProperty { + + /** + * 连接地址,格式:IP:端口 + * 多个逗号分隔 + * 示例:127.0.0.1:9201,127.0.0.1:9202,127.0.0.1:9203 + */ + private String address; + + /** + * 用户名 + */ + private String userName; + + /** + * 密码 + */ + private String password; + + /** + * 连接超时时间 + * 默认10s + */ + private int connectTimeout = 10000; + + /** + * socket超时时间 + * 默认10s + */ + private int socketTimeout = 10000; + + /** + * 请求连接超时时间 + * 默认10s + */ + private int connectionRequestTimeout = 10000; + +} + diff --git a/adc-da-report/src/main/java/com/adc/da/report/controller/ElasticSearchTestController.java b/adc-da-report/src/main/java/com/adc/da/report/controller/ElasticSearchTestController.java new file mode 100644 index 0000000..1f7b88b --- /dev/null +++ b/adc-da-report/src/main/java/com/adc/da/report/controller/ElasticSearchTestController.java @@ -0,0 +1,52 @@ +package com.adc.da.report.controller; + +import com.adc.da.report.client.ElasticSearchRestApiClient; +import com.adc.da.report.model.ReportInfo; +import lombok.extern.slf4j.Slf4j; +import org.elasticsearch.client.RestHighLevelClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.StringUtils; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author 程序员小强 + * @date 2020-12-14 10:21 + */ +@Slf4j +@RestController +@RequestMapping("/elasticSearch") +public class ElasticSearchTestController { + + @Autowired + private ElasticSearchRestApiClient restHighLevelClient; + + private static final String INDEX = "test_index"; + + /** + * 分页查询 + * 使用,from-size 的"浅"分页 + */ + @RequestMapping("searchPageByIndex") + public Object searchPageByIndex(@RequestParam(value = "pageNo", required = false) Integer pageNo, + @RequestParam(value = "pageSize", required = false) Integer pageSize, + @RequestParam(value = "index", required = false) String index) { + pageNo = pageNo == null ? 1 : pageNo; + pageSize = pageSize == null ? 10 : pageSize; + index = StringUtils.isEmpty(index) ? INDEX : index; + List dataList = restHighLevelClient.searchPageByIndex(index, pageNo, pageSize, ReportInfo.class); + + Map result = new HashMap<>(); + result.put("index", index); + result.put("pageNo", pageNo); + result.put("pageSize", pageSize); + result.put("dataList", dataList); + log.info("[ searchPageByIndex ] >> index:{},pageNo:{},pageSize:{}", index, pageNo, pageSize); + return result; + } +} diff --git a/adc-da-report/src/main/java/com/adc/da/report/exception/BaseException.java b/adc-da-report/src/main/java/com/adc/da/report/exception/BaseException.java new file mode 100644 index 0000000..6f6e4fd --- /dev/null +++ b/adc-da-report/src/main/java/com/adc/da/report/exception/BaseException.java @@ -0,0 +1,27 @@ +package com.adc.da.report.exception; + +import java.text.MessageFormat; + +/** + * 基础异常 + * + * @author 程序员小强 + */ +public class BaseException extends RuntimeException { + + public String msg; + + public BaseException(String message) { + super(message); + } + + public BaseException(String msgFormat, Object... args) { + super(MessageFormat.format(msgFormat, args)); + this.msg = MessageFormat.format(msgFormat, args); + } + + public String getMsg() { + return this.msg; + } + +} diff --git a/adc-da-report/src/main/java/com/adc/da/report/exception/ElasticSearchRunException.java b/adc-da-report/src/main/java/com/adc/da/report/exception/ElasticSearchRunException.java new file mode 100644 index 0000000..f75ce45 --- /dev/null +++ b/adc-da-report/src/main/java/com/adc/da/report/exception/ElasticSearchRunException.java @@ -0,0 +1,19 @@ +package com.adc.da.report.exception; + + +/** + * es 执行异常 + * + * @author 程序员小强 + */ +public class ElasticSearchRunException extends BaseException { + + public ElasticSearchRunException(String message) { + super(message); + } + + public ElasticSearchRunException(String mess, Object... args) { + super(mess, args); + } + +} diff --git a/adc-da-report/src/main/java/com/adc/da/report/model/ReportInfo.java b/adc-da-report/src/main/java/com/adc/da/report/model/ReportInfo.java new file mode 100644 index 0000000..327a084 --- /dev/null +++ b/adc-da-report/src/main/java/com/adc/da/report/model/ReportInfo.java @@ -0,0 +1,27 @@ +package com.adc.da.report.model; + + +import lombok.Data; + +import java.io.Serializable; + +/** + * 报表信息实体类 + * @author Caihaohan + */ +@Data +public class ReportInfo implements Serializable { + + private static final long serialVersionUID = 8802812229085206905L; + + /** + * 用户ID + */ + private String reportId; + + /** + * 文章内容 + */ + private String content; + +} diff --git a/adc-da-report/src/main/java/com/adc/da/report/service/impl/IReportServiceImpl.java b/adc-da-report/src/main/java/com/adc/da/report/service/impl/IReportServiceImpl.java index 63f95f6..1d6be45 100644 --- a/adc-da-report/src/main/java/com/adc/da/report/service/impl/IReportServiceImpl.java +++ b/adc-da-report/src/main/java/com/adc/da/report/service/impl/IReportServiceImpl.java @@ -28,6 +28,9 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.extern.slf4j.Slf4j; + +import javax.annotation.Resource; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.StringRedisTemplate; diff --git a/adc-da-report/src/main/java/com/adc/da/report/util/PageUtils.java b/adc-da-report/src/main/java/com/adc/da/report/util/PageUtils.java new file mode 100644 index 0000000..9c9f964 --- /dev/null +++ b/adc-da-report/src/main/java/com/adc/da/report/util/PageUtils.java @@ -0,0 +1,72 @@ +package com.adc.da.report.util; + +import java.util.ArrayList; +import java.util.List; + +/** + * 分页工具类 + * + * @author 程序员小强 + */ +public class PageUtils { + + /** + * 默认第一页 + */ + private static final int PAGE = 1; + + /** + * 默认一页10条 + */ + private static final int PAGE_SIZE = 10; + + + public static Integer getStartRow(Integer pageNo, Integer pageSize) { + if (null == pageNo) { + pageNo = PAGE; + } + if (null == pageSize) { + pageSize = PAGE_SIZE; + } + + return pageSize * (pageNo - 1); + } + + public static Integer getOffset(Integer pageSize) { + if (null == pageSize) { + pageSize = PAGE_SIZE; + } + return pageSize; + } + + /** + * list分页 + * + * @param list + * @param pageNo + * @param pageSize + */ + public static List listPage(List list, Integer pageNo, Integer pageSize) { + if (null == list || list.isEmpty()) { + return list; + } + if (null == pageNo) { + pageNo = PAGE; + } + if (null == pageSize) { + pageSize = PAGE_SIZE; + } + int totalCount = list.size(); + pageNo = pageNo - 1; + int fromIndex = pageNo * pageSize; + if (fromIndex > totalCount) { + return new ArrayList<>(0); + } + int toIndex = ((pageNo + 1) * pageSize); + if (toIndex > totalCount) { + toIndex = totalCount; + } + return list.subList(fromIndex, toIndex); + } + +} From 746a23ef94c22bfcdddf43cc45707c93784dd2ba Mon Sep 17 00:00:00 2001 From: Mzaxd Date: Wed, 26 Apr 2023 11:57:10 +0800 Subject: [PATCH 04/16] =?UTF-8?q?ci:=20=E6=9B=B4=E6=94=B9=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E9=BB=98=E8=AE=A4=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E4=B8=BA=E6=9C=AC=E5=9C=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/resources/application-dev.properties | 7 +- .../com/adc/da/report/util/LocalFileUtil.java | 73 +++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 adc-da-report/src/main/java/com/adc/da/report/util/LocalFileUtil.java diff --git a/adc-da-main/src/main/resources/application-dev.properties b/adc-da-main/src/main/resources/application-dev.properties index 858d3b9..6db4219 100644 --- a/adc-da-main/src/main/resources/application-dev.properties +++ b/adc-da-main/src/main/resources/application-dev.properties @@ -61,8 +61,13 @@ swaggerLevel=0 # #picPath=/EPR/file/home/pic/ +# \u672C\u5730\u6587\u4EF6\u5B58\u50A8\u8DEF\u5F84\u65B9\u5F0F jar\u5305\u8DEF\u5F84\uFF1Ajar \u5DE5\u4F5C\u76EE\u5F55\uFF1Auserdir \u56FA\u5B9A\u76EE\u5F55\uFF1Asettled +localSaveFileType=settled +#localSaveFileType=userdir + # \u672C\u5730\u5B58\u50A8\u6587\u4EF6\u7684\u78C1\u76D8\u5730\u5740 -uploadFile=D:\\work\\idea\\changan\\ +#uploadFile=D:\\work\\idea\\changan\\ +uploadFile=/data/DeploymentPackage/report_library/uploadfile # \u672C\u5730\u6587\u4EF6\u8BBF\u95EE\u7684url\u5730\u5740 picPath=/api/home/pic/ diff --git a/adc-da-report/src/main/java/com/adc/da/report/util/LocalFileUtil.java b/adc-da-report/src/main/java/com/adc/da/report/util/LocalFileUtil.java new file mode 100644 index 0000000..9e58c73 --- /dev/null +++ b/adc-da-report/src/main/java/com/adc/da/report/util/LocalFileUtil.java @@ -0,0 +1,73 @@ +package com.adc.da.report.util; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import java.io.*; +import java.net.URISyntaxException; + +/** + * @author Caihaohan + */ +@Slf4j +@Component +public class LocalFileUtil { + + @Value("${uploadFile}") + private String uploadFile; + + @Value("${localSaveFileType}") + private String localSaveFileType; + + /** + * 获取当前Jar包的路径 + * @return jar包路径 + */ + private String getJarPath() throws URISyntaxException { + return new File(LocalFileUtil.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()).getParentFile().getPath(); + } + + /** + * 获取当前工作目录路径 + * @return 当前工作目录路径 + */ + private String getUserDir() { + return System.getProperty("user.dir"); + } + + /** + * 按照配置文件里指定的方式返回对应路径 + * @return + */ + private String getPath() { + try { + switch (localSaveFileType) { + case "userdir": + return getUserDir(); + case "settled": + return uploadFile; + case "jar": + return getJarPath(); + default: + } + } catch (URISyntaxException e) { + log.info("获取Jar包路径失败,返回固定路径", e); + } + return uploadFile; + } + + public void saveFile(InputStream fileInputStream, String fileName) throws IOException { + // 获取当前工作目录并拼接文件名 + String path = getPath() + File.separator + fileName; + FileOutputStream fileOutputStream = new FileOutputStream(path); + byte[] buffer = new byte[1024]; + int length; + while ((length = fileInputStream.read(buffer)) > 0) { + fileOutputStream.write(buffer, 0, length); + } + fileInputStream.close(); + fileOutputStream.close(); + } + +} \ No newline at end of file From 01f967360cca711f7b7cbbec707e51a3b4f4cc8a Mon Sep 17 00:00:00 2001 From: Mzaxd Date: Wed, 26 Apr 2023 12:00:44 +0800 Subject: [PATCH 05/16] =?UTF-8?q?ci:=20=E5=A2=9E=E5=8A=A0ES=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application-dev.properties | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/adc-da-main/src/main/resources/application-dev.properties b/adc-da-main/src/main/resources/application-dev.properties index 6db4219..13b8787 100644 --- a/adc-da-main/src/main/resources/application-dev.properties +++ b/adc-da-main/src/main/resources/application-dev.properties @@ -138,3 +138,13 @@ iam.url=https://iamuat.faw-vw.com/ iam.appkey=xxxx iam.appSecret=xxx +# elasticSearch \u914D\u7F6E +# \u8FDE\u63A5\u591A\u4E2A\u9017\u53F7\u5206\u9694,\u683C\u5F0F(IP:\u7AEF\u53E3) +elasticsearch.address=121.36.69.172:9200 +#elasticsearch.address=localhost:9200 +#\u82E5\u5F00\u542F\u4E86\u9A8C\u8BC1\u5219\u9700\u8981\u914D\u7F6E +#elasticsearch.userName=elastic +#elasticsearch.password=1234567 +elasticsearch.connectTimeout=10000 +elasticsearch.socketTimeout=60000 +elasticsearch.connectionRequestTimeout=15000 \ No newline at end of file From 189fe69662d8994c035be7027101d8aee2a4c6c8 Mon Sep 17 00:00:00 2001 From: Mzaxd Date: Wed, 26 Apr 2023 14:09:34 +0800 Subject: [PATCH 06/16] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E6=89=BE=E4=B8=8D=E5=88=B0ES=E5=8C=85=E7=9A=84Bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adc-da-report/pom.xml | 7 +++++++ pom.xml | 12 ++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/adc-da-report/pom.xml b/adc-da-report/pom.xml index 3adf21d..2d3285b 100644 --- a/adc-da-report/pom.xml +++ b/adc-da-report/pom.xml @@ -118,6 +118,13 @@ spring-boot-starter-data-redis + + + org.elasticsearch.client + elasticsearch-rest-client + 7.6.2 + + org.elasticsearch elasticsearch diff --git a/pom.xml b/pom.xml index 995c7c9..01b5151 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ 2.5 1.10 1.10 - 2.4.6 + 1.4.0-RC2 8.5.37 3.16 @@ -332,11 +332,11 @@ ${aspectj.version} - - org.elasticsearch - elasticsearch - ${elasticsearch.version} - + + + + + org.jdom From 44971c6e60038a49f2768205b6769ff37fb8aa5e Mon Sep 17 00:00:00 2001 From: Mzaxd Date: Wed, 26 Apr 2023 14:10:45 +0800 Subject: [PATCH 07/16] =?UTF-8?q?ci:=20=E7=AE=80=E5=8C=96=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E4=B8=8A=E4=BC=A0=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/resources/application-dev.properties | 4 -- .../service/impl/IReportServiceImpl.java | 6 ++- .../com/adc/da/report/util/LocalFileUtil.java | 43 +------------------ 3 files changed, 5 insertions(+), 48 deletions(-) diff --git a/adc-da-main/src/main/resources/application-dev.properties b/adc-da-main/src/main/resources/application-dev.properties index 13b8787..5ded25d 100644 --- a/adc-da-main/src/main/resources/application-dev.properties +++ b/adc-da-main/src/main/resources/application-dev.properties @@ -61,10 +61,6 @@ swaggerLevel=0 # #picPath=/EPR/file/home/pic/ -# \u672C\u5730\u6587\u4EF6\u5B58\u50A8\u8DEF\u5F84\u65B9\u5F0F jar\u5305\u8DEF\u5F84\uFF1Ajar \u5DE5\u4F5C\u76EE\u5F55\uFF1Auserdir \u56FA\u5B9A\u76EE\u5F55\uFF1Asettled -localSaveFileType=settled -#localSaveFileType=userdir - # \u672C\u5730\u5B58\u50A8\u6587\u4EF6\u7684\u78C1\u76D8\u5730\u5740 #uploadFile=D:\\work\\idea\\changan\\ uploadFile=/data/DeploymentPackage/report_library/uploadfile diff --git a/adc-da-report/src/main/java/com/adc/da/report/service/impl/IReportServiceImpl.java b/adc-da-report/src/main/java/com/adc/da/report/service/impl/IReportServiceImpl.java index 1d6be45..1f5d9d4 100644 --- a/adc-da-report/src/main/java/com/adc/da/report/service/impl/IReportServiceImpl.java +++ b/adc-da-report/src/main/java/com/adc/da/report/service/impl/IReportServiceImpl.java @@ -536,10 +536,12 @@ public class IReportServiceImpl extends ServiceImpl String path = uploadFile + fileEntity.getSavePath(); FileOutputStream outputStream = new FileOutputStream(path); // 上传方式:阿里云:alioss 华为云:hwobs - if (uploadType.equals("hwobs")) { + if ("hwobs".equals(uploadType)) { obsBootUtil.getFileFromOBS(fileEntity.getSavePath(), outputStream); - } else if (uploadType.equals("alioss")) { + } else if ("alioss".equals(uploadType)) { ossClientUtil.getFileFromOSS(fileEntity.getSavePath(), outputStream); + } else if ("local".equals(uploadType)) { + // do nothing } String html = null; diff --git a/adc-da-report/src/main/java/com/adc/da/report/util/LocalFileUtil.java b/adc-da-report/src/main/java/com/adc/da/report/util/LocalFileUtil.java index 9e58c73..e0e4b8e 100644 --- a/adc-da-report/src/main/java/com/adc/da/report/util/LocalFileUtil.java +++ b/adc-da-report/src/main/java/com/adc/da/report/util/LocalFileUtil.java @@ -17,49 +17,8 @@ public class LocalFileUtil { @Value("${uploadFile}") private String uploadFile; - @Value("${localSaveFileType}") - private String localSaveFileType; - - /** - * 获取当前Jar包的路径 - * @return jar包路径 - */ - private String getJarPath() throws URISyntaxException { - return new File(LocalFileUtil.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()).getParentFile().getPath(); - } - - /** - * 获取当前工作目录路径 - * @return 当前工作目录路径 - */ - private String getUserDir() { - return System.getProperty("user.dir"); - } - - /** - * 按照配置文件里指定的方式返回对应路径 - * @return - */ - private String getPath() { - try { - switch (localSaveFileType) { - case "userdir": - return getUserDir(); - case "settled": - return uploadFile; - case "jar": - return getJarPath(); - default: - } - } catch (URISyntaxException e) { - log.info("获取Jar包路径失败,返回固定路径", e); - } - return uploadFile; - } - public void saveFile(InputStream fileInputStream, String fileName) throws IOException { - // 获取当前工作目录并拼接文件名 - String path = getPath() + File.separator + fileName; + String path = uploadFile + File.separator + fileName; FileOutputStream fileOutputStream = new FileOutputStream(path); byte[] buffer = new byte[1024]; int length; From 2b50369f0adfd3c09b7e160a8abc46641655a627 Mon Sep 17 00:00:00 2001 From: Mzaxd Date: Wed, 26 Apr 2023 16:28:36 +0800 Subject: [PATCH 08/16] =?UTF-8?q?feat:=20=E6=9C=AC=E5=9C=B0=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加本地上传功能,需在配置文件中配置 --- .../main/resources/application-dev.properties | 9 ++- .../service/impl/IReportServiceImpl.java | 5 +- .../com/adc/da/report/util/LocalFileUtil.java | 31 +++++++++- .../java/com/adc/da/report/util/PdfUtil.java | 62 ++++++++++++------- 4 files changed, 79 insertions(+), 28 deletions(-) diff --git a/adc-da-main/src/main/resources/application-dev.properties b/adc-da-main/src/main/resources/application-dev.properties index 5ded25d..7e5bae3 100644 --- a/adc-da-main/src/main/resources/application-dev.properties +++ b/adc-da-main/src/main/resources/application-dev.properties @@ -63,9 +63,11 @@ swaggerLevel=0 # \u672C\u5730\u5B58\u50A8\u6587\u4EF6\u7684\u78C1\u76D8\u5730\u5740 #uploadFile=D:\\work\\idea\\changan\\ -uploadFile=/data/DeploymentPackage/report_library/uploadfile +uploadFile=D:\\uploadfile\\tmp\\ +#uploadFile=/data/DeploymentPackage/report_library/uploadfile/ # \u672C\u5730\u6587\u4EF6\u8BBF\u95EE\u7684url\u5730\u5740 picPath=/api/home/pic/ +#picPath=D:\\uploadfile\\tmp\\pic\\ serverIp=http://127.0.0.1:7060/ @@ -92,11 +94,13 @@ IPANDPORT=http://localhost:7061/ #redis #Redis\u670D\u52A1\u5668\u5730\u5740 spring.redis.host=192.168.144.29 +#spring.redis.host=192.168.1.103 #spring.redis.host=localhost ## Redis\u670D\u52A1\u5668\u8FDE\u63A5\u7AEF\u53E3 spring.redis.port=6379 ## Redis\u670D\u52A1\u5668\u8FDE\u63A5\u5BC6\u7801\uFF08\u9ED8\u8BA4\u4E3A\u7A7A\uFF09 spring.redis.password=123321 +#spring.redis.password= ## \u8FDE\u63A5\u8D85\u65F6\u65F6\u95F4\uFF08\u6BEB\u79D2\uFF09 spring.redis.timeout=200000ms ## \u8FDE\u63A5\u6C60\u4E2D\u7684\u6700\u5927\u7A7A\u95F2\u8FDE\u63A5\uFF0C\u9ED8\u8BA4\u503C\u662F8\u3002 @@ -113,6 +117,9 @@ spring.redis.database=6 # \u4E0A\u4F20\u65B9\u5F0F\uFF1A\u963F\u91CC\u4E91\uFF1Aalioss \u534E\u4E3A\u4E91\uFF1Ahwobs \u672C\u5730\uFF1Alocal uploadType: local +# \u672C\u5730\u6587\u4EF6\u5B58\u50A8\u5730\u5740 +localFilePath=D:\\uploadfile\\ + # ======= \u963F\u91CCOSS\u914D\u7F6E ========= aliyun.OSS.endpoint=https://oss-cn-hangzhou.aliyuncs.com aliyun.OSS.accessKeyId= LTAI5tBmUfVF6Z8R6sHTdTG7 diff --git a/adc-da-report/src/main/java/com/adc/da/report/service/impl/IReportServiceImpl.java b/adc-da-report/src/main/java/com/adc/da/report/service/impl/IReportServiceImpl.java index 1f5d9d4..bfcefaf 100644 --- a/adc-da-report/src/main/java/com/adc/da/report/service/impl/IReportServiceImpl.java +++ b/adc-da-report/src/main/java/com/adc/da/report/service/impl/IReportServiceImpl.java @@ -93,6 +93,9 @@ public class IReportServiceImpl extends ServiceImpl @Autowired private RoleEODao roleEODao; + @Autowired + private LocalFileUtil localFileUtil; + /** * 新增或编辑报告 * @@ -541,7 +544,7 @@ public class IReportServiceImpl extends ServiceImpl } else if ("alioss".equals(uploadType)) { ossClientUtil.getFileFromOSS(fileEntity.getSavePath(), outputStream); } else if ("local".equals(uploadType)) { - // do nothing + localFileUtil.getFileFromLocal(fileEntity.getSavePath(), outputStream); } String html = null; diff --git a/adc-da-report/src/main/java/com/adc/da/report/util/LocalFileUtil.java b/adc-da-report/src/main/java/com/adc/da/report/util/LocalFileUtil.java index e0e4b8e..b931796 100644 --- a/adc-da-report/src/main/java/com/adc/da/report/util/LocalFileUtil.java +++ b/adc-da-report/src/main/java/com/adc/da/report/util/LocalFileUtil.java @@ -5,7 +5,6 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import java.io.*; -import java.net.URISyntaxException; /** * @author Caihaohan @@ -17,8 +16,11 @@ public class LocalFileUtil { @Value("${uploadFile}") private String uploadFile; + @Value("${localFilePath}") + private String localFilePath; + public void saveFile(InputStream fileInputStream, String fileName) throws IOException { - String path = uploadFile + File.separator + fileName; + String path = localFilePath + fileName; FileOutputStream fileOutputStream = new FileOutputStream(path); byte[] buffer = new byte[1024]; int length; @@ -29,4 +31,29 @@ public class LocalFileUtil { fileOutputStream.close(); } + public void getFileFromLocal(String savePath, FileOutputStream outputStream) throws IOException { + // 创建源文件对象 + File sourceFile = new File(localFilePath, savePath); + + // 如果源文件不存在,则抛出异常 + if (!sourceFile.exists()) { + throw new IOException("Source file does not exist."); + } + + // 创建输入流 + FileInputStream inputStream = new FileInputStream(sourceFile); + + // 创建缓冲区 + byte[] buffer = new byte[1024]; + int bytesRead; + + // 从输入流读取数据,并写入输出流 + while ((bytesRead = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); + } + + // 关闭输入流和输出流 + inputStream.close(); + outputStream.close(); + } } \ No newline at end of file diff --git a/adc-da-report/src/main/java/com/adc/da/report/util/PdfUtil.java b/adc-da-report/src/main/java/com/adc/da/report/util/PdfUtil.java index 93b699a..e555ba5 100644 --- a/adc-da-report/src/main/java/com/adc/da/report/util/PdfUtil.java +++ b/adc-da-report/src/main/java/com/adc/da/report/util/PdfUtil.java @@ -4,6 +4,8 @@ import com.adc.da.util.utils.UUID; import lombok.extern.slf4j.Slf4j; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.rendering.PDFRenderer; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; import sun.misc.BASE64Encoder; import javax.imageio.ImageIO; @@ -14,28 +16,37 @@ import java.util.ArrayList; import java.util.List; @Slf4j +@Component public class PdfUtil { - private PdfUtil(){ - throw new IllegalStateException("Utility class"); + private static String uploadType; + + @Value("${uploadType}") + public void setUploadType(String uploadType) { + PdfUtil.uploadType = uploadType; + } + + private PdfUtil() { + } /** * 截取pdf成图片 + * * @param inputStream * @param targetPath * @param ipAddress * @return */ - public static String pdfStreamToPng( InputStream inputStream,String targetPath,String ipAddress) { + public static String pdfStreamToPng(InputStream inputStream, String targetPath, String ipAddress) { - try(PDDocument doc=PDDocument.load( inputStream)) { + try (PDDocument doc = PDDocument.load(inputStream)) { PDFRenderer renderer = new PDFRenderer(doc); - List list=new ArrayList<>(); + List list = new ArrayList<>(); int pageCount = doc.getNumberOfPages(); BufferedImage image = null; - log.info("开始时间"+System.currentTimeMillis()); + log.info("开始时间" + System.currentTimeMillis()); String fileName = UUID.randomUUID10(); for (int i = 0; i < pageCount; i++) { image = renderer.renderImage(i, 2.0f); @@ -46,32 +57,35 @@ public class PdfUtil { imOut = ImageIO.createImageOutputStream(bs); ImageIO.write(image, "png", imOut); - try(ByteArrayInputStream byteInputStream = new ByteArrayInputStream(bs.toByteArray());){ - File ff=new File(targetPath+"/"+fileName); - if(!ff.exists()){ + try (ByteArrayInputStream byteInputStream = new ByteArrayInputStream(bs.toByteArray());) { + File ff = new File(targetPath + "/" + fileName); + if (!ff.exists()) { ff.mkdirs(); } - File uploadFile = new File(targetPath+"/"+fileName+"/"+i+".png"); - try(FileOutputStream fops = new FileOutputStream(uploadFile);){ + File uploadFile = new File(targetPath + "/" + fileName + "/" + i + ".png"); + try (FileOutputStream fops = new FileOutputStream(uploadFile);) { fops.write(readInputStream(byteInputStream)); - } - catch (Exception e){ - log.error(e.getMessage(),e); + } catch (Exception e) { + log.error(e.getMessage(), e); } - list.add(ipAddress+"api/home/pic"+"/"+fileName+"/"+i+".png"); - } - catch (Exception e){ + //判断是否是服务器环境 + if ("local".equals(uploadType)) { + list.add(targetPath + fileName + "/" + i + ".png"); + } else { + list.add(ipAddress + "api/home/pic" + "/" + fileName + "/" + i + ".png"); + } + } catch (Exception e) { } } - log.info("结束时间"+System.currentTimeMillis()); + log.info("结束时间" + System.currentTimeMillis()); - String htmlByBase64 = createHtmlByImg(list); + String htmlByBase64 = createHtmlByImg(list); return htmlByBase64; } catch (Exception e) { - log.error(e.getMessage(),e); + log.error(e.getMessage(), e); return ""; } } @@ -88,15 +102,15 @@ public class PdfUtil { buffer.append("\r\n"); - for(int i=0;i"); + for (int i = 0; i < baseList.size(); i++) { + buffer.append(""); } buffer.append(""); try { return buffer.toString(); } catch (Exception e) { - log.error(e.getMessage(),e); + log.error(e.getMessage(), e); return ""; } @@ -109,7 +123,7 @@ public class PdfUtil { public static byte[] readInputStream(InputStream inStream) throws Exception { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); - byte[] buffer = new byte[1024*1024]; + byte[] buffer = new byte[1024 * 1024]; int len = 0; while ((len = inStream.read(buffer)) != -1) { outStream.write(buffer, 0, len); From 906623936ef99a66698780cdd2679a1b3cd31a9e Mon Sep 17 00:00:00 2001 From: Mzaxd Date: Wed, 26 Apr 2023 17:31:17 +0800 Subject: [PATCH 09/16] =?UTF-8?q?feat:=20=E6=9C=AC=E5=9C=B0=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加本地文件下载功能 --- .../controller/ReportManageConroller.java | 2 +- .../com/adc/da/report/util/LocalFileUtil.java | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/adc-da-report/src/main/java/com/adc/da/report/controller/ReportManageConroller.java b/adc-da-report/src/main/java/com/adc/da/report/controller/ReportManageConroller.java index 2dbb23b..43e756a 100644 --- a/adc-da-report/src/main/java/com/adc/da/report/controller/ReportManageConroller.java +++ b/adc-da-report/src/main/java/com/adc/da/report/controller/ReportManageConroller.java @@ -361,7 +361,7 @@ public class ReportManageConroller { }else if ("alioss".equals(uploadType)){ ossClientUtil.downloadFileFromOSS(entity.getSavePath(),response); }else if ("local".equals(uploadType)){ - //do nothing + localFileUtil.downFile(entity.getSavePath(), response); } } catch (Exception ex) { diff --git a/adc-da-report/src/main/java/com/adc/da/report/util/LocalFileUtil.java b/adc-da-report/src/main/java/com/adc/da/report/util/LocalFileUtil.java index b931796..6204671 100644 --- a/adc-da-report/src/main/java/com/adc/da/report/util/LocalFileUtil.java +++ b/adc-da-report/src/main/java/com/adc/da/report/util/LocalFileUtil.java @@ -1,10 +1,15 @@ package com.adc.da.report.util; +import com.adc.da.util.exception.AdcDaBaseException; +import com.obs.services.exception.ObsException; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; +import javax.servlet.http.HttpServletResponse; import java.io.*; +import java.nio.file.Files; +import java.nio.file.Paths; /** * @author Caihaohan @@ -56,4 +61,26 @@ public class LocalFileUtil { inputStream.close(); outputStream.close(); } + + public void downFile(String savePath, HttpServletResponse response) throws IOException { + String filePath = uploadFile + savePath; + + //复制到本地 + FileOutputStream fileOutputStream = new FileOutputStream(filePath); + getFileFromLocal(savePath, fileOutputStream); + + //将文件写到response中 + try (InputStream objectContent = Files.newInputStream(Paths.get(filePath))) { + byte[] bt = new byte[1024 * 1024]; + int len = 0; + while ((len = objectContent.read(bt)) != -1) { + response.getOutputStream().write(bt, 0, len); + } + } catch (ObsException | IOException oe) { + throw new AdcDaBaseException("获取本地文件失败"); + } finally { + // 数据读取完成后,获取的流必须关闭,否则会造成连接泄漏,导致请求无连接可用,程序无法正常工作。 + response.getOutputStream().close(); + } + } } \ No newline at end of file From 8fbe459c317d1d3ff3a6f46b0f374f49ac704ba1 Mon Sep 17 00:00:00 2001 From: Mzaxd Date: Thu, 27 Apr 2023 10:48:33 +0800 Subject: [PATCH 10/16] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=A2=84?= =?UTF-8?q?=E8=A7=88=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 报表上传以后目前可以正常预览 --- .../main/java/com/adc/da/main/config/WebMvcConfig.java | 2 +- adc-da-main/src/main/resources/application-dev.properties | 2 -- .../src/main/java/com/adc/da/report/util/PdfUtil.java | 8 ++------ 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/adc-da-main/src/main/java/com/adc/da/main/config/WebMvcConfig.java b/adc-da-main/src/main/java/com/adc/da/main/config/WebMvcConfig.java index da045a1..968ab09 100644 --- a/adc-da-main/src/main/java/com/adc/da/main/config/WebMvcConfig.java +++ b/adc-da-main/src/main/java/com/adc/da/main/config/WebMvcConfig.java @@ -21,7 +21,7 @@ public class WebMvcConfig implements WebMvcConfigurer { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { // /home/file/**为前端URL访问路径 后面 file:xxxx为本地磁盘映射 - registry.addResourceHandler(picPath+"**").addResourceLocations("file://"+uploadFile); + registry.addResourceHandler(picPath + "**").addResourceLocations("file:" + uploadFile); } } diff --git a/adc-da-main/src/main/resources/application-dev.properties b/adc-da-main/src/main/resources/application-dev.properties index 7e5bae3..5d1090d 100644 --- a/adc-da-main/src/main/resources/application-dev.properties +++ b/adc-da-main/src/main/resources/application-dev.properties @@ -67,8 +67,6 @@ uploadFile=D:\\uploadfile\\tmp\\ #uploadFile=/data/DeploymentPackage/report_library/uploadfile/ # \u672C\u5730\u6587\u4EF6\u8BBF\u95EE\u7684url\u5730\u5740 picPath=/api/home/pic/ -#picPath=D:\\uploadfile\\tmp\\pic\\ - serverIp=http://127.0.0.1:7060/ diff --git a/adc-da-report/src/main/java/com/adc/da/report/util/PdfUtil.java b/adc-da-report/src/main/java/com/adc/da/report/util/PdfUtil.java index e555ba5..9fb2c15 100644 --- a/adc-da-report/src/main/java/com/adc/da/report/util/PdfUtil.java +++ b/adc-da-report/src/main/java/com/adc/da/report/util/PdfUtil.java @@ -69,12 +69,8 @@ public class PdfUtil { log.error(e.getMessage(), e); } - //判断是否是服务器环境 - if ("local".equals(uploadType)) { - list.add(targetPath + fileName + "/" + i + ".png"); - } else { - list.add(ipAddress + "api/home/pic" + "/" + fileName + "/" + i + ".png"); - } + list.add(ipAddress + "api/home/pic" + "/" + fileName + "/" + i + ".png"); + } catch (Exception e) { } From 9b5112592628229f3a37de4ef555fcc94fd2a893 Mon Sep 17 00:00:00 2001 From: bupengxiang Date: Mon, 24 Apr 2023 21:55:16 +0800 Subject: [PATCH 11/16] =?UTF-8?q?=E5=90=88=E5=B9=B6master=E5=88=B0caihaoha?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business_main/entity/TaskEntity.java | 73 +++++++++++++++++++ .../business_main/mapper/TaskMapper.java | 18 +++++ 2 files changed, 91 insertions(+) create mode 100644 report-activity/src/main/java/com/adc/da/wkflow/business_main/entity/TaskEntity.java create mode 100644 report-activity/src/main/java/com/adc/da/wkflow/business_main/mapper/TaskMapper.java diff --git a/report-activity/src/main/java/com/adc/da/wkflow/business_main/entity/TaskEntity.java b/report-activity/src/main/java/com/adc/da/wkflow/business_main/entity/TaskEntity.java new file mode 100644 index 0000000..e6501a0 --- /dev/null +++ b/report-activity/src/main/java/com/adc/da/wkflow/business_main/entity/TaskEntity.java @@ -0,0 +1,73 @@ +package com.adc.da.wkflow.business_main.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.util.Date; + +@Data +@TableName("ACT_RU_TASK") +public class TaskEntity { + + @TableId(value = "ID_", type = IdType.INPUT) + private String id; + + @TableField("REV_") + private int rev; + + @TableField("EXECUTION_ID_") + private String executionId; + + @TableField("PROC_INST_ID_") + private String processInstanceId; + + @TableField("PROC_DEF_ID_") + private String processDefinitionId; + + @TableField("NAME_") + private String name; + + @TableField("PARENT_TASK_ID_") + private String parentTaskId; + + @TableField("DESCRIPTION_") + private String description; + + @TableField("TASK_DEF_KEY_") + private String taskDefinitionKey; + + @TableField("OWNER_") + private String owner; + + @TableField("ASSIGNEE_") + private String assignee; + + @TableField("DELEGATION_") + private String delegation; + + @TableField("PRIORITY_") + private int priority; + + @TableField("CREATE_TIME_") + private Date createTime; + + @TableField("DUE_DATE_") + private Date dueDate; + + @TableField("CATEGORY_") + private String category; + + @TableField("SUSPENSION_STATE_") + private int suspensionState; + + @TableField("TENANT_ID_") + private String tenantId; + + @TableField("FORM_KEY_") + private String formKey; + + +} diff --git a/report-activity/src/main/java/com/adc/da/wkflow/business_main/mapper/TaskMapper.java b/report-activity/src/main/java/com/adc/da/wkflow/business_main/mapper/TaskMapper.java new file mode 100644 index 0000000..67f4985 --- /dev/null +++ b/report-activity/src/main/java/com/adc/da/wkflow/business_main/mapper/TaskMapper.java @@ -0,0 +1,18 @@ +package com.adc.da.wkflow.business_main.mapper; + +import com.adc.da.wkflow.business_activiti.dto.TaskCommonQuery; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import org.activiti.engine.task.Task; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +public interface TaskMapper extends BaseMapper { + + + List todoTaskList(Page page, @Param("pageVO") TaskCommonQuery taskCommonQuery); + + long todoTaskListCount(@Param("pageVO") TaskCommonQuery taskCommonQuery); + +} From 1763720520a73c6cc510d1a7b2ad52f39dedbcf2 Mon Sep 17 00:00:00 2001 From: bupengxiang Date: Tue, 25 Apr 2023 09:18:52 +0800 Subject: [PATCH 12/16] =?UTF-8?q?[=E6=96=B0=E5=A2=9E]=20=E4=BB=A3=E5=8A=9E?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business_main/entity/TaskEntity.java | 73 ------------------- .../business_main/mapper/TaskMapper.java | 18 ----- 2 files changed, 91 deletions(-) delete mode 100644 report-activity/src/main/java/com/adc/da/wkflow/business_main/entity/TaskEntity.java delete mode 100644 report-activity/src/main/java/com/adc/da/wkflow/business_main/mapper/TaskMapper.java diff --git a/report-activity/src/main/java/com/adc/da/wkflow/business_main/entity/TaskEntity.java b/report-activity/src/main/java/com/adc/da/wkflow/business_main/entity/TaskEntity.java deleted file mode 100644 index e6501a0..0000000 --- a/report-activity/src/main/java/com/adc/da/wkflow/business_main/entity/TaskEntity.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.adc.da.wkflow.business_main.entity; - -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; - -import java.util.Date; - -@Data -@TableName("ACT_RU_TASK") -public class TaskEntity { - - @TableId(value = "ID_", type = IdType.INPUT) - private String id; - - @TableField("REV_") - private int rev; - - @TableField("EXECUTION_ID_") - private String executionId; - - @TableField("PROC_INST_ID_") - private String processInstanceId; - - @TableField("PROC_DEF_ID_") - private String processDefinitionId; - - @TableField("NAME_") - private String name; - - @TableField("PARENT_TASK_ID_") - private String parentTaskId; - - @TableField("DESCRIPTION_") - private String description; - - @TableField("TASK_DEF_KEY_") - private String taskDefinitionKey; - - @TableField("OWNER_") - private String owner; - - @TableField("ASSIGNEE_") - private String assignee; - - @TableField("DELEGATION_") - private String delegation; - - @TableField("PRIORITY_") - private int priority; - - @TableField("CREATE_TIME_") - private Date createTime; - - @TableField("DUE_DATE_") - private Date dueDate; - - @TableField("CATEGORY_") - private String category; - - @TableField("SUSPENSION_STATE_") - private int suspensionState; - - @TableField("TENANT_ID_") - private String tenantId; - - @TableField("FORM_KEY_") - private String formKey; - - -} diff --git a/report-activity/src/main/java/com/adc/da/wkflow/business_main/mapper/TaskMapper.java b/report-activity/src/main/java/com/adc/da/wkflow/business_main/mapper/TaskMapper.java deleted file mode 100644 index 67f4985..0000000 --- a/report-activity/src/main/java/com/adc/da/wkflow/business_main/mapper/TaskMapper.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.adc.da.wkflow.business_main.mapper; - -import com.adc.da.wkflow.business_activiti.dto.TaskCommonQuery; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import org.activiti.engine.task.Task; -import org.apache.ibatis.annotations.Param; - -import java.util.List; - -public interface TaskMapper extends BaseMapper { - - - List todoTaskList(Page page, @Param("pageVO") TaskCommonQuery taskCommonQuery); - - long todoTaskListCount(@Param("pageVO") TaskCommonQuery taskCommonQuery); - -} From 9c54f2d52a452975a16fbd2b18762658fec0c9af Mon Sep 17 00:00:00 2001 From: bupengxiang Date: Tue, 25 Apr 2023 21:05:37 +0800 Subject: [PATCH 13/16] =?UTF-8?q?[=E6=96=B0=E5=A2=9E]=20=E6=9D=83=E9=99=90?= =?UTF-8?q?=E7=94=B3=E8=AF=B7=E6=B5=81=E7=A8=8B=20=E5=8F=8A=20=E5=B7=A5?= =?UTF-8?q?=E4=BD=9C=E5=8F=B0=E7=9A=84=E6=8E=A5=E5=8F=A3=20=E5=BC=80?= =?UTF-8?q?=E5=8F=91=E5=AE=8C=E6=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/resources/mybatis/mapper/mysql/ReportManageMapper.xml | 3 --- 1 file changed, 3 deletions(-) diff --git a/adc-da-report/src/main/resources/mybatis/mapper/mysql/ReportManageMapper.xml b/adc-da-report/src/main/resources/mybatis/mapper/mysql/ReportManageMapper.xml index b4d36de..6b52bac 100644 --- a/adc-da-report/src/main/resources/mybatis/mapper/mysql/ReportManageMapper.xml +++ b/adc-da-report/src/main/resources/mybatis/mapper/mysql/ReportManageMapper.xml @@ -304,9 +304,6 @@ and name like CONCAT(CONCAT('%',#{pageVO.name}),'%') - - and keycontent like CONCAT(CONCAT('%',#{pageVO.keyContent}),'%') - and year in From a1db2cd9fd44cb58518fdf3e95ea1531711ffc07 Mon Sep 17 00:00:00 2001 From: Mzaxd Date: Thu, 27 Apr 2023 17:41:42 +0800 Subject: [PATCH 14/16] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=8A=A5?= =?UTF-8?q?=E8=A1=A8=E6=8E=A5=E5=8F=A3=20=E6=96=87=E4=BB=B6=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E5=AD=98=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 现在报表添加接口,会同时将报表文件的内容存入数据库 --- .../controller/ReportManageConroller.java | 2 +- .../adc/da/report/service/IReportService.java | 3 +- .../service/impl/IReportServiceImpl.java | 11 +- .../mapper/mysql/ReportManageMapper.xml | 127 ++---------------- 4 files changed, 24 insertions(+), 119 deletions(-) diff --git a/adc-da-report/src/main/java/com/adc/da/report/controller/ReportManageConroller.java b/adc-da-report/src/main/java/com/adc/da/report/controller/ReportManageConroller.java index 43e756a..f203b8c 100644 --- a/adc-da-report/src/main/java/com/adc/da/report/controller/ReportManageConroller.java +++ b/adc-da-report/src/main/java/com/adc/da/report/controller/ReportManageConroller.java @@ -79,7 +79,7 @@ public class ReportManageConroller { @ApiOperation("新增或编辑报告") @PostMapping("/add") @ReportLog(description = "新增或编辑") - public ResponseMessage add(@RequestBody ReportVo vo) { + public ResponseMessage add(@RequestBody ReportVo vo) throws IOException { ReportEntity entity = new ReportEntity(); BeanUtils.copyProperties(vo, entity); String name = reportService.insert(entity, vo.getLabelList()); diff --git a/adc-da-report/src/main/java/com/adc/da/report/service/IReportService.java b/adc-da-report/src/main/java/com/adc/da/report/service/IReportService.java index 30bb799..52281eb 100644 --- a/adc-da-report/src/main/java/com/adc/da/report/service/IReportService.java +++ b/adc-da-report/src/main/java/com/adc/da/report/service/IReportService.java @@ -5,6 +5,7 @@ import com.adc.da.report.vo.ReportQueryVo; import com.adc.da.report.vo.ReportVo; import com.baomidou.mybatisplus.core.metadata.IPage; +import java.io.IOException; import java.util.List; /** @@ -20,7 +21,7 @@ public interface IReportService { * @param labelList * @return 报告名称 */ - String insert(ReportEntity entity, List labelList); + String insert(ReportEntity entity, List labelList) throws IOException; /** * 报告列表展示 diff --git a/adc-da-report/src/main/java/com/adc/da/report/service/impl/IReportServiceImpl.java b/adc-da-report/src/main/java/com/adc/da/report/service/impl/IReportServiceImpl.java index bfcefaf..c36cb2a 100644 --- a/adc-da-report/src/main/java/com/adc/da/report/service/impl/IReportServiceImpl.java +++ b/adc-da-report/src/main/java/com/adc/da/report/service/impl/IReportServiceImpl.java @@ -11,6 +11,7 @@ import com.adc.da.report.eo.FileEntity; import com.adc.da.report.eo.ReportEntity; import com.adc.da.report.eo.ReportLabelEntity; import com.adc.da.report.eo.ReportUserEntity; +import com.adc.da.report.service.IReportContentService; import com.adc.da.report.service.IReportLabelService; import com.adc.da.report.service.IReportService; import com.adc.da.report.service.ITreeLabelService; @@ -40,6 +41,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.IOException; import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; @@ -93,6 +95,9 @@ public class IReportServiceImpl extends ServiceImpl @Autowired private RoleEODao roleEODao; + @Resource + private IReportContentService iReportContentService; + @Autowired private LocalFileUtil localFileUtil; @@ -105,7 +110,7 @@ public class IReportServiceImpl extends ServiceImpl */ @Override @Transactional(rollbackFor = Exception.class) - public String insert(ReportEntity entity, List labelList) { + public String insert(ReportEntity entity, List labelList) throws IOException { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); if (StringUtils.isEmpty(entity.getId())) { @@ -130,6 +135,9 @@ public class IReportServiceImpl extends ServiceImpl reportLabelDao.insert(reportLabelEntity); }); + //插入报表内容表 + iReportContentService.insertReportContent(entity.getId() ,entity.getFileId()); + CommonUtils.threadPoolExecutor().execute(() -> { //生成html try { @@ -223,7 +231,6 @@ public class IReportServiceImpl extends ServiceImpl idSet.add(reportLabelEntity.getReportId()); }); } - // TODO ES模糊查询 IPage list = reportDao.list(page, vo, idSet); diff --git a/adc-da-report/src/main/resources/mybatis/mapper/mysql/ReportManageMapper.xml b/adc-da-report/src/main/resources/mybatis/mapper/mysql/ReportManageMapper.xml index 6b52bac..2ddcf03 100644 --- a/adc-da-report/src/main/resources/mybatis/mapper/mysql/ReportManageMapper.xml +++ b/adc-da-report/src/main/resources/mybatis/mapper/mysql/ReportManageMapper.xml @@ -2,124 +2,21 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -