45 changed files with 0 additions and 1631 deletions
@ -1,25 +0,0 @@ |
|||
-- 用户表 |
|||
CREATE TABLE tb_user ( |
|||
id bigint NOT NULL COMMENT 'id', |
|||
username varchar(50) NOT NULL COMMENT '用户名', |
|||
mobile varchar(20) NOT NULL COMMENT '手机号', |
|||
password varchar(64) COMMENT '密码', |
|||
create_date datetime COMMENT '创建时间', |
|||
PRIMARY KEY (id), |
|||
UNIQUE INDEX (username) |
|||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户'; |
|||
|
|||
-- 用户Token表 |
|||
CREATE TABLE tb_token ( |
|||
id bigint NOT NULL COMMENT 'id', |
|||
user_id bigint NOT NULL COMMENT '用户ID', |
|||
token varchar(100) NOT NULL COMMENT 'token', |
|||
expire_date datetime COMMENT '过期时间', |
|||
update_date datetime COMMENT '更新时间', |
|||
PRIMARY KEY (id), |
|||
UNIQUE INDEX (user_id), |
|||
UNIQUE INDEX (token) |
|||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户Token'; |
|||
|
|||
-- 账号:13612345678 密码:admin |
|||
INSERT INTO tb_user (id, username, mobile, password, create_date) VALUES (1067246875800000168, 'mark', '13612345678', '8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918', now()); |
@ -1,24 +0,0 @@ |
|||
CREATE TABLE tb_user ( |
|||
id NUMBER(20, 0) NOT NULL, |
|||
username varchar(50) NOT NULL, |
|||
mobile varchar(20) NOT NULL, |
|||
password varchar(64), |
|||
create_date date, |
|||
PRIMARY KEY (id) |
|||
); |
|||
CREATE UNIQUE INDEX idx_user_username on tb_user(username); |
|||
|
|||
CREATE TABLE tb_token ( |
|||
id NUMBER(20, 0) NOT NULL, |
|||
user_id NUMBER(20, 0) NOT NULL, |
|||
token varchar(100) NOT NULL, |
|||
expire_date date, |
|||
update_date date, |
|||
PRIMARY KEY (id) |
|||
); |
|||
CREATE UNIQUE INDEX idx_token_user_id on tb_token(user_id); |
|||
CREATE UNIQUE INDEX idx_token on tb_token(token); |
|||
|
|||
|
|||
-- 账号:13612345678 密码:admin |
|||
INSERT INTO tb_user (id, username, mobile, password, create_date) VALUES (1067246875800000168, 'mark', '13612345678', '8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918', CURRENT_DATE); |
@ -1,24 +0,0 @@ |
|||
CREATE TABLE tb_user ( |
|||
id int8 NOT NULL, |
|||
username varchar(50) NOT NULL, |
|||
mobile varchar(20) NOT NULL, |
|||
password varchar(64), |
|||
create_date timestamp, |
|||
PRIMARY KEY (id), |
|||
UNIQUE (username) |
|||
); |
|||
|
|||
CREATE TABLE tb_token ( |
|||
id int8 NOT NULL, |
|||
user_id int8 NOT NULL, |
|||
token varchar(100) NOT NULL, |
|||
expire_date timestamp, |
|||
update_date timestamp, |
|||
PRIMARY KEY (id), |
|||
UNIQUE (user_id), |
|||
UNIQUE (token) |
|||
); |
|||
|
|||
|
|||
-- 账号:13612345678 密码:admin |
|||
INSERT INTO tb_user (id, username, mobile, password, create_date) VALUES (1067246875800000168, 'mark', '13612345678', '8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918', now()); |
@ -1,24 +0,0 @@ |
|||
CREATE TABLE tb_user ( |
|||
id bigint NOT NULL, |
|||
username varchar(50) NOT NULL, |
|||
mobile varchar(20) NOT NULL, |
|||
password varchar(64), |
|||
create_date datetime, |
|||
PRIMARY KEY (id), |
|||
UNIQUE (username) |
|||
); |
|||
|
|||
CREATE TABLE tb_token ( |
|||
id bigint NOT NULL, |
|||
user_id bigint NOT NULL, |
|||
token varchar(100) NOT NULL, |
|||
expire_date datetime, |
|||
update_date datetime, |
|||
PRIMARY KEY (id), |
|||
UNIQUE (user_id), |
|||
UNIQUE (token) |
|||
); |
|||
|
|||
|
|||
-- 账号:13612345678 密码:admin |
|||
INSERT INTO tb_user (id, username, mobile, password, create_date) VALUES (1067246875800000168, 'mark', '13612345678', '8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918', getdate()); |
@ -1,35 +0,0 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|||
<modelVersion>4.0.0</modelVersion> |
|||
|
|||
<parent> |
|||
<groupId>com.epmet</groupId> |
|||
<artifactId>epmet-api</artifactId> |
|||
<version>2.0.0</version> |
|||
</parent> |
|||
|
|||
<artifactId>epmet-api-client</artifactId> |
|||
<packaging>jar</packaging> |
|||
|
|||
<dependencies> |
|||
<dependency> |
|||
<groupId>com.epmet</groupId> |
|||
<artifactId>epmet-commons-tools</artifactId> |
|||
<version>2.0.0</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>io.springfox</groupId> |
|||
<artifactId>springfox-swagger2</artifactId> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>io.springfox</groupId> |
|||
<artifactId>springfox-swagger-ui</artifactId> |
|||
</dependency> |
|||
</dependencies> |
|||
|
|||
<build> |
|||
<finalName>${project.artifactId}</finalName> |
|||
</build> |
|||
|
|||
</project> |
@ -1,34 +0,0 @@ |
|||
/** |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.epmet.dto; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
|
|||
/** |
|||
* 登录表单 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
*/ |
|||
@Data |
|||
@ApiModel(value = "登录表单") |
|||
public class LoginDTO { |
|||
@ApiModelProperty(value = "手机号") |
|||
@NotBlank(message="{api.mobile.require}") |
|||
private String mobile; |
|||
|
|||
@ApiModelProperty(value = "密码") |
|||
@NotBlank(message="{api.password.require}") |
|||
private String password; |
|||
|
|||
} |
@ -1,33 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.epmet.dto; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
|
|||
/** |
|||
* 注册表单 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
*/ |
|||
@Data |
|||
@ApiModel(value = "注册表单") |
|||
public class RegisterDTO { |
|||
@ApiModelProperty(value = "手机号") |
|||
@NotBlank(message="{api.mobile.require}") |
|||
private String mobile; |
|||
|
|||
@ApiModelProperty(value = "密码") |
|||
@NotBlank(message="{api.password.require}") |
|||
private String password; |
|||
|
|||
} |
@ -1,142 +0,0 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|||
<modelVersion>4.0.0</modelVersion> |
|||
|
|||
<parent> |
|||
<groupId>com.epmet</groupId> |
|||
<artifactId>epmet-api</artifactId> |
|||
<version>2.0.0</version> |
|||
</parent> |
|||
|
|||
<artifactId>epmet-api-server</artifactId> |
|||
<packaging>jar</packaging> |
|||
|
|||
<dependencies> |
|||
<dependency> |
|||
<groupId>com.epmet</groupId> |
|||
<artifactId>epmet-oss-client</artifactId> |
|||
<version>2.0.0</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.epmet</groupId> |
|||
<artifactId>epmet-api-client</artifactId> |
|||
<version>2.0.0</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.epmet</groupId> |
|||
<artifactId>epmet-commons-tools</artifactId> |
|||
<version>2.0.0</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.epmet</groupId> |
|||
<artifactId>epmet-commons-mybatis</artifactId> |
|||
<version>2.0.0</version> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-web</artifactId> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.springframework</groupId> |
|||
<artifactId>spring-context-support</artifactId> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-actuator</artifactId> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.alibaba.cloud</groupId> |
|||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> |
|||
</dependency> |
|||
<dependency> |
|||
<groupId>com.alibaba.cloud</groupId> |
|||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> |
|||
</dependency> |
|||
</dependencies> |
|||
|
|||
<build> |
|||
<finalName>${project.artifactId}</finalName> |
|||
<plugins> |
|||
<plugin> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-maven-plugin</artifactId> |
|||
</plugin> |
|||
<plugin> |
|||
<groupId>org.apache.maven.plugins</groupId> |
|||
<artifactId>maven-surefire-plugin</artifactId> |
|||
<configuration> |
|||
<skipTests>true</skipTests> |
|||
</configuration> |
|||
</plugin> |
|||
</plugins> |
|||
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory> |
|||
<resources> |
|||
<resource> |
|||
<filtering>true</filtering> |
|||
<directory>${basedir}/src/main/resources</directory> |
|||
</resource> |
|||
</resources> |
|||
</build> |
|||
<profiles> |
|||
<profile> |
|||
<id>dev</id> |
|||
|
|||
<activation> |
|||
<activeByDefault>true</activeByDefault> |
|||
</activation> |
|||
|
|||
<properties> |
|||
<server.port>8087</server.port> |
|||
<spring.profiles.active>dev</spring.profiles.active> |
|||
|
|||
<!-- 数据库配置--> |
|||
<spring.datasource.druid.url> |
|||
<![CDATA[jdbc:mysql://47.104.224.45:3308/epmet_admin?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai]]> |
|||
</spring.datasource.druid.url> |
|||
<spring.datasource.druid.username>epmet</spring.datasource.druid.username> |
|||
<spring.datasource.druid.password>elink@833066</spring.datasource.druid.password> |
|||
<!-- redis配置 --> |
|||
<spring.redis.index>0</spring.redis.index> |
|||
<spring.redis.host>122.152.200.70</spring.redis.host> |
|||
<spring.redis.port>6379</spring.redis.port> |
|||
<spring.redis.password>123456</spring.redis.password> |
|||
<!-- nacos --> |
|||
<nacos.register-enabled>false</nacos.register-enabled> |
|||
<nacos.server-addr>122.152.200.70:8848</nacos.server-addr> |
|||
<nacos.discovery.namespace>fcd6fc8f-ca3a-4b01-8026-2b05cdc5976b</nacos.discovery.namespace> |
|||
<nacos.config.namespace></nacos.config.namespace> |
|||
<nacos.config.group></nacos.config.group> |
|||
<nacos.config-enabled>false</nacos.config-enabled> |
|||
<nacos.ip/> |
|||
</properties> |
|||
</profile> |
|||
<profile> |
|||
<id>test</id> |
|||
<properties> |
|||
<server.port>8087</server.port> |
|||
<spring.profiles.active>test</spring.profiles.active> |
|||
|
|||
<!-- 数据库配置--> |
|||
<spring.datasource.druid.url> |
|||
<![CDATA[jdbc:mysql://47.104.224.45:3308/epmet_admin?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai]]> |
|||
</spring.datasource.druid.url> |
|||
<spring.datasource.druid.username>epmet</spring.datasource.druid.username> |
|||
<spring.datasource.druid.password>elink@833066</spring.datasource.druid.password> |
|||
<!-- redis配置 --> |
|||
<spring.redis.index>0</spring.redis.index> |
|||
<spring.redis.host>122.152.200.70</spring.redis.host> |
|||
<spring.redis.port>6379</spring.redis.port> |
|||
<spring.redis.password>123456</spring.redis.password> |
|||
<!-- nacos --> |
|||
<nacos.register-enabled>true</nacos.register-enabled> |
|||
<nacos.server-addr>122.152.200.70:8848</nacos.server-addr> |
|||
<nacos.discovery.namespace>fcd6fc8f-ca3a-4b01-8026-2b05cdc5976b</nacos.discovery.namespace> |
|||
<nacos.config.namespace></nacos.config.namespace> |
|||
<nacos.config.group></nacos.config.group> |
|||
<nacos.config-enabled>false</nacos.config-enabled> |
|||
<nacos.ip/> |
|||
</properties> |
|||
</profile> |
|||
</profiles> |
|||
</project> |
@ -1,31 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.epmet; |
|||
|
|||
import org.springframework.boot.SpringApplication; |
|||
import org.springframework.boot.autoconfigure.SpringBootApplication; |
|||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; |
|||
import org.springframework.cloud.openfeign.EnableFeignClients; |
|||
|
|||
/** |
|||
* API模块 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
@SpringBootApplication |
|||
@EnableDiscoveryClient |
|||
@EnableFeignClients |
|||
public class ApiApplication { |
|||
|
|||
public static void main(String[] args) { |
|||
SpringApplication.run(ApiApplication.class, args); |
|||
} |
|||
|
|||
} |
@ -1,21 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.epmet.annotation; |
|||
|
|||
import java.lang.annotation.*; |
|||
|
|||
/** |
|||
* 登录效验 |
|||
* @author Mark sunlightcs@gmail.com |
|||
*/ |
|||
@Target(ElementType.METHOD) |
|||
@Retention(RetentionPolicy.RUNTIME) |
|||
@Documented |
|||
public @interface Login { |
|||
} |
@ -1,25 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.epmet.annotation; |
|||
|
|||
import java.lang.annotation.ElementType; |
|||
import java.lang.annotation.Retention; |
|||
import java.lang.annotation.RetentionPolicy; |
|||
import java.lang.annotation.Target; |
|||
|
|||
/** |
|||
* 登录用户信息 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
*/ |
|||
@Target(ElementType.PARAMETER) |
|||
@Retention(RetentionPolicy.RUNTIME) |
|||
public @interface LoginUser { |
|||
|
|||
} |
@ -1,35 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.epmet.config; |
|||
|
|||
import com.epmet.commons.tools.xss.XssFilter; |
|||
import org.springframework.boot.web.servlet.FilterRegistrationBean; |
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
|
|||
import javax.servlet.DispatcherType; |
|||
|
|||
/** |
|||
* Filter配置 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
*/ |
|||
@Configuration |
|||
public class FilterConfig { |
|||
|
|||
@Bean |
|||
public FilterRegistrationBean xssFilterRegistration() { |
|||
FilterRegistrationBean registration = new FilterRegistrationBean(); |
|||
registration.setDispatcherTypes(DispatcherType.REQUEST); |
|||
registration.setFilter(new XssFilter()); |
|||
registration.addUrlPatterns("/*"); |
|||
registration.setName("xssFilter"); |
|||
return registration; |
|||
} |
|||
} |
@ -1,26 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.epmet.config; |
|||
|
|||
import com.epmet.commons.tools.config.ModuleConfig; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
/** |
|||
* 模块配置信息 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
@Service |
|||
public class ModuleConfigImpl implements ModuleConfig { |
|||
@Override |
|||
public String getName() { |
|||
return "api"; |
|||
} |
|||
} |
@ -1,68 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.epmet.config; |
|||
|
|||
import com.epmet.commons.tools.constant.Constant; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
|||
import springfox.documentation.builders.ApiInfoBuilder; |
|||
import springfox.documentation.builders.PathSelectors; |
|||
import springfox.documentation.builders.RequestHandlerSelectors; |
|||
import springfox.documentation.service.ApiInfo; |
|||
import springfox.documentation.service.ApiKey; |
|||
import springfox.documentation.spi.DocumentationType; |
|||
import springfox.documentation.spring.web.plugins.Docket; |
|||
import springfox.documentation.swagger2.annotations.EnableSwagger2; |
|||
|
|||
import java.util.List; |
|||
|
|||
import static com.google.common.collect.Lists.newArrayList; |
|||
|
|||
/** |
|||
* Swagger配置 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
@Configuration |
|||
@EnableSwagger2 |
|||
public class SwaggerConfig implements WebMvcConfigurer { |
|||
|
|||
@Bean |
|||
public Docket createRestApi() { |
|||
return new Docket(DocumentationType.SWAGGER_2) |
|||
.apiInfo(apiInfo()) |
|||
.select() |
|||
//加了ApiOperation注解的类,才生成接口文档
|
|||
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) |
|||
.paths(PathSelectors.any()) |
|||
.build() |
|||
.directModelSubstitute(java.util.Date.class, String.class) |
|||
.securitySchemes(security()); |
|||
|
|||
} |
|||
|
|||
private ApiInfo apiInfo() { |
|||
return new ApiInfoBuilder() |
|||
.title("人人开源") |
|||
.description("API接口文档") |
|||
.termsOfServiceUrl("https://www.renren.io") |
|||
.version("1.1.0") |
|||
.build(); |
|||
} |
|||
|
|||
private List<ApiKey> security() { |
|||
return newArrayList( |
|||
new ApiKey(Constant.TOKEN_HEADER, Constant.TOKEN_HEADER, "header") |
|||
); |
|||
} |
|||
|
|||
} |
@ -1,42 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.epmet.config; |
|||
|
|||
import com.epmet.interceptor.AuthorizationInterceptor; |
|||
import com.epmet.resolver.LoginUserHandlerMethodArgumentResolver; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.context.annotation.Configuration; |
|||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; |
|||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; |
|||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* MVC配置 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
*/ |
|||
@Configuration |
|||
public class WebConfig implements WebMvcConfigurer { |
|||
@Autowired |
|||
private AuthorizationInterceptor authorizationInterceptor; |
|||
@Autowired |
|||
private LoginUserHandlerMethodArgumentResolver loginUserHandlerMethodArgumentResolver; |
|||
|
|||
@Override |
|||
public void addInterceptors(InterceptorRegistry registry) { |
|||
registry.addInterceptor(authorizationInterceptor).addPathPatterns("/**"); |
|||
} |
|||
|
|||
@Override |
|||
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) { |
|||
argumentResolvers.add(loginUserHandlerMethodArgumentResolver); |
|||
} |
|||
} |
@ -1,61 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.epmet.controller; |
|||
|
|||
|
|||
import com.epmet.annotation.Login; |
|||
import com.epmet.commons.tools.utils.Result; |
|||
import com.epmet.commons.tools.validator.ValidatorUtils; |
|||
import com.epmet.dto.LoginDTO; |
|||
import com.epmet.service.TokenService; |
|||
import com.epmet.service.UserService; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
import springfox.documentation.annotations.ApiIgnore; |
|||
|
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 登录接口 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("auth") |
|||
@Api(tags="登录接口") |
|||
public class ApiLoginController { |
|||
@Autowired |
|||
private UserService userService; |
|||
@Autowired |
|||
private TokenService tokenService; |
|||
|
|||
|
|||
@PostMapping("login") |
|||
@ApiOperation("登录") |
|||
public Result<Map<String, Object>> login(@RequestBody LoginDTO dto){ |
|||
//表单校验
|
|||
ValidatorUtils.validateEntity(dto); |
|||
|
|||
//用户登录
|
|||
Map<String, Object> map = userService.login(dto); |
|||
|
|||
return new Result().ok(map); |
|||
} |
|||
|
|||
@Login |
|||
@PostMapping("logout") |
|||
@ApiOperation("退出") |
|||
public Result logout(@ApiIgnore @RequestAttribute("userId") Long userId){ |
|||
tokenService.expireToken(userId); |
|||
return new Result(); |
|||
} |
|||
|
|||
} |
@ -1,54 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.epmet.controller; |
|||
|
|||
import com.epmet.commons.tools.utils.Result; |
|||
import com.epmet.commons.tools.validator.ValidatorUtils; |
|||
import com.epmet.entity.UserEntity; |
|||
import com.epmet.dto.RegisterDTO; |
|||
import com.epmet.service.UserService; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import org.apache.commons.codec.digest.DigestUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestBody; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 注册接口 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("register") |
|||
@Api(tags="注册接口") |
|||
public class ApiRegisterController { |
|||
@Autowired |
|||
private UserService userService; |
|||
|
|||
@PostMapping |
|||
@ApiOperation("注册") |
|||
public Result register(@RequestBody RegisterDTO dto){ |
|||
//表单校验
|
|||
ValidatorUtils.validateEntity(dto); |
|||
|
|||
UserEntity user = new UserEntity(); |
|||
user.setMobile(dto.getMobile()); |
|||
user.setUsername(dto.getMobile()); |
|||
user.setPassword(DigestUtils.sha256Hex(dto.getPassword())); |
|||
user.setCreateDate(new Date()); |
|||
userService.insert(user); |
|||
|
|||
return new Result(); |
|||
} |
|||
} |
@ -1,63 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.epmet.controller; |
|||
|
|||
import com.epmet.annotation.Login; |
|||
import com.epmet.annotation.LoginUser; |
|||
import com.epmet.commons.tools.utils.Result; |
|||
import com.epmet.dto.UploadDTO; |
|||
import com.epmet.entity.UserEntity; |
|||
import com.epmet.feign.OssFeignClient; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
import springfox.documentation.annotations.ApiIgnore; |
|||
|
|||
/** |
|||
* 测试接口 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("test") |
|||
@Api(tags="测试接口") |
|||
public class ApiTestController { |
|||
@Autowired |
|||
private OssFeignClient ossFeignClient; |
|||
|
|||
@Login |
|||
@GetMapping("userInfo") |
|||
@ApiOperation(value="获取用户信息", response=UserEntity.class) |
|||
public Result<UserEntity> userInfo(@ApiIgnore @LoginUser UserEntity user){ |
|||
return new Result<UserEntity>().ok(user); |
|||
} |
|||
|
|||
@Login |
|||
@GetMapping("userId") |
|||
@ApiOperation("获取用户ID") |
|||
public Result<Long> userInfo(@ApiIgnore @RequestAttribute("userId") Long userId){ |
|||
return new Result<Long>().ok(userId); |
|||
} |
|||
|
|||
@GetMapping("notToken") |
|||
@ApiOperation("忽略Token验证测试") |
|||
public Result<String> notToken(){ |
|||
return new Result<String>().ok("无需token也能访问。。。"); |
|||
} |
|||
|
|||
@PostMapping("upload") |
|||
@ApiOperation(value = "上传文件") |
|||
public Result<UploadDTO> upload(@RequestParam("file") MultipartFile file) { |
|||
Result<UploadDTO> dto = ossFeignClient.upload(file); |
|||
|
|||
return dto; |
|||
} |
|||
} |
@ -1,25 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.epmet.dao; |
|||
|
|||
import com.epmet.commons.mybatis.dao.BaseDao; |
|||
import com.epmet.entity.TokenEntity; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
|
|||
/** |
|||
* 用户Token |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
*/ |
|||
@Mapper |
|||
public interface TokenDao extends BaseDao<TokenEntity> { |
|||
TokenEntity getByToken(String token); |
|||
|
|||
TokenEntity getByUserId(Long userId); |
|||
} |
@ -1,25 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.epmet.dao; |
|||
|
|||
import com.epmet.commons.mybatis.dao.BaseDao; |
|||
import com.epmet.entity.UserEntity; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
|
|||
/** |
|||
* 用户 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
*/ |
|||
@Mapper |
|||
public interface UserDao extends BaseDao<UserEntity> { |
|||
UserEntity getUserByMobile(String mobile); |
|||
|
|||
UserEntity getUserByUserId(Long userId); |
|||
} |
@ -1,47 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.epmet.entity; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.TableId; |
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 用户Token |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
*/ |
|||
@Data |
|||
@TableName("tb_token") |
|||
public class TokenEntity implements Serializable { |
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
@TableId |
|||
private Long id; |
|||
/** |
|||
* 用户ID |
|||
*/ |
|||
private Long userId; |
|||
/** |
|||
* 用户token |
|||
*/ |
|||
private String token; |
|||
/** |
|||
* 过期时间 |
|||
*/ |
|||
private Date expireDate; |
|||
/** |
|||
* 更新时间 |
|||
*/ |
|||
private Date updateDate; |
|||
|
|||
} |
@ -1,52 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.epmet.entity; |
|||
|
|||
import com.alibaba.fastjson.annotation.JSONField; |
|||
import com.baomidou.mybatisplus.annotation.TableId; |
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 用户 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
*/ |
|||
@Data |
|||
@TableName("tb_user") |
|||
public class UserEntity implements Serializable { |
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** |
|||
* 用户ID |
|||
*/ |
|||
@TableId |
|||
private Long id; |
|||
/** |
|||
* 用户名 |
|||
*/ |
|||
private String username; |
|||
/** |
|||
* 手机号 |
|||
*/ |
|||
private String mobile; |
|||
/** |
|||
* 密码 |
|||
*/ |
|||
@JSONField(serialize=false) |
|||
private String password; |
|||
/** |
|||
* 创建时间 |
|||
*/ |
|||
private Date createDate; |
|||
|
|||
} |
@ -1,25 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.epmet.exception; |
|||
|
|||
import com.epmet.commons.tools.exception.ErrorCode; |
|||
|
|||
/** |
|||
* 模块错误编码,由9位数字组成,前6位为模块编码,后3位为业务编码 |
|||
* <p> |
|||
* 如:100001001(100001代表模块,001代表业务代码) |
|||
* </p> |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
public interface ModuleErrorCode extends ErrorCode { |
|||
int TOKEN_NOT_EMPTY = 100005001; |
|||
int TOKEN_INVALID = 100005002; |
|||
} |
@ -1,73 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.epmet.interceptor; |
|||
|
|||
import com.epmet.annotation.Login; |
|||
import com.epmet.commons.tools.exception.RenException; |
|||
import com.epmet.entity.TokenEntity; |
|||
import com.epmet.exception.ModuleErrorCode; |
|||
import com.epmet.service.TokenService; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
import org.springframework.web.method.HandlerMethod; |
|||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import javax.servlet.http.HttpServletResponse; |
|||
|
|||
/** |
|||
* 权限(Token)验证 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
*/ |
|||
@Component |
|||
public class AuthorizationInterceptor extends HandlerInterceptorAdapter { |
|||
@Autowired |
|||
private TokenService tokenService; |
|||
|
|||
public static final String USER_KEY = "userId"; |
|||
|
|||
@Override |
|||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { |
|||
Login annotation; |
|||
if(handler instanceof HandlerMethod) { |
|||
annotation = ((HandlerMethod) handler).getMethodAnnotation(Login.class); |
|||
}else{ |
|||
return true; |
|||
} |
|||
|
|||
if(annotation == null){ |
|||
return true; |
|||
} |
|||
|
|||
//从header中获取token
|
|||
String token = request.getHeader("token"); |
|||
//如果header中不存在token,则从参数中获取token
|
|||
if(StringUtils.isBlank(token)){ |
|||
token = request.getParameter("token"); |
|||
} |
|||
|
|||
//token为空
|
|||
if(StringUtils.isBlank(token)){ |
|||
throw new RenException(ModuleErrorCode.TOKEN_NOT_EMPTY); |
|||
} |
|||
|
|||
//查询token信息
|
|||
TokenEntity tokenEntity = tokenService.getByToken(token); |
|||
if(tokenEntity == null || tokenEntity.getExpireDate().getTime() < System.currentTimeMillis()){ |
|||
throw new RenException(ModuleErrorCode.TOKEN_INVALID); |
|||
} |
|||
|
|||
//设置userId到request里,后续根据userId,获取用户信息
|
|||
request.setAttribute(USER_KEY, tokenEntity.getUserId()); |
|||
|
|||
return true; |
|||
} |
|||
} |
@ -1,53 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.epmet.resolver; |
|||
|
|||
import com.epmet.annotation.LoginUser; |
|||
import com.epmet.entity.UserEntity; |
|||
import com.epmet.interceptor.AuthorizationInterceptor; |
|||
import com.epmet.service.UserService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.core.MethodParameter; |
|||
import org.springframework.stereotype.Component; |
|||
import org.springframework.web.bind.support.WebDataBinderFactory; |
|||
import org.springframework.web.context.request.NativeWebRequest; |
|||
import org.springframework.web.context.request.RequestAttributes; |
|||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; |
|||
import org.springframework.web.method.support.ModelAndViewContainer; |
|||
|
|||
/** |
|||
* 有@LoginUser注解的方法参数,注入当前登录用户 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
*/ |
|||
@Component |
|||
public class LoginUserHandlerMethodArgumentResolver implements HandlerMethodArgumentResolver { |
|||
@Autowired |
|||
private UserService userService; |
|||
|
|||
@Override |
|||
public boolean supportsParameter(MethodParameter parameter) { |
|||
return parameter.getParameterType().isAssignableFrom(UserEntity.class) && parameter.hasParameterAnnotation(LoginUser.class); |
|||
} |
|||
|
|||
@Override |
|||
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer container, |
|||
NativeWebRequest request, WebDataBinderFactory factory) throws Exception { |
|||
//获取用户ID
|
|||
Object object = request.getAttribute(AuthorizationInterceptor.USER_KEY, RequestAttributes.SCOPE_REQUEST); |
|||
if(object == null){ |
|||
return null; |
|||
} |
|||
|
|||
//获取用户信息
|
|||
UserEntity user = userService.getUserByUserId((Long)object); |
|||
|
|||
return user; |
|||
} |
|||
} |
@ -1,36 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.epmet.service; |
|||
|
|||
import com.epmet.commons.mybatis.service.BaseService; |
|||
import com.epmet.entity.TokenEntity; |
|||
|
|||
/** |
|||
* 用户Token |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
*/ |
|||
public interface TokenService extends BaseService<TokenEntity> { |
|||
|
|||
TokenEntity getByToken(String token); |
|||
|
|||
/** |
|||
* 生成token |
|||
* @param userId 用户ID |
|||
* @return 返回token信息 |
|||
*/ |
|||
TokenEntity createToken(Long userId); |
|||
|
|||
/** |
|||
* 设置token过期 |
|||
* @param userId 用户ID |
|||
*/ |
|||
void expireToken(Long userId); |
|||
|
|||
} |
@ -1,34 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.epmet.service; |
|||
|
|||
import com.epmet.commons.mybatis.service.BaseService; |
|||
import com.epmet.entity.UserEntity; |
|||
import com.epmet.dto.LoginDTO; |
|||
|
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 用户 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
*/ |
|||
public interface UserService extends BaseService<UserEntity> { |
|||
|
|||
UserEntity getByMobile(String mobile); |
|||
|
|||
UserEntity getUserByUserId(Long userId); |
|||
|
|||
/** |
|||
* 用户登录 |
|||
* @param dto 登录表单 |
|||
* @return 返回登录信息 |
|||
*/ |
|||
Map<String, Object> login(LoginDTO dto); |
|||
} |
@ -1,92 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.epmet.service.impl; |
|||
|
|||
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|||
import com.epmet.dao.TokenDao; |
|||
import com.epmet.entity.TokenEntity; |
|||
import com.epmet.service.TokenService; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.Date; |
|||
import java.util.UUID; |
|||
|
|||
|
|||
@Service |
|||
public class TokenServiceImpl extends BaseServiceImpl<TokenDao, TokenEntity> implements TokenService { |
|||
/** |
|||
* 12小时后过期 |
|||
*/ |
|||
private final static int EXPIRE = 3600 * 12; |
|||
|
|||
@Override |
|||
public TokenEntity getByToken(String token) { |
|||
return baseDao.getByToken(token); |
|||
} |
|||
|
|||
@Override |
|||
public TokenEntity createToken(Long userId) { |
|||
//当前时间
|
|||
Date now = new Date(); |
|||
//过期时间
|
|||
Date expireTime = new Date(now.getTime() + EXPIRE * 1000); |
|||
|
|||
//用户token
|
|||
String token; |
|||
|
|||
//判断是否生成过token
|
|||
TokenEntity tokenEntity = baseDao.getByUserId(userId); |
|||
if(tokenEntity == null){ |
|||
//生成一个token
|
|||
token = generateToken(); |
|||
|
|||
tokenEntity = new TokenEntity(); |
|||
tokenEntity.setUserId(userId); |
|||
tokenEntity.setToken(token); |
|||
tokenEntity.setUpdateDate(now); |
|||
tokenEntity.setExpireDate(expireTime); |
|||
|
|||
//保存token
|
|||
this.insert(tokenEntity); |
|||
}else{ |
|||
//判断token是否过期
|
|||
if(tokenEntity.getExpireDate().getTime() < System.currentTimeMillis()){ |
|||
//token过期,重新生成token
|
|||
token = generateToken(); |
|||
}else { |
|||
token = tokenEntity.getToken(); |
|||
} |
|||
|
|||
tokenEntity.setToken(token); |
|||
tokenEntity.setUpdateDate(now); |
|||
tokenEntity.setExpireDate(expireTime); |
|||
|
|||
//更新token
|
|||
this.updateById(tokenEntity); |
|||
} |
|||
|
|||
return tokenEntity; |
|||
} |
|||
|
|||
@Override |
|||
public void expireToken(Long userId){ |
|||
Date now = new Date(); |
|||
|
|||
TokenEntity tokenEntity = new TokenEntity(); |
|||
tokenEntity.setUserId(userId); |
|||
tokenEntity.setUpdateDate(now); |
|||
tokenEntity.setExpireDate(now); |
|||
|
|||
this.updateById(tokenEntity); |
|||
} |
|||
|
|||
private String generateToken(){ |
|||
return UUID.randomUUID().toString().replace("-", ""); |
|||
} |
|||
} |
@ -1,63 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.epmet.service.impl; |
|||
|
|||
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|||
import com.epmet.commons.tools.exception.ErrorCode; |
|||
import com.epmet.commons.tools.exception.RenException; |
|||
import com.epmet.commons.tools.validator.AssertUtils; |
|||
import com.epmet.dao.UserDao; |
|||
import com.epmet.entity.TokenEntity; |
|||
import com.epmet.entity.UserEntity; |
|||
import com.epmet.dto.LoginDTO; |
|||
import com.epmet.service.TokenService; |
|||
import com.epmet.service.UserService; |
|||
import org.apache.commons.codec.digest.DigestUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
@Service |
|||
public class UserServiceImpl extends BaseServiceImpl<UserDao, UserEntity> implements UserService { |
|||
@Autowired |
|||
private TokenService tokenService; |
|||
|
|||
@Override |
|||
public UserEntity getByMobile(String mobile) { |
|||
return baseDao.getUserByMobile(mobile); |
|||
} |
|||
|
|||
@Override |
|||
public UserEntity getUserByUserId(Long userId) { |
|||
return baseDao.getUserByUserId(userId); |
|||
} |
|||
|
|||
@Override |
|||
public Map<String, Object> login(LoginDTO dto) { |
|||
UserEntity user = getByMobile(dto.getMobile()); |
|||
AssertUtils.isNull(user, ErrorCode.ACCOUNT_PASSWORD_ERROR); |
|||
|
|||
//密码错误
|
|||
if(!user.getPassword().equals(DigestUtils.sha256Hex(dto.getPassword()))){ |
|||
throw new RenException(ErrorCode.ACCOUNT_PASSWORD_ERROR); |
|||
} |
|||
|
|||
//获取登录token
|
|||
TokenEntity tokenEntity = tokenService.createToken(user.getId()); |
|||
|
|||
Map<String, Object> map = new HashMap<>(2); |
|||
map.put("token", tokenEntity.getToken()); |
|||
map.put("expire", tokenEntity.getExpireDate().getTime() - System.currentTimeMillis()); |
|||
|
|||
return map; |
|||
} |
|||
|
|||
} |
@ -1,94 +0,0 @@ |
|||
server: |
|||
port: @server.port@ |
|||
servlet: |
|||
context-path: /api |
|||
|
|||
spring: |
|||
application: |
|||
name: epmet-api-server |
|||
#环境 dev|test|prod |
|||
profiles: |
|||
active: dev |
|||
messages: |
|||
encoding: UTF-8 |
|||
basename: i18n/messages,i18n/messages_common |
|||
jackson: |
|||
time-zone: GMT+8 |
|||
date-format: yyyy-MM-dd HH:mm:ss |
|||
redis: |
|||
database: @spring.redis.index@ |
|||
host: @spring.redis.host@ |
|||
port: @spring.redis.port@ |
|||
password: @spring.redis.password@ |
|||
timeout: 30s |
|||
datasource: |
|||
druid: |
|||
#MySQL |
|||
driver-class-name: com.mysql.cj.jdbc.Driver |
|||
url: @spring.datasource.druid.url@ |
|||
username: @spring.datasource.druid.username@ |
|||
password: @spring.datasource.druid.password@ |
|||
cloud: |
|||
nacos: |
|||
discovery: |
|||
server-addr: @nacos.server-addr@ |
|||
#nacos的命名空间ID,默认是public |
|||
namespace: @nacos.discovery.namespace@ |
|||
#不把自己注册到注册中心的地址 |
|||
register-enabled: @nacos.register-enabled@ |
|||
ip: @nacos.ip@ |
|||
config: |
|||
enabled: @nacos.config-enabled@ |
|||
server-addr: @nacos.server-addr@ |
|||
namespace: @nacos.config.namespace@ |
|||
group: @nacos.config.group@ |
|||
file-extension: yaml |
|||
management: |
|||
endpoints: |
|||
web: |
|||
exposure: |
|||
include: "*" |
|||
endpoint: |
|||
health: |
|||
show-details: ALWAYS |
|||
|
|||
mybatis-plus: |
|||
mapper-locations: classpath:/mapper/**/*.xml |
|||
#实体扫描,多个package用逗号或者分号分隔 |
|||
typeAliasesPackage: com.epmet.entity |
|||
global-config: |
|||
#数据库相关配置 |
|||
db-config: |
|||
#主键类型 AUTO:"数据库ID自增", INPUT:"用户输入ID", ID_WORKER:"全局唯一ID (数字类型唯一ID)", UUID:"全局唯一ID UUID"; |
|||
id-type: ID_WORKER |
|||
banner: false |
|||
#原生配置 |
|||
configuration: |
|||
map-underscore-to-camel-case: true |
|||
cache-enabled: false |
|||
call-setters-on-nulls: true |
|||
jdbc-type-for-null: 'null' |
|||
|
|||
feign: |
|||
hystrix: |
|||
enabled: true |
|||
client: |
|||
config: |
|||
default: |
|||
loggerLevel: BASIC |
|||
httpclient: |
|||
enabled: true |
|||
max-connections: 200 |
|||
max-connections-per-route: 50 |
|||
|
|||
hystrix: |
|||
command: |
|||
default: |
|||
execution: |
|||
isolation: |
|||
thread: |
|||
timeoutInMilliseconds: 60000 #缺省为1000 |
|||
|
|||
ribbon: |
|||
ReadTimeout: 300000 |
|||
ConnectTimeout: 300000 |
@ -1,3 +0,0 @@ |
|||
#Default |
|||
100005001=token\u4E0D\u80FD\u4E3A\u7A7A |
|||
100005002=token\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55 |
@ -1,3 +0,0 @@ |
|||
#English |
|||
100005001=Token cannot be empty |
|||
100005002=Token is invalid, please log in again |
@ -1,3 +0,0 @@ |
|||
#\u7B80\u4F53\u4E2D\u6587 |
|||
100005001=token\u4E0D\u80FD\u4E3A\u7A7A |
|||
100005002=token\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55 |
@ -1,3 +0,0 @@ |
|||
#\u7E41\u4F53\u4E2D\u6587 |
|||
100005001=token\u4E0D\u80FD\u70BA\u7A7A |
|||
100005002=token\u5931\u6548\uFF0C\u8ACB\u91CD\u65B0\u767B\u9304 |
@ -1,3 +0,0 @@ |
|||
#Default |
|||
api.mobile.require=\u624B\u673A\u53F7\u4E0D\u80FD\u4E3A\u7A7A |
|||
api.password.require=\u5BC6\u7801\u4E0D\u80FD\u4E3A\u7A7A |
@ -1,3 +0,0 @@ |
|||
#English |
|||
api.mobile.require=The phone number cannot be empty |
|||
api.password.require=Password cannot be empty |
@ -1,3 +0,0 @@ |
|||
#\u7B80\u4F53\u4E2D\u6587 |
|||
api.mobile.require=\u624B\u673A\u53F7\u4E0D\u80FD\u4E3A\u7A7A |
|||
api.password.require=\u5BC6\u7801\u4E0D\u80FD\u4E3A\u7A7A |
@ -1,3 +0,0 @@ |
|||
#\u7E41\u4F53\u4E2D\u6587 |
|||
api.mobile.require=\u624B\u6A5F\u865F\u4E0D\u80FD\u70BA\u7A7A |
|||
api.password.require=\u5BC6\u78BC\u4E0D\u80FD\u70BA\u7A7A |
@ -1,159 +0,0 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<configuration> |
|||
<include resource="org/springframework/boot/logging/logback/base.xml"/> |
|||
|
|||
<property name="log.path" value="logs/admin"/> |
|||
|
|||
<!-- 彩色日志格式 --> |
|||
<property name="CONSOLE_LOG_PATTERN" |
|||
value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/> |
|||
|
|||
<!--1. 输出到控制台--> |
|||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> |
|||
<!--此日志appender是为开发使用,只配置最底级别,控制台输出的日志级别是大于或等于此级别的日志信息--> |
|||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter"> |
|||
<level>debug</level> |
|||
</filter> |
|||
<encoder> |
|||
<Pattern>${CONSOLE_LOG_PATTERN}</Pattern> |
|||
<!-- 设置字符集 --> |
|||
<charset>UTF-8</charset> |
|||
</encoder> |
|||
</appender> |
|||
|
|||
<!--2. 输出到文档--> |
|||
<!-- 2.1 level为 DEBUG 日志,时间滚动输出 --> |
|||
<appender name="DEBUG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
|||
<!-- 正在记录的日志文档的路径及文档名 --> |
|||
<file>${log.path}/debug.log</file> |
|||
<!--日志文档输出格式--> |
|||
<encoder> |
|||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern> |
|||
<charset>UTF-8</charset> <!-- 设置字符集 --> |
|||
</encoder> |
|||
<!-- 日志记录器的滚动策略,按日期,按大小记录 --> |
|||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
|||
<!-- 日志归档 --> |
|||
<fileNamePattern>${log.path}/debug-%d{yyyy-MM-dd}.%i.log</fileNamePattern> |
|||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
|||
<maxFileSize>100MB</maxFileSize> |
|||
</timeBasedFileNamingAndTriggeringPolicy> |
|||
<!--日志文档保留天数--> |
|||
<maxHistory>15</maxHistory> |
|||
</rollingPolicy> |
|||
<!-- 此日志文档只记录debug级别的 --> |
|||
<filter class="ch.qos.logback.classic.filter.LevelFilter"> |
|||
<level>debug</level> |
|||
<onMatch>ACCEPT</onMatch> |
|||
<onMismatch>DENY</onMismatch> |
|||
</filter> |
|||
</appender> |
|||
|
|||
<!-- 2.2 level为 INFO 日志,时间滚动输出 --> |
|||
<appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
|||
<!-- 正在记录的日志文档的路径及文档名 --> |
|||
<file>${log.path}/info.log</file> |
|||
<!--日志文档输出格式--> |
|||
<encoder> |
|||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern> |
|||
<charset>UTF-8</charset> |
|||
</encoder> |
|||
<!-- 日志记录器的滚动策略,按日期,按大小记录 --> |
|||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
|||
<!-- 每天日志归档路径以及格式 --> |
|||
<fileNamePattern>${log.path}/info-%d{yyyy-MM-dd}.%i.log</fileNamePattern> |
|||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
|||
<maxFileSize>100MB</maxFileSize> |
|||
</timeBasedFileNamingAndTriggeringPolicy> |
|||
<!--日志文档保留天数--> |
|||
<maxHistory>15</maxHistory> |
|||
</rollingPolicy> |
|||
<!-- 此日志文档只记录info级别的 --> |
|||
<filter class="ch.qos.logback.classic.filter.LevelFilter"> |
|||
<level>info</level> |
|||
<onMatch>ACCEPT</onMatch> |
|||
<onMismatch>DENY</onMismatch> |
|||
</filter> |
|||
</appender> |
|||
|
|||
<!-- 2.3 level为 WARN 日志,时间滚动输出 --> |
|||
<appender name="WARN_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
|||
<!-- 正在记录的日志文档的路径及文档名 --> |
|||
<file>${log.path}/warn.log</file> |
|||
<!--日志文档输出格式--> |
|||
<encoder> |
|||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern> |
|||
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
|||
</encoder> |
|||
<!-- 日志记录器的滚动策略,按日期,按大小记录 --> |
|||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
|||
<fileNamePattern>${log.path}/warn-%d{yyyy-MM-dd}.%i.log</fileNamePattern> |
|||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
|||
<maxFileSize>100MB</maxFileSize> |
|||
</timeBasedFileNamingAndTriggeringPolicy> |
|||
<!--日志文档保留天数--> |
|||
<maxHistory>15</maxHistory> |
|||
</rollingPolicy> |
|||
<!-- 此日志文档只记录warn级别的 --> |
|||
<filter class="ch.qos.logback.classic.filter.LevelFilter"> |
|||
<level>warn</level> |
|||
<onMatch>ACCEPT</onMatch> |
|||
<onMismatch>DENY</onMismatch> |
|||
</filter> |
|||
</appender> |
|||
|
|||
<!-- 2.4 level为 ERROR 日志,时间滚动输出 --> |
|||
<appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
|||
<!-- 正在记录的日志文档的路径及文档名 --> |
|||
<file>${log.path}/error.log</file> |
|||
<!--日志文档输出格式--> |
|||
<encoder> |
|||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern> |
|||
<charset>UTF-8</charset> <!-- 此处设置字符集 --> |
|||
</encoder> |
|||
<!-- 日志记录器的滚动策略,按日期,按大小记录 --> |
|||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
|||
<fileNamePattern>${log.path}/error-%d{yyyy-MM-dd}.%i.log</fileNamePattern> |
|||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> |
|||
<maxFileSize>100MB</maxFileSize> |
|||
</timeBasedFileNamingAndTriggeringPolicy> |
|||
<!--日志文档保留天数--> |
|||
<maxHistory>15</maxHistory> |
|||
</rollingPolicy> |
|||
<!-- 此日志文档只记录ERROR级别的 --> |
|||
<filter class="ch.qos.logback.classic.filter.LevelFilter"> |
|||
<level>ERROR</level> |
|||
<onMatch>ACCEPT</onMatch> |
|||
<onMismatch>DENY</onMismatch> |
|||
</filter> |
|||
</appender> |
|||
|
|||
<!-- 开发、测试环境 --> |
|||
<springProfile name="dev,test"> |
|||
<logger name="org.springframework.web" level="INFO"/> |
|||
<logger name="org.springboot.sample" level="INFO"/> |
|||
<logger name="com.epmet" level="INFO"/> |
|||
<logger name="com.epmet" level="DEBUG"/> |
|||
<root level="INFO"> |
|||
<appender-ref ref="DEBUG_FILE"/> |
|||
<appender-ref ref="INFO_FILE"/> |
|||
<appender-ref ref="WARN_FILE"/> |
|||
<appender-ref ref="ERROR_FILE"/> |
|||
</root> |
|||
</springProfile> |
|||
|
|||
<!-- 生产环境 --> |
|||
<springProfile name="prod"> |
|||
<logger name="org.springframework.web" level="INFO"/> |
|||
<logger name="org.springboot.sample" level="INFO"/> |
|||
<logger name="com.epmet" level="INFO"/> |
|||
<root level="INFO"> |
|||
<appender-ref ref="CONSOLE"/> |
|||
<appender-ref ref="DEBUG_FILE"/> |
|||
<appender-ref ref="INFO_FILE"/> |
|||
<appender-ref ref="WARN_FILE"/> |
|||
<appender-ref ref="ERROR_FILE"/> |
|||
</root> |
|||
</springProfile> |
|||
|
|||
</configuration> |
@ -1,14 +0,0 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
|||
|
|||
<mapper namespace="com.epmet.dao.TokenDao"> |
|||
|
|||
<select id="getByToken" resultType="com.epmet.entity.TokenEntity"> |
|||
select * from tb_token where token = #{value} |
|||
</select> |
|||
|
|||
<select id="getByUserId" resultType="com.epmet.entity.TokenEntity"> |
|||
select * from tb_token where user_id = #{value} |
|||
</select> |
|||
|
|||
</mapper> |
@ -1,13 +0,0 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
|||
|
|||
<mapper namespace="com.epmet.dao.UserDao"> |
|||
|
|||
<select id="getUserByMobile" resultType="com.epmet.entity.UserEntity"> |
|||
select * from tb_user where mobile = #{value} |
|||
</select> |
|||
|
|||
<select id="getUserByUserId" resultType="com.epmet.entity.UserEntity"> |
|||
select * from tb_user where id = #{value} |
|||
</select> |
|||
</mapper> |
@ -1,21 +0,0 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|||
<modelVersion>4.0.0</modelVersion> |
|||
|
|||
<parent> |
|||
<groupId>com.epmet</groupId> |
|||
<artifactId>epmet-module</artifactId> |
|||
<version>2.0.0</version> |
|||
</parent> |
|||
|
|||
<groupId>com.epmet</groupId> |
|||
<artifactId>epmet-api</artifactId> |
|||
<packaging>pom</packaging> |
|||
|
|||
<modules> |
|||
<module>epmet-api-client</module> |
|||
<module>epmet-api-server</module> |
|||
</modules> |
|||
|
|||
</project> |
Loading…
Reference in new issue