commit 07b5605c70f8767a61d6a674650b6aecb8eef3da Author: alex_q <914269@qq.com> Date: Fri Jul 10 10:41:19 2026 +0800 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e0934da --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +# Created by .ignore support plugin (hsz.mobi) +### Example sysUserDetails template template +### Example sysUserDetails template + +# IntelliJ project files +.idea +*.iml +out +gen +target +*.log +logs \ No newline at end of file diff --git a/lib/HikariCP-4.0.3.jar b/lib/HikariCP-4.0.3.jar new file mode 100644 index 0000000..f328920 Binary files /dev/null and b/lib/HikariCP-4.0.3.jar differ diff --git a/lib/alipay-sdk-java-4.34.0.ALL.jar b/lib/alipay-sdk-java-4.34.0.ALL.jar new file mode 100644 index 0000000..3a096fb Binary files /dev/null and b/lib/alipay-sdk-java-4.34.0.ALL.jar differ diff --git a/lib/annotations-13.0.jar b/lib/annotations-13.0.jar new file mode 100644 index 0000000..fb794be Binary files /dev/null and b/lib/annotations-13.0.jar differ diff --git a/lib/asm-7.3.1.jar b/lib/asm-7.3.1.jar new file mode 100644 index 0000000..8a50266 Binary files /dev/null and b/lib/asm-7.3.1.jar differ diff --git a/lib/asm-analysis-7.3.1.jar b/lib/asm-analysis-7.3.1.jar new file mode 100644 index 0000000..1f83a5e Binary files /dev/null and b/lib/asm-analysis-7.3.1.jar differ diff --git a/lib/asm-commons-7.3.1.jar b/lib/asm-commons-7.3.1.jar new file mode 100644 index 0000000..65fb30e Binary files /dev/null and b/lib/asm-commons-7.3.1.jar differ diff --git a/lib/asm-tree-7.3.1.jar b/lib/asm-tree-7.3.1.jar new file mode 100644 index 0000000..28858f4 Binary files /dev/null and b/lib/asm-tree-7.3.1.jar differ diff --git a/lib/asm-util-7.3.1.jar b/lib/asm-util-7.3.1.jar new file mode 100644 index 0000000..4fe6c52 Binary files /dev/null and b/lib/asm-util-7.3.1.jar differ diff --git a/lib/bcprov-jdk15on-1.62.jar b/lib/bcprov-jdk15on-1.62.jar new file mode 100644 index 0000000..c52b16e Binary files /dev/null and b/lib/bcprov-jdk15on-1.62.jar differ diff --git a/lib/commons-codec-1.15.jar b/lib/commons-codec-1.15.jar new file mode 100644 index 0000000..f14985a Binary files /dev/null and b/lib/commons-codec-1.15.jar differ diff --git a/lib/commons-fileupload-1.4.jar b/lib/commons-fileupload-1.4.jar new file mode 100644 index 0000000..e25a6bc Binary files /dev/null and b/lib/commons-fileupload-1.4.jar differ diff --git a/lib/commons-io-2.2.jar b/lib/commons-io-2.2.jar new file mode 100644 index 0000000..84ca565 Binary files /dev/null and b/lib/commons-io-2.2.jar differ diff --git a/lib/commons-logging-1.1.1.jar b/lib/commons-logging-1.1.1.jar new file mode 100644 index 0000000..1deef14 Binary files /dev/null and b/lib/commons-logging-1.1.1.jar differ diff --git a/lib/dom4j-1.6.1.jar b/lib/dom4j-1.6.1.jar new file mode 100644 index 0000000..c8c4dbb Binary files /dev/null and b/lib/dom4j-1.6.1.jar differ diff --git a/lib/easy-captcha-1.6.2.jar b/lib/easy-captcha-1.6.2.jar new file mode 100644 index 0000000..e8985a0 Binary files /dev/null and b/lib/easy-captcha-1.6.2.jar differ diff --git a/lib/fastjson-2.0.9.jar b/lib/fastjson-2.0.9.jar new file mode 100644 index 0000000..d0f8156 Binary files /dev/null and b/lib/fastjson-2.0.9.jar differ diff --git a/lib/fastjson2-2.0.9.jar b/lib/fastjson2-2.0.9.jar new file mode 100644 index 0000000..b1b8376 Binary files /dev/null and b/lib/fastjson2-2.0.9.jar differ diff --git a/lib/fastjson2-extension-2.0.9.jar b/lib/fastjson2-extension-2.0.9.jar new file mode 100644 index 0000000..6217325 Binary files /dev/null and b/lib/fastjson2-extension-2.0.9.jar differ diff --git a/lib/gson-2.9.0.jar b/lib/gson-2.9.0.jar new file mode 100644 index 0000000..fb62e05 Binary files /dev/null and b/lib/gson-2.9.0.jar differ diff --git a/lib/httpclient5-5.1.jar b/lib/httpclient5-5.1.jar new file mode 100644 index 0000000..0e83a86 Binary files /dev/null and b/lib/httpclient5-5.1.jar differ diff --git a/lib/httpcore5-5.1.4.jar b/lib/httpcore5-5.1.4.jar new file mode 100644 index 0000000..b436386 Binary files /dev/null and b/lib/httpcore5-5.1.4.jar differ diff --git a/lib/httpcore5-h2-5.1.4.jar b/lib/httpcore5-h2-5.1.4.jar new file mode 100644 index 0000000..6f3ed3a Binary files /dev/null and b/lib/httpcore5-h2-5.1.4.jar differ diff --git a/lib/jackson-annotations-2.13.3.jar b/lib/jackson-annotations-2.13.3.jar new file mode 100644 index 0000000..60a3ddb Binary files /dev/null and b/lib/jackson-annotations-2.13.3.jar differ diff --git a/lib/jackson-core-2.13.3.jar b/lib/jackson-core-2.13.3.jar new file mode 100644 index 0000000..7e2086d Binary files /dev/null and b/lib/jackson-core-2.13.3.jar differ diff --git a/lib/jackson-databind-2.13.3.jar b/lib/jackson-databind-2.13.3.jar new file mode 100644 index 0000000..a27e9d7 Binary files /dev/null and b/lib/jackson-databind-2.13.3.jar differ diff --git a/lib/jackson-datatype-jdk8-2.13.3.jar b/lib/jackson-datatype-jdk8-2.13.3.jar new file mode 100644 index 0000000..6e6a5a9 Binary files /dev/null and b/lib/jackson-datatype-jdk8-2.13.3.jar differ diff --git a/lib/jackson-datatype-jsr310-2.13.3.jar b/lib/jackson-datatype-jsr310-2.13.3.jar new file mode 100644 index 0000000..a0ea06b Binary files /dev/null and b/lib/jackson-datatype-jsr310-2.13.3.jar differ diff --git a/lib/jackson-module-parameter-names-2.13.3.jar b/lib/jackson-module-parameter-names-2.13.3.jar new file mode 100644 index 0000000..da15bb2 Binary files /dev/null and b/lib/jackson-module-parameter-names-2.13.3.jar differ diff --git a/lib/jakarta.annotation-api-1.3.5.jar b/lib/jakarta.annotation-api-1.3.5.jar new file mode 100644 index 0000000..606d992 Binary files /dev/null and b/lib/jakarta.annotation-api-1.3.5.jar differ diff --git a/lib/jakarta.servlet-api-4.0.4.jar b/lib/jakarta.servlet-api-4.0.4.jar new file mode 100644 index 0000000..3c7f7d9 Binary files /dev/null and b/lib/jakarta.servlet-api-4.0.4.jar differ diff --git a/lib/jakarta.websocket-api-1.1.2.jar b/lib/jakarta.websocket-api-1.1.2.jar new file mode 100644 index 0000000..0ab5684 Binary files /dev/null and b/lib/jakarta.websocket-api-1.1.2.jar differ diff --git a/lib/java-jwt-4.0.0.jar b/lib/java-jwt-4.0.0.jar new file mode 100644 index 0000000..813d78a Binary files /dev/null and b/lib/java-jwt-4.0.0.jar differ diff --git a/lib/jboss-logging-3.4.3.Final.jar b/lib/jboss-logging-3.4.3.Final.jar new file mode 100644 index 0000000..31d55c6 Binary files /dev/null and b/lib/jboss-logging-3.4.3.Final.jar differ diff --git a/lib/jboss-threads-3.1.0.Final.jar b/lib/jboss-threads-3.1.0.Final.jar new file mode 100644 index 0000000..b23b458 Binary files /dev/null and b/lib/jboss-threads-3.1.0.Final.jar differ diff --git a/lib/jsqlparser-4.4.jar b/lib/jsqlparser-4.4.jar new file mode 100644 index 0000000..b3eeba5 Binary files /dev/null and b/lib/jsqlparser-4.4.jar differ diff --git a/lib/jul-to-slf4j-1.7.36.jar b/lib/jul-to-slf4j-1.7.36.jar new file mode 100644 index 0000000..ae8f815 Binary files /dev/null and b/lib/jul-to-slf4j-1.7.36.jar differ diff --git a/lib/kotlin-stdlib-1.6.21.jar b/lib/kotlin-stdlib-1.6.21.jar new file mode 100644 index 0000000..a8a6906 Binary files /dev/null and b/lib/kotlin-stdlib-1.6.21.jar differ diff --git a/lib/kotlin-stdlib-common-1.6.21.jar b/lib/kotlin-stdlib-common-1.6.21.jar new file mode 100644 index 0000000..7223f7e Binary files /dev/null and b/lib/kotlin-stdlib-common-1.6.21.jar differ diff --git a/lib/kotlin-stdlib-jdk7-1.6.21.jar b/lib/kotlin-stdlib-jdk7-1.6.21.jar new file mode 100644 index 0000000..97142cb Binary files /dev/null and b/lib/kotlin-stdlib-jdk7-1.6.21.jar differ diff --git a/lib/kotlin-stdlib-jdk8-1.6.21.jar b/lib/kotlin-stdlib-jdk8-1.6.21.jar new file mode 100644 index 0000000..1a17f25 Binary files /dev/null and b/lib/kotlin-stdlib-jdk8-1.6.21.jar differ diff --git a/lib/log4j-api-2.17.2.jar b/lib/log4j-api-2.17.2.jar new file mode 100644 index 0000000..16d9061 Binary files /dev/null and b/lib/log4j-api-2.17.2.jar differ diff --git a/lib/log4j-to-slf4j-2.17.2.jar b/lib/log4j-to-slf4j-2.17.2.jar new file mode 100644 index 0000000..d6c35f4 Binary files /dev/null and b/lib/log4j-to-slf4j-2.17.2.jar differ diff --git a/lib/logback-classic-1.2.11.jar b/lib/logback-classic-1.2.11.jar new file mode 100644 index 0000000..b70c0e6 Binary files /dev/null and b/lib/logback-classic-1.2.11.jar differ diff --git a/lib/logback-core-1.2.11.jar b/lib/logback-core-1.2.11.jar new file mode 100644 index 0000000..e3038da Binary files /dev/null and b/lib/logback-core-1.2.11.jar differ diff --git a/lib/mybatis-3.5.10.jar b/lib/mybatis-3.5.10.jar new file mode 100644 index 0000000..0f941e0 Binary files /dev/null and b/lib/mybatis-3.5.10.jar differ diff --git a/lib/mybatis-plus-3.5.2.jar b/lib/mybatis-plus-3.5.2.jar new file mode 100644 index 0000000..0ec8605 Binary files /dev/null and b/lib/mybatis-plus-3.5.2.jar differ diff --git a/lib/mybatis-plus-annotation-3.5.2.jar b/lib/mybatis-plus-annotation-3.5.2.jar new file mode 100644 index 0000000..e411976 Binary files /dev/null and b/lib/mybatis-plus-annotation-3.5.2.jar differ diff --git a/lib/mybatis-plus-boot-starter-3.5.2.jar b/lib/mybatis-plus-boot-starter-3.5.2.jar new file mode 100644 index 0000000..183a869 Binary files /dev/null and b/lib/mybatis-plus-boot-starter-3.5.2.jar differ diff --git a/lib/mybatis-plus-core-3.5.2.jar b/lib/mybatis-plus-core-3.5.2.jar new file mode 100644 index 0000000..933dfe7 Binary files /dev/null and b/lib/mybatis-plus-core-3.5.2.jar differ diff --git a/lib/mybatis-plus-extension-3.5.2.jar b/lib/mybatis-plus-extension-3.5.2.jar new file mode 100644 index 0000000..98b6808 Binary files /dev/null and b/lib/mybatis-plus-extension-3.5.2.jar differ diff --git a/lib/mybatis-spring-2.0.7.jar b/lib/mybatis-spring-2.0.7.jar new file mode 100644 index 0000000..a930b60 Binary files /dev/null and b/lib/mybatis-spring-2.0.7.jar differ diff --git a/lib/mysql-connector-java-8.0.28.jar b/lib/mysql-connector-java-8.0.28.jar new file mode 100644 index 0000000..ac8904e Binary files /dev/null and b/lib/mysql-connector-java-8.0.28.jar differ diff --git a/lib/nashorn-core-15.4.jar b/lib/nashorn-core-15.4.jar new file mode 100644 index 0000000..b472660 Binary files /dev/null and b/lib/nashorn-core-15.4.jar differ diff --git a/lib/okhttp-4.9.3.jar b/lib/okhttp-4.9.3.jar new file mode 100644 index 0000000..b79d2c9 Binary files /dev/null and b/lib/okhttp-4.9.3.jar differ diff --git a/lib/okio-2.8.0.jar b/lib/okio-2.8.0.jar new file mode 100644 index 0000000..bac6c6e Binary files /dev/null and b/lib/okio-2.8.0.jar differ diff --git a/lib/slf4j-api-1.7.36.jar b/lib/slf4j-api-1.7.36.jar new file mode 100644 index 0000000..7d3ce68 Binary files /dev/null and b/lib/slf4j-api-1.7.36.jar differ diff --git a/lib/snakeyaml-1.30.jar b/lib/snakeyaml-1.30.jar new file mode 100644 index 0000000..6c9b2bc Binary files /dev/null and b/lib/snakeyaml-1.30.jar differ diff --git a/lib/spring-aop-5.3.22.jar b/lib/spring-aop-5.3.22.jar new file mode 100644 index 0000000..4cd4a5e Binary files /dev/null and b/lib/spring-aop-5.3.22.jar differ diff --git a/lib/spring-beans-5.3.22.jar b/lib/spring-beans-5.3.22.jar new file mode 100644 index 0000000..a221f6f Binary files /dev/null and b/lib/spring-beans-5.3.22.jar differ diff --git a/lib/spring-boot-2.7.2.jar b/lib/spring-boot-2.7.2.jar new file mode 100644 index 0000000..5360dc7 Binary files /dev/null and b/lib/spring-boot-2.7.2.jar differ diff --git a/lib/spring-boot-autoconfigure-2.7.2.jar b/lib/spring-boot-autoconfigure-2.7.2.jar new file mode 100644 index 0000000..9a9999d Binary files /dev/null and b/lib/spring-boot-autoconfigure-2.7.2.jar differ diff --git a/lib/spring-boot-jarmode-layertools-2.7.2.jar b/lib/spring-boot-jarmode-layertools-2.7.2.jar new file mode 100644 index 0000000..a27eb1c Binary files /dev/null and b/lib/spring-boot-jarmode-layertools-2.7.2.jar differ diff --git a/lib/spring-context-5.3.22.jar b/lib/spring-context-5.3.22.jar new file mode 100644 index 0000000..6420449 Binary files /dev/null and b/lib/spring-context-5.3.22.jar differ diff --git a/lib/spring-core-5.3.22.jar b/lib/spring-core-5.3.22.jar new file mode 100644 index 0000000..c668509 Binary files /dev/null and b/lib/spring-core-5.3.22.jar differ diff --git a/lib/spring-expression-5.3.22.jar b/lib/spring-expression-5.3.22.jar new file mode 100644 index 0000000..ceaaf79 Binary files /dev/null and b/lib/spring-expression-5.3.22.jar differ diff --git a/lib/spring-jcl-5.3.22.jar b/lib/spring-jcl-5.3.22.jar new file mode 100644 index 0000000..6d125c0 Binary files /dev/null and b/lib/spring-jcl-5.3.22.jar differ diff --git a/lib/spring-jdbc-5.3.22.jar b/lib/spring-jdbc-5.3.22.jar new file mode 100644 index 0000000..3b39e91 Binary files /dev/null and b/lib/spring-jdbc-5.3.22.jar differ diff --git a/lib/spring-tx-5.3.22.jar b/lib/spring-tx-5.3.22.jar new file mode 100644 index 0000000..a4a9cae Binary files /dev/null and b/lib/spring-tx-5.3.22.jar differ diff --git a/lib/spring-web-5.3.22.jar b/lib/spring-web-5.3.22.jar new file mode 100644 index 0000000..f6b6e66 Binary files /dev/null and b/lib/spring-web-5.3.22.jar differ diff --git a/lib/spring-webmvc-5.3.22.jar b/lib/spring-webmvc-5.3.22.jar new file mode 100644 index 0000000..beb27e7 Binary files /dev/null and b/lib/spring-webmvc-5.3.22.jar differ diff --git a/lib/tomcat-embed-el-9.0.65.jar b/lib/tomcat-embed-el-9.0.65.jar new file mode 100644 index 0000000..e54e084 Binary files /dev/null and b/lib/tomcat-embed-el-9.0.65.jar differ diff --git a/lib/undertow-core-2.2.18.Final.jar b/lib/undertow-core-2.2.18.Final.jar new file mode 100644 index 0000000..2cf361d Binary files /dev/null and b/lib/undertow-core-2.2.18.Final.jar differ diff --git a/lib/undertow-servlet-2.2.18.Final.jar b/lib/undertow-servlet-2.2.18.Final.jar new file mode 100644 index 0000000..69834c1 Binary files /dev/null and b/lib/undertow-servlet-2.2.18.Final.jar differ diff --git a/lib/undertow-websockets-jsr-2.2.18.Final.jar b/lib/undertow-websockets-jsr-2.2.18.Final.jar new file mode 100644 index 0000000..2471ec8 Binary files /dev/null and b/lib/undertow-websockets-jsr-2.2.18.Final.jar differ diff --git a/lib/wechatpay-java-0.2.12.jar b/lib/wechatpay-java-0.2.12.jar new file mode 100644 index 0000000..8ce8484 Binary files /dev/null and b/lib/wechatpay-java-0.2.12.jar differ diff --git a/lib/wechatpay-java-core-0.2.12.jar b/lib/wechatpay-java-core-0.2.12.jar new file mode 100644 index 0000000..6a416af Binary files /dev/null and b/lib/wechatpay-java-core-0.2.12.jar differ diff --git a/lib/wildfly-client-config-1.0.1.Final.jar b/lib/wildfly-client-config-1.0.1.Final.jar new file mode 100644 index 0000000..370e8c7 Binary files /dev/null and b/lib/wildfly-client-config-1.0.1.Final.jar differ diff --git a/lib/wildfly-common-1.5.4.Final.jar b/lib/wildfly-common-1.5.4.Final.jar new file mode 100644 index 0000000..a5b5892 Binary files /dev/null and b/lib/wildfly-common-1.5.4.Final.jar differ diff --git a/lib/xml-apis-1.0.b2.jar b/lib/xml-apis-1.0.b2.jar new file mode 100644 index 0000000..ad33a5a Binary files /dev/null and b/lib/xml-apis-1.0.b2.jar differ diff --git a/lib/xnio-api-3.8.7.Final.jar b/lib/xnio-api-3.8.7.Final.jar new file mode 100644 index 0000000..a8f589e Binary files /dev/null and b/lib/xnio-api-3.8.7.Final.jar differ diff --git a/lib/xnio-nio-3.8.7.Final.jar b/lib/xnio-nio-3.8.7.Final.jar new file mode 100644 index 0000000..e4b400f Binary files /dev/null and b/lib/xnio-nio-3.8.7.Final.jar differ diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..d0614d2 --- /dev/null +++ b/pom.xml @@ -0,0 +1,150 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.7.2 + + + com.datao + swadmin + 1.18.2 + swadmin + swadmin + + 1.17 + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + + org.springframework.boot + spring-boot-starter-undertow + + + + com.baomidou + mybatis-plus-boot-starter + 3.5.2 + + + org.apache.httpcomponents.client5 + httpclient5 + 5.1 + + + + + + + + + com.auth0 + java-jwt + 4.0.0 + + + + + + + + + + + com.alibaba + fastjson + 2.0.9 + + + + commons-fileupload + commons-fileupload + 1.4 + + + com.github.whvcse + easy-captcha + 1.6.2 + + + org.openjdk.nashorn + nashorn-core + 15.4 + + + mysql + mysql-connector-java + 8.0.28 + + + org.projectlombok + lombok + provided + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + + com.alipay.sdk + alipay-sdk-java + 4.34.0.ALL + + + com.github.wechatpay-apiv3 + wechatpay-java + 0.2.12 + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + ZIP + + + nothing + nothing + + + + + org.projectlombok + lombok + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 15 + 15 + + + + + + diff --git a/src/main/java/com/datao/Result/AjaxResult.java b/src/main/java/com/datao/Result/AjaxResult.java new file mode 100644 index 0000000..21c1df0 --- /dev/null +++ b/src/main/java/com/datao/Result/AjaxResult.java @@ -0,0 +1,162 @@ +package com.datao.Result; + +import org.springframework.http.HttpStatus; + +import java.util.HashMap; + +/** + * 操作消息提醒 + * + * @author ruoyi + */ +public class AjaxResult extends HashMap +{ + private static final long serialVersionUID = 1L; + + /** 状态码 */ + public static final String CODE_TAG = "code"; + + /** 返回内容 */ + public static final String MSG_TAG = "msg"; + + /** 数据对象 */ + public static final String DATA_TAG = "data"; + + /** + * 初始化一个新创建的 AjaxResult 对象,使其表示一个空消息。 + */ + public AjaxResult() + { + } + + /** + * 初始化一个新创建的 AjaxResult 对象 + * + * @param code 状态码 + * @param msg 返回内容 + */ + public AjaxResult(int code, String msg) + { + super.put(CODE_TAG, code); + super.put(MSG_TAG, msg); + } + + /** + * 初始化一个新创建的 AjaxResult 对象 + * + * @param code 状态码 + * @param msg 返回内容 + * @param data 数据对象 + */ + public AjaxResult(int code, String msg, Object data) + { + super.put(CODE_TAG, code); + super.put(MSG_TAG, msg); + if (data!=null) + { + super.put(DATA_TAG, data); + } + } + + /** + * 返回成功消息 + * + * @return 成功消息 + */ + public static AjaxResult success() + { + return AjaxResult.success("操作成功"); + } + + /** + * 返回成功数据 + * + * @return 成功消息 + */ + public static AjaxResult success(Object data) + { + return AjaxResult.success("操作成功", data); + } + + /** + * 返回成功消息 + * + * @param msg 返回内容 + * @return 成功消息 + */ + public static AjaxResult success(String msg) + { + return AjaxResult.success(msg, null); + } + + /** + * 返回成功消息 + * + * @param msg 返回内容 + * @param data 数据对象 + * @return 成功消息 + */ + public static AjaxResult success(String msg, Object data) + { + return new AjaxResult(HttpStatus.OK.value(), msg, data); + } + + /** + * 返回错误消息 + * + * @return + */ + public static AjaxResult error() + { + return AjaxResult.error("操作失败"); + } + + /** + * 返回错误消息 + * + * @param msg 返回内容 + * @return 警告消息 + */ + public static AjaxResult error(String msg) + { + return AjaxResult.error(msg, null); + } + + /** + * 返回错误消息 + * + * @param msg 返回内容 + * @param data 数据对象 + * @return 警告消息 + */ + public static AjaxResult error(String msg, Object data) + { + return new AjaxResult(HttpStatus.INTERNAL_SERVER_ERROR.value(), msg, data); + } + + /** + * 返回错误消息 + * + * @param code 状态码 + * @param msg 返回内容 + * @return 警告消息 + */ + public static AjaxResult error(int code, String msg) + { + return new AjaxResult(code, msg, null); + } + + /** + * 方便链式调用 + * + * @param key 键 + * @param value 值 + * @return 数据对象 + */ + @Override + public AjaxResult put(String key, Object value) + { + super.put(key, value); + return this; + } +} diff --git a/src/main/java/com/datao/SwadminApplication.java b/src/main/java/com/datao/SwadminApplication.java new file mode 100644 index 0000000..fdca0f3 --- /dev/null +++ b/src/main/java/com/datao/SwadminApplication.java @@ -0,0 +1,26 @@ +package com.datao; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ConfigurableApplicationContext; + +import javax.sql.DataSource; + +@SpringBootApplication +public class SwadminApplication { + + public static void main(String[] args) { + ConfigurableApplicationContext context = SpringApplication.run(SwadminApplication.class, args); + + try { + // ===== 在项目初始化bean后检验数据库连接是否 + DataSource dataSource = (DataSource) context.getBean("dataSource"); + dataSource.getConnection().close(); + } catch (Exception e) { + e.printStackTrace(); + // ===== 当检测数据库连接失败时, 停止项目启动 + System.exit(-1); +// context.close(); + } + } +} diff --git a/src/main/java/com/datao/config/AlipayUtil.java b/src/main/java/com/datao/config/AlipayUtil.java new file mode 100644 index 0000000..f0f37bd --- /dev/null +++ b/src/main/java/com/datao/config/AlipayUtil.java @@ -0,0 +1,64 @@ +package com.datao.config; + +import com.alipay.api.AlipayClient; +import com.alipay.api.AlipayConstants; +import com.alipay.api.DefaultAlipayClient; + +public class AlipayUtil { + public static final String APP_ID = "2016041901311447"; + //支付宝私钥 + private static final String APP_PRIVATE_KEY = """ + MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDKIIMWunigVf65\ + 5us9PWlMKebBlDwU8mkJHLWqSj35HWugWEq4lQkkCQOegUIHCvVGaQIyha9WpWdi\ + wxGQZTfry+VxGtA/TiFKD1K5hGQw7Wnf5yMqM/iFZGyORdWdtE1ajESrxHYqp05h\ + qqfk922qRgKtlFdHxU/52MCXhauhmvARrHHrFpe3QIXpFh5U05WyWqs2VhTGNihM\ + 83sOvu6D8uEru412cMnbe0iu5Rc+nc0Uzy+YaJEVKtDBueu8IMZmTsJenK8eizrU\ + 6gRZrgAB+bCJc4l1ZtA00/ygI6IawJf3S67fwb4+hL4fDyuhyCWU4lRGW8+mM8DP\ + tFaI9ciPAgMBAAECggEBAJ134MinM2yuMknARgoqusr0ZervwjMLe5r2u+zT9B4M\ + tplvz56ntTxWrXQh/T+hYN6e1nBnx+b362h80kUtJfjUm4aXPh/jjXm2IFuZcbjQ\ + bUhbOQEbBgVd7FiWvUokepMNbj5nSywFtcHPAwgVX2FlM5bpV2n5pUnffINPRxwZ\ + RverEmpcqZf1L5yPG8+axAh3RJdsM5PYp4D8erkD9bp0vU1Tq7hQ+MU9HHM/i9D8\ + L3kGSz/xah3l68QvI91MiyF3Qg1EMHyz4tqxq0Db63Err6s8v0Y0n8F9SCrzP2d5\ + d3Xh8MMuVNPtQnIEAG084IpK1HLy2pL9CDb47cRsyWkCgYEA7/E0ga9CFzMt6kAc\ + 2qolXbX1jopwjVFpmfdWjyrrrDgke+eC19bFP/BR7MpLEKanTY8azKKU3VInIHFy\ + uddp/ZJqrMNHV0BtaiRWqJMw5VnuQTgTo1BNJ128bfLDep6F4I103csQncu9I6/S\ + Am2GSKPRvKu1CrzOJpige0jQx9UCgYEA16dwtnrw4vKeFvsTC2LOkiQ9YC/EFKkP\ + EKPhtHuTXeaxBQ1scZgBVTr65pfz3cl3VKbIfxFM5TflSl5K72KtxGPn/2wUh0fV\ + ud+E5LM76mGSe5pBjoPyFY2i/Qyic+AA8L8vfHQwKqFo1OqfDBEJkmrsXgjQBtyX\ + 1Oi3zj9axNMCgYEA4J7FsMII9P8MdMcgO/QcluXIw3AGfcVBPsm1VsGvbsIAJZ5N\ + dxGwBnNLvoiCTUw2Qv088WUiRy6pQk3yQNfQeXmgM6t8FcpSo5LxLU7d71eJG7UL\ + bU+3aqrtw2AIb7oHSngid5+qJo6cudPWnj85/radmiqEiVDHDIrFcaRxDyECgYBW\ + TUDTFiIegH95rOKzNMh8PZp+Sr9KkVlhDGR/6NBRzMdcwUF7uBwYcrED5R2HzV8+\ + 9jvYdiDyvkq5V0DfyfrGVED8u9D/TmUerG+vYncA1ilb46CGmxEfRP5MDGlau/NE\ + ZQ5o3MqF1PBx/K7Hkm3lNXsAKsCtbkwovTUJidsWVwKBgQC9BED3+SJIKmGnP107\ + piz0hCvT/5HkfOXYgP8K0IAATW26h81k5QFEGfWHGSKqam9oB+Jz2YToh7gwuS6E\ + Zo6zc0xzYPR5QJvbZC/YYOMmfjz0F9Z7uFC2Tq+143bCkg9XlDwY8KKTxAfb80t7\ + m9zGkwDF59l1GEV9QNmh1q7jKA=="""; +// public static final String ALIPAY_PUBLIC_KEY = "***********";//这个为你在支付宝上的商户的公钥,而不是支付宝公钥 + //支付宝公钥 + public static final String ALIPAY_PUBLIC_KEY = """ + MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAi2w/yQ9QCkAeKD1mQDkN\ + tZ5GY83FQ2x+mEVmVMF1c2a4eb8btYd62WOzaCFb0Is8BP2up1B8GElTmoDEO44V\ + tuC+2elHYezSRXhiBcrnnRjZebFh+k5SG4pgIBXVsSR/2fL94p8reYadTmV18wLd\ + W7Mqi54S16WNlw+PXkg8o4bnYxvJj6K8/lhgZg5As5cfsWK4WMQ1osnlPkSUb4uj\ + ye4KB2RWkVla+cZmswu8gWA1M9ygtcjCpvTyT2oVIoFQkWIU3IO9CxVPWhF7l8nP\ + OJW2fj9qIWWISPNA4PJCeTvGwN7lwE4oASGnag0CSJxpgz8SmKKAFtOm4rB08aCG\ + 4QIDAQAB"""; + public static final String SIGNTYPE = "RSA2"; + //支付宝回调的接口 + public static final String NOTIFYURL = "http://www.ichangzuo.com/index.php/Client/alipayOrderNotify"; + public static final String SERVERURL = "https://openapi.alipay.com/gateway.do"; + private static AlipayClient alipayClient = null; + + //因为支付宝alipayClient本身是线程安全的,因此只用创建一个,创建成单例的模式 + public static AlipayClient getAlipayClient() { + synchronized (AlipayUtil.class) { + if (null == alipayClient) { + alipayClient = new DefaultAlipayClient(SERVERURL, APP_ID, APP_PRIVATE_KEY, + AlipayConstants.FORMAT_JSON, AlipayConstants.CHARSET_UTF8, + ALIPAY_PUBLIC_KEY, SIGNTYPE); + } + } + return alipayClient; + } +} diff --git a/src/main/java/com/datao/config/MpConfig.java b/src/main/java/com/datao/config/MpConfig.java new file mode 100644 index 0000000..b0ca050 --- /dev/null +++ b/src/main/java/com/datao/config/MpConfig.java @@ -0,0 +1,35 @@ +package com.datao.config; + +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; + +//import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class MpConfig { + @Bean // MP 3.5.2版格式 + public MybatisPlusInterceptor paginationInterceptor() { + MybatisPlusInterceptor mpInterceptor = new MybatisPlusInterceptor(); + mpInterceptor.addInnerInterceptor(new PaginationInnerInterceptor()); + return mpInterceptor; + } + + /** + * 逻辑删除插件 + */ +// @Bean +// public ISqlInjector sqlInjector() { +// return new LogicSqlInjector(); +// } + + /** + * 分页插件 MP 3.2.0版格式 + * @return + */ +// @Bean +// public PaginationInterceptor paginationInterceptor(){ +// return new PaginationInterceptor(); +// } +} diff --git a/src/main/java/com/datao/config/PassToken.java b/src/main/java/com/datao/config/PassToken.java new file mode 100644 index 0000000..1b8db1a --- /dev/null +++ b/src/main/java/com/datao/config/PassToken.java @@ -0,0 +1,11 @@ +package com.datao.config; + +import java.lang.annotation.*; + +@Documented +@Target({ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface PassToken { + boolean value() default true; +} + diff --git a/src/main/java/com/datao/config/TokenInterceptor.java b/src/main/java/com/datao/config/TokenInterceptor.java new file mode 100644 index 0000000..d8e9da9 --- /dev/null +++ b/src/main/java/com/datao/config/TokenInterceptor.java @@ -0,0 +1,95 @@ +package com.datao.config; + +import com.alibaba.fastjson.JSON; +import com.auth0.jwt.exceptions.AlgorithmMismatchException; +import com.auth0.jwt.exceptions.InvalidClaimException; +import com.auth0.jwt.exceptions.SignatureVerificationException; +import com.auth0.jwt.exceptions.TokenExpiredException; +import com.datao.Result.AjaxResult; +import com.datao.util.TokenUtil; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Component; +import org.springframework.web.method.HandlerMethod; +import org.springframework.web.servlet.HandlerInterceptor; +import org.springframework.web.servlet.ModelAndView; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.lang.reflect.Method; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; + +/** + * 添加拦截器 + */ +@Component +public class TokenInterceptor implements HandlerInterceptor { + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) + throws Exception { +// System.out.println(String.format("[%s]", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())) +// +" preHandle "+request.getRequestURL()); + //如果不是映射到方法直接放行 + if(!(handler instanceof HandlerMethod)){ + return true; + } + HandlerMethod handlerMethod = (HandlerMethod)handler; + Method method = handlerMethod.getMethod(); + + HashMap hashMap = new HashMap<>(); + String token = request.getHeader("Authorization"); + if((token == null || token.isEmpty()) + && method.isAnnotationPresent(PassToken.class)) { //带有PassToken注解的方法不处理 + return true; + } + + String msg = ""; + try { + if(token != null && token!="") { + TokenUtil.verifyToken(token.substring(7)); + return true; + } + else{ + msg = "token无效"; + } + }catch (SignatureVerificationException e){ +// e.printStackTrace(); + msg = "签名不一致"; + }catch (TokenExpiredException e){ +// e.printStackTrace(); + msg = "令牌过期异常"; + }catch (AlgorithmMismatchException e) { +// e.printStackTrace(); + msg = "算法不匹配异常"; + }catch (InvalidClaimException e){ +// e.printStackTrace(); + msg = "失效的claim异常"; + }catch (Exception e){ +// e.printStackTrace(); + msg = "token无效"; + } + + AjaxResult result = new AjaxResult(HttpStatus.UNAUTHORIZED.value(),msg); + + String resultJson = JSON.toJSONString(result); + response.setContentType("application/json;charset=utf-8"); + response.getWriter().print(resultJson); + return false; + } + + @Override + public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, + ModelAndView modelAndView) throws Exception { +// System.out.println("postHandle"); + HandlerInterceptor.super.postHandle(request, response, handler, modelAndView); + } + + @Override + public void afterCompletion(HttpServletRequest request, HttpServletResponse response, + Object handler, Exception ex) throws Exception { +// System.out.println("afterCompletion"); + HandlerInterceptor.super.afterCompletion(request, response, handler, ex); + } +} diff --git a/src/main/java/com/datao/config/TokenWebMvcConfigurer.java b/src/main/java/com/datao/config/TokenWebMvcConfigurer.java new file mode 100644 index 0000000..9dd7976 --- /dev/null +++ b/src/main/java/com/datao/config/TokenWebMvcConfigurer.java @@ -0,0 +1,50 @@ +package com.datao.config; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +import javax.annotation.Resource; +import java.util.ArrayList; + +//配置拦截事件 +@Configuration +public class TokenWebMvcConfigurer implements WebMvcConfigurer { + + @Autowired + private TokenInterceptor tokenInterceptor; + + /** + * 配置跨域请求 + * + * @param registry + */ + @Override + public void addCorsMappings(CorsRegistry registry) { + //定义哪些URL接受跨域 + registry.addMapping("/**") + //定义哪些origin可以跨域请求 +// .allowedOrigins("*") + .allowedOriginPatterns("*") + //定义接受的跨域请求方法 + .allowedMethods("POST", "GET", "PUT", "DELETE") + .exposedHeaders("Set-Token") + .allowCredentials(true) + .allowedHeaders("*") + .maxAge(3600); + } + + @Override + public void addInterceptors(InterceptorRegistry registry) { + ArrayList list = new ArrayList<>(); + list.add("/error"); + list.add("/Api/**"); + + registry.addInterceptor(tokenInterceptor) + .addPathPatterns("/**") + .excludePathPatterns(list); + } +} + diff --git a/src/main/java/com/datao/config/WxpayUtil.java b/src/main/java/com/datao/config/WxpayUtil.java new file mode 100644 index 0000000..03a436c --- /dev/null +++ b/src/main/java/com/datao/config/WxpayUtil.java @@ -0,0 +1,35 @@ +package com.datao.config; + +import com.wechat.pay.java.core.Config; +import com.wechat.pay.java.core.RSAAutoCertificateConfig; + +public class WxpayUtil { + /** App号 */ + public static String appId = "wx8f83a7f750d63431"; + /** 商户号 */ + public static String merchantId = "1266239101"; + /** 商户API私钥路径 */ + public static String privateKeyPath = "/opt/datao/ssl/apiclient_key.pem"; //"F:/唱作网工作交接/Wxpay/apiclient_key.pem"; + /** 商户证书序列号 */ + public static String merchantSerialNumber = "18650196CADB6AB05753AFF90B5C60EBFDDB9858"; + /** 商户APIV3密钥 */ + public static String apiV3Key = "aS1yC4sS3xM8hI3oF1qD2uZ7kH8mO3uB"; + //回调地址 + public static final String NOTIFYURL = "http://www.ichangzuo.com/index.php/Client/wxpayOrderNotify"; + //Wxpayconfig + private static Config wxpayConfig = null; + + public static Config getWxpayConfig() { + synchronized (AlipayUtil.class) { + if (null == wxpayConfig) { + wxpayConfig = new RSAAutoCertificateConfig.Builder() + .merchantId(merchantId) + .privateKeyFromPath(privateKeyPath) + .merchantSerialNumber(merchantSerialNumber) + .apiV3Key(apiV3Key) + .build(); + } + } + return wxpayConfig; + } +} diff --git a/src/main/java/com/datao/controller/AdminController.java b/src/main/java/com/datao/controller/AdminController.java new file mode 100644 index 0000000..5274e57 --- /dev/null +++ b/src/main/java/com/datao/controller/AdminController.java @@ -0,0 +1,65 @@ +package com.datao.controller; + +import com.datao.Result.AjaxResult; +import com.datao.config.PassToken; +import com.datao.controller.dto.PwdDto; +import com.datao.controller.dto.LoginDto; +import com.datao.service.LoginService; +import com.datao.util.CaptchaUtil; +import com.datao.util.TokenUtil; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; + +import java.util.HashMap; +import java.util.UUID; + +@RestController +@RequestMapping("/admin") +public class AdminController { +// @Autowired + final private LoginService loginService; + + public AdminController(LoginService loginService) { + this.loginService = loginService; + } + + @GetMapping("/captcha") + @PassToken + public AjaxResult captcha(){ + String uuid = UUID.randomUUID().toString(); + + AjaxResult ajax = AjaxResult.success(); + ajax.put("uuid", uuid); + ajax.put("img", CaptchaUtil.getCaptcha(uuid)); + + return ajax; + } + + @PostMapping("/login") + @PassToken + public AjaxResult login(@RequestBody LoginDto dto){ + if( !CaptchaUtil.verifyCaptcha(dto.getUuid(), dto.getCode())) { + return AjaxResult.error(HttpStatus.NOT_ACCEPTABLE.value(), "登录失败!验证码不正确。"); + } + + if (loginService.login(dto)) { + HashMap claim = new HashMap(); + claim.put("name", dto.getUsername()); + String token = TokenUtil.createToken(claim); + + return AjaxResult.success().put("token", token); + } + + return AjaxResult.error(HttpStatus.NOT_ACCEPTABLE.value(), "登录失败!账号或者密码不正确。"); + } + + @PutMapping("/password") + public AjaxResult password(@RequestBody PwdDto dto) { + if(loginService.updatePassword(dto.getUsername(), dto.getPassword(), dto.getNewPassword())) { + return AjaxResult.success("操作成功"); + } + else { + return AjaxResult.error("操作失败"); + } + } +} diff --git a/src/main/java/com/datao/controller/ApiController.java b/src/main/java/com/datao/controller/ApiController.java new file mode 100644 index 0000000..ab2064f --- /dev/null +++ b/src/main/java/com/datao/controller/ApiController.java @@ -0,0 +1,136 @@ +package com.datao.controller; + +import com.datao.Result.AjaxResult; +import com.datao.config.PassToken; +import com.datao.service.ApiService; +import com.datao.util.ParamDecoder; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +@RestController +@RequestMapping("/Api") +public class ApiController { + @Autowired + private ParamDecoder decoder; + + @Autowired + private ApiService apiService; + + @GetMapping("/chkServer") + public String chkServer(){ + return "ok"; + } + + @GetMapping("/getUpgradeUrl") + public String getUpgradeUrl(@RequestParam Integer sid){ + return apiService.getUpgradePath(sid); + } + + @PostMapping("/verifyAppleReceipt") + public AjaxResult verifyAppleReceipt(@RequestBody String param) { +// System.out.println(param); + return apiService.verifyAppleReceipt(param, false); + } + +// @PostMapping("/getOrderInfo") +// public AjaxResult getOrderInfo(@RequestParam String user, @RequestParam String password, @RequestParam String money) { +// String order = "20240609-ali_ad-328577-230635"; +// return apiService.getAlipayInfo(money, order); +// } + @PostMapping("/getPrepayInfo") + public AjaxResult getPrepayInfo(@RequestParam String order, @RequestParam String money, @RequestParam String type) { + System.out.println("getPrepayInfo: " + order + " " + money + " " + type); + if(Objects.equals(type, "ali_ad")) + return apiService.getAliPayInfo(money, order); + else if(Objects.equals(type, "wx_ad")) + return apiService.getWxPayInfo(money, order); + + return AjaxResult.error("无效的支付类型参数"); + } + +// @PostMapping("/getAlipaySign") +// public AjaxResult getAlipaySign(@RequestParam String order, @RequestParam String money) { +// System.out.println("getAlipaySign: " + order + " " + money); +// return apiService.getAliPayInfo(money, order); +// } + + @PostMapping("/notifyAlipayOrder") + public AjaxResult notifyAlipayOrder(HttpServletRequest request) { + return apiService.handleAlipayNotify(request); + } + + @PostMapping("/notifyWxpayOrder") + public AjaxResult notifyWxpayOrder(HttpServletRequest request) { + return apiService.handleWxpayNotify(request); + } + + @PostMapping + public String handleApiRequest(@RequestBody String param) { + HashMap map = decoder.Decode(param); + + if(map==null || map.isEmpty() || !map.containsKey("op")) return "err:103"; + + String op = map.get("op"); + switch (op) { + case "getInfo": { + Integer sid = Integer.parseInt(map.get("sid")); + Integer ver = Integer.parseInt(map.get("ver")); + + System.out.println(String.format("[%s]", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())) + + map.toString()); + + return apiService.getInfo(sid, ver); + } + case "userLogin": { + String uname = map.get("un").trim().toLowerCase(); + Integer sid = Integer.parseInt(map.get("sid")); + String web = map.get("web"); + + System.out.println(String.format("[%s]", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())) + + map.toString()); + + return apiService.userLogin(uname, sid, web); + } + case "setSlpAmo": { +// return "err:102"; + Integer srv = Integer.parseInt(map.get("srv")); + Integer tim = Integer.parseInt(map.get("tim")); + Integer amo = Integer.parseInt(map.get("amo")); + Integer ver = Integer.parseInt(map.get("ver")); + + return apiService.setSlpAmo(srv, tim, amo, ver); + } + case "chkSlp": + return apiService.chkSlp(); + case "getWebsite": { + Integer sid = Integer.parseInt(map.get("sid")); + String web = map.get("web"); + + return apiService.getWebsite(sid, web); + } + case "userRegister": { + Integer sid = Integer.parseInt(map.get("sid")); + String uname = map.get("un").trim().toLowerCase(); + String web = map.get("web"); + + System.out.println(String.format("[%s]", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())) + + map.toString()); + + return apiService.userRegister(uname, sid, web); + } + case "predMatches": { + Integer sid = Integer.parseInt(map.get("sid")); + return apiService.getPredMatches(sid); + } + } + + return "err:101"; + } +} diff --git a/src/main/java/com/datao/controller/MessageController.java b/src/main/java/com/datao/controller/MessageController.java new file mode 100644 index 0000000..7c108b6 --- /dev/null +++ b/src/main/java/com/datao/controller/MessageController.java @@ -0,0 +1,53 @@ +package com.datao.controller; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.datao.Result.AjaxResult; +import com.datao.controller.dto.MsgDto; +import com.datao.domain.Msg; +import com.datao.service.MsgService; +import com.datao.util.page.BasePage; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("admin/message") +public class MessageController { +// @Autowired + final private MsgService msgService; + + public MessageController(MsgService msgService) { + this.msgService = msgService; + } + + @PostMapping("/page") + public AjaxResult pageList(@RequestBody BasePage dto){ + IPage page = msgService.pageList(dto); + + AjaxResult ajax = AjaxResult.success(); + ajax.put("data", page); + + return ajax; + } + + @PutMapping + public AjaxResult update(@RequestBody MsgDto dto){ + Integer id = msgService.update(dto); + if( id > 0 ) { + AjaxResult ajax = AjaxResult.success(); + ajax.put("data", id); + return ajax; + } + else { + return AjaxResult.error("操作失败"); + } + } + + @DeleteMapping("/{id}") + public AjaxResult delete(@PathVariable Integer id){ + if(msgService.setHide(id)) { + return AjaxResult.success("操作成功"); + } + else { + return AjaxResult.error("操作失败"); + } + } +} diff --git a/src/main/java/com/datao/controller/MsgerController.java b/src/main/java/com/datao/controller/MsgerController.java new file mode 100644 index 0000000..173670d --- /dev/null +++ b/src/main/java/com/datao/controller/MsgerController.java @@ -0,0 +1,77 @@ +package com.datao.controller; + +import com.datao.Result.AjaxResult; +import com.datao.config.PassToken; +import com.datao.controller.dto.LoginDto; +import com.datao.controller.dto.MsgDto; +import com.datao.controller.dto.MsgListDto; +import com.datao.controller.dto.PwdDto; +import com.datao.domain.vo.MsgVo; +import com.datao.service.MsgService; +import com.datao.util.TokenUtil; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; + +import java.util.HashMap; +import java.util.List; + +@RestController +@RequestMapping("/msger") +public class MsgerController { +// @Autowired + final private MsgService msgService; + + public MsgerController(MsgService msgService) { + this.msgService = msgService; + } + + @PostMapping("/login") + @PassToken + public AjaxResult login(@RequestBody LoginDto dto){ + Integer uid = msgService.login(dto); + if (uid > 0) { + HashMap claim = new HashMap(); + claim.put("name", dto.getUsername()); + String token = TokenUtil.createToken(claim); + + return AjaxResult.success() + .put("uid", uid) + .put("token", token); + } + + return AjaxResult.error(HttpStatus.NOT_ACCEPTABLE.value(), "登录失败!账号或者密码不正确。"); + } + + @PutMapping("/password") + public AjaxResult password(@RequestBody PwdDto dto) { + if(msgService.updatePassword(dto.getUsername().trim(), dto.getPassword(), dto.getNewPassword())) { + return AjaxResult.success("操作成功"); + } + else { + return AjaxResult.error("操作失败"); + } + } + + @PostMapping("/list") + public AjaxResult getList(@RequestBody MsgListDto dto){ + List lst = msgService.getList(dto); + + AjaxResult ajax = AjaxResult.success(); + ajax.put("data", lst); + + return ajax; + } + + @PostMapping("/send") + public AjaxResult send(@RequestBody MsgDto dto){ + Integer id = msgService.update(dto); + if( id > 0 ) { + AjaxResult ajax = AjaxResult.success(); + ajax.put("data", id); + return ajax; + } + else { + return AjaxResult.error("操作失败"); + } + } +} diff --git a/src/main/java/com/datao/controller/ServerController.java b/src/main/java/com/datao/controller/ServerController.java new file mode 100644 index 0000000..729dbb9 --- /dev/null +++ b/src/main/java/com/datao/controller/ServerController.java @@ -0,0 +1,47 @@ +package com.datao.controller; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.datao.Result.AjaxResult; +import com.datao.domain.Server; +import com.datao.service.ServerService; +import com.datao.util.page.BasePage; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("admin/server") +public class ServerController { + @Autowired + ServerService serverService; + + @PostMapping("/page") + public AjaxResult pageList(@RequestBody BasePage dto){ + IPage swPage = serverService.page(new Page(dto.getPageNum(),dto.getPageSize())); // .pageList(dto); + + AjaxResult ajax = AjaxResult.success(); + ajax.put("data", swPage); + + return ajax; + } + + @PutMapping + public AjaxResult update(@RequestBody Server dto){ + if( serverService.saveOrUpdate(dto)){// .update(dto) ) { + return AjaxResult.success("操作成功"); + } + else { + return AjaxResult.error("操作失败"); + } + } + + @DeleteMapping("/{sid}") + public AjaxResult delete(@PathVariable Integer sid){ + if(serverService.removeById(sid)){//.delete(sid)) { + return AjaxResult.success("操作成功"); + } + else { + return AjaxResult.error("操作失败"); + } + } +} diff --git a/src/main/java/com/datao/controller/SlpController.java b/src/main/java/com/datao/controller/SlpController.java new file mode 100644 index 0000000..27125fa --- /dev/null +++ b/src/main/java/com/datao/controller/SlpController.java @@ -0,0 +1,43 @@ +package com.datao.controller; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.datao.Result.AjaxResult; +import com.datao.controller.dto.SlpPageDto; +import com.datao.domain.vo.SlpVo; +import com.datao.service.SlpService; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; + +import static com.datao.Result.AjaxResult.DATA_TAG; + +@RestController +@RequestMapping("/admin/slp") +public class SlpController { +// @Autowired + final private SlpService slpService; + + public SlpController(SlpService slpService) { + this.slpService = slpService; + } + + @PostMapping("/page") + public AjaxResult pageList(@RequestBody SlpPageDto dto){ + IPage page = slpService.pageList(dto); + + AjaxResult ajax = AjaxResult.success(); + ajax.put(DATA_TAG, page); + + return ajax; + } + + @PostMapping("/sum") + public AjaxResult sumList(@RequestBody(required=false) String mon){ + Map data = slpService.sumList(mon); + + AjaxResult ajax = AjaxResult.success(); + ajax.put(DATA_TAG, data); + + return ajax; + } +} diff --git a/src/main/java/com/datao/controller/SoftwareController.java b/src/main/java/com/datao/controller/SoftwareController.java new file mode 100644 index 0000000..5407bb7 --- /dev/null +++ b/src/main/java/com/datao/controller/SoftwareController.java @@ -0,0 +1,51 @@ +package com.datao.controller; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.datao.Result.AjaxResult; +import com.datao.domain.Software; +import com.datao.service.SoftwareService; +import com.datao.util.page.BasePage; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/admin/software") +public class SoftwareController { +// @Autowired + private final SoftwareService softwareService; + +// @Autowired + public SoftwareController(SoftwareService softwareService) { + this.softwareService = softwareService; + } + + @PostMapping("/page") + public AjaxResult pageList(@RequestBody BasePage dto){ + IPage swPage = softwareService.page(new Page<>(dto.getPageNum(),dto.getPageSize())); // .pageList(dto); + + AjaxResult ajax = AjaxResult.success(); + ajax.put("data", swPage); + + return ajax; + } + + @PutMapping + public AjaxResult update(@RequestBody Software dto){ + if( softwareService.saveOrUpdate(dto) ){ //.update(dto) ) { + return AjaxResult.success("操作成功"); + } + else { + return AjaxResult.error("操作失败"); + } + } + + @DeleteMapping("/{sid}") + public AjaxResult deprecated(@PathVariable Integer sid){ + if(softwareService.deprecated(sid)) { + return AjaxResult.success("操作成功"); + } + else { + return AjaxResult.error("操作失败"); + } + } +} diff --git a/src/main/java/com/datao/controller/SwMemberController.java b/src/main/java/com/datao/controller/SwMemberController.java new file mode 100644 index 0000000..b54f21e --- /dev/null +++ b/src/main/java/com/datao/controller/SwMemberController.java @@ -0,0 +1,50 @@ +package com.datao.controller; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.datao.Result.AjaxResult; +import com.datao.controller.dto.MemberDto; +import com.datao.controller.dto.MemberPageDto; +import com.datao.domain.vo.MemberVo; +import com.datao.service.MemberService; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/admin/swmember") +public class SwMemberController { +// @Autowired + final private MemberService memberService; + + public SwMemberController(MemberService memberService) { + this.memberService = memberService; + } + + @PostMapping("/page") + public AjaxResult pageList(@RequestBody MemberPageDto dto){ + IPage memberIPage = memberService.pageList(dto); + + AjaxResult ajax = AjaxResult.success(); + ajax.put("data", memberIPage); + + return ajax; + } + + @PutMapping + public AjaxResult update(@RequestBody MemberDto dto){ + if( memberService.update(dto) ) { + return AjaxResult.success("操作成功"); + } + else { + return AjaxResult.error("操作失败"); + } + } + + @DeleteMapping("/{id}") + public AjaxResult remove(@PathVariable Integer id){ + if(memberService.removeById(id)){// .remove(id)) { + return AjaxResult.success("操作成功"); + } + else { + return AjaxResult.error("操作失败"); + } + } +} diff --git a/src/main/java/com/datao/controller/UploadController.java b/src/main/java/com/datao/controller/UploadController.java new file mode 100644 index 0000000..8174232 --- /dev/null +++ b/src/main/java/com/datao/controller/UploadController.java @@ -0,0 +1,63 @@ +package com.datao.controller; + +import com.datao.Result.AjaxResult; +import com.datao.config.PassToken; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import java.io.File; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Date; + +@RestController +@RequestMapping("/upload") +public class UploadController { + @Autowired + private Environment env; + + @PostMapping + public AjaxResult upload(MultipartFile file){ + if (file == null) return AjaxResult.error("文件获取失败"); + + String originalName = file.getOriginalFilename(); + if( originalName==null || originalName=="") return AjaxResult.error("文件获取失败"); + + StringBuilder url = new StringBuilder("/upload/");//返回值封装 + try { + String uploadPath = env.getProperty("spring.servlet.multipart.location"); +// String[] strArray = originalName.split("\\."); + int pos = originalName.lastIndexOf("."); + String prefix = originalName.substring(0, pos), + suffix = originalName.substring(pos+1); + + File dir = new File(uploadPath); + if (!dir.exists()) { + dir.mkdirs(); + } + + Integer num = Integer.valueOf(1); + String newName = originalName; + File targetFile = new File(dir, originalName); + while( targetFile.exists() ){ + newName = prefix + "(" + num + ")."+ suffix; + targetFile = new File(dir, newName); + num++; + } + + file.transferTo(targetFile); + url.append(newName); + } catch (IOException e) { + e.printStackTrace(); + return AjaxResult.error("文件保存失败"); + } + + AjaxResult ajax = AjaxResult.success(); + ajax.put("data", url); + + return ajax; + } +} + diff --git a/src/main/java/com/datao/controller/WebsiteController.java b/src/main/java/com/datao/controller/WebsiteController.java new file mode 100644 index 0000000..274d75c --- /dev/null +++ b/src/main/java/com/datao/controller/WebsiteController.java @@ -0,0 +1,53 @@ +package com.datao.controller; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.datao.Result.AjaxResult; +import com.datao.domain.Website; +import com.datao.service.WebsiteService; +import com.datao.util.page.BasePage; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/admin/website") +public class WebsiteController { + + // @Autowired + private final WebsiteService websiteService; + + // @Autowired + public WebsiteController(WebsiteService websiteService) { + this.websiteService = websiteService; + } + + @PostMapping("/page") + public AjaxResult pageList(@RequestBody BasePage dto){ + IPage swPage = websiteService.page(new Page(dto.getPageNum(),dto.getPageSize())); // .pageList(dto); + + AjaxResult ajax = AjaxResult.success(); + ajax.put("data", swPage); + + return ajax; + } + + @PutMapping + public AjaxResult update(@RequestBody Website dto){ + if( websiteService.saveOrUpdate(dto) ){ //.update(dto) ) { + return AjaxResult.success("操作成功"); + } + else { + return AjaxResult.error("操作失败"); + } + } + + @DeleteMapping("/{id}") + public AjaxResult deprecated(@PathVariable Integer id){ + if(websiteService.deprecated(id)) { + return AjaxResult.success("操作成功"); + } + else { + return AjaxResult.error("操作失败"); + } + } + +} diff --git a/src/main/java/com/datao/controller/dto/LoginDto.java b/src/main/java/com/datao/controller/dto/LoginDto.java new file mode 100644 index 0000000..c3087ab --- /dev/null +++ b/src/main/java/com/datao/controller/dto/LoginDto.java @@ -0,0 +1,11 @@ +package com.datao.controller.dto; + +import lombok.Data; + +@Data +public class LoginDto { + private String username; + private String password; + private String uuid; + private String code; +} diff --git a/src/main/java/com/datao/controller/dto/MemberDto.java b/src/main/java/com/datao/controller/dto/MemberDto.java new file mode 100644 index 0000000..02d5191 --- /dev/null +++ b/src/main/java/com/datao/controller/dto/MemberDto.java @@ -0,0 +1,16 @@ +package com.datao.controller.dto; + +import lombok.Data; + +import java.util.Date; + +@Data +public class MemberDto { + private Integer id; +// private Integer sid; + private String web; + private String swids; + private String uname; + private Date exptime; + private String comment; +} diff --git a/src/main/java/com/datao/controller/dto/MemberPageDto.java b/src/main/java/com/datao/controller/dto/MemberPageDto.java new file mode 100644 index 0000000..60c692e --- /dev/null +++ b/src/main/java/com/datao/controller/dto/MemberPageDto.java @@ -0,0 +1,11 @@ +package com.datao.controller.dto; + +import com.datao.util.page.BasePage; +import lombok.Data; + +@Data +public class MemberPageDto extends BasePage { + private String swids; + private String sortBy; + private String orderBy; +} diff --git a/src/main/java/com/datao/controller/dto/MsgDto.java b/src/main/java/com/datao/controller/dto/MsgDto.java new file mode 100644 index 0000000..89c78bc --- /dev/null +++ b/src/main/java/com/datao/controller/dto/MsgDto.java @@ -0,0 +1,15 @@ +package com.datao.controller.dto; + +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +@Data +public class MsgDto { + private Integer id; + + private Integer sendid; + private Integer sendtime; + + private String content; + private String attach; +} diff --git a/src/main/java/com/datao/controller/dto/MsgListDto.java b/src/main/java/com/datao/controller/dto/MsgListDto.java new file mode 100644 index 0000000..cc18123 --- /dev/null +++ b/src/main/java/com/datao/controller/dto/MsgListDto.java @@ -0,0 +1,9 @@ +package com.datao.controller.dto; + +import lombok.Data; + +@Data +public class MsgListDto { + private Integer recvid; + private Integer mintime; +} diff --git a/src/main/java/com/datao/controller/dto/PwdDto.java b/src/main/java/com/datao/controller/dto/PwdDto.java new file mode 100644 index 0000000..87371ea --- /dev/null +++ b/src/main/java/com/datao/controller/dto/PwdDto.java @@ -0,0 +1,16 @@ +package com.datao.controller.dto; + +import lombok.Data; +import org.springframework.lang.NonNull; + +import java.io.Serializable; + +@Data +public class PwdDto implements Serializable { + @NonNull + private String username; + @NonNull + private String password; + @NonNull + private String newPassword; +} diff --git a/src/main/java/com/datao/controller/dto/SlpPageDto.java b/src/main/java/com/datao/controller/dto/SlpPageDto.java new file mode 100644 index 0000000..5008a58 --- /dev/null +++ b/src/main/java/com/datao/controller/dto/SlpPageDto.java @@ -0,0 +1,15 @@ +package com.datao.controller.dto; + +import com.datao.util.page.BasePage; +import lombok.Data; + +import java.util.Date; + +@Data +public class SlpPageDto extends BasePage { + private Date startDate; + private Date endDate; + private String sortBy; + private String orderBy; + private Integer isrv; +} diff --git a/src/main/java/com/datao/dao/AdminDao.java b/src/main/java/com/datao/dao/AdminDao.java new file mode 100644 index 0000000..6963e0c --- /dev/null +++ b/src/main/java/com/datao/dao/AdminDao.java @@ -0,0 +1,9 @@ +package com.datao.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.datao.domain.Admin; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface AdminDao extends BaseMapper { +} diff --git a/src/main/java/com/datao/dao/MemberDao.java b/src/main/java/com/datao/dao/MemberDao.java new file mode 100644 index 0000000..bc985ae --- /dev/null +++ b/src/main/java/com/datao/dao/MemberDao.java @@ -0,0 +1,10 @@ +package com.datao.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.datao.domain.Member; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface MemberDao extends BaseMapper { + +} diff --git a/src/main/java/com/datao/dao/MsgDao.java b/src/main/java/com/datao/dao/MsgDao.java new file mode 100644 index 0000000..e22e9d7 --- /dev/null +++ b/src/main/java/com/datao/dao/MsgDao.java @@ -0,0 +1,9 @@ +package com.datao.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.datao.domain.Msg; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface MsgDao extends BaseMapper { +} diff --git a/src/main/java/com/datao/dao/MsguserDao.java b/src/main/java/com/datao/dao/MsguserDao.java new file mode 100644 index 0000000..57b42ac --- /dev/null +++ b/src/main/java/com/datao/dao/MsguserDao.java @@ -0,0 +1,9 @@ +package com.datao.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.datao.domain.Msguser; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface MsguserDao extends BaseMapper { +} diff --git a/src/main/java/com/datao/dao/ServerDao.java b/src/main/java/com/datao/dao/ServerDao.java new file mode 100644 index 0000000..e8c3439 --- /dev/null +++ b/src/main/java/com/datao/dao/ServerDao.java @@ -0,0 +1,9 @@ +package com.datao.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.datao.domain.Server; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface ServerDao extends BaseMapper { +} diff --git a/src/main/java/com/datao/dao/SlpDao.java b/src/main/java/com/datao/dao/SlpDao.java new file mode 100644 index 0000000..ac93185 --- /dev/null +++ b/src/main/java/com/datao/dao/SlpDao.java @@ -0,0 +1,9 @@ +package com.datao.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.datao.domain.Slp; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface SlpDao extends BaseMapper { +} diff --git a/src/main/java/com/datao/dao/SoftwareDao.java b/src/main/java/com/datao/dao/SoftwareDao.java new file mode 100644 index 0000000..be9b33c --- /dev/null +++ b/src/main/java/com/datao/dao/SoftwareDao.java @@ -0,0 +1,9 @@ +package com.datao.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.datao.domain.Software; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface SoftwareDao extends BaseMapper { +} diff --git a/src/main/java/com/datao/dao/SummaryDao.java b/src/main/java/com/datao/dao/SummaryDao.java new file mode 100644 index 0000000..f865bb0 --- /dev/null +++ b/src/main/java/com/datao/dao/SummaryDao.java @@ -0,0 +1,9 @@ +package com.datao.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.datao.domain.Summary; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface SummaryDao extends BaseMapper { +} diff --git a/src/main/java/com/datao/dao/WebsiteDao.java b/src/main/java/com/datao/dao/WebsiteDao.java new file mode 100644 index 0000000..387fc34 --- /dev/null +++ b/src/main/java/com/datao/dao/WebsiteDao.java @@ -0,0 +1,9 @@ +package com.datao.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.datao.domain.Website; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface WebsiteDao extends BaseMapper { +} diff --git a/src/main/java/com/datao/domain/Admin.java b/src/main/java/com/datao/domain/Admin.java new file mode 100644 index 0000000..0004939 --- /dev/null +++ b/src/main/java/com/datao/domain/Admin.java @@ -0,0 +1,19 @@ +package com.datao.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableLogic; +import lombok.Data; + +@Data +public class Admin { + @TableId(type = IdType.AUTO) + private Integer id; + private String username; + private String password; + private String salt; + + @TableLogic + private Integer deleted; +} diff --git a/src/main/java/com/datao/domain/Member.java b/src/main/java/com/datao/domain/Member.java new file mode 100644 index 0000000..285a096 --- /dev/null +++ b/src/main/java/com/datao/domain/Member.java @@ -0,0 +1,23 @@ +package com.datao.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableLogic; +import lombok.Data; + +@Data +public class Member { + @TableId(type = IdType.AUTO) + private Integer id; +// private Integer sid; + private String web; + private String swids; + private String uname; + private Integer addtime; + private Integer logcount; + private Integer logtime; + private Integer exptime; + private String comment; + @TableLogic + private Integer deleted; +} diff --git a/src/main/java/com/datao/domain/Msg.java b/src/main/java/com/datao/domain/Msg.java new file mode 100644 index 0000000..cbfe267 --- /dev/null +++ b/src/main/java/com/datao/domain/Msg.java @@ -0,0 +1,21 @@ +package com.datao.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +@Data +public class Msg { + @TableId(type = IdType.AUTO) + private Integer id; + + private Integer sendid; + private Integer recvid; + private Integer sendtime; + private Integer readtime; + + private String content; + private String attach; + + private Integer hidden; +} diff --git a/src/main/java/com/datao/domain/Msguser.java b/src/main/java/com/datao/domain/Msguser.java new file mode 100644 index 0000000..e46693b --- /dev/null +++ b/src/main/java/com/datao/domain/Msguser.java @@ -0,0 +1,20 @@ +package com.datao.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableLogic; +import lombok.Data; + +@Data +public class Msguser { + @TableId(type = IdType.AUTO) + private Integer id; + private String uname; + private String password; + + private Integer logcount; + private Integer logtime; + + @TableLogic + private Integer deleted; +} diff --git a/src/main/java/com/datao/domain/Server.java b/src/main/java/com/datao/domain/Server.java new file mode 100644 index 0000000..d7a76c9 --- /dev/null +++ b/src/main/java/com/datao/domain/Server.java @@ -0,0 +1,15 @@ +package com.datao.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +@Data +public class Server { + @TableId(type = IdType.AUTO) + private Integer id; + + private String iport; + private String swid; + private Integer priority; +} diff --git a/src/main/java/com/datao/domain/Slp.java b/src/main/java/com/datao/domain/Slp.java new file mode 100644 index 0000000..329ea38 --- /dev/null +++ b/src/main/java/com/datao/domain/Slp.java @@ -0,0 +1,18 @@ +package com.datao.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +@Data +public class Slp { + @TableId(type = IdType.AUTO) + private Integer id; + + private Integer isrv; + private Integer regtime; + private Integer logtime; + private Integer amount; + private Integer swver; +} diff --git a/src/main/java/com/datao/domain/Software.java b/src/main/java/com/datao/domain/Software.java new file mode 100644 index 0000000..e9bb70a --- /dev/null +++ b/src/main/java/com/datao/domain/Software.java @@ -0,0 +1,18 @@ +package com.datao.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableLogic; +import lombok.Data; + +@Data +public class Software { + @TableId(type = IdType.AUTO) + private Integer sid; + + private String sname; + private Integer verLatest; + private Integer verValid; + private String upgradePath; + private Integer deprecated; +} diff --git a/src/main/java/com/datao/domain/Summary.java b/src/main/java/com/datao/domain/Summary.java new file mode 100644 index 0000000..238eee0 --- /dev/null +++ b/src/main/java/com/datao/domain/Summary.java @@ -0,0 +1,19 @@ +package com.datao.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +@Data +public class Summary { + @TableId(type = IdType.INPUT) + private Integer dt; + + private int ps1; + private int ps2; + private int ps3; + private int rs0; + private int rs1; + private int rs2; + private int rs3; +} diff --git a/src/main/java/com/datao/domain/Website.java b/src/main/java/com/datao/domain/Website.java new file mode 100644 index 0000000..0d771ca --- /dev/null +++ b/src/main/java/com/datao/domain/Website.java @@ -0,0 +1,15 @@ +package com.datao.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Data; + +@Data +public class Website { + @TableId(type = IdType.AUTO) + private Integer id; + private Integer sid; + private String web; + private String website; + private Integer deprecated; +} diff --git a/src/main/java/com/datao/domain/vo/MemberVo.java b/src/main/java/com/datao/domain/vo/MemberVo.java new file mode 100644 index 0000000..e23c346 --- /dev/null +++ b/src/main/java/com/datao/domain/vo/MemberVo.java @@ -0,0 +1,19 @@ +package com.datao.domain.vo; + +import lombok.Data; + +import java.util.Date; + +@Data +public class MemberVo { + private Integer id; +// private Integer sid; + private String web; + private String swids; + private String uname; + private Date addtime; + private Integer logcount; + private Date logtime; + private Date exptime; + private String comment; +} diff --git a/src/main/java/com/datao/domain/vo/MsgVo.java b/src/main/java/com/datao/domain/vo/MsgVo.java new file mode 100644 index 0000000..980e07d --- /dev/null +++ b/src/main/java/com/datao/domain/vo/MsgVo.java @@ -0,0 +1,16 @@ +package com.datao.domain.vo; + +import lombok.Data; + +@Data +public class MsgVo { + private Integer id; + + private Integer sendid; + private String sendname; + private Integer sendtime; + private Integer readtime; + + private String content; + private String attach; +} diff --git a/src/main/java/com/datao/domain/vo/SlpSumVo.java b/src/main/java/com/datao/domain/vo/SlpSumVo.java new file mode 100644 index 0000000..5aa1579 --- /dev/null +++ b/src/main/java/com/datao/domain/vo/SlpSumVo.java @@ -0,0 +1,20 @@ +package com.datao.domain.vo; + +import lombok.Data; + +import java.util.List; + +@Data +public class SlpSumVo { + private Integer dt; + + private int ps1; + private int ps2; + private int ps3; + private int psum; + private int rs0; + private int rs1; + private int rs2; + private int rs3; + private int rsum; +} diff --git a/src/main/java/com/datao/domain/vo/SlpVo.java b/src/main/java/com/datao/domain/vo/SlpVo.java new file mode 100644 index 0000000..e2e032f --- /dev/null +++ b/src/main/java/com/datao/domain/vo/SlpVo.java @@ -0,0 +1,15 @@ +package com.datao.domain.vo; + +import lombok.Data; + +import java.util.Date; + +@Data +public class SlpVo { + private Integer id; + private Integer isrv; + private Date regtime; + private Date logtime; + private Integer amount; + private Integer swver; +} diff --git a/src/main/java/com/datao/service/ApiService.java b/src/main/java/com/datao/service/ApiService.java new file mode 100644 index 0000000..f968096 --- /dev/null +++ b/src/main/java/com/datao/service/ApiService.java @@ -0,0 +1,541 @@ +package com.datao.service; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alipay.api.AlipayApiException; +import com.alipay.api.AlipayConstants; +import com.alipay.api.domain.AlipayTradeAppPayModel; +import com.alipay.api.internal.util.AlipaySignature; +import com.alipay.api.request.AlipayTradeAppPayRequest; +import com.alipay.api.response.AlipayTradeAppPayResponse; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.datao.Result.AjaxResult; +import com.datao.config.AlipayUtil; +import com.datao.config.WxpayUtil; +import com.datao.dao.*; +import com.datao.domain.*; +//import com.datao.service.alipay.Base64; +//import com.datao.service.alipay.SignUtils; + +import com.wechat.pay.java.core.exception.ValidationException; +import com.wechat.pay.java.core.notification.NotificationConfig; +import com.wechat.pay.java.core.notification.NotificationParser; +import com.wechat.pay.java.core.notification.RequestParam; +import com.wechat.pay.java.service.payments.app.AppServiceExtension; +import com.wechat.pay.java.service.payments.model.Transaction; +import com.wechat.pay.java.service.payments.nativepay.NativePayService; +import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension; +import com.wechat.pay.java.service.payments.app.model.PrepayWithRequestPaymentResponse; +import com.wechat.pay.java.service.payments.app.model.PrepayRequest; +import com.wechat.pay.java.service.payments.app.model.Amount; +//import com.wechat.pay.java.service.payments.nativepay.model.PrepayResponse; + +import org.apache.hc.client5.http.classic.methods.HttpGet; +import org.apache.hc.client5.http.classic.methods.HttpPost; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; +import org.apache.hc.client5.http.impl.classic.HttpClients; +import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder; +import org.apache.hc.client5.http.io.HttpClientConnectionManager; +import org.apache.hc.client5.http.ssl.NoopHostnameVerifier; +import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory; +import org.apache.hc.core5.http.HttpEntity; +import org.apache.hc.core5.http.ParseException; +import org.apache.hc.core5.http.io.entity.EntityUtils; +import org.apache.hc.core5.http.io.entity.StringEntity; +import org.apache.hc.core5.ssl.SSLContexts; +import org.apache.hc.core5.ssl.TrustStrategy; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Service; + +import javax.net.ssl.SSLContext; +import javax.servlet.http.HttpServletRequest; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; +import java.security.*; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.*; + +//@Setter +@Service +public class ApiService { + @Autowired + private SoftwareDao softwareDao; + @Autowired + private ServerDao serverDao; + @Autowired + private MemberDao memberDao; + @Autowired + private SlpDao slpDao; + @Autowired + private SummaryDao summaryDao; + @Autowired + private WebsiteDao websiteDao; + + public String getUpgradePath(int sid){ + LambdaQueryWrapper swWrapper = new LambdaQueryWrapper<>(); + swWrapper.eq(Software::getSid,sid) + .eq(Software::getDeprecated,0); + Software software = softwareDao.selectOne(swWrapper); + if(software == null) return "err:101"; + + return "url:" + software.getUpgradePath(); + } + public String chkSlp() { + LambdaQueryWrapper swWrapper = new LambdaQueryWrapper<>(); + swWrapper.eq(Software::getSid, 9); + Software software = softwareDao.selectOne(swWrapper); + + StringBuffer sb = new StringBuffer(); + + //最新版本号为当前版本号 + //有效版本号为0 = 暂停使用(H) + //逻辑删除 = 停止使用(L) + if(software == null || software.getDeprecated()!=0){ + sb.append("L"); + } + else{ + Integer ver = software.getVerLatest(); + sb.append(String.format("%04d",ver)); + + if(software.getVerValid()==0){ + sb.append("H"); + } + else{ + sb.append("O"); + } + } + + LambdaQueryWrapper srvWrapper = new LambdaQueryWrapper<>(); + srvWrapper.gt(Server::getPriority, 0) + .apply(true,"FIND_IN_SET ('9',swid)") + .orderByDesc(Server::getPriority) + .last("limit 1");; + Server srv = serverDao.selectOne(srvWrapper); + if(srv!=null && !srv.getIport().isEmpty()) { + sb.append("|S").append(srv.getIport()); + } + + return sb.toString(); + } + + private static HttpClientConnectionManager getHttpClientConnectionManager() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + return PoolingHttpClientConnectionManagerBuilder.create() + .setSSLSocketFactory(getSslConnectionSocketFactory()) + .build(); + } + + /** + * 支持SSL + * + * @return SSLConnectionSocketFactory + */ + private static SSLConnectionSocketFactory getSslConnectionSocketFactory() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + TrustStrategy acceptingTrustStrategy = (x509Certificates, s) -> true; + SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build(); + return new SSLConnectionSocketFactory(sslContext, new NoopHostnameVerifier()); + } + +// @Test + public void httpClient5SslConnect() { + //创建post请求对象 + String url = "https://buy.itunes.apple.com/verifyReceipt"; + HttpPost httpPost = new HttpPost(url); + HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); + try (CloseableHttpClient httpClient = httpClientBuilder.setConnectionManager(getHttpClientConnectionManager()).build()) { + httpPost.setEntity(new StringEntity("{[\"receipt-data\":\"\"]}", StandardCharsets.UTF_8)); + //使用CloseableHttpClient发送请求 + CloseableHttpResponse response = httpClient.execute(httpPost); + HttpEntity entity = response.getEntity(); + JSONObject jsonObject = JSON.parseObject(EntityUtils.toString(entity, "UTF-8")); + System.out.println(jsonObject); +// log.info(body); + // TODO 获取页面内容实现 + } catch (IOException | ParseException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { + e.printStackTrace(); + } + } + + public AjaxResult verifyAppleReceipt(String param, boolean isSanbox) { + String url = isSanbox ? "https://sandbox.itunes.apple.com/verifyReceipt" + : "https://buy.itunes.apple.com/verifyReceipt"; + HttpPost httpPost = new HttpPost(url); + String errMsg = null; + HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); + + try (CloseableHttpClient httpClient = httpClientBuilder.setConnectionManager(getHttpClientConnectionManager()).build()) { + httpPost.setEntity(new StringEntity(param, StandardCharsets.UTF_8)); + //使用CloseableHttpClient发送请求 + CloseableHttpResponse response = httpClient.execute(httpPost); + HttpEntity entity = response.getEntity(); + String sBody = EntityUtils.toString(entity, "UTF-8"); + JSONObject jsonObject = JSON.parseObject(sBody); + + System.out.println(jsonObject.toJSONString()); + + if(jsonObject.containsKey("status")){ + int status = jsonObject.getIntValue("status"); + + if(status==21007){ + return verifyAppleReceipt(param, true); + } + else if(status==0){ + return AjaxResult.success(jsonObject); + } + else{ + errMsg = String.valueOf(status); + } + } + } catch (IOException | ParseException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { + e.printStackTrace(); + errMsg = e.getMessage(); + } + + return AjaxResult.error(errMsg); + } + + public AjaxResult getAliPayInfo(String money, String order) { + int num = (int) (Double.parseDouble(money) * 100); + String errMsg = null; + AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest(); + //SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。 + AlipayTradeAppPayModel model = new AlipayTradeAppPayModel(); + model.setBody("花费" + money + "元购买" + num + "唱作音符"); + model.setSubject("唱作音符"); + model.setOutTradeNo(order); + model.setTimeoutExpress("30m"); + model.setTotalAmount(money); + model.setProductCode("QUICK_MSECURITY_PAY"); + request.setBizModel(model); + request.setNotifyUrl(AlipayUtil.NOTIFYURL); + try { + //这里和普通的接口调用不同,使用的是sdkExecute + AlipayTradeAppPayResponse response = AlipayUtil.getAlipayClient().sdkExecute(request); +// System.out.println(response.getBody()); //就是orderString 可以直接给客户端请求,无需再做处理。 + return AjaxResult.success("操作成功", response.getBody()); + } + catch (AlipayApiException e){ + e.printStackTrace(); + } + + return AjaxResult.error(errMsg); + } + + public AjaxResult handleAlipayNotify(HttpServletRequest request) { + String errMsg = null; + + try { + //获取支付宝POST过来反馈信息 + BufferedReader bufr = new BufferedReader(new InputStreamReader(request.getInputStream(), + StandardCharsets.UTF_8)); + StringBuilder sBuilder = new StringBuilder(); + String temp = ""; + while ((temp = bufr.readLine()) != null) { + sBuilder.append(temp); + } + bufr.close(); +// System.out.println(sBuilder); + + //将异步通知中收到的待验证所有参数都存放到map中 + Map params = new HashMap<>(); + String[] split = sBuilder.toString().split("&"); + for (String str : split) { + String[] strings = str.split("="); + if (strings.length == 2) { + params.put(strings[0], URLDecoder.decode(strings[1], StandardCharsets.UTF_8)); + } + } + + //调用SDK验证签名 + boolean signVerified = AlipaySignature.rsaCheckV1(params, AlipayUtil.ALIPAY_PUBLIC_KEY, + AlipayConstants.CHARSET_UTF8,"RSA2") ; + if(signVerified){ + String status = params.get("trade_status"); + if(Objects.equals(status, "TRADE_FINISHED") || Objects.equals(status, "TRADE_SUCCESS")) { + String out_trade_no = params.get("out_trade_no"); + System.out.println("alipayNotify: " + out_trade_no); + return AjaxResult.success("操作成功", out_trade_no); + } + else{ + errMsg = status; + } + } + else{ + errMsg = "验签失败"; + } + } catch (AlipayApiException | IOException e) { + e.printStackTrace(); + errMsg = e.getMessage(); + } + + System.out.println(errMsg); + return AjaxResult.error(errMsg); + } + + public AjaxResult getWxPayInfo(String money, String order) { + int num = (int) (Double.parseDouble(money) * 100); + String errMsg = null; + AppServiceExtension service = new AppServiceExtension.Builder().config(WxpayUtil.getWxpayConfig()).build(); + + // 跟之前下单示例一样,填充预下单参数 + PrepayRequest request = new PrepayRequest(); + Amount amount = new Amount(); + amount.setTotal(num); + request.setAmount(amount); + request.setAppid(WxpayUtil.appId); + request.setMchid(WxpayUtil.merchantId); + request.setDescription("花费" + money + "元购买" + num + "唱作音符"); + request.setNotifyUrl(WxpayUtil.NOTIFYURL); + request.setOutTradeNo(order); + // response包含了调起支付所需的所有参数,可直接用于前端调起支付 + PrepayWithRequestPaymentResponse response = service.prepayWithRequestPayment(request); +// PrepayResponse response = service.prepay(request); + return AjaxResult.success("操作成功", JSON.toJSONString(response)); + } + + public AjaxResult handleWxpayNotify(HttpServletRequest request) { + String errMsg = null; + + Map headerMap = new HashMap<>(); + Enumeration enumeration = request.getHeaderNames(); + while (enumeration.hasMoreElements()) { + String name = enumeration.nextElement(); + if( name.contains("Wechatpay-") ) { + String value = request.getHeader(name); + headerMap.put(name, value); + System.out.println(name + ":" + value); + } + } + + try { + //获取支付宝POST过来反馈信息 + BufferedReader bufr = new BufferedReader(new InputStreamReader(request.getInputStream(), + StandardCharsets.UTF_8)); + StringBuilder requestBody = new StringBuilder(); + String temp = ""; + while ((temp = bufr.readLine()) != null) { + requestBody.append(temp); + } + bufr.close(); + + System.out.println(requestBody); + +// if(true) { +// throw new RuntimeException(); +// } + + // 构造 RequestParam + RequestParam requestParam = new RequestParam.Builder() + .serialNumber(headerMap.get("Wechatpay-Serial")) + .nonce(headerMap.get("Wechatpay-Nonce")) + .signature(headerMap.get("Wechatpay-Signature")) + .timestamp(headerMap.get("Wechatpay-Timestamp")) +// .serialNumber(request.getHeader("Wechatpay-Serial")) +// .nonce(request.getHeader("Wechatpay-Nonce")) +// .signature(request.getHeader("Wechatpay-Signature")) +// .timestamp(request.getHeader("Wechatpay-Timestamp")) + .body(requestBody.toString()) + .build(); + + // 初始化 NotificationParser + NotificationParser parser = new NotificationParser((NotificationConfig) WxpayUtil.getWxpayConfig()); + + // 以支付通知回调为例,验签、解密并转换成 Transaction + Transaction transaction = parser.parse(requestParam, Transaction.class); + Transaction.TradeStateEnum status = transaction.getTradeState(); + if(status==Transaction.TradeStateEnum.SUCCESS) { + String out_trade_no = transaction.getOutTradeNo(); + System.out.println("wxpayNotify: " + out_trade_no); + return AjaxResult.success("操作成功", out_trade_no); + } + else{ + errMsg = transaction.getTradeStateDesc(); + } + } catch (ValidationException e) { + // 签名验证失败,返回 401 UNAUTHORIZED 状态码 + return AjaxResult.error(401, "验签失败"); + } catch (IOException e) { +// throw new RuntimeException(e); + errMsg = e.getMessage(); + } + + System.out.println(errMsg); + return AjaxResult.error(errMsg); + } + + public String userLogin(String uname, Integer sid, String web) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(Member::getUname, uname) + .eq(Member::getDeleted, 0) + .apply(sid>0,"FIND_IN_SET ('"+sid+"',swids)"); + if(web!=null && !web.isEmpty()){ + wrapper.eq(Member::getWeb, web); + } + wrapper.last("limit 1"); + Member member = memberDao.selectOne(wrapper); + + if(member == null) return "err:104"; + + Integer now = (int)Instant.now().getEpochSecond(); + if(now > member.getExptime()) return "err:112"; + + member.setLogcount(member.getLogcount()+1); + member.setLogtime(now); + memberDao.updateById(member); + + return "uid:" + member.getId(); + } + + public String setSlpAmo(Integer srv, Integer tim, Integer amo, Integer ver) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(Slp::getRegtime, tim) + .eq(Slp::getIsrv, srv) + .last("limit 1"); + Slp slp = slpDao.selectOne(wrapper); + + if(slp == null){ + slp = new Slp(); + slp.setIsrv(srv); + slp.setAmount(amo); + slp.setSwver(ver); + slp.setRegtime(tim); + slp.setLogtime((int)Instant.now().getEpochSecond()); + + if( slpDao.insert(slp) > 0 ){ //更新统计 + LocalDateTime ldt = LocalDateTime.ofInstant(Instant.ofEpochSecond(tim), ZoneId.systemDefault()); + Integer dt = ldt.getYear() * 10000 + ldt.getMonthValue() * 100 + ldt.getDayOfMonth(); + Summary summary = summaryDao.selectById(dt); + boolean newSum = false; + + if(summary == null){ + summary = new Summary(); + summary.setDt(dt); + newSum = true; + } + + if(srv==0){ + summary.setRs0(summary.getRs0() + amo); + } + else if(srv==1){ + summary.setRs1(summary.getRs1() + amo); + } + else if(srv==2){ + summary.setRs2(summary.getRs2() + amo); + } + else if(srv==3){ + summary.setRs3(summary.getRs3() + amo); + } + + if( newSum ) + summaryDao.insert(summary); + else + summaryDao.updateById(summary); + } + else { + return "err:102"; + } + } + + return "srv=" + srv + "|tim=" + tim; + } + + public String getInfo(Integer sid, Integer ver) { + LambdaQueryWrapper swWrapper = new LambdaQueryWrapper<>(); + swWrapper.eq(Software::getSid,sid) + .eq(Software::getDeprecated,0); + Software software = softwareDao.selectOne(swWrapper); + if(software == null) return "err:101"; + + StringBuffer sb = new StringBuffer(); + sb.append("flg=").append(software.getVerValid() > ver ? "0" : "1"); + sb.append("|ver=").append(software.getVerLatest()); + + LambdaQueryWrapper srvWrapper = new LambdaQueryWrapper<>(); + srvWrapper.gt(Server::getPriority, 0) + .apply(sid>0,"FIND_IN_SET ('"+sid+"',swid)") + .orderByDesc(Server::getPriority); + List srvs = serverDao.selectList(srvWrapper); + if(!srvs.isEmpty()) { + sb.append("|srv="); + for (int i=0; i wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(Member::getUname, uname) +// .eq(Member::getSid, sid) + .eq(Member::getWeb, web) + .apply(sid>0,"FIND_IN_SET ('"+sid+"',swids)") + .last("limit 1"); + Member member = memberDao.selectOne(wrapper); + + if(member != null) return "err:104"; + + member = new Member(); + member.setAddtime((int)Instant.now().getEpochSecond()); + +// member.setSid(sid); + member.setSwids(sid.toString()); + member.setUname(uname); + member.setWeb(web); + member.setComment("软件注册"); + member.setExptime((int) (Instant.now().getEpochSecond()+2678400));//31622400)); + + int ret = memberDao.insert(member); + if( ret>0 ) + return "uid:" + member.getId(); + else + return "err:104"; + } + + public String getPredMatches(Integer sid) { + String url = "http://localhost:10081/predmatches?sid=" + sid; + HttpGet httpGet = new HttpGet(url); + try (CloseableHttpClient httpClient = HttpClients.createDefault()) { +// httpGet.setEntity(new StringEntity("{[\"receipt-data\":\"\"]}", StandardCharsets.UTF_8)); + //使用CloseableHttpClient发送请求 + CloseableHttpResponse response = httpClient.execute(httpGet); + HttpEntity entity = response.getEntity(); + +// return EntityUtils.toString(entity, "UTF-8"); + JSONObject jsonObject = JSON.parseObject(EntityUtils.toString(entity, "UTF-8")); +// System.out.println(jsonObject); + return "dat:" + jsonObject.get("data").toString(); + } catch (IOException | ParseException e) { + e.printStackTrace(); + } + return "err:102"; + } +} diff --git a/src/main/java/com/datao/service/LoginService.java b/src/main/java/com/datao/service/LoginService.java new file mode 100644 index 0000000..bb87359 --- /dev/null +++ b/src/main/java/com/datao/service/LoginService.java @@ -0,0 +1,74 @@ +package com.datao.service; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.datao.dao.AdminDao; +import com.datao.domain.Admin; +import com.datao.controller.dto.LoginDto; +import org.springframework.stereotype.Service; +import org.springframework.util.DigestUtils; + +@Service +public class LoginService { +// @Autowired + final private AdminDao adminDao; + + public LoginService(AdminDao adminDao) { + this.adminDao = adminDao; + } + + public Boolean login(LoginDto dto) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(Admin::getUsername,dto.getUsername().toLowerCase().trim()); + + Admin admin = adminDao.selectOne(wrapper); + // 判断查询结果是否为null + if (admin == null) return false; + // 判断查询结果中的isDelete是否为1 + if (admin.getDeleted() == 1) return false; + // 从查询结果中获取盐值 + String salt = admin.getSalt(); + // 调用getMd5Password()方法,将参数password和salt结合起来进行加密 + String md5Password = getMd5Password(dto.getPassword(), salt); + // 判断查询结果中的密码,与以上加密得到的密码是否不一致 + return admin.getPassword().equals(md5Password); + } + + public Boolean updatePassword(String username, String origPwd, String newPwd) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(Admin::getUsername, username.trim()) + .last("limit 1"); + Admin user = adminDao.selectOne(wrapper); + // 判断查询结果是否为null + if (user == null || user.getDeleted() == 1) { + return false; + } + + // 从查询结果中获取盐值 + String salt = user.getSalt(); + // 调用getMd5Password()方法,将参数password和salt结合起来进行加密 + String md5Password = getMd5Password(origPwd, salt); + // 判断查询结果中的密码,与以上加密得到的密码是否不一致 + if (!user.getPassword().equals(md5Password)) { + return false; + } + + md5Password = getMd5Password(newPwd, salt); + user.setPassword(md5Password); + + adminDao.updateById(user); + + return true; + } + + /** + * md5算法加密 + */ + private String getMd5Password(String password, String salt) { + for (int i = 0; i < 3; i++) { + //三次加密 + password = DigestUtils.md5DigestAsHex((salt + password + salt).getBytes()).toUpperCase(); + } + //返回加密的密码 + return password; + } +} diff --git a/src/main/java/com/datao/service/MemberService.java b/src/main/java/com/datao/service/MemberService.java new file mode 100644 index 0000000..5bf4b4e --- /dev/null +++ b/src/main/java/com/datao/service/MemberService.java @@ -0,0 +1,156 @@ +package com.datao.service; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.datao.domain.Member; +import com.datao.domain.vo.MemberVo; +import com.datao.controller.dto.MemberDto; +import com.datao.controller.dto.MemberPageDto; +import com.datao.dao.MemberDao; +import org.springframework.stereotype.Service; + +import java.time.Instant; +import java.util.Date; +import java.util.Objects; + +@Service +public class MemberService extends ServiceImpl { +// @Autowired + final private MemberDao memberDao; + + public MemberService(MemberDao memberDao) { + this.memberDao = memberDao; + } + + public IPage pageList(MemberPageDto dto) { + QueryWrapper wrapper = new QueryWrapper<>(); + + String swids = dto.getSwids(); + if(swids != null && !swids.isEmpty()) { + String[] ids = swids.split(","); + StringBuilder qry = new StringBuilder(); + for(int i=0; i0 ) + qry.append(" OR "); + +// qry.append("swids=").append(ids[i]); + qry.append("FIND_IN_SET ('").append(ids[i]).append("',swids)"); + } + wrapper.apply(true, qry.toString()); + } + + String order = dto.getOrderBy(); + if(order != null && !order.isEmpty()) { + if (order.equals("descending")) { + wrapper.orderByDesc(dto.getSortBy()); + } else if (order.equals("ascending")) { + wrapper.orderByAsc(dto.getSortBy()); + } + } + else{ + wrapper.lambda().orderByDesc(Member::getLogtime); + } + + Page page = new Page<>(dto.getPageNum(), dto.getPageSize()); + page = (Page) memberDao.selectPage(page, wrapper); + + //MP3.2+用法 + return page.convert(result -> { + MemberVo vo = new MemberVo(); + vo.setId(result.getId()); + vo.setUname(result.getUname()); + vo.setComment(result.getComment()); + vo.setAddtime(new Date(result.getAddtime()*1000L)); + vo.setExptime(new Date(result.getExptime()*1000L)); + vo.setWeb(result.getWeb()); + + if(swids != null && !swids.isEmpty()) { + String[] rids = swids.split(","); + String sids = result.getSwids(); + String[] gids = sids.split(","); + String setids = ""; + + for (String gid : gids) { + for (String rid : rids) { + if (rid.equals(gid)) { + if( !setids.isEmpty() ) + setids += ","; + + setids += rid; + } + } + } + + vo.setSwids(setids); + } + else{ + vo.setSwids(result.getSwids()); + } + + if(result.getLogcount()>0) { + vo.setLogcount(result.getLogcount()); + vo.setLogtime(new Date(result.getLogtime()*1000L)); + } + return vo; + }); + } + + public Boolean update(MemberDto dto){ + Integer id = dto.getId(); + LambdaQueryWrapper query = new LambdaQueryWrapper<>(); + query.eq(Member::getUname,dto.getUname()) + .eq(Member::getWeb, dto.getWeb()) + .last("limit 1"); + Member member = memberDao.selectOne(query); + + if(member != null ){ + if(id!=null && !id.equals(member.getId())) + return false; + } + else if (id != null){ + member = memberDao.selectById(id); + + if (member == null) return false; + } + else { + member = new Member(); + member.setAddtime((int)Instant.now().getEpochSecond()); + } + + String memberSwids = member.getSwids(); + if(id==null && memberSwids!=null && !memberSwids.isEmpty()){ //新增用户时合并swid + String[] aOldIds = memberSwids.split(","); + String dtoSwids = dto.getSwids(); + String[] aNewIds = dtoSwids.split(","); + for (String nid : aNewIds){ + boolean bGot = false; + for(String oid : aOldIds){ + if(oid.equals(nid)){ + bGot = true; + break; + } + } + if(!bGot){ + memberSwids = memberSwids.concat(",").concat(nid); + } + } + + member.setSwids(memberSwids); + } + else{ + member.setSwids(dto.getSwids()); + } + member.setUname(dto.getUname()); + member.setWeb(dto.getWeb()); + member.setComment(dto.getComment()); + member.setExptime((int) (dto.getExptime().getTime()/1000L)); + + int ret = member.getId()==null ? memberDao.insert(member) + : memberDao.updateById(member); + + return ret > 0; + } +} diff --git a/src/main/java/com/datao/service/MsgService.java b/src/main/java/com/datao/service/MsgService.java new file mode 100644 index 0000000..569a766 --- /dev/null +++ b/src/main/java/com/datao/service/MsgService.java @@ -0,0 +1,196 @@ +package com.datao.service; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.datao.domain.Msg; +import com.datao.domain.Msguser; +import com.datao.domain.vo.MsgVo; +import com.datao.controller.dto.LoginDto; +import com.datao.controller.dto.MsgDto; +import com.datao.controller.dto.MsgListDto; +import com.datao.dao.MsgDao; +import com.datao.dao.MsguserDao; +import com.datao.util.page.BasePage; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.time.Instant; +import java.util.ArrayList; +import java.util.List; + +@Service +public class MsgService { +// @Autowired + private MsgDao msgDao; + +// @Autowired + private MsguserDao usrDao; + + @Autowired + public void setMsgDao(MsgDao msgDao) { + this.msgDao = msgDao; + } + + @Autowired + public void setUsrDao(MsguserDao usrDao) { + this.usrDao = usrDao; + } + + private String getSHA256(String str){ + try { + MessageDigest messageDigest = MessageDigest.getInstance("SHA-256"); + + for(int t=0; t<2; t++) { + messageDigest.update(str.getBytes(StandardCharsets.UTF_8)); + StringBuffer stringBuffer = new StringBuffer(); + + byte[] bytes = messageDigest.digest(); + for (int i = 0; i < bytes.length; i++) { + String temp = Integer.toHexString(bytes[i] & 0xFF); + if (temp.length() == 1) { //1得到一位的进行补0操作 + stringBuffer.append("0"); + } + stringBuffer.append(temp); + } + + str = stringBuffer.toString(); + } + } catch (NoSuchAlgorithmException e) { + return null; + } + + return str; + } + + public Integer login(LoginDto dto) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(Msguser::getUname, dto.getUsername().trim()) + .last("limit 1"); + + Msguser usr = usrDao.selectOne(wrapper); + // 判断查询结果是否为null + if (usr == null) return -1; + // 判断查询结果中的isDelete是否为1 + if (usr.getDeleted() == 1) return -1; + + String encodestr = getSHA256(dto.getPassword()); + if(encodestr == null || !usr.getPassword().equals(encodestr)){ + return -1; + } + + usr.setLogcount(usr.getLogcount()+1); + usr.setLogtime((int) Instant.now().getEpochSecond()); + usrDao.updateById(usr); + + return usr.getId(); + } + + public Boolean updatePassword(String username, String origPwd, String newPwd) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(Msguser::getUname, username.trim()) + .last("limit 1"); + Msguser user = usrDao.selectOne(wrapper); + // 判断查询结果是否为null + if (user == null || user.getDeleted() == 1) { + return false; + } + + String shaPassword = getSHA256(origPwd); + // 判断查询结果中的密码,与以上加密得到的密码是否不一致 + if (shaPassword == null || !user.getPassword().equals(shaPassword)) { + return false; + } + + shaPassword = getSHA256(newPwd); + user.setPassword(shaPassword); + + usrDao.updateById(user); + + return true; + } + + //Admin业务 + public IPage pageList(BasePage dto) { + Page page = new Page(dto.getPageNum(), dto.getPageSize()); + page = (Page) msgDao.selectPage(page, new QueryWrapper().orderByDesc("id")); + return page; + } + + public Integer update(MsgDto dto){ + Msg msg = dto.getId() == null ? new Msg() : msgDao.selectById(dto.getId()); + if (msg == null) return 0; + + msg.setSendtime(dto.getSendtime() == null ? (int) Instant.now().getEpochSecond() + : dto.getSendtime()); + msg.setSendid(dto.getSendid()); + msg.setContent(dto.getContent()); + msg.setAttach(dto.getAttach()); + + int ret = dto.getId()==null ? msgDao.insert(msg) + : msgDao.updateById(msg); + + return ret > 0 ? msg.getId() : 0; + } + + public Boolean setHide(Integer id){ + Msg msg = msgDao.selectById(id); + if (msg == null) return false; + + msg.setHidden(1 - msg.getHidden()); //第2位=1表示隐藏 + msgDao.updateById(msg); + + return true; + } + + //Msger业务 + public List getList(MsgListDto dto){ + Integer now = (int) Instant.now().getEpochSecond(); + Integer recvid = dto.getRecvid(); + Integer time = dto.getMintime(); + + if(time==null || time==0) { + time = now; + } + + List lst = msgDao.selectList( + new LambdaQueryWrapper() + .eq(Msg::getHidden, 0) //显示 + .lt(Msg::getSendtime, time) + .orderByDesc(Msg::getSendtime) + .last("limit 10")); + + List vos = new ArrayList(); + + for(Msg msg : lst){ + MsgVo vo = new MsgVo(); + vo.setId(msg.getId()); + vo.setContent(msg.getContent()); + vo.setAttach(msg.getAttach()); + vo.setSendtime(msg.getSendtime()); + + Integer sendId = msg.getSendid(); + Integer readTime = msg.getReadtime(); + vo.setSendid(sendId); + vo.setReadtime(readTime); + + if(sendId!=recvid){ + Msguser usr = usrDao.selectById(sendId); + vo.setSendname(usr.getUname()); + + if(readTime == null || readTime==0){ //设为已读 + msg.setReadtime(now); + msgDao.updateById(msg); + } + } + + vos.add(vo); + } + + return vos; + } +} diff --git a/src/main/java/com/datao/service/ServerService.java b/src/main/java/com/datao/service/ServerService.java new file mode 100644 index 0000000..be4a313 --- /dev/null +++ b/src/main/java/com/datao/service/ServerService.java @@ -0,0 +1,11 @@ +package com.datao.service; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.datao.domain.Server; +import com.datao.dao.ServerDao; +import org.springframework.stereotype.Service; + +@Service +public class ServerService extends ServiceImpl { + +} diff --git a/src/main/java/com/datao/service/SlpService.java b/src/main/java/com/datao/service/SlpService.java new file mode 100644 index 0000000..1570dea --- /dev/null +++ b/src/main/java/com/datao/service/SlpService.java @@ -0,0 +1,126 @@ +package com.datao.service; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.datao.domain.Slp; +import com.datao.domain.Summary; +import com.datao.domain.vo.SlpVo; +import com.datao.controller.dto.SlpPageDto; +import com.datao.dao.SlpDao; +import org.springframework.stereotype.Service; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service +public class SlpService { +// @Autowired + final private SlpDao slpDao; + final private SummaryService summaryService; + + public SlpService(SlpDao slpDao, SummaryService summaryService) { + this.slpDao = slpDao; + this.summaryService = summaryService; + } + + public IPage pageList(SlpPageDto dto) { + QueryWrapper wrapper = new QueryWrapper<>(); + + Integer isrv = dto.getIsrv(); + if(isrv != null) { + wrapper.lambda().eq(Slp::getIsrv, isrv); + } + + Date start = dto.getStartDate(); + if(start!=null){ + wrapper.lambda().ge(Slp::getRegtime, (int)(start.getTime()/1000L)); + } + + Date end = dto.getEndDate(); + if(end!=null){ + wrapper.lambda().le(Slp::getRegtime, (int)(end.getTime()/1000L + 86400)); + } + + boolean bOrdered = false; + String order = dto.getOrderBy(); + if(order != null) { + if (order.equals("descending")) { + bOrdered = true; + wrapper.orderByDesc(dto.getSortBy()); + } else if (order.equals("ascending")) { + bOrdered = true; + wrapper.orderByAsc(dto.getSortBy()); + } + } + + if(!bOrdered){ + wrapper.lambda().orderByDesc(Slp::getId); + } + + Page page = new Page(dto.getPageNum(), dto.getPageSize()); + page = slpDao.selectPage(page, wrapper); + + IPage convertPage = page.convert(result -> { + SlpVo vo = new SlpVo(); + vo.setId(result.getId()); + vo.setIsrv(result.getIsrv()); + vo.setAmount(result.getAmount()); + vo.setSwver(result.getSwver()); + + vo.setRegtime(new Date(result.getRegtime()*1000L)); + vo.setLogtime(new Date(result.getLogtime()*1000L)); + + return vo; + }); + + return convertPage; + } + + public Map sumList(String mon){ + Map map = new HashMap<>(); + + if(mon==null || mon.equals("")){ + Summary summary = summaryService.getOne(new LambdaQueryWrapper().orderByDesc(Summary::getDt).last("limit 1")); + if(summary != null){ + String maxMon = summary.getDt().toString().substring(0, 6); + map.put("maxMon", maxMon); + mon = maxMon; + } + summary = summaryService.getOne(new LambdaQueryWrapper().orderByAsc(Summary::getDt).last("limit 1")); + if(summary != null){ + String minMon = summary.getDt().toString().substring(0, 6); + map.put("minMon", minMon); + } + } + + List list = null; + if( mon != null ) { + int begin = Integer.parseInt(mon) * 100; + int end = begin + 32; + list = summaryService.list(new LambdaQueryWrapper().between(Summary::getDt, begin, end).orderByAsc(Summary::getDt)); + + if (!list.isEmpty()) { + Summary total = new Summary(); + + list.forEach(summary -> { + total.setPs1(total.getPs1() + summary.getPs1()); + total.setPs2(total.getPs2() + summary.getPs2()); + total.setPs3(total.getPs3() + summary.getPs3()); + total.setRs0(total.getRs0() + summary.getRs0()); + total.setRs1(total.getRs1() + summary.getRs1()); + total.setRs2(total.getRs2() + summary.getRs2()); + total.setRs3(total.getRs3() + summary.getRs3()); + }); + list.add(total); + } + } + + map.put("records", list); + + return map; + } +} diff --git a/src/main/java/com/datao/service/SoftwareService.java b/src/main/java/com/datao/service/SoftwareService.java new file mode 100644 index 0000000..b76803d --- /dev/null +++ b/src/main/java/com/datao/service/SoftwareService.java @@ -0,0 +1,56 @@ +package com.datao.service; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.datao.dao.SoftwareDao; +import com.datao.domain.Software; +import org.springframework.stereotype.Service; + +@Service +public class SoftwareService extends ServiceImpl{ +// @Autowired + private final SoftwareDao softwareDao; + + public SoftwareService(SoftwareDao softwareDao) { + this.softwareDao = softwareDao; + } + + public Boolean deprecated(Integer sid){ + Software software = softwareDao.selectById(sid); + if (software == null) return false; + + software.setDeprecated(1 - software.getDeprecated()); + softwareDao.updateById(software); + + return true; + } +// public IPage pageList(BasePage dto) { +// Page page = new Page(dto.getPageNum(), dto.getPageSize()); +// page = (Page) softwareDao.selectPage(page, null); +// return page; +// } + +// public Boolean update(Software dto){ +// Software software = null; +// +// Integer sid = dto.getSid(); +// if (sid != null){ +// software = softwareDao.selectById(sid); +// +// if (software == null) return false; +// } +// else { +// software = new Software(); +// software.setDeprecated(0); +// } +// +// software.setSname(dto.getSname()); +// software.setVerLatest(dto.getVerLatest()); +// software.setVerValid(dto.getVerValid()); +// +// int ret = sid==null ? softwareDao.insert(software) +// : softwareDao.updateById(software); +// +// return ret > 0; +// } + +} diff --git a/src/main/java/com/datao/service/SummaryService.java b/src/main/java/com/datao/service/SummaryService.java new file mode 100644 index 0000000..f5f7c11 --- /dev/null +++ b/src/main/java/com/datao/service/SummaryService.java @@ -0,0 +1,10 @@ +package com.datao.service; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.datao.domain.Summary; +import com.datao.dao.SummaryDao; +import org.springframework.stereotype.Service; + +@Service +public class SummaryService extends ServiceImpl { +} diff --git a/src/main/java/com/datao/service/WebsiteService.java b/src/main/java/com/datao/service/WebsiteService.java new file mode 100644 index 0000000..dc80806 --- /dev/null +++ b/src/main/java/com/datao/service/WebsiteService.java @@ -0,0 +1,26 @@ +package com.datao.service; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.datao.domain.Website; +import com.datao.dao.WebsiteDao; +import org.springframework.stereotype.Service; + +@Service +public class WebsiteService extends ServiceImpl { + // @Autowired + private final WebsiteDao websiteDao; + + public WebsiteService(WebsiteDao websiteDao) { + this.websiteDao = websiteDao; + } + + public Boolean deprecated(Integer id){ + Website website = websiteDao.selectById(id); + if (website == null) return false; + + website.setDeprecated(1 - website.getDeprecated()); + websiteDao.updateById(website); + + return true; + } +} diff --git a/src/main/java/com/datao/service/alipay/Base64.java b/src/main/java/com/datao/service/alipay/Base64.java new file mode 100644 index 0000000..b7b1203 --- /dev/null +++ b/src/main/java/com/datao/service/alipay/Base64.java @@ -0,0 +1,269 @@ +package com.datao.service.alipay; + +import java.util.Arrays; + +public final class Base64 { + + private static final int BASELENGTH = 128; + private static final int LOOKUPLENGTH = 64; + private static final int TWENTYFOURBITGROUP = 24; + private static final int EIGHTBIT = 8; + private static final int SIXTEENBIT = 16; + private static final int FOURBYTE = 4; + private static final int SIGN = -128; + private static char PAD = '='; + private static byte[] base64Alphabet = new byte[BASELENGTH]; + private static char[] lookUpBase64Alphabet = new char[LOOKUPLENGTH]; + + static { + Arrays.fill(base64Alphabet, (byte) -1); + + for (int i = 'Z'; i >= 'A'; i--) { + base64Alphabet[i] = (byte) (i - 'A'); + } + for (int i = 'z'; i >= 'a'; i--) { + base64Alphabet[i] = (byte) (i - 'a' + 26); + } + + for (int i = '9'; i >= '0'; i--) { + base64Alphabet[i] = (byte) (i - '0' + 52); + } + + base64Alphabet['+'] = 62; + base64Alphabet['/'] = 63; + + for (int i = 0; i <= 25; i++) { + lookUpBase64Alphabet[i] = (char) ('A' + i); + } + + for (int i = 26, j = 0; i <= 51; i++, j++) { + lookUpBase64Alphabet[i] = (char) ('a' + j); + } + + for (int i = 52, j = 0; i <= 61; i++, j++) { + lookUpBase64Alphabet[i] = (char) ('0' + j); + } + lookUpBase64Alphabet[62] = (char) '+'; + lookUpBase64Alphabet[63] = (char) '/'; + + } + + private static boolean isWhiteSpace(char octect) { + return (octect == 0x20 || octect == 0xd || octect == 0xa || octect == 0x9); + } + + private static boolean isPad(char octect) { + return (octect == PAD); + } + + private static boolean isData(char octect) { + return (octect < BASELENGTH && base64Alphabet[octect] != -1); + } + + /** + * Encodes hex octects into Base64 + * + * @param binaryData + * Array containing binaryData + * @return Encoded Base64 array + */ + public static String encode(byte[] binaryData) { + + if (binaryData == null) { + return null; + } + + int lengthDataBits = binaryData.length * EIGHTBIT; + if (lengthDataBits == 0) { + return ""; + } + + int fewerThan24bits = lengthDataBits % TWENTYFOURBITGROUP; + int numberTriplets = lengthDataBits / TWENTYFOURBITGROUP; + int numberQuartet = fewerThan24bits != 0 ? numberTriplets + 1 + : numberTriplets; + char encodedData[] = null; + + encodedData = new char[numberQuartet * 4]; + + byte k = 0, l = 0, b1 = 0, b2 = 0, b3 = 0; + + int encodedIndex = 0; + int dataIndex = 0; + + for (int i = 0; i < numberTriplets; i++) { + b1 = binaryData[dataIndex++]; + b2 = binaryData[dataIndex++]; + b3 = binaryData[dataIndex++]; + + l = (byte) (b2 & 0x0f); + k = (byte) (b1 & 0x03); + + byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) + : (byte) ((b1) >> 2 ^ 0xc0); + byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) + : (byte) ((b2) >> 4 ^ 0xf0); + byte val3 = ((b3 & SIGN) == 0) ? (byte) (b3 >> 6) + : (byte) ((b3) >> 6 ^ 0xfc); + + encodedData[encodedIndex++] = lookUpBase64Alphabet[val1]; + encodedData[encodedIndex++] = lookUpBase64Alphabet[val2 | (k << 4)]; + encodedData[encodedIndex++] = lookUpBase64Alphabet[(l << 2) | val3]; + encodedData[encodedIndex++] = lookUpBase64Alphabet[b3 & 0x3f]; + } + + // form integral number of 6-bit groups + if (fewerThan24bits == EIGHTBIT) { + b1 = binaryData[dataIndex]; + k = (byte) (b1 & 0x03); + + byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) + : (byte) ((b1) >> 2 ^ 0xc0); + encodedData[encodedIndex++] = lookUpBase64Alphabet[val1]; + encodedData[encodedIndex++] = lookUpBase64Alphabet[k << 4]; + encodedData[encodedIndex++] = PAD; + encodedData[encodedIndex++] = PAD; + } else if (fewerThan24bits == SIXTEENBIT) { + b1 = binaryData[dataIndex]; + b2 = binaryData[dataIndex + 1]; + l = (byte) (b2 & 0x0f); + k = (byte) (b1 & 0x03); + + byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) + : (byte) ((b1) >> 2 ^ 0xc0); + byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) + : (byte) ((b2) >> 4 ^ 0xf0); + + encodedData[encodedIndex++] = lookUpBase64Alphabet[val1]; + encodedData[encodedIndex++] = lookUpBase64Alphabet[val2 | (k << 4)]; + encodedData[encodedIndex++] = lookUpBase64Alphabet[l << 2]; + encodedData[encodedIndex++] = PAD; + } + + return new String(encodedData); + } + + /** + * Decodes Base64 data into octects + * + * @param encoded + * string containing Base64 data + * @return Array containind decoded data. + */ + public static byte[] decode(String encoded) { + + if (encoded == null) { + return null; + } + + char[] base64Data = encoded.toCharArray(); + // remove white spaces + int len = removeWhiteSpace(base64Data); + + if (len % FOURBYTE != 0) { + return null;// should be divisible by four + } + + int numberQuadruple = (len / FOURBYTE); + + if (numberQuadruple == 0) { + return new byte[0]; + } + + byte decodedData[] = null; + byte b1 = 0, b2 = 0, b3 = 0, b4 = 0; + char d1 = 0, d2 = 0, d3 = 0, d4 = 0; + + int i = 0; + int encodedIndex = 0; + int dataIndex = 0; + decodedData = new byte[(numberQuadruple) * 3]; + + for (; i < numberQuadruple - 1; i++) { + + if (!isData((d1 = base64Data[dataIndex++])) + || !isData((d2 = base64Data[dataIndex++])) + || !isData((d3 = base64Data[dataIndex++])) + || !isData((d4 = base64Data[dataIndex++]))) { + return null; + }// if found "no data" just return null + + b1 = base64Alphabet[d1]; + b2 = base64Alphabet[d2]; + b3 = base64Alphabet[d3]; + b4 = base64Alphabet[d4]; + + decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4); + decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)); + decodedData[encodedIndex++] = (byte) (b3 << 6 | b4); + } + + if (!isData((d1 = base64Data[dataIndex++])) + || !isData((d2 = base64Data[dataIndex++]))) { + return null;// if found "no data" just return null + } + + b1 = base64Alphabet[d1]; + b2 = base64Alphabet[d2]; + + d3 = base64Data[dataIndex++]; + d4 = base64Data[dataIndex++]; + if (!isData((d3)) || !isData((d4))) {// Check if they are PAD characters + if (isPad(d3) && isPad(d4)) { + if ((b2 & 0xf) != 0)// last 4 bits should be zero + { + return null; + } + byte[] tmp = new byte[i * 3 + 1]; + System.arraycopy(decodedData, 0, tmp, 0, i * 3); + tmp[encodedIndex] = (byte) (b1 << 2 | b2 >> 4); + return tmp; + } else if (!isPad(d3) && isPad(d4)) { + b3 = base64Alphabet[d3]; + if ((b3 & 0x3) != 0)// last 2 bits should be zero + { + return null; + } + byte[] tmp = new byte[i * 3 + 2]; + System.arraycopy(decodedData, 0, tmp, 0, i * 3); + tmp[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4); + tmp[encodedIndex] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)); + return tmp; + } else { + return null; + } + } else { // No PAD e.g 3cQl + b3 = base64Alphabet[d3]; + b4 = base64Alphabet[d4]; + decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4); + decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)); + decodedData[encodedIndex++] = (byte) (b3 << 6 | b4); + + } + + return decodedData; + } + + /** + * remove WhiteSpace from MIME containing encoded Base64 data. + * + * @param data + * the byte array of base64 data (with WS) + * @return the new length + */ + private static int removeWhiteSpace(char[] data) { + if (data == null) { + return 0; + } + + // count characters that's not whitespace + int newSize = 0; + int len = data.length; + for (int i = 0; i < len; i++) { + if (!isWhiteSpace(data[i])) { + data[newSize++] = data[i]; + } + } + return newSize; + } +} diff --git a/src/main/java/com/datao/service/alipay/SignUtils.java b/src/main/java/com/datao/service/alipay/SignUtils.java new file mode 100644 index 0000000..33fafdd --- /dev/null +++ b/src/main/java/com/datao/service/alipay/SignUtils.java @@ -0,0 +1,38 @@ +package com.datao.service.alipay; + +import java.io.UnsupportedEncodingException; +import java.security.*; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.PKCS8EncodedKeySpec; + +public class SignUtils { + + private static final String ALGORITHM = "RSA"; + + private static final String SIGN_ALGORITHMS = "SHA1WithRSA"; + + private static final String SIGN_SHA256RSA_ALGORITHMS = "SHA256WithRSA"; + + private static final String DEFAULT_CHARSET = "UTF-8"; + + private static String getAlgorithms(boolean rsa2) { + return rsa2 ? SIGN_SHA256RSA_ALGORITHMS : SIGN_ALGORITHMS; + } + + public static String sign(String content, String privateKey, boolean rsa2) throws NoSuchAlgorithmException, + InvalidKeySpecException, InvalidKeyException, + UnsupportedEncodingException, SignatureException { + PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(Base64.decode(privateKey)); + KeyFactory keyf = KeyFactory.getInstance(ALGORITHM); + PrivateKey priKey = keyf.generatePrivate(priPKCS8); + + Signature signature = Signature.getInstance(getAlgorithms(rsa2)); + + signature.initSign(priKey); + signature.update(content.getBytes(DEFAULT_CHARSET)); + + byte[] signed = signature.sign(); + + return Base64.encode(signed); + } +} diff --git a/src/main/java/com/datao/util/CaptchaUtil.java b/src/main/java/com/datao/util/CaptchaUtil.java new file mode 100644 index 0000000..16edee6 --- /dev/null +++ b/src/main/java/com/datao/util/CaptchaUtil.java @@ -0,0 +1,46 @@ +package com.datao.util; + +import com.wf.captcha.ArithmeticCaptcha; + +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; + +public class CaptchaUtil { + private static final Map captchaMap = new ConcurrentHashMap<>(); + + public static String getCaptcha(String uuid) { + // 生成验证码 + ArithmeticCaptcha captcha = new ArithmeticCaptcha(111, 36, 2); + + String code = captcha.text(); + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.MINUTE,5); + captchaMap.put(uuid+code, calendar.getTimeInMillis()); + + return captcha.toBase64(); + } + + public static Boolean verifyCaptcha(String uuid, String code) { + Long now = new Date().getTime(); + checkExpired(now); + + String verifyCode = uuid + code; + if(captchaMap.containsKey(verifyCode)) { + captchaMap.remove(verifyCode); + + return true; + } + + return false; + } + + private static void checkExpired(Long now){ + Iterator> entries = captchaMap.entrySet().iterator(); + while (entries.hasNext()){ + Map.Entry next = entries.next(); + Long exp = next.getValue(); + if(exp < now) + entries.remove(); + } + } +} diff --git a/src/main/java/com/datao/util/ParamDecoder.java b/src/main/java/com/datao/util/ParamDecoder.java new file mode 100644 index 0000000..bb53c3f --- /dev/null +++ b/src/main/java/com/datao/util/ParamDecoder.java @@ -0,0 +1,105 @@ +package com.datao.util; + +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; + +@Component +public class ParamDecoder { + private static final int SHIFT_NUM = 3; + private static final int MAX_KEY_NUM = 32; + private static final int MAX_STR_LEN = 256; + private static final byte[] base64_decode_map = { + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, + -1, 0, -1, -1, -1, 1, 0, 3, 2, 5, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 27, 26, 29, + 28, 31, 30, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, + 49, 50, 51, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; + + private byte[] Base64Decode(byte[] src){ + byte[] dst = new byte[src.length]; + for (int i=0, j=0; i > 4); + dst[j++] = (byte) ((base64_decode_map[src[i + 1]] & 0xff) << 4 | (base64_decode_map[src[i + 2]] & 0xff) >> 2); + dst[j++] = (byte) ((base64_decode_map[src[i + 2]] & 0xff) << 6 | base64_decode_map[src[i + 3]]); + } + return dst; + } + + private void ShiftCopy( byte[] buf, boolean bReverse ) + { + int shift = bReverse ? (8-SHIFT_NUM) : SHIFT_NUM; + byte mR = (byte) ((1 << (8-shift)) - 1), mL = (byte) (0xFF - mR); + + for( int i=0; i> (8-shift)) | ((ch & mR) << shift) ); + } + } + + public HashMap Decode(String inParam){ + HashMap params = null; + + byte[] src = inParam.getBytes(); + + if(src==null || src.length==0) return null; + + byte[] dst = Base64Decode( src ); + + if(dst==null || dst.length==0) return null; + + ShiftCopy(dst,true); + + int vc1 = 0, vc2 = 0; + for(int i=0; i<4; i++){ + vc1 += (dst[i] & 0xff) << (i*8); + } + for(int i=4; i0 && count<=MAX_KEY_NUM ){ + params = new HashMap(); + + for( int i=0; i=MAX_STR_LEN ) return null; + + byte[] op = new byte[lenTemp]; + for(int j=0; j=MAX_STR_LEN ) return null; + + byte[] val = new byte[lenTemp]; + for(int j=0; j hashMap){ + //默认令牌过期时间1天 + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.HOUR,6); + + //创建jwt builder + JWTCreator.Builder builder = JWT.create(); + + hashMap.forEach((k,v)-> builder.withClaim(k,v)); + + String token = builder//.withExpiresAt(calendar.getTime()) + .withSubject("subject") + .sign(Algorithm.HMAC256(SIGNATURE)); //加密 + + tokenMap.put(token, calendar.getTimeInMillis()); + + return token; + } + + private static void checkExpired(Long now){ + Iterator> entries = tokenMap.entrySet().iterator(); + while (entries.hasNext()){ + Map.Entry next = entries.next(); + Long exp = next.getValue(); + if(exp < now) + entries.remove(); + } + } + + /** + * 验证token DecodedJWT 为解密之后的对象 可以获取payload中添加的数据 + * @param token + * @return + */ + public static DecodedJWT verifyToken(String token){ + Long now = new Date().getTime(); + checkExpired(now); + + if(tokenMap.containsKey(token)){ + tokenMap.put(token, now + 21600000);//6小时 + } + else{ + throw new TokenExpiredException("状态已过期", now()); + } + //进行token的校验,注意使用同样的算法和同样的秘钥 + return JWT.require(Algorithm.HMAC256(SIGNATURE)).build().verify(token); + } + + /** + * 不验证token是否过期,获取token信息 + * @param token + * @return + */ + public static DecodedJWT decodeToken(String token){ + return JWT.decode(token); + } +} diff --git a/src/main/java/com/datao/util/page/BasePage.java b/src/main/java/com/datao/util/page/BasePage.java new file mode 100644 index 0000000..e276616 --- /dev/null +++ b/src/main/java/com/datao/util/page/BasePage.java @@ -0,0 +1,33 @@ +package com.datao.util.page; + +public class BasePage { + + private Integer pageSize; + private Integer pageNum; + + public BasePage() { + } + + public BasePage(Integer pageSize, Integer pageNum) { + super(); + this.pageSize = pageSize; + this.pageNum = pageNum; + } + + public Integer getPageSize() { + return pageSize; + } + + public void setPageSize(Integer pageSize) { + this.pageSize = pageSize; + } + + public Integer getPageNum() { + return pageNum; + } + + public void setPageNum(Integer pageNum) { + this.pageNum = pageNum; + } + +} \ No newline at end of file diff --git a/src/main/java/com/datao/util/page/PageResult.java b/src/main/java/com/datao/util/page/PageResult.java new file mode 100644 index 0000000..babafbb --- /dev/null +++ b/src/main/java/com/datao/util/page/PageResult.java @@ -0,0 +1,47 @@ +package com.datao.util.page; + +import java.util.List; + +public class PageResult { + private Long total;// 总条数 + private Long totalPage;// 总页数 + private List items;// 当前页数据 + + public PageResult() { + } + + public PageResult(Long total, List items) { + this.total = total; + this.items = items; + } + + public PageResult(Long total, Long totalPage, List items) { + this.total = total; + this.totalPage = totalPage; + this.items = items; + } + + public Long getTotal() { + return total; + } + + public void setTotal(Long total) { + this.total = total; + } + + public List getItems() { + return items; + } + + public void setItems(List items) { + this.items = items; + } + + public Long getTotalPage() { + return totalPage; + } + + public void setTotalPage(Long totalPage) { + this.totalPage = totalPage; + } +} diff --git a/src/main/java/com/datao/util/page/PageUtils.java b/src/main/java/com/datao/util/page/PageUtils.java new file mode 100644 index 0000000..debe5dc --- /dev/null +++ b/src/main/java/com/datao/util/page/PageUtils.java @@ -0,0 +1,18 @@ +package com.datao.util.page; + +public class PageUtils { + + /* 默认每页分页条数 */ + private static final Integer DEFALUT_PAGE_SIZE = 10; + /* 默认开始页码 */ + private static final Integer DEFALUT_PAGE_NUM = 1; + + public static void setDefaultPage(BasePage page) { + if (page.getPageSize() == null) { + page.setPageSize(DEFALUT_PAGE_SIZE); + } + if (page.getPageNum() == null) { + page.setPageNum(DEFALUT_PAGE_NUM); + } + } +} \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..60385e3 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,31 @@ +server: + port: 10080 + +spring: + datasource: +# type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.cj.jdbc.Driver +# url: jdbc:mysql://localhost:3306/software?serverTimezone=GMT%2B8&useSSL=false + url: jdbc:mysql:///software?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=UTF-8&allowPublicKeyRetrieval=true #/// 省略localhost:3300 + username: root + password: 168soft.xyz + + servlet: + multipart: + enabled: true + max-file-size: 100MB + max-request-size: 500MB + location: /opt/datao/upload/ #e:/datao/upload/ # + +mybatis-plus: + configuration: +# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + map-underscore-to-camel-case: true + global-config: + banner: false + db-config: + logic-delete-field: deleted + logic-delete-value: 1 + logic-not-delete-value: 0 + table-prefix: sw_ + diff --git a/src/test/java/com/datao/SwadminApplicationTests.java b/src/test/java/com/datao/SwadminApplicationTests.java new file mode 100644 index 0000000..c149280 --- /dev/null +++ b/src/test/java/com/datao/SwadminApplicationTests.java @@ -0,0 +1,44 @@ +package com.datao; + +import com.datao.controller.ApiController; +import com.datao.dao.AdminDao; +import com.datao.service.ApiService; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneOffset; + +@SpringBootTest +class SwadminApplicationTests { +// @Autowired +// private AdminDao adminDao; + +// @Test + void contextLoads() { +// List admins = adminDao.selectList(null); +// System.out.println(admins); +// String param = "bjgBBAgQf4M4OyujSnMzfxiaSyMQibFYsyuTGImAwQ=="; +// Instant timestamp = Instant.now(); +// System.out.println("当前时间戳 : " + timestamp.getEpochSecond()); +// System.out.println("System时间戳 : " + System.currentTimeMillis()); + LocalDateTime dt = LocalDateTime.ofEpochSecond(1519383600, 0, ZoneOffset.ofHours(8)); + int y = dt.getYear(); + int m = dt.getMonthValue(); + int d = dt.getDayOfMonth(); + int h = dt.getHour(); + + System.out.println(y + " " + m + " " + d + " " + h); + System.out.println(Instant.now().getEpochSecond()); + } + + @Autowired + private ApiService apiService; +// @Test + void getPredMatchs() { + String res = apiService.getPredMatches(21); + System.out.println(res); + } +}