ソースを参照

Merge branch 'feature-v4-20220801' into project-local-jg

# Conflicts:
#	4dkankan-common-utils/src/main/java/com/fdkankan/common/constant/ErrorCode.java
#	4dkankan-utils-es/pom.xml
dsx 2 年 前
コミット
e4ff5ee8b8
38 ファイル変更1839 行追加288 行削除
  1. 27 8
      4dkankan-common-web/src/main/java/com/fdkankan/web/constant/CameraTypeEnum.java
  2. 12 0
      4dkankan-common-utils/src/main/java/com/fdkankan/common/constant/CommonOperStatus.java
  3. 44 0
      4dkankan-common-utils/src/main/java/com/fdkankan/common/constant/CommonSuccessStatus.java
  4. 15 0
      4dkankan-common-utils/src/main/java/com/fdkankan/common/constant/ErrorCode.java
  5. 12 4
      4dkankan-common-utils/src/main/java/com/fdkankan/common/constant/ImageUtil.java
  6. 1 0
      4dkankan-common-utils/src/main/java/com/fdkankan/common/constant/SceneSource.java
  7. 15 1
      4dkankan-common-utils/src/main/java/com/fdkankan/common/constant/SceneStatus.java
  8. 40 0
      4dkankan-common-utils/src/main/java/com/fdkankan/common/constant/SpaceType.java
  9. 1 0
      4dkankan-common-utils/src/main/java/com/fdkankan/common/util/DateExtUtil.java
  10. 23 16
      4dkankan-common-utils/src/main/java/com/fdkankan/common/util/PasswordUtils.java
  11. 21 5
      4dkankan-common-utils/src/main/java/com/fdkankan/common/util/StrExtUtil.java
  12. 1 1
      4dkankan-common-web/src/main/java/com/fdkankan/web/exception/GlobalExceptionHandler.java
  13. 64 0
      4dkankan-utils-elasticsearch/pom.xml
  14. 115 0
      4dkankan-utils-elasticsearch/src/main/java/com/fdkankan/elasticsearch/config/ElasticsearchConfig.java
  15. 60 0
      4dkankan-utils-elasticsearch/src/main/java/com/fdkankan/elasticsearch/service/DocumentService.java
  16. 45 0
      4dkankan-utils-elasticsearch/src/main/java/com/fdkankan/elasticsearch/service/IndexService.java
  17. 149 0
      4dkankan-utils-elasticsearch/src/main/java/com/fdkankan/elasticsearch/service/QueryDataService.java
  18. 141 0
      4dkankan-utils-elasticsearch/src/main/java/com/fdkankan/elasticsearch/service/impl/DocumentServiceImpl.java
  19. 106 0
      4dkankan-utils-elasticsearch/src/main/java/com/fdkankan/elasticsearch/service/impl/IndexServiceImpl.java
  20. 531 0
      4dkankan-utils-elasticsearch/src/main/java/com/fdkankan/elasticsearch/service/impl/QueryDataServiceImpl.java
  21. 0 13
      4dkankan-utils-es/src/main/java/com/fdkankan/App.java
  22. 0 20
      4dkankan-utils-es/src/test/java/com/fdkankan/AppTest.java
  23. 44 23
      4dkankan-utils-fyun-local/src/main/java/com/fdkankan/fyun/local/LocalFileService.java
  24. 55 0
      4dkankan-utils-fyun-oss/src/main/java/com/fdkankan/fyun/oss/OssFileService.java
  25. 3 0
      4dkankan-utils-fyun-parent/src/main/java/com/fdkankan/fyun/config/FYunFileConfig.java
  26. 2 1
      4dkankan-utils-fyun-parent/src/main/java/com/fdkankan/fyun/face/AbstractFYunFileService.java
  27. 4 0
      4dkankan-utils-fyun-parent/src/main/java/com/fdkankan/fyun/face/FYunFileServiceInterface.java
  28. 10 0
      4dkankan-utils-fyun-s3/src/main/java/com/fdkankan/fyun/s3/S3FileService.java
  29. 5 0
      4dkankan-utils-model/src/main/java/com/fdkankan/model/constants/ConstantFilePath.java
  30. 24 0
      4dkankan-utils-model/src/main/java/com/fdkankan/model/utils/SceneUtil.java
  31. 35 0
      4dkankan-utils-pdf/pom.xml
  32. 19 1
      4dkankan-utils-rabbitmq/src/main/java/com/fdkankan/rabbitmq/util/RabbitMqProducer.java
  33. 36 1
      4dkankan-utils-redis/src/main/java/com/fdkankan/redis/constant/RedisKey.java
  34. 13 0
      4dkankan-utils-redis/src/main/java/com/fdkankan/redis/constant/RedisLockKey.java
  35. 67 194
      4dkankan-utils-redis/src/main/java/com/fdkankan/redis/util/RedisUtil.java
  36. 5 0
      4dkankan-utils-sms/pom.xml
  37. 93 0
      4dkankan-utils-sms/src/main/java/com/fdkankan/sms/SmsServiceV2.java
  38. 1 0
      pom.xml

+ 27 - 8
4dkankan-common-web/src/main/java/com/fdkankan/web/constant/CameraTypeEnum.java

@@ -1,26 +1,32 @@
-package com.fdkankan.web.constant;
+package com.fdkankan.common.constant;
 
 import java.util.HashMap;
 import java.util.Map;
 
 public enum CameraTypeEnum {
-    DOUBLE_EYE(0,"KK-","4DKKLITE_","旧双目相机"),
-    FDKK_PRO(1,"KK-","4DKKPRO_","四维看看pro八目相机"),
-    FDKK_LITE(2,"KK-","4DKKLITE_","四维看看lite"),
-    ZHIHOUSE_REDHOUSE(5,"KK-","4DKKLITE_","指房宝小红屋相机"),
-    DOUBLE_EYE_TURN(9,"KJ-","4DKKLITE_","双目转台"),
-    LASER_TURN(10,"SS-","4DKKLA_","激光转台");
+    DOUBLE_EYE(0,"KK-","4DKKLITE_","旧双目相机", "4DKanKan"),
+    FDKK_PRO(1,"KK-","4DKKPRO_","四维看看pro八目相机", "4DKanKan"),
+    FDKK_LITE(2,"KK-","4DKKLITE_","四维看看lite", "4DKanKan"),
+    ZHIHOUSE_REDHOUSE(5,"KK-","4DKKLITE_","指房宝小红屋相机", "4DKanKan"),
+    DOUBLE_EYE_TURN(9,"KJ-","4DKKLITE_","双目转台", "4DMinion"),
+    LASER_TURN(10,"SS-","4DKKLA_","激光转台", "4DMega"),
+    LASER_SG(11,"SG-","4DSG_","深光", "4DMega");
 
 
     private int type;
     private String sceneNumPrefix;
     private String wifiNamePrefix;
     private String desc;
+    private String cameraName;
 
     public int getType() {
         return type;
     }
 
+    public String getCameraName() {
+        return cameraName;
+    }
+
     public String getSceneNumPrefix() {
         return sceneNumPrefix;
     }
@@ -33,11 +39,12 @@ public enum CameraTypeEnum {
         }
     }
 
-    CameraTypeEnum(Integer type, String sceneNumPrefix, String wifiNamePrefix, String desc) {
+    CameraTypeEnum(Integer type, String sceneNumPrefix, String wifiNamePrefix, String desc, String cameraName) {
         this.type = type;
         this.sceneNumPrefix = sceneNumPrefix;
         this.wifiNamePrefix = wifiNamePrefix;
         this.desc = desc;
+        this.cameraName = cameraName;
     }
 
     public static String getSceneNumPrefixByType(Integer type){
@@ -47,4 +54,16 @@ public enum CameraTypeEnum {
         return "";
     }
 
+    public static CameraTypeEnum get(int type){
+        CameraTypeEnum[] values = CameraTypeEnum.values();
+        Integer enumValue = null;
+        for(CameraTypeEnum eachValue : values){
+            enumValue = eachValue.getType();
+            if(enumValue.equals(type)){
+                return eachValue;
+            }
+        }
+        return null;
+    }
+
 }

+ 12 - 0
4dkankan-common-utils/src/main/java/com/fdkankan/common/constant/CommonOperStatus.java

@@ -22,4 +22,16 @@ public enum CommonOperStatus {
         return message;
     }
 
+    public static CommonOperStatus get(Integer code){
+        CommonOperStatus[] values = CommonOperStatus.values();
+        Integer enumValue = null;
+        for(CommonOperStatus eachValue : values){
+            enumValue = eachValue.code();
+            if(enumValue.equals(code)){
+                return eachValue;
+            }
+        }
+        return null;
+    }
+
 }

+ 44 - 0
4dkankan-common-utils/src/main/java/com/fdkankan/common/constant/CommonSuccessStatus.java

@@ -0,0 +1,44 @@
+package com.fdkankan.common.constant;
+
+/**
+ * <p>
+        是否成功状态枚举
+ * </p>
+ * @author dengsixing
+ * @date 2022/1/28
+ **/
+public enum CommonSuccessStatus {
+
+    FAIL(-1, "失败"),
+    WAITING(0, "等待"),
+    SUCCESS(1, "成功");
+
+    private Integer code;
+    private String message;
+
+    private CommonSuccessStatus(Integer code, String message) {
+        this.code = code;
+        this.message = message;
+    }
+
+    public static CommonSuccessStatus get(Integer code){
+        CommonSuccessStatus[] values = CommonSuccessStatus.values();
+        Integer enumValue = null;
+        for(CommonSuccessStatus eachValue : values){
+            enumValue = eachValue.code();
+            if(enumValue.equals(code)){
+                return eachValue;
+            }
+        }
+        return null;
+    }
+
+    public Integer code() {
+        return code;
+    }
+
+    public String message() {
+        return message;
+    }
+
+}

+ 15 - 0
4dkankan-common-utils/src/main/java/com/fdkankan/common/constant/ErrorCode.java

@@ -9,6 +9,8 @@ public enum ErrorCode {
     SYSTEM_BUSY(-5, "系统繁忙,请稍后再试!"),
 
     HAVE_NO_RIGHT(1001, "无权访问!"),
+    APP_KEY_IS_NULL(1002, "appkey为空"),
+    APP_KEY_ILLEGAL(1003, "appkey不正确"),
 
 
     AUTH_FAIL(4000, "鉴权失败!"),
@@ -83,6 +85,8 @@ public enum ErrorCode {
     FAILURE_CODE_4001(4001, "缺少必要文件:%s"),
     FAILURE_CODE_4002(4002, "文件不存在:%s"),
     FAILURE_CODE_4003(4003, "图片大小不能超过:%s"),
+    FAILURE_CODE_4004(4004, "此接口仅支持看看和看见相机场景"),
+    FAILURE_CODE_4005(4005, "已超出容量,不允许重新上传"),
 
 
     FAILURE_CODE_5001(5001, "modeldata.json为空"),
@@ -156,6 +160,9 @@ public enum ErrorCode {
     FAILURE_CODE_5069(5069, "floors.json文件数据不正常"),
     FAILURE_CODE_5070(5070, "楼层文件数据不正常"),
     FAILURE_CODE_5071(5071, "另一个程序正在使用此文件,进程无法访问"),
+    FAILURE_CODE_5072(5072, "相机原始资源已被删除,不支持重算"),
+    FAILURE_CODE_5073(5073, "相机原始资源正在被清除"),
+    FAILURE_CODE_5074(5074, "复制场景不支持重算"),
 
     FAILURE_CODE_6003(6003, "该相机未被绑定,请前往 我的相机 先绑定相机后再进行授权 "),
 
@@ -197,6 +204,14 @@ public enum ErrorCode {
     FAILURE_CODE_9003(9003, "快递单号不能为空"),
     FAILURE_CODE_9004(9004, "查询不到开票信息"),
 
+    //-----------------openApi----------------------start
+    FAILURE_CODE_10000(10000, "appkey未启用"),
+    FAILURE_CODE_10001(10001, "appkey未生效"),
+    FAILURE_CODE_10002(10002, "账号已存在,请勿重复创建"),
+    FAILURE_CODE_10003(10003, "账号不存在"),
+    FAILURE_CODE_10004(10004, "api次数不能为空")
+    //-----------------openApi----------------------end
+
 
 
     ;

+ 12 - 4
4dkankan-common-utils/src/main/java/com/fdkankan/common/constant/ImageUtil.java

@@ -1,5 +1,10 @@
 package com.fdkankan.common.constant;
 
+import cn.hutool.core.img.ImgUtil;
+
+import javax.imageio.ImageIO;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
@@ -78,10 +83,13 @@ public class ImageUtil {
         return stringBuilder.toString();
     }
 
-    public static void main(String[] args) throws Exception{
-        FileInputStream fis = new FileInputStream(new File("F:\\test\\1.png"));
-        boolean image = ImageUtil.isImage(fis);
-        System.out.println(image);
+    public static void main(String[] args) throws IOException {
+        ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
+        String path = "G:\\home\\backend\\4dkankan_v4\\sale\\file\\sale\\file\\test\\5474a1e8d93747f3aec79e6021c10a3b.png";
+        String picType = getPicType(new FileInputStream(path));
+        System.out.println(picType);
+        BufferedImage read = ImgUtil.read(new File(path));
+        ImageIO.write(read, "png", byteArrayOut);
     }
 
 }

+ 1 - 0
4dkankan-common-utils/src/main/java/com/fdkankan/common/constant/SceneSource.java

@@ -9,6 +9,7 @@ public enum SceneSource {
     SM(2, "双目"),
     ZT(3, "转台"),
     JG(4, "激光"),
+    SG(5, "深光"),
     YJHZ(11, "一键换装");
 
     private Integer code;

+ 15 - 1
4dkankan-common-utils/src/main/java/com/fdkankan/common/constant/SceneStatus.java

@@ -5,7 +5,9 @@ public enum SceneStatus {
     wait(0, "未建好"),
     SUCCESS(1, "已建好"),
     FAILD(-1, "出错"),
-    NO_DISPLAY(-2, "不要在官网上显示");
+    NO_DISPLAY(-2, "不要在官网上显示"),
+    EXCEED_SPACE(-3, "超出容量,未计算")
+    ;
 
     private Integer code;
     private String message;
@@ -23,4 +25,16 @@ public enum SceneStatus {
         return message;
     }
 
+    public static SceneStatus get(Integer code){
+        SceneStatus[] values = SceneStatus.values();
+        Integer enumValue = null;
+        for(SceneStatus eachValue : values){
+            enumValue = eachValue.code();
+            if(enumValue.equals(code)){
+                return eachValue;
+            }
+        }
+        return null;
+    }
+
 }

+ 40 - 0
4dkankan-common-utils/src/main/java/com/fdkankan/common/constant/SpaceType.java

@@ -0,0 +1,40 @@
+package com.fdkankan.common.constant;
+
+/**
+ * 容量统计方式
+ */
+public enum SpaceType {
+
+    GB("GB", "按容量"),
+    SP("SP", "按个数"),
+    ;
+
+    private String code;
+    private String message;
+
+    private SpaceType(String code, String message) {
+        this.code = code;
+        this.message = message;
+    }
+
+    public String code() {
+        return code;
+    }
+
+    public String message() {
+        return message;
+    }
+
+    public static SpaceType get(String code){
+        SpaceType[] values = SpaceType.values();
+        String enumValue = null;
+        for(SpaceType eachValue : values){
+            enumValue = eachValue.code();
+            if(enumValue.equals(code)){
+                return eachValue;
+            }
+        }
+        return null;
+    }
+
+}

+ 1 - 0
4dkankan-common-utils/src/main/java/com/fdkankan/common/util/DateExtUtil.java

@@ -26,6 +26,7 @@ public class DateExtUtil extends DateUtil {
     public static final String dateStyle8 = "yyyy-MM-dd HH:mm";
     public static final String dateStyle9 = "yyyy.MM.dd";
     public static final String dateStyle10 = "yyyyMM";
+    public static final String dateStyle11 = "yyyyMMddHHmmssSSS";
 
     public static Date hoursCalculate(Date beginDate, int hours) {
         return timesCalculate(beginDate, hours, GregorianCalendar.HOUR);

+ 23 - 16
4dkankan-common-utils/src/main/java/com/fdkankan/common/util/PasswordUtils.java

@@ -10,6 +10,7 @@ import java.security.SecureRandom;
 
 public class PasswordUtils {
 
+    public static char[] arr = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
 
     /**
      * JAVA6支持以下任意一种算法 PBEWITHMD5ANDDES PBEWITHMD5ANDTRIPLEDES
@@ -166,25 +167,31 @@ public class PasswordUtils {
         return (byte) "0123456789ABCDEF".indexOf(c);
     }
 
-    public static void main(String[] args) {
-
-        //管理后台密码加解密
-        String userName = "admin6";
-        String password = "123456";
-
-        try {
-            byte[] salt = PasswordUtils.getStaticSalt();
-            String ciphertext = PasswordUtils.encrypt(userName, password, salt);
-            System.out.println(ciphertext);
-            String plaintext = PasswordUtils.decrypt(ciphertext, password, salt);
-            System.out.println(plaintext);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-
 
+    /**
+     * 模拟前端密码加密
+     * @param str
+     */
+    public static String decycptPasswordWeb(String str){
+        int num = 2;
+        String front = randomWord(8);
+        String middle = randomWord(8);
+        String end = randomWord(8);
 
+        String str1 = str.substring(0, num);
+        String str2 = str.substring(num);
 
+        return front + str2 + middle + str1 + end ;
     }
 
+    public static String randomWord(Integer min) {
+        String str = "";
+        Integer range = min;
+        // 随机产生
+        for (int i = 0; i < range; i++) {
+            int pos = (int) Math.round(Math.random() * (arr.length - 1));
+            str += arr[pos];
+        }
+        return str;
+    }
 }

+ 21 - 5
4dkankan-common-utils/src/main/java/com/fdkankan/common/util/StrExtUtil.java

@@ -1,8 +1,16 @@
 package com.fdkankan.common.util;
 
+import cn.hutool.captcha.CaptchaUtil;
+import cn.hutool.captcha.LineCaptcha;
+import cn.hutool.captcha.generator.RandomGenerator;
+import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.util.ReUtil;
 import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSON;
 import com.fdkankan.common.constant.ErrorCode;
+
+import java.io.File;
+import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import jdk.nashorn.internal.runtime.regexp.joni.Regex;
@@ -54,14 +62,22 @@ public class StrExtUtil extends StrUtil {
         return ReUtil.contains(regex, content);
     }
 
-    public static void main(String[] args) {
+    public static void main(String[] args) throws Exception {
 
-        String test = null;
-//        System.out.println(test.lastIndexOf("."));
-//        System.out.println(test.substring(test.lastIndexOf(".")));
+//        String test = null;
+////        System.out.println(test.lastIndexOf("."));
+////        System.out.println(test.substring(test.lastIndexOf(".")));
+//
+//        System.out.println("123".equals(test));;
 
-        System.out.println("123".equals(test));;
+//        List<String> fileNames = FileUtils.list(new File("C:\\Users\\dsx\\Desktop\\90d95cdb5_202211141023024060"));
+//        System.out.println(JSON.toJSONString(fileNames));
 
+        RandomGenerator randomGenerator = new RandomGenerator("0123456789asdfghjklASDFGHJKL", 10);
+        LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(300, 100);
+        lineCaptcha.setGenerator(randomGenerator);
+        lineCaptcha.write("D:\\test2\\1.png");
+        System.out.println(lineCaptcha.getCode());
 
 
     }

+ 1 - 1
4dkankan-common-web/src/main/java/com/fdkankan/web/exception/GlobalExceptionHandler.java

@@ -98,7 +98,7 @@ public class GlobalExceptionHandler {
     @ResponseBody
     @ExceptionHandler(value = HttpMessageNotReadableException.class)
     public ResultData httpMessageNotReadableException(HttpMessageNotReadableException e){
-        return ResultData.error(ErrorCode.FAILURE_CODE_3001);
+        return ResultData.error(ErrorCode.PARAM_ERROR.code(), ExceptionUtil.stacktraceToString(e, 3000));
     }
 
 

+ 64 - 0
4dkankan-utils-elasticsearch/pom.xml

@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>4dkankan-utils</artifactId>
+        <groupId>com.fdkankan</groupId>
+        <version>3.0.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>4dkankan-utils-elasticsearch</artifactId>
+
+
+    <dependencies>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-aop</artifactId>
+        </dependency>
+
+        <!--引入es-high-level-client相关依赖  start-->
+        <dependency>
+            <groupId>org.elasticsearch</groupId>
+            <artifactId>elasticsearch</artifactId>
+            <version>7.6.2</version>
+        </dependency>
+        <dependency>
+            <groupId>org.elasticsearch.client</groupId>
+            <artifactId>elasticsearch-rest-client</artifactId>
+            <version>7.6.2</version>
+        </dependency>
+        <dependency>
+            <groupId>org.elasticsearch.client</groupId>
+            <artifactId>elasticsearch-rest-high-level-client</artifactId>
+            <version>7.6.2</version>
+        </dependency>
+        <!--引入es-high-level-client相关依赖  end-->
+
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+            <version>1.2.83</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>commons-collections</groupId>
+            <artifactId>commons-collections</artifactId>
+            <version>3.2.2</version>
+        </dependency>
+
+    </dependencies>
+
+</project>

+ 115 - 0
4dkankan-utils-elasticsearch/src/main/java/com/fdkankan/elasticsearch/config/ElasticsearchConfig.java

@@ -0,0 +1,115 @@
+package com.fdkankan.elasticsearch.config;
+
+import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
+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.elasticsearch.client.RestClient;
+import org.elasticsearch.client.RestClientBuilder;
+import org.elasticsearch.client.RestHighLevelClient;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @author yanfengzhang
+ * @description restHighLevelClient 客户端配置类
+ * @date 2022/12/7  23:34
+ */
+
+@Slf4j
+@Data
+@Configuration
+@ConfigurationProperties(prefix = "elasticsearch")
+public class ElasticsearchConfig {
+    /**
+     * es host ip 地址(集群)
+     */
+    private String hosts;
+    /**
+     * es用户名
+     */
+    private String userName;
+    /**
+     * es密码
+     */
+    private String password;
+    /**
+     * es 请求方式
+     */
+    private String scheme;
+    /**
+     * es集群名称
+     */
+    private String clusterName;
+    /**
+     * es 连接超时时间
+     */
+    private int connectTimeOut;
+    /**
+     * es socket 连接超时时间
+     */
+    private int socketTimeOut;
+    /**
+     * es 请求超时时间
+     */
+    private int connectionRequestTimeOut;
+    /**
+     * es 最大连接数
+     */
+    private int maxConnectNum;
+    /**
+     * es 每个路由的最大连接数
+     */
+    private int maxConnectNumPerRoute;
+
+    /**
+     * 如果@Bean没有指定bean的名称,那么这个bean的名称就是方法名
+     */
+    @Bean(name = "restHighLevelClient")
+    public RestHighLevelClient restHighLevelClient() {
+        /** 拆分地址
+         /**        List<HttpHost> hostLists = new ArrayList<>();
+         /**        String[] hostList = hosts.split(",");
+         /**        for (String addr : hostList) {
+         /**            String host = addr.split(":")[0];
+         /**            String port = addr.split(":")[1];
+         /**            hostLists.add(new HttpHost(host, Integer.parseInt(port), scheme));
+         /**        }
+         /**        /** 转换成 HttpHost 数组
+         /**        HttpHost[] httpHost = hostLists.toArray(new HttpHost[]{});*/
+
+        /*此处为单节点es*/
+        String host = hosts.split(":")[0];
+        String port = hosts.split(":")[1];
+        HttpHost httpHost = new HttpHost(host, Integer.parseInt(port));
+
+        /*构建连接对象*/
+        RestClientBuilder builder = RestClient.builder(httpHost);
+
+        /*设置用户名、密码*/
+        CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
+        credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userName, password));
+
+        /*连接延时配置*/
+        builder.setRequestConfigCallback(requestConfigBuilder -> {
+            requestConfigBuilder.setConnectTimeout(connectTimeOut);
+            requestConfigBuilder.setSocketTimeout(socketTimeOut);
+            requestConfigBuilder.setConnectionRequestTimeout(connectionRequestTimeOut);
+            return requestConfigBuilder;
+        });
+
+        /*连接数配置*/
+        builder.setHttpClientConfigCallback(httpClientBuilder -> {
+            httpClientBuilder.setMaxConnTotal(maxConnectNum);
+            httpClientBuilder.setMaxConnPerRoute(maxConnectNumPerRoute);
+            httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
+            return httpClientBuilder;
+        });
+
+        return new RestHighLevelClient(builder);
+    }
+}

+ 60 - 0
4dkankan-utils-elasticsearch/src/main/java/com/fdkankan/elasticsearch/service/DocumentService.java

@@ -0,0 +1,60 @@
+package com.fdkankan.elasticsearch.service;
+
+import com.alibaba.fastjson.JSONObject;
+import org.elasticsearch.rest.RestStatus;
+
+import java.io.IOException;
+import java.util.List;
+
+public interface  DocumentService {
+
+    /**
+     * 增加文档信息
+     *
+     * @param indexName 索引名
+     * @param keyId     主键
+     * @param data      json数据
+     * @return 增加文档信息状态
+     * @throws IOException 异常信息
+     */
+    RestStatus addDocument(String indexName, String keyId,String data) throws IOException;
+
+    /**
+     * 获取文档信息
+     *
+     * @param indexName 索引名
+     * @param id        文档ID
+     * @return 商品数据
+     * @throws Exception 异常信息
+     */
+    String getDocument(String indexName, String id) throws Exception;
+
+    /**
+     * 更新文档信息
+     *
+     * @param indexName 索引名
+     * @param data      数据
+     * @return 更新文档信息状态
+     * @throws IOException 异常信息
+     */
+    RestStatus updateDocument(String indexName, String id ,String data) throws IOException;
+
+    /**
+     * 删除文档信息
+     *
+     * @param indexName 索引名
+     * @param id        文档ID
+     * @return 删除文档信息状态
+     * @throws IOException 异常信息
+     */
+    RestStatus deleteDocument(String indexName, String id) throws IOException;
+
+    /**
+     * 批量导入
+     *
+     * @param dataList 商品列表
+     * @return 批量导入状态
+     * @throws IOException 异常信息
+     */
+    RestStatus batchImportGoodsData(List<JSONObject> dataList, String index) throws IOException;
+}

+ 45 - 0
4dkankan-utils-elasticsearch/src/main/java/com/fdkankan/elasticsearch/service/IndexService.java

@@ -0,0 +1,45 @@
+package com.fdkankan.elasticsearch.service;
+
+
+import java.util.Map;
+
+public interface IndexService {
+
+
+    /**
+     * 创建索引
+     *
+     * @param indexName 索引名
+     * @param mapping   映射结构配置
+     * @return true-创建成功
+     * @throws Exception 异常
+     */
+    boolean indexCreate(String indexName, String mapping) throws Exception;
+
+    /**
+     * 获取索引结构
+     *
+     * @param indexName 索引名
+     * @return 索引结构
+     * @throws Exception 异常
+     */
+    Map<String, Object> getMapping(String indexName) throws Exception;
+
+    /**
+     * 删除索引库
+     *
+     * @param indexName 索引名
+     * @return true-删除成功
+     * @throws Exception 异常
+     */
+    boolean indexDelete(String indexName) throws Exception;
+
+    /**
+     * 判断索引是否存在
+     *
+     * @param indexName 索引名
+     * @return true-存在
+     * @throws Exception 异常
+     */
+    boolean indexExists(String indexName) throws Exception;
+}

+ 149 - 0
4dkankan-utils-elasticsearch/src/main/java/com/fdkankan/elasticsearch/service/QueryDataService.java

@@ -0,0 +1,149 @@
+package com.fdkankan.elasticsearch.service;
+
+import java.util.List;
+
+public interface QueryDataService {
+
+    /**
+     * 精确查询(termQuery)
+     *
+     * @param indexName  索引名
+     * @param columnName 列名或字段名
+     * @param value      查询内容
+     * @param classz     数据结构
+     * @param <T>        数据结构
+     * @return 精确查询内容数据
+     */
+    <T> List<T> termQuery(String indexName, String columnName, Object value, Class<T> classz);
+
+    /**
+     * terms:多个查询内容在一个字段中进行查询
+     *
+     * @param indexName  索引名
+     * @param columnName 列名或字段名
+     * @param dataArgs   查询内容集合
+     * @param classz     数据结构
+     * @param <T>        数据结构
+     * @return 多个查询内容在一个字段中进行查询对应结果
+     */
+    <T> List<T> termsQuery(String indexName, String columnName, Object[] dataArgs, Class<T> classz);
+
+    /**
+     * 匹配查询符合条件的所有数据,并设置分页
+     *
+     * @param indexName  索引名
+     * @param classz     数据结构
+     * @param startIndex 起始下标
+     * @param pageSize   页大小
+     * @param orderList  设置排序
+     * @param columnName 列名或字段名
+     * @param value      列名或字段名指定内容
+     * @param <T>        数据结构
+     * @return 符合条件的所有数据
+     */
+    <T> List<T> matchAllQuery(String indexName, Class<T> classz, int startIndex, int pageSize, List<String> orderList, String columnName, Object value);
+
+    /**
+     * 词语匹配查询
+     *
+     * @param indexName  索引名
+     * @param classz     数据结构
+     * @param columnName 列名或字段名
+     * @param value      指定内容
+     * @param <T>        数据结构
+     * @return 词语匹配查询结果
+     */
+    <T> List<T> matchPhraseQuery(String indexName, Class<T> classz, String columnName, Object value);
+
+    /**
+     * 内容在多字段中进行查询
+     *
+     * @param indexName 索引名
+     * @param classz    数据结构
+     * @param fields    列名或字段名集合
+     * @param text      指定内容
+     * @param <T>       数据结构
+     * @return 查询结果
+     */
+    <T> List<T> matchMultiQuery(String indexName, Class<T> classz, String[] fields, Object text);
+
+    /**
+     * 通配符查询(wildcard):会对查询条件进行分词。还可以使用通配符 ?(任意单个字符) 和 * (0个或多个字符)
+     *
+     * @param indexName 索引名
+     * @param classz    数据结构
+     * @param field     列名或字段名集合
+     * @param text      指定内容
+     * @param <T>       数据结构
+     * @return 查询结果
+     */
+    <T> List<T> wildcardQuery(String indexName, Class<T> classz, String field, String text);
+
+    /**
+     * 模糊查询商品信息
+     *
+     * @param indexName 索引名
+     * @param classz    数据结构
+     * @param field     列名或字段名集合
+     * @param text      指定内容
+     * @param <T>       数据结构
+     * @return 查询结果
+     */
+    <T> List<T> fuzzyQuery(String indexName, Class<T> classz, String field, String text);
+
+    /**
+     * boolQuery 查询
+     * 高亮展示标题搜索字段
+     * 设置出参返回字段
+     * 案例:查询从2018-2022年间标题含 三星 的商品信息
+     *
+     * @param indexName 索引名
+     * @param beanClass 数据结构
+     * @param <T>       数据结构
+     * @return 查询结果
+     */
+    <T> List<T> boolQuery(String indexName, Class<T> beanClass);
+
+    /**
+     * 聚合查询 : 聚合查询一定是【先查出结果】,然后对【结果使用聚合函数】做处理.
+     * Metric 指标聚合分析。常用的操作有:avg:求平均、max:最大值、min:最小值、sum:求和等
+     * 案例:分别获取最贵的商品和获取最便宜的商品
+     *
+     * @param indexName 索引名
+     */
+    void metricQuery(String indexName);
+
+    /**
+     * 聚合查询: 聚合查询一定是【先查出结果】,然后对【结果使用聚合函数】做处理
+     * Bucket 分桶聚合分析 : 对查询出的数据进行分组group by,再在组上进行游标聚合
+     * 案例:根据品牌进行聚合查询
+     *
+     * @param indexName        索引名
+     * @param bucketField
+     * @param bucketFieldAlias
+     */
+    void bucketQuery(String indexName, String bucketField, String bucketFieldAlias);
+
+    /**
+     * 子聚合聚合查询  Bucket 分桶聚合分析
+     * <p>
+     * 案例:根据商品分类进行分组查询,并且获取分类商品中的平均价格
+     *
+     * @param indexName        索引名
+     * @param bucketField
+     * @param bucketFieldAlias
+     * @param avgFiled
+     * @param avgFiledAlias
+     */
+    void subBucketQuery(String indexName, String bucketField, String bucketFieldAlias, String avgFiled, String avgFiledAlias);
+
+    /**
+     * 综合聚合查询
+     * <p>
+     * 根据商品分类聚合,获取每个商品类的平均价格,并且在商品分类聚合之上子聚合每个品牌的平均价格
+     *
+     * @param indexName 索引名
+     */
+    void subSubAgg(String indexName);
+
+}

+ 141 - 0
4dkankan-utils-elasticsearch/src/main/java/com/fdkankan/elasticsearch/service/impl/DocumentServiceImpl.java

@@ -0,0 +1,141 @@
+package com.fdkankan.elasticsearch.service.impl;
+
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.fdkankan.elasticsearch.service.DocumentService;
+import lombok.extern.log4j.Log4j2;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.elasticsearch.action.bulk.BulkRequest;
+import org.elasticsearch.action.bulk.BulkResponse;
+import org.elasticsearch.action.delete.DeleteRequest;
+import org.elasticsearch.action.delete.DeleteResponse;
+import org.elasticsearch.action.get.GetRequest;
+import org.elasticsearch.action.get.GetResponse;
+import org.elasticsearch.action.index.IndexRequest;
+import org.elasticsearch.action.index.IndexResponse;
+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.common.xcontent.XContentType;
+import org.elasticsearch.rest.RestStatus;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+import java.util.List;
+
+@Slf4j
+@Service
+public class DocumentServiceImpl implements DocumentService {
+
+    @Autowired
+    private RestHighLevelClient restHighLevelClient;
+
+    /**
+     * 增加文档信息
+     *
+     * @param indexName 索引名
+     * @param keyId     主键
+     * @param data      json数据
+     * @return 增加文档信息状态
+     * @throws IOException 异常信息
+     */
+    @Override
+    public RestStatus addDocument(String indexName, String keyId, String data) throws IOException {
+        /*2.将对象转为json*/
+        /*3.创建索引请求对象*/
+        IndexRequest indexRequest = new IndexRequest(indexName).id(keyId).source(data, XContentType.JSON);
+        /*4.执行增加文档*/
+        IndexResponse response = restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
+
+        return response.status();
+    }
+
+    /**
+     * 获取文档信息
+     *
+     * @param indexName 索引名
+     * @param id        文档ID
+     * @return 商品数据
+     * @throws Exception 异常信息
+     */
+    @Override
+    public String getDocument(String indexName, String id) throws Exception {
+        /*2.创建获取请求对象*/
+        GetRequest getRequest = new GetRequest(indexName, id);
+        GetResponse response = restHighLevelClient.get(getRequest, RequestOptions.DEFAULT);
+
+        return response.getSourceAsString();
+    }
+
+    /**
+     * 更新文档信息
+     *
+     * @param indexName 索引名
+     * @param data      数据
+     * @return 更新文档信息状态
+     * @throws IOException 异常信息
+     */
+    @Override
+    public RestStatus updateDocument(String indexName, String id ,String data) throws IOException {
+
+        /*2.创建索引请求对象*/
+        UpdateRequest updateRequest = new UpdateRequest(indexName, id);
+        /*3.设置更新文档内容*/
+        updateRequest.doc(data, XContentType.JSON);
+        /*4.执行更新文档*/
+        UpdateResponse response = restHighLevelClient.update(updateRequest, RequestOptions.DEFAULT);
+
+        return response.status();
+    }
+
+    /**
+     * 删除文档信息
+     *
+     * @param indexName 索引名
+     * @param type      文档类型
+     * @param id        文档ID
+     * @return 删除文档信息状态
+     * @throws IOException 异常信息
+     */
+    @Override
+    public RestStatus deleteDocument(String indexName, String id) throws IOException {
+        /*2.创建删除请求对象*/
+        DeleteRequest deleteRequest = new DeleteRequest(indexName, id);
+        /*3.执行删除文档*/
+        DeleteResponse response = restHighLevelClient.delete(deleteRequest, RequestOptions.DEFAULT);
+
+        return response.status();
+    }
+
+    /**
+     * 批量导入
+     *
+     * @param dataList 列表
+     * @return 批量导入状态
+     * @throws IOException 异常信息
+     */
+    @Override
+    public RestStatus batchImportGoodsData(List<JSONObject> dataList, String index) throws IOException {
+        if (CollectionUtils.isEmpty(dataList)) {
+            return RestStatus.CREATED;
+        }
+
+        /*bulk导入 循环goodsList,创建IndexRequest添加数据*/
+        BulkRequest bulkRequest = new BulkRequest();
+        for (JSONObject data : dataList) {
+            //将goods对象转换为json字符串
+            IndexRequest indexRequest = new IndexRequest(index);
+            indexRequest.id(data.getString("id")).source(JSON.toJSONString(data), XContentType.JSON);
+            bulkRequest.add(indexRequest);
+        }
+
+        BulkResponse response = restHighLevelClient.bulk(bulkRequest, RequestOptions.DEFAULT);
+        return response.status();
+    }
+
+}

+ 106 - 0
4dkankan-utils-elasticsearch/src/main/java/com/fdkankan/elasticsearch/service/impl/IndexServiceImpl.java

@@ -0,0 +1,106 @@
+package com.fdkankan.elasticsearch.service.impl;
+
+
+import com.fdkankan.elasticsearch.service.IndexService;
+import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
+import org.elasticsearch.action.support.master.AcknowledgedResponse;
+import org.elasticsearch.client.IndicesClient;
+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.client.indices.GetIndexResponse;
+import org.elasticsearch.cluster.metadata.MappingMetaData;
+import org.elasticsearch.common.xcontent.XContentType;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Map;
+
+
+@Service
+public class IndexServiceImpl implements IndexService {
+
+    @Autowired
+    private RestHighLevelClient restHighLevelClient;
+
+
+
+    /**
+     * 创建索引
+     *
+     * @param indexName 索引名
+     * @param mapping   映射结构配置
+     * @return true-创建成功
+     * @throws Exception 异常
+     */
+    @Override
+    public boolean indexCreate(String indexName, String mapping) throws Exception {
+        CreateIndexRequest indexRequest = new CreateIndexRequest(indexName);
+
+        IndicesClient indicesClient = restHighLevelClient.indices();
+        indexRequest.mapping(mapping, XContentType.JSON);
+
+        // 请求服务器
+        CreateIndexResponse response = indicesClient.create(indexRequest, RequestOptions.DEFAULT);
+
+        return response.isAcknowledged();
+    }
+
+    /**
+     * 获取索引结构
+     *
+     * @param indexName 索引名
+     * @return 索引结构
+     * @throws Exception 异常
+     */
+    @Override
+    public Map<String, Object> getMapping(String indexName) throws Exception {
+        IndicesClient indicesClient = restHighLevelClient.indices();
+
+        // 创建get请求
+        GetIndexRequest request = new GetIndexRequest(indexName);
+        // 发送get请求
+        GetIndexResponse response = indicesClient.get(request, RequestOptions.DEFAULT);
+        // 获取表结构
+        Map<String, MappingMetaData> mappings = response.getMappings();
+        Map<String, Object> sourceAsMap = mappings.get(indexName).getSourceAsMap();
+        return sourceAsMap;
+    }
+
+    /**
+     * 删除索引库
+     *
+     * @param indexName 索引名
+     * @return true-删除成功
+     * @throws Exception 异常
+     */
+    @Override
+    public boolean indexDelete(String indexName) throws Exception {
+        IndicesClient indicesClient = restHighLevelClient.indices();
+        // 创建delete请求方式
+        DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(indexName);
+        // 发送delete请求
+        AcknowledgedResponse response = indicesClient.delete(deleteIndexRequest, RequestOptions.DEFAULT);
+
+        return response.isAcknowledged();
+    }
+
+    /**
+     * 判断索引是否存在
+     *
+     * @param indexName 索引名
+     * @return true-存在
+     * @throws Exception 异常
+     */
+    @Override
+    public boolean indexExists(String indexName) throws Exception {
+        IndicesClient indicesClient = restHighLevelClient.indices();
+        // 创建get请求
+        GetIndexRequest request = new GetIndexRequest(indexName);
+        // 判断索引库是否存在
+        return indicesClient.exists(request, RequestOptions.DEFAULT);
+    }
+
+}

+ 531 - 0
4dkankan-utils-elasticsearch/src/main/java/com/fdkankan/elasticsearch/service/impl/QueryDataServiceImpl.java

@@ -0,0 +1,531 @@
+package com.fdkankan.elasticsearch.service.impl;
+
+
+import com.alibaba.fastjson.JSON;
+import com.fdkankan.elasticsearch.service.QueryDataService;
+import lombok.extern.log4j.Log4j2;
+import org.apache.commons.lang3.StringUtils;
+import org.elasticsearch.action.search.SearchRequest;
+import org.elasticsearch.action.search.SearchResponse;
+import org.elasticsearch.client.RequestOptions;
+import org.elasticsearch.client.RestHighLevelClient;
+import org.elasticsearch.common.text.Text;
+import org.elasticsearch.common.unit.Fuzziness;
+import org.elasticsearch.index.query.BoolQueryBuilder;
+import org.elasticsearch.index.query.MatchAllQueryBuilder;
+import org.elasticsearch.index.query.MatchQueryBuilder;
+import org.elasticsearch.index.query.QueryBuilders;
+import org.elasticsearch.rest.RestStatus;
+import org.elasticsearch.search.SearchHit;
+import org.elasticsearch.search.SearchHits;
+import org.elasticsearch.search.aggregations.AggregationBuilder;
+import org.elasticsearch.search.aggregations.AggregationBuilders;
+import org.elasticsearch.search.aggregations.Aggregations;
+import org.elasticsearch.search.aggregations.bucket.terms.ParsedStringTerms;
+import org.elasticsearch.search.aggregations.bucket.terms.Terms;
+import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
+import org.elasticsearch.search.aggregations.metrics.ParsedAvg;
+import org.elasticsearch.search.aggregations.metrics.ParsedMax;
+import org.elasticsearch.search.aggregations.metrics.ParsedMin;
+import org.elasticsearch.search.builder.SearchSourceBuilder;
+import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
+import org.elasticsearch.search.fetch.subphase.highlight.HighlightField;
+import org.elasticsearch.search.sort.SortOrder;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * @author yanfengzhang
+ * @description
+ * @date 2022/12/8  23:37
+ */
+@Service
+@Log4j2
+public class QueryDataServiceImpl implements QueryDataService {
+    @Autowired
+    private RestHighLevelClient restHighLevelClient;
+
+    /**
+     * 精确查询(termQuery)
+     *
+     * @param indexName  索引名
+     * @param columnName 列名或字段名
+     * @param value      查询内容
+     * @param classz     数据结构
+     * @param <T>        数据结构
+     * @return 精确查询内容数据
+     */
+    @Override
+    public <T> List<T> termQuery(String indexName, String columnName, Object value, Class<T> classz) {
+        /* 查询的数据列表 */
+        List<T> list = new ArrayList<>();
+        try {
+            /*构建查询条件(注意:termQuery 支持多种格式查询,如 boolean、int、double、string 等,这里使用的是 string 的查询)*/
+            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
+            searchSourceBuilder.query(QueryBuilders.termQuery(columnName, value));
+            /*执行查询es数据*/
+            queryEsData(indexName, classz, list, searchSourceBuilder);
+        } catch (IOException e) {
+            log.error("精确查询数据失败,错误信息:", e);
+        }
+        return list;
+    }
+
+    /**
+     * terms:多个查询内容在一个字段中进行查询
+     *
+     * @param indexName  索引名
+     * @param columnName 列名或字段名
+     * @param dataArgs   查询内容集合
+     * @param classz     数据结构
+     * @param <T>        数据结构
+     * @return 多个查询内容在一个字段中进行查询对应结果
+     */
+    @Override
+    public <T> List<T> termsQuery(String indexName, String columnName, Object[] dataArgs, Class<T> classz) {
+        /*查询的数据列表*/
+        List<T> list = new ArrayList<>();
+        try {
+            /* 构建查询条件(注意:termsQuery 支持多种格式查询,如 boolean、int、double、string 等,这里使用的是 string 的查询)*/
+            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
+            searchSourceBuilder.query(QueryBuilders.termsQuery(columnName, dataArgs));
+            /*展示100条,默认只展示10条记录*/
+            searchSourceBuilder.size(100);
+            /*执行查询es数据*/
+            queryEsData(indexName, classz, list, searchSourceBuilder);
+        } catch (IOException e) {
+            log.error("单字段多内容查询数据失败,错误信息:", e);
+        }
+        return list;
+    }
+
+    /**
+     * 匹配查询符合条件的所有数据,并设置分页
+     *
+     * @param indexName  索引名
+     * @param classz     数据结构
+     * @param startIndex 起始下标
+     * @param pageSize   页大小
+     * @param orderList  设置排序
+     * @param columnName 列名或字段名
+     * @param value      列名或字段名指定内容
+     * @param <T>        数据结构
+     * @return 符合条件的所有数据
+     */
+    @Override
+    public <T> List<T> matchAllQuery(String indexName, Class<T> classz, int startIndex, int pageSize, List<String> orderList, String columnName, Object value) {
+        /*查询的数据列表*/
+        List<T> list = new ArrayList<>();
+        try {
+            /*创建查询源构造器*/
+            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
+
+            /*构建查询条件*/
+            if (StringUtils.isNotBlank(columnName) && Objects.nonNull(value)) {
+                MatchQueryBuilder matchQueryBuilder = QueryBuilders.matchQuery(columnName, value);
+                searchSourceBuilder.query(matchQueryBuilder);
+            } else {
+                MatchAllQueryBuilder matchAllQueryBuilder = QueryBuilders.matchAllQuery();
+                searchSourceBuilder.query(matchAllQueryBuilder);
+            }
+
+            /*设置分页*/
+            searchSourceBuilder.from(startIndex);
+            searchSourceBuilder.size(pageSize);
+
+            /*设置排序*/
+            if (orderList != null) {
+                for (String order : orderList) {
+                    /*开头代表:倒序*/
+                    boolean flag = order.startsWith("-");
+                    SortOrder sort = flag ? SortOrder.DESC : SortOrder.ASC;
+                    order = flag ? order.substring(1) : order;
+                    searchSourceBuilder.sort(order, sort);
+                }
+            }
+            /*执行查询es数据*/
+            queryEsData(indexName, classz, list, searchSourceBuilder);
+        } catch (IOException e) {
+            log.error("查询所有数据失败,错误信息:", e);
+        }
+        return list;
+    }
+
+    /**
+     * 词语匹配查询
+     *
+     * @param indexName  索引名
+     * @param classz     数据结构
+     * @param columnName 列名或字段名
+     * @param value      指定内容
+     * @param <T>        数据结构
+     * @return 词语匹配查询结果
+     */
+    @Override
+    public <T> List<T> matchPhraseQuery(String indexName, Class<T> classz, String columnName, Object value) {
+        /*查询的数据列表*/
+        List<T> list = new ArrayList<>();
+        try {
+            /*构建查询条件*/
+            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
+            searchSourceBuilder.query(QueryBuilders.matchPhraseQuery(columnName, value));
+            /*执行查询es数据*/
+            queryEsData(indexName, classz, list, searchSourceBuilder);
+        } catch (IOException e) {
+            log.error("词语匹配查询失败,错误信息:", e);
+        }
+        return list;
+    }
+
+    /**
+     * 内容在多字段中进行查询
+     *
+     * @param indexName 索引名
+     * @param classz    数据结构
+     * @param fields    列名或字段名集合
+     * @param text      指定内容
+     * @param <T>       数据结构
+     * @return 查询结果
+     */
+    @Override
+    public <T> List<T> matchMultiQuery(String indexName, Class<T> classz, String[] fields, Object text) {
+        /*查询的数据列表*/
+        List<T> list = new ArrayList<>();
+        try {
+            /*构建查询条件*/
+            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
+            /*设置查询条件*/
+            searchSourceBuilder.query(QueryBuilders.multiMatchQuery(text, fields));
+            /*执行查询es数据*/
+            queryEsData(indexName, classz, list, searchSourceBuilder);
+        } catch (IOException e) {
+            log.error("词语匹配查询失败,错误信息:", e);
+        }
+        return list;
+    }
+
+    /**
+     * 通配符查询(wildcard):会对查询条件进行分词。还可以使用通配符 ?(任意单个字符) 和 * (0个或多个字符)
+     *
+     * @param indexName 索引名
+     * @param classz    数据结构
+     * @param field     列名或字段名集合
+     * @param text      指定内容
+     * @param <T>       数据结构
+     * @return 查询结果
+     */
+    @Override
+    public <T> List<T> wildcardQuery(String indexName, Class<T> classz, String field, String text) {
+        /*查询的数据列表*/
+        List<T> list = new ArrayList<>();
+        try {
+            /*构建查询条件*/
+            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
+            searchSourceBuilder.query(QueryBuilders.wildcardQuery(field, text));
+            /*执行查询es数据*/
+            queryEsData(indexName, classz, list, searchSourceBuilder);
+        } catch (IOException e) {
+            log.error("通配符查询失败,错误信息:", e);
+        }
+        return list;
+    }
+
+    /**
+     * 模糊查询商品信息
+     *
+     * @param indexName 索引名
+     * @param classz    数据结构
+     * @param field     列名或字段名集合
+     * @param text      指定内容
+     * @param <T>       数据结构
+     * @return 查询结果
+     */
+    @Override
+    public <T> List<T> fuzzyQuery(String indexName, Class<T> classz, String field, String text) {
+        /*查询的数据列表*/
+        List<T> list = new ArrayList<>();
+        try {
+            /*构建查询条件*/
+            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
+            searchSourceBuilder.query(QueryBuilders.fuzzyQuery(field, text).fuzziness(Fuzziness.AUTO));
+            /*执行查询es数据*/
+            queryEsData(indexName, classz, list, searchSourceBuilder);
+        } catch (IOException e) {
+            log.error("通配符查询失败,错误信息:", e);
+        }
+        return list;
+    }
+
+    /**
+     * boolQuery 查询
+     * 高亮展示标题搜索字段
+     * 设置出参返回字段
+     * 案例:查询从2018-2022年间标题含 三星 的商品信息
+     *
+     * @param indexName 索引名
+     * @param beanClass 数据结构
+     * @param <T>       数据结构
+     * @return 查询结果
+     */
+    @Override
+    public <T> List<T> boolQuery(String indexName, Class<T> beanClass) {
+        /*查询的数据列表*/
+        List<T> list = new ArrayList<>();
+        try {
+            /*创建 Bool 查询构建器*/
+            BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
+            /*构建查询条件*/
+            /*构建查询源构建器*/
+            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
+            searchSourceBuilder.query(boolQueryBuilder);
+            searchSourceBuilder.size(100);
+            /*甚至返回字段
+            如果查询的属性很少,那就使用includes,而excludes设置为空数组
+            如果排序的属性很少,那就使用excludes,而includes设置为空数组*/
+            /*创建查询请求对象,将查询对象配置到其中*/
+            SearchRequest searchRequest = new SearchRequest(indexName);
+            searchRequest.source(searchSourceBuilder);
+            /*执行查询,然后处理响应结果*/
+            SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
+            /*根据状态和数据条数验证是否返回了数据*/
+            if (RestStatus.OK.equals(searchResponse.status()) && searchResponse.getHits().getTotalHits().value > 0) {
+                SearchHits hits = searchResponse.getHits();
+                for (SearchHit hit : hits) {
+                    /* 将 JSON 转换成对象*/
+                    T bean = JSON.parseObject(hit.getSourceAsString(), beanClass);
+                    /*获取高亮的数据*/
+                    HighlightField highlightField = hit.getHighlightFields().get("title");
+                    log.info("高亮名称:{}", highlightField.getFragments()[0].string());
+                    /*替换掉原来的数据*/
+                    Text[] fragments = highlightField.getFragments();
+                    if (fragments != null && fragments.length > 0) {
+                        StringBuilder title = new StringBuilder();
+                        for (Text fragment : fragments) {
+                            title.append(fragment);
+                        }
+                        /* 获取method对象,其中包含方法名称和参数列表*/
+                        Method setTitle = beanClass.getMethod("setTitle", String.class);
+                        if (setTitle != null) {
+                            /*执行method,bean为实例对象,后面是方法参数列表;setTitle没有返回值*/
+                            setTitle.invoke(bean, title.toString());
+                        }
+                    }
+                    list.add(bean);
+                }
+            }
+        } catch (Exception e) {
+            log.error("布尔查询失败,错误信息:", e);
+        }
+        return list;
+    }
+
+    /**
+     * 聚合查询 : 聚合查询一定是【先查出结果】,然后对【结果使用聚合函数】做处理.
+     * Metric 指标聚合分析。常用的操作有:avg:求平均、max:最大值、min:最小值、sum:求和等
+     * 案例:分别获取最贵的商品和获取最便宜的商品
+     *
+     * @param indexName 索引名
+     */
+    @Override
+    public void metricQuery(String indexName) {
+        try {
+            /* 构建查询条件*/
+            MatchAllQueryBuilder matchAllQueryBuilder = QueryBuilders.matchAllQuery();
+            /*创建查询源构造器*/
+            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
+            searchSourceBuilder.query(matchAllQueryBuilder);
+
+            /*获取最贵的商品*/
+            AggregationBuilder maxPrice = AggregationBuilders.max("maxPrice").field("price");
+            searchSourceBuilder.aggregation(maxPrice);
+            /*获取最便宜的商品*/
+            AggregationBuilder minPrice = AggregationBuilders.min("minPrice").field("price");
+            searchSourceBuilder.aggregation(minPrice);
+
+            /*创建查询请求对象,将查询对象配置到其中*/
+            SearchRequest searchRequest = new SearchRequest(indexName);
+            searchRequest.source(searchSourceBuilder);
+            /*执行查询,然后处理响应结果*/
+            SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
+            Aggregations aggregations = searchResponse.getAggregations();
+            ParsedMax max = aggregations.get("maxPrice");
+            log.info("最贵的价格:" + max.getValue());
+            ParsedMin min = aggregations.get("minPrice");
+            log.info("最便宜的价格:" + min.getValue());
+        } catch (Exception e) {
+            log.error("指标聚合分析查询失败,错误信息:", e);
+        }
+    }
+
+    /**
+     * 聚合查询: 聚合查询一定是【先查出结果】,然后对【结果使用聚合函数】做处理
+     * Bucket 分桶聚合分析 : 对查询出的数据进行分组group by,再在组上进行游标聚合
+     * 案例:根据品牌进行聚合查询
+     *
+     * @param indexName        索引名
+     * @param bucketField
+     * @param bucketFieldAlias
+     */
+    @Override
+    public void bucketQuery(String indexName, String bucketField, String bucketFieldAlias) {
+        try {
+            /*构建查询条件*/
+            MatchAllQueryBuilder matchAllQueryBuilder = QueryBuilders.matchAllQuery();
+            /*创建查询源构造器*/
+            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
+            searchSourceBuilder.query(matchAllQueryBuilder);
+
+            /*根据bucketField进行分组查询*/
+            TermsAggregationBuilder aggBrandName = AggregationBuilders.terms(bucketFieldAlias).field(bucketField);
+            searchSourceBuilder.aggregation(aggBrandName);
+
+            /*创建查询请求对象,将查询对象配置到其中*/
+            SearchRequest searchRequest = new SearchRequest(indexName);
+            searchRequest.source(searchSourceBuilder);
+            /*执行查询,然后处理响应结果*/
+            SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
+            Aggregations aggregations = searchResponse.getAggregations();
+            /*分组结果数据*/
+            ParsedStringTerms aggBrandName1 = aggregations.get(bucketFieldAlias);
+            for (Terms.Bucket bucket : aggBrandName1.getBuckets()) {
+                log.info(bucket.getKeyAsString() + "====" + bucket.getDocCount());
+            }
+        } catch (IOException e) {
+            log.error("分桶聚合分析查询失败,错误信息:", e);
+        }
+    }
+
+    /**
+     * 子聚合聚合查询  Bucket 分桶聚合分析
+     * <p>
+     * 案例:根据商品分类进行分组查询,并且获取分类商品中的平均价格
+     *
+     * @param indexName        索引名
+     * @param bucketField
+     * @param bucketFieldAlias
+     * @param avgFiled
+     * @param avgFiledAlias
+     */
+    @Override
+    public void subBucketQuery(String indexName, String bucketField, String bucketFieldAlias, String avgFiled, String avgFiledAlias) {
+        try {
+            /*构建查询条件*/
+            MatchAllQueryBuilder matchAllQueryBuilder = QueryBuilders.matchAllQuery();
+            /*创建查询源构造器*/
+            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
+            searchSourceBuilder.query(matchAllQueryBuilder);
+
+            /* 根据 bucketField进行分组查询,并且获取分类信息中 指定字段的平均值*/
+            TermsAggregationBuilder subAggregation = AggregationBuilders.terms(bucketFieldAlias).field(bucketField)
+                    .subAggregation(AggregationBuilders.avg(avgFiledAlias).field(avgFiled));
+            searchSourceBuilder.aggregation(subAggregation);
+
+            /* 创建查询请求对象,将查询对象配置到其中*/
+            SearchRequest searchRequest = new SearchRequest(indexName);
+            searchRequest.source(searchSourceBuilder);
+            /*执行查询,然后处理响应结果*/
+            SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
+            Aggregations aggregations = searchResponse.getAggregations();
+            ParsedStringTerms aggBrandName1 = aggregations.get(bucketFieldAlias);
+            for (Terms.Bucket bucket : aggBrandName1.getBuckets()) {
+                /*获取聚合后的 组内字段平均值,注意返回值不是Aggregation对象,而是指定的ParsedAvg对象*/
+                ParsedAvg avgPrice = bucket.getAggregations().get(avgFiledAlias);
+                log.info(bucket.getKeyAsString() + "====" + avgPrice.getValueAsString());
+            }
+        } catch (IOException e) {
+            log.error("分桶聚合分析查询失败,错误信息:", e);
+        }
+    }
+
+    /**
+     * 综合聚合查询
+     * <p>
+     * 根据商品分类聚合,获取每个商品类的平均价格,并且在商品分类聚合之上子聚合每个品牌的平均价格
+     *
+     * @param indexName 索引名
+     */
+    @Override
+    public void subSubAgg(String indexName) {
+        try {
+            /*构建查询条件*/
+            MatchAllQueryBuilder matchAllQueryBuilder = QueryBuilders.matchAllQuery();
+            /*创建查询源构造器*/
+            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
+            searchSourceBuilder.query(matchAllQueryBuilder);
+
+            /*注意这里聚合写的位置不要写错,很容易搞混,错一个括号就不对了*/
+            TermsAggregationBuilder subAggregation = AggregationBuilders.terms("categoryNameAgg").field("categoryName")
+                    .subAggregation(AggregationBuilders.avg("categoryNameAvgPrice").field("price"))
+                    .subAggregation(AggregationBuilders.terms("brandNameAgg").field("brandName")
+                            .subAggregation(AggregationBuilders.avg("brandNameAvgPrice").field("price")));
+            searchSourceBuilder.aggregation(subAggregation);
+
+            /*创建查询请求对象,将查询对象配置到其中*/
+            SearchRequest searchRequest = new SearchRequest(indexName);
+            searchRequest.source(searchSourceBuilder);
+            /*执行查询,然后处理响应结果*/
+            SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
+            /*获取总记录数*/
+            log.info("totalHits = " + searchResponse.getHits().getTotalHits().value);
+            /*获取聚合信息*/
+            Aggregations aggregations = searchResponse.getAggregations();
+            ParsedStringTerms categoryNameAgg = aggregations.get("categoryNameAgg");
+
+            /*获取值返回*/
+            for (Terms.Bucket bucket : categoryNameAgg.getBuckets()) {
+                /*获取聚合后的分类名称*/
+                String categoryName = bucket.getKeyAsString();
+                /*获取聚合命中的文档数量*/
+                long docCount = bucket.getDocCount();
+                /*获取聚合后的分类的平均价格,注意返回值不是Aggregation对象,而是指定的ParsedAvg对象*/
+                ParsedAvg avgPrice = bucket.getAggregations().get("categoryNameAvgPrice");
+                log.info(categoryName + "======平均价:" + avgPrice.getValue() + "======数量:" + docCount);
+
+                ParsedStringTerms brandNameAgg = bucket.getAggregations().get("brandNameAgg");
+                for (Terms.Bucket brandeNameAggBucket : brandNameAgg.getBuckets()) {
+                    /*获取聚合后的品牌名称*/
+                    String brandName = brandeNameAggBucket.getKeyAsString();
+                    /*获取聚合后的品牌的平均价格,注意返回值不是Aggregation对象,而是指定的ParsedAvg对象*/
+                    ParsedAvg brandNameAvgPrice = brandeNameAggBucket.getAggregations().get("brandNameAvgPrice");
+                    log.info("     " + brandName + "======" + brandNameAvgPrice.getValue());
+                }
+            }
+        } catch (IOException e) {
+            log.error("综合聚合查询失败,错误信息:", e);
+        }
+    }
+
+
+    /**
+     * 执行es查询
+     *
+     * @param indexName
+     * @param beanClass
+     * @param list
+     * @param searchSourceBuilder
+     * @param <T>
+     * @throws IOException
+     */
+    private <T> void queryEsData(String indexName, Class<T> beanClass, List<T> list, SearchSourceBuilder searchSourceBuilder) throws IOException {
+        /*创建查询请求对象,将查询对象配置到其中*/
+        SearchRequest searchRequest = new SearchRequest(indexName);
+        searchRequest.source(searchSourceBuilder);
+        /*执行查询,然后处理响应结果*/
+        SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
+        /*根据状态和数据条数验证是否返回了数据*/
+        if (RestStatus.OK.equals(searchResponse.status()) && searchResponse.getHits().getTotalHits().value > 0) {
+            SearchHits hits = searchResponse.getHits();
+            for (SearchHit hit : hits) {
+                /*将 JSON 转换成对象*/
+                T bean = JSON.parseObject(hit.getSourceAsString(), beanClass);
+                list.add(bean);
+            }
+        }
+    }
+}

+ 0 - 13
4dkankan-utils-es/src/main/java/com/fdkankan/App.java

@@ -1,13 +0,0 @@
-package com.fdkankan;
-
-/**
- * Hello world!
- *
- */
-public class App 
-{
-    public static void main( String[] args )
-    {
-        System.out.println( "Hello World!" );
-    }
-}

+ 0 - 20
4dkankan-utils-es/src/test/java/com/fdkankan/AppTest.java

@@ -1,20 +0,0 @@
-package com.fdkankan;
-
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
-
-/**
- * Unit test for simple App.
- */
-public class AppTest 
-{
-    /**
-     * Rigorous Test :-)
-     */
-    @Test
-    public void shouldAnswerWithTrue()
-    {
-        assertTrue( true );
-    }
-}

+ 44 - 23
4dkankan-utils-fyun-local/src/main/java/com/fdkankan/fyun/local/LocalFileService.java

@@ -27,7 +27,11 @@ public class LocalFileService extends AbstractFYunFileService {
 
     @Override
     public String uploadFile(String bucket, byte[] data, String remoteFilePath) {
-        FileUtil.writeBytes(data, getOssPath(bucket, remoteFilePath));
+        try {
+            FileUtil.writeBytes(data, getOssPath(bucket, remoteFilePath));
+        }catch (Exception e){
+            log.error("oss上传文件失败,remoteFilePath:" + remoteFilePath, e);
+        }
         return null;
     }
 
@@ -38,17 +42,28 @@ public class LocalFileService extends AbstractFYunFileService {
 
     @Override
     public String uploadFile(String bucket, InputStream inputStream, String remoteFilePath) {
-        FileUtil.writeFromStream(inputStream,getOssPath(bucket, remoteFilePath));
+        try {
+            FileUtil.writeFromStream(inputStream,getOssPath(bucket, remoteFilePath));
+        }catch (Exception e){
+            log.error("上传文件失败,remoteFilePath:{}", remoteFilePath);
+            log.error("上传文件失败", e);
+        }
         return null;
     }
 
     @Override
     public String uploadFile(String bucket, String filePath, String remoteFilePath, Map<String, String> headers) {
-        if (!new File(filePath).exists()) {
-            log.error("文件不存在,不予上传:{}", filePath);
-            return null;
+        try {
+            if (!new File(filePath).exists()) {
+                log.warn("文件不存在:{}", filePath);
+                return null;
+            }
+            FileUtil.copy(filePath, getOssPath(bucket, remoteFilePath), true);
+        }catch (Exception e){
+            log.error("上传文件失败,filePath:{},remoteFilePath:{}", filePath, remoteFilePath);
+            log.error("上传文件失败", e);
         }
-        FileUtil.copy(filePath, getOssPath(bucket, remoteFilePath), true);
+
         return null;
     }
 
@@ -61,7 +76,6 @@ public class LocalFileService extends AbstractFYunFileService {
             callshell(command);
         } catch (Exception e) {
             log.error("上传文件失败, ossPath:{}, srcPath:{}", remoteFilePath, filePath);
-            e.printStackTrace();
         }
         return null;
     }
@@ -75,7 +89,6 @@ public class LocalFileService extends AbstractFYunFileService {
             callshell(command);
         } catch (Exception e) {
             log.error("上传文件失败, ossPath:{}, srcPath:{}", remoteFilePath, filePath);
-            e.printStackTrace();
         }
     }
 
@@ -91,12 +104,8 @@ public class LocalFileService extends AbstractFYunFileService {
 
     @Override
     public void uploadMulFiles(String bucket, Map<String, String> filepaths) {
-        try {
-            for (Map.Entry<String, String> entry : filepaths.entrySet()) {
-                uploadFile(bucket, entry.getKey(), entry.getValue(), null);
-            }
-        } catch (Exception e) {
-            log.error("OSS批量上传文件失败!");
+        for (Map.Entry<String, String> entry : filepaths.entrySet()) {
+            uploadFile(bucket, entry.getKey(), entry.getValue(), null);
         }
     }
 
@@ -114,7 +123,12 @@ public class LocalFileService extends AbstractFYunFileService {
 
     @Override
     public void copyFileBetweenBucket(String sourceBucketName, String sourcePath, String targetBucketName, String targetPath) {
-        FileUtil.copyContent(new File(getOssPath(sourceBucketName, sourcePath)), new File(getOssPath(targetBucketName, targetPath)), true);
+        try {
+            FileUtil.copyContent(new File(getOssPath(sourceBucketName, sourcePath)), new File(getOssPath(targetBucketName, targetPath)), true);
+        }catch (Exception e){
+            log.error("复制文件失败,sourcePath:{},targetPath:{}",sourcePath,targetPath);
+            log.error("复制文件失败", e);
+        }
     }
 
     @Override
@@ -122,18 +136,20 @@ public class LocalFileService extends AbstractFYunFileService {
         if (ObjectUtils.isEmpty(pathMap)) {
             return;
         }
-        try {
-            for (Map.Entry<String, String> entry : pathMap.entrySet()) {
-                copyFileBetweenBucket(sourceBucketName, entry.getKey(), targetBucketName, entry.getValue());
-            }
-        } catch (Exception e) {
-            log.error("批量复制文件失败!");
+        for (Map.Entry<String, String> entry : pathMap.entrySet()) {
+            copyFileBetweenBucket(sourceBucketName, entry.getKey(), targetBucketName, entry.getValue());
         }
     }
 
     @Override
     public String getFileContent(String bucketName, String remoteFilePath) {
-        return FileUtil.readUtf8String(getOssPath(bucketName, remoteFilePath));
+        try {
+            return FileUtil.readUtf8String(getOssPath(bucketName, remoteFilePath));
+        }catch (Exception e){
+            log.error("读取文件失败,remoteFilePath:{}", remoteFilePath);
+            log.error("读取文件失败", e);
+            return null;
+        }
     }
 
     @Override
@@ -143,7 +159,12 @@ public class LocalFileService extends AbstractFYunFileService {
 
     @Override
     public void downloadFile(String bucket, String remoteFilePath, String localPath) {
-        FileUtil.copy(getOssPath(bucket, remoteFilePath), localPath, true);
+        try {
+            FileUtil.copy(getOssPath(bucket, remoteFilePath), localPath, true);
+        }catch (Exception e){
+            log.error("下载文件失败,remoteFilePath:{},localPath:{}", remoteFilePath, localPath);
+            log.error("下载文件失败", e);
+        }
     }
 
     @Override

+ 55 - 0
4dkankan-utils-fyun-oss/src/main/java/com/fdkankan/fyun/oss/OssFileService.java

@@ -1,5 +1,6 @@
 package com.fdkankan.fyun.oss;
 
+import cn.hutool.core.collection.CollUtil;
 import com.aliyun.oss.HttpMethod;
 import com.aliyun.oss.OSS;
 import com.aliyun.oss.model.*;
@@ -321,4 +322,58 @@ public class OssFileService extends AbstractFYunFileService {
         return totalSubFileNum;
     }
 
+    @Override
+    public void restoreFolder(String bucket, String folderName, Integer priority) {
+
+        List<String> objectList = this.listRemoteFiles(bucket, folderName);
+        if(CollUtil.isEmpty(objectList)){
+            return;
+        }
+        objectList.parallelStream().forEach(objectName -> {
+            this.restoreFile(bucket, objectName, priority);
+        });
+    }
+
+    @Override
+    public void restoreFile(String bucket, String objectName, Integer priority){
+        ObjectMetadata objectMetadata = ossClient.getObjectMetadata(bucket, objectName);
+
+        // 校验Object是否为归档类型Object。
+        StorageClass storageClass = objectMetadata.getObjectStorageClass();
+        if (storageClass == StorageClass.ColdArchive) {
+            // 设置解冻冷归档Object的优先级。
+            // RestoreTier.RESTORE_TIER_EXPEDITED 表示1小时内完成解冻。
+            // RestoreTier.RESTORE_TIER_STANDARD 表示2~5小时内完成解冻。
+            // RestoreTier.RESTORE_TIER_BULK 表示5~12小时内完成解冻。
+            RestoreTier restoreTier = null;
+            switch (priority){
+                case 1 :
+                    restoreTier = RestoreTier.RESTORE_TIER_EXPEDITED;
+                    break;
+                case 2 :
+                    restoreTier = RestoreTier.RESTORE_TIER_STANDARD;
+                    break;
+                default:
+                    restoreTier = RestoreTier.RESTORE_TIER_BULK;
+            }
+            RestoreJobParameters jobParameters = new RestoreJobParameters(restoreTier);
+            // 配置解冻参数,以设置5小时内解冻完成,解冻状态保持2天为例。
+            // 第一个参数表示保持解冻状态的天数,默认是1天,此参数适用于解冻Archive(归档)与ColdArchive(冷归档)类型Object。
+            // 第二个参数jobParameters表示解冻优先级,只适用于解冻ColdArchive类型Object。
+            RestoreConfiguration configuration = new RestoreConfiguration(1, jobParameters);
+            //开始解冻
+            ossClient.restoreObject(bucket, objectName, configuration);
+            // 等待解冻完成。
+            do {
+                try {
+                    Thread.sleep(1000);
+                } catch (InterruptedException e) {
+                    e.printStackTrace();
+                }
+                objectMetadata = ossClient.getObjectMetadata(bucket, objectName);
+            } while (!objectMetadata.isRestoreCompleted());
+        }
+    }
+
+
 }

+ 3 - 0
4dkankan-utils-fyun-parent/src/main/java/com/fdkankan/fyun/config/FYunFileConfig.java

@@ -15,6 +15,9 @@ public class FYunFileConfig {
     @Value("${fyun.bucket}")
     private String bucket;
 
+    @Value("${fyun.freeze-bucket:4dkk-bak}")
+    private String freezeBucket;
+
     @Value("${fyun.endPoint}")
     private String endPoint;
 

+ 2 - 1
4dkankan-utils-fyun-parent/src/main/java/com/fdkankan/fyun/face/AbstractFYunFileService.java

@@ -127,7 +127,7 @@ public abstract class AbstractFYunFileService implements FYunFileServiceInterfac
             process.waitFor();
             log.info("脚本{}执行完毕,用时:{}ms",command,System.currentTimeMillis()-start);
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error("调用脚本文件上传下载失败, command : " + command, e);
         }
     }
 
@@ -141,4 +141,5 @@ public abstract class AbstractFYunFileService implements FYunFileServiceInterfac
     public long getSubFileNums(String url) {
         return getSubFileNums(fYunFileConfig.getBucket(), url);
     }
+
 }

+ 4 - 0
4dkankan-utils-fyun-parent/src/main/java/com/fdkankan/fyun/face/FYunFileServiceInterface.java

@@ -328,4 +328,8 @@ public interface FYunFileServiceInterface {
     public long getSubFileNums(String url);
 
     public long getSubFileNums(String bucket,String url);
+
+    public void restoreFolder(String bucket, String folderName, Integer priority);
+
+    public void restoreFile(String bucket, String objectName, Integer priority);
 }

+ 10 - 0
4dkankan-utils-fyun-s3/src/main/java/com/fdkankan/fyun/s3/S3FileService.java

@@ -331,4 +331,14 @@ public class S3FileService extends AbstractFYunFileService {
         }
         return totalFileNums;
     }
+
+    @Override
+    public void restoreFolder(String bucket, String folderName, Integer priority) {
+
+    }
+
+    @Override
+    public void restoreFile(String bucket, String objectName, Integer priority){
+
+    }
 }

+ 5 - 0
4dkankan-utils-model/src/main/java/com/fdkankan/model/constants/ConstantFilePath.java

@@ -139,6 +139,11 @@ public class ConstantFilePath {
      */
     public static final String FILE_CONVERT_PATH = BASE_PATH + "/fileConvert/";
 
+    /**
+     * 文件转换目录
+     */
+    public static final String OPENAPI_DOWNLOAD_PATH = SCENE_V4_PATH + "%s/openApi/download/";
+
 
 
 

+ 24 - 0
4dkankan-utils-model/src/main/java/com/fdkankan/model/utils/SceneUtil.java

@@ -9,7 +9,9 @@ import com.fdkankan.model.constants.ConstantFilePath;
 
 import java.io.File;
 import java.nio.charset.Charset;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 /**
@@ -71,5 +73,27 @@ public class SceneUtil {
         return homePath;
     }
 
+    public static Map<String, String> getPropertyFromDataSource(String dataSource){
+        if(StrUtil.isEmpty(dataSource)){
+            return null;
+        }
+        String homePath = getHomePath(dataSource);
+        homePath = homePath.substring(0, homePath.lastIndexOf("/"));
+        String[] arr = homePath.split("/");
+        Map<String, String> result = new HashMap<>();
+        result.put("homePath", homePath);
+        result.put("snCode", arr[1]);
+        result.put("fileId", arr[2]);
+        result.put("uuid", arr[3]);
+        return result;
+    }
+
+    public static void main(String[] args) {
+        String str = "27";
+        int  n = 8;
+        System.out.println("10进制=" + Integer.parseInt(str, n));
+        System.out.println(Integer.toHexString(Integer.parseInt(str, n)));
+    }
+
 
 }

+ 35 - 0
4dkankan-utils-pdf/pom.xml

@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>4dkankan-utils</artifactId>
+        <groupId>com.fdkankan</groupId>
+        <version>3.0.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>4dkankan-utils-pdf</artifactId>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.aspose</groupId>
+            <artifactId>aspose-cells</artifactId>
+            <version>22.7</version>
+        </dependency>
+
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>8</source>
+                    <target>8</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>

+ 19 - 1
4dkankan-utils-rabbitmq/src/main/java/com/fdkankan/rabbitmq/util/RabbitMqProducer.java

@@ -35,7 +35,9 @@ public class RabbitMqProducer {
     private RabbitTemplate rabbitTemplate;
 
     /**
-     * 工作队列模式发送
+     * 工作队列模式发送消息
+     * @param queue 队列名
+     * @param content 载荷
      */
     public void sendByWorkQueue(String queue, Object content){
         String messageId = UUID.randomUUID().toString();
@@ -47,6 +49,22 @@ public class RabbitMqProducer {
     }
 
     /**
+     * 工作队列模式发送带优先级消息
+     * @param queue 队列名
+     * @param content 载荷
+     * @param priority 优先级,正整数,值越大优先级越高,当值大于队列设置的最大优先级时,效果等同于最大优先级
+     */
+    public void sendByWorkQueue(String queue, Object content, Integer priority){
+        String messageId = UUID.randomUUID().toString();
+        log.info("开始发送Mq消息,messageId:{},消息队列:{},消息内容:{}",messageId, queue, new JSONObject(content).toString());
+        rabbitTemplate.convertAndSend(queue, content, message -> {
+            message.getMessageProperties().setMessageId(messageId);
+            message.getMessageProperties().setPriority(priority);
+            return message;
+        }, new CorrelationData(messageId));
+    }
+
+    /**
      * 获取队列未被消费的消息数量
      * @return
      */

+ 36 - 1
4dkankan-utils-redis/src/main/java/com/fdkankan/redis/constant/RedisKey.java

@@ -120,6 +120,11 @@ public class RedisKey {
     public static final String SCENE_LINKPAN_STYLES = "scene:LinkPanStyles:num:%s";
 
     /**
+     * 场景指示牌数据列表
+     */
+    public static final String SCENE_BILLBOARDS = "scene:billboards:num:%s";
+
+    /**
      * 场景下载任务列表
      */
     public static final String SCENE_DOWNLOADS_TASK_V4 = "scene:downloads:task:v4";
@@ -173,10 +178,40 @@ public class RedisKey {
     public static final String SCENE_UPLOAD_MATTERPRO_NUM= "scene:upload:matterpro:num";
 
     /**
-     * 上传matterprodata状态
+     * 人体抠图任务id
      */
     public static final String SCENE_BODY_SEGMENT= "scene:body:segment:uuid:%s";
 
+    /**
+     * 场景oss原始资源目录删除
+     */
+    public static final String SCENE_OSS_HOME_DIR_DELETE= "scene:oss:home:dir:delete:unicode:%s";
+
+    /**
+     * 场景oss原始资源目录上传
+     */
+    public static final String SCENE_OSS_HOME_DIR_UPLOAD= "scene:oss:home:dir:upload:unicode:%s";
+
+    /**
+     * 场景oss原始资源目录上传
+     */
+    public static final String SCENE_BUILD_EXPECT_TOTAL_TIME_NUM= "scene:build:expect:total:time:num:%s";
+
+    /**
+     * 场景oss原始资源目录上传
+     */
+    public static final String SCENE_BUILD_FINISH_NUM = "scene:build:finish:num:%s";
+
+    /**
+     * 场景oss原始资源目录上传
+     */
+    public static final String SINGLE_MODELING_SERVER_BUSY = "singleModelingServerBusy";
+
+    /**
+     * 打点系统应用id缓存
+     */
+    public static final String TRACK_APPID = "track:appid";
+
 
 
 

+ 13 - 0
4dkankan-utils-redis/src/main/java/com/fdkankan/redis/constant/RedisLockKey.java

@@ -90,6 +90,11 @@ public class RedisLockKey {
     public static String LOCK_LINKPAN_STYLES_SYNC = "lock:linkpan:styles:sync:num:%s";
 
     /**
+     * 场景指示牌数据恢复锁
+     */
+    public static String LOCK_BILLBOARDS_SYNC = "lock:billboards:sync:num:%s";
+
+    /**
      * 热点数据写文件锁
      */
     public static String LOCK_HOT_JSON = "lock:hot:json:num:%s";
@@ -159,6 +164,14 @@ public class RedisLockKey {
      */
     public static final String LOCK_GET_MATTERPRO_NUM = "lock:get:matterpro:num";
 
+    public static final String LOCK_CLEAN_SCENE_ORIG_V3 = "lock:clean:scene:orig:v3";
+
+    public static final String LOCK_CLEAN_SCENE_ORIG_V4 = "lock:clean:scene:orig:v4";
+
+    public static final String LOCK_CLEAN_SCENE_DELETED_ORIG_V3 = "lock:clean:scene:deleted:orig:v3";
+
+    public static final String LOCK_CLEAN_SCENE_DELETED_ORIG_V4 = "lock:clean:scene:deleted:orig:v4";
+
     public static void main(String[] args) {
         FileUtil.copyContent(new File("F:\\test\\test"), new File("F:\\test\\test2"), true);
     }

+ 67 - 194
4dkankan-utils-redis/src/main/java/com/fdkankan/redis/util/RedisUtil.java

@@ -28,15 +28,10 @@ public class RedisUtil<K, V>{
      * @return
      */
     public boolean expire(String key, long time) {
-        try {
-            if (time > 0) {
-                redisTemplate.expire(key, time, TimeUnit.SECONDS);
-            }
-            return true;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
+        if (time > 0) {
+            redisTemplate.expire(key, time, TimeUnit.SECONDS);
         }
+        return true;
     }
     /**
      * 根据key 获取过期时间
@@ -54,12 +49,7 @@ public class RedisUtil<K, V>{
      * @return true 存在 false不存在
      */
     public boolean hasKey(String key) {
-        try {
-            return redisTemplate.hasKey(key);
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
-        }
+        return redisTemplate.hasKey(key);
     }
     /**
      * 删除缓存
@@ -94,13 +84,8 @@ public class RedisUtil<K, V>{
      * @return true成功 false失败
      */
     public boolean set(String key, String value) {
-        try {
-            redisTemplate.opsForValue().set(key, value);
-            return true;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
-        }
+        redisTemplate.opsForValue().set(key, value);
+        return true;
     }
     /**
      * 普通缓存放入并设置时间
@@ -111,17 +96,12 @@ public class RedisUtil<K, V>{
      * @return true成功 false 失败
      */
     public boolean set(String key, String value, long time) {
-        try {
-            if (time > 0) {
-                redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
-            } else {
-                set(key, value);
-            }
-            return true;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
+        if (time > 0) {
+            redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
+        } else {
+            set(key, value);
         }
+        return true;
     }
     /**
      * 递增
@@ -203,13 +183,8 @@ public class RedisUtil<K, V>{
      * @return true 成功 false 失败
      */
     public boolean hmset(String key, Map<String, Object> map) {
-        try {
-            redisTemplate.opsForHash().putAll(key, map);
-            return true;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
-        }
+        redisTemplate.opsForHash().putAll(key, map);
+        return true;
     }
     /**
      * HashSet 并设置时间
@@ -220,16 +195,11 @@ public class RedisUtil<K, V>{
      * @return true成功 false失败
      */
     public boolean hmset(String key, Map<String, Object> map, long time) {
-        try {
-            redisTemplate.opsForHash().putAll(key, map);
-            if (time > 0) {
-                expire(key, time);
-            }
-            return true;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
+        redisTemplate.opsForHash().putAll(key, map);
+        if (time > 0) {
+            expire(key, time);
         }
+        return true;
     }
     /**
      * 向一张hash表中放入数据,如果不存在将创建
@@ -240,13 +210,8 @@ public class RedisUtil<K, V>{
      * @return true 成功 false失败
      */
     public boolean hset(String key, String item, Object value) {
-        try {
-            redisTemplate.opsForHash().put(key, item, value);
-            return true;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
-        }
+        redisTemplate.opsForHash().put(key, item, value);
+        return true;
     }
     /**
      * 向一张hash表中放入数据,如果不存在将创建
@@ -258,16 +223,11 @@ public class RedisUtil<K, V>{
      * @return true 成功 false失败
      */
     public boolean hset(String key, String item, Object value, long time) {
-        try {
-            redisTemplate.opsForHash().put(key, item, value);
-            if (time > 0) {
-                expire(key, time);
-            }
-            return true;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
+        redisTemplate.opsForHash().put(key, item, value);
+        if (time > 0) {
+            expire(key, time);
         }
+        return true;
     }
     /**
      * 删除hash表中的值
@@ -318,12 +278,7 @@ public class RedisUtil<K, V>{
      * @return
      */
     public Set<Object> sGet(String key) {
-        try {
-            return redisTemplate.opsForSet().members(key);
-        } catch (Exception e) {
-            e.printStackTrace();
-            return null;
-        }
+        return redisTemplate.opsForSet().members(key);
     }
     /**
      * 根据value从一个set中查询,是否存在
@@ -333,12 +288,7 @@ public class RedisUtil<K, V>{
      * @return true 存在 false不存在
      */
     public boolean sHasKey(String key, Object value) {
-        try {
-            return redisTemplate.opsForSet().isMember(key, value);
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
-        }
+        return redisTemplate.opsForSet().isMember(key, value);
     }
     /**
      * 将数据放入set缓存
@@ -348,12 +298,7 @@ public class RedisUtil<K, V>{
      * @return 成功个数
      */
     public long sSet(String key, Object... values) {
-        try {
-            return redisTemplate.opsForSet().add(key, values);
-        } catch (Exception e) {
-            e.printStackTrace();
-            return 0;
-        }
+        return redisTemplate.opsForSet().add(key, values);
     }
     /**
      * 将set数据放入缓存
@@ -364,15 +309,10 @@ public class RedisUtil<K, V>{
      * @return 成功个数
      */
     public long sSet(String key, long time, Object... values) {
-        try {
-            Long count = redisTemplate.opsForSet().add(key, values);
-            if (time > 0)
-                expire(key, time);
-            return count;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return 0;
-        }
+        Long count = redisTemplate.opsForSet().add(key, values);
+        if (time > 0)
+            expire(key, time);
+        return count;
     }
     /**
      * 获取set缓存的长度
@@ -381,13 +321,19 @@ public class RedisUtil<K, V>{
      * @return
      */
     public long sGetSize(String key) {
-        try {
-            return redisTemplate.opsForSet().size(key);
-        } catch (Exception e) {
-            e.printStackTrace();
-            return 0;
-        }
+        return redisTemplate.opsForSet().size(key);
     }
+
+    /**
+     * 获取set缓存的长度
+     *
+     * @param key 键
+     * @return
+     */
+    public boolean sExists(String key, Object value) {
+        return redisTemplate.opsForSet().isMember(key, value);
+    }
+
     /**
      * 移除值为value的
      *
@@ -396,13 +342,7 @@ public class RedisUtil<K, V>{
      * @return 移除的个数
      */
     public long setRemove(String key, Object... values) {
-        try {
-            Long count = redisTemplate.opsForSet().remove(key, values);
-            return count;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return 0;
-        }
+        return redisTemplate.opsForSet().remove(key, values);
     }
     // ===============================list=================================
     /**
@@ -414,13 +354,7 @@ public class RedisUtil<K, V>{
      * @return
      */
     public List<Object> lGet(String key, long start, long end) {
-        try {
-            List<Object> range = redisTemplate.opsForList().range(key, start, end);
-            return range;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return null;
-        }
+        return redisTemplate.opsForList().range(key, start, end);
     }
     /**
      * 获取list缓存的长度
@@ -429,12 +363,7 @@ public class RedisUtil<K, V>{
      * @return
      */
     public long lGetSize(String key) {
-        try {
-            return redisTemplate.opsForList().size(key);
-        } catch (Exception e) {
-            e.printStackTrace();
-            return 0;
-        }
+        return redisTemplate.opsForList().size(key);
     }
     /**
      * 通过索引 获取list中的值
@@ -444,12 +373,7 @@ public class RedisUtil<K, V>{
      * @return
      */
     public Object lGetIndex(String key, long index) {
-        try {
-            return redisTemplate.opsForList().index(key, index);
-        } catch (Exception e) {
-            e.printStackTrace();
-            return null;
-        }
+        return redisTemplate.opsForList().index(key, index);
     }
     /**
      * 将list放入缓存
@@ -458,13 +382,8 @@ public class RedisUtil<K, V>{
      * @return
      */
     public boolean lRightPush(String key, Object value) {
-        try {
-            redisTemplate.opsForList().rightPush(key, value);
-            return true;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
-        }
+        redisTemplate.opsForList().rightPush(key, value);
+        return true;
     }
     /**
      * 将list放入缓存
@@ -475,15 +394,10 @@ public class RedisUtil<K, V>{
      * @return
      */
     public boolean lRightPush(String key, Object value, long time) {
-        try {
-            redisTemplate.opsForList().rightPush(key, value);
-            if (time > 0)
-                expire(key, time);
-            return true;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
-        }
+        redisTemplate.opsForList().rightPush(key, value);
+        if (time > 0)
+            expire(key, time);
+        return true;
     }
     /**
      * 将list放入缓存
@@ -493,13 +407,8 @@ public class RedisUtil<K, V>{
      * @return
      */
     public boolean lRightPushAll(String key, List<Object> value) {
-        try {
-            redisTemplate.opsForList().rightPushAll(key, value);
-            return true;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
-        }
+        redisTemplate.opsForList().rightPushAll(key, value);
+        return true;
     }
 
     /**
@@ -511,15 +420,10 @@ public class RedisUtil<K, V>{
      * @return
      */
     public boolean lRightPushAll(String key, List<Object> value, long time) {
-        try {
-            redisTemplate.opsForList().rightPushAll(key, value);
-            if (time > 0)
-                expire(key, time);
-            return true;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
-        }
+        redisTemplate.opsForList().rightPushAll(key, value);
+        if (time > 0)
+            expire(key, time);
+        return true;
     }
 
     /**
@@ -530,13 +434,8 @@ public class RedisUtil<K, V>{
      * @return
      */
     public boolean lLeftPushAll(String key, List<Object> value) {
-        try {
-            redisTemplate.opsForList().leftPushAll(key, value);
-            return true;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
-        }
+        redisTemplate.opsForList().leftPushAll(key, value);
+        return true;
     }
 
     /**
@@ -547,13 +446,8 @@ public class RedisUtil<K, V>{
      * @return
      */
     public boolean lLeftPush(String key, String value) {
-        try {
-            redisTemplate.opsForList().leftPush(key, value);
-            return true;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
-        }
+        redisTemplate.opsForList().leftPush(key, value);
+        return true;
     }
 
     /**
@@ -562,12 +456,7 @@ public class RedisUtil<K, V>{
      * @return
      */
     public String lLeftPop(String key) {
-        try {
-            return (String)redisTemplate.opsForList().leftPop(key);
-        } catch (Exception e) {
-            e.printStackTrace();
-            return null;
-        }
+        return (String)redisTemplate.opsForList().leftPop(key);
     }
 
     /**
@@ -579,13 +468,8 @@ public class RedisUtil<K, V>{
      * @return
      */
     public boolean lUpdateByIndex(String key, long index, Object value) {
-        try {
-            redisTemplate.opsForList().set(key, index, value);
-            return true;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return false;
-        }
+        redisTemplate.opsForList().set(key, index, value);
+        return true;
     }
     /**
      * 移除N个值为value
@@ -596,13 +480,7 @@ public class RedisUtil<K, V>{
      * @return 移除的个数
      */
     public long lRemove(String key, long count, Object value) {
-        try {
-            Long remove = redisTemplate.opsForList().remove(key, count, value);
-            return remove;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return 0;
-        }
+        return redisTemplate.opsForList().remove(key, count, value);
     }
 
     /**
@@ -612,12 +490,7 @@ public class RedisUtil<K, V>{
      * @return 移除的个数
      */
     public Set<String> keys(String pattern) {
-        try {
-            return redisTemplate.keys(pattern);
-        } catch (Exception e) {
-            e.printStackTrace();
-            return new HashSet<>();
-        }
+        return redisTemplate.keys(pattern);
     }
 
     public void expire(String key,Duration time){

+ 5 - 0
4dkankan-utils-sms/pom.xml

@@ -52,6 +52,11 @@
             <artifactId>javax.mail</artifactId>
             <version>1.5.4</version>
         </dependency>
+        <dependency>
+            <groupId>com.aliyun</groupId>
+            <artifactId>dysmsapi20170525</artifactId>
+            <version>2.0.23</version>
+        </dependency>
     </dependencies>
 
 </project>

+ 93 - 0
4dkankan-utils-sms/src/main/java/com/fdkankan/sms/SmsServiceV2.java

@@ -0,0 +1,93 @@
+package com.fdkankan.sms;
+
+import com.aliyun.dysmsapi20170525.Client;
+import com.aliyun.tea.*;
+import com.aliyuncs.DefaultAcsClient;
+import com.aliyuncs.IAcsClient;
+import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
+import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
+import com.aliyuncs.exceptions.ClientException;
+import com.aliyuncs.profile.DefaultProfile;
+import com.aliyuncs.profile.IClientProfile;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
+
+/**
+ * @author Xiewj
+ * @date 2023/6/14
+ */
+@Component
+public class SmsServiceV2 {
+    private static Logger log = LoggerFactory.getLogger("programLog");
+
+    private static final String accessKeyId = "LTAIUrvuHqj8pvry";//你的accessKeyId,参考本文档步骤2
+    private static final String accessKeySecret = "JLOVl0k8Ke0aaM8nLMMiUAZ3EiiqI4";//你的accessKeySecret,参考本文档步骤2
+    @Value("${phone.sign:四维看看}")
+    private String sign;
+
+    public String sendSms(String phoneNum, String templateParam, String templateCode) throws Exception {
+        log.info("cnCode:" + templateCode);
+        log.info("templateParam:" + templateParam);
+        log.info("sign:" + sign);
+        // 可自助调整超时时间
+        System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
+        System.setProperty("sun.net.client.defaultReadTimeout", "10000");
+        String result = null;
+        try {
+            Client client = createClient();
+
+            com.aliyun.dysmsapi20170525.models.SendSmsRequest sendSmsRequest = new com.aliyun.dysmsapi20170525.models.SendSmsRequest();
+            // 必填:待发送手机号
+            sendSmsRequest.setPhoneNumbers(phoneNum);
+            // 必填:短信签名-可在短信控制台中找到
+            sendSmsRequest.setSignName(sign);
+            // 必填:短信模板-可在短信控制台中找到
+            sendSmsRequest.setTemplateCode(templateCode);
+
+            // 可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
+            sendSmsRequest.setTemplateParam(templateParam);
+            com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
+            com.aliyun.dysmsapi20170525.models.SendSmsResponse sendSmsResponse = client.sendSmsWithOptions(sendSmsRequest, runtime);
+            // 组装请求对象-具体描述见控制台-文档部分内容
+
+            // hint 此处可能会抛出异常,注意catch
+            if (sendSmsResponse != null
+                    && !StringUtils.isEmpty(sendSmsResponse.getBody().getCode())){
+
+                if("OK".equals(sendSmsResponse.getBody().getCode())){
+                    log.debug("阿里云短信发送成功");
+                }else {
+                    log.debug("阿里云短信发送失败:" + sendSmsResponse.getStatusCode());
+                    log.debug("阿里云短信发送失败原因:" + sendSmsResponse.getStatusCode());
+                }
+                result = sendSmsResponse.getBody().getCode();
+            }else {
+                log.debug("阿里云短信发送失败:" + sendSmsResponse.getStatusCode());
+                log.debug("阿里云短信发送失败原因:" + sendSmsResponse.getStatusCode());
+            }
+        }catch (ClientException e){
+            log.error("阿里云短信发送失败:" + e);
+        }
+        return result;
+    }
+
+    /**
+     * 使用AK&SK初始化账号Client
+     * @return Client
+     * @throws Exception
+     */
+    public static com.aliyun.dysmsapi20170525.Client createClient() throws Exception {
+        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
+                // 必填,您的 AccessKey ID
+                .setAccessKeyId(accessKeyId)
+                // 必填,您的 AccessKey Secret
+                .setAccessKeySecret(accessKeySecret);
+        // 访问的域名
+        config.endpoint = "dysmsapi.aliyuncs.com";
+        return new com.aliyun.dysmsapi20170525.Client(config);
+    }
+
+}

+ 1 - 0
pom.xml

@@ -26,6 +26,7 @@
         <module>4dkankan-utils-wechat</module>
         <module>4dkankan-utils-image</module>
         <module>4dkankan-utils-sensitive-word</module>
+        <module>4dkankan-utils-elasticsearch</module>
     </modules>
 
     <groupId>com.fdkankan</groupId>