From 3af22ea7dd8522cb5eb9d92b5565b74a3b31cfea Mon Sep 17 00:00:00 2001 From: tianea Date: Wed, 16 Feb 2022 10:45:36 +0800 Subject: [PATCH] first commit --- backend/._readme.txt | Bin 0 -> 4096 bytes backend/readme.txt | 1 + front/._readme.txt | Bin 0 -> 4096 bytes front/readme.txt | 1 + tz/.gitignore | 55 ++++++ tz/common/common-core/pom.xml | 120 ++++++++++++ .../tz/platform/common/core/base/Base.java | 38 ++++ .../common/core/base/BaseException.java | 39 ++++ .../tz/platform/common/core/base/Result.java | 86 ++++++++ .../common/core/config/SystemUtil.java | 27 +++ .../common/core/enmus/LoginStatusEnum.java | 19 ++ .../common/core/enmus/RedisPreEnum.java | 14 ++ .../common/core/enmus/ResultEnum.java | 40 ++++ .../common/core/enmus/UserTypeEnum.java | 14 ++ .../platform/common/core/tools/BeanUtils.java | 61 ++++++ .../platform/common/core/tools/HttpUtil.java | 100 ++++++++++ .../tz/platform/common/core/tools/JSUtil.java | 43 ++++ .../platform/common/core/tools/JWTUtil.java | 61 ++++++ .../platform/common/core/tools/SHA1Util.java | 50 +++++ .../src/main/resources/logback-tz.xml | 108 ++++++++++ .../src/main/resources/system.properties | 1 + .../common-core/target/classes/logback-tz.xml | 108 ++++++++++ .../target/classes/system.properties | 1 + tz/common/common-service/pom.xml | 82 ++++++++ tz/common/pom.xml | 20 ++ tz/competition/competition-service/pom.xml | 29 +++ .../competitiion/CompetitionApplication.java | 15 ++ .../competitiion/api/TestController.java | 30 +++ .../src/main/resources/bootstrap.yml | 17 ++ .../target/classes/bootstrap.yml | 17 ++ tz/competition/pom.xml | 21 ++ tz/gateway/pom.xml | 70 +++++++ .../platform/gateway/GatewayApplication.java | 13 ++ .../gateway/GlobalErrorAttributes.java | 29 +++ .../tz/platform/gateway/IndexController.java | 12 ++ .../gateway/filter/TzGlobalFilter.java | 184 ++++++++++++++++++ tz/gateway/src/main/resources/bootstrap.yml | 17 ++ tz/gateway/target/classes/bootstrap.yml | 17 ++ tz/pom.xml | 126 ++++++++++++ tz/user/pom.xml | 21 ++ tz/user/user-feign/pom.xml | 26 +++ .../tz/platform/feign/user/IFeignUser.java | 15 ++ .../com/tz/platform/feign/user/qo/UserQO.java | 57 ++++++ .../com/tz/platform/feign/user/vo/UserVo.java | 49 +++++ .../classes/META-INF/userfeign.kotlin_module | Bin 0 -> 16 bytes tz/user/user-service/pom.xml | 37 ++++ .../java/com/tz/platform/Application.java | 16 ++ .../java/com/tz/platform/entity/User.java | 118 +++++++++++ .../com/tz/platform/repository/UserDao.java | 10 + .../platform/user/api/UserInfoController.java | 24 +++ .../platform/user/api/biz/apiUserInfoBiz.java | 20 ++ .../user/api/bo/UserLoginPasswordBO.java | 32 +++ .../platform/user/api/dto/UserLoginDTO.java | 33 ++++ .../user/feign/FeignUserController.java | 25 +++ .../platform/user/feign/biz/FeignUserBiz.java | 24 +++ .../src/main/resources/bootstrap.yml | 17 ++ .../repository/UserRepositoryTest.java | 26 +++ .../user-service/target/classes/bootstrap.yml | 17 ++ 58 files changed, 2253 insertions(+) create mode 100644 backend/._readme.txt create mode 100644 backend/readme.txt create mode 100644 front/._readme.txt create mode 100644 front/readme.txt create mode 100644 tz/.gitignore create mode 100644 tz/common/common-core/pom.xml create mode 100644 tz/common/common-core/src/main/java/com/tz/platform/common/core/base/Base.java create mode 100644 tz/common/common-core/src/main/java/com/tz/platform/common/core/base/BaseException.java create mode 100644 tz/common/common-core/src/main/java/com/tz/platform/common/core/base/Result.java create mode 100644 tz/common/common-core/src/main/java/com/tz/platform/common/core/config/SystemUtil.java create mode 100644 tz/common/common-core/src/main/java/com/tz/platform/common/core/enmus/LoginStatusEnum.java create mode 100644 tz/common/common-core/src/main/java/com/tz/platform/common/core/enmus/RedisPreEnum.java create mode 100644 tz/common/common-core/src/main/java/com/tz/platform/common/core/enmus/ResultEnum.java create mode 100644 tz/common/common-core/src/main/java/com/tz/platform/common/core/enmus/UserTypeEnum.java create mode 100644 tz/common/common-core/src/main/java/com/tz/platform/common/core/tools/BeanUtils.java create mode 100644 tz/common/common-core/src/main/java/com/tz/platform/common/core/tools/HttpUtil.java create mode 100644 tz/common/common-core/src/main/java/com/tz/platform/common/core/tools/JSUtil.java create mode 100644 tz/common/common-core/src/main/java/com/tz/platform/common/core/tools/JWTUtil.java create mode 100644 tz/common/common-core/src/main/java/com/tz/platform/common/core/tools/SHA1Util.java create mode 100644 tz/common/common-core/src/main/resources/logback-tz.xml create mode 100644 tz/common/common-core/src/main/resources/system.properties create mode 100644 tz/common/common-core/target/classes/logback-tz.xml create mode 100644 tz/common/common-core/target/classes/system.properties create mode 100644 tz/common/common-service/pom.xml create mode 100644 tz/common/pom.xml create mode 100644 tz/competition/competition-service/pom.xml create mode 100644 tz/competition/competition-service/src/main/java/com/tz/platform/competitiion/CompetitionApplication.java create mode 100644 tz/competition/competition-service/src/main/java/com/tz/platform/competitiion/api/TestController.java create mode 100644 tz/competition/competition-service/src/main/resources/bootstrap.yml create mode 100644 tz/competition/competition-service/target/classes/bootstrap.yml create mode 100644 tz/competition/pom.xml create mode 100644 tz/gateway/pom.xml create mode 100644 tz/gateway/src/main/java/com/tz/platform/gateway/GatewayApplication.java create mode 100644 tz/gateway/src/main/java/com/tz/platform/gateway/GlobalErrorAttributes.java create mode 100644 tz/gateway/src/main/java/com/tz/platform/gateway/IndexController.java create mode 100644 tz/gateway/src/main/java/com/tz/platform/gateway/filter/TzGlobalFilter.java create mode 100644 tz/gateway/src/main/resources/bootstrap.yml create mode 100644 tz/gateway/target/classes/bootstrap.yml create mode 100644 tz/pom.xml create mode 100644 tz/user/pom.xml create mode 100644 tz/user/user-feign/pom.xml create mode 100644 tz/user/user-feign/src/main/java/com/tz/platform/feign/user/IFeignUser.java create mode 100644 tz/user/user-feign/src/main/java/com/tz/platform/feign/user/qo/UserQO.java create mode 100644 tz/user/user-feign/src/main/java/com/tz/platform/feign/user/vo/UserVo.java create mode 100644 tz/user/user-feign/target/classes/META-INF/userfeign.kotlin_module create mode 100644 tz/user/user-service/pom.xml create mode 100644 tz/user/user-service/src/main/java/com/tz/platform/Application.java create mode 100644 tz/user/user-service/src/main/java/com/tz/platform/entity/User.java create mode 100644 tz/user/user-service/src/main/java/com/tz/platform/repository/UserDao.java create mode 100644 tz/user/user-service/src/main/java/com/tz/platform/user/api/UserInfoController.java create mode 100644 tz/user/user-service/src/main/java/com/tz/platform/user/api/biz/apiUserInfoBiz.java create mode 100644 tz/user/user-service/src/main/java/com/tz/platform/user/api/bo/UserLoginPasswordBO.java create mode 100644 tz/user/user-service/src/main/java/com/tz/platform/user/api/dto/UserLoginDTO.java create mode 100644 tz/user/user-service/src/main/java/com/tz/platform/user/feign/FeignUserController.java create mode 100644 tz/user/user-service/src/main/java/com/tz/platform/user/feign/biz/FeignUserBiz.java create mode 100644 tz/user/user-service/src/main/resources/bootstrap.yml create mode 100644 tz/user/user-service/src/test/java/com/tz/platform/repository/UserRepositoryTest.java create mode 100644 tz/user/user-service/target/classes/bootstrap.yml diff --git a/backend/._readme.txt b/backend/._readme.txt new file mode 100644 index 0000000000000000000000000000000000000000..093bf05317907d31cdda61ca16a5ea12d1baf731 GIT binary patch literal 4096 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103v0xDsI z>d*kP`_Z(p0Hs0V;tUL;$@#f@i3J5Ysd|N_iA9NdC7F4tAno=*f*+^^As>=jQR14H zoS%}Jmku_N(GN%oFfd3V)Z`=LUiqgEqyqt^*kZTMKEX=IUj0}>^OpTJP z!465uEU_*vNz=8kHZ(RdGBmfeFi}b6Ndnn7PiK-Pi2ii)x|+WFMqypa9p$H2%>E>P zKCQmrQAl$_&n=0Xnzl9T7pZhEJIcQF9-qYIi|csxZ_F>vOlxqmUwpgls>H6db9XJ- zqP=9Atycsqr@$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103v0xDsI z>d*kP`_Z(p0Hs0V;tUL;$@#f@i3J5Ysd|N_iA9NdC7F4tAno=*f*+^^As>=jQR14H zoS%}Jmku_N(GN%oFfd3V)Z`=LUiqgEqyqt^*kZTMKEX=IUj0}>^Ow7}) z!465uEU_*vNz=8kHZ(RdGBmfeFey#pNdnooF5M33dj^J2>4lc<*48H%PFYpC%~jMZ zM(>aD0=c-Wo|{|tEqf6EG+CbSq@edLmT!7>uDdsA)dZ}q3uxK+&ABl0*WxK@4EeY2 zL|oIK`=;;t{pRl;8>gsq7qiSb_xukeOGK3hZ{~=OyOkR4U}8 drj;lp + + + common + com.tz + 1.0-SNAPSHOT + + 4.0.0 + + common-core + + + + + cn.hutool + hutool-all + 5.3.8 + + + + + com.auth0 + java-jwt + 3.10.3 + + + + + org.apache.poi + poi-ooxml + 3.17 + + + + + com.github.abel533 + ECharts + 3.0.0.6 + + + + + org.jsoup + jsoup + 1.14.2 + + + + com.itextpdf + itextpdf + 5.5.13.1 + + + + com.spring4all + swagger-spring-boot-starter + 1.9.1.RELEASE + + + com.github.xiaoymin + knife4j-spring-ui + 2.0.7 + + + + + org.apache.httpcomponents + httpclient + + + org.apache.httpcomponents + httpmime + + + + + net.logstash.logback + logstash-logback-encoder + 6.4 + + + ch.qos.logback + logback-classic + + + org.slf4j + log4j-over-slf4j + + + org.slf4j + jcl-over-slf4j + + + org.slf4j + jul-to-slf4j + + + org.projectlombok + lombok + + + + org.apache.httpcomponents + httpclient + + + org.apache.httpcomponents + httpmime + + + + org.springframework.boot + spring-boot-starter-web + + + + + \ No newline at end of file diff --git a/tz/common/common-core/src/main/java/com/tz/platform/common/core/base/Base.java b/tz/common/common-core/src/main/java/com/tz/platform/common/core/base/Base.java new file mode 100644 index 0000000..bd4296b --- /dev/null +++ b/tz/common/common-core/src/main/java/com/tz/platform/common/core/base/Base.java @@ -0,0 +1,38 @@ +package com.tz.platform.common.core.base; + +import cn.hutool.json.JSONUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.math.BigDecimal; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +public class Base { + protected static final String REGEX_MOBILE = "^((13[0-9])|(14[5,7,9])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199)\\d{8}$";// 手机号码校验 + + protected final Logger logger = LoggerFactory.getLogger(this.getClass()); + + protected static final ExecutorService callbackExecutor = Executors.newFixedThreadPool(50); + + public final static Integer FREEZE = 3;// 冻结状态 + + public final static BigDecimal LECTURER_DEFAULT_PROPORTION = BigDecimal.valueOf(0.70); // 讲师默认分成 + + public static String getString(Map map, String key) { + if (null != map.get(key)) { + return map.get(key).toString(); + } + return ""; + } + + public static Map getMap() { + return new HashMap<>(); + } + + public void log(Object obj) { + logger.info(JSONUtil.toJsonPrettyStr(obj)); + } +} diff --git a/tz/common/common-core/src/main/java/com/tz/platform/common/core/base/BaseException.java b/tz/common/common-core/src/main/java/com/tz/platform/common/core/base/BaseException.java new file mode 100644 index 0000000..3a71350 --- /dev/null +++ b/tz/common/common-core/src/main/java/com/tz/platform/common/core/base/BaseException.java @@ -0,0 +1,39 @@ +package com.tz.platform.common.core.base; + +import com.tz.platform.common.core.enmus.ResultEnum; + +public class BaseException extends RuntimeException { + /** + * 异常码 + */ + protected int code; + + public BaseException() { + super("系统异常"); + this.code = 99; + } + + public BaseException(ResultEnum resultEnum) { + super(resultEnum.getDesc()); + this.code = resultEnum.getCode(); + } + + public BaseException(String message) { + super(message); + this.code = 99; + } + + public BaseException(int code, String message) { + super(message); + this.code = code; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + +} diff --git a/tz/common/common-core/src/main/java/com/tz/platform/common/core/base/Result.java b/tz/common/common-core/src/main/java/com/tz/platform/common/core/base/Result.java new file mode 100644 index 0000000..1939bf4 --- /dev/null +++ b/tz/common/common-core/src/main/java/com/tz/platform/common/core/base/Result.java @@ -0,0 +1,86 @@ +package com.tz.platform.common.core.base; + +import com.tz.platform.common.core.enmus.ResultEnum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.Serializable; + +public class Result implements Serializable { + private static final Logger logger = LoggerFactory.getLogger(Result.class); + + private static final long serialVersionUID = 1L; + + /** + * 错误码 + */ + private Integer code = ResultEnum.ERROR.getCode(); + + /** + * 错误信息 + */ + private String msg = null; + + /** + * 返回结果实体 + */ + private T data = null; + + public Result() { + } + + private Result(int code, String msg, T data) { + this.code = code; + this.msg = msg; + this.data = data; + } + + public static Result error(String msg) { + logger.debug("返回错误:code={}, msg={}", ResultEnum.ERROR.getCode(), msg); + return new Result(ResultEnum.ERROR.getCode(), msg, null); + } + + public static Result error(ResultEnum resultEnum) { + logger.debug("返回错误:code={}, msg={}", resultEnum.getCode(), resultEnum.getDesc()); + return new Result(resultEnum.getCode(), resultEnum.getDesc(), null); + } + + public static Result error(int code, String msg) { + logger.debug("返回错误:code={}, msg={}", code, msg); + return new Result(code, msg, null); + } + + public static Result success(T data) { + return new Result(ResultEnum.SUCCESS.getCode(), "", data); + } + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } + + @Override + public String toString() { + return "Result [code=" + code + ", msg=" + msg + ", data=" + data + "]"; + } + +} diff --git a/tz/common/common-core/src/main/java/com/tz/platform/common/core/config/SystemUtil.java b/tz/common/common-core/src/main/java/com/tz/platform/common/core/config/SystemUtil.java new file mode 100644 index 0000000..0ed47c0 --- /dev/null +++ b/tz/common/common-core/src/main/java/com/tz/platform/common/core/config/SystemUtil.java @@ -0,0 +1,27 @@ +package com.tz.platform.common.core.config; + +import java.io.IOException; +import java.util.Properties; + +public class SystemUtil { + private SystemUtil() { + } + + private static final Properties properties = new Properties(); + + static { + try { + properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("system.properties")); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private static String getProperty(String keyName) { + return properties.getProperty(keyName, "").trim(); + } + + public static final String PIC_PATH = getProperty("pic_path"); + + +} diff --git a/tz/common/common-core/src/main/java/com/tz/platform/common/core/enmus/LoginStatusEnum.java b/tz/common/common-core/src/main/java/com/tz/platform/common/core/enmus/LoginStatusEnum.java new file mode 100644 index 0000000..96d9571 --- /dev/null +++ b/tz/common/common-core/src/main/java/com/tz/platform/common/core/enmus/LoginStatusEnum.java @@ -0,0 +1,19 @@ +package com.tz.platform.common.core.enmus; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum LoginStatusEnum { + SUCCESS(1, "登录成功", ""), + // + FAIL(0, "登录失败", "red"); + + private Integer code; + + private String desc; + + private String color; + +} diff --git a/tz/common/common-core/src/main/java/com/tz/platform/common/core/enmus/RedisPreEnum.java b/tz/common/common-core/src/main/java/com/tz/platform/common/core/enmus/RedisPreEnum.java new file mode 100644 index 0000000..d34241b --- /dev/null +++ b/tz/common/common-core/src/main/java/com/tz/platform/common/core/enmus/RedisPreEnum.java @@ -0,0 +1,14 @@ +package com.tz.platform.common.core.enmus; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum RedisPreEnum { + ADMINI_MENU("admini_menu_", "管理员菜单-admini_menu_"); + private String code; + + private String desc; + +} diff --git a/tz/common/common-core/src/main/java/com/tz/platform/common/core/enmus/ResultEnum.java b/tz/common/common-core/src/main/java/com/tz/platform/common/core/enmus/ResultEnum.java new file mode 100644 index 0000000..22fd120 --- /dev/null +++ b/tz/common/common-core/src/main/java/com/tz/platform/common/core/enmus/ResultEnum.java @@ -0,0 +1,40 @@ +package com.tz.platform.common.core.enmus; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum ResultEnum { + // 成功 + SUCCESS(200, "成功"), + + // token异常 + TOKEN_PAST(301, "token过期"), TOKEN_ERROR(302, "token异常"), + // 登录异常 + LOGIN_ERROR(303, "登录异常"), REMOTE_ERROR(304, "异地登录"), + + MENU_PAST(305, "菜单过期"), MENU_NO(306, "没此权限,请联系管理员!"), + + // 课程异常,4开头 + COURSE_SAVE_FAIL(403, "添加失败"), COURSE_UPDATE_FAIL(404, "更新失败"), COURSE_DELETE_FAIL(405, "删除失败"), + // + COLLECTION(406, "已收藏"), USER_ADVICE(406, "保存建议失败,不能重复提建议"), COURSE_AUDIT_FAIL(407, "审核失败"), + + // 用户异常,5开头 + LECTURER_REQUISITION_REGISTERED(501, "申请失败!该手机没注册,请先注册账号"), LECTURER_REQUISITION_WAIT(502, "申请失败!该账号已提交申请入驻成为讲师,待审核中,在7个工作日内会有相关人员与您联系确认"), LECTURER_REQUISITION_YET(503, "申请失败!该账号已成为讲师,请直接登录"), + // + USER_SAVE_FAIL(504, "添加失败"), USER_UPDATE_FAIL(505, "更新失败"), LECTURER_REQUISITION_FAIL(506, "申请失败!该账号已提交申请入驻成为讲师,审核不通过,请联系平台管理员"), USER_LECTURER_AUDIT(507, "审核失败"), USER_SEND_FAIL(508, "发送失败"), + USER_DELETE_FAIL(509, "删除失败"), + + // 系統异常,6开头 + SYSTEM_SAVE_FAIL(601, "添加失败"), SYSTEM_UPDATE_FAIL(602, "更新失败"), SYSTEM_DELETE_FAIL(603, "删除失败"), + + // 错误 + ERROR(999, "错误"); + + private Integer code; + + private String desc; + +} diff --git a/tz/common/common-core/src/main/java/com/tz/platform/common/core/enmus/UserTypeEnum.java b/tz/common/common-core/src/main/java/com/tz/platform/common/core/enmus/UserTypeEnum.java new file mode 100644 index 0000000..2b91fc1 --- /dev/null +++ b/tz/common/common-core/src/main/java/com/tz/platform/common/core/enmus/UserTypeEnum.java @@ -0,0 +1,14 @@ +package com.tz.platform.common.core.enmus; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum UserTypeEnum { + USER(1, "用户"), TEACHER(2, "教师") ,ADMIN(3,"管理员"); + + private Integer code; + + private String desc; +} diff --git a/tz/common/common-core/src/main/java/com/tz/platform/common/core/tools/BeanUtils.java b/tz/common/common-core/src/main/java/com/tz/platform/common/core/tools/BeanUtils.java new file mode 100644 index 0000000..342fc60 --- /dev/null +++ b/tz/common/common-core/src/main/java/com/tz/platform/common/core/tools/BeanUtils.java @@ -0,0 +1,61 @@ +package com.tz.platform.common.core.tools; + + +import java.io.Serializable; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class BeanUtils { + private BeanUtils() { + } + + /** + * @param source + * @param clazz + * @return + * @throws IllegalAccessException + * @throws InvocationTargetException + * @throws InstantiationException + */ + public static T copyProperties(Object source, Class clazz) { + if (source == null) { + return null; + } + T t = null; + try { + t = clazz.newInstance(); + org.springframework.beans.BeanUtils.copyProperties(source, t); + } catch (Exception e) { + e.printStackTrace(); + } + return t; + } + + /** + * @param source + * @param clazz + * @return + * @throws IllegalAccessException + * @throws InvocationTargetException + * @throws InstantiationException + */ + public static List copyProperties(List source, Class clazz) { + if (source == null || source.size() == 0) { + return Collections.emptyList(); + } + List res = new ArrayList<>(source.size()); + for (Object o : source) { + T t = null; + try { + t = clazz.newInstance(); + org.springframework.beans.BeanUtils.copyProperties(o, t); + } catch (Exception e) { + e.printStackTrace(); + } + res.add(t); + } + return res; + } +} diff --git a/tz/common/common-core/src/main/java/com/tz/platform/common/core/tools/HttpUtil.java b/tz/common/common-core/src/main/java/com/tz/platform/common/core/tools/HttpUtil.java new file mode 100644 index 0000000..fa6da71 --- /dev/null +++ b/tz/common/common-core/src/main/java/com/tz/platform/common/core/tools/HttpUtil.java @@ -0,0 +1,100 @@ +package com.tz.platform.common.core.tools; + +import com.fasterxml.jackson.databind.JsonNode; +import org.apache.http.HttpResponse; +import org.apache.http.NameValuePair; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.message.BasicHeader; +import org.apache.http.message.BasicNameValuePair; +import org.apache.http.protocol.HTTP; +import org.apache.http.util.EntityUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.client.SimpleClientHttpRequestFactory; +import org.springframework.web.client.RestTemplate; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class HttpUtil { + private static final String APPLICATION_JSON = "application/json"; + private static final String CONTENT_TYPE_TEXT_JSON = "text/json"; + private static final String CHARSET_UTF_8 = "UTF-8"; + private static final int TIMEOUT = 10000; + + private HttpUtil() { + } + + private static final Logger logger = LoggerFactory.getLogger(HttpUtil.class); + + private static SimpleClientHttpRequestFactory requestFactory = null; + + static { + requestFactory = new SimpleClientHttpRequestFactory(); + requestFactory.setConnectTimeout(60000); // 连接超时时间,单位=毫秒 + requestFactory.setReadTimeout(60000); // 读取超时时间,单位=毫秒 + } + + private static RestTemplate restTemplate = new RestTemplate(requestFactory); + + public static JsonNode postForObject(String url, Map map) { + logger.info("POST 请求, url={},map={}", url, map.toString()); + return restTemplate.postForObject(url, map, JsonNode.class); + } + + /** + * @param url + * @param param + * @return + */ + public static String postForPay(String url, Map param) { + logger.info("POST 请求, url={},map={}", url, param.toString()); + try { + HttpPost httpPost = new HttpPost(url.trim()); + RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(TIMEOUT).setConnectionRequestTimeout(TIMEOUT).setSocketTimeout(TIMEOUT).build(); + httpPost.setConfig(requestConfig); + List nvps = new ArrayList(); + for (Map.Entry entry : param.entrySet()) { + nvps.add(new BasicNameValuePair(entry.getKey(), entry.getValue().toString())); + } + StringEntity se = new UrlEncodedFormEntity(nvps, CHARSET_UTF_8); + httpPost.setEntity(se); + HttpResponse httpResponse = HttpClientBuilder.create().build().execute(httpPost); + return EntityUtils.toString(httpResponse.getEntity(), CHARSET_UTF_8); + } catch (Exception e) { + logger.info("HTTP请求出错", e); + e.printStackTrace(); + } + return ""; + } + + /** + * @param url + * @param param + * @return + */ + public static String post(String url, Map param) { + logger.info("POST 请求, url={},map={}", url, param.toString()); + try { + HttpPost httpPost = new HttpPost(url.trim()); + RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(TIMEOUT).setConnectionRequestTimeout(TIMEOUT).setSocketTimeout(TIMEOUT).build(); + httpPost.setConfig(requestConfig); + httpPost.addHeader(HTTP.CONTENT_TYPE, APPLICATION_JSON); + StringEntity se = new StringEntity(param.toString(), CHARSET_UTF_8); + se.setContentType(CONTENT_TYPE_TEXT_JSON); + se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, APPLICATION_JSON)); + httpPost.setEntity(se); + HttpResponse httpResponse = HttpClientBuilder.create().build().execute(httpPost); + return EntityUtils.toString(httpResponse.getEntity(), CHARSET_UTF_8); + } catch (Exception e) { + logger.info("HTTP请求出错", e); + e.printStackTrace(); + } + return ""; + } +} diff --git a/tz/common/common-core/src/main/java/com/tz/platform/common/core/tools/JSUtil.java b/tz/common/common-core/src/main/java/com/tz/platform/common/core/tools/JSUtil.java new file mode 100644 index 0000000..298ce4c --- /dev/null +++ b/tz/common/common-core/src/main/java/com/tz/platform/common/core/tools/JSUtil.java @@ -0,0 +1,43 @@ +package com.tz.platform.common.core.tools; + +import cn.hutool.json.JSONArray; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import lombok.extern.slf4j.Slf4j; + +import java.util.List; + +@Slf4j +public class JSUtil { + private JSUtil() { + } + + public static String toJSONString(Object obj) { + try { + return JSONUtil.toJsonStr(obj); + } catch (Exception e) { + log.error("json序列化失败", e); + return ""; + } + } + + public static T parseObject(String jsonString, Class elementClasses) { + try { + JSONObject jsonObject = JSONUtil.parseObj(jsonString); + return jsonObject.toBean(elementClasses); + } catch (Exception e) { + log.error("json解析失败,原字符串={}", jsonString); + return null; + } + } + + public static List parseArray(String jsonString, Class elementClasses) { + try { + JSONArray jsonArray = JSONUtil.parseArray(jsonString); + return jsonArray.toList(elementClasses); + } catch (Exception e) { + log.error("json解析失败,原因:", e); + return null; + } + } +} diff --git a/tz/common/common-core/src/main/java/com/tz/platform/common/core/tools/JWTUtil.java b/tz/common/common-core/src/main/java/com/tz/platform/common/core/tools/JWTUtil.java new file mode 100644 index 0000000..5ecf0f0 --- /dev/null +++ b/tz/common/common-core/src/main/java/com/tz/platform/common/core/tools/JWTUtil.java @@ -0,0 +1,61 @@ +package com.tz.platform.common.core.tools; + +import com.auth0.jwt.JWT; +import com.auth0.jwt.algorithms.Algorithm; +import com.auth0.jwt.exceptions.JWTCreationException; +import com.auth0.jwt.exceptions.JWTVerificationException; +import com.auth0.jwt.interfaces.DecodedJWT; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.UnsupportedEncodingException; +import java.util.Date; + +public class JWTUtil { + protected static final Logger logger = LoggerFactory.getLogger(JWTUtil.class); + + private static final String TOKEN_SECRET = "eyJhbGciOiJIUzI1NiJ9"; + private static final String ISSUER = "RONCOO"; + public static final String USERNO = "userNo"; + public static final Long DATE = 30 * 24 * 3600 * 1000L; // 1个月 + + /** + * @param userNo + * @param date + * @return + * @throws IllegalArgumentException + * @throws JWTCreationException + * @throws UnsupportedEncodingException + */ + public static String create(Long userNo, Long date) { + try { + return JWT.create().withIssuer(ISSUER).withClaim(USERNO, userNo.toString()).withExpiresAt(new Date(System.currentTimeMillis() + date)).sign(Algorithm.HMAC256(TOKEN_SECRET)); + } catch (Exception e) { + logger.error("JWT生成失败", e); + return ""; + } + } + + /** + * @param token + * @return + * @throws JWTVerificationException + * @throws IllegalArgumentException + * @throws UnsupportedEncodingException + */ + public static DecodedJWT verify(String token) throws JWTVerificationException, IllegalArgumentException, UnsupportedEncodingException { + return JWT.require(Algorithm.HMAC256(TOKEN_SECRET)).withIssuer(ISSUER).build().verify(token); + } + + /** + * @param decodedJWT + * @return + * @throws JWTVerificationException + * @throws IllegalArgumentException + * @throws UnsupportedEncodingException + */ + public static Long getUserNo(DecodedJWT decodedJWT) { + return Long.valueOf(decodedJWT.getClaim(USERNO).asString()); + } + +} diff --git a/tz/common/common-core/src/main/java/com/tz/platform/common/core/tools/SHA1Util.java b/tz/common/common-core/src/main/java/com/tz/platform/common/core/tools/SHA1Util.java new file mode 100644 index 0000000..b1c3638 --- /dev/null +++ b/tz/common/common-core/src/main/java/com/tz/platform/common/core/tools/SHA1Util.java @@ -0,0 +1,50 @@ +package com.tz.platform.common.core.tools; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +public class SHA1Util { + private SHA1Util() { + } + + public static final String getSign(String message) { + MessageDigest md = null; + String tmpStr = null; + try { + md = MessageDigest.getInstance("SHA-1"); + byte[] digest = md.digest(message.getBytes()); + tmpStr = byteToStr(digest); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } + return tmpStr; + } + + /** + * 将字节数组转换为十六进制字符串 + * + * @param byteArray + * @return + */ + private static String byteToStr(byte[] byteArray) { + String strDigest = ""; + for (int i = 0; i < byteArray.length; i++) { + strDigest += byteToHexStr(byteArray[i]); + } + return strDigest; + } + + /** + * 将字节转换为十六进制字符串 + * + * @param mByte + * @return + */ + private static String byteToHexStr(byte mByte) { + char[] Digit = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; + char[] tempArr = new char[2]; + tempArr[0] = Digit[(mByte >>> 4) & 0X0F]; + tempArr[1] = Digit[mByte & 0X0F]; + return new String(tempArr); + } +} diff --git a/tz/common/common-core/src/main/resources/logback-tz.xml b/tz/common/common-core/src/main/resources/logback-tz.xml new file mode 100644 index 0000000..99cd557 --- /dev/null +++ b/tz/common/common-core/src/main/resources/logback-tz.xml @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + ${PATTERN} + + + + + + + + + + + + + ${FILE_PATH}/warn + + ${FILE_PATH}/warn.%d{yyyy-MM-dd}.log + 30 + + + ${PATTERN} + + + + + ${FILE_PATH}/json + + ${FILE_PATH}/json.%d{yyyy-MM-dd}.gz + 7 + + + + + UTC + + + + { + "severity": "%level", + "service": "${springApplicationName:-}", + "trace": "%X{X-B3-TraceId:-}", + "span": "%X{X-B3-SpanId:-}", + "parent": "%X{X-B3-ParentSpanId:-}", + "exportable": "%X{X-Span-Export:-}", + "pid": "${PID:-}", + "thread": "%thread", + "class": "%logger{40}", + "rest": "%message" + } + + + + + + + + + + + + + + + + + + + ${PATTERN} + + + + + ${FILE_PATH}/info + + + ${FILE_PATH}/info.%d{yyyy-MM-dd}.log + + 7 + + + + ${PATTERN} + + + + + + + + + + + + + diff --git a/tz/common/common-core/src/main/resources/system.properties b/tz/common/common-core/src/main/resources/system.properties new file mode 100644 index 0000000..1189973 --- /dev/null +++ b/tz/common/common-core/src/main/resources/system.properties @@ -0,0 +1 @@ +pic_path=/Volumes/Lexar/www/pic \ No newline at end of file diff --git a/tz/common/common-core/target/classes/logback-tz.xml b/tz/common/common-core/target/classes/logback-tz.xml new file mode 100644 index 0000000..99cd557 --- /dev/null +++ b/tz/common/common-core/target/classes/logback-tz.xml @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + ${PATTERN} + + + + + + + + + + + + + ${FILE_PATH}/warn + + ${FILE_PATH}/warn.%d{yyyy-MM-dd}.log + 30 + + + ${PATTERN} + + + + + ${FILE_PATH}/json + + ${FILE_PATH}/json.%d{yyyy-MM-dd}.gz + 7 + + + + + UTC + + + + { + "severity": "%level", + "service": "${springApplicationName:-}", + "trace": "%X{X-B3-TraceId:-}", + "span": "%X{X-B3-SpanId:-}", + "parent": "%X{X-B3-ParentSpanId:-}", + "exportable": "%X{X-Span-Export:-}", + "pid": "${PID:-}", + "thread": "%thread", + "class": "%logger{40}", + "rest": "%message" + } + + + + + + + + + + + + + + + + + + + ${PATTERN} + + + + + ${FILE_PATH}/info + + + ${FILE_PATH}/info.%d{yyyy-MM-dd}.log + + 7 + + + + ${PATTERN} + + + + + + + + + + + + + diff --git a/tz/common/common-core/target/classes/system.properties b/tz/common/common-core/target/classes/system.properties new file mode 100644 index 0000000..1189973 --- /dev/null +++ b/tz/common/common-core/target/classes/system.properties @@ -0,0 +1 @@ +pic_path=/Volumes/Lexar/www/pic \ No newline at end of file diff --git a/tz/common/common-service/pom.xml b/tz/common/common-service/pom.xml new file mode 100644 index 0000000..314f312 --- /dev/null +++ b/tz/common/common-service/pom.xml @@ -0,0 +1,82 @@ + + + + common + com.tz + 1.0-SNAPSHOT + + 4.0.0 + + common-service + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-sentinel + + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + + + com.alibaba + druid-spring-boot-starter + 1.1.21 + + + mysql + mysql-connector-java + runtime + + + org.projectlombok + lombok + true + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + org.springframework.boot + spring-boot-configuration-processor + true + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + org.springframework.boot + spring-boot-devtools + runtime + + + + + \ No newline at end of file diff --git a/tz/common/pom.xml b/tz/common/pom.xml new file mode 100644 index 0000000..46757c9 --- /dev/null +++ b/tz/common/pom.xml @@ -0,0 +1,20 @@ + + + + platform + com.tz + 1.0-SNAPSHOT + + 4.0.0 + + common + pom + + common-service + common-core + + + + \ No newline at end of file diff --git a/tz/competition/competition-service/pom.xml b/tz/competition/competition-service/pom.xml new file mode 100644 index 0000000..de92584 --- /dev/null +++ b/tz/competition/competition-service/pom.xml @@ -0,0 +1,29 @@ + + + + competition + com.tz + 1.0-SNAPSHOT + + 4.0.0 + + competition-service + + + + com.tz + common-core + + + com.tz + common-service + + + com.tz + user-feign + + + + \ No newline at end of file diff --git a/tz/competition/competition-service/src/main/java/com/tz/platform/competitiion/CompetitionApplication.java b/tz/competition/competition-service/src/main/java/com/tz/platform/competitiion/CompetitionApplication.java new file mode 100644 index 0000000..b68e817 --- /dev/null +++ b/tz/competition/competition-service/src/main/java/com/tz/platform/competitiion/CompetitionApplication.java @@ -0,0 +1,15 @@ +package com.tz.platform.competitiion; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; + +@SpringBootApplication +@EnableDiscoveryClient +@EnableFeignClients(basePackages = "com.tz.platform.feign") +public class CompetitionApplication { + public static void main(String[] args) { + SpringApplication.run(CompetitionApplication.class,args); + } +} diff --git a/tz/competition/competition-service/src/main/java/com/tz/platform/competitiion/api/TestController.java b/tz/competition/competition-service/src/main/java/com/tz/platform/competitiion/api/TestController.java new file mode 100644 index 0000000..d551557 --- /dev/null +++ b/tz/competition/competition-service/src/main/java/com/tz/platform/competitiion/api/TestController.java @@ -0,0 +1,30 @@ +package com.tz.platform.competitiion.api; + +import com.tz.platform.common.core.base.Result; +import com.tz.platform.feign.user.IFeignUser; +import com.tz.platform.feign.user.vo.UserVo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping(value = "/api/competition") +public class TestController { + + @Autowired + private IFeignUser iFeignUser; + + @GetMapping(value = "/user/{userNo}") + public String getUserByNo(@PathVariable(value = "userNo") Long userNo){ + UserVo user = iFeignUser.getByUserNo(userNo); + return user.getMobile(); + } + + @GetMapping(value = "/get/user/mobile/{mobile}") + public Result getByMobile(@PathVariable(value = "mobile") String mobile){ + UserVo user = iFeignUser.getByMobile(mobile); + return Result.success(user.getId()); + } +} diff --git a/tz/competition/competition-service/src/main/resources/bootstrap.yml b/tz/competition/competition-service/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..0b6e2ae --- /dev/null +++ b/tz/competition/competition-service/src/main/resources/bootstrap.yml @@ -0,0 +1,17 @@ +server: + port: 50012 +spring: + application: + name: tz-competition-service + profiles: + active: dev + cloud: + nacos: + server-addr: 127.0.0.1:8848 + username: nacos + password: nacos + config: + namespace: ${spring.profiles.active} + file-extension: yaml + discovery: + namespace: ${spring.profiles.active} \ No newline at end of file diff --git a/tz/competition/competition-service/target/classes/bootstrap.yml b/tz/competition/competition-service/target/classes/bootstrap.yml new file mode 100644 index 0000000..0b6e2ae --- /dev/null +++ b/tz/competition/competition-service/target/classes/bootstrap.yml @@ -0,0 +1,17 @@ +server: + port: 50012 +spring: + application: + name: tz-competition-service + profiles: + active: dev + cloud: + nacos: + server-addr: 127.0.0.1:8848 + username: nacos + password: nacos + config: + namespace: ${spring.profiles.active} + file-extension: yaml + discovery: + namespace: ${spring.profiles.active} \ No newline at end of file diff --git a/tz/competition/pom.xml b/tz/competition/pom.xml new file mode 100644 index 0000000..2afaa3b --- /dev/null +++ b/tz/competition/pom.xml @@ -0,0 +1,21 @@ + + + + platform + com.tz + 1.0-SNAPSHOT + + 4.0.0 + + competition + pom + + competition-service + + + + + + \ No newline at end of file diff --git a/tz/gateway/pom.xml b/tz/gateway/pom.xml new file mode 100644 index 0000000..9b9570f --- /dev/null +++ b/tz/gateway/pom.xml @@ -0,0 +1,70 @@ + + + + platform + com.tz + 1.0-SNAPSHOT + + 4.0.0 + + gateway + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + + + org.springframework.cloud + spring-cloud-starter-gateway + + + + org.springframework.boot + spring-boot-starter-data-redis + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-devtools + + + com.tz + common-core + + + org.springframework.boot + spring-boot-starter-web + + + + + + + app-gateway + + + org.springframework.boot + spring-boot-maven-plugin + + + org.sonarsource.scanner.maven + sonar-maven-plugin + + + + + + \ No newline at end of file diff --git a/tz/gateway/src/main/java/com/tz/platform/gateway/GatewayApplication.java b/tz/gateway/src/main/java/com/tz/platform/gateway/GatewayApplication.java new file mode 100644 index 0000000..2526920 --- /dev/null +++ b/tz/gateway/src/main/java/com/tz/platform/gateway/GatewayApplication.java @@ -0,0 +1,13 @@ +package com.tz.platform.gateway; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; + +@SpringBootApplication +@EnableDiscoveryClient +public class GatewayApplication { + public static void main(String[] args) { + SpringApplication.run(GatewayApplication.class,args); + } +} diff --git a/tz/gateway/src/main/java/com/tz/platform/gateway/GlobalErrorAttributes.java b/tz/gateway/src/main/java/com/tz/platform/gateway/GlobalErrorAttributes.java new file mode 100644 index 0000000..9d83c01 --- /dev/null +++ b/tz/gateway/src/main/java/com/tz/platform/gateway/GlobalErrorAttributes.java @@ -0,0 +1,29 @@ +package com.tz.platform.gateway; + +import com.tz.platform.common.core.base.BaseException; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.web.error.ErrorAttributeOptions; +import org.springframework.boot.web.reactive.error.DefaultErrorAttributes; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.server.ServerRequest; + +import java.util.Map; + +@Component +@Slf4j +public class GlobalErrorAttributes extends DefaultErrorAttributes { + @Override + public Map getErrorAttributes(ServerRequest request, ErrorAttributeOptions options) { + Map map = super.getErrorAttributes(request, options); + log.error("系统异常,{}", map); + map.put("status", HttpStatus.OK.value()); + Throwable error = this.getError(request); + if (error instanceof BaseException) { + BaseException be = (BaseException) error; + map.put("code", be.getCode()); + map.put("msg", be.getMessage()); + } + return map; + } +} diff --git a/tz/gateway/src/main/java/com/tz/platform/gateway/IndexController.java b/tz/gateway/src/main/java/com/tz/platform/gateway/IndexController.java new file mode 100644 index 0000000..ea3716f --- /dev/null +++ b/tz/gateway/src/main/java/com/tz/platform/gateway/IndexController.java @@ -0,0 +1,12 @@ +package com.tz.platform.gateway; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; +import reactor.core.publisher.Mono; + +@RestController +public class IndexController { + + @GetMapping("/") + public Mono index(){ return Mono.just("success");} +} diff --git a/tz/gateway/src/main/java/com/tz/platform/gateway/filter/TzGlobalFilter.java b/tz/gateway/src/main/java/com/tz/platform/gateway/filter/TzGlobalFilter.java new file mode 100644 index 0000000..415468d --- /dev/null +++ b/tz/gateway/src/main/java/com/tz/platform/gateway/filter/TzGlobalFilter.java @@ -0,0 +1,184 @@ +package com.tz.platform.gateway.filter; + +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import com.auth0.jwt.interfaces.DecodedJWT; +import com.tz.platform.common.core.base.BaseException; +import com.tz.platform.common.core.enmus.RedisPreEnum; +import com.tz.platform.common.core.enmus.ResultEnum; +import com.tz.platform.common.core.tools.JSUtil; +import com.tz.platform.common.core.tools.JWTUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cloud.gateway.filter.GatewayFilterChain; +import org.springframework.cloud.gateway.filter.GlobalFilter; +import org.springframework.cloud.gateway.filter.factory.rewrite.CachedBodyOutputMessage; +import org.springframework.cloud.gateway.support.BodyInserterContext; +import org.springframework.core.annotation.Order; +import org.springframework.core.io.buffer.DataBuffer; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.server.reactive.ServerHttpRequest; +import org.springframework.http.server.reactive.ServerHttpRequestDecorator; +import org.springframework.util.StringUtils; +import org.springframework.web.reactive.function.BodyInserter; +import org.springframework.web.reactive.function.BodyInserters; +import org.springframework.web.reactive.function.server.HandlerStrategies; +import org.springframework.web.reactive.function.server.ServerRequest; +import org.springframework.web.server.ServerWebExchange; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +@Order(0) +public class TzGlobalFilter implements GlobalFilter { + private static final Logger logger = LoggerFactory.getLogger(TzGlobalFilter.class); + + private static final String TOKEN = "token"; + private static final String USERNO = "userNo"; + + @Autowired + private StringRedisTemplate stringRedisTemplate; + + @Override + public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { + ServerHttpRequest request = exchange.getRequest(); + String uri = request.getPath().value(); + if (uri.contains("/callback")) { + // 第三方回调接口,不鉴权 + return chain.filter(exchange); + } + if (uri.contains("/api")) { + // 路径存在关键词:/api,不鉴权 + return chain.filter(exchange); + } + + // 解析token + Long userNo = getUserNoByToken(request); + if (uri.contains("/pc") && !uri.contains("/system/pc/menu/user/list") && !uri.contains("/system/pc/menu/user/button/list")) { + // 管理后台鉴权 + if (!stringRedisTemplate.hasKey(RedisPreEnum.ADMINI_MENU.getCode().concat(userNo.toString()))) { + throw new BaseException(ResultEnum.MENU_PAST); + } + String tk = stringRedisTemplate.opsForValue().get(RedisPreEnum.ADMINI_MENU.getCode().concat(userNo.toString())); + // 校验接口是否有权限 + if (!checkUri(uri, tk)) { + throw new BaseException(ResultEnum.MENU_NO); + } + // 更新时间,使用户菜单不过期 + stringRedisTemplate.opsForValue().set(RedisPreEnum.ADMINI_MENU.getCode().concat(userNo.toString()), tk, 1, TimeUnit.HOURS); + } + return request(exchange, chain, modifiedBody(exchange, userNo)); + } + + // 校验用户是否有权限 + private static Boolean checkUri(String uri, String tk) { + List menuVOList1 = JSUtil.parseArray(tk, String.class); + if (StringUtils.hasText(uri) && uri.endsWith("/")) { + uri = uri.substring(0, uri.length() - 1); + } + for (String s : menuVOList1) { + if (s.contains(uri)) { + return true; + } + } + return false; + } + + + + private Mono modifiedBody(ServerWebExchange serverWebExchange, Long userNo) { + MediaType mediaType = serverWebExchange.getRequest().getHeaders().getContentType(); + ServerRequest serverRequest = ServerRequest.create(serverWebExchange, HandlerStrategies.withDefaults().messageReaders()); + return serverRequest.bodyToMono(String.class).flatMap(body -> { + JSONObject bodyJson; + if (MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(mediaType)) { + Map bodyMap = decodeBody(body); + bodyJson = JSONUtil.parseObj(bodyMap); + } else { + bodyJson = JSONUtil.parseObj(body); + } + if (ObjectUtil.isNotNull(userNo)) { + bodyJson.set(USERNO, userNo); + } + return Mono.just(JSONUtil.toJsonStr(bodyJson)); + }); + } + + private Map decodeBody(String body) { + return Arrays.stream(body.split("&")).map(s -> s.split("=")).collect(Collectors.toMap(arr -> arr[0], arr -> arr[1])); + } + + private Mono request(ServerWebExchange exchange, GatewayFilterChain chain, Mono modifiedBody) { + BodyInserter bodyInserter = BodyInserters.fromPublisher(modifiedBody, String.class); + HttpHeaders headers = new HttpHeaders(); + headers.putAll(exchange.getRequest().getHeaders()); + headers.remove(HttpHeaders.CONTENT_LENGTH); + CachedBodyOutputMessage outputMessage = new CachedBodyOutputMessage(exchange, headers); + return bodyInserter.insert(outputMessage, new BodyInserterContext()) + .then(Mono.defer(() -> { + ServerHttpRequestDecorator decorator = + new ServerHttpRequestDecorator(exchange.getRequest()) { + @Override + public HttpHeaders getHeaders() { + return headers; + } + + @Override + public Flux getBody() { + return outputMessage.getBody(); + } + }; + return chain.filter(exchange.mutate().request(decorator).build()); + })); + } + + private Long getUserNoByToken(ServerHttpRequest request) { + // 头部 + String token = request.getHeaders().getFirst(TOKEN); + if (StringUtils.isEmpty(token)) { // token不存在,则从报文里面获取 + throw new BaseException("token不存在,请重新登录"); + } + // 解析 token + DecodedJWT jwt = null; + try { + jwt = JWTUtil.verify(token); + } catch (Exception e) { + logger.error("token异常,token={}", token.toString()); + throw new BaseException(ResultEnum.TOKEN_ERROR); + } + + // 校验token + if (null == jwt) { + throw new BaseException(ResultEnum.TOKEN_ERROR); + } + Long userNo = JWTUtil.getUserNo(jwt); + if (userNo <= 0) { + throw new BaseException(ResultEnum.TOKEN_ERROR); + } + + // 单点登录处理,注意,登录的时候必须要放入缓存 +// if (!stringRedisTemplate.hasKey(userNo.toString())) { +// // 不存在,则登录异常,有效期为1小时 +// throw new BaseException(ResultEnum.TOKEN_PAST); +// } +// // 存在,判断是否token相同 +// String tk = stringRedisTemplate.opsForValue().get(userNo.toString()); +// if (!token.equals(tk)) { +// // 不同则为不同的用户登录,这时候提示异地登录 +// throw new BaseException(ResultEnum.REMOTE_ERROR); +// } + + // 更新时间,使token不过期 + stringRedisTemplate.opsForValue().set(userNo.toString(), token, 1, TimeUnit.HOURS); + return userNo; + } +} diff --git a/tz/gateway/src/main/resources/bootstrap.yml b/tz/gateway/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..71dbc38 --- /dev/null +++ b/tz/gateway/src/main/resources/bootstrap.yml @@ -0,0 +1,17 @@ +spring: + application: + name: tz-gateway + cloud: + nacos: + username: nacos + password: nacos + discovery: + server-addr: 127.0.0.1:8848 + namespace: ${spring.profiles.active} + config: + file-extension: yaml + namespace: ${spring.profiles.active} + profiles: + active: dev +server: + port: 50010 \ No newline at end of file diff --git a/tz/gateway/target/classes/bootstrap.yml b/tz/gateway/target/classes/bootstrap.yml new file mode 100644 index 0000000..71dbc38 --- /dev/null +++ b/tz/gateway/target/classes/bootstrap.yml @@ -0,0 +1,17 @@ +spring: + application: + name: tz-gateway + cloud: + nacos: + username: nacos + password: nacos + discovery: + server-addr: 127.0.0.1:8848 + namespace: ${spring.profiles.active} + config: + file-extension: yaml + namespace: ${spring.profiles.active} + profiles: + active: dev +server: + port: 50010 \ No newline at end of file diff --git a/tz/pom.xml b/tz/pom.xml new file mode 100644 index 0000000..cba95da --- /dev/null +++ b/tz/pom.xml @@ -0,0 +1,126 @@ + + + 4.0.0 + + com.tz + platform + pom + 1.0-SNAPSHOT + + common + user + gateway + competition + + + + 1.8 + UTF-8 + UTF-8 + + + + + + + org.springframework.boot + spring-boot-starter-parent + 2.3.5.RELEASE + pom + import + + + + + org.springframework.cloud + spring-cloud-dependencies + Hoxton.SR9 + pom + import + + + + + com.alibaba.cloud + spring-cloud-alibaba-dependencies + 2.2.6.RELEASE + pom + import + + + com.tz + common-service + ${project.version} + + + + com.tz + common-core + ${project.version} + + + com.tz + user-feign + ${project.version} + + + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + true + + + + package + + repackage + build-info + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + ${java.version} + ${java.version} + true + ${project.build.sourceEncoding} + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tz/user/pom.xml b/tz/user/pom.xml new file mode 100644 index 0000000..d1f86e4 --- /dev/null +++ b/tz/user/pom.xml @@ -0,0 +1,21 @@ + + + + platform + com.tz + 1.0-SNAPSHOT + + 4.0.0 + + user + pom + + user-service + user-feign + + + + + \ No newline at end of file diff --git a/tz/user/user-feign/pom.xml b/tz/user/user-feign/pom.xml new file mode 100644 index 0000000..ea03bd3 --- /dev/null +++ b/tz/user/user-feign/pom.xml @@ -0,0 +1,26 @@ + + + + user + com.tz + 1.0-SNAPSHOT + + 4.0.0 + + user-feign + + + + com.tz + common-core + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + + + \ No newline at end of file diff --git a/tz/user/user-feign/src/main/java/com/tz/platform/feign/user/IFeignUser.java b/tz/user/user-feign/src/main/java/com/tz/platform/feign/user/IFeignUser.java new file mode 100644 index 0000000..6cf1a9f --- /dev/null +++ b/tz/user/user-feign/src/main/java/com/tz/platform/feign/user/IFeignUser.java @@ -0,0 +1,15 @@ +package com.tz.platform.feign.user; + +import com.tz.platform.feign.user.vo.UserVo; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; + +@FeignClient(value = "tz-user-service") +public interface IFeignUser { + + @GetMapping(value = "/feign/user/getByUserNo/{userNo}") + UserVo getByUserNo(@PathVariable(value = "userNo") Long userNo); + @GetMapping(value = "/feign/user/getByMobile/{mobile}") + UserVo getByMobile(@PathVariable(value = "mobile") String mobile); +} diff --git a/tz/user/user-feign/src/main/java/com/tz/platform/feign/user/qo/UserQO.java b/tz/user/user-feign/src/main/java/com/tz/platform/feign/user/qo/UserQO.java new file mode 100644 index 0000000..348a09d --- /dev/null +++ b/tz/user/user-feign/src/main/java/com/tz/platform/feign/user/qo/UserQO.java @@ -0,0 +1,57 @@ +package com.tz.platform.feign.user.qo; + +import lombok.Data; +import lombok.experimental.Accessors; + +import java.util.Date; + +@Data +@Accessors(chain = true) +public class UserQO { + private static final long serialVersionUID = 1L; + + /** + * 当前页 + */ + private int pageCurrent; + /** + * 每页记录数 + */ + private int pageSize; + /** + * 主键 + */ + private Long id; + /** + * 创建时间 + */ + private Date gmtCreate; + /** + * 修改时间 + */ + private Date gmtModified; + /** + * 状态(1:正常,0:禁用) + */ + private Integer statusId; + /** + * 用户编号 + */ + private Long userNo; + /** + * 手机号码 + */ + private String mobile; + /** + * 密码盐 + */ + private String mobileSalt; + /** + * 登录密码 + */ + private String mobilePsw; + /** + * 用户来源(client_id) + */ + private String userSource; +} diff --git a/tz/user/user-feign/src/main/java/com/tz/platform/feign/user/vo/UserVo.java b/tz/user/user-feign/src/main/java/com/tz/platform/feign/user/vo/UserVo.java new file mode 100644 index 0000000..41ca3e6 --- /dev/null +++ b/tz/user/user-feign/src/main/java/com/tz/platform/feign/user/vo/UserVo.java @@ -0,0 +1,49 @@ +package com.tz.platform.feign.user.vo; + +import lombok.Data; +import lombok.experimental.Accessors; + +import java.util.Date; + +@Data +@Accessors(chain = true) +public class UserVo { + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + private Long id; + /** + * 创建时间 + */ + private Date gmtCreate; + /** + * 修改时间 + */ + private Date gmtModified; + /** + * 状态(1:正常,0:禁用) + */ + private Integer statusId; + /** + * 用户编号 + */ + private Long userNo; + /** + * 手机号码 + */ + private String mobile; + /** + * 密码盐 + */ + private String mobileSalt; + /** + * 登录密码 + */ + private String mobilePsw; + /** + * 用户来源(client_id) + */ + private String userSource; +} diff --git a/tz/user/user-feign/target/classes/META-INF/userfeign.kotlin_module b/tz/user/user-feign/target/classes/META-INF/userfeign.kotlin_module new file mode 100644 index 0000000000000000000000000000000000000000..8fb60192d378759239a3ecbf60eac8c8de446e9c GIT binary patch literal 16 RcmZQzU|?ooU|@t|UH|}6022TJ literal 0 HcmV?d00001 diff --git a/tz/user/user-service/pom.xml b/tz/user/user-service/pom.xml new file mode 100644 index 0000000..a1f1b61 --- /dev/null +++ b/tz/user/user-service/pom.xml @@ -0,0 +1,37 @@ + + + + user + com.tz + 1.0-SNAPSHOT + + 4.0.0 + + user-service + + + + com.tz + common-service + + + com.tz + common-core + + + + org.springframework.boot + spring-boot-starter-test + test + + + com.tz + user-feign + + + + + + \ No newline at end of file diff --git a/tz/user/user-service/src/main/java/com/tz/platform/Application.java b/tz/user/user-service/src/main/java/com/tz/platform/Application.java new file mode 100644 index 0000000..cfc68d4 --- /dev/null +++ b/tz/user/user-service/src/main/java/com/tz/platform/Application.java @@ -0,0 +1,16 @@ +package com.tz.platform; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; + + +@SpringBootApplication +@EnableDiscoveryClient +@EnableFeignClients +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class,args); + } +} diff --git a/tz/user/user-service/src/main/java/com/tz/platform/entity/User.java b/tz/user/user-service/src/main/java/com/tz/platform/entity/User.java new file mode 100644 index 0000000..c066c7a --- /dev/null +++ b/tz/user/user-service/src/main/java/com/tz/platform/entity/User.java @@ -0,0 +1,118 @@ +package com.tz.platform.entity; + +import javax.persistence.*; +import java.util.Date; + +@Entity +@Table(name = "user") +public class User { + + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + private Long id; + + private Date gmtCreate; + + private Date gmtModified; + + private Integer statusId; + + private Long userNo; + + private String mobile; + + private String userName; + + private String studentNo; + + private String mobileSalt; + + private String mobilePsw; + + + private static final long serialVersionUID = 1L; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Date getGmtCreate() { + return gmtCreate; + } + + public void setGmtCreate(Date gmtCreate) { + this.gmtCreate = gmtCreate; + } + + public Date getGmtModified() { + return gmtModified; + } + + public void setGmtModified(Date gmtModified) { + this.gmtModified = gmtModified; + } + + public Integer getStatusId() { + return statusId; + } + + public void setStatusId(Integer statusId) { + this.statusId = statusId; + } + + public Long getUserNo() { + return userNo; + } + + public void setUserNo(Long userNo) { + this.userNo = userNo; + } + + public String getMobile() { + return mobile; + } + + public void setMobile(String mobile) { + this.mobile = mobile == null ? null : mobile.trim(); + } + + public String getMobileSalt() { + return mobileSalt; + } + + public void setMobileSalt(String mobileSalt) { + this.mobileSalt = mobileSalt == null ? null : mobileSalt.trim(); + } + + public String getMobilePsw() { + return mobilePsw; + } + + public void setMobilePsw(String mobilePsw) { + this.mobilePsw = mobilePsw == null ? null : mobilePsw.trim(); + } + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()); + sb.append(" ["); + sb.append("Hash = ").append(hashCode()); + sb.append(", id=").append(id); + sb.append(", gmtCreate=").append(gmtCreate); + sb.append(", gmtModified=").append(gmtModified); + sb.append(", statusId=").append(statusId); + sb.append(", userNo=").append(userNo); + sb.append(", mobile=").append(mobile); + sb.append(", mobileSalt=").append(mobileSalt); + sb.append(", mobilePsw=").append(mobilePsw); + sb.append(", serialVersionUID=").append(serialVersionUID); + sb.append("]"); + return sb.toString(); + } +} diff --git a/tz/user/user-service/src/main/java/com/tz/platform/repository/UserDao.java b/tz/user/user-service/src/main/java/com/tz/platform/repository/UserDao.java new file mode 100644 index 0000000..65949fe --- /dev/null +++ b/tz/user/user-service/src/main/java/com/tz/platform/repository/UserDao.java @@ -0,0 +1,10 @@ +package com.tz.platform.repository; + +import com.tz.platform.entity.User; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface UserDao extends JpaRepository { + User findByMobile(String mobile); +} diff --git a/tz/user/user-service/src/main/java/com/tz/platform/user/api/UserInfoController.java b/tz/user/user-service/src/main/java/com/tz/platform/user/api/UserInfoController.java new file mode 100644 index 0000000..cfa6752 --- /dev/null +++ b/tz/user/user-service/src/main/java/com/tz/platform/user/api/UserInfoController.java @@ -0,0 +1,24 @@ +package com.tz.platform.user.api; + +import com.tz.platform.entity.User; +import com.tz.platform.repository.UserDao; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequestMapping(path = "/api/user") +public class UserInfoController { + + @Autowired + UserDao userDao; + + @GetMapping(path = "test") + public String test(){ + List userList = userDao.findAll(); + return "user count:"+userList.size(); + } +} diff --git a/tz/user/user-service/src/main/java/com/tz/platform/user/api/biz/apiUserInfoBiz.java b/tz/user/user-service/src/main/java/com/tz/platform/user/api/biz/apiUserInfoBiz.java new file mode 100644 index 0000000..5022353 --- /dev/null +++ b/tz/user/user-service/src/main/java/com/tz/platform/user/api/biz/apiUserInfoBiz.java @@ -0,0 +1,20 @@ +package com.tz.platform.user.api.biz; + +import com.tz.platform.common.core.base.Result; +import com.tz.platform.repository.UserDao; +import com.tz.platform.user.api.bo.UserLoginPasswordBO; +import com.tz.platform.user.api.dto.UserLoginDTO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class apiUserInfoBiz { + + @Autowired + private UserDao userDao; + + public Result loginPassword(UserLoginPasswordBO userLoginPasswordBO){ + UserLoginDTO userLoginDTO = new UserLoginDTO(); + return Result.success(userLoginDTO); + } +} diff --git a/tz/user/user-service/src/main/java/com/tz/platform/user/api/bo/UserLoginPasswordBO.java b/tz/user/user-service/src/main/java/com/tz/platform/user/api/bo/UserLoginPasswordBO.java new file mode 100644 index 0000000..930d056 --- /dev/null +++ b/tz/user/user-service/src/main/java/com/tz/platform/user/api/bo/UserLoginPasswordBO.java @@ -0,0 +1,32 @@ +package com.tz.platform.user.api.bo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +@Data +@Accessors(chain = true) +public class UserLoginPasswordBO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 手机号码 + */ + @ApiModelProperty(value = "手机号", required = true) + private String mobile; + /** + * 登录密码 + */ + @ApiModelProperty(value = "密码", required = true) + private String password; + /** + * clientId + */ + @ApiModelProperty(value = "clientId", required = true) + private String clientId; + + private String ip; +} diff --git a/tz/user/user-service/src/main/java/com/tz/platform/user/api/dto/UserLoginDTO.java b/tz/user/user-service/src/main/java/com/tz/platform/user/api/dto/UserLoginDTO.java new file mode 100644 index 0000000..37515e8 --- /dev/null +++ b/tz/user/user-service/src/main/java/com/tz/platform/user/api/dto/UserLoginDTO.java @@ -0,0 +1,33 @@ +package com.tz.platform.user.api.dto; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +@Data +@Accessors(chain = true) +public class UserLoginDTO implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 用户编号 + */ + @ApiModelProperty(value = "用户编号") + @JsonSerialize(using = ToStringSerializer.class) + private Long userNo; + /** + * 手机号码 + */ + @ApiModelProperty(value = "手机号") + private String mobile; + /** + * token,设置有效期为1天 + */ + @ApiModelProperty(value = "token,有效期为1天") + private String token; + +} diff --git a/tz/user/user-service/src/main/java/com/tz/platform/user/feign/FeignUserController.java b/tz/user/user-service/src/main/java/com/tz/platform/user/feign/FeignUserController.java new file mode 100644 index 0000000..c5ffacb --- /dev/null +++ b/tz/user/user-service/src/main/java/com/tz/platform/user/feign/FeignUserController.java @@ -0,0 +1,25 @@ +package com.tz.platform.user.feign; + +import com.tz.platform.user.feign.biz.FeignUserBiz; +import com.tz.platform.feign.user.IFeignUser; +import com.tz.platform.feign.user.vo.UserVo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class FeignUserController implements IFeignUser { + + @Autowired + private FeignUserBiz feignUserBiz; + + @Override + public UserVo getByUserNo(@PathVariable(value = "userNo") Long userNo) { + return feignUserBiz.getByUserNo(userNo); + } + + @Override + public UserVo getByMobile(@PathVariable(value = "mobile") String mobile){ + return feignUserBiz.getByMobile(mobile); + } +} diff --git a/tz/user/user-service/src/main/java/com/tz/platform/user/feign/biz/FeignUserBiz.java b/tz/user/user-service/src/main/java/com/tz/platform/user/feign/biz/FeignUserBiz.java new file mode 100644 index 0000000..06ab827 --- /dev/null +++ b/tz/user/user-service/src/main/java/com/tz/platform/user/feign/biz/FeignUserBiz.java @@ -0,0 +1,24 @@ +package com.tz.platform.user.feign.biz; + +import com.tz.platform.common.core.tools.BeanUtils; +import com.tz.platform.entity.User; +import com.tz.platform.repository.UserDao; +import com.tz.platform.feign.user.vo.UserVo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class FeignUserBiz { + @Autowired + private UserDao userDao; + + public UserVo getByUserNo(Long userNo){ + User user = userDao.findById(userNo).get(); + return BeanUtils.copyProperties(user,UserVo.class); + } + + public UserVo getByMobile(String mobile){ + User user = userDao.findByMobile(mobile); + return BeanUtils.copyProperties(user,UserVo.class); + } +} diff --git a/tz/user/user-service/src/main/resources/bootstrap.yml b/tz/user/user-service/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..81b6d3e --- /dev/null +++ b/tz/user/user-service/src/main/resources/bootstrap.yml @@ -0,0 +1,17 @@ +server: + port: 50011 +spring: + application: + name: tz-user-service + profiles: + active: dev + cloud: + nacos: + server-addr: 127.0.0.1:8848 + username: nacos + password: nacos + config: + namespace: ${spring.profiles.active} + file-extension: yaml + discovery: + namespace: ${spring.profiles.active} diff --git a/tz/user/user-service/src/test/java/com/tz/platform/repository/UserRepositoryTest.java b/tz/user/user-service/src/test/java/com/tz/platform/repository/UserRepositoryTest.java new file mode 100644 index 0000000..50bcac2 --- /dev/null +++ b/tz/user/user-service/src/test/java/com/tz/platform/repository/UserRepositoryTest.java @@ -0,0 +1,26 @@ +package com.tz.platform.repository; + +import com.tz.platform.entity.User; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.Rollback; + +@SpringBootTest +public class UserRepositoryTest { + @Autowired + private UserDao userDao; + + @Test + @Rollback + public void userSaveTest(){ + User user = new User(); + user.setUserNo(1L); + user.setMobile("18600024112"); + user.setMobileSalt(""); + user.setMobilePsw("11111111"); + user.setUserSource("1123123"); + userDao.save(user); + } + +} diff --git a/tz/user/user-service/target/classes/bootstrap.yml b/tz/user/user-service/target/classes/bootstrap.yml new file mode 100644 index 0000000..81b6d3e --- /dev/null +++ b/tz/user/user-service/target/classes/bootstrap.yml @@ -0,0 +1,17 @@ +server: + port: 50011 +spring: + application: + name: tz-user-service + profiles: + active: dev + cloud: + nacos: + server-addr: 127.0.0.1:8848 + username: nacos + password: nacos + config: + namespace: ${spring.profiles.active} + file-extension: yaml + discovery: + namespace: ${spring.profiles.active}