修复一些问题以及优惠券管理功能
This commit is contained in:
@@ -73,8 +73,6 @@ public class PermissionAspect {
|
||||
|
||||
// 获取权限码
|
||||
String permissionCode = requirePermission.value();
|
||||
// 获取需要的用户类型
|
||||
int requireUserType = requirePermission.requireUserType();
|
||||
|
||||
// 默认有权限
|
||||
boolean hasPermission = true;
|
||||
@@ -84,11 +82,6 @@ public class PermissionAspect {
|
||||
hasPermission = permissionService.hasPermission(userId, permissionCode);
|
||||
}
|
||||
|
||||
// 如果需要检查用户类型,则进行类型检查
|
||||
if (hasPermission && requireUserType >= 0) {
|
||||
hasPermission = permissionService.hasPermissionByType(userDO.getType(), requireUserType);
|
||||
}
|
||||
|
||||
// 如果没有权限,返回错误
|
||||
if (!hasPermission) {
|
||||
return Result.error(403, "权限不足");
|
||||
|
||||
@@ -66,6 +66,7 @@ public class AuthInterceptor implements HandlerInterceptor {
|
||||
path.contains("/shop/list/simple") ||
|
||||
path.contains("/admin/auth/login") ||
|
||||
path.contains("/admin/object-storage-file/upload") ||
|
||||
path.contains("/health");
|
||||
path.contains("/health") ||
|
||||
path.contains("/error");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,12 +16,13 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
||||
registry.addInterceptor(authInterceptor)
|
||||
.addPathPatterns("/**")
|
||||
.excludePathPatterns(
|
||||
"/api/user/login",
|
||||
"/api/user/register",
|
||||
"/api/user/refresh-token",
|
||||
"/api/shop/list/simple",
|
||||
"/api/admin/auth/login",
|
||||
"/api/admin/object-storage-file/upload",
|
||||
"/user/login",
|
||||
"/user/register",
|
||||
"/user/refresh-token",
|
||||
"/user/get/account/**",
|
||||
"/shop/list/simple",
|
||||
"/admin/auth/login",
|
||||
"/admin/object-storage-file/upload",
|
||||
"/error",
|
||||
"/health/**"
|
||||
);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.xiaowang.yuminailcore.controller;
|
||||
|
||||
import com.xiaowang.yuminailcore.annotation.RequirePermission;
|
||||
import com.xiaowang.yuminailcore.common.Result;
|
||||
import com.xiaowang.yuminailcore.dto.TagDTO;
|
||||
import com.xiaowang.yuminailcore.vo.TagVO;
|
||||
@@ -30,6 +31,7 @@ public class TagController {
|
||||
* @return 标签ID
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
@RequirePermission("tag:create")
|
||||
public Result<Long> createTag(@RequestBody TagDTO tagDTO) {
|
||||
Long id = tagService.createTag(tagDTO);
|
||||
return Result.success(id);
|
||||
@@ -43,6 +45,7 @@ public class TagController {
|
||||
* @return 是否更新成功
|
||||
*/
|
||||
@PutMapping("/update/{id}")
|
||||
@RequirePermission("tag:edit")
|
||||
public Result<Boolean> updateTag(@PathVariable Long id, @RequestBody TagDTO tagDTO) {
|
||||
boolean success = tagService.updateTag(id, tagDTO);
|
||||
return Result.success(success);
|
||||
@@ -55,6 +58,7 @@ public class TagController {
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@RequirePermission("tag:delete")
|
||||
public Result<Boolean> deleteTag(@PathVariable Long id) {
|
||||
boolean success = tagService.deleteTag(id);
|
||||
return Result.success(success);
|
||||
@@ -67,6 +71,7 @@ public class TagController {
|
||||
* @return 标签VO
|
||||
*/
|
||||
@GetMapping("/get/{id}")
|
||||
@RequirePermission("tag:view")
|
||||
public Result<TagVO> getTagById(@PathVariable Long id) {
|
||||
TagVO tagVO = tagService.getTagById(id);
|
||||
return Result.success(tagVO);
|
||||
@@ -78,6 +83,7 @@ public class TagController {
|
||||
* @return 标签VO列表
|
||||
*/
|
||||
@GetMapping("/list/all")
|
||||
@RequirePermission("tag:view")
|
||||
public Result<List<TagVO>> listAllTags() {
|
||||
List<TagVO> tagVOs = tagService.listAllTags();
|
||||
return Result.success(tagVOs);
|
||||
@@ -90,6 +96,7 @@ public class TagController {
|
||||
* @return 标签VO列表
|
||||
*/
|
||||
@GetMapping("/list/by-shop/{shopId}")
|
||||
@RequirePermission("tag:view")
|
||||
public Result<List<TagVO>> listTagsByShopId(@PathVariable Long shopId) {
|
||||
List<TagVO> tagVOs = tagService.listTagsByShopId(shopId);
|
||||
return Result.success(tagVOs);
|
||||
@@ -102,6 +109,7 @@ public class TagController {
|
||||
* @return 标签VO
|
||||
*/
|
||||
@GetMapping("/get/tagName/{tagName}")
|
||||
@RequirePermission("tag:view")
|
||||
public Result<TagVO> getTagByTagName(@PathVariable String tagName) {
|
||||
TagVO tagVO = tagService.getTagByTagName(tagName);
|
||||
return Result.success(tagVO);
|
||||
|
||||
@@ -57,6 +57,11 @@ public class CouponDTO {
|
||||
*/
|
||||
private LocalDateTime endTime;
|
||||
|
||||
/**
|
||||
* 所属店铺ID
|
||||
*/
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 可用标签ID列表
|
||||
*/
|
||||
|
||||
@@ -72,6 +72,11 @@ public class CouponDO extends BaseEntity {
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 所属店铺ID
|
||||
*/
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 逻辑删除:0-未删,1-已删
|
||||
*/
|
||||
|
||||
+2
-11
@@ -83,20 +83,11 @@ public interface PermissionService extends IService<PermissionDO> {
|
||||
boolean assignPermissions(UserPermissionDTO userPermissionDTO, Long currentUserId);
|
||||
|
||||
/**
|
||||
* 检查用户是否有指定权限
|
||||
* 检查用户是否拥有指定权限
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param permissionCode 权限编码
|
||||
* @return 是否有权限
|
||||
* @return 是否拥有权限
|
||||
*/
|
||||
boolean hasPermission(Long userId, String permissionCode);
|
||||
|
||||
/**
|
||||
* 根据用户类型判断是否有权限(基于用户级别)
|
||||
*
|
||||
* @param userType 用户类型
|
||||
* @param requireType 需要的最低用户类型
|
||||
* @return 是否有权限
|
||||
*/
|
||||
boolean hasPermissionByType(Integer userType, Integer requireType);
|
||||
}
|
||||
|
||||
+13
@@ -11,6 +11,7 @@ import com.xiaowang.yuminailcore.entity.TagDO;
|
||||
import com.xiaowang.yuminailcore.entity.UserCouponDO;
|
||||
import com.xiaowang.yuminailcore.mapper.CouponMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.CouponTagMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.ShopMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.TagMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.UserCouponMapper;
|
||||
import com.xiaowang.yuminailcore.service.CouponService;
|
||||
@@ -38,6 +39,7 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, CouponDO> imple
|
||||
private final CouponTagMapper couponTagMapper;
|
||||
private final UserCouponMapper userCouponMapper;
|
||||
private final TagMapper tagMapper;
|
||||
private final ShopMapper shopMapper;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@@ -55,6 +57,7 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, CouponDO> imple
|
||||
couponDO.setStartTime(couponDTO.getStartTime());
|
||||
couponDO.setEndTime(couponDTO.getEndTime());
|
||||
couponDO.setStatus(1);
|
||||
couponDO.setShopId(shopId);
|
||||
save(couponDO);
|
||||
|
||||
// 处理标签关联
|
||||
@@ -81,6 +84,7 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, CouponDO> imple
|
||||
couponDO.setTotalCount(couponDTO.getTotalCount());
|
||||
couponDO.setStartTime(couponDTO.getStartTime());
|
||||
couponDO.setEndTime(couponDTO.getEndTime());
|
||||
couponDO.setShopId(shopId);
|
||||
updateById(couponDO);
|
||||
|
||||
// 处理标签关联
|
||||
@@ -408,6 +412,15 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, CouponDO> imple
|
||||
couponVO.setStartTime(couponDO.getStartTime());
|
||||
couponVO.setEndTime(couponDO.getEndTime());
|
||||
couponVO.setStatus(couponDO.getStatus());
|
||||
couponVO.setShopId(couponDO.getShopId());
|
||||
|
||||
// 获取店铺名称
|
||||
if (couponDO.getShopId() != null) {
|
||||
com.xiaowang.yuminailcore.entity.ShopDO shopDO = shopMapper.selectById(couponDO.getShopId());
|
||||
if (shopDO != null) {
|
||||
couponVO.setShopName(shopDO.getShopName());
|
||||
}
|
||||
}
|
||||
|
||||
switch (couponDO.getStatus()) {
|
||||
case 1:
|
||||
|
||||
+6
-42
@@ -155,25 +155,17 @@ public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permiss
|
||||
throw new RuntimeException("目标用户不存在");
|
||||
}
|
||||
|
||||
// 检查权限:只有管理员和店长可以给其他用户分配权限
|
||||
if (currentUser.getType() != 4 && currentUser.getType() != 2) {
|
||||
throw new RuntimeException("权限不足,只有管理员和店长可以分配权限");
|
||||
// 检查权限:只有拥有权限分配权限的用户可以给其他用户分配权限
|
||||
if (!hasPermission(currentUserId, "permission:assign")) {
|
||||
throw new RuntimeException("权限不足,没有权限分配权限");
|
||||
}
|
||||
|
||||
// 如果当前用户是店长(不是管理员),需要进一步检查
|
||||
// 如果当前用户是店长,需要进一步检查
|
||||
if (currentUser.getType() == 2) {
|
||||
// 店长只能给属于自己店铺的美甲师分配权限
|
||||
// 店长只能给属于自己店铺的用户分配权限
|
||||
if (targetUser.getShopId() == null || !targetUser.getShopId().equals(currentUser.getShopId())) {
|
||||
throw new RuntimeException("权限不足,只能给本店铺的美甲师分配权限");
|
||||
throw new RuntimeException("权限不足,只能给本店铺的用户分配权限");
|
||||
}
|
||||
|
||||
// 店长只能给美甲师(type=3)分配权限
|
||||
if (targetUser.getType() != 3) {
|
||||
throw new RuntimeException("权限不足,只能给美甲师分配权限");
|
||||
}
|
||||
|
||||
// 这里可以添加更多逻辑,例如检查权限是否与当前店铺相关
|
||||
// 由于当前权限系统没有与店铺关联,暂时跳过这一步
|
||||
}
|
||||
|
||||
// 删除旧的权限分配
|
||||
@@ -198,12 +190,6 @@ public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permiss
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(Long userId, String permissionCode) {
|
||||
// 先检查用户是否为管理员,管理员拥有所有权限
|
||||
UserDO userDO = userMapper.selectById(userId);
|
||||
if (userDO != null && userDO.getType() == 4) {
|
||||
return true;
|
||||
}
|
||||
|
||||
List<UserPermissionDO> userPermissions = userPermissionMapper.selectList(
|
||||
Wrappers.lambdaQuery(UserPermissionDO.class)
|
||||
.eq(UserPermissionDO::getUserId, userId)
|
||||
@@ -230,28 +216,6 @@ public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permiss
|
||||
return permissionIds.contains(permissionDO.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermissionByType(Integer userType, Integer requireType) {
|
||||
if (userType == null || requireType == null) {
|
||||
return false;
|
||||
}
|
||||
// 管理员(4)拥有最高权限
|
||||
if (userType == 4) {
|
||||
return true;
|
||||
}
|
||||
// 店长(2)的权限高于美甲师(3)
|
||||
if (userType == 2) {
|
||||
// 店长可以访问需要店长或美甲师权限的接口
|
||||
return requireType == 2 || requireType == 3;
|
||||
}
|
||||
// 美甲师(3)只能访问需要美甲师权限的接口
|
||||
if (userType == 3) {
|
||||
return requireType == 3;
|
||||
}
|
||||
// 用户(0)只能访问需要用户权限的接口
|
||||
return userType >= requireType;
|
||||
}
|
||||
|
||||
private PermissionVO convertToVO(PermissionDO permissionDO) {
|
||||
PermissionVO permissionVO = new PermissionVO();
|
||||
permissionVO.setId(permissionDO.getId());
|
||||
|
||||
+93
-6
@@ -10,7 +10,11 @@ import com.xiaowang.yuminailcore.dto.LoginRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.RegisterRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.UserDTO;
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
import com.xiaowang.yuminailcore.entity.UserPermissionDO;
|
||||
import com.xiaowang.yuminailcore.entity.PermissionDO;
|
||||
import com.xiaowang.yuminailcore.mapper.UserMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.UserPermissionMapper;
|
||||
import com.xiaowang.yuminailcore.mapper.PermissionMapper;
|
||||
import com.xiaowang.yuminailcore.service.ShopService;
|
||||
import com.xiaowang.yuminailcore.service.UserService;
|
||||
import com.xiaowang.yuminailcore.utils.JwtUtil;
|
||||
@@ -19,7 +23,9 @@ import com.xiaowang.yuminailcore.vo.PageResultVO;
|
||||
import com.xiaowang.yuminailcore.vo.UserVO;
|
||||
import com.xiaowang.yuminailcore.vo.ShopVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
@@ -41,6 +47,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
private final UserMapper userMapper;
|
||||
private final JwtUtil jwtUtil;
|
||||
private final ShopService shopService;
|
||||
private final UserPermissionMapper userPermissionMapper;
|
||||
private final PermissionMapper permissionMapper;
|
||||
private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||
|
||||
/**
|
||||
* 创建新用户
|
||||
@@ -48,6 +57,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
* @return 新创建用户的ID
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long createUser(UserDTO userDTO) {
|
||||
// 检查账号是否已存在
|
||||
UserDO existingUser = userMapper.selectOne(
|
||||
@@ -64,7 +74,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
userDO.setShopId(userDTO.getShopId());
|
||||
userDO.setNickname(userDTO.getNickname());
|
||||
userDO.setAccount(userDTO.getAccount());
|
||||
userDO.setPassword(userDTO.getPassword());
|
||||
userDO.setPassword(passwordEncoder.encode(userDTO.getPassword()));
|
||||
userDO.setPhone(userDTO.getPhone());
|
||||
userDO.setSignature(userDTO.getSignature());
|
||||
userDO.setLevel(userDTO.getLevel());
|
||||
@@ -87,8 +97,83 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
throw e;
|
||||
}
|
||||
|
||||
// 分配默认权限
|
||||
assignDefaultPermissions(userDO.getId(), userDO.getType());
|
||||
|
||||
return userDO.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 分配默认权限
|
||||
* @param userId 用户ID
|
||||
* @param userType 用户类型
|
||||
*/
|
||||
private void assignDefaultPermissions(Long userId, Integer userType) {
|
||||
List<PermissionDO> permissions = null;
|
||||
|
||||
if (userType == 4) { // 管理员
|
||||
// 分配所有权限
|
||||
permissions = permissionMapper.selectList(
|
||||
Wrappers.lambdaQuery(PermissionDO.class)
|
||||
.eq(PermissionDO::getIsDelete, 0)
|
||||
);
|
||||
} else if (userType == 2) { // 店长
|
||||
// 分配店长默认权限
|
||||
// 首页的全部权限
|
||||
// 仪表盘的全部权限
|
||||
// 当前店铺的用户管理的全部权限
|
||||
// 当前店铺的商品管理的全部权限
|
||||
// 当前店铺的店铺管理的全部权限
|
||||
// 当前店铺的权限管理的全部权限
|
||||
// 当前店铺的标签管理的全部权限
|
||||
// 当前店铺的优惠券管理的全部权限
|
||||
// 当前店铺的订单管理的全部权限
|
||||
permissions = permissionMapper.selectList(
|
||||
Wrappers.lambdaQuery(PermissionDO.class)
|
||||
.eq(PermissionDO::getIsDelete, 0)
|
||||
.in(PermissionDO::getPermissionCode, "home:view", "dashboard:view", "user:view",
|
||||
"user:create", "user:edit", "user:reset_password", "user:delete",
|
||||
"product:view", "product:create", "product:edit", "product:delete",
|
||||
"product:category:manage", "shop:view", "shop:create", "shop:edit",
|
||||
"shop:delete", "shop:staff:manage", "permission:view", "permission:create",
|
||||
"permission:edit", "permission:delete", "permission:assign",
|
||||
"tag:view", "tag:create", "tag:edit", "tag:delete", "tag:assign",
|
||||
"coupon:view", "coupon:create", "coupon:edit", "coupon:delete",
|
||||
"coupon:assign", "order:view", "order:edit", "order:delete",
|
||||
"order:process")
|
||||
);
|
||||
} else if (userType == 3) { // 美甲师
|
||||
// 分配美甲师默认权限
|
||||
// 首页的全部权限
|
||||
// 仪表盘的全部权限
|
||||
// 当前店铺的用户管理的查看权限,新增权限,密码重置权限,其他无
|
||||
// 当前店铺的商品管理的查看权限,新增权限,编辑权限,管理商品分类权限
|
||||
// 当前店铺的店铺管理的查看权限,无其他权限
|
||||
// 无当前店铺的权限管理的全部权限
|
||||
// 当前店铺的标签管理的查看,新增,编辑,分配权限,无删除权限
|
||||
// 当前店铺的优惠券管理的查看和分配权限,无其他权限
|
||||
// 当前店铺的订单管理的查看和处理权限
|
||||
permissions = permissionMapper.selectList(
|
||||
Wrappers.lambdaQuery(PermissionDO.class)
|
||||
.eq(PermissionDO::getIsDelete, 0)
|
||||
.in(PermissionDO::getPermissionCode, "home:view", "dashboard:view", "user:view",
|
||||
"user:create", "user:reset_password", "product:view", "product:create",
|
||||
"product:edit", "product:category:manage", "shop:view",
|
||||
"tag:view", "tag:create", "tag:edit", "tag:assign",
|
||||
"coupon:view", "coupon:assign", "order:view", "order:process")
|
||||
);
|
||||
}
|
||||
|
||||
if (permissions != null && !permissions.isEmpty()) {
|
||||
for (PermissionDO permission : permissions) {
|
||||
UserPermissionDO userPermissionDO = new UserPermissionDO();
|
||||
userPermissionDO.setUserId(userId);
|
||||
userPermissionDO.setPermissionId(permission.getId());
|
||||
userPermissionDO.setCreateBy(userId); // 设置创建人为当前用户
|
||||
userPermissionMapper.insert(userPermissionDO);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户信息
|
||||
@@ -125,7 +210,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
userDO.setNickname(userDTO.getNickname());
|
||||
}
|
||||
if (userDTO.getPassword() != null) {
|
||||
userDO.setPassword(userDTO.getPassword());
|
||||
userDO.setPassword(passwordEncoder.encode(userDTO.getPassword()));
|
||||
}
|
||||
if (userDTO.getPhone() != null) {
|
||||
userDO.setPhone(userDTO.getPhone());
|
||||
@@ -285,7 +370,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
throw new RuntimeException("用户不存在");
|
||||
}
|
||||
|
||||
if (!userDO.getPassword().equals(loginRequestDTO.getPassword())) {
|
||||
if (!passwordEncoder.matches(loginRequestDTO.getPassword(), userDO.getPassword())) {
|
||||
throw new RuntimeException("密码错误");
|
||||
}
|
||||
|
||||
@@ -319,7 +404,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
throw new RuntimeException("用户不存在");
|
||||
}
|
||||
|
||||
if (!userDO.getPassword().equals(loginRequestDTO.getPassword())) {
|
||||
if (!passwordEncoder.matches(loginRequestDTO.getPassword(), userDO.getPassword())) {
|
||||
throw new RuntimeException("密码错误");
|
||||
}
|
||||
|
||||
@@ -361,7 +446,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
UserDO userDO = new UserDO();
|
||||
userDO.setShopId(registerRequestDTO.getShopId());
|
||||
userDO.setAccount(registerRequestDTO.getAccount());
|
||||
userDO.setPassword(registerRequestDTO.getPassword());
|
||||
userDO.setPassword(passwordEncoder.encode(registerRequestDTO.getPassword()));
|
||||
userDO.setNickname(registerRequestDTO.getNickname());
|
||||
userDO.setType(Integer.valueOf(0));
|
||||
userDO.setLevel("普通");
|
||||
@@ -471,7 +556,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
throw new RuntimeException("权限不足,只能重置比自己级别低的用户密码");
|
||||
}
|
||||
|
||||
targetUser.setPassword("88888888");
|
||||
targetUser.setPassword(passwordEncoder.encode("88888888"));
|
||||
targetUser.setUpdateTime(LocalDateTime.now());
|
||||
|
||||
return userMapper.updateById(targetUser) > 0;
|
||||
@@ -483,6 +568,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
|
||||
LambdaQueryWrapper<UserDO> wrapper = Wrappers.lambdaQuery(UserDO.class);
|
||||
wrapper.eq(UserDO::getIsDelete, 0);
|
||||
// 过滤掉普通用户(type为0)
|
||||
wrapper.ne(UserDO::getType, 0);
|
||||
if (StringUtils.hasText(keyword)) {
|
||||
wrapper.and(w -> w.like(UserDO::getAccount, keyword)
|
||||
.or().like(UserDO::getNickname, keyword)
|
||||
|
||||
@@ -87,6 +87,16 @@ public class CouponVO {
|
||||
*/
|
||||
private String statusName;
|
||||
|
||||
/**
|
||||
* 所属店铺ID
|
||||
*/
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 所属店铺名称
|
||||
*/
|
||||
private String shopName;
|
||||
|
||||
/**
|
||||
* 可用标签列表
|
||||
*/
|
||||
|
||||
@@ -333,9 +333,10 @@ create index idx_vip_level
|
||||
|
||||
|
||||
|
||||
-- 清空现有权限数据(可选,根据需要执行)
|
||||
-- 清空现有数据
|
||||
DELETE FROM t_user_permission WHERE 1=1;
|
||||
DELETE FROM t_permission WHERE 1=1;
|
||||
DELETE FROM t_user WHERE 1=1;
|
||||
|
||||
-- 插入完整的系统权限
|
||||
INSERT INTO t_permission (permission_code, permission_name, permission_group, description, create_time, update_time, is_delete) VALUES
|
||||
@@ -377,77 +378,73 @@ INSERT INTO t_permission (permission_code, permission_name, permission_group, de
|
||||
('tag:view', '查看标签', '标签管理', '查看标签列表和详情', NOW(), NOW(), 0),
|
||||
('tag:create', '新增标签', '标签管理', '新增标签', NOW(), NOW(), 0),
|
||||
('tag:edit', '编辑标签', '标签管理', '编辑标签信息', NOW(), NOW(), 0),
|
||||
('tag:delete', '删除标签', '标签管理', '删除标签', NOW(), NOW(), 0);
|
||||
('tag:delete', '删除标签', '标签管理', '删除标签', NOW(), NOW(), 0),
|
||||
('tag:assign', '分配标签', '标签管理', '为商品分配标签', NOW(), NOW(), 0),
|
||||
|
||||
-- 优惠券管理权限
|
||||
('coupon:view', '查看优惠券', '优惠券管理', '查看优惠券列表和详情', NOW(), NOW(), 0),
|
||||
('coupon:create', '新增优惠券', '优惠券管理', '新增优惠券', NOW(), NOW(), 0),
|
||||
('coupon:edit', '编辑优惠券', '优惠券管理', '编辑优惠券信息', NOW(), NOW(), 0),
|
||||
('coupon:delete', '删除优惠券', '优惠券管理', '删除优惠券', NOW(), NOW(), 0),
|
||||
('coupon:assign', '分配优惠券', '优惠券管理', '为用户分配优惠券', NOW(), NOW(), 0),
|
||||
|
||||
-- 为管理员(type=4)分配所有权限
|
||||
INSERT INTO t_user_permission (user_id, permission_id, create_time, update_time)
|
||||
SELECT
|
||||
u.id as user_id,
|
||||
p.id as permission_id,
|
||||
NOW() as create_time,
|
||||
NOW() as update_time
|
||||
FROM t_user u
|
||||
CROSS JOIN t_permission p
|
||||
WHERE u.type = 4
|
||||
AND p.is_delete = 0;
|
||||
-- 订单管理权限
|
||||
('order:view', '查看订单', '订单管理', '查看订单列表和详情', NOW(), NOW(), 0),
|
||||
('order:edit', '编辑订单', '订单管理', '编辑订单信息', NOW(), NOW(), 0),
|
||||
('order:delete', '删除订单', '订单管理', '删除订单', NOW(), NOW(), 0),
|
||||
('order:process', '处理订单', '订单管理', '处理订单状态', NOW(), NOW(), 0);
|
||||
|
||||
-- 为店长(type=2)分配默认权限
|
||||
INSERT INTO t_user_permission (user_id, permission_id, create_time, update_time)
|
||||
SELECT
|
||||
u.id as user_id,
|
||||
p.id as permission_id,
|
||||
NOW() as create_time,
|
||||
NOW() as update_time
|
||||
FROM t_user u
|
||||
CROSS JOIN t_permission p
|
||||
WHERE u.type = 2
|
||||
AND p.is_delete = 0
|
||||
AND p.permission_code IN (
|
||||
'home:view',
|
||||
'dashboard:view',
|
||||
'user:view',
|
||||
'user:create',
|
||||
'user:edit',
|
||||
'user:reset_password',
|
||||
'user:delete',
|
||||
'product:view',
|
||||
'product:create',
|
||||
'product:edit',
|
||||
'product:delete',
|
||||
'product:category:manage',
|
||||
'shop:view',
|
||||
'shop:edit',
|
||||
'permission:view',
|
||||
'permission:assign',
|
||||
'tag:view',
|
||||
'tag:create',
|
||||
'tag:edit',
|
||||
'tag:delete'
|
||||
);
|
||||
-- 初始化admin用户,密码为123456
|
||||
-- 密码使用BCrypt加密,123456的加密值为:$2a$10$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW
|
||||
INSERT INTO t_user (id, shop_id, nickname, account, password, type, status, create_time, update_time, is_delete) VALUES
|
||||
(1, 0, '管理员', 'admin', '$2a$10$EixZaYVK1fsbw1ZfbX3OXePaWxn96p36WQoeG6Lruj3vjPGga31lW', 4, 1, NOW(), NOW(), 0);
|
||||
|
||||
-- 为管理员分配权限
|
||||
-- 首页的全部权限
|
||||
-- 仪表盘的全部权限
|
||||
-- 所有店铺的用户管理的全部权限
|
||||
-- 所有店铺的商品管理的查看权限,无新增编辑删除管理商品分类权限
|
||||
-- 所有店铺的店铺管理的全部权限
|
||||
-- 所有店铺的权限管理的全部权限
|
||||
-- 所有店铺的标签管理的查看权限无新增编辑删除权限
|
||||
-- 所有店铺的优惠券管理的查看权限
|
||||
-- 所有店铺的订单管理的查看权限
|
||||
INSERT INTO t_user_permission (user_id, permission_id, create_time, update_time, create_by)
|
||||
SELECT
|
||||
1 as user_id,
|
||||
p.id as permission_id,
|
||||
NOW() as create_time,
|
||||
NOW() as update_time,
|
||||
1 as create_by
|
||||
FROM t_permission p
|
||||
WHERE p.is_delete = 0
|
||||
AND p.permission_code IN (
|
||||
'home:view',
|
||||
'dashboard:view',
|
||||
'user:view',
|
||||
'user:create',
|
||||
'user:edit',
|
||||
'user:reset_password',
|
||||
'user:delete',
|
||||
'product:view',
|
||||
'shop:view',
|
||||
'shop:create',
|
||||
'shop:edit',
|
||||
'shop:delete',
|
||||
'shop:staff:manage',
|
||||
'permission:view',
|
||||
'permission:create',
|
||||
'permission:edit',
|
||||
'permission:delete',
|
||||
'permission:assign',
|
||||
'tag:view',
|
||||
'coupon:view',
|
||||
'order:view'
|
||||
);
|
||||
|
||||
-- 为美甲师(type=3)分配默认权限
|
||||
INSERT INTO t_user_permission (user_id, permission_id, create_time, update_time)
|
||||
SELECT
|
||||
u.id as user_id,
|
||||
p.id as permission_id,
|
||||
NOW() as create_time,
|
||||
NOW() as update_time
|
||||
FROM t_user u
|
||||
CROSS JOIN t_permission p
|
||||
WHERE u.type = 3
|
||||
AND p.is_delete = 0
|
||||
AND p.permission_code IN (
|
||||
'home:view',
|
||||
'user:view',
|
||||
'user:reset_password',
|
||||
'product:view',
|
||||
'product:create',
|
||||
'product:edit'
|
||||
);
|
||||
-- 注意:店长和美甲师的权限需要在系统中手动分配,因为需要关联具体的店铺
|
||||
-- 这里只初始化管理员的权限
|
||||
|
||||
use nailart;
|
||||
-- 优惠券信息表
|
||||
create table t_coupon
|
||||
(
|
||||
@@ -464,6 +461,7 @@ create table t_coupon
|
||||
start_time datetime not null comment '开始时间',
|
||||
end_time datetime not null comment '结束时间',
|
||||
status tinyint unsigned default 1 not null comment '状态:1-可用,2-已过期,3-已用完',
|
||||
shop_id bigint unsigned not null comment '所属店铺ID',
|
||||
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
|
||||
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
|
||||
is_delete tinyint unsigned default 0 null comment '逻辑删除:0-未删,1-已删',
|
||||
@@ -474,6 +472,9 @@ create table t_coupon
|
||||
create index idx_status
|
||||
on t_coupon (status) comment '按状态查询优惠券的索引';
|
||||
|
||||
create index idx_shop_id
|
||||
on t_coupon (shop_id) comment '按店铺查询优惠券的索引';
|
||||
|
||||
-- 用户优惠券关联表
|
||||
create table t_user_coupon
|
||||
(
|
||||
@@ -518,54 +519,6 @@ create index idx_coupon_id
|
||||
create index idx_tag_id
|
||||
on t_coupon_tag (tag_id) comment '按标签查询优惠券的索引';
|
||||
|
||||
-- 插入优惠券管理相关权限
|
||||
INSERT INTO t_permission (permission_code, permission_name, permission_group, description, create_time, update_time, is_delete) VALUES
|
||||
('coupon:view', '查看优惠券', '优惠券管理', '查看优惠券列表和详情', NOW(), NOW(), 0),
|
||||
('coupon:create', '新增优惠券', '优惠券管理', '新增优惠券', NOW(), NOW(), 0),
|
||||
('coupon:edit', '编辑优惠券', '优惠券管理', '编辑优惠券信息', NOW(), NOW(), 0),
|
||||
('coupon:delete', '删除优惠券', '优惠券管理', '删除优惠券', NOW(), NOW(), 0),
|
||||
('coupon:assign', '分配优惠券', '优惠券管理', '为用户分配优惠券', NOW(), NOW(), 0);
|
||||
|
||||
-- 为管理员(type=4)分配优惠券管理权限
|
||||
INSERT INTO t_user_permission (user_id, permission_id, create_time, update_time)
|
||||
SELECT
|
||||
u.id as user_id,
|
||||
p.id as permission_id,
|
||||
NOW() as create_time,
|
||||
NOW() as update_time
|
||||
FROM t_user u
|
||||
CROSS JOIN t_permission p
|
||||
WHERE u.type = 4
|
||||
AND p.is_delete = 0
|
||||
AND p.permission_code IN (
|
||||
'coupon:view',
|
||||
'coupon:create',
|
||||
'coupon:edit',
|
||||
'coupon:delete',
|
||||
'coupon:assign'
|
||||
);
|
||||
|
||||
-- 为店长(type=2)分配优惠券管理权限
|
||||
INSERT INTO t_user_permission (user_id, permission_id, create_time, update_time)
|
||||
SELECT
|
||||
u.id as user_id,
|
||||
p.id as permission_id,
|
||||
NOW() as create_time,
|
||||
NOW() as update_time
|
||||
FROM t_user u
|
||||
CROSS JOIN t_permission p
|
||||
WHERE u.type = 2
|
||||
AND p.is_delete = 0
|
||||
AND p.permission_code IN (
|
||||
'coupon:view',
|
||||
'coupon:create',
|
||||
'coupon:edit',
|
||||
'coupon:delete',
|
||||
'coupon:assign'
|
||||
);
|
||||
|
||||
|
||||
|
||||
-- 购物车表
|
||||
create table t_cart
|
||||
(
|
||||
@@ -623,47 +576,4 @@ create table t_order_item
|
||||
) comment '订单商品表';
|
||||
|
||||
create index idx_order_id
|
||||
on t_order_item (order_id) comment '按订单查询商品的索引';
|
||||
|
||||
-- 插入订单管理相关权限
|
||||
INSERT INTO t_permission (permission_code, permission_name, permission_group, description, create_time, update_time, is_delete) VALUES
|
||||
('order:view', '查看订单', '订单管理', '查看订单列表和详情', NOW(), NOW(), 0),
|
||||
('order:edit', '编辑订单', '订单管理', '编辑订单信息', NOW(), NOW(), 0),
|
||||
('order:delete', '删除订单', '订单管理', '删除订单', NOW(), NOW(), 0),
|
||||
('order:process', '处理订单', '订单管理', '处理订单状态', NOW(), NOW(), 0);
|
||||
|
||||
-- 为管理员(type=4)分配订单管理权限
|
||||
INSERT INTO t_user_permission (user_id, permission_id, create_time, update_time)
|
||||
SELECT
|
||||
u.id as user_id,
|
||||
p.id as permission_id,
|
||||
NOW() as create_time,
|
||||
NOW() as update_time
|
||||
FROM t_user u
|
||||
CROSS JOIN t_permission p
|
||||
WHERE u.type = 4
|
||||
AND p.is_delete = 0
|
||||
AND p.permission_code IN (
|
||||
'order:view',
|
||||
'order:edit',
|
||||
'order:delete',
|
||||
'order:process'
|
||||
);
|
||||
|
||||
-- 为店长(type=2)分配订单管理权限
|
||||
INSERT INTO t_user_permission (user_id, permission_id, create_time, update_time)
|
||||
SELECT
|
||||
u.id as user_id,
|
||||
p.id as permission_id,
|
||||
NOW() as create_time,
|
||||
NOW() as update_time
|
||||
FROM t_user u
|
||||
CROSS JOIN t_permission p
|
||||
WHERE u.type = 2
|
||||
AND p.is_delete = 0
|
||||
AND p.permission_code IN (
|
||||
'order:view',
|
||||
'order:edit',
|
||||
'order:delete',
|
||||
'order:process'
|
||||
);
|
||||
on t_order_item (order_id) comment '按订单查询商品的索引';
|
||||
Reference in New Issue
Block a user