Compare commits

..

5 Commits

Author SHA1 Message Date
panqihua 9f7007896f 1.增加重置密码接口 2 years ago
panqihua a43b6b8ca0 1.调整项目结构 2 years ago
panqihua ac904bd24e 1.增加店家注册接口 2 years ago
panqihua c375ffeb5d 1.增加短信验证码接口 2 years ago
panqihua 466798d1aa 1.增加获取平台设置接口 2 years ago
  1. 2
      pom.xml
  2. 8
      ruoyi-admin/pom.xml
  3. 30
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/platform/PlatformSmsController.java
  4. 30
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/platform/config/PlatformConfigController.java
  5. 116
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/platform/store/account/PlatformStoreAccountController.java
  6. 2
      ruoyi-admin/src/main/resources/application.yml
  7. 12
      ruoyi-admin/src/main/resources/logback.xml
  8. 6
      ruoyi-common/pom.xml
  9. 5
      ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java
  10. 17
      ruoyi-common/src/main/java/com/ruoyi/common/enums/AccountType.java
  11. 23
      ruoyi-common/src/main/java/com/ruoyi/common/enums/PlatformConfig.java
  12. 7
      ruoyi-framework/pom.xml
  13. 14
      ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java
  14. 34
      ruoyi-framework/src/main/java/com/ruoyi/framework/security/TypeUsernamePasswordAuthenticationToken.java
  15. 38
      ruoyi-framework/src/main/java/com/ruoyi/framework/security/filter/JwtAuthenticationTokenFilter.java
  16. 35
      ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/StoreLoginService.java
  17. 16
      ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java
  18. 82
      ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java
  19. 64
      ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/UserDetailsServiceImpl.java
  20. 52
      sql/ttsbg.sql
  21. 26
      ttsbg-framework/pom.xml
  22. 76
      ttsbg-framework/src/main/java/com/ruoyi/framework/domain/PlatformLoginUser.java
  23. 124
      ttsbg-framework/src/main/java/com/ruoyi/framework/domain/Sms.java
  24. 62
      ttsbg-framework/src/main/java/com/ruoyi/framework/mapper/SmsMapper.java
  25. 72
      ttsbg-framework/src/main/java/com/ruoyi/framework/service/ISmsService.java
  26. 125
      ttsbg-framework/src/main/java/com/ruoyi/framework/service/impl/SmsServiceImpl.java
  27. 85
      ttsbg-framework/src/main/resources/mapper/PlatformSmsMapper.xml
  28. 6
      ttsbg-platform/pom.xml
  29. 32
      ttsbg-store/pom.xml
  30. 164
      ttsbg-store/src/main/java/com/ruoyi/store/domain/StoreAccount.java
  31. 20
      ttsbg-store/src/main/java/com/ruoyi/store/domain/StoreLoginUser.java
  32. 15
      ttsbg-store/src/main/java/com/ruoyi/store/domain/vo/StoreAccountVo.java
  33. 56
      ttsbg-store/src/main/java/com/ruoyi/store/mapper/StoreAccountMapper.java
  34. 75
      ttsbg-store/src/main/java/com/ruoyi/store/service/IStoreAccountService.java
  35. 150
      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>

@ -0,0 +1,30 @@
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.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;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/platform/public/sms")
public class PlatformSmsController extends BaseController {
@Autowired
private ISmsService platformSmsService;
@Autowired
private ISysConfigService sysConfigService;
@PostMapping("send")
public AjaxResult send(@Validated @RequestBody Sms sms) {
return success(platformSmsService.send(sms.getMobile(), Integer.valueOf(sysConfigService.selectConfigById(PlatformConfig.smsTime.getConfigId()).getConfigValue())));
}
}

@ -0,0 +1,30 @@
package com.ruoyi.web.controller.platform.config;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.PlatformConfig;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.SysConfig;
import com.ruoyi.system.service.ISysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import static com.ruoyi.common.core.domain.AjaxResult.success;
/**
* 平台设置
*/
@RestController
@RequestMapping("/platform/config")
public class PlatformConfigController {
@Autowired
private ISysConfigService configService;
@GetMapping("{config}")
public AjaxResult config(@PathVariable PlatformConfig config) {
SysConfig _config = configService.selectConfigById(config.getConfigId());
return success(StringUtils.format("{}获取成功", _config.getConfigName()), _config.getConfigValue());
}
}

@ -0,0 +1,116 @@
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.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.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* 店家账号Controller
*
* @author ruoyi
* @date 2023-02-10
*/
@RestController
@RequestMapping("/platform/store/account")
public class PlatformStoreAccountController extends BaseController {
@Autowired
private IStoreAccountService platformStoreAccountService;
@Autowired
private StoreLoginService loginService;
@PostMapping("register")
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;
}
@PostMapping("resetpwd")
public AjaxResult resetpwd(@RequestBody StoreAccountVo account) {
return success(platformStoreAccountService.resetpwd(account));
}
/**
* 查询店家账号列表
*/
@PreAuthorize("@ss.hasPermi('platform:account:list')")
@GetMapping("/list")
public TableDataInfo list(StoreAccount platformStoreAccount) {
startPage();
List<StoreAccount> list = platformStoreAccountService.selectStoreAccountList(platformStoreAccount);
return getDataTable(list);
}
/**
* 导出店家账号列表
*/
@PreAuthorize("@ss.hasPermi('platform:account:export')")
@Log(title = "店家账号", businessType = BusinessType.EXPORT)
@PostMapping("/export")
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, "店家账号数据");
}
/**
* 获取店家账号详细信息
*/
@PreAuthorize("@ss.hasPermi('platform:account:query')")
@GetMapping(value = "/{storeid}")
public AjaxResult getInfo(@PathVariable("storeid") Long storeid) {
return success(platformStoreAccountService.selectStoreAccountByStoreid(storeid));
}
/**
* 新增店家账号
*/
@PreAuthorize("@ss.hasPermi('platform:account:add')")
@Log(title = "店家账号", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody StoreAccount platformStoreAccount) {
return toAjax(platformStoreAccountService.insertStoreAccount(platformStoreAccount));
}
/**
* 修改店家账号
*/
@PreAuthorize("@ss.hasPermi('platform:account:edit')")
@Log(title = "店家账号", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody StoreAccount platformStoreAccount) {
return toAjax(platformStoreAccountService.updateStoreAccount(platformStoreAccount));
}
/**
* 删除店家账号
*/
@PreAuthorize("@ss.hasPermi('platform:account:remove')")
@Log(title = "店家账号", businessType = BusinessType.DELETE)
@DeleteMapping("/{storeids}")
public AjaxResult remove(@PathVariable Long[] storeids) {
return toAjax(platformStoreAccountService.deleteStoreAccountByStoreids(storeids));
}
}

@ -126,6 +126,6 @@ xss:
# 过滤开关
enabled: true
# 排除链接(多个用逗号分隔)
excludes: /system/notice
excludes: /system/notice,/system/config
# 匹配链接
urlPatterns: /system/*,/monitor/*,/tool/*

@ -72,18 +72,20 @@
</appender>
<!-- 系统模块日志级别控制 -->
<logger name="com.ruoyi" level="info" />
<logger name="com.ruoyi" level="debug"/>
<!-- Spring日志级别控制 -->
<logger name="org.springframework" level="warn" />
<logger name="org.springframework" level="warn"/>
<!-- mybatisplus-->
<logger name="com.baomidou.mybatisplus" level="debug"/>
<root level="info">
<appender-ref ref="console" />
<appender-ref ref="console"/>
</root>
<!--系统操作日志-->
<root level="info">
<appender-ref ref="file_info" />
<appender-ref ref="file_error" />
<appender-ref ref="file_info"/>
<appender-ref ref="file_error"/>
</root>
<!--系统用户操作日志-->

@ -139,6 +139,12 @@
<version>3.4.2</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.26</version>
</dependency>
</dependencies>
</project>

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

@ -0,0 +1,23 @@
package com.ruoyi.common.enums;
/**
* 平台设置
*/
public enum PlatformConfig {
//用户协议
userAgreement(100L),
//隐私政策
privacyPolicy(101L),
//短信验证码配置
smsTime(102L);
private final Long configId;
PlatformConfig(Long configId) {
this.configId = configId;
}
public Long getConfigId() {
return configId;
}
}

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

@ -1,5 +1,9 @@
package com.ruoyi.framework.config;
import com.ruoyi.framework.config.properties.PermitAllUrlProperties;
import com.ruoyi.framework.security.filter.JwtAuthenticationTokenFilter;
import com.ruoyi.framework.security.handle.AuthenticationEntryPointImpl;
import com.ruoyi.framework.security.handle.LogoutSuccessHandlerImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpMethod;
@ -15,10 +19,6 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.authentication.logout.LogoutFilter;
import org.springframework.web.filter.CorsFilter;
import com.ruoyi.framework.config.properties.PermitAllUrlProperties;
import com.ruoyi.framework.security.filter.JwtAuthenticationTokenFilter;
import com.ruoyi.framework.security.handle.AuthenticationEntryPointImpl;
import com.ruoyi.framework.security.handle.LogoutSuccessHandlerImpl;
/**
* spring security配置
@ -115,6 +115,12 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
// 静态资源,可匿名访问
.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
.antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()
//平台设置
.antMatchers("/platform/config/**").permitAll()
//平台短信发送
.antMatchers("/platform/public/sms/send").permitAll()
//店家注册登录
.antMatchers("/platform/store/account/register", "/platform/store/account/login", "/platform/store/account/resetpwd").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,16 +33,24 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
throws ServletException, IOException
{
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()))
{
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,22 +39,40 @@ public class UserDetailsServiceImpl implements UserDetailsService
@Autowired
private SysPermissionService permissionService;
@Autowired
private IStoreAccountService storeAccountService;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException
{
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
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))
{
if (StringUtils.isNull(user)) {
log.info("登录用户:{} 不存在.", username);
throw new ServiceException("登录用户:" + username + " 不存在");
}
else if (UserStatus.DELETED.getCode().equals(user.getDelFlag()))
{
} else if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) {
log.info("登录用户:{} 已被删除.", username);
throw new ServiceException("对不起,您的账号:" + username + " 已被删除");
}
else if (UserStatus.DISABLE.getCode().equals(user.getStatus()))
{
} else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
log.info("登录用户:{} 已被停用.", username);
throw new ServiceException("对不起,您的账号:" + username + " 已停用");
}
@ -57,9 +81,13 @@ public class UserDetailsServiceImpl implements UserDetailsService
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));
}
}

@ -1,16 +1,35 @@
alter table sys_user
add wechat_nick_name varchar(30) null comment '微信昵称';
alter table sys_user
add balance float null comment '账户余额';
alter table sys_user
add referrer_id bigint null comment '推荐人ID';
alter table sys_user
add constraint sys_user_sys_user_user_id_fk
foreign key (referrer_id) references sys_user (user_id);
alter table sys_user
modify user_name varchar(30) null comment '用户账号';
# 收货地址表
create table ttsbg.platform_address
CREATE TABLE IF NOT EXISTS `platform_sms`
(
`id` INTEGER NOT NULL auto_increment COMMENT '主键',
`mobile` VARCHAR(255) NOT NULL COMMENT '中国大陆手机号',
`code` VARCHAR(255) NOT NULL COMMENT '6位数字',
`sendTime` datetime COMMENT '未发送或发送失败为空',
`deadTime` datetime COMMENT '未发送或发送失败为空',
`error` VARCHAR(255),
`remark` VARCHAR(255) COMMENT '注册|修改手机号',
PRIMARY KEY (`id`)
) ENGINE = InnoDB COMMENT '短信验证码表';
CREATE TABLE IF NOT EXISTS `platform_store_account`
(
storeId int auto_increment
primary key,
mobile varchar(255) not null comment '中国大陆手机号',
password varchar(255) not null comment 'HS512 加密',
status int not null comment '枚举值、详看数据字典编码',
registerDate datetime not null comment 'yyyy-MM-dd',
nickname varchar(255) not null comment '待确定格式',
sex int not null comment '枚举值、详看数据字典编码',
avatar varchar(255) null comment '待确定存储格式',
loginDate datetime null comment 'yyyy-MM-dd',
constraint platform_store_account_mobile_uindex
unique (mobile)
)
comment '店家账号表';
# TODO:熟悉框架建立的表,后面可能要再调整
create table platform_address
(
id bigint auto_increment
primary key,
@ -28,12 +47,12 @@ create table ttsbg.platform_address
update_time datetime null,
user_id bigint null comment '关联用户',
constraint platform_address_sys_user_user_id_fk
foreign key (user_id) references ttsbg.sys_user (user_id)
foreign key (user_id) references sys_user (user_id)
)
comment '收货地址表';
# TODO:熟悉框架建立的表,后面可能要再调整
create table platform_follower
(
id bigint auto_increment
@ -49,4 +68,5 @@ create table platform_follower
comment '粉丝表';
select max(deadTime)
from platform_sms;

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

@ -0,0 +1,124 @@
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;
import org.apache.commons.lang3.builder.ToStringStyle;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import java.util.Date;
/**
* 短信验证码对象 platform_sms
*
* @author ruoyi
* @date 2023-02-09
*/
@TableName("platform_sms")
public class Sms extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@TableId(type = IdType.AUTO)
private Long id;
/**
* 中国大陆手机号
*/
@Excel(name = "中国大陆手机号")
@NotBlank(message = "手机号不能为空")
@Pattern(message = "手机号不合法", regexp = "^1(3\\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\\d|9[0-35-9])\\d{8}$")
private String mobile;
/**
* 6位数字
*/
@Excel(name = "6位数字")
private String code;
/**
* 未发送或发送失败为空
*/
@Excel(name = "未发送或发送失败为空")
private Date sendtime;
/**
* 未发送或发送失败为空
*/
@Excel(name = "未发送或发送失败为空")
private Date deadtime;
/**
* $column.columnComment
*/
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
private String error;
public void setId(Long id) {
this.id = id;
}
public Long getId() {
return id;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getMobile() {
return mobile;
}
public void setCode(String code) {
this.code = code;
}
public String getCode() {
return code;
}
public void setSendtime(Date sendtime) {
this.sendtime = sendtime;
}
public Date getSendtime() {
return sendtime;
}
public void setDeadtime(Date deadtime) {
this.deadtime = deadtime;
}
public Date getDeadtime() {
return deadtime;
}
public void setError(String error) {
this.error = error;
}
public String getError() {
return error;
}
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("mobile", getMobile())
.append("code", getCode())
.append("sendtime", getSendtime())
.append("deadtime", getDeadtime())
.append("error", getError())
.append("remark", getRemark())
.toString();
}
}

@ -0,0 +1,62 @@
package com.ruoyi.framework.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.framework.domain.Sms;
import java.util.List;
/**
* 短信验证码Mapper接口
*
* @author ruoyi
* @date 2023-02-09
*/
public interface SmsMapper extends BaseMapper<Sms> {
/**
* 查询短信验证码
*
* @param id 短信验证码主键
* @return 短信验证码
*/
public Sms selectSmsById(Long id);
/**
* 查询短信验证码列表
*
* @param Sms 短信验证码
* @return 短信验证码集合
*/
public List<Sms> selectSmsList(Sms Sms);
/**
* 新增短信验证码
*
* @param Sms 短信验证码
* @return 结果
*/
public int insertSms(Sms Sms);
/**
* 修改短信验证码
*
* @param Sms 短信验证码
* @return 结果
*/
public int updateSms(Sms Sms);
/**
* 删除短信验证码
*
* @param id 短信验证码主键
* @return 结果
*/
public int deleteSmsById(Long id);
/**
* 批量删除短信验证码
*
* @param ids 需要删除的数据主键集合
* @return 结果
*/
public int deleteSmsByIds(Long[] ids);
}

@ -0,0 +1,72 @@
package com.ruoyi.framework.service;
import com.ruoyi.framework.domain.Sms;
import java.util.List;
/**
* 短信验证码Service接口
*
* @author ruoyi
* @date 2023-02-09
*/
public interface ISmsService {
/**
* 查询短信验证码
*
* @param id 短信验证码主键
* @return 短信验证码
*/
public Sms selectSmsById(Long id);
/**
* 查询短信验证码列表
*
* @param Sms 短信验证码
* @return 短信验证码集合
*/
public List<Sms> selectSmsList(Sms Sms);
/**
* 新增短信验证码
*
* @param Sms 短信验证码
* @return 结果
*/
public int insertSms(Sms Sms);
/**
* 修改短信验证码
*
* @param Sms 短信验证码
* @return 结果
*/
public int updateSms(Sms Sms);
/**
* 批量删除短信验证码
*
* @param ids 需要删除的短信验证码主键集合
* @return 结果
*/
public int deleteSmsByIds(Long[] ids);
/**
* 删除短信验证码信息
*
* @param id 短信验证码主键
* @return 结果
*/
public int deleteSmsById(Long id);
/**
* 发送短信验证码
*
* @param mobile 手机号
* @param integer
* @return 结果
*/
public String send(String mobile, Integer integer);
public Sms querySms(String mobile, String code);
}

@ -0,0 +1,125 @@
package com.ruoyi.framework.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.utils.DateUtils;
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;
import java.util.Date;
import java.util.List;
/**
* 短信验证码Service业务层处理
*
* @author ruoyi
* @date 2023-02-09
*/
@Service
public class SmsServiceImpl implements ISmsService {
@Autowired
private SmsMapper smsMapper;
/**
* 查询短信验证码
*
* @param id 短信验证码主键
* @return 短信验证码
*/
@Override
public Sms selectSmsById(Long id) {
return smsMapper.selectSmsById(id);
}
/**
* 查询短信验证码列表
*
* @param Sms 短信验证码
* @return 短信验证码
*/
@Override
public List<Sms> selectSmsList(Sms Sms) {
return smsMapper.selectSmsList(Sms);
}
/**
* 新增短信验证码
*
* @param Sms 短信验证码
* @return 结果
*/
@Override
public int insertSms(Sms Sms) {
return smsMapper.insertSms(Sms);
}
/**
* 修改短信验证码
*
* @param Sms 短信验证码
* @return 结果
*/
@Override
public int updateSms(Sms Sms) {
return smsMapper.updateSms(Sms);
}
/**
* 批量删除短信验证码
*
* @param ids 需要删除的短信验证码主键
* @return 结果
*/
@Override
public int deleteSmsByIds(Long[] ids) {
return smsMapper.deleteSmsByIds(ids);
}
/**
* 删除短信验证码信息
*
* @param id 短信验证码主键
* @return 结果
*/
@Override
public int deleteSmsById(Long id) {
return smsMapper.deleteSmsById(id);
}
/**
* 检查手机号是否存在有效短信验证码
*
* @return
*/
@Override
public Sms querySms(String mobile, String code) {
LambdaQueryWrapper<Sms> wrapper = new LambdaQueryWrapper<>();
Date d = new Date();
wrapper.select(Sms::getId).eq(Sms::getMobile, mobile).le(Sms::getSendtime, d).ge(Sms::getDeadtime, d);
if (code != null) {
wrapper.eq(Sms::getCode, code);
}
return smsMapper.selectOne(wrapper);
}
@Override
public String send(String mobile, Integer smsTime) {
if (querySms(mobile, null) != null) {
return "短信发送过于频繁";
} else {
String code = RandomStringUtils.randomNumeric(6);
Sms newSms = new Sms();
newSms.setMobile(mobile);
newSms.setCode(code);
//TODO 发送验证码成功
newSms.setSendtime(new Date());
newSms.setDeadtime(DateUtils.addSeconds(newSms.getSendtime(), smsTime));
smsMapper.insert(newSms);
return "短信验证码发送成功";
}
}
}

@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.framework.mapper.SmsMapper">
<resultMap type="Sms" id="PlatformSmsResult">
<result property="id" column="id"/>
<result property="mobile" column="mobile"/>
<result property="code" column="code"/>
<result property="sendtime" column="sendTime"/>
<result property="deadtime" column="deadTime"/>
<result property="error" column="error"/>
<result property="remark" column="remark"/>
</resultMap>
<sql id="selectPlatformSmsVo">
select id, mobile, code, sendTime, deadTime, error, remark
from platform_sms
</sql>
<select id="selectSmsList" parameterType="Sms" resultMap="PlatformSmsResult">
<include refid="selectPlatformSmsVo"/>
<where>
<if test="mobile != null and mobile != ''">and mobile = #{mobile}</if>
<if test="code != null and code != ''">and code = #{code}</if>
<if test="sendtime != null ">and sendTime = #{sendtime}</if>
<if test="deadtime != null ">and deadTime = #{deadtime}</if>
<if test="error != null and error != ''">and error = #{error}</if>
</where>
</select>
<select id="selectSmsById" parameterType="Long" resultMap="PlatformSmsResult">
<include refid="selectPlatformSmsVo"/>
where id = #{id}
</select>
<insert id="insertSms" parameterType="Sms">
insert into platform_sms
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="mobile != null and mobile != ''">mobile,</if>
<if test="code != null and code != ''">code,</if>
<if test="sendtime != null">sendTime,</if>
<if test="deadtime != null">deadTime,</if>
<if test="error != null and error != ''">error,</if>
<if test="remark != null and remark != ''">remark,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="mobile != null and mobile != ''">#{mobile},</if>
<if test="code != null and code != ''">#{code},</if>
<if test="sendtime != null">#{sendtime},</if>
<if test="deadtime != null">#{deadtime},</if>
<if test="error != null and error != ''">#{error},</if>
<if test="remark != null and remark != ''">#{remark},</if>
</trim>
</insert>
<update id="updateSms" parameterType="Sms">
update platform_sms
<trim prefix="SET" suffixOverrides=",">
<if test="mobile != null and mobile != ''">mobile = #{mobile},</if>
<if test="code != null and code != ''">code = #{code},</if>
<if test="sendtime != null">sendTime = #{sendtime},</if>
<if test="deadtime != null">deadTime = #{deadtime},</if>
<if test="error != null and error != ''">error = #{error},</if>
<if test="remark != null and remark != ''">remark = #{remark},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteSmsById" parameterType="Long">
delete
from platform_sms
where id = #{id}
</delete>
<delete id="deleteSmsByIds" parameterType="String">
delete from platform_sms where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>

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

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

@ -0,0 +1,164 @@
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;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.util.Date;
/**
* 店家账号对象 platform_store_account
*
* @author ruoyi
* @date 2023-02-10
*/
@TableName("platform_store_account")
public class StoreAccount extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* $column.columnComment
*/
@TableId(type = IdType.AUTO)
private Long storeid;
/**
* 中国大陆手机号
*/
@Excel(name = "中国大陆手机号")
private String mobile;
/**
* HS512 加密
*/
@Excel(name = "HS512 加密")
private String password;
/**
* 枚举值详看数据字典编码
*/
@Excel(name = "枚举值、详看数据字典编码")
private Long status;
/**
* yyyy-MM-dd
*/
@Excel(name = "yyyy-MM-dd")
private Date registerdate;
/**
* 待确定格式
*/
@Excel(name = "待确定格式")
private String nickname;
/**
* 枚举值详看数据字典编码
*/
@Excel(name = "枚举值、详看数据字典编码")
private Long sex;
/**
* 待确定存储格式
*/
@Excel(name = "待确定存储格式")
private String avatar;
/**
* yyyy-MM-dd
*/
@Excel(name = "yyyy-MM-dd")
private Date logindate;
public void setStoreid(Long storeid) {
this.storeid = storeid;
}
public Long getStoreid() {
return storeid;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getMobile() {
return mobile;
}
public void setPassword(String password) {
this.password = password;
}
public String getPassword() {
return password;
}
public void setStatus(Long status) {
this.status = status;
}
public Long getStatus() {
return status;
}
public void setRegisterdate(Date registerdate) {
this.registerdate = registerdate;
}
public Date getRegisterdate() {
return registerdate;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public String getNickname() {
return nickname;
}
public void setSex(Long sex) {
this.sex = sex;
}
public Long getSex() {
return sex;
}
public void setAvatar(String avatar) {
this.avatar = avatar;
}
public String getAvatar() {
return avatar;
}
public void setLogindate(Date logindate) {
this.logindate = logindate;
}
public Date getLogindate() {
return logindate;
}
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("storeid", getStoreid())
.append("mobile", getMobile())
.append("password", getPassword())
.append("status", getStatus())
.append("registerdate", getRegisterdate())
.append("nickname", getNickname())
.append("sex", getSex())
.append("avatar", getAvatar())
.append("logindate", getLogindate())
.toString();
}
}

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

@ -0,0 +1,15 @@
package com.ruoyi.store.domain.vo;
import lombok.Data;
import javax.validation.constraints.NotBlank;
@Data
public class StoreAccountVo {
@NotBlank
private String mobile;
@NotBlank
private String password;
@NotBlank
private String verificationCode;
}

@ -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,75 @@
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);
String resetpwd(StoreAccountVo account);
}

@ -0,0 +1,150 @@
package com.ruoyi.store.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.domain.Sms;
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) {
//检查验证码是否有效
Sms sms = smsService.querySms(account.getMobile(), account.getVerificationCode());
if (sms != null) {
sms.setDeadtime(new Date());
smsService.updateSms(sms);
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 "手机号或验证码错误";
}
}
@Override
public String resetpwd(StoreAccountVo account) {
//检查验证码是否有效
Sms sms = smsService.querySms(account.getMobile(), account.getVerificationCode());
if (sms != null) {
sms.setDeadtime(new Date());
smsService.updateSms(sms);
StoreAccount storeAccount = selectAccountByMobile(account.getMobile());
storeAccount.setPassword(SecurityUtils.encryptPassword(account.getPassword()));
if (storeAccountMapper.updateById(storeAccount) > 0) {
return "密码重置成功";
} else {
return "密码重置失败";
}
} else {
return "手机号或验证码错误";
}
}
}
Loading…
Cancel
Save