service位置调整
This commit is contained in:
parent
3b62eb6079
commit
259d015076
|
|
@ -0,0 +1,113 @@
|
|||
package com.czg.service.account.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import com.czg.account.dto.SysLoginDTO;
|
||||
import com.czg.account.entity.*;
|
||||
import com.czg.account.service.*;
|
||||
import com.czg.account.vo.LoginVO;
|
||||
import com.czg.config.RedisCst;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.RedisService;
|
||||
import com.czg.service.account.mapper.SysMenuMapper;
|
||||
import com.wf.captcha.SpecCaptcha;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
*/
|
||||
@Service
|
||||
public class AuthorizationServiceImpl implements AuthorizationService {
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
|
||||
@Resource
|
||||
private SysUserService sysUserService;
|
||||
@Resource
|
||||
private ShopStaffService shopStaffService;
|
||||
@Resource
|
||||
private ShopInfoService shopInfoService;
|
||||
@Resource
|
||||
private SysRoleService sysRoleService;
|
||||
@Resource
|
||||
private SysMenuMapper sysMenuMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public Object getCaptcha() {
|
||||
// 生成验证码(130x48,4位字符)
|
||||
SpecCaptcha captcha = new SpecCaptcha(130, 48, 4);
|
||||
|
||||
// 获取验证码文本
|
||||
String code = captcha.text();
|
||||
|
||||
// 生成唯一的验证码 ID
|
||||
String captchaKey = IdUtil.randomUUID();
|
||||
|
||||
redisService.set(RedisCst.LOGIN_CODE + captchaKey, code, 300);
|
||||
|
||||
// 返回 Base64 格式验证码
|
||||
return Map.of("code", captcha.toBase64(), "uuid", captchaKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
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("验证码错误");
|
||||
// }
|
||||
|
||||
SysUser user = sysUserService.queryChain().eq(SysUser::getAccount,loginDTO.username()).one();
|
||||
if (user == null) {
|
||||
throw new RuntimeException("账户不存在");
|
||||
}
|
||||
|
||||
String md5 = SecureUtil.md5(user.getId() + loginDTO.password());
|
||||
if (StrUtil.isBlank(user.getPassword()) || !user.getPassword().equals(md5)) {
|
||||
throw new RuntimeException("账户或密码错误");
|
||||
}
|
||||
|
||||
ShopInfo shopInfo;
|
||||
// 商户员工登录
|
||||
if (loginDTO.loginType() == 1) {
|
||||
ShopStaff shopStaff = shopStaffService.queryChain().eq(ShopStaff::getStatus, 1)
|
||||
.eq(ShopStaff::getIsManage, 1)
|
||||
.eq(ShopStaff::getId, user.getId()).one();
|
||||
if (shopStaff == null) {
|
||||
throw new RuntimeException("账户未启用");
|
||||
}
|
||||
|
||||
shopInfo = shopInfoService.getById(shopStaff.getShopId());
|
||||
}else {
|
||||
shopInfo = shopInfoService.getById(user.getId());
|
||||
}
|
||||
|
||||
if (shopInfo == null) {
|
||||
throw new RuntimeException("商户不存在");
|
||||
}
|
||||
// 过期时间校验
|
||||
if (shopInfo.getExpireTime() != null) {
|
||||
if ((DateUtil.date().toLocalDateTime().isAfter(shopInfo.getExpireTime()))) {
|
||||
throw new RuntimeException("店铺已到期,请联系区域经理续费");
|
||||
}
|
||||
}
|
||||
|
||||
StpKit.ADMIN.login(user.getId());
|
||||
StpKit.ADMIN.setAdmin(user.getIsAdmin());
|
||||
// 查询角色
|
||||
List<SysRole> roleList = sysRoleService.getByUserId(user.getId());
|
||||
List<String> roleNames = roleList.stream().map(SysRole::getName).collect(Collectors.toList());
|
||||
StpKit.ADMIN.addRoleList(roleNames);
|
||||
// 权限赋予
|
||||
List<String> promissionList = sysMenuMapper.selectByUserId(user.getId(), null).stream().map(SysMenu::getPermission).filter(StrUtil::isNotBlank).collect(Collectors.toList());
|
||||
StpKit.ADMIN.addPermissionList(promissionList);
|
||||
return new LoginVO(StpKit.ADMIN.getTokenInfo(), promissionList, loginDTO.loginType(), shopInfo);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
package com.czg.service.account.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.czg.account.dto.PageDTO;
|
||||
import com.czg.account.dto.register.MerchantRegisterDTO;
|
||||
import com.czg.account.entity.MerchantRegister;
|
||||
import com.czg.account.service.MerchantRegisterService;
|
||||
import com.czg.service.account.mapper.MerchantRegisterMapper;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* 激活码 服务层实现。
|
||||
*
|
||||
* @author Administrator
|
||||
* @since 2025-02-11
|
||||
*/
|
||||
@Service
|
||||
public class MerchantRegisterServiceImpl extends ServiceImpl<MerchantRegisterMapper, MerchantRegister> implements MerchantRegisterService {
|
||||
|
||||
@Override
|
||||
public Page<MerchantRegister> get(PageDTO pageDTO, Integer state, String startTime, String endTime) {
|
||||
QueryWrapper queryWrapper = new QueryWrapper();
|
||||
|
||||
if (state != null) {
|
||||
queryWrapper.eq(MerchantRegister::getStatus, state);
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(startTime)) {
|
||||
queryWrapper.ge(MerchantRegister::getCreateTime, DateUtil.parse(startTime).toLocalDateTime());
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(endTime)) {
|
||||
queryWrapper.le(MerchantRegister::getCreateTime, DateUtil.parse(endTime).toLocalDateTime());
|
||||
}
|
||||
|
||||
return page(new Page<>(pageDTO.page(), pageDTO.size()), queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean add(MerchantRegisterDTO merchantRegisterDTO) {
|
||||
ArrayList<MerchantRegister> registers = new ArrayList<>();
|
||||
for (int i = 0; i < merchantRegisterDTO.num(); i++) {
|
||||
MerchantRegister tbMerchantRegister = new MerchantRegister();
|
||||
tbMerchantRegister.setRegisterCode(IdUtil.simpleUUID());
|
||||
tbMerchantRegister.setStatus(0);
|
||||
tbMerchantRegister.setPeriodMonth(merchantRegisterDTO.periodMonth());
|
||||
registers.add(tbMerchantRegister);
|
||||
}
|
||||
return saveBatch(registers);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package com.czg.service.account.service.impl;
|
||||
|
||||
import com.czg.account.service.PermissionService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author zs
|
||||
*/
|
||||
@Service
|
||||
public class PermissionServiceImpl implements PermissionService {
|
||||
}
|
||||
|
|
@ -0,0 +1,107 @@
|
|||
package com.czg.service.account.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import com.czg.account.dto.PageDTO;
|
||||
import com.czg.account.dto.shopinfo.ShopInfoAddDTO;
|
||||
import com.czg.account.dto.shopinfo.ShopInfoEditDTO;
|
||||
import com.czg.account.entity.*;
|
||||
import com.czg.account.service.*;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.account.mapper.ShopInfoMapper;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
*/
|
||||
@Service
|
||||
public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> implements ShopInfoService {
|
||||
@Resource
|
||||
private SysUserService sysUserService;
|
||||
@Resource
|
||||
private SysUsersRolesService sysUsersRolesService;
|
||||
@Resource
|
||||
private SysRoleService sysRoleService;
|
||||
@Resource
|
||||
private MerchantRegisterService merchantRegisterService;
|
||||
|
||||
@Override
|
||||
public Page<ShopInfo> get(PageDTO pageDTO, String shopName, Integer status) {
|
||||
QueryWrapper queryWrapper = new QueryWrapper();
|
||||
if (StrUtil.isNotBlank(shopName)) {
|
||||
queryWrapper.like(ShopInfo::getShopName, shopName);
|
||||
}
|
||||
if (status != null) {
|
||||
queryWrapper.eq(ShopInfo::getStatus, status);
|
||||
}
|
||||
return page(new Page<>(pageDTO.page(), pageDTO.size()), queryWrapper);
|
||||
}
|
||||
|
||||
private void activateShop(ShopInfo shopInfo, String activateCode) {
|
||||
MerchantRegister merchantRegister = merchantRegisterService.queryChain().eq(MerchantRegister::getRegisterCode, activateCode).one();
|
||||
AssertUtil.isNull(merchantRegister, "激活码不存在");
|
||||
if (merchantRegister.getStatus() == 1) {
|
||||
throw new CzgException("激活码已使用");
|
||||
}
|
||||
shopInfo.setExpireTime(DateUtil.offsetMonth(DateUtil.date(), merchantRegister.getPeriodMonth()).toLocalDateTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean add(ShopInfoAddDTO shopInfoAddDTO) {
|
||||
long count = sysUserService.queryChain().eq(SysUser::getAccount, shopInfoAddDTO.getAccountName()).count();
|
||||
if (count > 0) {
|
||||
throw new CzgException("账户已存在");
|
||||
}
|
||||
|
||||
// 添加系统账号
|
||||
SysUser sysUser = new SysUser();
|
||||
sysUser.setAccount(shopInfoAddDTO.getAccountName());
|
||||
sysUser.setNickName(shopInfoAddDTO.getShopName());
|
||||
sysUser.setPhone(shopInfoAddDTO.getPhone());
|
||||
sysUser.setStauts(1);
|
||||
sysUser.setCreateUserId(StpKit.ADMIN.getLoginIdAsLong());
|
||||
sysUserService.save(sysUser);
|
||||
sysUser.setPassword(SecureUtil.md5(sysUser.getId() + shopInfoAddDTO.getAccountPwd()));
|
||||
sysUserService.updateById(sysUser);
|
||||
|
||||
// 绑定角色
|
||||
long roleCount = sysRoleService.queryChain().eq(SysRole::getId, shopInfoAddDTO.getRoleId()).count();
|
||||
if (roleCount == 0) {
|
||||
throw new CzgException("角色不存在");
|
||||
}
|
||||
SysUsersRoles usersRoles = new SysUsersRoles();
|
||||
usersRoles.setUserId(sysUser.getId());
|
||||
usersRoles.setRoleId(shopInfoAddDTO.getRoleId());
|
||||
sysUsersRolesService.save(usersRoles);
|
||||
|
||||
// 保存店铺信息
|
||||
ShopInfo shopInfo = BeanUtil.copyProperties(shopInfoAddDTO, ShopInfo.class);
|
||||
shopInfo.setId(sysUser.getId());
|
||||
//设置激活码
|
||||
shopInfo.setStatus(1);
|
||||
shopInfo.setProfiles("release");
|
||||
activateShop(shopInfo, shopInfoAddDTO.getActivateCode());
|
||||
return save(shopInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean edit(ShopInfoEditDTO shopInfoEditDTO) {
|
||||
ShopInfo shopInfo = getById(StpKit.ADMIN.getLoginIdAsLong());
|
||||
BeanUtil.copyProperties(shopInfoEditDTO, shopInfo);
|
||||
|
||||
if (shopInfoEditDTO.getActivateCode() != null) {
|
||||
activateShop(shopInfo, shopInfoEditDTO.getActivateCode());
|
||||
}
|
||||
return updateById(shopInfo);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package com.czg.service.account.service.impl;
|
||||
|
||||
import com.czg.account.entity.ShopStaff;
|
||||
import com.czg.account.service.ShopStaffService;
|
||||
import com.czg.service.account.mapper.ShopStaffMapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 店铺员工 服务层实现。
|
||||
*
|
||||
* @author Administrator
|
||||
* @since 2025-02-10
|
||||
*/
|
||||
@Service
|
||||
public class ShopStaffServiceImpl extends ServiceImpl<ShopStaffMapper, ShopStaff> implements ShopStaffService {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package com.czg.service.account.service.impl;
|
||||
|
||||
import com.czg.account.entity.ShopUser;
|
||||
import com.czg.account.service.ShopUserService;
|
||||
import com.czg.service.account.mapper.ShopUserMapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 商户储值会员 服务层实现。
|
||||
*
|
||||
* @author Administrator
|
||||
* @since 2025-02-08
|
||||
*/
|
||||
@Service
|
||||
public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> implements ShopUserService {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
package com.czg.service.account.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.czg.account.entity.SysMenu;
|
||||
import com.czg.account.service.SysMenuService;
|
||||
import com.czg.account.vo.MenuVO;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.account.mapper.SysMenuMapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统菜单 服务层实现。
|
||||
*
|
||||
* @author Administrator
|
||||
* @since 2025-02-10
|
||||
*/
|
||||
@Service
|
||||
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService {
|
||||
|
||||
@Override
|
||||
public Object getMenu() {
|
||||
long sysUserId = StpKit.ADMIN.getLoginIdAsLong();
|
||||
List<SysMenu> allMenus = mapper.selectByUserId(sysUserId, null);
|
||||
List<MenuVO> rootMenus = new ArrayList<>();
|
||||
List<MenuVO> allMenuVos = new ArrayList<>();
|
||||
|
||||
// 分类菜单和按钮,并处理按钮的权限
|
||||
for (SysMenu menu : allMenus) {
|
||||
MenuVO menuVO = BeanUtil.copyProperties(menu, MenuVO.class);
|
||||
|
||||
// 如果是按钮类型,添加权限标识集合到 permissions
|
||||
if (menu.getType() == 2) {
|
||||
// 获取按钮的权限标识集合
|
||||
menuVO.setPermissions(getPermissionsForMenu(menu));
|
||||
}
|
||||
|
||||
// 分类根菜单与所有菜单
|
||||
if (menu.getPid() == null || menu.getPid() == 0) {
|
||||
rootMenus.add(menuVO);
|
||||
}
|
||||
allMenuVos.add(menuVO);
|
||||
}
|
||||
|
||||
// 给每个根菜单设置子菜单,同时把按钮权限标识加入到 permissions 中
|
||||
for (MenuVO rootMenu : rootMenus) {
|
||||
buildSubMenus(rootMenu, allMenuVos);
|
||||
}
|
||||
|
||||
return rootMenus;
|
||||
}
|
||||
|
||||
// 递归构建子菜单,按钮放在 permissions 中
|
||||
private void buildSubMenus(MenuVO parentMenu, List<MenuVO> allMenus) {
|
||||
List<MenuVO> children = new ArrayList<>();
|
||||
// 存储该菜单的按钮权限
|
||||
List<String> permissions = new ArrayList<>();
|
||||
|
||||
for (MenuVO menu : allMenus) {
|
||||
// 如果是菜单且父级菜单ID匹配,加入子菜单
|
||||
if (menu.getPid() != null && menu.getPid().equals(parentMenu.getMenuId()) && menu.getType() != 2) {
|
||||
children.add(menu);
|
||||
// 递归查找子菜单
|
||||
buildSubMenus(menu, allMenus);
|
||||
}
|
||||
// 如果是按钮类型,直接放到权限集合中
|
||||
if (menu.getPid() != null && menu.getPid().equals(parentMenu.getMenuId()) && menu.getType() == 2) {
|
||||
// 将按钮的权限标识加入权限列表
|
||||
permissions.addAll(getPermissionsForMenu(menu));
|
||||
}
|
||||
}
|
||||
|
||||
// 设置当前菜单的子菜单和权限
|
||||
parentMenu.setChildren(children);
|
||||
// 将按钮权限标识添加到菜单的权限中
|
||||
parentMenu.setPermissions(permissions);
|
||||
}
|
||||
|
||||
// 根据菜单获取权限标识(这里假设你有权限标识的获取逻辑)
|
||||
private List<String> getPermissionsForMenu(SysMenu menu) {
|
||||
List<String> permissions = new ArrayList<>();
|
||||
// 你可以根据需求从数据库或其他地方获取权限标识
|
||||
// 例如,假设菜单表中有权限字段
|
||||
if (menu.getPermission() != null) {
|
||||
String[] permissionArray = menu.getPermission().split(",");
|
||||
permissions.addAll(Arrays.asList(permissionArray));
|
||||
}
|
||||
return permissions;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,126 @@
|
|||
package com.czg.service.account.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.czg.account.dto.PageDTO;
|
||||
import com.czg.account.dto.role.RoleAddDTO;
|
||||
import com.czg.account.dto.role.RoleEditDTO;
|
||||
import com.czg.account.entity.SysMenu;
|
||||
import com.czg.account.entity.SysRole;
|
||||
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.sa.StpKit;
|
||||
import com.czg.service.account.mapper.SysRoleMapper;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.mybatisflex.core.query.QueryMethods.column;
|
||||
|
||||
/**
|
||||
* 角色表 服务层实现。
|
||||
*
|
||||
* @author Administrator
|
||||
* @since 2025-02-08
|
||||
*/
|
||||
@Service
|
||||
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements SysRoleService {
|
||||
@Resource
|
||||
private SysMenuService sysMenuService;
|
||||
@Resource
|
||||
private SysRolesMenusService sysRolesMenusService;
|
||||
|
||||
@Override
|
||||
public List<SysRole> getByUserId(Long id) {
|
||||
return mapper.selectByUserId(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<SysRole> getList(PageDTO pageDTO, String key, String startTime, String endTime) {
|
||||
QueryWrapper queryWrapper = new QueryWrapper();
|
||||
if (!StpKit.ADMIN.isAdmin()) {
|
||||
queryWrapper.eq(SysRole::getCreateUserId, StpKit.ADMIN.getLoginIdAsLong());
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(key)) {
|
||||
queryWrapper.and(column(SysRole::getName).like(key).or(column(SysRole::getDescription).like(key)));
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(startTime)) {
|
||||
queryWrapper.ge(SysRole::getCreateTime, DateUtil.parse(startTime));
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(endTime)) {
|
||||
queryWrapper.le(SysRole::getCreateTime, DateUtil.parse(endTime));
|
||||
}
|
||||
|
||||
return page(new Page<>(pageDTO.page(), pageDTO.size()), queryWrapper);
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
ArrayList<SysRolesMenus> rolesMenus = new ArrayList<>();
|
||||
for (Long id : menuIds) {
|
||||
rolesMenus.add(new SysRolesMenus(id, roleId));
|
||||
}
|
||||
return sysRolesMenusService.saveBatch(rolesMenus);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean add(RoleAddDTO roleAddDTO) {
|
||||
long roleCount = queryChain().eq(SysRole::getName, roleAddDTO.name()).count();
|
||||
if (roleCount > 0) {
|
||||
throw new RuntimeException("此角色名称已存在");
|
||||
}
|
||||
|
||||
SysRole sysRole = new SysRole();
|
||||
sysRole.setName(roleAddDTO.name());
|
||||
sysRole.setLevel(roleAddDTO.level());
|
||||
sysRole.setDescription(roleAddDTO.description());
|
||||
sysRole.setShopId(StpKit.ADMIN.getLoginIdAsLong());
|
||||
sysRole.setCreateUserId(StpKit.ADMIN.getLoginIdAsLong());
|
||||
sysRole.setCreateTime(DateUtil.date().toLocalDateTime());
|
||||
boolean save = save(sysRole);
|
||||
if (save) {
|
||||
return addMenu(sysRole.getId(), roleAddDTO.menuIdList());
|
||||
}
|
||||
|
||||
throw new RuntimeException("保存失败");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
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("角色不存在");
|
||||
}
|
||||
|
||||
long roleCount = queryChain().eq(SysRole::getName, roleEditDTO.getName()).count();
|
||||
if (roleCount > 0) {
|
||||
throw new RuntimeException("此角色名称已存在");
|
||||
}
|
||||
|
||||
BeanUtil.copyProperties(roleEditDTO, role);
|
||||
boolean b = updateById(role);
|
||||
if (b) {
|
||||
sysRolesMenusService.updateChain().eq(SysRolesMenus::getRoleId, role.getId()).remove();
|
||||
return addMenu(role.getId(), roleEditDTO.getMenuIdList());
|
||||
}
|
||||
throw new RuntimeException("保存失败");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package com.czg.service.account.service.impl;
|
||||
|
||||
import com.czg.account.entity.SysRolesMenus;
|
||||
import com.czg.account.service.SysRolesMenusService;
|
||||
import com.czg.service.account.mapper.SysRolesMenusMapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 角色菜单关联 服务层实现。
|
||||
*
|
||||
* @author Administrator
|
||||
* @since 2025-02-10
|
||||
*/
|
||||
@Service
|
||||
public class SysRolesMenusServiceImpl extends ServiceImpl<SysRolesMenusMapper, SysRolesMenus> implements SysRolesMenusService {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package com.czg.service.account.service.impl;
|
||||
|
||||
import com.czg.account.entity.SysUser;
|
||||
import com.czg.account.service.SysUserService;
|
||||
import com.czg.service.account.mapper.SysUserMapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 系统用户 服务层实现。
|
||||
*
|
||||
* @author Administrator
|
||||
* @since 2025-02-08
|
||||
*/
|
||||
@Service
|
||||
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package com.czg.service.account.service.impl;
|
||||
|
||||
import com.czg.account.entity.SysUsersRoles;
|
||||
import com.czg.account.service.SysUsersRolesService;
|
||||
import com.czg.service.account.mapper.SysUsersRolesMapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 用户角色关联 服务层实现。
|
||||
*
|
||||
* @author Administrator
|
||||
* @since 2025-02-10
|
||||
*/
|
||||
@Service
|
||||
public class SysUsersRolesServiceImpl extends ServiceImpl<SysUsersRolesMapper, SysUsersRoles> implements SysUsersRolesService {
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue