This commit is contained in:
Jack 2025-06-27 16:43:55 +08:00
parent 4947025a25
commit 64e772a47c
2 changed files with 39 additions and 11 deletions

View File

@ -47,13 +47,17 @@ public class UserInfoService {
userStr = null; userStr = null;
} }
UserDto userDto;
if (StrUtil.isNotBlank(userStr)) { if (StrUtil.isNotBlank(userStr)) {
// JSON 字符串转换为 UserDto 对象 // JSON 字符串转换为 UserDto 对象
return JSONUtil.toBean(userStr, UserDto.class); userDto = JSONUtil.toBean(userStr, UserDto.class);
} else {
// 如果 userStr 为空尝试通过 token 获取用户信息
userDto = getUserByToken();
} }
// 如果 userStr 为空尝试通过 token 获取用户信息 log.info("用户信息:{}", userDto);
return getUserByToken(); return userDto;
} }
public Integer getUserId() { public Integer getUserId() {

View File

@ -150,15 +150,39 @@ public class ShopPageBaseController extends BaseControllerImpl {
@ApiOperation(value = "页面表-通过page_id删除", notes = "页面表-通过page_id删除") @ApiOperation(value = "页面表-通过page_id删除", notes = "页面表-通过page_id删除")
@RequestMapping(value = "/remove", method = RequestMethod.POST) @RequestMapping(value = "/remove", method = RequestMethod.POST)
public CommonResult remove(@RequestParam(name = "page_id") Long page_id) { public CommonResult remove(@RequestParam(name = "page_id") Long page_id) {
UserDto user = getCurrentUser(); try {
if (user == null || !user.isPlatform()) { UserDto user = getCurrentUser();
throw new ApiException(ResultCode.FORBIDDEN);
}
if (shopPageBaseService.remove(page_id)) { // 用户未登录禁止操作
return CommonResult.success(); if (user == null) {
} else { throw new ApiException(ResultCode.FORBIDDEN);
return CommonResult.failed(); }
// 非平台管理员只能删除自己店铺的页面
if (!user.isPlatform()) {
String storeId = user.getStore_id();
ShopPageBase shopPageBase = shopPageBaseService.getById(page_id);
// log.info("storeId:{}", storeId);
// log.info("shopPageBase:{}", shopPageBase);
// 页面不存在 当前用户无店铺信息 页面归属与当前店铺不符则禁止删除
if (shopPageBase == null || StrUtil.isBlank(storeId) || !storeId.equals(shopPageBase.getStore_id().toString())) {
throw new ApiException(ResultCode.FORBIDDEN);
}
}
// 执行删除操作
boolean isRemoved = shopPageBaseService.remove(page_id);
return isRemoved ? CommonResult.success() : CommonResult.failed();
} catch (ApiException e) {
// 已知业务异常直接抛出
log.warn("删除页面失败,参数:{}", page_id, e);
throw e;
} catch (Exception e) {
// 未知系统异常记录日志并返回友好提示
log.error("删除页面发生系统异常page_id: {}", page_id, e);
throw new ApiException(ResultCode.FAILED);
} }
} }