1.调整项目结构

2.增加店家密码登录接口
master
panqihua 2 years ago
parent ac904bd24e
commit a43b6b8ca0
  1. 2
      pom.xml
  2. 8
      ruoyi-admin/pom.xml
  3. 8
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/platform/PlatformSmsController.java
  4. 47
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/platform/store/account/PlatformStoreAccountController.java
  5. 5
      ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java
  6. 17
      ruoyi-common/src/main/java/com/ruoyi/common/enums/AccountType.java
  7. 7
      ruoyi-framework/pom.xml
  8. 4
      ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java
  9. 34
      ruoyi-framework/src/main/java/com/ruoyi/framework/security/TypeUsernamePasswordAuthenticationToken.java
  10. 48
      ruoyi-framework/src/main/java/com/ruoyi/framework/security/filter/JwtAuthenticationTokenFilter.java
  11. 35
      ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/StoreLoginService.java
  12. 16
      ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java
  13. 82
      ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java
  14. 84
      ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/UserDetailsServiceImpl.java
  15. 26
      ttsbg-framework/pom.xml
  16. 76
      ttsbg-framework/src/main/java/com/ruoyi/framework/domain/PlatformLoginUser.java
  17. 6
      ttsbg-framework/src/main/java/com/ruoyi/framework/domain/Sms.java
  18. 24
      ttsbg-framework/src/main/java/com/ruoyi/framework/mapper/SmsMapper.java
  19. 24
      ttsbg-framework/src/main/java/com/ruoyi/framework/service/ISmsService.java
  20. 54
      ttsbg-framework/src/main/java/com/ruoyi/framework/service/impl/SmsServiceImpl.java
  21. 10
      ttsbg-framework/src/main/resources/mapper/PlatformSmsMapper.xml
  22. 6
      ttsbg-platform/pom.xml
  23. 56
      ttsbg-platform/src/main/java/com/ruoyi/platform/mapper/PlatformStoreAccountMapper.java
  24. 64
      ttsbg-platform/src/main/java/com/ruoyi/platform/service/IPlatformStoreAccountService.java
  25. 127
      ttsbg-platform/src/main/java/com/ruoyi/platform/service/impl/PlatformStoreAccountServiceImpl.java
  26. 32
      ttsbg-store/pom.xml
  27. 7
      ttsbg-store/src/main/java/com/ruoyi/store/domain/StoreAccount.java
  28. 20
      ttsbg-store/src/main/java/com/ruoyi/store/domain/StoreLoginUser.java
  29. 4
      ttsbg-store/src/main/java/com/ruoyi/store/domain/vo/StoreAccountVo.java
  30. 56
      ttsbg-store/src/main/java/com/ruoyi/store/mapper/StoreAccountMapper.java
  31. 73
      ttsbg-store/src/main/java/com/ruoyi/store/service/IStoreAccountService.java
  32. 127
      ttsbg-store/src/main/java/com/ruoyi/store/service/impl/StoreAccountServiceImpl.java

@ -189,6 +189,8 @@
<module>ruoyi-generator</module>
<module>ruoyi-common</module>
<module>ttsbg-platform</module>
<module>ttsbg-store</module>
<module>ttsbg-framework</module>
</modules>
<packaging>pom</packaging>

@ -66,7 +66,13 @@
<groupId>com.ruoyi</groupId>
<artifactId>ttsbg-platform</artifactId>
<version>3.8.5</version>
<scope>compile</scope>
</dependency>
<!--店家端-->
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>ttsbg-store</artifactId>
<version>3.8.5</version>
</dependency>
</dependencies>

@ -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())));
}
}

@ -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<PlatformStoreAccount> list = platformStoreAccountService.selectPlatformStoreAccountList(platformStoreAccount);
List<StoreAccount> 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<PlatformStoreAccount> list = platformStoreAccountService.selectPlatformStoreAccountList(platformStoreAccount);
ExcelUtil<PlatformStoreAccount> util = new ExcelUtil<PlatformStoreAccount>(PlatformStoreAccount.class);
public void export(HttpServletResponse response, StoreAccount platformStoreAccount) {
List<StoreAccount> list = platformStoreAccountService.selectStoreAccountList(platformStoreAccount);
ExcelUtil<StoreAccount> util = new ExcelUtil<StoreAccount>(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));
}
}

@ -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
*/

@ -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;
}
}

@ -59,6 +59,13 @@
<artifactId>ruoyi-system</artifactId>
</dependency>
<!--店家端-->
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>ttsbg-store</artifactId>
<version>3.8.5</version>
</dependency>
</dependencies>
</project>

@ -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()

@ -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<? extends GrantedAuthority> 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;
}
}

@ -1,20 +1,24 @@
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有效性
@ -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);
}

@ -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);
}
}

@ -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,6 +19,14 @@ 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;
/**
* 登录校验方法
@ -73,6 +74,7 @@ public class SysLoginService
{
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, password);
AuthenticationContextHolder.setContext(authenticationToken);
// 该方法会去调用UserDetailsServiceImpl.loadUserByUsername
authentication = authenticationManager.authenticate(authenticationToken);
}

@ -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<String, Object> 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;
}
}

@ -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;
/**
* 用户验证处理
@ -33,33 +39,55 @@ public class UserDetailsServiceImpl implements UserDetailsService
@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));
}
}

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi</artifactId>
<version>3.8.5</version>
</parent>
<artifactId>ttsbg-framework</artifactId>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-common</artifactId>
</dependency>
</dependencies>
</project>

@ -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<T> 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<? extends GrantedAuthority> 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;
}
}

@ -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;
/**

@ -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<PlatformSms> {
public interface SmsMapper extends BaseMapper<Sms> {
/**
* 查询短信验证码
*
* @param id 短信验证码主键
* @return 短信验证码
*/
public PlatformSms selectPlatformSmsById(Long id);
public Sms selectSmsById(Long id);
/**
* 查询短信验证码列表
*
* @param platformSms 短信验证码
* @param Sms 短信验证码
* @return 短信验证码集合
*/
public List<PlatformSms> selectPlatformSmsList(PlatformSms platformSms);
public List<Sms> 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<PlatformSms> {
* @param id 短信验证码主键
* @return 结果
*/
public int deletePlatformSmsById(Long id);
public int deleteSmsById(Long id);
/**
* 批量删除短信验证码
@ -58,5 +58,5 @@ public interface PlatformSmsMapper extends BaseMapper<PlatformSms> {
* @param ids 需要删除的数据主键集合
* @return 结果
*/
public int deletePlatformSmsByIds(Long[] ids);
public int deleteSmsByIds(Long[] ids);
}

@ -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<PlatformSms> selectPlatformSmsList(PlatformSms platformSms);
public List<Sms> 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);
/**
* 发送短信验证码

@ -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<PlatformSms> selectPlatformSmsList(PlatformSms platformSms) {
return platformSmsMapper.selectPlatformSmsList(platformSms);
public List<Sms> 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<PlatformSms> wrapper = new LambdaQueryWrapper<>();
LambdaQueryWrapper<Sms> 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 "短信验证码发送成功";
}
}

@ -2,9 +2,9 @@
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.system.mapper.PlatformSmsMapper">
<mapper namespace="com.ruoyi.framework.mapper.SmsMapper">
<resultMap type="PlatformSms" id="PlatformSmsResult">
<resultMap type="Sms" id="PlatformSmsResult">
<result property="id" column="id"/>
<result property="mobile" column="mobile"/>
<result property="code" column="code"/>
@ -19,7 +19,7 @@
from platform_sms
</sql>
<select id="selectPlatformSmsList" parameterType="PlatformSms" resultMap="PlatformSmsResult">
<select id="selectPlatformSmsList" parameterType="Sms" resultMap="PlatformSmsResult">
<include refid="selectPlatformSmsVo"/>
<where>
<if test="mobile != null and mobile != ''">and mobile = #{mobile}</if>
@ -35,7 +35,7 @@
where id = #{id}
</select>
<insert id="insertPlatformSms" parameterType="PlatformSms">
<insert id="insertPlatformSms" parameterType="Sms">
insert into platform_sms
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
@ -57,7 +57,7 @@
</trim>
</insert>
<update id="updatePlatformSms" parameterType="PlatformSms">
<update id="updatePlatformSms" parameterType="Sms">
update platform_sms
<trim prefix="SET" suffixOverrides=",">
<if test="mobile != null and mobile != ''">mobile = #{mobile},</if>

@ -30,5 +30,11 @@
<artifactId>ruoyi-common</artifactId>
</dependency>
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>ttsbg-framework</artifactId>
<version>3.8.5</version>
</dependency>
</dependencies>
</project>

@ -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<PlatformStoreAccount> {
/**
* 查询店家账号
*
* @param storeid 店家账号主键
* @return 店家账号
*/
public PlatformStoreAccount selectPlatformStoreAccountByStoreid(Long storeid);
/**
* 查询店家账号列表
*
* @param platformStoreAccount 店家账号
* @return 店家账号集合
*/
public List<PlatformStoreAccount> 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);
}

@ -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<PlatformStoreAccount> 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);
}

@ -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<PlatformStoreAccount> 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<PlatformStoreAccount> 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 "无效验证码";
}
}
}

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi</artifactId>
<version>3.8.5</version>
</parent>
<artifactId>ttsbg-store</artifactId>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-common</artifactId>
</dependency>
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>ttsbg-framework</artifactId>
<version>3.8.5</version>
</dependency>
</dependencies>
</project>

@ -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;
/**

@ -0,0 +1,20 @@
package com.ruoyi.store.domain;
import com.ruoyi.framework.domain.PlatformLoginUser;
public class StoreLoginUser extends PlatformLoginUser<StoreAccount> {
public StoreLoginUser(StoreAccount storeAccount) {
super(storeAccount);
}
@Override
public String getPassword() {
return getT().getPassword();
}
@Override
public String getUsername() {
return getT().getMobile();
}
}

@ -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

@ -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<StoreAccount> {
/**
* 查询店家账号
*
* @param storeid 店家账号主键
* @return 店家账号
*/
public StoreAccount selectStoreAccountByStoreid(Long storeid);
/**
* 查询店家账号列表
*
* @param StoreAccount 店家账号
* @return 店家账号集合
*/
public List<StoreAccount> 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);
}

@ -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<StoreAccount> 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);
}

@ -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<StoreAccount> 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<StoreAccount> 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 "无效验证码";
}
}
}
Loading…
Cancel
Save