From a43b6b8ca01acce36c4f407448acb5f65467c152 Mon Sep 17 00:00:00 2001 From: panqihua Date: Fri, 10 Feb 2023 16:46:44 +0800 Subject: [PATCH] =?UTF-8?q?1.=E8=B0=83=E6=95=B4=E9=A1=B9=E7=9B=AE=E7=BB=93?= =?UTF-8?q?=E6=9E=84=202.=E5=A2=9E=E5=8A=A0=E5=BA=97=E5=AE=B6=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E7=99=BB=E5=BD=95=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 + ruoyi-admin/pom.xml | 8 +- .../platform/PlatformSmsController.java | 8 +- .../PlatformStoreAccountController.java | 47 ++++--- .../com/ruoyi/common/constant/Constants.java | 9 +- .../com/ruoyi/common/enums/AccountType.java | 17 +++ ruoyi-framework/pom.xml | 9 +- .../framework/config/SecurityConfig.java | 4 +- ...peUsernamePasswordAuthenticationToken.java | 34 +++++ .../filter/JwtAuthenticationTokenFilter.java | 50 ++++--- .../web/service/StoreLoginService.java | 35 +++++ .../web/service/SysLoginService.java | 24 ++-- .../framework/web/service/TokenService.java | 82 ++++++++--- .../web/service/UserDetailsServiceImpl.java | 86 ++++++++---- ttsbg-framework/pom.xml | 26 ++++ .../framework/domain/PlatformLoginUser.java | 76 +++++++++++ .../java/com/ruoyi/framework/domain/Sms.java | 6 +- .../com/ruoyi/framework/mapper/SmsMapper.java | 24 ++-- .../ruoyi/framework/service/ISmsService.java | 24 ++-- .../service/impl/SmsServiceImpl.java | 54 ++++---- .../resources/mapper}/PlatformSmsMapper.xml | 10 +- ttsbg-platform/pom.xml | 6 + .../mapper/PlatformStoreAccountMapper.java | 56 -------- .../service/IPlatformStoreAccountService.java | 64 --------- .../impl/PlatformStoreAccountServiceImpl.java | 127 ------------------ ttsbg-store/pom.xml | 32 +++++ .../com/ruoyi/store/domain/StoreAccount.java | 7 +- .../ruoyi/store/domain/StoreLoginUser.java | 20 +++ .../ruoyi/store/domain/vo/StoreAccountVo.java | 4 +- .../store/mapper/StoreAccountMapper.java | 56 ++++++++ .../store/service/IStoreAccountService.java | 73 ++++++++++ .../service/impl/StoreAccountServiceImpl.java | 127 ++++++++++++++++++ 32 files changed, 791 insertions(+), 416 deletions(-) create mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/enums/AccountType.java create mode 100644 ruoyi-framework/src/main/java/com/ruoyi/framework/security/TypeUsernamePasswordAuthenticationToken.java create mode 100644 ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/StoreLoginService.java create mode 100644 ttsbg-framework/pom.xml create mode 100644 ttsbg-framework/src/main/java/com/ruoyi/framework/domain/PlatformLoginUser.java rename ttsbg-platform/src/main/java/com/ruoyi/platform/domain/PlatformSms.java => ttsbg-framework/src/main/java/com/ruoyi/framework/domain/Sms.java (94%) rename ttsbg-platform/src/main/java/com/ruoyi/platform/mapper/PlatformSmsMapper.java => ttsbg-framework/src/main/java/com/ruoyi/framework/mapper/SmsMapper.java (55%) rename ttsbg-platform/src/main/java/com/ruoyi/platform/service/IPlatformSmsService.java => ttsbg-framework/src/main/java/com/ruoyi/framework/service/ISmsService.java (62%) rename ttsbg-platform/src/main/java/com/ruoyi/platform/service/impl/PlatformSmsServiceImpl.java => ttsbg-framework/src/main/java/com/ruoyi/framework/service/impl/SmsServiceImpl.java (55%) rename {ttsbg-platform/src/main/resources/mapper/platform => ttsbg-framework/src/main/resources/mapper}/PlatformSmsMapper.xml (90%) delete mode 100644 ttsbg-platform/src/main/java/com/ruoyi/platform/mapper/PlatformStoreAccountMapper.java delete mode 100644 ttsbg-platform/src/main/java/com/ruoyi/platform/service/IPlatformStoreAccountService.java delete mode 100644 ttsbg-platform/src/main/java/com/ruoyi/platform/service/impl/PlatformStoreAccountServiceImpl.java create mode 100644 ttsbg-store/pom.xml rename ttsbg-platform/src/main/java/com/ruoyi/platform/domain/PlatformStoreAccount.java => ttsbg-store/src/main/java/com/ruoyi/store/domain/StoreAccount.java (95%) create mode 100644 ttsbg-store/src/main/java/com/ruoyi/store/domain/StoreLoginUser.java rename ttsbg-platform/src/main/java/com/ruoyi/platform/domain/vo/PlatformStoreAccountVo.java => ttsbg-store/src/main/java/com/ruoyi/store/domain/vo/StoreAccountVo.java (73%) create mode 100644 ttsbg-store/src/main/java/com/ruoyi/store/mapper/StoreAccountMapper.java create mode 100644 ttsbg-store/src/main/java/com/ruoyi/store/service/IStoreAccountService.java create mode 100644 ttsbg-store/src/main/java/com/ruoyi/store/service/impl/StoreAccountServiceImpl.java diff --git a/pom.xml b/pom.xml index cf861d0..5acb2e8 100644 --- a/pom.xml +++ b/pom.xml @@ -189,6 +189,8 @@ ruoyi-generator ruoyi-common ttsbg-platform + ttsbg-store + ttsbg-framework pom diff --git a/ruoyi-admin/pom.xml b/ruoyi-admin/pom.xml index 7029f3a..2c660e3 100644 --- a/ruoyi-admin/pom.xml +++ b/ruoyi-admin/pom.xml @@ -66,7 +66,13 @@ com.ruoyi ttsbg-platform 3.8.5 - compile + + + + + com.ruoyi + ttsbg-store + 3.8.5 diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/platform/PlatformSmsController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/platform/PlatformSmsController.java index 9dff94a..24ac18d 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/platform/PlatformSmsController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/platform/PlatformSmsController.java @@ -3,8 +3,8 @@ package com.ruoyi.web.controller.platform; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.enums.PlatformConfig; -import com.ruoyi.platform.domain.PlatformSms; -import com.ruoyi.platform.service.IPlatformSmsService; +import com.ruoyi.framework.domain.Sms; +import com.ruoyi.framework.service.ISmsService; import com.ruoyi.system.service.ISysConfigService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; @@ -18,13 +18,13 @@ import org.springframework.web.bind.annotation.RestController; public class PlatformSmsController extends BaseController { @Autowired - private IPlatformSmsService platformSmsService; + private ISmsService platformSmsService; @Autowired private ISysConfigService sysConfigService; @PostMapping("send") - public AjaxResult send(@Validated @RequestBody PlatformSms sms) { + public AjaxResult send(@Validated @RequestBody Sms sms) { return success(platformSmsService.send(sms.getMobile(), Integer.valueOf(sysConfigService.selectConfigById(PlatformConfig.smsTime.getConfigId()).getConfigValue()))); } } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/platform/store/account/PlatformStoreAccountController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/platform/store/account/PlatformStoreAccountController.java index fd3eb05..2b40bba 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/platform/store/account/PlatformStoreAccountController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/platform/store/account/PlatformStoreAccountController.java @@ -1,14 +1,16 @@ -package com.ruoyi.platform.controller; +package com.ruoyi.web.controller.platform.store.account; import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.constant.Constants; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.poi.ExcelUtil; -import com.ruoyi.platform.domain.PlatformStoreAccount; -import com.ruoyi.platform.domain.vo.PlatformStoreAccountVo; -import com.ruoyi.platform.service.IPlatformStoreAccountService; +import com.ruoyi.framework.web.service.StoreLoginService; +import com.ruoyi.store.domain.StoreAccount; +import com.ruoyi.store.domain.vo.StoreAccountVo; +import com.ruoyi.store.service.IStoreAccountService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; @@ -26,22 +28,33 @@ import java.util.List; @RequestMapping("/platform/store/account") public class PlatformStoreAccountController extends BaseController { @Autowired - private IPlatformStoreAccountService platformStoreAccountService; + private IStoreAccountService platformStoreAccountService; + @Autowired + private StoreLoginService loginService; @PostMapping("register") - public AjaxResult register(@RequestBody PlatformStoreAccountVo account) { + public AjaxResult register(@RequestBody StoreAccountVo account) { return success(platformStoreAccountService.register(account)); } + @PostMapping("login") + public AjaxResult login(@RequestBody StoreAccountVo account) { + AjaxResult ajax = AjaxResult.success("登陆成功"); + // 生成令牌 + String token = loginService.login(account.getMobile(), account.getPassword()); + ajax.put(Constants.TOKEN, token); + return ajax; + } + /** * 查询店家账号列表 */ @PreAuthorize("@ss.hasPermi('platform:account:list')") @GetMapping("/list") - public TableDataInfo list(PlatformStoreAccount platformStoreAccount) { + public TableDataInfo list(StoreAccount platformStoreAccount) { startPage(); - List list = platformStoreAccountService.selectPlatformStoreAccountList(platformStoreAccount); + List list = platformStoreAccountService.selectStoreAccountList(platformStoreAccount); return getDataTable(list); } @@ -51,9 +64,9 @@ public class PlatformStoreAccountController extends BaseController { @PreAuthorize("@ss.hasPermi('platform:account:export')") @Log(title = "店家账号", businessType = BusinessType.EXPORT) @PostMapping("/export") - public void export(HttpServletResponse response, PlatformStoreAccount platformStoreAccount) { - List list = platformStoreAccountService.selectPlatformStoreAccountList(platformStoreAccount); - ExcelUtil util = new ExcelUtil(PlatformStoreAccount.class); + public void export(HttpServletResponse response, StoreAccount platformStoreAccount) { + List list = platformStoreAccountService.selectStoreAccountList(platformStoreAccount); + ExcelUtil util = new ExcelUtil(StoreAccount.class); util.exportExcel(response, list, "店家账号数据"); } @@ -63,7 +76,7 @@ public class PlatformStoreAccountController extends BaseController { @PreAuthorize("@ss.hasPermi('platform:account:query')") @GetMapping(value = "/{storeid}") public AjaxResult getInfo(@PathVariable("storeid") Long storeid) { - return success(platformStoreAccountService.selectPlatformStoreAccountByStoreid(storeid)); + return success(platformStoreAccountService.selectStoreAccountByStoreid(storeid)); } /** @@ -72,8 +85,8 @@ public class PlatformStoreAccountController extends BaseController { @PreAuthorize("@ss.hasPermi('platform:account:add')") @Log(title = "店家账号", businessType = BusinessType.INSERT) @PostMapping - public AjaxResult add(@RequestBody PlatformStoreAccount platformStoreAccount) { - return toAjax(platformStoreAccountService.insertPlatformStoreAccount(platformStoreAccount)); + public AjaxResult add(@RequestBody StoreAccount platformStoreAccount) { + return toAjax(platformStoreAccountService.insertStoreAccount(platformStoreAccount)); } /** @@ -82,8 +95,8 @@ public class PlatformStoreAccountController extends BaseController { @PreAuthorize("@ss.hasPermi('platform:account:edit')") @Log(title = "店家账号", businessType = BusinessType.UPDATE) @PutMapping - public AjaxResult edit(@RequestBody PlatformStoreAccount platformStoreAccount) { - return toAjax(platformStoreAccountService.updatePlatformStoreAccount(platformStoreAccount)); + public AjaxResult edit(@RequestBody StoreAccount platformStoreAccount) { + return toAjax(platformStoreAccountService.updateStoreAccount(platformStoreAccount)); } /** @@ -93,6 +106,6 @@ public class PlatformStoreAccountController extends BaseController { @Log(title = "店家账号", businessType = BusinessType.DELETE) @DeleteMapping("/{storeids}") public AjaxResult remove(@PathVariable Long[] storeids) { - return toAjax(platformStoreAccountService.deletePlatformStoreAccountByStoreids(storeids)); + return toAjax(platformStoreAccountService.deleteStoreAccountByStoreids(storeids)); } } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java b/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java index f4ba293..060f597 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java @@ -4,7 +4,7 @@ import io.jsonwebtoken.Claims; /** * 通用常量信息 - * + * * @author ruoyi */ public class Constants @@ -63,7 +63,7 @@ public class Constants * 登录失败 */ public static final String LOGIN_FAIL = "Error"; - + /** * 验证码有效期(分钟) */ @@ -84,6 +84,11 @@ public class Constants */ public static final String LOGIN_USER_KEY = "login_user_key"; + /** + * 店家令牌前缀 + */ + public static final String STORE_KEY = "store_account_key"; + /** * 用户ID */ diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/enums/AccountType.java b/ruoyi-common/src/main/java/com/ruoyi/common/enums/AccountType.java new file mode 100644 index 0000000..28940cd --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/enums/AccountType.java @@ -0,0 +1,17 @@ +package com.ruoyi.common.enums; + +public enum AccountType { + + backend("后台账号"), + store("店家账号"); + + private String remark; + + AccountType(String remark) { + this.remark = remark; + } + + public String getRemark() { + return remark; + } +} diff --git a/ruoyi-framework/pom.xml b/ruoyi-framework/pom.xml index a2ccee2..5665db7 100644 --- a/ruoyi-framework/pom.xml +++ b/ruoyi-framework/pom.xml @@ -59,6 +59,13 @@ ruoyi-system + + + com.ruoyi + ttsbg-store + 3.8.5 + + - \ No newline at end of file + diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java index af80f3c..b472afe 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java @@ -119,8 +119,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter .antMatchers("/platform/config/**").permitAll() //平台短信发送 .antMatchers("/platform/public/sms/send").permitAll() - //店家注册 - .antMatchers("/platform/store/account/register").permitAll() + //店家注册登录 + .antMatchers("/platform/store/account/register", "/platform/store/account/login").permitAll() // 除上面外的所有请求全部需要鉴权认证 .anyRequest().authenticated() .and() diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/security/TypeUsernamePasswordAuthenticationToken.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/security/TypeUsernamePasswordAuthenticationToken.java new file mode 100644 index 0000000..2060e6f --- /dev/null +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/security/TypeUsernamePasswordAuthenticationToken.java @@ -0,0 +1,34 @@ +package com.ruoyi.framework.security; + +import com.ruoyi.common.enums.AccountType; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.GrantedAuthority; + +import javax.security.auth.Subject; +import java.util.Collection; + +/** + * 带账号类型的Token认证 + */ +public class TypeUsernamePasswordAuthenticationToken extends UsernamePasswordAuthenticationToken { + private final AccountType type; + + public TypeUsernamePasswordAuthenticationToken(Object principal, Object credentials, AccountType type) { + super(principal, credentials); + this.type = type; + } + + public TypeUsernamePasswordAuthenticationToken(Object principal, Object credentials, Collection authorities, AccountType type) { + super(principal, credentials, authorities); + this.type = type; + } + + @Override + public boolean implies(Subject subject) { + return super.implies(subject); + } + + public AccountType getType() { + return type; + } +} diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/security/filter/JwtAuthenticationTokenFilter.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/security/filter/JwtAuthenticationTokenFilter.java index 75fd00d..465e3d1 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/security/filter/JwtAuthenticationTokenFilter.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/security/filter/JwtAuthenticationTokenFilter.java @@ -1,24 +1,28 @@ package com.ruoyi.framework.security.filter; -import java.io.IOException; -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import com.ruoyi.common.core.domain.model.LoginUser; +import com.ruoyi.common.enums.AccountType; +import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.framework.security.TypeUsernamePasswordAuthenticationToken; +import com.ruoyi.framework.web.service.TokenService; +import com.ruoyi.store.domain.StoreLoginUser; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.web.authentication.WebAuthenticationDetailsSource; import org.springframework.stereotype.Component; import org.springframework.web.filter.OncePerRequestFilter; -import com.ruoyi.common.core.domain.model.LoginUser; -import com.ruoyi.common.utils.SecurityUtils; -import com.ruoyi.common.utils.StringUtils; -import com.ruoyi.framework.web.service.TokenService; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; /** * token过滤器 验证token有效性 - * + * * @author ruoyi */ @Component @@ -29,15 +33,23 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) - throws ServletException, IOException - { - LoginUser loginUser = tokenService.getLoginUser(request); - if (StringUtils.isNotNull(loginUser) && StringUtils.isNull(SecurityUtils.getAuthentication())) - { - tokenService.verifyToken(loginUser); - UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginUser, null, loginUser.getAuthorities()); - authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request)); - SecurityContextHolder.getContext().setAuthentication(authenticationToken); + throws ServletException, IOException { + if (request.getServletPath().startsWith("/platform/store")) { + StoreLoginUser storeLoginUser = tokenService.getStoreLoginUser(request); + if (StringUtils.isNotNull(storeLoginUser) && StringUtils.isNull(SecurityUtils.getAuthentication())) { + tokenService.verifyToken(storeLoginUser); + TypeUsernamePasswordAuthenticationToken authenticationToken = new TypeUsernamePasswordAuthenticationToken(storeLoginUser, null, storeLoginUser.getAuthorities(), AccountType.store); + authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request)); + SecurityContextHolder.getContext().setAuthentication(authenticationToken); + } + } else { + LoginUser loginUser = tokenService.getLoginUser(request); + if (StringUtils.isNotNull(loginUser) && StringUtils.isNull(SecurityUtils.getAuthentication())) { + tokenService.verifyToken(loginUser); + UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginUser, null, loginUser.getAuthorities()); + authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request)); + SecurityContextHolder.getContext().setAuthentication(authenticationToken); + } } chain.doFilter(request, response); } diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/StoreLoginService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/StoreLoginService.java new file mode 100644 index 0000000..1aa7da3 --- /dev/null +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/StoreLoginService.java @@ -0,0 +1,35 @@ +package com.ruoyi.framework.web.service; + +import com.ruoyi.common.enums.AccountType; +import com.ruoyi.framework.security.TypeUsernamePasswordAuthenticationToken; +import com.ruoyi.framework.security.context.AuthenticationContextHolder; +import com.ruoyi.store.domain.StoreLoginUser; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.core.Authentication; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +/** + * 店家登录 + */ +@Component +public class StoreLoginService { + @Autowired + private TokenService tokenService; + @Resource + private AuthenticationManager authenticationManager; + + public String login(String mobile, String password) { + // 用户验证 + Authentication authentication = null; + TypeUsernamePasswordAuthenticationToken authenticationToken = new TypeUsernamePasswordAuthenticationToken(mobile, password, AccountType.store); + AuthenticationContextHolder.setContext(authenticationToken); + // 该方法会去调用UserDetailsServiceImpl.loadUserByUsername + authentication = authenticationManager.authenticate(authenticationToken); + StoreLoginUser loginUser = (StoreLoginUser) authentication.getPrincipal(); + + return tokenService.createToken(loginUser); + } +} diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java index 56669a7..c2de65e 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java @@ -1,12 +1,5 @@ package com.ruoyi.framework.web.service; -import javax.annotation.Resource; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.authentication.BadCredentialsException; -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.core.Authentication; -import org.springframework.stereotype.Component; import com.ruoyi.common.constant.CacheConstants; import com.ruoyi.common.constant.Constants; import com.ruoyi.common.core.domain.entity.SysUser; @@ -26,10 +19,18 @@ import com.ruoyi.framework.manager.factory.AsyncFactory; import com.ruoyi.framework.security.context.AuthenticationContextHolder; import com.ruoyi.system.service.ISysConfigService; import com.ruoyi.system.service.ISysUserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.authentication.BadCredentialsException; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; /** * 登录校验方法 - * + * * @author ruoyi */ @Component @@ -43,7 +44,7 @@ public class SysLoginService @Autowired private RedisCache redisCache; - + @Autowired private ISysUserService userService; @@ -52,7 +53,7 @@ public class SysLoginService /** * 登录验证 - * + * * @param username 用户名 * @param password 密码 * @param code 验证码 @@ -73,6 +74,7 @@ public class SysLoginService { UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, password); AuthenticationContextHolder.setContext(authenticationToken); + // 该方法会去调用UserDetailsServiceImpl.loadUserByUsername authentication = authenticationManager.authenticate(authenticationToken); } @@ -102,7 +104,7 @@ public class SysLoginService /** * 校验验证码 - * + * * @param username 用户名 * @param code 验证码 * @param uuid 唯一标识 diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java index cadeb4e..a7bb3fd 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java @@ -1,12 +1,5 @@ package com.ruoyi.framework.web.service; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.TimeUnit; -import javax.servlet.http.HttpServletRequest; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; import com.ruoyi.common.constant.CacheConstants; import com.ruoyi.common.constant.Constants; import com.ruoyi.common.core.domain.model.LoginUser; @@ -16,10 +9,19 @@ import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.ip.AddressUtils; import com.ruoyi.common.utils.ip.IpUtils; import com.ruoyi.common.utils.uuid.IdUtils; +import com.ruoyi.store.domain.StoreLoginUser; import eu.bitwalker.useragentutils.UserAgent; import io.jsonwebtoken.Claims; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.SignatureAlgorithm; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import javax.servlet.http.HttpServletRequest; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.TimeUnit; /** * token验证处理 @@ -69,21 +71,35 @@ public class TokenService String userKey = getTokenKey(uuid); LoginUser user = redisCache.getCacheObject(userKey); return user; + } catch (Exception e) { } - catch (Exception e) - { + } + return null; + } + + public StoreLoginUser getStoreLoginUser(HttpServletRequest request) { + // 获取请求携带的令牌 + String token = getToken(request); + if (StringUtils.isNotEmpty(token)) { + try { + Claims claims = parseToken(token); + // 解析对应的权限以及用户信息 + String uuid = (String) claims.get(Constants.STORE_KEY); + String userKey = getTokenKey(uuid); + StoreLoginUser user = redisCache.getCacheObject(userKey); + return user; + } catch (Exception e) { } } return null; } + /** * 设置用户身份信息 */ - public void setLoginUser(LoginUser loginUser) - { - if (StringUtils.isNotNull(loginUser) && StringUtils.isNotEmpty(loginUser.getToken())) - { + public void setLoginUser(LoginUser loginUser) { + if (StringUtils.isNotNull(loginUser) && StringUtils.isNotEmpty(loginUser.getToken())) { refreshToken(loginUser); } } @@ -118,29 +134,46 @@ public class TokenService return createToken(claims); } + public String createToken(StoreLoginUser loginUser) { + String token = IdUtils.fastUUID(); + loginUser.setToken(token); + refreshToken(loginUser); + + Map claims = new HashMap<>(); + claims.put(Constants.STORE_KEY, token); + return createToken(claims); + } + /** * 验证令牌有效期,相差不足20分钟,自动刷新缓存 * * @param loginUser * @return 令牌 */ - public void verifyToken(LoginUser loginUser) - { + public void verifyToken(LoginUser loginUser) { long expireTime = loginUser.getExpireTime(); long currentTime = System.currentTimeMillis(); - if (expireTime - currentTime <= MILLIS_MINUTE_TEN) - { + if (expireTime - currentTime <= MILLIS_MINUTE_TEN) { refreshToken(loginUser); } } + + /** + * TODO:验证店家账号令牌有效期 + * + * @param storeLoginUser + */ + public void verifyToken(StoreLoginUser storeLoginUser) { + + } + /** * 刷新令牌有效期 * * @param loginUser 登录信息 */ - public void refreshToken(LoginUser loginUser) - { + public void refreshToken(LoginUser loginUser) { loginUser.setLoginTime(System.currentTimeMillis()); loginUser.setExpireTime(loginUser.getLoginTime() + expireTime * MILLIS_MINUTE); // 根据uuid将loginUser缓存 @@ -148,13 +181,18 @@ public class TokenService redisCache.setCacheObject(userKey, loginUser, expireTime, TimeUnit.MINUTES); } + public void refreshToken(StoreLoginUser loginUser) { + // 根据uuid将loginUser缓存 + String userKey = getTokenKey(loginUser.getToken()); + redisCache.setCacheObject(userKey, loginUser, expireTime, TimeUnit.MINUTES); + } + /** * 设置用户代理信息 * * @param loginUser 登录信息 */ - public void setUserAgent(LoginUser loginUser) - { + public void setUserAgent(LoginUser loginUser) { UserAgent userAgent = UserAgent.parseUserAgentString(ServletUtils.getRequest().getHeader("User-Agent")); String ip = IpUtils.getIpAddr(ServletUtils.getRequest()); loginUser.setIpaddr(ip); @@ -223,4 +261,6 @@ public class TokenService { return CacheConstants.LOGIN_TOKEN_KEY + uuid; } + + } diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/UserDetailsServiceImpl.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/UserDetailsServiceImpl.java index 234a502..22d97b0 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/UserDetailsServiceImpl.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/UserDetailsServiceImpl.java @@ -1,5 +1,17 @@ package com.ruoyi.framework.web.service; +import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.common.core.domain.model.LoginUser; +import com.ruoyi.common.enums.UserStatus; +import com.ruoyi.common.exception.ServiceException; +import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.framework.security.TypeUsernamePasswordAuthenticationToken; +import com.ruoyi.framework.security.context.AuthenticationContextHolder; +import com.ruoyi.store.domain.StoreAccount; +import com.ruoyi.store.domain.StoreLoginUser; +import com.ruoyi.store.service.IStoreAccountService; +import com.ruoyi.system.service.ISysUserService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -7,12 +19,6 @@ import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Service; -import com.ruoyi.common.core.domain.entity.SysUser; -import com.ruoyi.common.core.domain.model.LoginUser; -import com.ruoyi.common.enums.UserStatus; -import com.ruoyi.common.exception.ServiceException; -import com.ruoyi.common.utils.StringUtils; -import com.ruoyi.system.service.ISysUserService; /** * 用户验证处理 @@ -26,40 +32,62 @@ public class UserDetailsServiceImpl implements UserDetailsService @Autowired private ISysUserService userService; - + @Autowired private SysPasswordService passwordService; @Autowired private SysPermissionService permissionService; + @Autowired + private IStoreAccountService storeAccountService; + @Override - public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException - { - SysUser user = userService.selectUserByUserName(username); - if (StringUtils.isNull(user)) - { - log.info("登录用户:{} 不存在.", username); - throw new ServiceException("登录用户:" + username + " 不存在"); - } - else if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) - { - log.info("登录用户:{} 已被删除.", username); - throw new ServiceException("对不起,您的账号:" + username + " 已被删除"); - } - else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) - { - log.info("登录用户:{} 已被停用.", username); - throw new ServiceException("对不起,您的账号:" + username + " 已停用"); - } + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { - passwordService.validate(user); + if (AuthenticationContextHolder.getContext() instanceof TypeUsernamePasswordAuthenticationToken) { + TypeUsernamePasswordAuthenticationToken token = (TypeUsernamePasswordAuthenticationToken) AuthenticationContextHolder.getContext(); + String rawPassword = token.getCredentials().toString(); + switch (token.getType()) { + case store: { + StoreAccount storeAccount = storeAccountService.selectAccountByMobile(username); + if (StringUtils.isNull(storeAccount)) { + log.info(StringUtils.format("{}不存在{}", token.getType().getRemark(), username)); + throw new ServiceException(token.getType().getRemark() + "或密码错误"); + } + if (!SecurityUtils.matchesPassword(rawPassword, storeAccount.getPassword())) { + throw new ServiceException(token.getType().getRemark() + "或密码错误"); + } + return createLoginUser(storeAccount); + } + } + log.error("无法识别认证类型:" + AuthenticationContextHolder.getContext().getClass()); + throw new ServiceException("系统异常"); + } else { + + SysUser user = userService.selectUserByUserName(username); + if (StringUtils.isNull(user)) { + log.info("登录用户:{} 不存在.", username); + throw new ServiceException("登录用户:" + username + " 不存在"); + } else if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) { + log.info("登录用户:{} 已被删除.", username); + throw new ServiceException("对不起,您的账号:" + username + " 已被删除"); + } else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) { + log.info("登录用户:{} 已被停用.", username); + throw new ServiceException("对不起,您的账号:" + username + " 已停用"); + } + + passwordService.validate(user); + + return createLoginUser(user); + } + } - return createLoginUser(user); + private UserDetails createLoginUser(StoreAccount storeAccount) { + return new StoreLoginUser(storeAccount); } - public UserDetails createLoginUser(SysUser user) - { + public UserDetails createLoginUser(SysUser user) { return new LoginUser(user.getUserId(), user.getDeptId(), user, permissionService.getMenuPermission(user)); } } diff --git a/ttsbg-framework/pom.xml b/ttsbg-framework/pom.xml new file mode 100644 index 0000000..24f836b --- /dev/null +++ b/ttsbg-framework/pom.xml @@ -0,0 +1,26 @@ + + + 4.0.0 + + com.ruoyi + ruoyi + 3.8.5 + + + ttsbg-framework + + + 11 + 11 + UTF-8 + + + + com.ruoyi + ruoyi-common + + + + diff --git a/ttsbg-framework/src/main/java/com/ruoyi/framework/domain/PlatformLoginUser.java b/ttsbg-framework/src/main/java/com/ruoyi/framework/domain/PlatformLoginUser.java new file mode 100644 index 0000000..406144d --- /dev/null +++ b/ttsbg-framework/src/main/java/com/ruoyi/framework/domain/PlatformLoginUser.java @@ -0,0 +1,76 @@ +package com.ruoyi.framework.domain; + +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; + +import java.util.Collection; + +public abstract class PlatformLoginUser implements UserDetails { + + private String token; + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } + + private T t; + + public PlatformLoginUser(T t) { + this.t = t; + } + + public T getT() { + return t; + } + + public void setT(T t) { + this.t = t; + } + + @Override + public Collection getAuthorities() { + return null; + } + + /** + * 账户是否未过期,过期无法验证 + */ + @Override + public boolean isAccountNonExpired() { + return true; + } + + /** + * 指定用户是否解锁,锁定的用户无法进行身份验证 + * + * @return + */ + @Override + public boolean isAccountNonLocked() { + return true; + } + + /** + * 指示是否已过期的用户的凭据(密码),过期的凭据防止认证 + * + * @return + */ + @Override + public boolean isCredentialsNonExpired() { + return true; + } + + /** + * 是否可用 ,禁用的用户不能身份验证 + * + * @return + */ + @Override + public boolean isEnabled() { + return true; + } +} diff --git a/ttsbg-platform/src/main/java/com/ruoyi/platform/domain/PlatformSms.java b/ttsbg-framework/src/main/java/com/ruoyi/framework/domain/Sms.java similarity index 94% rename from ttsbg-platform/src/main/java/com/ruoyi/platform/domain/PlatformSms.java rename to ttsbg-framework/src/main/java/com/ruoyi/framework/domain/Sms.java index 61c6b2e..4b152c4 100644 --- a/ttsbg-platform/src/main/java/com/ruoyi/platform/domain/PlatformSms.java +++ b/ttsbg-framework/src/main/java/com/ruoyi/framework/domain/Sms.java @@ -1,7 +1,8 @@ -package com.ruoyi.platform.domain; +package com.ruoyi.framework.domain; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.core.domain.BaseEntity; import org.apache.commons.lang3.builder.ToStringBuilder; @@ -17,7 +18,8 @@ import java.util.Date; * @author ruoyi * @date 2023-02-09 */ -public class PlatformSms extends BaseEntity { +@TableName("platform_sms") +public class Sms extends BaseEntity { private static final long serialVersionUID = 1L; /** diff --git a/ttsbg-platform/src/main/java/com/ruoyi/platform/mapper/PlatformSmsMapper.java b/ttsbg-framework/src/main/java/com/ruoyi/framework/mapper/SmsMapper.java similarity index 55% rename from ttsbg-platform/src/main/java/com/ruoyi/platform/mapper/PlatformSmsMapper.java rename to ttsbg-framework/src/main/java/com/ruoyi/framework/mapper/SmsMapper.java index f62f354..9bc8e8d 100644 --- a/ttsbg-platform/src/main/java/com/ruoyi/platform/mapper/PlatformSmsMapper.java +++ b/ttsbg-framework/src/main/java/com/ruoyi/framework/mapper/SmsMapper.java @@ -1,7 +1,7 @@ -package com.ruoyi.platform.mapper; +package com.ruoyi.framework.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.ruoyi.platform.domain.PlatformSms; +import com.ruoyi.framework.domain.Sms; import java.util.List; @@ -11,38 +11,38 @@ import java.util.List; * @author ruoyi * @date 2023-02-09 */ -public interface PlatformSmsMapper extends BaseMapper { +public interface SmsMapper extends BaseMapper { /** * 查询短信验证码 * * @param id 短信验证码主键 * @return 短信验证码 */ - public PlatformSms selectPlatformSmsById(Long id); + public Sms selectSmsById(Long id); /** * 查询短信验证码列表 * - * @param platformSms 短信验证码 + * @param Sms 短信验证码 * @return 短信验证码集合 */ - public List selectPlatformSmsList(PlatformSms platformSms); + public List selectSmsList(Sms Sms); /** * 新增短信验证码 * - * @param platformSms 短信验证码 + * @param Sms 短信验证码 * @return 结果 */ - public int insertPlatformSms(PlatformSms platformSms); + public int insertSms(Sms Sms); /** * 修改短信验证码 * - * @param platformSms 短信验证码 + * @param Sms 短信验证码 * @return 结果 */ - public int updatePlatformSms(PlatformSms platformSms); + public int updateSms(Sms Sms); /** * 删除短信验证码 @@ -50,7 +50,7 @@ public interface PlatformSmsMapper extends BaseMapper { * @param id 短信验证码主键 * @return 结果 */ - public int deletePlatformSmsById(Long id); + public int deleteSmsById(Long id); /** * 批量删除短信验证码 @@ -58,5 +58,5 @@ public interface PlatformSmsMapper extends BaseMapper { * @param ids 需要删除的数据主键集合 * @return 结果 */ - public int deletePlatformSmsByIds(Long[] ids); + public int deleteSmsByIds(Long[] ids); } diff --git a/ttsbg-platform/src/main/java/com/ruoyi/platform/service/IPlatformSmsService.java b/ttsbg-framework/src/main/java/com/ruoyi/framework/service/ISmsService.java similarity index 62% rename from ttsbg-platform/src/main/java/com/ruoyi/platform/service/IPlatformSmsService.java rename to ttsbg-framework/src/main/java/com/ruoyi/framework/service/ISmsService.java index 50b7553..c4abbbb 100644 --- a/ttsbg-platform/src/main/java/com/ruoyi/platform/service/IPlatformSmsService.java +++ b/ttsbg-framework/src/main/java/com/ruoyi/framework/service/ISmsService.java @@ -1,6 +1,6 @@ -package com.ruoyi.platform.service; +package com.ruoyi.framework.service; -import com.ruoyi.platform.domain.PlatformSms; +import com.ruoyi.framework.domain.Sms; import java.util.List; @@ -10,38 +10,38 @@ import java.util.List; * @author ruoyi * @date 2023-02-09 */ -public interface IPlatformSmsService { +public interface ISmsService { /** * 查询短信验证码 * * @param id 短信验证码主键 * @return 短信验证码 */ - public PlatformSms selectPlatformSmsById(Long id); + public Sms selectSmsById(Long id); /** * 查询短信验证码列表 * - * @param platformSms 短信验证码 + * @param Sms 短信验证码 * @return 短信验证码集合 */ - public List selectPlatformSmsList(PlatformSms platformSms); + public List selectSmsList(Sms Sms); /** * 新增短信验证码 * - * @param platformSms 短信验证码 + * @param Sms 短信验证码 * @return 结果 */ - public int insertPlatformSms(PlatformSms platformSms); + public int insertSms(Sms Sms); /** * 修改短信验证码 * - * @param platformSms 短信验证码 + * @param Sms 短信验证码 * @return 结果 */ - public int updatePlatformSms(PlatformSms platformSms); + public int updateSms(Sms Sms); /** * 批量删除短信验证码 @@ -49,7 +49,7 @@ public interface IPlatformSmsService { * @param ids 需要删除的短信验证码主键集合 * @return 结果 */ - public int deletePlatformSmsByIds(Long[] ids); + public int deleteSmsByIds(Long[] ids); /** * 删除短信验证码信息 @@ -57,7 +57,7 @@ public interface IPlatformSmsService { * @param id 短信验证码主键 * @return 结果 */ - public int deletePlatformSmsById(Long id); + public int deleteSmsById(Long id); /** * 发送短信验证码 diff --git a/ttsbg-platform/src/main/java/com/ruoyi/platform/service/impl/PlatformSmsServiceImpl.java b/ttsbg-framework/src/main/java/com/ruoyi/framework/service/impl/SmsServiceImpl.java similarity index 55% rename from ttsbg-platform/src/main/java/com/ruoyi/platform/service/impl/PlatformSmsServiceImpl.java rename to ttsbg-framework/src/main/java/com/ruoyi/framework/service/impl/SmsServiceImpl.java index f9e00bd..032df70 100644 --- a/ttsbg-platform/src/main/java/com/ruoyi/platform/service/impl/PlatformSmsServiceImpl.java +++ b/ttsbg-framework/src/main/java/com/ruoyi/framework/service/impl/SmsServiceImpl.java @@ -1,10 +1,10 @@ -package com.ruoyi.platform.service.impl; +package com.ruoyi.framework.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.ruoyi.common.utils.DateUtils; -import com.ruoyi.platform.domain.PlatformSms; -import com.ruoyi.platform.mapper.PlatformSmsMapper; -import com.ruoyi.platform.service.IPlatformSmsService; +import com.ruoyi.framework.domain.Sms; +import com.ruoyi.framework.mapper.SmsMapper; +import com.ruoyi.framework.service.ISmsService; import org.apache.commons.lang3.RandomStringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -19,9 +19,9 @@ import java.util.List; * @date 2023-02-09 */ @Service -public class PlatformSmsServiceImpl implements IPlatformSmsService { +public class SmsServiceImpl implements ISmsService { @Autowired - private PlatformSmsMapper platformSmsMapper; + private SmsMapper smsMapper; /** * 查询短信验证码 @@ -30,41 +30,41 @@ public class PlatformSmsServiceImpl implements IPlatformSmsService { * @return 短信验证码 */ @Override - public PlatformSms selectPlatformSmsById(Long id) { - return platformSmsMapper.selectPlatformSmsById(id); + public Sms selectSmsById(Long id) { + return smsMapper.selectSmsById(id); } /** * 查询短信验证码列表 * - * @param platformSms 短信验证码 + * @param Sms 短信验证码 * @return 短信验证码 */ @Override - public List selectPlatformSmsList(PlatformSms platformSms) { - return platformSmsMapper.selectPlatformSmsList(platformSms); + public List selectSmsList(Sms Sms) { + return smsMapper.selectSmsList(Sms); } /** * 新增短信验证码 * - * @param platformSms 短信验证码 + * @param Sms 短信验证码 * @return 结果 */ @Override - public int insertPlatformSms(PlatformSms platformSms) { - return platformSmsMapper.insertPlatformSms(platformSms); + public int insertSms(Sms Sms) { + return smsMapper.insertSms(Sms); } /** * 修改短信验证码 * - * @param platformSms 短信验证码 + * @param Sms 短信验证码 * @return 结果 */ @Override - public int updatePlatformSms(PlatformSms platformSms) { - return platformSmsMapper.updatePlatformSms(platformSms); + public int updateSms(Sms Sms) { + return smsMapper.updateSms(Sms); } /** @@ -74,8 +74,8 @@ public class PlatformSmsServiceImpl implements IPlatformSmsService { * @return 结果 */ @Override - public int deletePlatformSmsByIds(Long[] ids) { - return platformSmsMapper.deletePlatformSmsByIds(ids); + public int deleteSmsByIds(Long[] ids) { + return smsMapper.deleteSmsByIds(ids); } /** @@ -85,8 +85,8 @@ public class PlatformSmsServiceImpl implements IPlatformSmsService { * @return 结果 */ @Override - public int deletePlatformSmsById(Long id) { - return platformSmsMapper.deletePlatformSmsById(id); + public int deleteSmsById(Long id) { + return smsMapper.deleteSmsById(id); } /** @@ -96,13 +96,13 @@ public class PlatformSmsServiceImpl implements IPlatformSmsService { */ @Override public boolean existsSms(String mobile, String code) { - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); Date d = new Date(); - wrapper.select(PlatformSms::getId).eq(PlatformSms::getMobile, mobile).le(PlatformSms::getSendtime, d).ge(PlatformSms::getDeadtime, d); + wrapper.select(Sms::getId).eq(Sms::getMobile, mobile).le(Sms::getSendtime, d).ge(Sms::getDeadtime, d); if (code != null) { - wrapper.eq(PlatformSms::getCode, code); + wrapper.eq(Sms::getCode, code); } - PlatformSms sms = platformSmsMapper.selectOne(wrapper); + Sms sms = smsMapper.selectOne(wrapper); return sms != null; } @@ -112,14 +112,14 @@ public class PlatformSmsServiceImpl implements IPlatformSmsService { return "短信发送过于频繁"; } else { String code = RandomStringUtils.randomNumeric(6); - PlatformSms newSms = new PlatformSms(); + Sms newSms = new Sms(); newSms.setMobile(mobile); newSms.setCode(code); //TODO 发送验证码成功 newSms.setSendtime(new Date()); newSms.setDeadtime(DateUtils.addSeconds(newSms.getSendtime(), smsTime)); - platformSmsMapper.insert(newSms); + smsMapper.insert(newSms); return "短信验证码发送成功"; } } diff --git a/ttsbg-platform/src/main/resources/mapper/platform/PlatformSmsMapper.xml b/ttsbg-framework/src/main/resources/mapper/PlatformSmsMapper.xml similarity index 90% rename from ttsbg-platform/src/main/resources/mapper/platform/PlatformSmsMapper.xml rename to ttsbg-framework/src/main/resources/mapper/PlatformSmsMapper.xml index 4d9f32b..13f6bf6 100644 --- a/ttsbg-platform/src/main/resources/mapper/platform/PlatformSmsMapper.xml +++ b/ttsbg-framework/src/main/resources/mapper/PlatformSmsMapper.xml @@ -2,9 +2,9 @@ - + - + @@ -19,7 +19,7 @@ from platform_sms - and mobile = #{mobile} @@ -35,7 +35,7 @@ where id = #{id} - + insert into platform_sms id, @@ -57,7 +57,7 @@ - + update platform_sms mobile = #{mobile}, diff --git a/ttsbg-platform/pom.xml b/ttsbg-platform/pom.xml index 37b2f8d..d98b89f 100644 --- a/ttsbg-platform/pom.xml +++ b/ttsbg-platform/pom.xml @@ -30,5 +30,11 @@ ruoyi-common + + com.ruoyi + ttsbg-framework + 3.8.5 + + diff --git a/ttsbg-platform/src/main/java/com/ruoyi/platform/mapper/PlatformStoreAccountMapper.java b/ttsbg-platform/src/main/java/com/ruoyi/platform/mapper/PlatformStoreAccountMapper.java deleted file mode 100644 index ae1aa45..0000000 --- a/ttsbg-platform/src/main/java/com/ruoyi/platform/mapper/PlatformStoreAccountMapper.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.ruoyi.platform.mapper; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.ruoyi.platform.domain.PlatformStoreAccount; - -import java.util.List; - -public interface PlatformStoreAccountMapper extends BaseMapper { - /** - * 查询店家账号 - * - * @param storeid 店家账号主键 - * @return 店家账号 - */ - public PlatformStoreAccount selectPlatformStoreAccountByStoreid(Long storeid); - - /** - * 查询店家账号列表 - * - * @param platformStoreAccount 店家账号 - * @return 店家账号集合 - */ - public List selectPlatformStoreAccountList(PlatformStoreAccount platformStoreAccount); - - /** - * 新增店家账号 - * - * @param platformStoreAccount 店家账号 - * @return 结果 - */ - public int insertPlatformStoreAccount(PlatformStoreAccount platformStoreAccount); - - /** - * 修改店家账号 - * - * @param platformStoreAccount 店家账号 - * @return 结果 - */ - public int updatePlatformStoreAccount(PlatformStoreAccount platformStoreAccount); - - /** - * 删除店家账号 - * - * @param storeid 店家账号主键 - * @return 结果 - */ - public int deletePlatformStoreAccountByStoreid(Long storeid); - - /** - * 批量删除店家账号 - * - * @param storeids 需要删除的数据主键集合 - * @return 结果 - */ - public int deletePlatformStoreAccountByStoreids(Long[] storeids); -} diff --git a/ttsbg-platform/src/main/java/com/ruoyi/platform/service/IPlatformStoreAccountService.java b/ttsbg-platform/src/main/java/com/ruoyi/platform/service/IPlatformStoreAccountService.java deleted file mode 100644 index f87da64..0000000 --- a/ttsbg-platform/src/main/java/com/ruoyi/platform/service/IPlatformStoreAccountService.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.ruoyi.platform.service; - -import com.ruoyi.platform.domain.PlatformStoreAccount; -import com.ruoyi.platform.domain.vo.PlatformStoreAccountVo; - -import java.util.List; - -/** - * 店家账号Service接口 - * - * @author ruoyi - * @date 2023-02-10 - */ -public interface IPlatformStoreAccountService { - /** - * 查询店家账号 - * - * @param storeid 店家账号主键 - * @return 店家账号 - */ - public PlatformStoreAccount selectPlatformStoreAccountByStoreid(Long storeid); - - /** - * 查询店家账号列表 - * - * @param platformStoreAccount 店家账号 - * @return 店家账号集合 - */ - public List selectPlatformStoreAccountList(PlatformStoreAccount platformStoreAccount); - - /** - * 新增店家账号 - * - * @param platformStoreAccount 店家账号 - * @return 结果 - */ - public int insertPlatformStoreAccount(PlatformStoreAccount platformStoreAccount); - - /** - * 修改店家账号 - * - * @param platformStoreAccount 店家账号 - * @return 结果 - */ - public int updatePlatformStoreAccount(PlatformStoreAccount platformStoreAccount); - - /** - * 批量删除店家账号 - * - * @param storeids 需要删除的店家账号主键集合 - * @return 结果 - */ - public int deletePlatformStoreAccountByStoreids(Long[] storeids); - - /** - * 删除店家账号信息 - * - * @param storeid 店家账号主键 - * @return 结果 - */ - public int deletePlatformStoreAccountByStoreid(Long storeid); - - public String register(PlatformStoreAccountVo account); -} diff --git a/ttsbg-platform/src/main/java/com/ruoyi/platform/service/impl/PlatformStoreAccountServiceImpl.java b/ttsbg-platform/src/main/java/com/ruoyi/platform/service/impl/PlatformStoreAccountServiceImpl.java deleted file mode 100644 index fd08710..0000000 --- a/ttsbg-platform/src/main/java/com/ruoyi/platform/service/impl/PlatformStoreAccountServiceImpl.java +++ /dev/null @@ -1,127 +0,0 @@ -package com.ruoyi.platform.service.impl; - -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.ruoyi.common.utils.SecurityUtils; -import com.ruoyi.platform.domain.PlatformStoreAccount; -import com.ruoyi.platform.domain.vo.PlatformStoreAccountVo; -import com.ruoyi.platform.mapper.PlatformStoreAccountMapper; -import com.ruoyi.platform.service.IPlatformSmsService; -import com.ruoyi.platform.service.IPlatformStoreAccountService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.Date; -import java.util.List; - -/** - * 店家账号Service业务层处理 - * - * @author ruoyi - * @date 2023-02-10 - */ -@Service -public class PlatformStoreAccountServiceImpl implements IPlatformStoreAccountService { - @Autowired - private PlatformStoreAccountMapper platformStoreAccountMapper; - - @Autowired - private IPlatformSmsService platformSmsService; - - /** - * 查询店家账号 - * - * @param storeid 店家账号主键 - * @return 店家账号 - */ - @Override - public PlatformStoreAccount selectPlatformStoreAccountByStoreid(Long storeid) { - return platformStoreAccountMapper.selectPlatformStoreAccountByStoreid(storeid); - } - - /** - * 查询店家账号列表 - * - * @param platformStoreAccount 店家账号 - * @return 店家账号 - */ - @Override - public List selectPlatformStoreAccountList(PlatformStoreAccount platformStoreAccount) { - return platformStoreAccountMapper.selectPlatformStoreAccountList(platformStoreAccount); - } - - /** - * 新增店家账号 - * - * @param platformStoreAccount 店家账号 - * @return 结果 - */ - @Override - public int insertPlatformStoreAccount(PlatformStoreAccount platformStoreAccount) { - return platformStoreAccountMapper.insertPlatformStoreAccount(platformStoreAccount); - } - - /** - * 修改店家账号 - * - * @param platformStoreAccount 店家账号 - * @return 结果 - */ - @Override - public int updatePlatformStoreAccount(PlatformStoreAccount platformStoreAccount) { - return platformStoreAccountMapper.updatePlatformStoreAccount(platformStoreAccount); - } - - /** - * 批量删除店家账号 - * - * @param storeids 需要删除的店家账号主键 - * @return 结果 - */ - @Override - public int deletePlatformStoreAccountByStoreids(Long[] storeids) { - return platformStoreAccountMapper.deletePlatformStoreAccountByStoreids(storeids); - } - - /** - * 删除店家账号信息 - * - * @param storeid 店家账号主键 - * @return 结果 - */ - @Override - public int deletePlatformStoreAccountByStoreid(Long storeid) { - return platformStoreAccountMapper.deletePlatformStoreAccountByStoreid(storeid); - } - - //检查手机号是否已注册 - public boolean exist(String mobile) { - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.select(PlatformStoreAccount::getStoreid).eq(PlatformStoreAccount::getMobile, mobile); - return platformStoreAccountMapper.selectOne(wrapper) != null; - } - - @Override - public String register(PlatformStoreAccountVo account) { - //检查验证码是否有效 - if (platformSmsService.existsSms(account.getMobile(), account.getVerificationCode())) { - if (exist(account.getMobile())) { - return "手机号已注册"; - } else { - PlatformStoreAccount newAccount = new PlatformStoreAccount(); - newAccount.setMobile(account.getMobile()); - newAccount.setPassword(SecurityUtils.encryptPassword(account.getPassword())); - newAccount.setStatus(1L); - newAccount.setRegisterdate(new Date()); - newAccount.setNickname(newAccount.getMobile()); - newAccount.setSex(0L); - if (platformStoreAccountMapper.insert(newAccount) > 0) { - return "注册成功"; - } else { - return "注册失败"; - } - } - } else { - return "无效验证码"; - } - } -} diff --git a/ttsbg-store/pom.xml b/ttsbg-store/pom.xml new file mode 100644 index 0000000..eb4eb4d --- /dev/null +++ b/ttsbg-store/pom.xml @@ -0,0 +1,32 @@ + + + 4.0.0 + + com.ruoyi + ruoyi + 3.8.5 + + + ttsbg-store + + + 11 + 11 + UTF-8 + + + + com.ruoyi + ruoyi-common + + + + com.ruoyi + ttsbg-framework + 3.8.5 + + + + diff --git a/ttsbg-platform/src/main/java/com/ruoyi/platform/domain/PlatformStoreAccount.java b/ttsbg-store/src/main/java/com/ruoyi/store/domain/StoreAccount.java similarity index 95% rename from ttsbg-platform/src/main/java/com/ruoyi/platform/domain/PlatformStoreAccount.java rename to ttsbg-store/src/main/java/com/ruoyi/store/domain/StoreAccount.java index 29090b4..ded2a42 100644 --- a/ttsbg-platform/src/main/java/com/ruoyi/platform/domain/PlatformStoreAccount.java +++ b/ttsbg-store/src/main/java/com/ruoyi/store/domain/StoreAccount.java @@ -1,7 +1,8 @@ -package com.ruoyi.platform.domain; +package com.ruoyi.store.domain; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.core.domain.BaseEntity; import org.apache.commons.lang3.builder.ToStringBuilder; @@ -15,7 +16,9 @@ import java.util.Date; * @author ruoyi * @date 2023-02-10 */ -public class PlatformStoreAccount extends BaseEntity { + +@TableName("platform_store_account") +public class StoreAccount extends BaseEntity { private static final long serialVersionUID = 1L; /** diff --git a/ttsbg-store/src/main/java/com/ruoyi/store/domain/StoreLoginUser.java b/ttsbg-store/src/main/java/com/ruoyi/store/domain/StoreLoginUser.java new file mode 100644 index 0000000..6681fd4 --- /dev/null +++ b/ttsbg-store/src/main/java/com/ruoyi/store/domain/StoreLoginUser.java @@ -0,0 +1,20 @@ +package com.ruoyi.store.domain; + +import com.ruoyi.framework.domain.PlatformLoginUser; + +public class StoreLoginUser extends PlatformLoginUser { + + public StoreLoginUser(StoreAccount storeAccount) { + super(storeAccount); + } + + @Override + public String getPassword() { + return getT().getPassword(); + } + + @Override + public String getUsername() { + return getT().getMobile(); + } +} diff --git a/ttsbg-platform/src/main/java/com/ruoyi/platform/domain/vo/PlatformStoreAccountVo.java b/ttsbg-store/src/main/java/com/ruoyi/store/domain/vo/StoreAccountVo.java similarity index 73% rename from ttsbg-platform/src/main/java/com/ruoyi/platform/domain/vo/PlatformStoreAccountVo.java rename to ttsbg-store/src/main/java/com/ruoyi/store/domain/vo/StoreAccountVo.java index b421e8e..4437c47 100644 --- a/ttsbg-platform/src/main/java/com/ruoyi/platform/domain/vo/PlatformStoreAccountVo.java +++ b/ttsbg-store/src/main/java/com/ruoyi/store/domain/vo/StoreAccountVo.java @@ -1,11 +1,11 @@ -package com.ruoyi.platform.domain.vo; +package com.ruoyi.store.domain.vo; import lombok.Data; import javax.validation.constraints.NotBlank; @Data -public class PlatformStoreAccountVo { +public class StoreAccountVo { @NotBlank private String mobile; @NotBlank diff --git a/ttsbg-store/src/main/java/com/ruoyi/store/mapper/StoreAccountMapper.java b/ttsbg-store/src/main/java/com/ruoyi/store/mapper/StoreAccountMapper.java new file mode 100644 index 0000000..fcf8dae --- /dev/null +++ b/ttsbg-store/src/main/java/com/ruoyi/store/mapper/StoreAccountMapper.java @@ -0,0 +1,56 @@ +package com.ruoyi.store.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.ruoyi.store.domain.StoreAccount; + +import java.util.List; + +public interface StoreAccountMapper extends BaseMapper { + /** + * 查询店家账号 + * + * @param storeid 店家账号主键 + * @return 店家账号 + */ + public StoreAccount selectStoreAccountByStoreid(Long storeid); + + /** + * 查询店家账号列表 + * + * @param StoreAccount 店家账号 + * @return 店家账号集合 + */ + public List selectStoreAccountList(StoreAccount StoreAccount); + + /** + * 新增店家账号 + * + * @param StoreAccount 店家账号 + * @return 结果 + */ + public int insertStoreAccount(StoreAccount StoreAccount); + + /** + * 修改店家账号 + * + * @param StoreAccount 店家账号 + * @return 结果 + */ + public int updateStoreAccount(StoreAccount StoreAccount); + + /** + * 删除店家账号 + * + * @param storeid 店家账号主键 + * @return 结果 + */ + public int deleteStoreAccountByStoreid(Long storeid); + + /** + * 批量删除店家账号 + * + * @param storeids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteStoreAccountByStoreids(Long[] storeids); +} diff --git a/ttsbg-store/src/main/java/com/ruoyi/store/service/IStoreAccountService.java b/ttsbg-store/src/main/java/com/ruoyi/store/service/IStoreAccountService.java new file mode 100644 index 0000000..082b1e8 --- /dev/null +++ b/ttsbg-store/src/main/java/com/ruoyi/store/service/IStoreAccountService.java @@ -0,0 +1,73 @@ +package com.ruoyi.store.service; + + +import com.ruoyi.store.domain.StoreAccount; +import com.ruoyi.store.domain.vo.StoreAccountVo; + +import java.util.List; + +/** + * 店家账号Service接口 + * + * @author ruoyi + * @date 2023-02-10 + */ +public interface IStoreAccountService { + /** + * 查询店家账号 + * + * @param storeid 店家账号主键 + * @return 店家账号 + */ + public StoreAccount selectStoreAccountByStoreid(Long storeid); + + /** + * 查询店家账号列表 + * + * @param StoreAccount 店家账号 + * @return 店家账号集合 + */ + public List selectStoreAccountList(StoreAccount StoreAccount); + + /** + * 新增店家账号 + * + * @param StoreAccount 店家账号 + * @return 结果 + */ + public int insertStoreAccount(StoreAccount StoreAccount); + + /** + * 修改店家账号 + * + * @param StoreAccount 店家账号 + * @return 结果 + */ + public int updateStoreAccount(StoreAccount StoreAccount); + + /** + * 批量删除店家账号 + * + * @param storeids 需要删除的店家账号主键集合 + * @return 结果 + */ + public int deleteStoreAccountByStoreids(Long[] storeids); + + /** + * 删除店家账号信息 + * + * @param storeid 店家账号主键 + * @return 结果 + */ + public int deleteStoreAccountByStoreid(Long storeid); + + public String register(StoreAccountVo account); + + /** + * 手机号查询店家账号 + * + * @param mobile + * @return + */ + public StoreAccount selectAccountByMobile(String mobile); +} diff --git a/ttsbg-store/src/main/java/com/ruoyi/store/service/impl/StoreAccountServiceImpl.java b/ttsbg-store/src/main/java/com/ruoyi/store/service/impl/StoreAccountServiceImpl.java new file mode 100644 index 0000000..d868e76 --- /dev/null +++ b/ttsbg-store/src/main/java/com/ruoyi/store/service/impl/StoreAccountServiceImpl.java @@ -0,0 +1,127 @@ +package com.ruoyi.store.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.framework.service.ISmsService; +import com.ruoyi.store.domain.StoreAccount; +import com.ruoyi.store.domain.vo.StoreAccountVo; +import com.ruoyi.store.mapper.StoreAccountMapper; +import com.ruoyi.store.service.IStoreAccountService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Date; +import java.util.List; + +/** + * 店家账号Service业务层处理 + * + * @author ruoyi + * @date 2023-02-10 + */ +@Service +public class StoreAccountServiceImpl implements IStoreAccountService { + @Autowired + private StoreAccountMapper storeAccountMapper; + + @Autowired + private ISmsService SmsService; + + /** + * 查询店家账号 + * + * @param storeid 店家账号主键 + * @return 店家账号 + */ + @Override + public StoreAccount selectStoreAccountByStoreid(Long storeid) { + return storeAccountMapper.selectStoreAccountByStoreid(storeid); + } + + /** + * 查询店家账号列表 + * + * @param StoreAccount 店家账号 + * @return 店家账号 + */ + @Override + public List selectStoreAccountList(StoreAccount StoreAccount) { + return storeAccountMapper.selectStoreAccountList(StoreAccount); + } + + /** + * 新增店家账号 + * + * @param StoreAccount 店家账号 + * @return 结果 + */ + @Override + public int insertStoreAccount(StoreAccount StoreAccount) { + return storeAccountMapper.insertStoreAccount(StoreAccount); + } + + /** + * 修改店家账号 + * + * @param StoreAccount 店家账号 + * @return 结果 + */ + @Override + public int updateStoreAccount(StoreAccount StoreAccount) { + return storeAccountMapper.updateStoreAccount(StoreAccount); + } + + /** + * 批量删除店家账号 + * + * @param storeids 需要删除的店家账号主键 + * @return 结果 + */ + @Override + public int deleteStoreAccountByStoreids(Long[] storeids) { + return storeAccountMapper.deleteStoreAccountByStoreids(storeids); + } + + /** + * 删除店家账号信息 + * + * @param storeid 店家账号主键 + * @return 结果 + */ + @Override + public int deleteStoreAccountByStoreid(Long storeid) { + return storeAccountMapper.deleteStoreAccountByStoreid(storeid); + } + + @Override + public StoreAccount selectAccountByMobile(String mobile) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.select(StoreAccount::getStoreid, StoreAccount::getMobile, StoreAccount::getPassword).eq(StoreAccount::getMobile, mobile); + return storeAccountMapper.selectOne(wrapper); + } + + @Override + public String register(StoreAccountVo account) { + //检查验证码是否有效 + if (SmsService.existsSms(account.getMobile(), account.getVerificationCode())) { + if (selectAccountByMobile(account.getMobile()) != null) { + return "手机号已注册"; + } else { + StoreAccount newAccount = new StoreAccount(); + newAccount.setMobile(account.getMobile()); + newAccount.setPassword(SecurityUtils.encryptPassword(account.getPassword())); + newAccount.setStatus(1L); + newAccount.setRegisterdate(new Date()); + newAccount.setNickname(newAccount.getMobile()); + newAccount.setSex(0L); + if (storeAccountMapper.insert(newAccount) > 0) { + return "注册成功"; + } else { + return "注册失败"; + } + } + } else { + return "无效验证码"; + } + } +}