Jelajahi Sumber

init from phab

xielq 4 tahun lalu
induk
melakukan
531d8885b2
29 mengubah file dengan 2360 tambahan dan 0 penghapusan
  1. 0 0
      README.md
  2. 92 0
      pom.xml
  3. 122 0
      usoft-base-dependencies/pom.xml
  4. 39 0
      usoft-bizcode-utils/pom.xml
  5. 76 0
      usoft-bizcode-utils/src/main/java/com/usoft/bizcode/utils/BizCodeUtil.java
  6. 67 0
      usoft-bizcode-utils/src/main/java/com/usoft/bizcode/utils/DecimalConverter.java
  7. 17 0
      usoft-bizcode-utils/src/test/java/com/usoft/bizcode/utils/BizCodeUtilTest.java
  8. 19 0
      usoft-bizcode-utils/src/test/java/com/usoft/bizcode/utils/DecimalConverterTest.java
  9. 29 0
      usoft-exception-utils/pom.xml
  10. 75 0
      usoft-exception-utils/src/main/java/com/usoft/exception/utils/BaseRuntimeException.java
  11. 82 0
      usoft-grpc-dependencies/pom.xml
  12. 50 0
      usoft-mq-utils/pom.xml
  13. 295 0
      usoft-mq-utils/src/main/java/com/usoft/mq/utils/BaseRabbitReceiveService.java
  14. 152 0
      usoft-mq-utils/src/main/java/com/usoft/mq/utils/MessageInfo.java
  15. 96 0
      usoft-mq-utils/src/main/java/com/usoft/mq/utils/RabbitSendService.java
  16. 34 0
      usoft-mybatis-utils/pom.xml
  17. 145 0
      usoft-mybatis-utils/src/main/java/com/usoft/mybatis/utils/MybatisCommentGenerator.java
  18. 115 0
      usoft-mybatis-utils/src/main/java/com/usoft/mybatis/utils/plugin/SelectByCodePlugin.java
  19. 58 0
      usoft-mybatis-utils/src/main/java/com/usoft/mybatis/utils/plugin/TableBaseColumnListPlugin.java
  20. 46 0
      usoft-protobuf-utils/pom.xml
  21. 117 0
      usoft-protobuf-utils/src/main/java/com/usoft/protobuf/utils/ProtoBufUtil.java
  22. 43 0
      usoft-rest-dependencies/pom.xml
  23. 54 0
      usoft-security-utils/pom.xml
  24. 50 0
      usoft-security-utils/src/main/java/com/usoft/security/utils/HmacUtil.java
  25. 208 0
      usoft-security-utils/src/main/java/com/usoft/security/utils/OpenApiSignUtil.java
  26. 58 0
      usoft-sso-utils/pom.xml
  27. 54 0
      usoft-sso-utils/src/main/java/com/usoft/sso/utils/BaseSsoController.java
  28. 75 0
      usoft-sso-utils/src/main/java/com/usoft/sso/utils/SsoProperties.java
  29. 92 0
      usoft-sso-utils/src/main/java/com/usoft/sso/utils/UserLoginState.java

+ 0 - 0
README.md


+ 92 - 0
pom.xml

@@ -0,0 +1,92 @@
+<?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">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>com.usoft.framework</groupId>
+    <artifactId>usoft-framework-parent</artifactId>
+    <packaging>pom</packaging>
+    <version>1.0-SNAPSHOT</version>
+    <description>usoft底层框架</description>
+    <modules>
+        <module>usoft-grpc-dependencies</module>
+        <module>usoft-base-dependencies</module>
+        <module>usoft-mybatis-utils</module>
+        <module>usoft-exception-utils</module>
+        <module>usoft-rest-dependencies</module>
+        <module>usoft-protobuf-utils</module>
+        <module>usoft-sso-utils</module>
+        <module>usoft-security-utils</module>
+        <module>usoft-bizcode-utils</module>
+        <module>usoft-mq-utils</module>
+    </modules>
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+        <maven.compiler.source>1.8</maven.compiler.source>
+        <maven.compiler.target>1.8</maven.compiler.target>
+    </properties>
+
+    <distributionManagement>
+        <!-- 发布release仓库 -->
+        <repository>
+            <id>platform-release</id>
+            <name>platform-release</name>
+            <url>http://113.105.74.141:8081/artifactory/libs-release-local</url>
+        </repository>
+        <!-- 发布快照版本 -->
+        <snapshotRepository>
+            <id>platform-snapshots</id>
+            <name>platform-snapshots</name>
+            <url>http://113.105.74.141:8081/artifactory/libs-snapshot-local</url>
+        </snapshotRepository>
+    </distributionManagement>
+
+    <profiles>
+        <profile>
+            <!-- 开发环境 -->
+            <id>dev</id>
+            <activation>
+                <activeByDefault>true</activeByDefault>
+            </activation>
+            <properties>
+                <profile>dev</profile>
+            </properties>
+        </profile>
+        <profile>
+            <!-- 测试环境 -->
+            <id>test</id>
+            <properties>
+                <profile>test</profile>
+            </properties>
+        </profile>
+        <profile>
+            <!-- 生产环境 -->
+            <id>prod</id>
+            <properties>
+                <profile>prod</profile>
+            </properties>
+        </profile>
+    </profiles>
+    
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-source-plugin</artifactId>
+                <version>3.0.1</version>
+                <executions>
+                    <execution>
+                        <id>attach-sources</id>
+                        <phase>verify</phase>
+                        <goals>
+                            <goal>jar-no-fork</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+</project>

+ 122 - 0
usoft-base-dependencies/pom.xml

@@ -0,0 +1,122 @@
+<?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>usoft-framework-parent</artifactId>
+        <groupId>com.usoft.framework</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>usoft-base-dependencies</artifactId>
+    <version>${profile}-1.0-SNAPSHOT</version>
+    <packaging>pom</packaging>
+
+    <properties>
+        <slf4j-api.version>1.7.25</slf4j-api.version>
+        <logback-classic.version>1.2.3</logback-classic.version>
+        <junit-jupiter-api.version>5.2.0</junit-jupiter-api.version>
+        <commons-lang3.version>3.7</commons-lang3.version>
+        <commons-collections4.version>4.2</commons-collections4.version>
+        <spring-boot-starter.version>1.5.11.RELEASE</spring-boot-starter.version>
+        <spring-boot-starter-test.version>1.5.11.RELEASE</spring-boot-starter-test.version>
+        <spring-boot-starter-data-redis.version>2.0.3.RELEASE</spring-boot-starter-data-redis.version>
+        <fastjson.version>1.2.47</fastjson.version>
+        <usoft-exception-utils.version>${profile}-1.0-SNAPSHOT</usoft-exception-utils.version>
+        <usoft-protobuf-utils.version>${profile}-1.0-SNAPSHOT</usoft-protobuf-utils.version>
+        <usoft-bizcode-utils.version>${profile}-1.0-SNAPSHOT</usoft-bizcode-utils.version>
+        <grpc-all.version>1.11.0</grpc-all.version>
+        <guava.version>20.0</guava.version>
+        <httpclient.version>4.5.6</httpclient.version>
+    </properties>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.slf4j</groupId>
+                <artifactId>slf4j-api</artifactId>
+                <version>${slf4j-api.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>ch.qos.logback</groupId>
+                <artifactId>logback-classic</artifactId>
+                <version>${logback-classic.version}</version>
+            </dependency>
+
+            <dependency>
+                <groupId>org.junit.jupiter</groupId>
+                <artifactId>junit-jupiter-api</artifactId>
+                <version>${junit-jupiter-api.version}</version>
+                <scope>test</scope>
+            </dependency>
+
+            <dependency>
+                <groupId>org.apache.commons</groupId>
+                <artifactId>commons-lang3</artifactId>
+                <version>${commons-lang3.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.commons</groupId>
+                <artifactId>commons-collections4</artifactId>
+                <version>${commons-collections4.version}</version>
+            </dependency>
+
+            <dependency>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-starter</artifactId>
+                <version>${spring-boot-starter.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-starter-test</artifactId>
+                <version>${spring-boot-starter-test.version}</version>
+                <scope>test</scope>
+            </dependency>
+            <dependency>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-starter-data-redis</artifactId>
+                <version>${spring-boot-starter-data-redis.version}</version>
+            </dependency>
+
+            <dependency>
+                <groupId>com.alibaba</groupId>
+                <artifactId>fastjson</artifactId>
+                <version>${fastjson.version}</version>
+            </dependency>
+
+            <dependency>
+                <groupId>com.usoft.framework</groupId>
+                <artifactId>usoft-exception-utils</artifactId>
+                <version>${usoft-exception-utils.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>com.usoft.framework</groupId>
+                <artifactId>usoft-protobuf-utils</artifactId>
+                <version>${usoft-protobuf-utils.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>com.usoft.framework</groupId>
+                <artifactId>usoft-bizcode-utils</artifactId>
+                <version>${usoft-bizcode-utils.version}</version>
+            </dependency>
+
+            <dependency>
+                <groupId>io.grpc</groupId>
+                <artifactId>grpc-all</artifactId>
+                <version>${grpc-all.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>com.google.guava</groupId>
+                <artifactId>guava</artifactId>
+                <version>${guava.version}</version>
+            </dependency>
+
+            <dependency>
+                <groupId>org.apache.httpcomponents</groupId>
+                <artifactId>httpclient</artifactId>
+                <version>${httpclient.version}</version>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+</project>

+ 39 - 0
usoft-bizcode-utils/pom.xml

@@ -0,0 +1,39 @@
+<?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>usoft-framework-parent</artifactId>
+        <groupId>com.usoft.framework</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>usoft-bizcode-utils</artifactId>
+    <version>${profile}-1.0-SNAPSHOT</version>
+    <packaging>jar</packaging>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>com.usoft.framework</groupId>
+                <artifactId>usoft-base-dependencies</artifactId>
+                <version>dev-1.0-SNAPSHOT</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-api</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+        </dependency>
+    </dependencies>
+</project>

+ 76 - 0
usoft-bizcode-utils/src/main/java/com/usoft/bizcode/utils/BizCodeUtil.java

@@ -0,0 +1,76 @@
+package com.usoft.bizcode.utils;
+
+import org.apache.commons.lang3.StringUtils;
+
+/**
+ * 业务号 工具类
+ *
+ * @author: wangcanyi
+ * @date: 2018-08-23 16:51
+ **/
+public class BizCodeUtil {
+	private static final int BIZ_CODE_MAX_LENGTH = 10;
+	private static final int PREFIX_LENGTH = 2;
+	private static final int SE_MAX = 9;
+	private static final int SE_LENGTH = 1;
+	private static int se = 0;
+
+	/**
+	 * 创建业务号  最长10位
+	 *
+	 * @param prefix 前缀 - 自定义 - 长度:2位
+	 * @return
+	 */
+	public static String genBizCode(String prefix) {
+		if (StringUtils.isBlank(prefix)) {
+			throw new IllegalArgumentException("prefix不能为空");
+		}
+		if (prefix.length() != PREFIX_LENGTH) {
+			throw new IllegalArgumentException("prefix长度必须为2位");
+		}
+		synchronized (BizCodeUtil.class) {
+			String nextCode;
+			if (se > SE_MAX) {
+				se = 0;
+			}
+			//当前精确到0.1毫秒
+			String decimalCode = "" + System.currentTimeMillis() + createSerial("" + se, SE_LENGTH);
+			//10进制转62进制
+			nextCode = DecimalConverter.fromDecimal(decimalCode, 62);
+			se++;
+			if (nextCode.length() > BIZ_CODE_MAX_LENGTH) {
+				throw new RuntimeException("生成业务号长度错误[" + nextCode + "]");
+			}
+			return prefix + nextCode;
+		}
+	}
+
+
+	/**
+	 * 生成固定长度的序列号,不足位数在前补0
+	 *
+	 * @param src
+	 * @param len
+	 * @return
+	 */
+	private static String createSerial(String src, int len) {
+		String dest = "";
+		if (src.length() >= len) {
+			dest = src.substring(0, len);
+		} else {
+			dest = createSameChar("0", len - src.length()) + src;
+		}
+		return dest;
+	}
+
+	/**
+	 * 返回相同字符的串
+	 */
+	private static String createSameChar(String src, int len) {
+		StringBuffer sb = new StringBuffer();
+		for (int i = 0; i < len; i++) {
+			sb.append(src);
+		}
+		return sb.toString();
+	}
+}

+ 67 - 0
usoft-bizcode-utils/src/main/java/com/usoft/bizcode/utils/DecimalConverter.java

@@ -0,0 +1,67 @@
+package com.usoft.bizcode.utils;
+
+import java.math.BigInteger;
+
+/**
+ * 十进制(Decimal)转换为 2-62进制
+ *
+ * @author: wangcanyi
+ * @date: 2018-08-23 10:32
+ */
+public class DecimalConverter {
+
+	private static final String[] NUM_TABLE = {"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"};
+	private static final int MAX_RADIX = 62;
+	private static final int MIN_RADIX = 2;
+
+	/**
+	 * 十进制(Decimal)转换为 2-62进制
+	 *
+	 * @param decimalText 10进制数
+	 * @param radix       几进制
+	 * @return
+	 */
+	public static String fromDecimal(String decimalText, int radix) {
+		if (decimalText == null || decimalText.trim().length() < 1) {
+			return decimalText;
+		}
+		BigInteger radixInteger = new BigInteger(Integer.toString(radix));
+		BigInteger decimalInteger = new BigInteger(decimalText);
+		return fromDecimal(decimalInteger, radixInteger);
+	}
+
+	/**
+	 * 十进制(Decimal)转换为 2-62进制
+	 *
+	 * @param decimalValue 10进制数
+	 * @param radixInteger 几进制
+	 * @return
+	 */
+	public static String fromDecimal(BigInteger decimalValue,
+	                                 BigInteger radixInteger) {
+
+		if (radixInteger.intValue() < MIN_RADIX
+				|| radixInteger.intValue() > MAX_RADIX) {
+			throw new IllegalArgumentException("只能转换为2-62进制");
+		}
+
+		if (decimalValue.compareTo(BigInteger.ZERO) < 0) {
+			return "-" + fromDecimal(decimalValue.negate(), radixInteger);
+		}
+
+		if (decimalValue.compareTo(radixInteger) < 0) {
+			return NUM_TABLE[decimalValue.intValue()];
+		} else {
+			BigInteger[] result = decimalValue.divideAndRemainder(radixInteger);
+			// 整除的余数
+			BigInteger suffix = result[1];
+			String prefix = fromDecimal(result[0], radixInteger);
+			return prefix + NUM_TABLE[suffix.intValue()];
+		}
+	}
+}

+ 17 - 0
usoft-bizcode-utils/src/test/java/com/usoft/bizcode/utils/BizCodeUtilTest.java

@@ -0,0 +1,17 @@
+package com.usoft.bizcode.utils;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * @author: wangcanyi
+ * @date: 2018-08-23 17:18
+ **/
+public class BizCodeUtilTest {
+	@Test
+	public void genBizCode(){
+		System.out.println(System.currentTimeMillis() + ":" + BizCodeUtil.genBizCode("11"));
+		for(int i = 10; i < 100;i++){
+			System.out.println(System.currentTimeMillis() + ":" + BizCodeUtil.genBizCode("" + i ));
+		}
+	}
+}

+ 19 - 0
usoft-bizcode-utils/src/test/java/com/usoft/bizcode/utils/DecimalConverterTest.java

@@ -0,0 +1,19 @@
+package com.usoft.bizcode.utils;
+
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+
+/**
+ * @author: wangcanyi
+ * @date: 2018-08-23 15:03
+ **/
+public class DecimalConverterTest {
+	@Test
+	public void fromDecimal() throws IOException {
+		long l = System.currentTimeMillis();
+		System.out.println(l);
+		System.out.println(DecimalConverter.fromDecimal("" + l + "9", 62));
+	}
+
+}

+ 29 - 0
usoft-exception-utils/pom.xml

@@ -0,0 +1,29 @@
+<?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>usoft-framework-parent</artifactId>
+        <groupId>com.usoft.framework</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>usoft-exception-utils</artifactId>
+    <version>${profile}-1.0-SNAPSHOT</version>
+    <packaging>jar</packaging>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>com.usoft.framework</groupId>
+                <artifactId>usoft-base-dependencies</artifactId>
+                <version>dev-1.0-SNAPSHOT</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+
+</project>

+ 75 - 0
usoft-exception-utils/src/main/java/com/usoft/exception/utils/BaseRuntimeException.java

@@ -0,0 +1,75 @@
+package com.usoft.exception.utils;
+
+/**
+ * Base公用异常
+ *
+ * @author: wangcanyi
+ * @date: 2018-07-31 17:57
+ */
+public abstract class BaseRuntimeException extends RuntimeException {
+	/**
+	 * 默认异常号 100
+	 */
+	public static final int ERROR_CODE_100 = 100;
+	/**
+	 * 服务器异常,请重试
+	 */
+	public static final String ERROR_CODE_100_MSG = "服务器异常,请重试";
+
+
+	private int errorCode;
+	private String errorMessage;
+
+	/**
+	 * Base公用异常
+	 *
+	 * @param errorMessage 错误信息
+	 */
+	public BaseRuntimeException(String errorMessage) {
+		this(ERROR_CODE_100, errorMessage);
+	}
+
+	/**
+	 * Base公用异常
+	 *
+	 * @param errorCode    错误号
+	 * @param errorMessage 错误信息
+	 */
+	public BaseRuntimeException(int errorCode, String errorMessage) {
+		super(errorMessage);
+		this.errorCode = errorCode;
+		this.errorMessage = errorMessage;
+	}
+
+	/**
+	 * 错误号
+	 *
+	 * @return
+	 */
+	public int getErrorCode() {
+		return errorCode;
+	}
+
+	/**
+	 * @param errorCode 错误号
+	 */
+	public void setErrorCode(int errorCode) {
+		this.errorCode = errorCode;
+	}
+
+	/**
+	 * 错误信息
+	 *
+	 * @return
+	 */
+	public String getErrorMessage() {
+		return errorMessage;
+	}
+
+	/**
+	 * @param errorMessage 错误信息
+	 */
+	public void setErrorMessage(String errorMessage) {
+		this.errorMessage = errorMessage;
+	}
+}

+ 82 - 0
usoft-grpc-dependencies/pom.xml

@@ -0,0 +1,82 @@
+<?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>usoft-framework-parent</artifactId>
+        <groupId>com.usoft.framework</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>usoft-grpc-dependencies</artifactId>
+    <version>${profile}-1.0-SNAPSHOT</version>
+    <packaging>pom</packaging>
+
+    <properties>
+        <usoft-base-dependencies.version>${profile}-1.0-SNAPSHOT</usoft-base-dependencies.version>
+        <grpc-spring-boot-starter.version>2.3.2</grpc-spring-boot-starter.version>
+        <netty-all.version>4.1.22.Final</netty-all.version>
+        <usoft-mq-utils.version>${profile}-1.0-SNAPSHOT</usoft-mq-utils.version>
+        <spring-boot-starter-amqp.version>1.5.11.RELEASE</spring-boot-starter-amqp.version>
+        <mybatis-spring-boot-starter.version>1.3.2</mybatis-spring-boot-starter.version>
+        <usoft-mybatis-utils.version>${profile}-1.0-SNAPSHOT</usoft-mybatis-utils.version>
+        <mybatis-generator-core.version>1.3.7</mybatis-generator-core.version>
+        <mysql-connector-java.version>6.0.6</mysql-connector-java.version>
+    </properties>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>com.usoft.framework</groupId>
+                <artifactId>usoft-base-dependencies</artifactId>
+                <version>${usoft-base-dependencies.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+            <dependency>
+                <groupId>org.lognet</groupId>
+                <artifactId>grpc-spring-boot-starter</artifactId>
+                <version>${grpc-spring-boot-starter.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>io.netty</groupId>
+                <artifactId>netty-all</artifactId>
+                <version>${netty-all.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>com.usoft.framework</groupId>
+                <artifactId>usoft-mq-utils</artifactId>
+                <version>${usoft-mq-utils.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-starter-amqp</artifactId>
+                <version>${spring-boot-starter-amqp.version}</version>
+            </dependency>
+
+            <!--############mybatis###########################################-->
+            <dependency>
+                <groupId>org.mybatis.spring.boot</groupId>
+                <artifactId>mybatis-spring-boot-starter</artifactId>
+                <version>${mybatis-spring-boot-starter.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>com.usoft.framework</groupId>
+                <artifactId>usoft-mybatis-utils</artifactId>
+                <version>${usoft-mybatis-utils.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.mybatis.generator</groupId>
+                <artifactId>mybatis-generator-core</artifactId>
+                <version>${mybatis-generator-core.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>mysql</groupId>
+                <artifactId>mysql-connector-java</artifactId>
+                <version>${mysql-connector-java.version}</version>
+            </dependency>
+            <!--############mybatis########################################-->
+        </dependencies>
+    </dependencyManagement>
+</project>

+ 50 - 0
usoft-mq-utils/pom.xml

@@ -0,0 +1,50 @@
+<?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>usoft-framework-parent</artifactId>
+        <groupId>com.usoft.framework</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>usoft-mq-utils</artifactId>
+    <version>${profile}-1.0-SNAPSHOT</version>
+    <packaging>jar</packaging>
+
+    <properties></properties>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>com.usoft.framework</groupId>
+                <artifactId>usoft-grpc-dependencies</artifactId>
+                <version>dev-1.0-SNAPSHOT</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-amqp</artifactId>
+        </dependency>
+
+    </dependencies>
+</project>

+ 295 - 0
usoft-mq-utils/src/main/java/com/usoft/mq/utils/BaseRabbitReceiveService.java

@@ -0,0 +1,295 @@
+package com.usoft.mq.utils;
+
+import com.alibaba.fastjson.JSON;
+import com.rabbitmq.client.AMQP;
+import com.rabbitmq.client.Channel;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.amqp.core.AcknowledgeMode;
+import org.springframework.amqp.core.Message;
+import org.springframework.amqp.rabbit.annotation.RabbitHandler;
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
+import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
+import org.springframework.amqp.rabbit.connection.ConnectionFactory;
+import org.springframework.amqp.rabbit.core.ChannelAwareMessageListener;
+import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
+import org.springframework.amqp.support.AmqpHeaders;
+import org.springframework.context.annotation.Bean;
+import org.springframework.core.annotation.AnnotationConfigurationException;
+import org.springframework.messaging.handler.annotation.Headers;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * RabbitMq 消息接收处理基类
+ *
+ * @author: wangcanyi
+ * @date: 2018-08-30 17:41
+ **/
+public abstract class BaseRabbitReceiveService implements ChannelAwareMessageListener {
+	private static final Logger LOGGER = LoggerFactory.getLogger(BaseRabbitReceiveService.class);
+	private static final String DELAY_QUEUE_NAME_SUFFIX = "_delay";
+	/**
+	 * 是否动态创建消息监听
+	 */
+	protected boolean isDynamicCreate = false;
+	/**
+	 * IP地址
+	 */
+	protected String host;
+	/**
+	 * 端口
+	 */
+	protected int port;
+	/**
+	 * Virtual Host
+	 */
+	protected String virtualHost;
+	/**
+	 * 用户名
+	 */
+	protected String username;
+	/**
+	 * 密码
+	 */
+	protected String password;
+	/**
+	 * 队列名
+	 */
+	protected String queueName;
+	/**
+	 * 延时时间,单位:毫秒
+	 */
+	protected String delayTime = "60000";
+	/**
+	 * 心跳时间,单位秒
+	 */
+	protected int requestedHeartBeat = 30;
+	/**
+	 * 延时队列名
+	 */
+	private String delayQueueName;
+
+	/**
+	 * 初始化连接工厂
+	 *
+	 * @return
+	 */
+	private ConnectionFactory initConnectionFactory() {
+		if (StringUtils.isBlank(host)) {
+			throw new IllegalArgumentException("host为空");
+		}
+		if (port <= 0) {
+			throw new IllegalArgumentException("port小于等于0");
+		}
+		if (StringUtils.isBlank(virtualHost)) {
+			throw new IllegalArgumentException("virtualHost为空");
+		}
+		if (StringUtils.isBlank(username)) {
+			throw new IllegalArgumentException("username为空");
+		}
+		if (StringUtils.isBlank(password)) {
+			throw new IllegalArgumentException("password为空");
+		}
+		CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
+		connectionFactory.setHost(host);
+		connectionFactory.setPort(port);
+		connectionFactory.setVirtualHost(virtualHost);
+		connectionFactory.setUsername(username);
+		connectionFactory.setPassword(password);
+		connectionFactory.setRequestedHeartBeat(requestedHeartBeat);
+		return connectionFactory;
+	}
+
+	/**
+	 * 动态创建消息监听
+	 *
+	 * @return
+	 */
+	@Bean
+	protected SimpleMessageListenerContainer simpleMessageListenerContainer() {
+		if (!isDynamicCreate) {
+			return null;
+		}
+		if (this.getClass().isAnnotationPresent(RabbitListener.class)) {
+			throw new AnnotationConfigurationException("动态创建时,不能配置@RabbitListener注解");
+		}
+		if (StringUtils.isBlank(queueName)) {
+			throw new IllegalArgumentException("queueName为空");
+		}
+		ConnectionFactory connectionFactory = initConnectionFactory();
+		SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory);
+		container.setQueueNames(queueName);
+		//设置手动应答
+		container.setAcknowledgeMode(AcknowledgeMode.MANUAL);
+		//使用ChannelAwareMessageListener接口,必须实现OnMessage方法
+		container.setMessageListener(this);
+		return container;
+	}
+
+	@Override
+	public void onMessage(Message message, Channel channel) {
+		String messageJson = new String(message.getBody());
+		long tag = message.getMessageProperties().getDeliveryTag();
+		String queueName = message.getMessageProperties().getConsumerQueue();
+		processMessage(messageJson, channel, tag, queueName);
+	}
+
+	/**
+	 * 接收消息处理
+	 *
+	 * @param messageBytes
+	 * @param channel
+	 * @param headers
+	 */
+	@RabbitHandler
+	public void receiveMessage(byte[] messageBytes, Channel channel, @Headers Map<String, Object> headers) {
+		receiveMessage(new String(messageBytes), channel, headers);
+	}
+
+	/**
+	 * 接收消息处理
+	 *
+	 * @param messageJson
+	 * @param channel
+	 * @param headers
+	 */
+	@RabbitHandler
+	public void receiveMessage(String messageJson, Channel channel, @Headers Map<String, Object> headers) {
+		long tag = (Long) headers.get(AmqpHeaders.DELIVERY_TAG);
+		String queueName = (String) headers.get(AmqpHeaders.CONSUMER_QUEUE);
+		processMessage(messageJson, channel, tag, queueName);
+	}
+
+	/**
+	 * 处理消息
+	 *
+	 * @param messageJson 消息Json内容
+	 * @param channel     管道
+	 * @param tag         Delivery Tag
+	 * @param queueName   队列名
+	 */
+	private void processMessage(String messageJson, Channel channel, long tag, String queueName) {
+		MessageInfo messageInfo = getMessageInfo(messageJson);
+		//当消息不符合格式MessageInfo格式时,丢弃消息
+		if (messageInfo == null) {
+			LOGGER.warn("接收消息处理.消息格式.异常,messageJson:{},tag:{}", messageJson, tag);
+			basicNack(channel, tag);
+			return;
+		}
+		try {
+			LOGGER.info("接收消息处理[BaseRabbitReceiveService.receiveMessage].处理开始,messageJson:{},tag:{}", messageJson, tag);
+			processMessage(messageInfo);
+			LOGGER.info("接收消息处理[BaseRabbitReceiveService.receiveMessage].处理结束,messageJson:{},tag:{}", messageJson, tag);
+		} catch (Exception e) {
+			LOGGER.error("接收消息处理[BaseRabbitReceiveService.receiveMessage].异常,messageJson:{},tag:{}", messageJson, tag, e);
+			//出现异常时,消息转发为延时消息
+			sendDelayMessage(messageInfo, channel, queueName);
+		} finally {
+			basicAck(channel, tag);
+		}
+	}
+
+	/**
+	 * 获取消息内容实体
+	 *
+	 * @param messageJson
+	 * @return
+	 */
+	private MessageInfo getMessageInfo(String messageJson) {
+		MessageInfo messageInfo = null;
+		try {
+			messageInfo = JSON.parseObject(messageJson, MessageInfo.class);
+		} catch (Exception e) {
+			LOGGER.error("获取消息内容实体[BaseRabbitReceiveService.getMessageInfo].异常,messageJson:{}", messageJson, e);
+
+		}
+		return messageInfo;
+	}
+
+	/**
+	 * 发送延时消息
+	 *
+	 * @param messageInfo
+	 * @param channel
+	 * @param queueName
+	 */
+	private void sendDelayMessage(MessageInfo messageInfo, Channel channel, String queueName) {
+		//重试次数+1
+		messageInfo.setRetryCount(messageInfo.getRetryCount() + 1);
+		String messageJson = JSON.toJSONString(messageInfo);
+		try {
+			String dQueueName = getDelayQueueName(channel, queueName);
+			AMQP.BasicProperties.Builder builder = new AMQP.BasicProperties.Builder();
+			//设置延时时间
+			builder.expiration(delayTime);
+			channel.basicPublish("", dQueueName, builder.build(), messageJson.getBytes());
+			LOGGER.info("发送延时消息[BaseRabbitReceiveService.sendDelayMessage].正常,messageJson:{},queueName:{}", messageJson, queueName);
+		} catch (IOException e) {
+			LOGGER.error("发送延时消息[BaseRabbitReceiveService.sendDelayMessage].异常,messageJson:{},queueName:{}", messageJson, queueName, e);
+		}
+	}
+
+	/**
+	 * 获取延时队列名
+	 *
+	 * @param channel
+	 * @param queueName
+	 * @return
+	 * @throws IOException
+	 */
+	private String getDelayQueueName(Channel channel, String queueName) throws IOException {
+		if (StringUtils.isNotBlank(delayQueueName)) {
+			return delayQueueName;
+		}
+		//初始化延时队列
+		String dQueueName = queueName + DELAY_QUEUE_NAME_SUFFIX;
+		Map<String, Object> arguments = new HashMap<>(2);
+		arguments.put("x-dead-letter-exchange", "");
+		arguments.put("x-dead-letter-routing-key", queueName);
+		channel.queueDeclare(dQueueName, true, false, false, arguments);
+		delayQueueName = dQueueName;
+		return dQueueName;
+	}
+
+	/**
+	 * 消息应答No
+	 *
+	 * @param channel
+	 * @param tag
+	 */
+	private void basicNack(Channel channel, long tag) {
+		try {
+			channel.basicNack(tag, false, false);
+			LOGGER.info("接收消息处理.消息应答No[BaseRabbitReceiveService.receiveMessage.basicNack].正常,tag:{}", tag);
+		} catch (IOException e) {
+			LOGGER.error("接收消息处理.消息应答No[BaseRabbitReceiveService.receiveMessage.basicNack].异常,tag:{}", tag, e);
+		}
+	}
+
+	/**
+	 * 消息应答Yes
+	 *
+	 * @param channel
+	 * @param tag
+	 */
+	private void basicAck(Channel channel, long tag) {
+		try {
+			channel.basicAck(tag, false);
+			LOGGER.info("接收消息处理.消息应答Yes[BaseRabbitReceiveService.receiveMessage.basicAck].正常,tag:{}", tag);
+		} catch (IOException e) {
+			LOGGER.error("接收消息处理.消息应答Yes[BaseRabbitReceiveService.receiveMessage.basicAck].异常,tag:{}", tag, e);
+		}
+	}
+
+	/**
+	 * 处理消息
+	 *
+	 * @param messageInfo 消息体
+	 * @throws Exception 处理失败时,抛出异常
+	 */
+	public abstract void processMessage(MessageInfo messageInfo) throws Exception;
+}

+ 152 - 0
usoft-mq-utils/src/main/java/com/usoft/mq/utils/MessageInfo.java

@@ -0,0 +1,152 @@
+package com.usoft.mq.utils;
+
+/**
+ * 消息内容
+ *
+ * @author: wangcanyi
+ * @date: 2018-08-24 15:08
+ **/
+public class MessageInfo {
+	/**
+	 * 消息ID
+	 */
+	private String msgId;
+	/**
+	 * 用户ID
+	 */
+	private String userId;
+	/**
+	 * 应用号
+	 */
+	private String appId;
+	/**
+	 * 业务类型
+	 */
+	private String bizType;
+	/**
+	 * 业务号
+	 */
+	private String bizId;
+	/**
+	 * 时间戳
+	 */
+	private long timestamp;
+	/**
+	 * 重试次数
+	 */
+	private int retryCount;
+
+	/**
+	 * 消息ID
+	 *
+	 * @return
+	 */
+	public String getMsgId() {
+		return msgId;
+	}
+
+	/**
+	 * @param msgId 消息ID
+	 */
+	public void setMsgId(String msgId) {
+		this.msgId = msgId;
+	}
+
+	/**
+	 * 用户ID
+	 *
+	 * @return
+	 */
+	public String getUserId() {
+		return userId;
+	}
+
+	/**
+	 * @param userId 用户ID
+	 */
+	public void setUserId(String userId) {
+		this.userId = userId;
+	}
+
+	/**
+	 * 应用号
+	 *
+	 * @return
+	 */
+	public String getAppId() {
+		return appId;
+	}
+
+	/**
+	 * @param appId 应用号
+	 */
+	public void setAppId(String appId) {
+		this.appId = appId;
+	}
+
+	/**
+	 * 业务类型
+	 *
+	 * @return
+	 */
+	public String getBizType() {
+		return bizType;
+	}
+
+	/**
+	 * @param bizType 业务类型
+	 */
+	public void setBizType(String bizType) {
+		this.bizType = bizType;
+	}
+
+	/**
+	 * 业务号
+	 *
+	 * @return
+	 */
+	public String getBizId() {
+		return bizId;
+	}
+
+	/**
+	 * @param bizId 业务号
+	 */
+	public void setBizId(String bizId) {
+		this.bizId = bizId;
+	}
+
+	/**
+	 * 时间戳
+	 *
+	 * @return
+	 */
+	public long getTimestamp() {
+		return timestamp;
+	}
+
+	/**
+	 * @param timestamp 时间戳
+	 */
+	public void setTimestamp(long timestamp) {
+		this.timestamp = timestamp;
+	}
+
+	/**
+	 * 重试次数
+	 *
+	 * @return
+	 */
+	public int getRetryCount() {
+		return retryCount;
+	}
+
+	/**
+	 * 重试次数
+	 *
+	 * @param retryCount
+	 */
+	public void setRetryCount(int retryCount) {
+		this.retryCount = retryCount;
+	}
+}

+ 96 - 0
usoft-mq-utils/src/main/java/com/usoft/mq/utils/RabbitSendService.java

@@ -0,0 +1,96 @@
+package com.usoft.mq.utils;
+
+import com.alibaba.fastjson.JSON;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.amqp.core.Message;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
+import org.springframework.amqp.rabbit.support.CorrelationData;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+import java.util.UUID;
+
+/**
+ * RabbitMQ 发送消息
+ *
+ * @author: wangcanyi
+ * @date: 2018-08-30 15:11
+ **/
+@Service
+public class RabbitSendService implements RabbitTemplate.ConfirmCallback, RabbitTemplate.ReturnCallback {
+	private static final Logger LOGGER = LoggerFactory.getLogger(RabbitSendService.class);
+	@Autowired
+	private RabbitTemplate rabbitTemplate;
+
+	@PostConstruct
+	public void init() {
+//		如果消息没有到exchange,则confirm回调,ack=false
+//		如果消息到达exchange,则confirm回调,ack=true
+//		exchange到queue成功,则不回调return
+//		exchange到queue失败,则回调return(否则不回回调,消息就丢了)
+		rabbitTemplate.setConfirmCallback(this);
+		rabbitTemplate.setReturnCallback(this);
+	}
+
+	/**
+	 * @param queueName 队列名
+	 * @param userId    用户ID
+	 * @param appId     应用号
+	 * @param bizType   业务类型
+	 * @param bizId     业务ID
+	 * @return 消息ID
+	 */
+	public String sendMessage(String queueName, String userId, String appId, String bizType, String bizId) {
+		MessageInfo messageInfo = new MessageInfo();
+		messageInfo.setUserId(userId);
+		messageInfo.setAppId(appId);
+		messageInfo.setBizType(bizType);
+		messageInfo.setBizId(bizId);
+		return sendMessage(queueName, messageInfo);
+	}
+
+
+	/**
+	 * 发送消息
+	 *
+	 * @param queueName   队列名
+	 * @param messageInfo 消息体
+	 * @return 消息ID
+	 */
+	public String sendMessage(String queueName, MessageInfo messageInfo) {
+		if (StringUtils.isBlank(queueName)) {
+			throw new IllegalArgumentException("queueName不能为空");
+		}
+		if (messageInfo == null) {
+			throw new IllegalArgumentException("messageInfo不能为空");
+		}
+		//设置消息ID
+		messageInfo.setMsgId(UUID.randomUUID().toString());
+		//设置时间戳
+		messageInfo.setTimestamp(System.currentTimeMillis());
+		CorrelationData correlationData = new CorrelationData(messageInfo.getMsgId());
+		String messageJson = JSON.toJSONString(messageInfo);
+		rabbitTemplate.convertAndSend(queueName, (Object) messageJson, correlationData);
+		LOGGER.info("发送消息[RabbitSendService.sendMessage].正常,queueName:{},messageInfo:{},correlationData:{}",
+				queueName, messageJson, correlationData.getId());
+		return messageInfo.getMsgId();
+	}
+
+	@Override
+	public void confirm(CorrelationData correlationData, boolean ack, String cause) {
+		if (ack) {
+			LOGGER.info("发送消息确认[RabbitSendService.confirm].正常,correlationData:{}", correlationData.getId());
+		} else {
+			LOGGER.error("发送消息确认[RabbitSendService.confirm].异常,correlationData:{},cause:{}", correlationData.getId(), cause);
+		}
+	}
+
+	@Override
+	public void returnedMessage(Message message, int replyCode, String replyText, String exchange, String routingKey) {
+		LOGGER.error("发送消息确认到达队列[RabbitSendService.returnedMessage].异常,message:{},replyCode:{},replyText:{},exchange:{},routingKey:{}",
+				message, replyCode, replyText, exchange, routingKey);
+	}
+}

+ 34 - 0
usoft-mybatis-utils/pom.xml

@@ -0,0 +1,34 @@
+<?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>usoft-framework-parent</artifactId>
+        <groupId>com.usoft.framework</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>usoft-mybatis-utils</artifactId>
+    <version>${profile}-1.0-SNAPSHOT</version>
+    <packaging>jar</packaging>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>com.usoft.framework</groupId>
+                <artifactId>usoft-grpc-dependencies</artifactId>
+                <version>dev-1.0-SNAPSHOT</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.mybatis.generator</groupId>
+            <artifactId>mybatis-generator-core</artifactId>
+        </dependency>
+    </dependencies>
+</project>

+ 145 - 0
usoft-mybatis-utils/src/main/java/com/usoft/mybatis/utils/MybatisCommentGenerator.java

@@ -0,0 +1,145 @@
+package com.usoft.mybatis.utils;
+
+import org.mybatis.generator.api.CommentGenerator;
+import org.mybatis.generator.api.IntrospectedColumn;
+import org.mybatis.generator.api.IntrospectedTable;
+import org.mybatis.generator.api.dom.java.*;
+import org.mybatis.generator.api.dom.xml.XmlElement;
+
+import java.util.Properties;
+import java.util.Set;
+
+/**
+ * @author wangcanyi
+ * @date 2018-07-31 17:57
+ */
+public class MybatisCommentGenerator implements CommentGenerator {
+
+	@Override
+	public void addConfigurationProperties(Properties properties) {
+
+	}
+
+	@Override
+	public void addFieldComment(Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
+		this.addComment(field, introspectedTable, introspectedColumn);
+	}
+
+	@Override
+	public void addFieldComment(Field field, IntrospectedTable introspectedTable) {
+
+	}
+
+	@Override
+	public void addModelClassComment(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
+		// 添加字段注释
+		StringBuffer comment = new StringBuffer();
+		topLevelClass.addJavaDocLine("/**");
+		topLevelClass.addJavaDocLine(" * <pre>");
+		if (introspectedTable.getRemarks() != null) {
+			topLevelClass.addJavaDocLine(" * " + introspectedTable.getRemarks());
+		}
+		comment.append(" * 表名 : ");
+		comment.append(introspectedTable.getFullyQualifiedTable());
+		topLevelClass.addJavaDocLine(comment.toString());
+		topLevelClass.addJavaDocLine(" * </pre>");
+		topLevelClass.addJavaDocLine(" * @author: Mybatis Generator");
+		topLevelClass.addJavaDocLine(" */");
+	}
+
+	@Override
+	public void addClassComment(InnerClass innerClass, IntrospectedTable introspectedTable) {
+
+	}
+
+	@Override
+	public void addClassComment(InnerClass innerClass, IntrospectedTable introspectedTable, boolean markAsDoNotDelete) {
+
+	}
+
+	@Override
+	public void addEnumComment(InnerEnum innerEnum, IntrospectedTable introspectedTable) {
+
+	}
+
+	@Override
+	public void addGetterComment(Method method, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
+		this.addComment(method, introspectedTable, introspectedColumn);
+	}
+
+	@Override
+	public void addSetterComment(Method method, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
+		this.addComment(method, introspectedTable, introspectedColumn);
+	}
+
+	@Override
+	public void addGeneralMethodComment(Method method, IntrospectedTable introspectedTable) {
+		method.addJavaDocLine("/**");
+		method.addJavaDocLine(" * " + method.getName());
+		method.addJavaDocLine(" * ");
+		for (Parameter parameter : method.getParameters()) {
+			method.addJavaDocLine(" * @param " + parameter.getName());
+		}
+		String returnType = method.getReturnType().toString();
+		returnType = returnType.lastIndexOf(".") != -1 ? returnType.substring(returnType.lastIndexOf(".") + 1) : returnType;
+		method.addJavaDocLine(" * @return " + returnType);
+		method.addJavaDocLine(" */");
+	}
+
+	@Override
+	public void addJavaFileComment(CompilationUnit compilationUnit) {
+
+	}
+
+	@Override
+	public void addComment(XmlElement xmlElement) {
+
+	}
+
+	@Override
+	public void addRootComment(XmlElement rootElement) {
+
+	}
+
+	@Override
+	public void addGeneralMethodAnnotation(Method method, IntrospectedTable introspectedTable, Set<FullyQualifiedJavaType> set) {
+
+	}
+
+	@Override
+	public void addGeneralMethodAnnotation(Method method, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn, Set<FullyQualifiedJavaType> set) {
+
+	}
+
+	@Override
+	public void addFieldAnnotation(Field field, IntrospectedTable introspectedTable, Set<FullyQualifiedJavaType> set) {
+
+	}
+
+	@Override
+	public void addFieldAnnotation(Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn, Set<FullyQualifiedJavaType> set) {
+
+	}
+
+	@Override
+	public void addClassAnnotation(InnerClass innerClass, IntrospectedTable introspectedTable, Set<FullyQualifiedJavaType> set) {
+
+	}
+
+	private void addComment(JavaElement javaElement, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
+		// 添加字段注释
+		StringBuffer comment = new StringBuffer();
+		javaElement.addJavaDocLine("/**");
+		javaElement.addJavaDocLine(" * <pre>");
+		if (introspectedColumn.getRemarks() != null) {
+			javaElement.addJavaDocLine(" * " + introspectedColumn.getRemarks());
+		}
+		comment.append(" * 表字段 : ");
+		comment.append(introspectedTable.getFullyQualifiedTable());
+		comment.append('.');
+		comment.append(introspectedColumn.getActualColumnName());
+		javaElement.addJavaDocLine(comment.toString());
+		javaElement.addJavaDocLine(" * </pre>");
+		javaElement.addJavaDocLine(" */");
+	}
+}

+ 115 - 0
usoft-mybatis-utils/src/main/java/com/usoft/mybatis/utils/plugin/SelectByCodePlugin.java

@@ -0,0 +1,115 @@
+package com.usoft.mybatis.utils.plugin;
+
+import org.mybatis.generator.api.IntrospectedColumn;
+import org.mybatis.generator.api.IntrospectedTable;
+import org.mybatis.generator.api.PluginAdapter;
+import org.mybatis.generator.api.dom.java.*;
+import org.mybatis.generator.api.dom.xml.Attribute;
+import org.mybatis.generator.api.dom.xml.Document;
+import org.mybatis.generator.api.dom.xml.TextElement;
+import org.mybatis.generator.api.dom.xml.XmlElement;
+import org.mybatis.generator.codegen.mybatis3.MyBatis3FormattingUtilities;
+
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+/**
+ * 生成 selectByCode 插件
+ *
+ * @author: wangcanyi
+ * @date: 2018-09-04 10:55
+ **/
+public class SelectByCodePlugin extends PluginAdapter {
+	private static final String CODE_NAME = "code";
+	private static final String METHOD_NAME = "selectByCode";
+
+	@Override
+	public boolean validate(List<String> warnings) {
+		return true;
+	}
+
+	@Override
+	public boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
+		boolean super_result = super.clientGenerated(interfaze, topLevelClass, introspectedTable);
+		IntrospectedColumn codeColumn = introspectedTable.getColumn(CODE_NAME);
+		//不存在Code列时,则不需要生成
+		if (codeColumn == null) {
+			return super_result;
+		}
+
+		Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
+		Method method = new Method();
+		//设置方法可见度
+		method.setVisibility(JavaVisibility.PUBLIC);
+
+		//设置返回类型
+		FullyQualifiedJavaType returnType = introspectedTable.getRules().calculateAllFieldsClass();
+		method.setReturnType(returnType);
+		importedTypes.add(returnType);
+		//设置方法名
+		method.setName(METHOD_NAME);
+		//设置参数
+		FullyQualifiedJavaType type = codeColumn.getFullyQualifiedJavaType();
+		importedTypes.add(type);
+		Parameter parameter = new Parameter(type, codeColumn.getJavaProperty());
+		//parameter.addAnnotation("@Param(\"" + codeColumn.getJavaProperty() + "\")");
+		method.addParameter(parameter);
+
+		//引入注释
+		context.getCommentGenerator().addGeneralMethodComment(method,
+				introspectedTable);
+
+		//添加方法生成
+		interfaze.addImportedTypes(importedTypes);
+		interfaze.addMethod(method);
+		return true;
+	}
+
+	@Override
+	public boolean sqlMapDocumentGenerated(Document document, IntrospectedTable introspectedTable) {
+		boolean super_result = super.sqlMapDocumentGenerated(document, introspectedTable);
+		IntrospectedColumn codeColumn = introspectedTable.getColumn(CODE_NAME);
+		//不存在Code列时,则不需要生成
+		if (codeColumn == null) {
+			return super_result;
+		}
+
+		XmlElement answer = new XmlElement("select");
+		answer.addAttribute(new Attribute("id", METHOD_NAME));
+		if (introspectedTable.getRules().generateResultMapWithBLOBs()) {
+			answer.addAttribute(new Attribute("resultMap", introspectedTable.getResultMapWithBLOBsId()));
+		} else {
+			answer.addAttribute(new Attribute("resultMap", introspectedTable.getBaseResultMapId()));
+		}
+		answer.addAttribute(new Attribute("parameterType", codeColumn.getFullyQualifiedJavaType().toString()));
+
+		context.getCommentGenerator().addComment(answer);
+
+		answer.addElement(new TextElement("select "));
+		answer.addElement(getBaseColumnListElement(introspectedTable));
+		if (introspectedTable.hasBLOBColumns()) {
+			answer.addElement(new TextElement(","));
+			answer.addElement(getBlobColumnListElement(introspectedTable));
+		}
+		answer.addElement(new TextElement("from " + introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()));
+		answer.addElement(new TextElement("where " + CODE_NAME + " = " + MyBatis3FormattingUtilities.getParameterClause(codeColumn)));
+
+		XmlElement parentElement = document.getRootElement();
+		parentElement.addElement(answer);
+
+		return true;
+	}
+
+	private XmlElement getBaseColumnListElement(IntrospectedTable introspectedTable) {
+		XmlElement answer = new XmlElement("include");
+		answer.addAttribute(new Attribute("refid", introspectedTable.getBaseColumnListId()));
+		return answer;
+	}
+
+	private XmlElement getBlobColumnListElement(IntrospectedTable introspectedTable) {
+		XmlElement answer = new XmlElement("include");
+		answer.addAttribute(new Attribute("refid", introspectedTable.getBlobColumnListId()));
+		return answer;
+	}
+}

+ 58 - 0
usoft-mybatis-utils/src/main/java/com/usoft/mybatis/utils/plugin/TableBaseColumnListPlugin.java

@@ -0,0 +1,58 @@
+package com.usoft.mybatis.utils.plugin;
+
+import org.mybatis.generator.api.IntrospectedColumn;
+import org.mybatis.generator.api.IntrospectedTable;
+import org.mybatis.generator.api.PluginAdapter;
+import org.mybatis.generator.api.dom.xml.Attribute;
+import org.mybatis.generator.api.dom.xml.Document;
+import org.mybatis.generator.api.dom.xml.TextElement;
+import org.mybatis.generator.api.dom.xml.XmlElement;
+import org.mybatis.generator.codegen.mybatis3.MyBatis3FormattingUtilities;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * 生成带表名的字段列表
+ *
+ * @author: wangcanyi
+ * @date: 2018-09-04 14:39
+ **/
+public class TableBaseColumnListPlugin extends PluginAdapter {
+	@Override
+	public boolean validate(List<String> warnings) {
+		return true;
+	}
+
+	@Override
+	public boolean sqlMapDocumentGenerated(Document document, IntrospectedTable introspectedTable) {
+		XmlElement answer = new XmlElement("sql");
+		answer.addAttribute(new Attribute("id", "Table_Base_Column_List"));
+		context.getCommentGenerator().addComment(answer);
+		StringBuilder sb = new StringBuilder();
+		Iterator<IntrospectedColumn> iter = introspectedTable
+				.getNonBLOBColumns().iterator();
+		while (iter.hasNext()) {
+			sb.append(introspectedTable.getFullyQualifiedTableNameAtRuntime());
+			sb.append('.');
+
+			sb.append(MyBatis3FormattingUtilities.getSelectListPhrase(iter
+					.next()));
+			if (iter.hasNext()) {
+				sb.append(", ");
+			}
+			if (sb.length() > 80) {
+				answer.addElement(new TextElement(sb.toString()));
+				sb.setLength(0);
+			}
+		}
+
+		if (sb.length() > 0) {
+			answer.addElement(new TextElement(sb.toString()));
+		}
+
+		XmlElement parentElement = document.getRootElement();
+		parentElement.addElement(answer);
+		return true;
+	}
+}

+ 46 - 0
usoft-protobuf-utils/pom.xml

@@ -0,0 +1,46 @@
+<?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>usoft-framework-parent</artifactId>
+        <groupId>com.usoft.framework</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>usoft-protobuf-utils</artifactId>
+    <version>${profile}-1.0-SNAPSHOT</version>
+    <packaging>jar</packaging>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>com.usoft.framework</groupId>
+                <artifactId>usoft-base-dependencies</artifactId>
+                <version>dev-1.0-SNAPSHOT</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <dependencies>
+        <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-classic</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>io.grpc</groupId>
+            <artifactId>grpc-all</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+        </dependency>
+    </dependencies>
+</project>

+ 117 - 0
usoft-protobuf-utils/src/main/java/com/usoft/protobuf/utils/ProtoBufUtil.java

@@ -0,0 +1,117 @@
+package com.usoft.protobuf.utils;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.serializer.SerializerFeature;
+import com.google.protobuf.InvalidProtocolBufferException;
+import com.google.protobuf.Message;
+import com.google.protobuf.MessageOrBuilder;
+import com.google.protobuf.util.JsonFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * ProtoBuf 工具类
+ *
+ * @author wangcanyi
+ * @date 2018-07-31 17:57
+ */
+public class ProtoBufUtil {
+	private static final Logger LOGGER = LoggerFactory.getLogger(ProtoBufUtil.class);
+	/**
+	 * 日期格式
+	 */
+	private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
+	/**
+	 * ProtoBuf to Json Format
+	 */
+	private static final JsonFormat.Printer JSON_FORMAT_PRINTER = JsonFormat.printer().includingDefaultValueFields();
+	/**
+	 * Parser Json To ProtoBuf
+	 */
+	private static final JsonFormat.Parser JSON_FORMAT_PARSER = JsonFormat.parser().ignoringUnknownFields();
+
+	/**
+	 * ProtoBuf实体 转换为 Javabean
+	 *
+	 * @param message ProtoBuf实体
+	 * @param cls     Javabean Class
+	 * @param <T>
+	 * @return Javabean
+	 * @throws InvalidProtocolBufferException
+	 */
+	public static <T> T toBean(MessageOrBuilder message, Class<T> cls) throws InvalidProtocolBufferException {
+		String jsonStr = JSON_FORMAT_PRINTER.print(message);
+		return JSON.parseObject(jsonStr, cls);
+	}
+
+	/**
+	 * JavaBean 转换为 ProtoBuf实体
+	 *
+	 * @param builder    ProtoBuf Builder
+	 * @param beanSource JavaBean
+	 * @param <T>
+	 * @return
+	 * @throws InvalidProtocolBufferException
+	 */
+	public static <T extends Message.Builder> T toProtoBuf(T builder, Object beanSource) throws InvalidProtocolBufferException {
+		JSON.DEFFAULT_DATE_FORMAT = DATE_FORMAT;
+		String jsonStr = JSON.toJSONString(beanSource, SerializerFeature.WriteDateUseDateFormat);
+		JSON_FORMAT_PARSER.merge(jsonStr, builder);
+		return builder;
+	}
+
+	/**
+	 * ProtoBuf实体之间的转换
+	 *
+	 * @param builder        目标ProtoBuf实体
+	 * @param protoBufSource 原来的ProtoBuf实体
+	 * @param <T>
+	 * @return
+	 * @throws InvalidProtocolBufferException
+	 */
+	public static <T extends Message.Builder> T toProtoBuf(T builder, MessageOrBuilder protoBufSource) throws InvalidProtocolBufferException {
+		JSON_FORMAT_PARSER.merge(JSON_FORMAT_PRINTER.print(protoBufSource), builder);
+		return builder;
+	}
+
+	/**
+	 * Json字符串 转 ProtoBuf实体
+	 *
+	 * @param builder    目标ProtoBuf实体
+	 * @param jsonSource Json字符串
+	 * @param <T>
+	 * @return
+	 * @throws Exception
+	 */
+	public static <T extends Message.Builder> T toProtoBuf(T builder, String jsonSource) throws InvalidProtocolBufferException {
+		JSON_FORMAT_PARSER.merge(jsonSource, builder);
+		return builder;
+	}
+
+	/**
+	 * ProtoBuf实体 转 Json字符串
+	 *
+	 * @param message ProtoBuf实体
+	 * @return Json字符串
+	 * @throws InvalidProtocolBufferException
+	 */
+	public static String toJSON(MessageOrBuilder message) throws InvalidProtocolBufferException {
+		return JSON_FORMAT_PRINTER.print(message);
+	}
+
+	/**
+	 * ProtoBuf实体 转 Json字符串 捕获异常
+	 *
+	 * @param message
+	 * @return
+	 */
+	public static String toJSONHasTryCatch(MessageOrBuilder message) {
+		String jsonStr = "";
+		try {
+			jsonStr = JSON_FORMAT_PRINTER.print(message);
+		} catch (InvalidProtocolBufferException e) {
+			LOGGER.error("ProtoBuf实体 转 Json字符串 捕获异常[ProtoBufUtil.toJSONHasTryCatch]异常,参数:{}", message, e);
+		}
+		return jsonStr;
+	}
+}

+ 43 - 0
usoft-rest-dependencies/pom.xml

@@ -0,0 +1,43 @@
+<?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>usoft-framework-parent</artifactId>
+        <groupId>com.usoft.framework</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>usoft-rest-dependencies</artifactId>
+    <version>${profile}-1.0-SNAPSHOT</version>
+    <packaging>pom</packaging>
+
+    <properties>
+        <usoft-base-dependencies.version>${profile}-1.0-SNAPSHOT</usoft-base-dependencies.version>
+        <spring-boot-starter-web.version>1.5.11.RELEASE</spring-boot-starter-web.version>
+        <usoft-security-utils.version>${profile}-1.0-SNAPSHOT</usoft-security-utils.version>
+    </properties>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>com.usoft.framework</groupId>
+                <artifactId>usoft-base-dependencies</artifactId>
+                <version>${usoft-base-dependencies.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+            <dependency>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-starter-web</artifactId>
+                <version>${spring-boot-starter-web.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>com.usoft.framework</groupId>
+                <artifactId>usoft-security-utils</artifactId>
+                <version>${usoft-security-utils.version}</version>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+</project>

+ 54 - 0
usoft-security-utils/pom.xml

@@ -0,0 +1,54 @@
+<?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>usoft-framework-parent</artifactId>
+        <groupId>com.usoft.framework</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>usoft-security-utils</artifactId>
+    <version>${profile}-1.0-SNAPSHOT</version>
+    <packaging>jar</packaging>
+
+    <properties>
+        <maven.compiler.source>1.7</maven.compiler.source>
+        <maven.compiler.target>1.7</maven.compiler.target>
+    </properties>
+
+    <dependencyManagement>
+        <!--该包将可能暴露给外部公司使用,则不使用底层框架依赖配置,以最简包导入-->
+        <!--<dependencies>
+            <dependency>
+                <groupId>com.usoft.framework</groupId>
+                <artifactId>usoft-rest-dependencies</artifactId>
+                <version>dev-1.0-SNAPSHOT</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>-->
+    </dependencyManagement>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>org.apache.tomcat.embed</groupId>
+            <artifactId>tomcat-embed-core</artifactId>
+            <version>8.5.29</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <version>1.7.25</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+            <version>1.2.47</version>
+        </dependency>
+    </dependencies>
+</project>

+ 50 - 0
usoft-security-utils/src/main/java/com/usoft/security/utils/HmacUtil.java

@@ -0,0 +1,50 @@
+package com.usoft.security.utils;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+import javax.xml.bind.DatatypeConverter;
+import java.io.UnsupportedEncodingException;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+
+/**
+ * HMAC 加密工具类
+ *
+ * @author: wangcanyi
+ * @date: 2018-08-22 10:32
+ **/
+public class HmacUtil {
+	public static final String HMAC_ALGORITHM = "HmacSHA1";
+	public static final String HMAC_SHA256_ALGORITHM = "HmacSHA256";
+	private static final String CONTENT_CHARSET = "UTF-8";
+
+	/**
+	 * 签名
+	 *
+	 * @param src       待签名字符串
+	 * @param key       密钥
+	 * @param algorithm 算法
+	 * @return
+	 */
+	public static String sign(String src, String key, String algorithm) throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException {
+		if (src == null || src.trim().length() == 0) {
+			throw new RuntimeException("src不能为空");
+		}
+		if (key == null || src.trim().length() == 0) {
+			throw new RuntimeException("key不能为空");
+		}
+		if (algorithm == null || algorithm.trim().length() == 0) {
+			throw new RuntimeException("algorithm不能为空");
+		}
+		if (!algorithm.equals(HMAC_ALGORITHM) && !algorithm.equals(HMAC_SHA256_ALGORITHM)) {
+			throw new RuntimeException("不支持的algorithm");
+		}
+		Mac mac = Mac.getInstance(algorithm);
+		SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(CONTENT_CHARSET), mac.getAlgorithm());
+		mac.init(secretKey);
+		byte[] digest = mac.doFinal(src.getBytes(CONTENT_CHARSET));
+		//因需要给外部公司使用,需兼容Java7,故无法使用Java8特性的Base64,使用Java6的javax.xml.bind.DatatypeConverter
+		//详情见:https://blog.csdn.net/u013476542/article/details/53213783
+		return DatatypeConverter.printBase64Binary(digest);
+	}
+}

+ 208 - 0
usoft-security-utils/src/main/java/com/usoft/security/utils/OpenApiSignUtil.java

@@ -0,0 +1,208 @@
+package com.usoft.security.utils;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+
+/**
+ * Open Api 签名 工具类
+ *
+ * @author: wangcanyi
+ * @date: 2018-08-22 11:18
+ **/
+public class OpenApiSignUtil {
+	public static final String SIGNATURE_KEY = "signature";
+	private static final String HTTP_GET = "GET";
+	private static final String ENCODE = "UTF-8";
+	private static final Logger LOGGER = LoggerFactory.getLogger(OpenApiSignUtil.class);
+
+	/**
+	 * 验证签名
+	 *
+	 * @param request   请求参数
+	 * @param secretKey 密钥
+	 * @return
+	 * @throws NoSuchAlgorithmException
+	 * @throws InvalidKeyException
+	 * @throws IOException
+	 */
+	public static boolean verifySignForHttpGet(HttpServletRequest request, String secretKey) throws NoSuchAlgorithmException, InvalidKeyException, IOException {
+		if (request == null) {
+			throw new RuntimeException("request不能为空");
+		}
+
+		String oldSignatureValue = request.getParameter(SIGNATURE_KEY);
+		if (oldSignatureValue == null || oldSignatureValue.trim().length() == 0) {
+			throw new RuntimeException("signature为空");
+		}
+		String newSignatureValue = signForHttpGet(request, secretKey);
+		LOGGER.debug("[OpenApiSignUtil.verifySignForHttpGet]旧签名{}:新签名:{}", oldSignatureValue, newSignatureValue);
+		return oldSignatureValue.equals(newSignatureValue);
+	}
+
+	/**
+	 * 验证签名
+	 *
+	 * @param jsonBody  json内容
+	 * @param secretKey 密钥
+	 * @return
+	 * @throws NoSuchAlgorithmException
+	 * @throws InvalidKeyException
+	 * @throws UnsupportedEncodingException
+	 */
+	public static boolean verifySignForJson(String jsonBody, String secretKey) throws NoSuchAlgorithmException, InvalidKeyException, UnsupportedEncodingException {
+		if (jsonBody == null || jsonBody.trim().length() == 0) {
+			throw new RuntimeException("jsonBody不能为空");
+		}
+		String oldSignatureValue = getValueByJson(jsonBody, SIGNATURE_KEY);
+		if (oldSignatureValue == null || oldSignatureValue.trim().length() == 0) {
+			throw new RuntimeException("signature为空");
+		}
+		String newSignatureValue = signForJson(jsonBody, secretKey);
+		LOGGER.debug("[OpenApiSignUtil.verifySignForJson]旧签名{}:新签名:{}", oldSignatureValue, newSignatureValue);
+		return oldSignatureValue.equals(newSignatureValue);
+	}
+
+	/**
+	 * 签名 For Http Get
+	 *
+	 * @param request   Http Request
+	 * @param secretKey 密钥
+	 * @return
+	 * @throws NoSuchAlgorithmException
+	 * @throws InvalidKeyException
+	 * @throws UnsupportedEncodingException
+	 */
+	public static String signForHttpGet(HttpServletRequest request, String secretKey) throws NoSuchAlgorithmException, InvalidKeyException, IOException {
+		if (request == null) {
+			throw new RuntimeException("request不能为空");
+		}
+		if (!HTTP_GET.equals(request.getMethod())) {
+			throw new RuntimeException("只支持GET请求");
+		}
+		String src = getSrcByHttpGet(request);
+		return sign(src, secretKey);
+	}
+
+	/**
+	 * 签名 For Json
+	 *
+	 * @param jsonBody  json内容
+	 * @param secretKey 密钥
+	 * @return
+	 * @throws NoSuchAlgorithmException
+	 * @throws InvalidKeyException
+	 * @throws UnsupportedEncodingException
+	 */
+	public static String signForJson(String jsonBody, String secretKey) throws NoSuchAlgorithmException, InvalidKeyException, UnsupportedEncodingException {
+		if (jsonBody == null || jsonBody.trim().length() == 0) {
+			throw new RuntimeException("jsonBody不能为空");
+		}
+		String src = getSrcByJson(jsonBody);
+		return sign(src, secretKey);
+	}
+
+	/**
+	 * 签名
+	 *
+	 * @param src       待签名字符串
+	 * @param secretKey 密钥
+	 * @return
+	 * @throws NoSuchAlgorithmException
+	 * @throws InvalidKeyException
+	 * @throws UnsupportedEncodingException
+	 */
+	public static String sign(String src, String secretKey) throws NoSuchAlgorithmException, InvalidKeyException, UnsupportedEncodingException {
+		return HmacUtil.sign(src, secretKey, HmacUtil.HMAC_SHA256_ALGORITHM);
+	}
+
+	/**
+	 * 获取 Http Get 请求参数,排除签名键值对,注意:排除签名键值对,非签名值
+	 *
+	 * @param request HTTP 请求头
+	 * @return
+	 */
+	private static String getSrcByHttpGet(HttpServletRequest request) throws UnsupportedEncodingException {
+		String signatureValue = request.getParameter(SIGNATURE_KEY);
+		String queryString = URLDecoder.decode(request.getQueryString(), ENCODE);
+		if (queryString == null || queryString.trim().length() == 0) {
+			throw new RuntimeException("请求参数为空");
+		}
+		if (signatureValue == null || signatureValue.trim().length() == 0) {
+			throw new RuntimeException("signature为空");
+		}
+		LOGGER.debug("[OpenApiSignUtil.getSrcByHttpGet]请求参数:{}", queryString);
+		//获取签名键值对
+		String signatureKV = SIGNATURE_KEY + "=" + signatureValue;
+		LOGGER.debug("[OpenApiSignUtil.getSrcByHttpGet]签名键值对:{}", signatureKV);
+		//获取签名键值对位置
+		int signatureIndex = queryString.indexOf(signatureKV);
+		if (signatureIndex == -1) {
+			throw new RuntimeException("不存在signature键值对");
+		}
+		//排队签名键值对
+		String src;
+		if (signatureIndex == 0) {
+			//排第一位
+			src = queryString.replace(signatureKV + "&", "");
+		} else {
+			//不排在第一位
+			src = queryString.replace("&" + signatureKV, "");
+		}
+		LOGGER.debug("[OpenApiSignUtil.getSrcByHttpGet]待签名串:{}", src);
+		return src;
+	}
+
+	/**
+	 * 获取 Json 请求参数,排除签名值,注意:排除签名值,非签名键值对
+	 *
+	 * @param jsonBody
+	 * @return
+	 * @throws IOException
+	 */
+	private static String getSrcByJson(String jsonBody) {
+		if (jsonBody == null || jsonBody.trim().length() == 0) {
+			throw new RuntimeException("请求参数为空");
+		}
+		LOGGER.debug("[OpenApiSignUtil.getSrcByJson]请求参数:{}", jsonBody);
+		String signatureValue = getValueByJson(jsonBody, SIGNATURE_KEY);
+		if (signatureValue == null || signatureValue.trim().length() == 0) {
+			throw new RuntimeException("不存在signature值");
+		}
+		LOGGER.debug("[OpenApiSignUtil.getSrcByJson]签名值:{}", signatureValue);
+		//排除签名值,注意:json只排除签名值,而HTTP GET则排除签名键值对
+		String src = jsonBody.replace(signatureValue, "");
+		LOGGER.debug("[OpenApiSignUtil.getSrcByJson]待签名串:{}", src);
+		return src;
+	}
+
+	/**
+	 * 获取Json里面的特定值
+	 *
+	 * @param jsonBody json内容
+	 * @param key      Json里的属性名
+	 * @return
+	 */
+	private static String getValueByJson(String jsonBody, String key) {
+		if (jsonBody == null || jsonBody.trim().length() == 0) {
+			throw new RuntimeException("jsonBody不能为空");
+		}
+		if (key == null || key.trim().length() == 0) {
+			throw new RuntimeException("Key不能为空");
+		}
+		JSONObject jsonObject = JSON.parseObject(jsonBody);
+		if (jsonObject.containsKey(key)) {
+			return jsonObject.getString(key);
+		} else {
+			return "";
+		}
+	}
+}

+ 58 - 0
usoft-sso-utils/pom.xml

@@ -0,0 +1,58 @@
+<?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>usoft-framework-parent</artifactId>
+        <groupId>com.usoft.framework</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>usoft-sso-utils</artifactId>
+    <version>${profile}-1.0-SNAPSHOT</version>
+    <packaging>jar</packaging>
+
+    <properties>
+        <sso-core.version>0.0.1-SNAPSHOT</sso-core.version>
+        <spring-boot-configuration-processor.version>1.5.11.RELEASE</spring-boot-configuration-processor.version>
+    </properties>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>com.usoft.framework</groupId>
+                <artifactId>usoft-rest-dependencies</artifactId>
+                <version>dev-1.0-SNAPSHOT</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.uas.account</groupId>
+            <artifactId>sso-core</artifactId>
+            <version>${sso-core.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-configuration-processor</artifactId>
+            <version>${spring-boot-configuration-processor.version}</version>
+            <optional>true</optional>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+        </dependency>
+    </dependencies>
+</project>

+ 54 - 0
usoft-sso-utils/src/main/java/com/usoft/sso/utils/BaseSsoController.java

@@ -0,0 +1,54 @@
+package com.usoft.sso.utils;
+
+import com.alibaba.fastjson.JSON;
+import com.uas.sso.SSOConfig;
+import com.uas.sso.SSOHelper;
+import com.uas.sso.SSOToken;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import javax.annotation.PostConstruct;
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * Sso 控制层 基类
+ *
+ * @author: wangcanyi
+ * @date: 2018-08-16 10:20
+ **/
+public abstract class BaseSsoController {
+	@Autowired
+	private SsoProperties ssoProperties;
+
+	@PostConstruct
+	public void init() {
+		if (StringUtils.isBlank(ssoProperties.getApp())) {
+			throw new RuntimeException("应用号不能为空,请在Properties文件配置sso.app");
+		}
+		if (StringUtils.isBlank(ssoProperties.getSecretKey())) {
+			throw new RuntimeException("秘钥不能为空,请在Properties文件配置sso.secret-key");
+		}
+		//初始化sso-core包里的SSOConfig信息
+		SSOConfig ssoConfig = SSOHelper.getSSOService().getConfig();
+		ssoConfig.setAppName(ssoProperties.getApp());
+		ssoConfig.setSecretkey(ssoProperties.getSecretKey());
+		SSOHelper.getSSOService().getConfig().setCookieBrowser(ssoProperties.isCookieBrowser());
+	}
+
+	/**
+	 * 获取登录态
+	 *
+	 * @param request
+	 * @return
+	 */
+	protected UserLoginState getUserLoginState(HttpServletRequest request) {
+		SSOToken ssoToken = SSOHelper.getToken(request);
+		if (ssoToken == null) {
+			return null;
+		}
+		if (StringUtils.isBlank(ssoToken.getData())) {
+			return null;
+		}
+		return JSON.parseObject(ssoToken.getData(), UserLoginState.class);
+	}
+}

+ 75 - 0
usoft-sso-utils/src/main/java/com/usoft/sso/utils/SsoProperties.java

@@ -0,0 +1,75 @@
+package com.usoft.sso.utils;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+/**
+ * SSO 配置
+ *
+ * @author: wangcanyi
+ * @date: 2018-08-16 09:29
+ **/
+@Component
+@ConfigurationProperties("sso")
+public class SsoProperties {
+	/**
+	 * Application Number
+	 */
+	private String app = "";
+	/**
+	 * Login, decrypt, secret key
+	 */
+	private String secretKey = "";
+	/**
+	 * cookie is check user-agent property
+	 */
+	private boolean cookieBrowser = false;
+
+	/**
+	 * Application Number
+	 *
+	 * @return
+	 */
+	public String getApp() {
+		return app;
+	}
+
+	/**
+	 * @param app Application Number
+	 */
+	public void setApp(String app) {
+		this.app = app;
+	}
+
+	/**
+	 * Login, decrypt, secret key
+	 *
+	 * @return
+	 */
+	public String getSecretKey() {
+		return secretKey;
+	}
+
+	/**
+	 * @param secretKey Login, decrypt, secret key
+	 */
+	public void setSecretKey(String secretKey) {
+		this.secretKey = secretKey;
+	}
+
+	/**
+	 * cookie is check user-agent property
+	 *
+	 * @return
+	 */
+	public boolean isCookieBrowser() {
+		return cookieBrowser;
+	}
+
+	/**
+	 * @param cookieBrowser cookie is check user-agent property
+	 */
+	public void setCookieBrowser(boolean cookieBrowser) {
+		this.cookieBrowser = cookieBrowser;
+	}
+}

+ 92 - 0
usoft-sso-utils/src/main/java/com/usoft/sso/utils/UserLoginState.java

@@ -0,0 +1,92 @@
+package com.usoft.sso.utils;
+
+import java.util.Date;
+
+/**
+ * 用户登录态
+ *
+ * @author: wangcanyi
+ * @date: 2018-08-16 10:41
+ **/
+public class UserLoginState {
+	/**
+	 * 应用Id
+	 */
+	private String appId;
+	/**
+	 * 用户UU号
+	 */
+	private Long userUU;
+	/**
+	 * 企业UU号,为空则说明,非企业登录
+	 */
+	private Long spaceUU;
+	/**
+	 * 上次登录时间
+	 */
+	private Date lastLoginTime;
+
+	/**
+	 * 应用Id
+	 *
+	 * @return
+	 */
+	public String getAppId() {
+		return appId;
+	}
+
+	/**
+	 * @param appId 应用Id
+	 */
+	public void setAppId(String appId) {
+		this.appId = appId;
+	}
+
+	/**
+	 * 用户UU号
+	 *
+	 * @return
+	 */
+	public Long getUserUU() {
+		return userUU;
+	}
+
+	/**
+	 * @param userUU 用户UU号
+	 */
+	public void setUserUU(Long userUU) {
+		this.userUU = userUU;
+	}
+
+	/**
+	 * 企业UU号,为空则说明,非企业登录
+	 *
+	 * @return
+	 */
+	public Long getSpaceUU() {
+		return spaceUU;
+	}
+
+	/**
+	 * @param spaceUU 企业UU号,为空则说明,非企业登录
+	 */
+	public void setSpaceUU(Long spaceUU) {
+		this.spaceUU = spaceUU;
+	}
+
+	/**
+	 * 上次登录时间
+	 *
+	 * @return
+	 */
+	public Date getLastLoginTime() {
+		return lastLoginTime;
+	}
+
+	/**
+	 * @param lastLoginTime 上次登录时间
+	 */
+	public void setLastLoginTime(Date lastLoginTime) {
+		this.lastLoginTime = lastLoginTime;
+	}
+}