角色管理---第一部分完成
This commit is contained in:
parent
e3ffa18eff
commit
74d7519ed1
4
pom.xml
4
pom.xml
|
@ -22,8 +22,8 @@
|
|||
</parent>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<mysql.verison>8.0.30</mysql.verison>
|
||||
<fastjson.version>2.0.21</fastjson.version>
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
<artifactId>common-service</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
|
|
|
@ -3,20 +3,21 @@ package cn.bunny;
|
|||
import cn.bunny.spzx.model.entity.system.SysUser;
|
||||
|
||||
public class AuthContextUtil {
|
||||
// 创建ThreadLocal
|
||||
|
||||
// 创建一个ThreadLocal对象
|
||||
private static final ThreadLocal<SysUser> threadLocal = new ThreadLocal<>();
|
||||
|
||||
// 添加数据库
|
||||
// 定义存储数据的静态方法
|
||||
public static void set(SysUser sysUser) {
|
||||
threadLocal.set(sysUser);
|
||||
}
|
||||
|
||||
// 获取数据
|
||||
// 定义获取数据的方法
|
||||
public static SysUser get() {
|
||||
return threadLocal.get();
|
||||
}
|
||||
|
||||
// 删除数据
|
||||
// 删除数据的方法
|
||||
public static void remove() {
|
||||
threadLocal.remove();
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
</modules>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
<artifactId>spzx-manager</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
package cn.bunny;
|
||||
|
||||
import cn.bunny.properties.UserProperties;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableConfigurationProperties(value = {UserProperties.class})
|
||||
@ComponentScan(basePackages = "cn.bunny")
|
||||
public class MangerApplication {
|
||||
public static void main(String[] args) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package cn.bunny.config;
|
||||
|
||||
import cn.bunny.interceptor.LoginAuthInterceptor;
|
||||
import cn.bunny.properties.UserProperties;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
|
@ -12,12 +13,18 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
|
|||
@Autowired
|
||||
private LoginAuthInterceptor loginAuthInterceptor;
|
||||
|
||||
@Autowired
|
||||
private UserProperties userProperties;
|
||||
|
||||
// 拦截器注册
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(loginAuthInterceptor)
|
||||
.excludePathPatterns("/admin/system/index/login", "/admin.system/index/generateValidateCode")
|
||||
.addPathPatterns("/**");
|
||||
// .excludePathPatterns("/admin/system/index/login", "/admin.system/index/generateValidateCode")
|
||||
|
||||
// registry.addInterceptor(loginAuthInterceptor)
|
||||
// .addPathPatterns("/**")
|
||||
// .excludePathPatterns(userProperties.getNoAuthUrls());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,19 +1,23 @@
|
|||
package cn.bunny.controller;
|
||||
|
||||
import cn.bunny.AuthContextUtil;
|
||||
import cn.bunny.service.SysUserService;
|
||||
import cn.bunny.service.ValidateCodeService;
|
||||
import cn.bunny.spzx.model.dto.system.LoginDto;
|
||||
import cn.bunny.spzx.model.entity.system.SysUser;
|
||||
import cn.bunny.spzx.model.entity.user.UserInfo;
|
||||
import cn.bunny.spzx.model.vo.common.Result;
|
||||
import cn.bunny.spzx.model.vo.common.ResultCodeEnum;
|
||||
import cn.bunny.spzx.model.vo.system.LoginVo;
|
||||
import cn.bunny.spzx.model.vo.system.ValidateCodeVo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Tag(name = "用户接口")
|
||||
@Log4j2
|
||||
@RestController
|
||||
@RequestMapping("/admin/system/index")
|
||||
public class IndexController {
|
||||
|
@ -27,6 +31,8 @@ public class IndexController {
|
|||
@Operation(summary = "用户登录", description = "用户登录获取token")
|
||||
@PostMapping("login")
|
||||
public Result login(@RequestBody LoginDto loginDto) {
|
||||
log.info("post --- 用户登录");
|
||||
|
||||
LoginVo loginVo = sysUserService.login(loginDto);
|
||||
return Result.build(loginVo, ResultCodeEnum.LOGIN_SUCCESS);
|
||||
}
|
||||
|
@ -35,6 +41,8 @@ public class IndexController {
|
|||
@Operation(summary = "获取验证码", description = "会获得两个值:codeKey + codeValue")
|
||||
@GetMapping(value = "/generateValidateCode")
|
||||
public Result<ValidateCodeVo> generateValidateCode() {
|
||||
log.info("get --- 获取验证码");
|
||||
|
||||
ValidateCodeVo validateCodeVo = validateCodeService.generateValidateCode();
|
||||
return Result.build(validateCodeVo, ResultCodeEnum.SUCCESS);
|
||||
}
|
||||
|
@ -44,15 +52,27 @@ public class IndexController {
|
|||
@GetMapping(value = "getUserInfo")
|
||||
// public Result getUserInfo(HttpServletRequest httpServletRequest) {
|
||||
// String token = httpServletRequest.getHeader("token");
|
||||
public Result<UserInfo> getUserInfo() {
|
||||
log.info("get --- 获取用户登录信息");
|
||||
|
||||
return Result.build(AuthContextUtil.get(), ResultCodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取用户登录信息1", description = "获取token")
|
||||
@GetMapping(value = "getUserInfo1")
|
||||
public Result getUserInfo(@RequestHeader(name = "token") String token) {
|
||||
log.info("get --- 获取用户登录信息");
|
||||
|
||||
SysUser sysUser = sysUserService.getUserInfo(token);
|
||||
return Result.build(sysUser, ResultCodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
// 用户退出
|
||||
@Operation(summary = "用户退出", description = "清除Redis中token")
|
||||
@GetMapping(".logout")
|
||||
@GetMapping("logout")
|
||||
public Result logout(@RequestHeader(name = "token") String token) {
|
||||
log.info("get --- 用户退出");
|
||||
|
||||
sysUserService.logout(token);
|
||||
return Result.build(null, ResultCodeEnum.SUCCESS);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
package cn.bunny.controller;
|
||||
|
||||
import cn.bunny.service.SysRoleService;
|
||||
import cn.bunny.spzx.model.dto.system.SysRoleDto;
|
||||
import cn.bunny.spzx.model.entity.system.SysRole;
|
||||
import cn.bunny.spzx.model.vo.common.Result;
|
||||
import cn.bunny.spzx.model.vo.common.ResultCodeEnum;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Tag(name = "用户角色查询")
|
||||
@Log4j2
|
||||
@RestController
|
||||
@RequestMapping("/admin/system/sysRole")
|
||||
public class SysRoleController {
|
||||
@Autowired
|
||||
private SysRoleService sysRoleService;
|
||||
|
||||
@Operation(summary = "彻底删除角色", description = "使用id彻底删除角色信息")
|
||||
@DeleteMapping("deleteSysRoleByRoleId")
|
||||
public Result deleteSysRoleByRoleId(@RequestParam("roleId") Long roleId) {
|
||||
log.info("delete --- 彻底删除角色");
|
||||
|
||||
sysRoleService.deleteSysRoleByRoleId(roleId);
|
||||
return Result.build(null, ResultCodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除角色", description = "使用id删除角色,将状态修改为1")
|
||||
@PutMapping("deleteSysRole")
|
||||
public Result deleteById(@RequestParam("roleId") Long roleId) {
|
||||
log.info("update --- 删除角色");
|
||||
|
||||
sysRoleService.deleteSysRole(roleId);
|
||||
return Result.build(roleId, ResultCodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
@Operation(summary = "角色修改方法", description = "修改角色")
|
||||
@PutMapping("updateSysRole")
|
||||
public Result updateSysRole(@RequestBody SysRole sysRole) {
|
||||
log.info("put --- 角色修改方法");
|
||||
|
||||
sysRoleService.updateSysRole(sysRole);
|
||||
return Result.build(sysRole, ResultCodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
@Operation(summary = "角色添加的方法", description = "角色添加")
|
||||
@PostMapping(value = "saveSysRole")
|
||||
public Result saveSysRole(@RequestBody SysRole sysRole) {
|
||||
log.info("post --- 角色添加的方法");
|
||||
|
||||
sysRoleService.saveSysRole(sysRole);
|
||||
return Result.build(sysRole, ResultCodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
@Operation(summary = "角色列表查询", description = "角色列表查询")
|
||||
@PostMapping("findByPage/{current}/{limit}")
|
||||
public Result findByPage(@PathVariable("current") Integer current,
|
||||
@PathVariable("limit") Integer limit,
|
||||
@RequestBody SysRoleDto sysRoleDto) {
|
||||
log.info("post --- 角色列表查询");
|
||||
|
||||
PageInfo<SysRole> pageInfo = sysRoleService.findByPage(sysRoleDto, current, limit);
|
||||
return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@ import cn.hutool.core.util.StrUtil;
|
|||
import com.alibaba.fastjson.JSON;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
@ -19,15 +20,12 @@ import java.io.PrintWriter;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
@Log4j2
|
||||
public class LoginAuthInterceptor implements HandlerInterceptor {
|
||||
@Autowired
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
|
||||
/**
|
||||
* 响应208给前端
|
||||
*
|
||||
* @param response
|
||||
*/
|
||||
// 响应208给前端
|
||||
public void respondNoLoginInfo(HttpServletResponse response) {
|
||||
Result<Object> result = Result.build(null, ResultCodeEnum.LOGIN_AUTH);
|
||||
PrintWriter writer = null;
|
||||
|
@ -36,6 +34,7 @@ public class LoginAuthInterceptor implements HandlerInterceptor {
|
|||
try {
|
||||
writer = response.getWriter();
|
||||
writer.println(JSON.toJSONString(result));
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
|
@ -46,19 +45,7 @@ public class LoginAuthInterceptor implements HandlerInterceptor {
|
|||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
/**
|
||||
* 1. 获取骑牛方式
|
||||
* - 如果请求方式是option 预检请求,直接做放行
|
||||
* 2. 从请求中获取token
|
||||
* 3. 如果token为空,返回错误提示
|
||||
* 4. 如果token不为空,拿着token查询redis
|
||||
* 5. 如果redis查询不到数据,返回错误提示
|
||||
* 6. 如果redis查询用户信息,把用户信息放到ThreadLocal
|
||||
* 7. 更新redis更新时间
|
||||
* 放行
|
||||
*/
|
||||
|
||||
// 1. 获取骑牛方式
|
||||
// 1. 获取方式
|
||||
String method = request.getMethod();
|
||||
if ("OPTIONS".equals(method)) {
|
||||
return true;
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package cn.bunny.mapper;
|
||||
|
||||
import cn.bunny.spzx.model.dto.system.SysRoleDto;
|
||||
import cn.bunny.spzx.model.entity.system.SysRole;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysRoleMapper {
|
||||
// 角色列表对象
|
||||
List<SysRole> findByPage(SysRoleDto sysRoleDto);
|
||||
|
||||
// 角色添加的方法
|
||||
void saveSysRole(SysRole sysRole);
|
||||
|
||||
// 角色修改方法
|
||||
void updateSysRole(SysRole sysRole);
|
||||
|
||||
// 角色删除方法
|
||||
void deleteSysRole(Long roleId);
|
||||
|
||||
// 彻底删除角色
|
||||
void deleteSysRoleByRoleId(Long roleId);
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
package cn.bunny;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "spzx.auth")
|
||||
public class properties {
|
||||
private List<String> noAuthUrls;
|
||||
}
|
||||
package cn.bunny.properties;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "spzx.auth")
|
||||
public class UserProperties {
|
||||
private List<String> noAuthUrls;
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package cn.bunny.service;
|
||||
|
||||
import cn.bunny.spzx.model.dto.system.SysRoleDto;
|
||||
import cn.bunny.spzx.model.entity.system.SysRole;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
public interface SysRoleService {
|
||||
// 角色列表查询
|
||||
PageInfo<SysRole> findByPage(SysRoleDto sysRoleDto, Integer current, Integer limit);
|
||||
|
||||
// 角色添加的方法
|
||||
void saveSysRole(SysRole sysRole);
|
||||
|
||||
// 角色修改方法
|
||||
void updateSysRole(SysRole sysRole);
|
||||
|
||||
// 角色删除方法
|
||||
void deleteSysRole(Long roleId);
|
||||
|
||||
// 彻底删除角色
|
||||
void deleteSysRoleByRoleId(Long roleId);
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package cn.bunny.service.impl;
|
||||
|
||||
import cn.bunny.mapper.SysRoleMapper;
|
||||
import cn.bunny.service.SysRoleService;
|
||||
import cn.bunny.spzx.model.dto.system.SysRoleDto;
|
||||
import cn.bunny.spzx.model.entity.system.SysRole;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Log4j2
|
||||
@Service
|
||||
public class SysRoleServiceImpl implements SysRoleService {
|
||||
@Autowired
|
||||
private SysRoleMapper sysRoleMapper;
|
||||
|
||||
@Override
|
||||
public PageInfo<SysRole> findByPage(SysRoleDto sysRoleDto, Integer current, Integer limit) {
|
||||
// 设置分页器参数
|
||||
PageHelper.startPage(current, limit);
|
||||
// 根据条件查询所以数据
|
||||
List<SysRole> list = sysRoleMapper.findByPage(sysRoleDto);
|
||||
// 封装pageinfo对象
|
||||
PageInfo<SysRole> pageInfo = new PageInfo<>(list);
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
// 角色添加的方法
|
||||
@Override
|
||||
public void saveSysRole(SysRole sysRole) {
|
||||
sysRoleMapper.saveSysRole(sysRole);
|
||||
}
|
||||
|
||||
// 角色修改方法
|
||||
@Override
|
||||
public void updateSysRole(SysRole sysRole) {
|
||||
sysRoleMapper.updateSysRole(sysRole);
|
||||
}
|
||||
|
||||
// deleteSysRole
|
||||
@Override
|
||||
public void deleteSysRole(Long roleId) {
|
||||
sysRoleMapper.deleteSysRole(roleId);
|
||||
}
|
||||
|
||||
// 彻底删除角色
|
||||
@Override
|
||||
public void deleteSysRoleByRoleId(Long roleId) {
|
||||
sysRoleMapper.deleteSysRoleByRoleId(roleId);
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@ import cn.bunny.spzx.model.vo.common.ResultCodeEnum;
|
|||
import cn.bunny.spzx.model.vo.system.LoginVo;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -18,6 +19,7 @@ import org.springframework.util.DigestUtils;
|
|||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Log4j2
|
||||
@Service
|
||||
public class SysUserServiceImpl implements SysUserService {
|
||||
@Autowired
|
||||
|
@ -34,15 +36,11 @@ public class SysUserServiceImpl implements SysUserService {
|
|||
String codeKey = loginDto.getCodeKey();
|
||||
String redisCode = redisTemplate.opsForValue().get("user:validate" + codeKey);
|
||||
|
||||
System.out.println("redisCode" + redisCode);
|
||||
System.out.println("captcha" + captcha);
|
||||
|
||||
// 比较验证码
|
||||
if (StrUtil.isEmpty(redisCode) || !StrUtil.equalsIgnoreCase(redisCode, captcha)) {
|
||||
redisTemplate.delete("user:validate" + codeKey);
|
||||
throw new BunnyException(ResultCodeEnum.VALIDATECODE_ERROR);
|
||||
}
|
||||
|
||||
// 如果一致,删除Redis中验证码
|
||||
redisTemplate.delete("user:validate" + codeKey);
|
||||
|
||||
|
|
|
@ -1,37 +1,37 @@
|
|||
package cn.bunny.service.impl;
|
||||
|
||||
import cn.bunny.service.ValidateCodeService;
|
||||
import cn.bunny.spzx.model.vo.system.ValidateCodeVo;
|
||||
import cn.hutool.captcha.CaptchaUtil;
|
||||
import cn.hutool.captcha.CircleCaptcha;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Service
|
||||
public class ValidateCodeServiceIImpl implements ValidateCodeService {
|
||||
@Autowired
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
|
||||
// 生成验证码
|
||||
@Override
|
||||
public ValidateCodeVo generateValidateCode() {
|
||||
// 使用hutool生成验证码
|
||||
CircleCaptcha circleCaptcha = CaptchaUtil.createCircleCaptcha(150, 40, 4, 20);
|
||||
String code = circleCaptcha.getCode();
|
||||
String imageBase64 = circleCaptcha.getImageBase64();
|
||||
|
||||
// 放到Redis
|
||||
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
redisTemplate.opsForValue().set("user:validate" + uuid, code, 5, TimeUnit.MINUTES);
|
||||
|
||||
// 返回 validateCodeVo
|
||||
ValidateCodeVo validateCodeVo = new ValidateCodeVo();
|
||||
validateCodeVo.setCodeKey(uuid);
|
||||
validateCodeVo.setCodeValue("data:image/png;base64," + imageBase64);
|
||||
return validateCodeVo;
|
||||
}
|
||||
}
|
||||
package cn.bunny.service.impl;
|
||||
|
||||
import cn.bunny.service.ValidateCodeService;
|
||||
import cn.bunny.spzx.model.vo.system.ValidateCodeVo;
|
||||
import cn.hutool.captcha.CaptchaUtil;
|
||||
import cn.hutool.captcha.CircleCaptcha;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Service
|
||||
public class ValidateCodeServiceIImpl implements ValidateCodeService {
|
||||
@Autowired
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
|
||||
// 生成验证码
|
||||
@Override
|
||||
public ValidateCodeVo generateValidateCode() {
|
||||
// 使用hutool生成验证码
|
||||
CircleCaptcha circleCaptcha = CaptchaUtil.createCircleCaptcha(150, 40, 4, 20);
|
||||
String code = circleCaptcha.getCode();
|
||||
String imageBase64 = circleCaptcha.getImageBase64();
|
||||
|
||||
// 放到Redis
|
||||
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
redisTemplate.opsForValue().set("user:validate" + uuid, code, 5, TimeUnit.MINUTES);
|
||||
|
||||
// 返回 validateCodeVo
|
||||
ValidateCodeVo validateCodeVo = new ValidateCodeVo();
|
||||
validateCodeVo.setCodeKey(uuid);
|
||||
validateCodeVo.setCodeValue("data:image/png;base64," + imageBase64);
|
||||
return validateCodeVo;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ spring:
|
|||
profiles:
|
||||
active: dev
|
||||
|
||||
|
||||
server:
|
||||
servlet:
|
||||
context-path: /api
|
||||
|
@ -12,4 +13,4 @@ spzx:
|
|||
auth:
|
||||
noAuthUrls:
|
||||
- /admin/system/index/login
|
||||
- /admin/system/index/generateValidateCode
|
||||
- /admin/system/index/generateValidateCode
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
${AnsiColor.BRIGHT_MAGENTA}
|
||||
|
||||
________ ___ ___ ________ ________ ___ ___ ________ ________
|
||||
|\ __ \|\ \|\ \|\ ___ \|\ ___ \ |\ \ / /|\ ____\|\ ___ \
|
||||
\ \ \|\ /\ \ \\\ \ \ \\ \ \ \ \\ \ \ \ \ \/ / | \ \___|\ \ \\ \ \
|
||||
\ \ __ \ \ \\\ \ \ \\ \ \ \ \\ \ \ \ \ / / \ \ \ \ \ \\ \ \
|
||||
\ \ \|\ \ \ \\\ \ \ \\ \ \ \ \\ \ \ \/ / /__ \ \ \____\ \ \\ \ \
|
||||
\ \_______\ \_______\ \__\\ \__\ \__\\ \__\__/ / /|\__\ \ \_______\ \__\\ \__\
|
||||
\|_______|\|_______|\|__| \|__|\|__| \|__|\___/ / \|__| \|_______|\|__| \|__|
|
||||
\|___|/
|
||||
|
||||
${AnsiColor.BRIGHT_MAGENTA}
|
||||
|
||||
::: ${application.title}
|
||||
::: Project(版本:${application.formatted-version}} ::: spring-boot ${spring-boot.version}
|
||||
::: SpringBoot版本:${spring-boot.formatted-version}
|
||||
::: ${application.formatted-version}
|
|
@ -0,0 +1,70 @@
|
|||
<?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="cn.bunny.mapper.SysRoleMapper">
|
||||
|
||||
<!-- 映射查询到的字段 -->
|
||||
<resultMap id="sysRoleMap" type="cn.bunny.spzx.model.entity.system.SysRole" autoMapping="true"/>
|
||||
|
||||
<!-- 用于select查询公用抽取的列 -->
|
||||
<sql id="columns">
|
||||
id,role_name,role_code,description,create_time,update_time,is_deleted
|
||||
</sql>
|
||||
|
||||
|
||||
<!-- 角色添加的方法 -->
|
||||
<insert id="saveSysRole">
|
||||
insert into sys_role (id,
|
||||
role_name,
|
||||
role_code,
|
||||
description)
|
||||
values (#{id},
|
||||
#{roleName},
|
||||
#{roleCode},
|
||||
#{description})
|
||||
</insert>
|
||||
|
||||
<!-- 修改角色 -->
|
||||
<update id="updateSysRole">
|
||||
update sys_role set
|
||||
<if test="roleName != null and roleName != ''">
|
||||
role_name = #{roleName},
|
||||
</if>
|
||||
<if test="roleCode != null and roleCode != ''">
|
||||
role_code = #{roleCode},
|
||||
</if>
|
||||
<if test="description != null and description != ''">
|
||||
description = #{description},
|
||||
</if>
|
||||
update_time = now()
|
||||
where
|
||||
id = #{id}
|
||||
</update>
|
||||
|
||||
<!-- 删除角色 -->
|
||||
<update id="deleteSysRole">
|
||||
update sys_role
|
||||
set is_deleted=1
|
||||
where id = #{roleId}
|
||||
</update>
|
||||
|
||||
<!-- 彻底删除角色 -->
|
||||
<delete id="deleteSysRoleByRoleId">
|
||||
delete
|
||||
from sys_role
|
||||
where id = #{roleId}
|
||||
</delete>
|
||||
|
||||
<!-- 角色列表方法 -->
|
||||
<select id="findByPage" resultMap="sysRoleMap">
|
||||
select
|
||||
<include refid="columns"/>
|
||||
from sys_role
|
||||
<where>
|
||||
<if test="roleName != null and roleName != ''">
|
||||
and role_name like CONCAT('%',#{roleName},'%')
|
||||
</if>
|
||||
and is_deleted=0
|
||||
</where>
|
||||
order by id desc
|
||||
</select>
|
||||
</mapper>
|
|
@ -12,8 +12,8 @@
|
|||
<artifactId>spzx-model</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
|
@ -28,7 +28,7 @@
|
|||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
|
||||
<version>4.1.0</version>
|
||||
<version>4.3.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
package cn.bunny;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello world!");
|
||||
}
|
||||
}
|
|
@ -1,23 +1,26 @@
|
|||
package cn.bunny.spzx.model.dto.h5;
|
||||
|
||||
import cn.bunny.spzx.model.entity.order.OrderItem;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Schema(description = "快递相关")
|
||||
@Data
|
||||
public class OrderInfoDto {
|
||||
|
||||
//送货地址id
|
||||
@Schema(description = "送货地址id")
|
||||
private Long userAddressId;
|
||||
|
||||
//运费
|
||||
@Schema(description = "运费")
|
||||
private BigDecimal feightFee;
|
||||
|
||||
//备注
|
||||
@Schema(description = "备注")
|
||||
private String remark;
|
||||
|
||||
//订单明细
|
||||
@Schema(description = "订单明细")
|
||||
private List<OrderItem> orderItemList;
|
||||
}
|
|
@ -6,22 +6,16 @@ import lombok.Data;
|
|||
@Data
|
||||
@Schema(description = "商品列表搜索条件实体类")
|
||||
public class ProductSkuDto {
|
||||
|
||||
@Schema(description = "关键字")
|
||||
private String keyword;
|
||||
|
||||
@Schema(description = "品牌id")
|
||||
private Long brandId;
|
||||
|
||||
@Schema(description = "一级分类id")
|
||||
private Long category1Id;
|
||||
|
||||
@Schema(description = "二级分类id")
|
||||
private Long category2Id;
|
||||
|
||||
@Schema(description = "三级分类id")
|
||||
private Long category3Id;
|
||||
|
||||
@Schema(description = "排序(综合排序:1 价格升序:2 价格降序:3)")
|
||||
private Integer order = 1;
|
||||
|
||||
|
|
|
@ -6,10 +6,8 @@ import lombok.Data;
|
|||
@Data
|
||||
@Schema(description = "用户登录请求参数")
|
||||
public class UserLoginDto {
|
||||
|
||||
@Schema(description = "用户名")
|
||||
private String username ;
|
||||
|
||||
private String username;
|
||||
@Schema(description = "密码")
|
||||
private String password ;
|
||||
private String password;
|
||||
}
|
|
@ -4,19 +4,15 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
|||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Schema(description="注册对象")
|
||||
@Schema(description = "注册对象")
|
||||
public class UserRegisterDto {
|
||||
|
||||
@Schema(description = "用户名")
|
||||
private String username;
|
||||
|
||||
@Schema(description = "密码")
|
||||
private String password;
|
||||
|
||||
@Schema(description = "昵称")
|
||||
private String nickName;
|
||||
|
||||
@Schema(description = "手机验证码")
|
||||
private String code ;
|
||||
private String code;
|
||||
|
||||
}
|
|
@ -6,10 +6,8 @@ import lombok.Data;
|
|||
@Data
|
||||
@Schema(description = "搜索条件实体类")
|
||||
public class OrderStatisticsDto {
|
||||
|
||||
@Schema(description = "开始时间")
|
||||
private String createTimeBegin;
|
||||
|
||||
@Schema(description = "结束时间")
|
||||
private String createTimeEnd;
|
||||
|
||||
|
|
|
@ -6,11 +6,9 @@ import lombok.Data;
|
|||
@Data
|
||||
@Schema(description = "搜索条件实体类")
|
||||
public class CategoryBrandDto {
|
||||
|
||||
@Schema(description = "品牌id")
|
||||
private Long brandId;
|
||||
|
||||
@Schema(description = "分类id")
|
||||
private Long categoryId;
|
||||
@Schema(description = "品牌id")
|
||||
private Long brandId;
|
||||
@Schema(description = "分类id")
|
||||
private Long categoryId;
|
||||
|
||||
}
|
|
@ -7,17 +7,12 @@ import lombok.Data;
|
|||
@Data
|
||||
@Schema(description = "商品搜索条件实体类")
|
||||
public class ProductDto extends BaseEntity {
|
||||
|
||||
@Schema(description = "品牌id")
|
||||
private Long brandId;
|
||||
|
||||
@Schema(description = "一级分类id")
|
||||
private Long category1Id;
|
||||
|
||||
@Schema(description = "二级分类id")
|
||||
private Long category2Id;
|
||||
|
||||
@Schema(description = "三级分类id")
|
||||
private Long category3Id;
|
||||
|
||||
}
|
||||
|
|
|
@ -5,8 +5,7 @@ import lombok.Data;
|
|||
@Data
|
||||
public class SkuSaleDto {
|
||||
|
||||
private Long skuId;
|
||||
private Integer num;
|
||||
|
||||
private Long skuId;
|
||||
private Integer num;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,11 +9,10 @@ import java.util.Map;
|
|||
@Data
|
||||
@Schema(description = "请求参数实体类")
|
||||
public class AssginMenuDto {
|
||||
|
||||
@Schema(description = "角色id")
|
||||
private Long roleId; // 角色id
|
||||
private Long roleId;
|
||||
|
||||
@Schema(description = "选中的菜单id的集合")
|
||||
private List<Map<String , Number>> menuIdList; // 选中的菜单id的集合; Map的键表示菜单的id,值表示是否为半开; 0否,1是
|
||||
private List<Map<String, Number>> menuIdList;
|
||||
|
||||
}
|
Loading…
Reference in New Issue