增加自定义异常处理

店铺管理接口
This commit is contained in:
张松
2025-02-12 10:16:35 +08:00
parent d1a9383d34
commit 9057f5eadb
9 changed files with 323 additions and 27 deletions

View File

@@ -9,6 +9,8 @@ import com.czg.account.entity.*;
import com.czg.account.service.*;
import com.czg.account.vo.LoginVO;
import com.czg.config.RedisCst;
import com.czg.exception.ApiNotPrintException;
import com.czg.exception.CzgException;
import com.czg.sa.StpKit;
import com.czg.service.RedisService;
import com.czg.service.account.mapper.SysMenuMapper;
@@ -61,17 +63,17 @@ public class AuthorizationServiceImpl implements AuthorizationService {
public LoginVO login(SysLoginDTO loginDTO) {
// Object code = redisService.get(RedisCst.LOGIN_CODE + loginDTO.uuid());
// if (!"666666".equals(loginDTO.code()) && code == null || !code.equals(loginDTO.code())) {
// throw new RuntimeException("验证码错误");
// throw new ApiNotPrintException("验证码错误");
// }
SysUser user = sysUserService.queryChain().eq(SysUser::getAccount,loginDTO.username()).one();
if (user == null) {
throw new RuntimeException("账户不存在");
throw new ApiNotPrintException("账户不存在");
}
String md5 = SecureUtil.md5(user.getId() + loginDTO.password());
if (StrUtil.isBlank(user.getPassword()) || !user.getPassword().equals(md5)) {
throw new RuntimeException("账户或密码错误");
throw new ApiNotPrintException("账户或密码错误");
}
ShopInfo shopInfo;
@@ -81,7 +83,7 @@ public class AuthorizationServiceImpl implements AuthorizationService {
.eq(ShopStaff::getIsManage, 1)
.eq(ShopStaff::getId, user.getId()).one();
if (shopStaff == null) {
throw new RuntimeException("账户未启用");
throw new ApiNotPrintException("账户未启用");
}
shopInfo = shopInfoService.getById(shopStaff.getShopId());
@@ -90,12 +92,12 @@ public class AuthorizationServiceImpl implements AuthorizationService {
}
if (shopInfo == null) {
throw new RuntimeException("商户不存在");
throw new ApiNotPrintException("商户不存在");
}
// 过期时间校验
if (shopInfo.getExpireTime() != null) {
if ((DateUtil.date().toLocalDateTime().isAfter(shopInfo.getExpireTime()))) {
throw new RuntimeException("店铺已到期,请联系区域经理续费");
throw new ApiNotPrintException("店铺已到期,请联系区域经理续费");
}
}

View File

@@ -96,7 +96,15 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
@Override
public Boolean edit(ShopInfoEditDTO shopInfoEditDTO) {
ShopInfo shopInfo = getById(StpKit.ADMIN.getLoginIdAsLong());
ShopInfo shopInfo;
if (!StpKit.ADMIN.isAdmin()) {
shopInfo = queryChain().eq(ShopInfo::getId, StpKit.ADMIN.getLoginIdAsLong()).one();
}else {
shopInfo = getById(StpKit.ADMIN.getLoginIdAsLong());
}
if (shopInfo == null) {
throw new CzgException("店铺不存在");
}
BeanUtil.copyProperties(shopInfoEditDTO, shopInfo);
if (shopInfoEditDTO.getActivateCode() != null) {
@@ -104,4 +112,9 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
}
return updateById(shopInfo);
}
@Override
public ShopInfo detail() {
return queryChain().eq(ShopInfo::getId, StpKit.ADMIN.getLoginIdAsLong()).one();
}
}

View File

@@ -12,6 +12,7 @@ import com.czg.account.entity.SysRolesMenus;
import com.czg.account.service.SysMenuService;
import com.czg.account.service.SysRoleService;
import com.czg.account.service.SysRolesMenusService;
import com.czg.exception.ApiNotPrintException;
import com.czg.sa.StpKit;
import com.czg.service.account.mapper.SysRoleMapper;
import com.mybatisflex.core.paginate.Page;
@@ -69,7 +70,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> imp
public boolean addMenu(Long roleId, List<Long> menuIds) {
long count = sysMenuService.queryChain().in(SysMenu::getMenuId, menuIds).count();
if (count != menuIds.size()) {
throw new RuntimeException("菜单id包含错误id");
throw new ApiNotPrintException("菜单id包含错误id");
}
ArrayList<SysRolesMenus> rolesMenus = new ArrayList<>();
@@ -84,7 +85,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> imp
public Boolean add(RoleAddDTO roleAddDTO) {
long roleCount = queryChain().eq(SysRole::getName, roleAddDTO.name()).count();
if (roleCount > 0) {
throw new RuntimeException("此角色名称已存在");
throw new ApiNotPrintException("此角色名称已存在");
}
SysRole sysRole = new SysRole();
@@ -99,7 +100,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> imp
return addMenu(sysRole.getId(), roleAddDTO.menuIdList());
}
throw new RuntimeException("保存失败");
throw new ApiNotPrintException("保存失败");
}
@Override
@@ -107,12 +108,12 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> imp
public Boolean edit(RoleEditDTO roleEditDTO) {
SysRole role = queryChain().eq(SysRole::getId, roleEditDTO.getId()).eq(SysRole::getCreateUserId, StpKit.ADMIN.getLoginIdAsLong()).one();
if (role == null) {
throw new RuntimeException("角色不存在");
throw new ApiNotPrintException("角色不存在");
}
long roleCount = queryChain().eq(SysRole::getName, roleEditDTO.getName()).count();
if (roleCount > 0) {
throw new RuntimeException("此角色名称已存在");
throw new ApiNotPrintException("此角色名称已存在");
}
BeanUtil.copyProperties(roleEditDTO, role);
@@ -121,6 +122,6 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> imp
sysRolesMenusService.updateChain().eq(SysRolesMenus::getRoleId, role.getId()).remove();
return addMenu(role.getId(), roleEditDTO.getMenuIdList());
}
throw new RuntimeException("保存失败");
throw new ApiNotPrintException("保存失败");
}
}