商城角色定制新增,修改,删除,修改状态

This commit is contained in:
DB 2023-10-19 22:46:14 +08:00
parent 9eb8988d9c
commit 3d38a89e7a
9 changed files with 247 additions and 44 deletions

View File

@ -0,0 +1,83 @@
package com.cpop.mall.business.bo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;
/**
* @author DB
* @Description:
* @create 2023-10-19 22:23
*/
@Data
@Accessors(chain = true)
@ApiModel(value = "商城Role对象", description = "角色表")
public class MallRoleBo implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@ApiModelProperty("主键")
private String id;
/**
* 角色id
*/
@ApiModelProperty("角色id")
private String roleId;
/**
* 角色名称
*/
@NotBlank(message = "角色名称不能为空")
@ApiModelProperty("角色名称")
private String roleName;
/**
* 角色值
*/
@NotBlank(message = "角色值不能为空")
@ApiModelProperty("角色值")
private String roleValue;
/**
* 状态
*/
@NotNull(message = "状态不能为空")
@ApiModelProperty("状态")
private Boolean status;
/**
* 备注
*/
@ApiModelProperty("备注")
private String remark;
/**
* 排序
*/
@NotNull(message = "排序不能为空")
@ApiModelProperty("排序")
private Integer orderNo;
/**
* 菜单集合
*/
@ApiModelProperty("菜单集合")
private List<String> menuIds;
/**
* 品牌id
*/
@NotBlank(message = "品牌id不能为空")
@ApiModelProperty(value = "品牌id",required = true)
private String brandId;
}

View File

@ -0,0 +1,33 @@
package com.cpop.mall.business.bo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* @author DB
* @Description:
* @create 2023-10-19 22:21
*/
@Data
@Accessors(chain = true)
@ApiModel(value = "商城Role分页对象")
public class MallRolePageBo implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 角色名称
*/
@ApiModelProperty("角色名称")
private String roleName;
/**
* 状态
*/
@ApiModelProperty("状态")
private Boolean status;
}

View File

@ -1,16 +1,13 @@
package com.cpop.mall.business.controller;
import com.cpop.core.annontation.OperationLog;
import com.cpop.core.base.R;
import com.cpop.core.base.enums.OperationLogEnum;
import com.cpop.mall.business.bo.MallRoleBo;
import com.cpop.mall.business.bo.MallRolePageBo;
import com.cpop.mall.business.service.RoleBrandService;
import com.cpop.mall.business.vo.MallRolePageVo;
import com.cpop.system.business.bo.MenuListBo;
import com.cpop.system.business.bo.RoleBo;
import com.cpop.system.business.bo.RolePageBo;
import com.cpop.system.business.bo.RoleStatusBo;
import com.cpop.system.business.service.MenuService;
import com.cpop.system.business.service.RoleService;
import com.cpop.system.business.vo.MenuVo;
import com.mybatisflex.core.paginate.Page;
import io.swagger.annotations.Api;
@ -35,9 +32,6 @@ public class MallRoleController {
@Autowired
private RoleBrandService roleBrandService;
@Autowired
private RoleService roleService;
@Autowired
private MenuService menuService;
@ -51,7 +45,7 @@ public class MallRoleController {
@PreAuthorize("@aps.hasPermission('system:role:list')")
@ApiOperation("查询商城角色分页列表")
@GetMapping("/getMallRolePageList")
public R<Page<MallRolePageVo>> getMallRolePageList(RolePageBo bo) {
public R<Page<MallRolePageVo>> getMallRolePageList(MallRolePageBo bo) {
Page<MallRolePageVo> pageVo = roleBrandService.getMallRolePageList(bo);
return R.ok(pageVo);
}
@ -64,10 +58,9 @@ public class MallRoleController {
* @return: com.cpop.core.base.R<java.lang.Void>
*/
@PreAuthorize("@aps.hasPermission('system:role:insert')")
@OperationLog(operationLogEnumType = OperationLogEnum.INSERT_OAM_ROLE)
@ApiOperation("新增商城角色")
@PostMapping("/insertMallRole")
public R<Void> insertMallRole(@RequestBody @Validated RoleBo bo) {
public R<Void> insertMallRole(@RequestBody @Validated MallRoleBo bo) {
roleBrandService.insertMallRole(bo);
return R.ok();
}
@ -94,23 +87,25 @@ public class MallRoleController {
* @return com.jambox.core.base.R<java.lang.Void>
*/
@PreAuthorize("@aps.hasPermission('system:role:update')")
@OperationLog(operationLogEnumType = OperationLogEnum.UPDATE_OAM_ROLE)
@ApiOperation("修改商城角色")
@PutMapping("/updateSysRole")
public R<Void> updateSysRole(@RequestBody @Validated RoleBo bo) {
roleService.updateSysRole(bo);
@PutMapping("/updateMallRole")
public R<Void> updateMallRole(@RequestBody @Validated MallRoleBo bo) {
roleBrandService.updateMallRole(bo);
return R.ok();
}
/**
* 删除系统角色表
* @Description: 删除商城角色
* @param id 主键
* @return R<Void>
* @Author DB
* @Date: 2023/10/19 22:34
*/
@PreAuthorize("@aps.hasPermission('system:role:remove')")
@OperationLog(operationLogEnumType = OperationLogEnum.REMOVE_OAM_ROLE)
@ApiOperation("删除商城角色表")
@DeleteMapping("/removeSysRole/{id}")
public R<Void> removeSysRole(@PathVariable String id) {
roleService.removeSysRole(id);
@ApiOperation("删除商城角色")
@DeleteMapping("/removeMallRole/{id}")
public R<Void> removeMallRole(@PathVariable String id) {
roleBrandService.removeMallRole(id);
return R.ok();
}
@ -122,11 +117,10 @@ public class MallRoleController {
* @Date: 2023/5/9 14:13
**/
@PreAuthorize("@aps.hasPermission('system:role:update')")
@OperationLog(operationLogEnumType = OperationLogEnum.UPDATE_OAM_ROLE)
@ApiOperation("设置商城角色状态")
@PutMapping("/setSysRoleStatus")
public R<Void> setSysRoleStatus(@RequestBody @Validated RoleStatusBo bo) {
roleService.setSysRoleStatus(bo);
@PutMapping("/setMallRoleStatus")
public R<Void> setMallRoleStatus(@RequestBody @Validated RoleStatusBo bo) {
roleBrandService.setMallRoleStatus(bo);
return R.ok();
}
}

View File

@ -1,9 +1,10 @@
package com.cpop.mall.business.service;
import com.cpop.mall.business.bo.MallRoleBo;
import com.cpop.mall.business.bo.MallRolePageBo;
import com.cpop.mall.business.entity.RoleBrand;
import com.cpop.mall.business.vo.MallRolePageVo;
import com.cpop.system.business.bo.RoleBo;
import com.cpop.system.business.bo.RolePageBo;
import com.cpop.system.business.bo.RoleStatusBo;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.service.IService;
@ -22,7 +23,7 @@ public interface RoleBrandService extends IService<RoleBrand> {
* @param bo 请求参数
* @return R<PageVo<MallRolePageVo>>
*/
Page<MallRolePageVo> getMallRolePageList(RolePageBo bo);
Page<MallRolePageVo> getMallRolePageList(MallRolePageBo bo);
/**
* @descriptions 新增角色
@ -31,5 +32,32 @@ public interface RoleBrandService extends IService<RoleBrand> {
* @param bo 请求参数
* @return: com.cpop.core.base.R<java.lang.Void>
*/
void insertMallRole(RoleBo bo);
void insertMallRole(MallRoleBo bo);
/**
* @descriptions 修改角色
* @author DB
* @date 2023/09/10 17:45
* @param bo 请求参数
* @return com.jambox.core.base.R<java.lang.Void>
*/
void updateMallRole(MallRoleBo bo);
/**
* @Description: 删除商城角色
* @param id 主键
* @return
* @Author DB
* @Date: 2023/10/19 22:34
*/
void removeMallRole(String id);
/**
* @Description: 设置角色状态
* @param bo 请求参数
* @return: R<Void>
* @Author: DB
* @Date: 2023/5/9 14:13
**/
void setMallRoleStatus(RoleStatusBo bo);
}

View File

@ -6,12 +6,13 @@ import com.cpop.core.base.entity.PageDomain;
import com.cpop.core.utils.SecurityUtils;
import com.cpop.core.utils.SpringUtils;
import com.cpop.core.utils.sql.SqlUtils;
import com.cpop.mall.business.bo.MallRoleBo;
import com.cpop.mall.business.bo.MallRolePageBo;
import com.cpop.mall.business.entity.RoleBrand;
import com.cpop.mall.business.mapper.RoleBrandMapper;
import com.cpop.mall.business.service.RoleBrandService;
import com.cpop.mall.business.vo.MallRolePageVo;
import com.cpop.system.business.bo.RoleBo;
import com.cpop.system.business.bo.RolePageBo;
import com.cpop.system.business.bo.RoleStatusBo;
import com.cpop.system.business.entity.Role;
import com.cpop.system.business.entity.RoleMenu;
import com.cpop.system.business.service.RoleMenuService;
@ -50,7 +51,7 @@ public class RoleBrandServiceImpl extends ServiceImpl<RoleBrandMapper, RoleBrand
* @return R<PageVo<SysRolePageVo>>
*/
@Override
public Page<MallRolePageVo> getMallRolePageList(RolePageBo bo) {
public Page<MallRolePageVo> getMallRolePageList(MallRolePageBo bo) {
//获取当前登录用户信息
JSONObject staffInfo = SecurityUtils.getInstance().getLoginStaffInfo();
//获取分页参数
@ -85,7 +86,7 @@ public class RoleBrandServiceImpl extends ServiceImpl<RoleBrandMapper, RoleBrand
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void insertMallRole(RoleBo bo) {
public void insertMallRole(MallRoleBo bo) {
Role role = BeanUtils.mapToClass(bo, Role.class);
SpringUtils.getBean(RoleService.class).save(role);
//将菜单信息录入中间表
@ -105,4 +106,70 @@ public class RoleBrandServiceImpl extends ServiceImpl<RoleBrandMapper, RoleBrand
.setBrandId(bo.getBrandId());
this.save(roleBrand);
}
/**
* @descriptions 修改角色
* @author DB
* @date 2023/09/10 17:45
* @param bo 请求参数
* @return com.jambox.core.base.R<java.lang.Void>
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void updateMallRole(MallRoleBo bo) {
Role entity = new Role();
BeanUtils.copyBeanProp(entity, bo);
entity.setId(bo.getRoleId());
SpringUtils.getBean(RoleService.class).updateById(entity);
//将菜单信息录入中间表
if (!bo.getMenuIds().isEmpty()) {
//先删后存
RoleMenuService sysRoleMenuService = SpringUtils.getBean(RoleMenuService.class);
sysRoleMenuService.remove(QueryWrapper.create()
.where(ROLE_MENU.ROLE_ID.eq(entity.getId())));
List<RoleMenu> roleMenus = new ArrayList<>();
bo.getMenuIds().forEach(item -> {
RoleMenu roleMenu = new RoleMenu();
roleMenu.setMenuId(item);
roleMenu.setRoleId(entity.getId());
roleMenus.add(roleMenu);
});
sysRoleMenuService.saveBatch(roleMenus);
}
}
/**
* @Description: 删除商城角色
* @param id 主键
* @return
* @Author DB
* @Date: 2023/10/19 22:34
*/
@Override
public void removeMallRole(String id) {
//获取中间表
RoleBrand roleBrand = this.queryChain().where(ROLE_BRAND.ID.eq(id)).one();
//删除角色
SpringUtils.getBean(RoleService.class).removeById(roleBrand.getRoleId());
//删除相关联菜单
SpringUtils.getBean(RoleMenuService.class).remove(QueryWrapper.create().where(ROLE_MENU.ROLE_ID.eq(roleBrand.getRoleId())));
this.removeById(id);
}
/**
* @Description: 设置角色状态
* @param bo 请求参数
* @return: R<Void>
* @Author: DB
* @Date: 2023/5/9 14:13
**/
@Override
public void setMallRoleStatus(RoleStatusBo bo) {
//获取中间表
RoleBrand roleBrand = this.queryChain().where(ROLE_BRAND.ID.eq(bo.getId())).one();
SpringUtils.getBean(RoleService.class).updateChain()
.set(ROLE.STATUS, bo.getStatus())
.where(ROLE.ID.eq(roleBrand.getRoleId()))
.update();
}
}

View File

@ -69,10 +69,4 @@ public class RoleBo implements Serializable {
@ApiModelProperty("菜单集合")
private List<String> menuIds;
/**
* 当前品牌id
*/
@ApiModelProperty("菜单集合")
private String brandId;
}

View File

@ -60,4 +60,5 @@ public interface RoleService extends IService<Role> {
* @return: void
*/
void setSysRoleStatus(RoleStatusBo bo);
}

View File

@ -5,18 +5,16 @@ import com.cpop.common.constant.Constants;
import com.cpop.common.utils.StringUtils;
import com.cpop.common.utils.bean.BeanUtils;
import com.cpop.core.base.entity.LoginUser;
import com.cpop.core.base.entity.loginInfo.OamStaffLoginInfo;
import com.cpop.core.utils.SecurityUtils;
import com.cpop.core.utils.SpringUtils;
import com.cpop.system.business.bo.MenuBo;
import com.cpop.system.business.bo.MenuListBo;
import com.cpop.system.business.entity.Menu;
import com.cpop.system.business.mapper.MenuMapper;
import com.cpop.system.business.service.MenuService;
import com.cpop.system.business.vo.MenuRouteVo;
import com.cpop.system.business.vo.MenuVo;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.cpop.system.business.entity.Menu;
import com.cpop.system.business.mapper.MenuMapper;
import com.cpop.system.business.service.MenuService;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@ -85,6 +83,7 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
.and(MENU.TITLE.like(bo.getTitle()))
//构建公共菜单与特有菜单
.and(MENU.USER_TYPE.in("COMMON", user.getUserType()))
.and(MENU.STATUS.eq(true))
.orderBy(MENU.ORDER_NO.asc()), MenuVo.class));
}

View File

@ -154,4 +154,8 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
public void setSysRoleStatus(RoleStatusBo bo) {
this.updateById(BeanUtils.mapToClass(bo, Role.class));
}
}