diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 00c72ccf..bdca58df 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -12,13 +12,15 @@ - - + + + + diff --git a/dq-financial-guarantee/pom.xml b/dq-financial-guarantee/pom.xml deleted file mode 100644 index 8d030265..00000000 --- a/dq-financial-guarantee/pom.xml +++ /dev/null @@ -1,76 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.1.8.RELEASE - - - com.daqing.financial - dq-financial-guarantee - 0.0.1-SNAPSHOT - dq-financial-guarantee - 大庆智慧金融平台-担保业务服务 - - - 1.8 - Greenwich.SR3 - - - - - - com.daqing.framework - dq-framework-model - 1.0-SNAPSHOT - - - - org.springframework.cloud - spring-cloud-starter-openfeign - - - - org.springframework.boot - spring-boot-starter-test - test - - - org.junit.vintage - junit-vintage-engine - - - - - - - - - org.springframework.cloud - spring-cloud-dependencies - ${spring-cloud.version} - pom - import - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/dq-financial-guarantee/src/main/java/com/daqing/financial/guarantee/DqFinancialGuaranteeApplication.java b/dq-financial-guarantee/src/main/java/com/daqing/financial/guarantee/DqFinancialGuaranteeApplication.java deleted file mode 100644 index 85b79c03..00000000 --- a/dq-financial-guarantee/src/main/java/com/daqing/financial/guarantee/DqFinancialGuaranteeApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.daqing.financial.guarantee; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class DqFinancialGuaranteeApplication { - - public static void main(String[] args) { - SpringApplication.run(DqFinancialGuaranteeApplication.class, args); - } - -} diff --git a/dq-financial-guarantee/src/main/resources/application.properties b/dq-financial-guarantee/src/main/resources/application.properties deleted file mode 100644 index 8b137891..00000000 --- a/dq-financial-guarantee/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ - diff --git a/dq-financial-guarantee/src/main/resources/logback-spring.xml b/dq-financial-guarantee/src/main/resources/logback-spring.xml deleted file mode 100644 index a7d9bdd4..00000000 --- a/dq-financial-guarantee/src/main/resources/logback-spring.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - - - - - %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - utf8 - - - - - - - - ${LOG_HOME}/guarantee.%d{yyyy-MM-dd}.log - - - %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - 0 - - 512 - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/dq-financial-guarantee/src/test/java/com/daqing/financial/guarantee/DqFinancialGuaranteeApplicationTests.java b/dq-financial-guarantee/src/test/java/com/daqing/financial/guarantee/DqFinancialGuaranteeApplicationTests.java deleted file mode 100644 index fa202884..00000000 --- a/dq-financial-guarantee/src/test/java/com/daqing/financial/guarantee/DqFinancialGuaranteeApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.daqing.financial.guarantee; - -import org.junit.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class DqFinancialGuaranteeApplicationTests { - - @Test - void contextLoads() { - } - -} diff --git a/dq-financial-hrms-auth/pom.xml b/dq-financial-hrms-auth/pom.xml index 360c9d38..e9b706df 100644 --- a/dq-financial-hrms-auth/pom.xml +++ b/dq-financial-hrms-auth/pom.xml @@ -30,16 +30,27 @@ dq-framework-model 1.0-SNAPSHOT + org.springframework.boot - spring-boot-starter-web + spring-boot-starter-data-redis + + + org.springframework.cloud spring-cloud-starter-openfeign - + - + + + <!– 指明版本,解决redis存储出现的问题:java.lang.NoSuchMethodError: org.springframework.data.redis.connection.RedisConnection.set([B[B)V问题 –> 2.3.3.RELEASE - + --> - + diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/SpringContextHolder.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/SpringContextHolder.java new file mode 100644 index 00000000..77a606a0 --- /dev/null +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/SpringContextHolder.java @@ -0,0 +1,64 @@ +package com.daqing.financial.hrauth; + +import org.springframework.beans.factory.DisposableBean; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Component; + +@Component +@Lazy(false) +public class SpringContextHolder implements ApplicationContextAware, DisposableBean { + + private static ApplicationContext applicationContext = null; + + + /** + * 取得存储在静态变量中的ApplicationContext. + */ + public static ApplicationContext getApplicationContext() { + return applicationContext; + } + + /** + * 从静态变量applicationContext中取得Bean, 自动转型为所赋值对象的类型. + */ + @SuppressWarnings("unchecked") + public static T getBean(String name) { + return (T) applicationContext.getBean(name); + } + + /** + * 从静态变量applicationContext中取得Bean, 自动转型为所赋值对象的类型. + */ + public static T getBean(Class requiredType) { + return applicationContext.getBean(requiredType); + } + + public static T getBean(String name, Class clazz) { + return getApplicationContext().getBean(name, clazz); + } + + /** + * 清除SpringContextHolder中的ApplicationContext为Null. + */ + public static void clearHolder() { + applicationContext = null; + } + + /** + * 实现ApplicationContextAware接口, 注入Context到静态变量中. + */ + @Override + public void setApplicationContext(ApplicationContext appContext) { + applicationContext = appContext; + } + + /** + * 实现DisposableBean接口, 在Context关闭时清理静态变量. + */ + @Override + public void destroy() { + SpringContextHolder.clearHolder(); + } +} \ No newline at end of file diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/config/AuthorizationServer.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/config/AuthorizationServer.java index 0afbaf5a..54e45751 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/config/AuthorizationServer.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/config/AuthorizationServer.java @@ -1,109 +1,109 @@ -package com.daqing.financial.hrauth.config; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.http.HttpMethod; -import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.crypto.password.PasswordEncoder; -import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; -import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; -import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; -import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer; -import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer; -import org.springframework.security.oauth2.provider.ClientDetailsService; -import org.springframework.security.oauth2.provider.code.AuthorizationCodeServices; -import org.springframework.security.oauth2.provider.code.InMemoryAuthorizationCodeServices; -import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices; -import org.springframework.security.oauth2.provider.token.DefaultTokenServices; -import org.springframework.security.oauth2.provider.token.TokenStore; - -/** - * 配置OAuth2.0授权服务器 - * - * @auther River - * @date 2020/9/21 17:49 - */ -@Configuration -@EnableAuthorizationServer -public class AuthorizationServer extends AuthorizationServerConfigurerAdapter { - - @Autowired - private TokenStore tokenStore; - - @Autowired - private ClientDetailsService clientDetailsService; - - @Autowired - private AuthenticationManager authenticationManager; - - @Autowired - private AuthorizationCodeServices authorizationCodeServices; - @Autowired - public PasswordEncoder passwordEncoder; - - /** - * 配置令牌的安全约束(允许哪些请求访问) - */ - @Override - public void configure(AuthorizationServerSecurityConfigurer security) throws Exception { - security - .tokenKeyAccess("permitAll()") // 公开提供公钥加密的端点(就是使用jwt令牌的时候需要的) - .checkTokenAccess("permitAll()") // 校验令牌 - .allowFormAuthenticationForClients(); //允许表单提交,允许客户端访问 OAuth2 授权接口,否则请求 token 会返回 401。 - } - - /** - * 配置支持哪些客户端访问 - */ - @Override - public void configure(ClientDetailsServiceConfigurer clients) throws Exception { - clients.inMemory() - .withClient("order-client") - .secret(passwordEncoder.encode("order-secret-8888")) - .authorizedGrantTypes("refresh_token", "authorization_code", "password") - .accessTokenValiditySeconds(3600) - .scopes("all") - .and() - .withClient("user-client") - .secret(passwordEncoder.encode("user-secret-8888")) - .authorizedGrantTypes("refresh_token", "authorization_code", "password") - .accessTokenValiditySeconds(3600) - .scopes("all"); - } - - /** - * 配置令牌(token)的访问端点 - */ - @Override - public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { - endpoints - .authenticationManager(authenticationManager) // 密码模式需要 - .authorizationCodeServices(authorizationCodeServices) // 授权码模式需要 - .tokenServices(tokenServices()) // 令牌的管理方式 - .allowedTokenEndpointRequestMethods(HttpMethod.POST); // 允许的请求方式 - } - - /** - * 令牌服务 - */ - @Bean - public AuthorizationServerTokenServices tokenServices(){ - DefaultTokenServices service = new DefaultTokenServices(); - service.setClientDetailsService(clientDetailsService); // 客户端信息的服务 - service.setSupportRefreshToken(true); // 是否产生刷新令牌 - service.setTokenStore(tokenStore); // 令牌的存储策略 - service.setAccessTokenValiditySeconds(7200); // 令牌有效期 - service.setRefreshTokenValiditySeconds(259200); // 刷新令牌有效期 - return service; - } - - /** - * 授权码服务(设置授权码模式的授权码如何存取,暂时在内存,后期在数据库) - */ - @Bean - public AuthorizationCodeServices authorizationCodeServices(){ - - return new InMemoryAuthorizationCodeServices(); - } -} +//package com.daqing.financial.hrauth.config; +// +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.context.annotation.Bean; +//import org.springframework.context.annotation.Configuration; +//import org.springframework.http.HttpMethod; +//import org.springframework.security.authentication.AuthenticationManager; +//import org.springframework.security.crypto.password.PasswordEncoder; +//import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; +//import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; +//import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; +//import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer; +//import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer; +//import org.springframework.security.oauth2.provider.ClientDetailsService; +//import org.springframework.security.oauth2.provider.code.AuthorizationCodeServices; +//import org.springframework.security.oauth2.provider.code.InMemoryAuthorizationCodeServices; +//import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices; +//import org.springframework.security.oauth2.provider.token.DefaultTokenServices; +//import org.springframework.security.oauth2.provider.token.TokenStore; +// +///** +// * 配置OAuth2.0授权服务器 +// * +// * @auther River +// * @date 2020/9/21 17:49 +// */ +//@Configuration +//@EnableAuthorizationServer +//public class AuthorizationServer extends AuthorizationServerConfigurerAdapter { +// +// @Autowired +// private TokenStore tokenStore; +// +// @Autowired +// private ClientDetailsService clientDetailsService; +// +// @Autowired +// private AuthenticationManager authenticationManager; +// +// @Autowired +// private AuthorizationCodeServices authorizationCodeServices; +// @Autowired +// public PasswordEncoder passwordEncoder; +// +// /** +// * 配置令牌的安全约束(允许哪些请求访问) +// */ +// @Override +// public void configure(AuthorizationServerSecurityConfigurer security) throws Exception { +// security +// .tokenKeyAccess("permitAll()") // 公开提供公钥加密的端点(就是使用jwt令牌的时候需要的) +// .checkTokenAccess("permitAll()") // 校验令牌 +// .allowFormAuthenticationForClients(); //允许表单提交,允许客户端访问 OAuth2 授权接口,否则请求 token 会返回 401。 +// } +// +// /** +// * 配置支持哪些客户端访问 +// */ +// @Override +// public void configure(ClientDetailsServiceConfigurer clients) throws Exception { +// clients.inMemory() +// .withClient("order-client") +// .secret(passwordEncoder.encode("order-secret-8888")) +// .authorizedGrantTypes("refresh_token", "authorization_code", "password") +// .accessTokenValiditySeconds(3600) +// .scopes("all") +// .and() +// .withClient("user-client") +// .secret(passwordEncoder.encode("user-secret-8888")) +// .authorizedGrantTypes("refresh_token", "authorization_code", "password") +// .accessTokenValiditySeconds(3600) +// .scopes("all"); +// } +// +// /** +// * 配置令牌(token)的访问端点 +// */ +// @Override +// public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { +// endpoints +// .authenticationManager(authenticationManager) // 密码模式需要 +// .authorizationCodeServices(authorizationCodeServices) // 授权码模式需要 +// .tokenServices(tokenServices()) // 令牌的管理方式 +// .allowedTokenEndpointRequestMethods(HttpMethod.POST); // 允许的请求方式 +// } +// +// /** +// * 令牌服务 +// */ +// @Bean +// public AuthorizationServerTokenServices tokenServices(){ +// DefaultTokenServices service = new DefaultTokenServices(); +// service.setClientDetailsService(clientDetailsService); // 客户端信息的服务 +// service.setSupportRefreshToken(true); // 是否产生刷新令牌 +// service.setTokenStore(tokenStore); // 令牌的存储策略 +// service.setAccessTokenValiditySeconds(7200); // 令牌有效期 +// service.setRefreshTokenValiditySeconds(259200); // 刷新令牌有效期 +// return service; +// } +// +// /** +// * 授权码服务(设置授权码模式的授权码如何存取,暂时在内存,后期在数据库) +// */ +// @Bean +// public AuthorizationCodeServices authorizationCodeServices(){ +// +// return new InMemoryAuthorizationCodeServices(); +// } +//} diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/config/SecurityConfig.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/config/SecurityConfig.java index a558a568..e89031ff 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/config/SecurityConfig.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/config/SecurityConfig.java @@ -1,67 +1,67 @@ -package com.daqing.financial.hrauth.config; - -import com.daqing.financial.hrauth.service.impl.UserLoginServiceImpl; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -import org.springframework.security.crypto.password.PasswordEncoder; - -/** - * @auther River - * @date 2020/9/22 10:26 - */ -@Configuration -@EnableWebSecurity // 开启security -public class SecurityConfig extends WebSecurityConfigurerAdapter { - - /** - * 不能直接new对象,否则会在注入之前被拦截器拦截 - */ - @Bean - public UserLoginServiceImpl customerLoginService(){ - - return new UserLoginServiceImpl(); - } - - // 定义用户信息(查询用户信息),security帮助我们查询,但是需要告诉他如何去查询 - @Override - protected void configure(AuthenticationManagerBuilder auth) throws Exception { - - auth.userDetailsService(customerLoginService()); - } - - - // 密码编码器,比对密码的方式 - @Bean - public PasswordEncoder passwordEncoder(){ - - return new BCryptPasswordEncoder(); - } - - /** - * 认证管理器 - */ - @Override - @Bean - public AuthenticationManager authenticationManagerBean() throws Exception { - - return super.authenticationManagerBean(); - } - - // 安全拦截机制 - @Override - protected void configure(HttpSecurity http) throws Exception { - http.authorizeRequests() - .antMatchers("/*").authenticated() // 该路径下所有请求都会被拦截 - .anyRequest().permitAll() // 其余的请求可以通过 - .and() - .formLogin() // 允许表单认证 - .successForwardUrl("/customerLogin/loginSuccess"); // 登录成功跳转路径 - } -} - +//package com.daqing.financial.hrauth.config; +// +//import com.daqing.financial.hrauth.service.impl.UserLoginServiceImpl; +//import org.springframework.context.annotation.Bean; +//import org.springframework.context.annotation.Configuration; +//import org.springframework.security.authentication.AuthenticationManager; +//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +//import org.springframework.security.config.annotation.web.builders.HttpSecurity; +//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +//import org.springframework.security.crypto.password.PasswordEncoder; +// +///** +// * @auther River +// * @date 2020/9/22 10:26 +// */ +//@Configuration +//@EnableWebSecurity // 开启security +//public class SecurityConfig extends WebSecurityConfigurerAdapter { +// +// /** +// * 不能直接new对象,否则会在注入之前被拦截器拦截 +// */ +// @Bean +// public UserLoginServiceImpl customerLoginService(){ +// +// return new UserLoginServiceImpl(); +// } +// +// // 定义用户信息(查询用户信息),security帮助我们查询,但是需要告诉他如何去查询 +// @Override +// protected void configure(AuthenticationManagerBuilder auth) throws Exception { +// +// auth.userDetailsService(customerLoginService()); +// } +// +// +// // 密码编码器,比对密码的方式 +// @Bean +// public PasswordEncoder passwordEncoder(){ +// +// return new BCryptPasswordEncoder(); +// } +// +// /** +// * 认证管理器 +// */ +// @Override +// @Bean +// public AuthenticationManager authenticationManagerBean() throws Exception { +// +// return super.authenticationManagerBean(); +// } +// +// // 安全拦截机制 +// @Override +// protected void configure(HttpSecurity http) throws Exception { +// http.authorizeRequests() +// .antMatchers("/*").authenticated() // 该路径下所有请求都会被拦截 +// .anyRequest().permitAll() // 其余的请求可以通过 +// .and() +// .formLogin() // 允许表单认证 +// .successForwardUrl("/customerLogin/loginSuccess"); // 登录成功跳转路径 +// } +//} +// diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/config/TokenConfig.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/config/TokenConfig.java index 10df81ec..7162cb11 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/config/TokenConfig.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/config/TokenConfig.java @@ -1,22 +1,22 @@ -package com.daqing.financial.hrauth.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.oauth2.provider.token.TokenStore; -import org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore; - -/** - * 令牌配置类 - * - * @auther River - * @date 2020/9/22 9:54 - */ -@Configuration -public class TokenConfig { - - @Bean - public TokenStore tokenStore(){ - // 内存生成,普通令牌 - return new InMemoryTokenStore(); - } -} +//package com.daqing.financial.hrauth.config; +// +//import org.springframework.context.annotation.Bean; +//import org.springframework.context.annotation.Configuration; +//import org.springframework.security.oauth2.provider.token.TokenStore; +//import org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore; +// +///** +// * 令牌配置类 +// * +// * @auther River +// * @date 2020/9/22 9:54 +// */ +//@Configuration +//public class TokenConfig { +// +// @Bean +// public TokenStore tokenStore(){ +// // 内存生成,普通令牌 +// return new InMemoryTokenStore(); +// } +//} diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/UserLoginController.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/UserLoginController.java index 365b35f8..4a91a547 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/UserLoginController.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/UserLoginController.java @@ -1,8 +1,11 @@ package com.daqing.financial.hrauth.controller; import com.daqing.financial.hrauth.service.UserLoginService; +import com.daqing.framework.domain.hrms.request.LoginRequest; import com.daqing.framework.domain.hrms.request.UserLoginRequest; import com.daqing.framework.model.response.ResponseResult; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -12,6 +15,7 @@ import org.springframework.web.bind.annotation.*; */ @RestController @RequestMapping("/hrms/auth/userlogin") +@Api(tags = {"登录"}) public class UserLoginController { @Autowired @@ -34,4 +38,15 @@ public class UserLoginController { boolean result = userLoginService.getBackPwd(user); return result ? ResponseResult.SUCCESS() : ResponseResult.FAIL(); } + + @PostMapping(value = "/login") + @ApiOperation(value = "用户登录") + public ResponseResult login( + @RequestBody LoginRequest loginRequest + /*@RequestParam("password") String password, @RequestParam("phone") String phone*/){ + /*LoginRequest loginRequest = new LoginRequest(); + loginRequest.setPassword(password); + loginRequest.setPhone(phone);*/ + return userLoginService.login(loginRequest); + } } diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/dao/UserLoginDao.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/dao/UserLoginDao.java index 9f7e0c18..40f41009 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/dao/UserLoginDao.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/dao/UserLoginDao.java @@ -2,6 +2,7 @@ package com.daqing.financial.hrauth.dao; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.daqing.framework.domain.hrms.UserEntity; +import com.daqing.framework.domain.hrms.request.LoginRequest; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -15,4 +16,6 @@ public interface UserLoginDao extends BaseMapper { UserEntity getUser(String code); int selectCount(String phoneAccount); int updatePasswordByPhoneAccount(@Param("phoneAccount") String phoneAccount, @Param("password") String password); + + UserEntity login(LoginRequest loginRequest); } diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/UserLoginService.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/UserLoginService.java index 5e884bfd..583a4618 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/UserLoginService.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/UserLoginService.java @@ -2,7 +2,9 @@ package com.daqing.financial.hrauth.service; import com.baomidou.mybatisplus.extension.service.IService; import com.daqing.framework.domain.hrms.UserEntity; +import com.daqing.framework.domain.hrms.request.LoginRequest; import com.daqing.framework.domain.hrms.request.UserLoginRequest; +import com.daqing.framework.model.response.ResponseResult; /** * @auther River @@ -10,4 +12,7 @@ import com.daqing.framework.domain.hrms.request.UserLoginRequest; */ public interface UserLoginService extends IService { Boolean getBackPwd(UserLoginRequest user); + + //登录 + ResponseResult login(LoginRequest loginRequest); } diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserLoginServiceImpl.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserLoginServiceImpl.java index b2e27c6b..0770b129 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserLoginServiceImpl.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserLoginServiceImpl.java @@ -4,22 +4,21 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.daqing.financial.hrauth.dao.UserLoginDao; import com.daqing.financial.hrauth.service.UserLoginService; +import com.daqing.financial.hrauth.util.JwtUtil; import com.daqing.framework.domain.hrms.UserEntity; +import com.daqing.framework.domain.hrms.request.LoginRequest; import com.daqing.framework.domain.hrms.request.UserLoginRequest; import com.daqing.framework.domain.hrms.response.HrmsCode; +import com.daqing.framework.domain.hrms.response.LoginResponse; import com.daqing.framework.exception.ExceptionCast; +import com.daqing.framework.model.response.CommonCode; +import com.daqing.framework.model.response.ResponseResult; +import com.daqing.framework.util.Md5Util; import org.apache.commons.lang3.StringUtils; -import org.springframework.security.core.authority.SimpleGrantedAuthority; -import org.springframework.security.core.userdetails.User; -import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.security.core.userdetails.UserDetailsService; -import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -28,12 +27,15 @@ import java.util.regex.Pattern; * @date 2020/9/22 15:01 */ @Service("userLoginService") -public class UserLoginServiceImpl extends ServiceImpl implements UserLoginService, UserDetailsService { +public class UserLoginServiceImpl extends ServiceImpl implements UserLoginService{ @Resource private UserLoginDao userLoginDao; - @Override +/* @Autowired + private OdcProperties properties;*/ + +/* @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { UserEntity user = userLoginDao.getUser(username); List authorities = new ArrayList<>(); @@ -42,7 +44,7 @@ public class UserLoginServiceImpl extends ServiceImpl UserDetails userDetails = new User(user.getAccount(),new BCryptPasswordEncoder().encode(user.getPassword()),authorities); return userDetails; - } + }*/ /** * 忘记密码 @@ -78,4 +80,41 @@ public class UserLoginServiceImpl extends ServiceImpl int i = userLoginDao.updatePasswordByPhoneAccount(user.getPhoneAccount(),newMD5); return i > 0; } + + public ResponseResult login(LoginRequest loginRequest) { + //判断用户登录方式 + UserEntity userEntity = baseMapper.login(loginRequest); + if(loginRequest.getType() == 1){//手机号码登录 + + if(userEntity == null){ + return ResponseResult.FAIL(CommonCode.USER_IS_NOT_EXIST.code(), CommonCode.USER_IS_NOT_EXIST.message()); + } + String newPassword = Md5Util.md5(loginRequest.getPassword()+userEntity.getId()); + if(!newPassword.equals(loginRequest.getPassword())){ + return ResponseResult.FAIL(CommonCode.PASSWORD_IS_ERROR.code(), CommonCode.PASSWORD_IS_ERROR.message()); + } + + + }else {//微信登录 + + } + + //登录成功,token生成 + long times = 84600; + if(loginRequest.getTenDayEffective() == 1){ + times = 846000; + } + String token = JwtUtil.createJwtToken(userEntity.getId(), times); + if (true) { + JwtUtil.removeTokenByUserId(userEntity.getId()); + } + JwtUtil.putTokenToRedis(userEntity.getId(), token, times); + + //返回用户信息 + LoginResponse loginResponse = new LoginResponse(); + loginResponse.setAccount(userEntity.getAccount()); + loginResponse.setToken(token); + + return ResponseResult.SUCCESS(loginResponse); + } } diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/util/JwtUtil.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/util/JwtUtil.java new file mode 100644 index 00000000..1502c23f --- /dev/null +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/util/JwtUtil.java @@ -0,0 +1,71 @@ +package com.daqing.financial.hrauth.util; + + +import com.auth0.jwt.JWT; +import com.auth0.jwt.algorithms.Algorithm; +import com.daqing.financial.hrauth.SpringContextHolder; + +import java.util.Date; +import java.util.Set; + +/** + * @author zcw + * @version 1.0 + * @date 2019/11/23 11:06 + * @description jwt工具类 + */ +public class JwtUtil { + + private final static Algorithm algorithm = SpringContextHolder.getBean("algorithm", Algorithm.class); + + //private final static OdcProperties properties = SpringContextHolder.getBean("odcProperties", OdcProperties.class); + + /** + * 创建token + * + * @param userId; + * @param timeout; 单位是秒 + */ + public static String createJwtToken(Long userId, long timeout) { + return JWT.create() + .withClaim("member", userId) + .withExpiresAt(new Date(System.currentTimeMillis() + timeout * 1000)) + .sign(algorithm); + } + + /** + * token正确且有效,则返回userId + */ + public static Long verifyToken(String token) { + try { + String noBearerToken = token.replaceFirst("Bearer ", ""); + Long userId = JWT.require(algorithm) + .build() + .verify(noBearerToken) + .getClaim("member") + .asLong(); + if (RedisUtil.get(getRedisKey(userId, noBearerToken)) != null) { + return userId; + } + } catch (Exception e) { + e.printStackTrace(); + return null; + } + return null; + } + + public static String getRedisKey(Long userId, String token) { + return String.format("dq:token:%d:%s", userId, token); + } + + public static void putTokenToRedis(Long userId, String token, long times) { + RedisUtil.setEx(getRedisKey(userId, token), "nothing", times); + } + + public static void removeTokenByUserId(Long userId) { + Set tokenSet = RedisUtil.keys(getRedisKey(userId, "*")); + for (String key : tokenSet) { + RedisUtil.del(key); + } + } +} diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/util/RedisUtil.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/util/RedisUtil.java new file mode 100644 index 00000000..de1bf1a8 --- /dev/null +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/util/RedisUtil.java @@ -0,0 +1,298 @@ +package com.daqing.financial.hrauth.util; + + +import com.daqing.financial.hrauth.SpringContextHolder; +import org.springframework.data.redis.core.HashOperations; +import org.springframework.data.redis.core.ListOperations; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.data.redis.core.ValueOperations; + +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +/** + * redis工具类 + */ +public class RedisUtil { + + private final static StringRedisTemplate stringRedisTemplate = SpringContextHolder.getBean("stringRedisTemplate"); + + /** + * 匹配key + */ + public static Set keys(String pattern) { + return stringRedisTemplate.keys(pattern); + } + + /** + * 删除一个key + */ + public static void del(String key) { + stringRedisTemplate.delete(key); + } + + /** + * 批量删除key + */ + public static void delByPattern(String pattern) { + Set keySet = keys(pattern); + stringRedisTemplate.delete(keySet); + } + + /** + * 设置过期时间,单位为秒 + */ + public static boolean expire(String key, long seconds) { + return stringRedisTemplate.expire(key, seconds, TimeUnit.SECONDS); + } + + /** + * 获取自动过期时间 + */ + public static long ttl(String key) { + return stringRedisTemplate.getExpire(key, TimeUnit.SECONDS); + } + + /** + * 移除过期时间 + */ + public static boolean persist(String key) { + return stringRedisTemplate.persist(key); + } + + /////// String 操作 + + /** + * 给key赋值 + */ + public static void set(String key, String value) { + ValueOperations op = stringRedisTemplate.opsForValue(); + op.set(key, value); + } + + /** + * 给key赋值,并设置过期时间,单位为秒 + */ + public static void setEx(String key, String value, long seconds) { + set(key, value); + expire(key, seconds); + } + + /** + * 将key的值加num + */ + public static void incrBy(String key, long num) { + ValueOperations op = stringRedisTemplate.opsForValue(); + op.increment(key, num); + } + + /** + * 获取key的值 + */ + public static String get(String key) { + ValueOperations op = stringRedisTemplate.opsForValue(); + return op.get(key); + } + + /////// list操作 + + /** + * 插入到表头 + */ + public static void lPush(String key, String... values) { + ListOperations listOp = stringRedisTemplate.opsForList(); + listOp.leftPushAll(key, values); + } + + /** + * 移除第一个 + */ + public static String rPop(String key) { + ListOperations listOp = stringRedisTemplate.opsForList(); + return listOp.rightPop(key); + } + + /** + * 获取list所有 + * + * @param key + * @param start + * @param end + * @return + */ + public static List lRange(String key, int start, int end) { + ListOperations opsForList = stringRedisTemplate.opsForList(); + return opsForList.range(key, start, end); + } + + /////// hash + + /* + * public static void hset(String key,String hashKey,String value){ + * HashOperations opsForHash = + * stringRedisTemplate.opsForHash(); opsForHash.put(key, hashKey, value); } + */ + /////// set + /////// sorted set + + /** + * 存放list + * @param key + * @param list + */ + public static void setList(String key, List list){ + ListOperations opsForList = stringRedisTemplate.opsForList(); + opsForList.leftPushAll(key, list); + } + + /** + * HashGet + * @param key 键 不能为null + * @param item 项 不能为null + * @return 值 + */ + public static Object hGet(String key,String item){ + HashOperations mapOp = stringRedisTemplate.opsForHash(); + return mapOp.get(key, item); + } + + /** + * 获取hashKey对应的所有键值 + * @param key 键 + * @return 对应的多个键值 + */ + public static Map hmGet(String key){ + HashOperations mapOp = stringRedisTemplate.opsForHash(); + return mapOp.entries(key); + } + + /** + * HashSet + * @param key 键 + * @param map 对应多个键值 + * @return true 成功 false 失败 + */ + public static boolean hmSet(String key, Map map){ + try { + HashOperations mapOp = stringRedisTemplate.opsForHash(); + mapOp.putAll(key, map); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * HashSet 并设置时间 + * @param key 键 + * @param map 对应多个键值 + * @param time 时间(秒) + * @return true成功 false失败 + */ + public static boolean hmset(String key, Map map, long time){ + try { + HashOperations mapOp = stringRedisTemplate.opsForHash(); + mapOp.putAll(key, map); + if(time>0){ + expire(key, time); + } + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 向一张hash表中放入数据,如果不存在将创建 + * @param key 键 + * @param item 项 + * @param value 值 + * @return true 成功 false失败 + */ + public static boolean hset(String key,String item,Object value) { + try { + HashOperations mapOp = stringRedisTemplate.opsForHash(); + mapOp.put(key, item, value); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 向一张hash表中放入数据,如果不存在将创建 + * @param key 键 + * @param item 项 + * @param value 值 + * @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间 + * @return true 成功 false失败 + */ + public static boolean hset(String key,String item,Object value,long time) { + try { + HashOperations mapOp = stringRedisTemplate.opsForHash(); + mapOp.put(key, item, value); + if(time>0){ + expire(key, time); + } + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 删除hash表中的值 + * @param key 键 不能为null + * @param item 项 可以使多个 不能为null + */ + public static void hdel(String key, Object... item){ + HashOperations mapOp = stringRedisTemplate.opsForHash(); + + mapOp.delete(key,item); + } + + /** + * 判断hash表中是否有该项的值 + * @param key 键 不能为null + * @param item 项 不能为null + * @return true 存在 false不存在 + */ + public static boolean hHasKey(String key, String item){ + HashOperations mapOp = stringRedisTemplate.opsForHash(); + + return mapOp.hasKey(key, item); + } + + /** + * hash递增 如果不存在,就会创建一个 并把新增后的值返回 + * @param key 键 + * @param item 项 + * @param by 要增加几(大于0) + * @return + */ + public static double hincr(String key, String item,double by){ + HashOperations mapOp = stringRedisTemplate.opsForHash(); + + return mapOp.increment(key, item, by); + } + + /** + * hash递减 + * @param key 键 + * @param item 项 + * @param by 要减少记(小于0) + * @return + */ + public static double hdecr(String key, String item,double by){ + HashOperations mapOp = stringRedisTemplate.opsForHash(); + + return mapOp.increment(key, item,-by); + } + +} diff --git a/dq-financial-hrms-auth/src/main/resources/bootstrap.properties b/dq-financial-hrms-auth/src/main/resources/bootstrap.properties index 40330e13..a7c7a0bb 100644 --- a/dq-financial-hrms-auth/src/main/resources/bootstrap.properties +++ b/dq-financial-hrms-auth/src/main/resources/bootstrap.properties @@ -1,6 +1,6 @@ #�������� -spring.application.name=dq-financial-hrms +spring.application.name=dq-financial-hrms-auth #�������ĵ�ַ spring.cloud.nacos.config.server-addr=192.168.31.142:8848 spring.cloud.nacos.config.namespace=7632bdaa-3381-4669-b3f9-2fc73be451e8 diff --git a/dq-financial-hrms-auth/src/main/resources/mapper/hrmsauth/UserLoginMapper.xml b/dq-financial-hrms-auth/src/main/resources/mapper/hrmsauth/UserLoginMapper.xml index 00a7fad6..a1e90a4b 100644 --- a/dq-financial-hrms-auth/src/main/resources/mapper/hrmsauth/UserLoginMapper.xml +++ b/dq-financial-hrms-auth/src/main/resources/mapper/hrmsauth/UserLoginMapper.xml @@ -13,4 +13,16 @@ select count(1) from hrms_user where phone_account = #{phoneAccount} + + select id,account,phone_account,password,login_num from hrms_user + where del_or_not = 0 and status = 0 + + and phone_account = #{loginRequest.phone} + + + and wechat_id = #{loginRequest.wechat_id} + + + + \ No newline at end of file diff --git a/dq-financial-hrms-auth/src/test/java/com/daqing/financial/hrauth/DqFinancialHrmsAuthApplicationTests.java b/dq-financial-hrms-auth/src/test/java/com/daqing/financial/hrauth/DqFinancialHrmsAuthApplicationTests.java index a39aa46e..6ea6444c 100644 --- a/dq-financial-hrms-auth/src/test/java/com/daqing/financial/hrauth/DqFinancialHrmsAuthApplicationTests.java +++ b/dq-financial-hrms-auth/src/test/java/com/daqing/financial/hrauth/DqFinancialHrmsAuthApplicationTests.java @@ -1,13 +1,13 @@ -package com.daqing.financial.hrauth; - -import org.junit.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class DqFinancialHrmsAuthApplicationTests { - - @Test - void contextLoads() { - } - -} +//package com.daqing.financial.hrauth; +// +//import org.junit.Test; +//import org.springframework.boot.test.context.SpringBootTest; +// +//@SpringBootTest +//class DqFinancialHrmsAuthApplicationTests { +// +// @Test +// void contextLoads() { +// } +// +//} diff --git a/dq-financial-workflow/pom.xml b/dq-financial-workflow/pom.xml deleted file mode 100644 index 96d34131..00000000 --- a/dq-financial-workflow/pom.xml +++ /dev/null @@ -1,76 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.1.8.RELEASE - - - com.daqing.financial - dq-financial-workflow - 0.0.1-SNAPSHOT - dq-financial-workflow - 大庆智慧金融平台-工作流服务 - - - 1.8 - Greenwich.SR3 - - - - - com.daqing.framework - dq-framework-common - 1.0-SNAPSHOT - - - com.daqing.framework - dq-framework-model - 1.0-SNAPSHOT - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.cloud - spring-cloud-starter-openfeign - - - - org.springframework.boot - spring-boot-starter-test - test - - - org.junit.vintage - junit-vintage-engine - - - - - - - - - org.springframework.cloud - spring-cloud-dependencies - ${spring-cloud.version} - pom - import - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/dq-financial-workflow/src/main/java/com/daqing/financial/workflow/DqFinancialWorkflowApplication.java b/dq-financial-workflow/src/main/java/com/daqing/financial/workflow/DqFinancialWorkflowApplication.java deleted file mode 100644 index cd7c9823..00000000 --- a/dq-financial-workflow/src/main/java/com/daqing/financial/workflow/DqFinancialWorkflowApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.daqing.financial.workflow; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class DqFinancialWorkflowApplication { - - public static void main(String[] args) { - SpringApplication.run(DqFinancialWorkflowApplication.class, args); - } - -} diff --git a/dq-financial-workflow/src/main/resources/application.properties b/dq-financial-workflow/src/main/resources/application.properties deleted file mode 100644 index 8b137891..00000000 --- a/dq-financial-workflow/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ - diff --git a/dq-financial-workflow/src/main/resources/logback-spring.xml b/dq-financial-workflow/src/main/resources/logback-spring.xml deleted file mode 100644 index 067d56bd..00000000 --- a/dq-financial-workflow/src/main/resources/logback-spring.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - - - - - %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - utf8 - - - - - - - - ${LOG_HOME}/workflow.%d{yyyy-MM-dd}.log - - - %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - 0 - - 512 - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/dq-financial-workflow/src/test/java/com/daqing/financial/workflow/DqFinancialWorkflowApplicationTests.java b/dq-financial-workflow/src/test/java/com/daqing/financial/workflow/DqFinancialWorkflowApplicationTests.java deleted file mode 100644 index df9bd3ac..00000000 --- a/dq-financial-workflow/src/test/java/com/daqing/financial/workflow/DqFinancialWorkflowApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.daqing.financial.workflow; - -import org.junit.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class DqFinancialWorkflowApplicationTests { - - @Test - void contextLoads() { - } - -} diff --git a/dq-framework-common/pom.xml b/dq-framework-common/pom.xml index 4dd9b22a..51d36fa3 100644 --- a/dq-framework-common/pom.xml +++ b/dq-framework-common/pom.xml @@ -102,6 +102,24 @@ com.alibaba.cloud spring-cloud-starter-alibaba-nacos-config + + + com.auth0 + java-jwt + 3.3.0 + + + + com.alibaba + fastjson + 1.2.70 + + + + org.springframework.boot + spring-boot-starter-data-redis + 2.1.8.RELEASE + diff --git a/dq-framework-common/src/main/java/com/daqing/framework/model/response/CommonCode.java b/dq-framework-common/src/main/java/com/daqing/framework/model/response/CommonCode.java index 259467a7..24a89f0f 100644 --- a/dq-framework-common/src/main/java/com/daqing/framework/model/response/CommonCode.java +++ b/dq-framework-common/src/main/java/com/daqing/framework/model/response/CommonCode.java @@ -19,6 +19,8 @@ public enum CommonCode implements ResultCode { UNAUTHENTICATED(false, 10001, "此操作需要登陆系统!"), UNAUTHORISE(false, 10002, "权限不足,无权操作!"), INVALID_PARAM(false, 10003, "非法参数!"), + USER_IS_NOT_EXIST(false, 10004, "用户不存在或用户已禁用!"), + PASSWORD_IS_ERROR(false, 10005, "密码错误!"), SERVER_ERROR(false, 99999, "抱歉,系统繁忙,请稍后重试!"); /** diff --git a/dq-framework-common/src/main/java/com/daqing/framework/model/response/ResponseResult.java b/dq-framework-common/src/main/java/com/daqing/framework/model/response/ResponseResult.java index c897e97e..607c6a1d 100644 --- a/dq-framework-common/src/main/java/com/daqing/framework/model/response/ResponseResult.java +++ b/dq-framework-common/src/main/java/com/daqing/framework/model/response/ResponseResult.java @@ -52,7 +52,7 @@ public class ResponseResult { return new ResponseResult(CommonCode.SUCCESS); } - public ResponseResult SUCCESS(T t) { + public static ResponseResult SUCCESS(Object t) { return new ResponseResult<>(true, 10000, t, "操作成功!"); } @@ -60,4 +60,8 @@ public class ResponseResult { return new ResponseResult(CommonCode.FAIL); } + public static ResponseResult FAIL(int code, String message) { + return new ResponseResult<>(false, code, null, message); + } + } diff --git a/dq-framework-common/src/main/java/com/daqing/framework/util/Md5Util.java b/dq-framework-common/src/main/java/com/daqing/framework/util/Md5Util.java new file mode 100644 index 00000000..c2fa7837 --- /dev/null +++ b/dq-framework-common/src/main/java/com/daqing/framework/util/Md5Util.java @@ -0,0 +1,20 @@ + +package com.daqing.framework.util; + +import org.springframework.util.DigestUtils; + +/** + * @author zcw + * @version 1.0 + * @date 2020/1/6 17:03 + * @description md5工具类 + */ +public class Md5Util { + + public static String md5(String str) { + if (str == null) { + return null; + } + return DigestUtils.md5DigestAsHex(str.getBytes()); + } +} diff --git a/dq-framework-common/target/classes/com/daqing/framework/model/response/CommonCode.class b/dq-framework-common/target/classes/com/daqing/framework/model/response/CommonCode.class index 2f3adc83..e7fabb96 100644 Binary files a/dq-framework-common/target/classes/com/daqing/framework/model/response/CommonCode.class and b/dq-framework-common/target/classes/com/daqing/framework/model/response/CommonCode.class differ diff --git a/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/request/LoginRequest.java b/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/request/LoginRequest.java new file mode 100644 index 00000000..a8ba2434 --- /dev/null +++ b/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/request/LoginRequest.java @@ -0,0 +1,23 @@ +package com.daqing.framework.domain.hrms.request; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +public class LoginRequest { + + @ApiModelProperty(value = "手机号码") + private String phone; + + @ApiModelProperty(value = "登录类型(1:手机号 2:微信登录)") + private int type; + + @ApiModelProperty(value = "微信唯一编号") + private String wechatId; + + @ApiModelProperty(value = "密码") + private String password; + + @ApiModelProperty(value = "登录十天有效 1:有效 2:不处理") + private int tenDayEffective; +} diff --git a/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/request/UserLoginRequest.java b/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/request/UserLoginRequest.java index 651f8fcd..bb485b32 100644 --- a/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/request/UserLoginRequest.java +++ b/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/request/UserLoginRequest.java @@ -2,6 +2,7 @@ package com.daqing.framework.domain.hrms.request; import lombok.Data; +import javax.validation.constraints.Pattern; import java.io.Serializable; /** @@ -21,6 +22,7 @@ public class UserLoginRequest implements Serializable { /**A * 密码 */ + @Pattern(regexp = "^[a-zA-Z0-9]{8,20}$") private String password; /** diff --git a/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/response/LoginResponse.java b/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/response/LoginResponse.java new file mode 100644 index 00000000..9be2a5a1 --- /dev/null +++ b/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/response/LoginResponse.java @@ -0,0 +1,12 @@ +package com.daqing.framework.domain.hrms.response; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +public class LoginResponse { + @ApiModelProperty(value = "用户名") + private String account; + @ApiModelProperty("token令牌") + private String token; +} diff --git a/dq-govern-gateway/src/main/java/com/daqing/financial/gateway/exception/DqException.java b/dq-govern-gateway/src/main/java/com/daqing/financial/gateway/exception/DqException.java deleted file mode 100644 index 81a9cb24..00000000 --- a/dq-govern-gateway/src/main/java/com/daqing/financial/gateway/exception/DqException.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.daqing.financial.gateway.exception; - -import com.daqing.financial.gateway.util.ResultCodeEnum; -import lombok.Data; - -@Data -public class DqException extends RuntimeException { - - private int code; - - private ResultCodeEnum resultCodeEnum; - - public DqException(ResultCodeEnum codeEnum) { - super(codeEnum.getRemark()); - code = codeEnum.getCode(); - } - - public int getCode() { - return code; - } - - public ResultCodeEnum getResultCodeEnum() { - return resultCodeEnum; - } -} \ No newline at end of file diff --git a/dq-govern-gateway/src/main/java/com/daqing/financial/gateway/util/JwtUtil.java b/dq-govern-gateway/src/main/java/com/daqing/financial/gateway/util/JwtUtil.java index 46547e6f..af0d0001 100644 --- a/dq-govern-gateway/src/main/java/com/daqing/financial/gateway/util/JwtUtil.java +++ b/dq-govern-gateway/src/main/java/com/daqing/financial/gateway/util/JwtUtil.java @@ -1,10 +1,9 @@ package com.daqing.financial.gateway.util; + import com.auth0.jwt.JWT; import com.auth0.jwt.algorithms.Algorithm; - import com.daqing.financial.gateway.SpringContextHolder; -import com.daqing.financial.gateway.exception.DqException; import java.util.Date; import java.util.Set; @@ -19,7 +18,7 @@ public class JwtUtil { private final static Algorithm algorithm = SpringContextHolder.getBean("algorithm", Algorithm.class); - private final static OdcProperties properties = SpringContextHolder.getBean("odcProperties", OdcProperties.class); + //private final static OdcProperties properties = SpringContextHolder.getBean("odcProperties", OdcProperties.class); /** * 创建token @@ -49,17 +48,18 @@ public class JwtUtil { return userId; } } catch (Exception e) { - throw new DqException(ResultCodeEnum.UN_AUTHORIZATION); + e.printStackTrace(); + return null; } - throw new DqException(ResultCodeEnum.UN_AUTHORIZATION); + return null; } public static String getRedisKey(Long userId, String token) { - return String.format(properties.getConfig().getTokenRedisKeyFormat(), userId, token); + return String.format("dq:token:%d:%s", userId, token); } - public static void putTokenToRedis(Long userId, String token) { - RedisUtil.setEx(getRedisKey(userId, token), "nothing", properties.getConfig().getTokenExpireSeconds()); + public static void putTokenToRedis(Long userId, String token, long times) { + RedisUtil.setEx(getRedisKey(userId, token), "nothing", times); } public static void removeTokenByUserId(Long userId) { diff --git a/dq-govern-gateway/src/main/java/com/daqing/financial/gateway/util/ResultCodeEnum.java b/dq-govern-gateway/src/main/java/com/daqing/financial/gateway/util/ResultCodeEnum.java deleted file mode 100644 index 62846ece..00000000 --- a/dq-govern-gateway/src/main/java/com/daqing/financial/gateway/util/ResultCodeEnum.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.daqing.financial.gateway.util; - -public enum ResultCodeEnum { - - SUCCESS(0, "请求成功"), - BAD_REQUEST(400, "错误请求"), - UN_AUTHORIZATION(401, "未授权"), - SERVER_EXCEPTION(500, "服务器异常"), - - ACCOUNT_NOT_EXIST(10000, "账号不存在"), - ACCOUNT_NOT_BIND(10001, "账号未绑定钱包"), - ACCOUNT_NOT_ACTIVE(10002, "账号未激活"), - ACCOUNT_EXIST(10003, "账号已存在,请登录"), - COIN_ADDRESS_IS_NOT_EXIST(10004, "该币种地址不存在"), - COIN_NAME_IS_NOT_EXIST(10005, "该币种不存在"), - - WALLET_BAD_PARAM(10100, "非法参数,禁止访问他人账号"), - WALLET_NOT_ENOUGH(10101, "可用余额不足"), - SUB_ACCOUNT_NOT_ALLOW_WITHDRAW(10102, "子账号不允许提币"), - USER_NAME_ALREADY_EXISTS(10103,"用户名已存在"), - USER_EMAIL_ALREADY_EXISTS(10104,"邮箱已存在"), - INVITATION_CODE_NOT_EXIST(10105,"邀请码不存在"), - DEVICE_EXIST(10106,"设备号相同"), - LOGINPASSWORD_ERROR(10107,"登录密码错误"), - ACCOUNT_DISABLED(10108,"账号已禁用"), - USER_NAME_IS_ENABLE(10109,"用户名不存在"), - USER_IS_ACTIVE(10111,"该用户已激活"), - PAY_PASSWORD_IS_ERROR(10112,"支付密码错误"), - USER_IS_ACTIVE_MAX(10113,"您的激活次数已上线"), - WITHDRAW_IS_ENABLE(10114,"该币种已关闭提币通道"), - WITHDRAW_IS_NOT_BEGIN_TIME(10115,"未到提币时间"), - WITHDRAW_IS_SUPER_END_TIME(10116,"提币时间已过"), - WITHDRAW_MIN_ERROR(10117,"不能小于最小提币金额"), - WITHDRAW_MAX_ERROR(10118,"不能大于最大提币金额"), - WITHDRAW_MAX_TODAY(10120,"当日提币金额已上限"), - TRANSFER_IS_ENABLE(10121,"该币种已关闭转账通道"), - TRANSFER_MIN_ERROR(10122,"不能小于最小转账金额"), - TRANSFER_MAX_ERROR(10123,"不能大于最大转账金额"), - TRANSFER_MAX_TODAY(10124,"当日转账金额已上限"), - USERNAME_AND_EMAIL_ERROR(10125,"用户名和邮箱不匹配"), - EMAIL_CODE_IS_ERROR(10126,"验证码错误"), - PAY_PASSWORD_IS_NULL(10127,"请先设置支付密码"), - CHAIN_IS_ERROR(10128,"链上异常请联系管理员"); - - - - private final int code; - private final String remark; - - ResultCodeEnum(int code, String remark) { - this.code = code; - this.remark = remark; - } - - public int getCode() { - return code; - } - - public String getRemark() { - return remark; - } -} diff --git a/dq-govern-gateway/src/main/resources/jwt.properties b/dq-govern-gateway/src/main/resources/jwt.properties index b72b07ea..8697f53c 100644 --- a/dq-govern-gateway/src/main/resources/jwt.properties +++ b/dq-govern-gateway/src/main/resources/jwt.properties @@ -1 +1 @@ -jwt.ignoreUrlList=/api/hrms/employee/list,/route-api/refresh \ No newline at end of file +jwt.ignoreUrlList=/api/hrms/employee/list,/apiHrmsAuth/hrms/auth/userlogin/login \ No newline at end of file diff --git a/pom.xml b/pom.xml index ecd9c34b..3802a3da 100644 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,7 @@ dq-financial-hrms-auth dq-financial-crms dq-financial-crms-auth - dq-financial-workflow - dq-financial-guarantee +