diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..d4dfde6
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,31 @@
+HELP.md
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**
+!**/src/test/**
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+
+### VS Code ###
+.vscode/
\ No newline at end of file
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..190741e
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,12 @@
+FROM java:8
+MAINTAINER king <1609724385@qq.com>
+VOLUME /tmp
+COPY target/dipperposition.jar dipperposition.jar
+COPY --from=hengyunabc/arthas:latest /opt/arthas /opt/arthas
+ENV TimeZone=Asia/Shanghai
+ENV active=dev
+ENV JAVA_OPTS="-Xmx256M -Xms256M"
+RUN ln -snf /usr/share/zoneinfo/$TimeZone /etc/localtime && echo $TimeZone > /etc/timezone
+ENTRYPOINT java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -Dio.netty.leakDetectionLevel=ADVANCED -jar /dipperposition.jar --spring.profiles.active=$active
+
+java -Xmx256M -Xms256M -Djava.security.egd=file:/dev/./urandom -Dio.netty.leakDetectionLevel=ADVANCED -jar /dipperposition.jar --spring.profiles.active=
\ No newline at end of file
diff --git a/dipper_position_run.sh b/dipper_position_run.sh
new file mode 100644
index 0000000..fb9d25a
--- /dev/null
+++ b/dipper_position_run.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+environment=$1
+version=$2
+echo "环境变量为${environment},版本为$version!"
+
+#processID='ps -ef | grep dipperposition | awk '{print $2}' | awk NR==1'
+ps -ef | grep dipperposition | awk '{print $2}' | xargs kill -9
+#echo $processID
+#if [[ "$processID" != "" ]]; then
+# kill -9 $processID
+#fi
+
+if [[ ${environment} == 'pro' ]]; then
+ echo 'run in production environment'
+ cd /home/data/dipperposition
+ if [[ -f /home/linwl/dipperposition/dipperposition.jar ]]; then
+ echo 'mv /home/linwl/dipperposition/dipperposition.jar to destination'
+ mv /home/linwl/dipperposition/dipperposition.jar /home/data/dipperposition/dipperposition.jar
+ fi
+
+ nohup java -Xmx1024M -Xms1024M -Djava.security.egd=file:/dev/./urandom -Dio.netty.leakDetectionLevel=ADVANCED -jar dipperposition.jar --spring.profiles.active=pro &
+
+fi
+if [[ ${environment} == 'test' ]]; then
+ cd /home/data/dipperposition
+ if [[ -f /home/linwl/Work/DipperPosition/dipperposition.jar ]]; then
+ mv /home/linwl/Work/DipperPosition/dipperposition.jar /home/data/dipperposition/dipperposition.jar
+ fi
+ nohup java -Xmx128M -Xms128M -Djava.security.egd=file:/dev/./urandom -Dio.netty.leakDetectionLevel=ADVANCED -jar dipperposition.jar --spring.profiles.active=test &
+fi
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..cabac44
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,159 @@
+
+
+ 4.0.0
+ com.telpo
+ dipperposition
+ 1.0-SNAPSHOT
+ dipperposition
+ 北斗定位服务
+ jar
+
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.2.5.RELEASE
+
+
+
+ UTF-8
+ UTF-8
+ 1.8
+ UTF-8
+ 2.2.0.RELEASE
+ Hoxton.RELEASE
+ true
+
+
+
+
+ org.springframework.boot
+ spring-boot-devtools
+ runtime
+ true
+
+
+
+ org.projectlombok
+ lombok
+ true
+
+
+
+ cn.hutool
+ hutool-core
+ 5.5.2
+
+
+
+ org.springframework.boot
+ spring-boot-starter-webflux
+
+
+
+ org.springframework.boot
+ spring-boot-configuration-processor
+ true
+
+
+
+
+ org.apache.commons
+ commons-lang3
+ 3.10
+
+
+
+
+ org.yaml
+ snakeyaml
+ 1.25
+
+
+
+ com.alibaba
+ fastjson
+ 1.2.28
+
+
+
+ io.netty
+ netty-all
+ 4.1.13.Final
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-data-redis
+
+
+
+
+ org.apache.commons
+ commons-pool2
+
+
+
+
+ com.squareup.okhttp3
+ okhttp
+ 4.8.0
+
+
+
+
+ de.codecentric
+ spring-boot-admin-starter-client
+ 2.2.4
+
+
+
+
+ net.sourceforge.javacsv
+ javacsv
+ 2.0
+
+
+
+ org.springframework.data
+ spring-data-mongodb
+ 2.2.5.RELEASE
+
+
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-dependencies
+ ${spring-cloud.version}
+ pom
+ import
+
+
+
+
+
+
+ ${project.artifactId}
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+ true
+
+
+
+
+ repackage
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/setup_dev.sh b/setup_dev.sh
new file mode 100644
index 0000000..b64f8da
--- /dev/null
+++ b/setup_dev.sh
@@ -0,0 +1,65 @@
+#!/bin/bash
+mvn clean
+mvn package -Dmaven.test.skip=true
+#image_version=$(date +%Y%m%d%H%M)
+image_version=$version
+
+#docker cp docker_jenkins:/var/jenkins_home/workspace/dipperpos_service/target/dipperposition.jar
+# /usr/local/dipperposition/dipperposition.jar
+docker stop dipperposition_service || true
+docker rm dipperposition_service || true
+
+# 删除镜像
+docker rmi -f $(docker images | grep telpo/dipperposition_service | awk '{print $3}')
+
+docker build . -t telpo/dipperposition_service:$image_version
+
+#TODO:推送镜像到私有仓库
+echo '=================开始推送镜像======================='
+docker tag telpo/dipperposition_service:$image_version 139.224.254.18:5000/dipperposition_service:$image_version
+docker push 139.224.254.18:5000/dipperposition_service:$image_version
+echo '=================推送镜像完成======================='
+
+#删除产生的None镜像
+docker rmi -f $(docker images | grep none | awk '{print $3}')
+# 查看镜像列表
+docker images
+# 启动容器
+docker run -v /home/data/dipperposition/log:/var/log/dipperposition -d -e active=dev --network host --restart=always -p 9011:9011 -p 9012:9012 -p 9013:9013 --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$image_version
+
+#echo "scp ${WORKSPACE} files......begin"
+#set passwd "telpo#1234"
+#scp /var/jenkins_home/workspace/dipperpos_service/target/dipperposition.jar root@47.116.142.20:/home/data/dipperposition/dipperposition.jar
+#expect {
+# "密码:"
+# {
+# send "$passwd\n"
+# }
+# "pass"
+# {
+# send "$passwd\n"
+# }
+#
+# "yes/no"
+# {
+# sleep 5
+# send_user "send yes"
+# send "yes\n"
+# }
+# eof
+# {
+# sleep 5
+# send_user "eof\n"
+# }
+#}
+#send "exit\r"
+#expect eof
+#echo "scp ${WORKSPACE} files......end"
+# 查看日志
+#docker logs dipperposition_service
+
+#echo '=================启动NettyAPP======================='
+#ps -ef |grep dipperposition |awk '{print $2}'|xargs kill -9
+#java -jar -Xms256m -Xmx256m -Xss256k -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=512m
+# /usr/local/dipperposition/dipperposition.jar --spring.profiles.active=dev
+#echo '=================完成NettyAPP启动======================='
diff --git a/setup_pro.sh b/setup_pro.sh
new file mode 100644
index 0000000..7de562d
--- /dev/null
+++ b/setup_pro.sh
@@ -0,0 +1,20 @@
+#!/usr/bin/env bash
+mvn clean
+mvn package -Dmaven.test.skip=true
+image_version=$version
+# 删除镜像
+docker rmi -f $(
+ docker images | grep registry.cn-shanghai.aliyuncs.com/telpo_platform/dipperposition_service | awk '{print $3}'
+)
+# 构建telpo/mrp:$image_version镜像
+docker build . -t telpo/dipperposition_service:$image_version
+#TODO:推送镜像到阿里仓库
+echo '=================开始推送镜像======================='
+docker login --username=rzl_wangjx@1111649216405698 --password=telpo.123 registry.cn-shanghai.aliyuncs.com
+docker tag telpo/dipperposition_service:$image_version registry.cn-shanghai.aliyuncs.com/telpo_platform/dipperposition_service:$image_version
+docker push registry.cn-shanghai.aliyuncs.com/telpo_platform/dipperposition_service:$image_version
+echo '=================推送镜像完成======================='
+#删除产生的None镜像
+docker rmi -f $(docker images | grep none | awk '{print $3}')
+# 查看镜像列表
+docker images
diff --git a/setup_test.sh b/setup_test.sh
new file mode 100644
index 0000000..1c0d5f8
--- /dev/null
+++ b/setup_test.sh
@@ -0,0 +1,27 @@
+#!/bin/bash
+mvn clean
+mvn package -Dmaven.test.skip=true
+#image_version=$(date +%Y%m%d%H%M)
+image_version=$version
+docker stop dipperposition_service || true
+docker rm dipperposition_service || true
+
+# 删除镜像
+docker rmi -f $(docker images | grep telpo/dipperposition_service | awk '{print $3}')
+
+docker build . -t telpo/dipperposition_service:$image_version
+
+#TODO:推送镜像到私有仓库
+echo '=================开始推送镜像======================='
+docker tag telpo/dipperposition_service:$image_version 139.224.254.18:5000/dipperposition_service:$image_version
+docker push 139.224.254.18:5000/dipperposition_service:$image_version
+echo '=================推送镜像完成======================='
+
+#删除产生的None镜像
+docker rmi -f $(docker images | grep none | awk '{print $3}')
+# 查看镜像列表
+docker images
+# 启动容器
+docker run -v /home/data/dipperposition/log:/var/log/dipperposition -d -e active=test --network host --restart=always -p 9012:9012 --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$image_version
+# 查看日志
+# docker logs dipperposition_service
diff --git a/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java
new file mode 100644
index 0000000..452e6e9
--- /dev/null
+++ b/src/main/java/com/telpo/dipperposition/DipperPositionApplication.java
@@ -0,0 +1,39 @@
+package com.telpo.dipperposition;
+
+import com.telpo.dipperposition.server.DipperPositionServer;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.core.env.ConfigurableEnvironment;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.annotation.EnableScheduling;
+
+/**
+ * @program: gateway
+ * @description: 网关启动类
+ * @author: linwl
+ * @create: 2020-06-18 16:39
+ */
+@SpringBootApplication
+@ConfigurationPropertiesScan
+@EnableAsync
+@EnableScheduling
+@Slf4j
+public class DipperPositionApplication {
+
+ public static void main(String[] args) {
+ try {
+ log.info("北斗定位服务开始!");
+ ConfigurableApplicationContext applicationContext = SpringApplication.run(DipperPositionApplication.class, args);
+ log.info("北斗定位服务启动!");
+ //启动服务端
+ ConfigurableEnvironment environment = applicationContext.getEnvironment();
+ DipperPositionServer nettyServer = new DipperPositionServer(environment);
+ nettyServer.start();
+ } catch (Exception e) {
+ log.error(e.getMessage());
+ }
+ }
+}
diff --git a/src/main/java/com/telpo/dipperposition/annotation/MongoSwitch.java b/src/main/java/com/telpo/dipperposition/annotation/MongoSwitch.java
new file mode 100644
index 0000000..6153006
--- /dev/null
+++ b/src/main/java/com/telpo/dipperposition/annotation/MongoSwitch.java
@@ -0,0 +1,22 @@
+package com.telpo.dipperposition.annotation;
+
+import java.lang.annotation.*;
+
+/**
+ * @program: DataPushServer
+ * @description: mongo数据源切换注解
+ * @author: linwl
+ * @create: 2020-07-11 15:06
+ */
+@Target({ElementType.METHOD})
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface MongoSwitch {
+
+ /**
+ * mongo数据库名称
+ *
+ * @return
+ */
+ String value() default "";
+}
diff --git a/src/main/java/com/telpo/dipperposition/co/PositionConfigInfo.java b/src/main/java/com/telpo/dipperposition/co/PositionConfigInfo.java
new file mode 100644
index 0000000..47c2d16
--- /dev/null
+++ b/src/main/java/com/telpo/dipperposition/co/PositionConfigInfo.java
@@ -0,0 +1,35 @@
+package com.telpo.dipperposition.co;
+
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+import okhttp3.*;
+import okhttp3.internal.ws.RealWebSocket;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.stereotype.Component;
+
+import javax.net.SocketFactory;
+
+/**
+ * @program: RzlAccount
+ * @description: 融智联账号配置
+ * @author: king
+ * @create: 2021-01-12 14:02
+ **/
+@Getter
+@Setter
+@Component
+@ConfigurationProperties(prefix = "position-server")
+public class PositionConfigInfo {
+
+ private String serverAddr;
+
+ private String timeAsycPort;
+
+ private String posAsycPort;
+
+ private String starsAsycPort;
+
+}
diff --git a/src/main/java/com/telpo/dipperposition/common/CSVUtil.java b/src/main/java/com/telpo/dipperposition/common/CSVUtil.java
new file mode 100644
index 0000000..0d840a2
--- /dev/null
+++ b/src/main/java/com/telpo/dipperposition/common/CSVUtil.java
@@ -0,0 +1,87 @@
+package com.telpo.dipperposition.common;
+
+import com.csvreader.CsvReader;
+import com.csvreader.CsvWriter;
+
+import java.io.FileNotFoundException;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.List;
+/**
+ * @program: dipperposition
+ * @description: CSV文件读取单元
+ * @author: linwl
+ * @create: 2021-01-14 11:19
+ **/
+public class CSVUtil {
+ /**
+ * 读取每行的数据
+ *
+ * @param readPath
+ * @return
+ */
+ public static List readCSV(String readPath) {
+ String filePath = readPath;
+ List listData = new ArrayList<>();
+ try {
+ filePath = readPath;
+ CsvReader csvReader = new CsvReader(filePath,',',Charset.forName("UTF-8"));
+ // 读表头
+ boolean re = csvReader.readHeaders();
+ while (csvReader.readRecord()) {
+ String rawRecord = csvReader.getRawRecord();
+ listData.add(rawRecord);
+ }
+ return listData;
+ } catch (FileNotFoundException e) {
+ throw new RuntimeException("文件未找到");
+ } catch (IOException e) {
+ throw new RuntimeException(e.getMessage());
+ }
+
+ }
+
+ /**
+ * 写入文件头
+ * @param writePath
+ * @param header
+ */
+ public static void writeCSV(String writePath, String[] header) {
+ String filePath = writePath;
+ try {
+ CsvWriter csvWriter = new CsvWriter(writePath, ',', Charset.forName("UTF-8"));
+ //String [] header = {"SkuId","SsuId","图片地址","大小(bit)","高度","宽度"};
+ csvWriter.writeRecord(header);
+ csvWriter.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ /**
+ * 利用输入输出流持续写
+ * @param fileName
+ * @param content
+ */
+ public static void writeContent(String fileName, String content) {
+ FileWriter writer = null;
+ try {
+ // 打开一个写文件器,构造函数中的第二个参数true表示以追加形式写文件
+ writer = new FileWriter(fileName, true);
+ writer.write(content + "\r\n");
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ if (writer != null) {
+ writer.close();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+}
diff --git a/src/main/java/com/telpo/dipperposition/common/HexConvert.java b/src/main/java/com/telpo/dipperposition/common/HexConvert.java
new file mode 100644
index 0000000..20a8708
--- /dev/null
+++ b/src/main/java/com/telpo/dipperposition/common/HexConvert.java
@@ -0,0 +1,174 @@
+package com.telpo.dipperposition.common;
+
+/**
+ * @program: dipperposition
+ * @description: 16进制处理
+ * @author: linwl
+ * @create: 2021-01-14 22:05
+ **/
+public class HexConvert {
+ public static String convertStringToHex(String str){
+
+ char[] chars = str.toCharArray();
+
+ StringBuffer hex = new StringBuffer();
+ for(int i = 0; i < chars.length; i++){
+ hex.append(Integer.toHexString((int)chars[i]));
+ }
+
+ return hex.toString();
+ }
+
+ public static String convertHexToString(String hex){
+
+ StringBuilder sb = new StringBuilder();
+ StringBuilder sb2 = new StringBuilder();
+
+ for( int i=0; i> 4));
+ hex += String.valueOf(hexStr.charAt(b & 0x0F));
+ result += hex + " ";
+ }
+ return result;
+ }
+
+ //將10進制轉換為16進制
+ public static String encodeHEX(long numb){
+
+ String hex= Long.toHexString(numb);
+ return hex;
+
+ }
+
+
+ //將16進制字符串轉換為10進制數字
+ public static long decodeHEX(String hexs){
+ long longValue= Long.parseLong("123ABC", 16);
+ return longValue;
+ }
+
+
+ /**
+ * 生成校验码的int值
+ * */
+ public static String makeChecksum(String data) {
+ if (data == null || data.equals("")) {
+ return "";
+ }
+ int total = 0;
+ int len = data.length();
+ int num = 0;
+ while (num < len) {
+ String s = data.substring(num, num + 2);
+ //System.out.println(s);
+ total += Integer.parseInt(s, 16);
+ num = num + 2;
+ }
+ /**
+ * 用256求余最大是255,即16进制的FF
+ */
+ int mod = total % 256;
+ String hex = Integer.toHexString(mod);
+ len = hex.length();
+ // 如果不够校验位的长度,补0,这里用的是两位校验
+ if (len < 2) {
+ hex = "0" + hex;
+ }
+ return hex;
+ }
+
+
+ /**
+ * 生成校验码的int值
+ * */
+ public static String makeChecksumForBytes(byte[] byteDatas) {
+ if (byteDatas == null || byteDatas.length == 0) {
+ return "";
+ }
+ int total = 0;
+ int len = byteDatas.length;
+
+ final String HEX = "0123456789abcdef";
+ StringBuilder sb = null;
+ for (byte b : byteDatas) {
+ sb = new StringBuilder(2);
+ // 取出这个字节的高4位,然后与0x0f与运算,得到一个0-15之间的数据,通过HEX.charAt(0-15)即为16进制数
+ sb.append(HEX.charAt((b >> 4) & 0x0f));
+ // 取出这个字节的低位,与0x0f与运算,得到一个0-15之间的数据,通过HEX.charAt(0-15)即为16进制数
+ sb.append(HEX.charAt(b & 0x0f));
+ total += Integer.parseInt(sb.toString(), 16);
+ }
+ /**
+ * 用256求余最大是255,即16进制的FF
+ */
+ int mod = total % 256;
+ String hex = Integer.toHexString(mod);
+ len = hex.length();
+ // 如果不够校验位的长度,补0,这里用的是两位校验
+ if (len < 2) {
+ hex = "0" + hex;
+ }
+ return hex;
+ }
+//
+// public static void main(String[] args) {
+//
+//
+// System.out.println("======ASCII码转换为16进制======");
+// String str = "*00007VERSION\\n1$";
+// System.out.println("字符串: " + str);
+// String hex = HexConvert.convertStringToHex(str);
+// System.out.println("====转换为16进制=====" + hex);
+//
+// System.out.println("======16进制转换为ASCII======");
+// System.out.println("Hex : " + hex);
+// System.out.println("ASCII : " + HexConvert.convertHexToString(hex));
+//
+// byte[] bytes = HexConvert.hexStringToBytes( hex );
+//
+// System.out.println(HexConvert.BinaryToHexString( bytes ));
+// }
+
+}
diff --git a/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java b/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java
new file mode 100644
index 0000000..5e4dd18
--- /dev/null
+++ b/src/main/java/com/telpo/dipperposition/common/OkHttpUtil.java
@@ -0,0 +1,172 @@
+package com.telpo.dipperposition.common;
+
+import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+import okhttp3.*;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.exception.ExceptionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+import java.text.MessageFormat;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * @program: DataPushServer
+ * @description: okhttp工具类
+ * @author: linwl
+ * @create: 2020-07-17 15:43
+ */
+@Slf4j
+@Component
+public class OkHttpUtil {
+
+ @Autowired private OkHttpClient okHttpClient;
+
+ public static OkHttpUtil okHttpUtil;
+
+ @PostConstruct
+ public void init() {
+ okHttpUtil = this;
+ }
+ /**
+ * 根据map获取get请求参数
+ *
+ * @param queries
+ * @return
+ */
+ public StringBuffer getQueryString(String url, Map queries) {
+ StringBuffer sb = new StringBuffer(url);
+ if (queries != null && queries.keySet().size() > 0) {
+ boolean firstFlag = true;
+ Iterator iterator = queries.entrySet().iterator();
+ while (iterator.hasNext()) {
+ Map.Entry entry = (Map.Entry) iterator.next();
+ if (firstFlag) {
+ sb.append("?" + entry.getKey() + "=" + entry.getValue());
+ firstFlag = false;
+ } else {
+ sb.append("&" + entry.getKey() + "=" + entry.getValue());
+ }
+ }
+ }
+ return sb;
+ }
+
+ /**
+ * get
+ *
+ * @param url 请求的url
+ * @param queries 请求的参数,在浏览器?后面的数据,没有可以传null
+ * @return
+ */
+ public String get(String url, Map queries) {
+ StringBuffer sb = getQueryString(url, queries);
+ Request request = new Request.Builder().url(sb.toString()).build();
+ log.debug(MessageFormat.format("发送Get to url<{0}>,参数为:{1}", url, queries));
+ return execNewCall(request);
+ }
+
+ /**
+ * post
+ *
+ * @param url 请求的url
+ * @param params post form 提交的参数
+ * @return
+ */
+ public String postFormParams(String url, Map params) {
+ FormBody.Builder builder = new FormBody.Builder();
+ // 添加参数
+ if (params != null && params.keySet().size() > 0) {
+ for (String key : params.keySet()) {
+ builder.add(key, params.get(key));
+ }
+ }
+ log.debug(MessageFormat.format("发送post from to url<{0}>,参数为:{1}", url, params));
+ Request request = new Request.Builder().url(url).post(builder.build()).build();
+ return execNewCall(request);
+ }
+
+ /** Post请求发送JSON数据....{"name":"zhangsan","pwd":"123456"} 参数一:请求Url 参数二:请求的JSON 参数三:请求回调 */
+ public String postJsonParams(String url, String jsonParams) {
+ RequestBody requestBody = RequestBody.create(jsonParams, MediaType.parse("application/json; charset=utf-8"));
+ Request request = new Request.Builder().url(url).post(requestBody).build();
+ log.debug(MessageFormat.format("发送post json to url<{0}>,参数为:{1}", url, jsonParams));
+ return execNewCall(request);
+ }
+
+
+ /** Post请求发送JSON数据....{"name":"zhangsan","pwd":"123456"} 参数一:请求Url 参数二:请求的JSON 参数三:请求回调 */
+ public String getJsonParams(String url, String jsonParams) {
+ Request request = new Request.Builder().url(url).addHeader("application/json","charset=utf-8").build();
+ log.debug(MessageFormat.format("get json to url<{0}>", url));
+
+ return execNewCall(request);
+ }
+
+
+
+ /** Post请求发送xml数据.... 参数一:请求Url 参数二:请求的xmlString 参数三:请求回调 */
+ public String postXmlParams(String url, String xml) {
+ RequestBody requestBody =
+ RequestBody.create(xml, MediaType.parse("application/xml; charset=utf-8"));
+ Request request = new Request.Builder().url(url).post(requestBody).build();
+ log.debug(MessageFormat.format("发送post xml to url<{0}>,参数为:{1}", url, xml));
+ return execNewCall(request);
+ }
+
+ /**
+ * 调用okhttp的newCall方法
+ *
+ * @param request
+ * @return
+ */
+ private String execNewCall(Request request) {
+ try (Response response = okHttpClient.newCall(request).execute()) {
+ if (response.isSuccessful()) {
+ return Objects.requireNonNull(response.body()).string();
+ }
+ } catch (Exception e) {
+ log.error("okhttp3 put error >> ex = {}", ExceptionUtils.getStackTrace(e));
+ }
+ return "FAIL";
+ }
+
+ /**
+ * Post请求发送JSON数据....{"name":"zhangsan","pwd":"123456"} 参数一:请求Url 参数二:请求的JSON 参数三:请求回调
+ */
+ public String postJsonParamsWithToken(String url, String token, String jsonParams) {
+ RequestBody requestBody =
+ RequestBody.create(jsonParams, MediaType.parse("application/json; charset=utf-8"));
+ Request request = new Request.Builder().url(url).
+ addHeader("Authorization", token).post(requestBody).build();
+ log.debug(MessageFormat.format("发送post json to url<{0}>,参数为:{1}", url, jsonParams));
+ return execNewCall(request);
+ }
+
+ public JSONObject postRequestWithJson(String url, String accessToken, JSONObject postData) {
+ String postResult;
+ if (ObjectUtils.isNotEmpty(accessToken)) {
+ postResult = postJsonParamsWithToken(url, accessToken, JSONObject.toJSONString(postData));
+ } else {
+ postResult = postJsonParams(url, JSONObject.toJSONString(postData));
+ }
+
+ if (postResult == null) {
+ log.error("访问错误");
+ return null;
+ } else {
+ log.debug(postResult);
+ if(("FAIL").equals(postResult.toString())) {
+ JSONObject object = new JSONObject();
+ object.put("result", "FAIL");
+ return object;
+ } else {
+ return JSONObject.parseObject(postResult);
+ }
+ }
+ }
+}
diff --git a/src/main/java/com/telpo/dipperposition/common/RedisUtil.java b/src/main/java/com/telpo/dipperposition/common/RedisUtil.java
new file mode 100644
index 0000000..f1e85eb
--- /dev/null
+++ b/src/main/java/com/telpo/dipperposition/common/RedisUtil.java
@@ -0,0 +1,672 @@
+package com.telpo.dipperposition.common;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @program: DataPushServer
+ * @description: redis工具类
+ * @author: linwl
+ * @create: 2020-07-11 10:26
+ */
+@Component
+@Slf4j
+public class RedisUtil {
+
+ @Resource private RedisTemplate redisTemplate;
+
+// public static RedisUtil redisUtil;
+// @PostConstruct
+// public void init() {
+// redisUtil = this;
+// }
+ // =============================common============================
+ /**
+ * 指定缓存失效时间
+ *
+ * @param key 键
+ * @param time 时间(秒)
+ * @return
+ */
+ public boolean expire(String key, long time) {
+ try {
+ if (time > 0) {
+ redisTemplate.expire(key, time, TimeUnit.SECONDS);
+ }
+ return true;
+ } catch (Exception e) {
+ log.error(key, e);
+ return false;
+ }
+ }
+
+ /**
+ * 根据key 获取过期时间
+ *
+ * @param key 键 不能为null
+ * @return 时间(秒) 返回0代表为永久有效
+ */
+ public long getExpire(String key) {
+ return redisTemplate.getExpire(key, TimeUnit.SECONDS);
+ }
+
+ /**
+ * 判断key是否存在
+ *
+ * @param key 键
+ * @return true 存在 false不存在
+ */
+ public boolean hasKey(String key) {
+ try {
+ return redisTemplate.hasKey(key);
+ } catch (Exception e) {
+ log.error(key, e);
+ return false;
+ }
+ }
+
+ /**
+ * 删除缓存
+ *
+ * @param key 可以传一个值 或多个
+ */
+ @SuppressWarnings("unchecked")
+ public void del(String... key) {
+ if (key != null && key.length > 0) {
+ if (key.length == 1) {
+ redisTemplate.delete(key[0]);
+ } else {
+ redisTemplate.delete(CollectionUtils.arrayToList(key));
+ }
+ }
+ }
+
+ // ============================String=============================
+ /**
+ * 普通缓存获取
+ *
+ * @param key 键
+ * @return 值
+ */
+ public Object get(String key) {
+ return key == null ? null : redisTemplate.opsForValue().get(key);
+ }
+
+ /**
+ * 普通缓存放入
+ *
+ * @param key 键
+ * @param value 值
+ * @return true成功 false失败
+ */
+ public boolean set(String key, Object value) {
+ try {
+ redisTemplate.opsForValue().set(key, value);
+ return true;
+ } catch (Exception e) {
+ log.error(key, e);
+ return false;
+ }
+ }
+
+ /**
+ * 普通缓存放入并设置时间
+ *
+ * @param key 键
+ * @param value 值
+ * @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期
+ * @return true成功 false 失败
+ */
+ public boolean set(String key, Object value, long time) {
+ try {
+ if (time > 0) {
+ redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
+ } else {
+ set(key, value);
+ }
+ return true;
+ } catch (Exception e) {
+ log.error(key, e);
+ return false;
+ }
+ }
+
+ /**
+ * 递增 适用场景: https://blog.csdn.net/y_y_y_k_k_k_k/article/details/79218254 高并发生成订单号,秒杀类的业务逻辑等。。
+ *
+ * @param key 键
+ * @param delta 要增加几(大于0)
+ * @return
+ */
+ public long incr(String key, long delta) {
+ if (delta < 0) {
+ throw new RuntimeException("递增因子必须大于0");
+ }
+ return redisTemplate.opsForValue().increment(key, delta);
+ }
+
+ /**
+ * 递减
+ *
+ * @param key 键
+ * @param delta 要减少几(小于0)
+ * @return
+ */
+ public long decr(String key, long delta) {
+ if (delta < 0) {
+ throw new RuntimeException("递减因子必须大于0");
+ }
+ return redisTemplate.opsForValue().increment(key, -delta);
+ }
+
+ // ================================Map=================================
+ /**
+ * HashGet
+ *
+ * @param key 键 不能为null
+ * @param item 项 不能为null
+ * @return 值
+ */
+ public Object hget(String key, String item) {
+ return redisTemplate.opsForHash().get(key, item);
+ }
+
+ /**
+ * 获取hashKey对应的所有键值
+ *
+ * @param key 键
+ * @return 对应的多个键值
+ */
+ public Map