商城角色定制查询

This commit is contained in:
DB 2023-10-19 21:51:22 +08:00
parent cf8a3d3f84
commit 9eb8988d9c
11 changed files with 112 additions and 35 deletions

View File

@ -6,7 +6,7 @@ import com.cpop.core.filter.JwtAuthenticationFilter;
import com.cpop.core.filter.RepeatableFilter;
import com.cpop.core.gateway.miniProgram.MiniProgramAuthenticationFilter;
import com.cpop.core.gateway.miniProgram.MiniProgramAuthenticationProvider;
import com.cpop.core.gateway.oam.OamUsernamePasswordAuthenticationFilter;
import com.cpop.core.gateway.oam.CpopUsernamePasswordAuthenticationFilter;
import com.cpop.core.gateway.sys.SysAuthenticationFilter;
import com.cpop.core.gateway.sys.SysAuthenticationProvider;
import com.cpop.core.handler.*;
@ -126,8 +126,8 @@ public class SecurityConfig implements WebMvcConfigurer {
* @return OamUsernamePasswordAuthenticationFilter oma管理器
*/
@Bean
public OamUsernamePasswordAuthenticationFilter oamLoginFilter(AuthenticationManager authenticationManager) {
OamUsernamePasswordAuthenticationFilter loginFilter = new OamUsernamePasswordAuthenticationFilter();
public CpopUsernamePasswordAuthenticationFilter oamLoginFilter(AuthenticationManager authenticationManager) {
CpopUsernamePasswordAuthenticationFilter loginFilter = new CpopUsernamePasswordAuthenticationFilter();
loginFilter.setFilterProcessesUrl("/login");
loginFilter.setAuthenticationManager(authenticationManager);
loginFilter.setAuthenticationSuccessHandler(loginSuccessHandler);

View File

@ -23,7 +23,7 @@ public class MiniProgramAuthenticationFilter extends AbstractAuthenticationProce
public MiniProgramAuthenticationFilter() {
super(new AntPathRequestMatcher("/miniProgramLogin", "POST"));
super(new AntPathRequestMatcher("/miniLogin", "POST"));
}
@Override

View File

@ -16,9 +16,9 @@ import java.util.Map;
/**
* @author DB
* @create 2023-04-05 17:38
* OAM管理系统为基础认证系统,使用默认的过滤认证方式
* Cpop管理系统为基础认证系统,使用默认的过滤认证方式
*/
public class OamUsernamePasswordAuthenticationFilter extends UsernamePasswordAuthenticationFilter {
public class CpopUsernamePasswordAuthenticationFilter extends UsernamePasswordAuthenticationFilter {
@SuppressWarnings("rawtypes")
@Override

View File

@ -39,7 +39,7 @@ public class OamStaffDetailsServiceImpl implements UserDetailsService {
* @author DB
* @date 2023/09/11 10:57
* @param username 用户名
* @return org.springframework.security.core.userdetails.UserDetails
* @return org.springframework.security.core.user.details.UserDetails
*/
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

View File

@ -19,10 +19,16 @@
<groupId>com.cpop</groupId>
<artifactId>Cpop-Core</artifactId>
</dependency>
<!--系统包-->
<dependency>
<groupId>com.cpop</groupId>
<artifactId>Cpop-System</artifactId>
</dependency>
<!--果酱包-->
<dependency>
<groupId>com.cpop</groupId>
<artifactId>Cpop-Jambox</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -12,7 +12,6 @@ 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.cpop.system.business.vo.RolePageVo;
import com.mybatisflex.core.paginate.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -67,9 +66,9 @@ public class MallRoleController {
@PreAuthorize("@aps.hasPermission('system:role:insert')")
@OperationLog(operationLogEnumType = OperationLogEnum.INSERT_OAM_ROLE)
@ApiOperation("新增商城角色")
@PostMapping("/insertSysRole")
public R<Void> insertSysRole(@RequestBody @Validated RoleBo bo) {
roleService.insertSysRole(bo);
@PostMapping("/insertMallRole")
public R<Void> insertMallRole(@RequestBody @Validated RoleBo bo) {
roleBrandService.insertMallRole(bo);
return R.ok();
}

View File

@ -5,13 +5,11 @@ import com.cpop.core.base.entity.BaseInsertListener;
import com.cpop.core.base.entity.BaseUpdateListener;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.Table;
import java.io.Serializable;
import java.time.LocalDateTime;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* 商城-角色-品牌id 实体类
*
@ -43,8 +41,4 @@ public class RoleBrand extends BaseEntity implements Serializable {
*/
private String brandId;
}

View File

@ -1,11 +1,11 @@
package com.cpop.mall.business.service;
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.vo.RolePageVo;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.service.IService;
import com.cpop.mall.business.entity.RoleBrand;
/**
* 商城-角色-品牌id 服务层
@ -23,4 +23,13 @@ public interface RoleBrandService extends IService<RoleBrand> {
* @return R<PageVo<MallRolePageVo>>
*/
Page<MallRolePageVo> getMallRolePageList(RolePageBo bo);
/**
* @descriptions 新增角色
* @author DB
* @date 2023/10/12 10:48
* @param bo 请求参数
* @return: com.cpop.core.base.R<java.lang.Void>
*/
void insertMallRole(RoleBo bo);
}

View File

@ -1,19 +1,37 @@
package com.cpop.mall.business.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.cpop.common.utils.bean.BeanUtils;
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.vo.MallRolePageVo;
import com.cpop.system.business.bo.RolePageBo;
import com.cpop.system.business.vo.RolePageVo;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
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.entity.Role;
import com.cpop.system.business.entity.RoleMenu;
import com.cpop.system.business.service.RoleMenuService;
import com.cpop.system.business.service.RoleService;
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 org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import static com.cpop.jambox.business.entity.table.BrandTableDef.BRAND;
import static com.cpop.mall.business.entity.table.RoleBrandTableDef.ROLE_BRAND;
import static com.cpop.mall.business.entity.table.StaffTableDef.STAFF;
import static com.cpop.system.business.entity.table.MenuTableDef.MENU;
import static com.cpop.system.business.entity.table.RoleMenuTableDef.ROLE_MENU;
import static com.cpop.system.business.entity.table.RoleTableDef.ROLE;
import static com.mybatisflex.core.query.QueryMethods.groupConcat;
/**
* 商城-角色-品牌id 服务层实现
@ -33,14 +51,58 @@ public class RoleBrandServiceImpl extends ServiceImpl<RoleBrandMapper, RoleBrand
*/
@Override
public Page<MallRolePageVo> getMallRolePageList(RolePageBo bo) {
//获取当前登录用户信息
JSONObject staffInfo = SecurityUtils.getInstance().getLoginStaffInfo();
//获取分页参数
PageDomain pageDomain = SqlUtils.getInstance().getPageDomain();
this.mapper.paginateAs(pageDomain.getPageNum(),pageDomain.getPageSize(),
return this.mapper.paginateAs(pageDomain.getPageNum(), pageDomain.getPageSize(),
QueryWrapper.create()
.select(ROLE_BRAND.ALL_COLUMNS)
//角色信息
.select(ROLE.ROLE_NAME, ROLE.ROLE_VALUE, ROLE.STATUS, ROLE.REMARK, ROLE.ORDER_NO, ROLE.CREATE_TIME)
.select(groupConcat(MENU.ID).as(MallRolePageVo::getMenuIds))
.leftJoin(STAFF).on(STAFF.ROLE_BRAND_ID.eq(ROLE_BRAND.ID))
.leftJoin(ROLE).on(ROLE.ID.eq(ROLE_BRAND.ROLE_ID))
//左联品牌表
.leftJoin(BRAND).on(ROLE_BRAND.ID.eq(ROLE_BRAND.BRAND_ID))
//角色菜单中甲表
.leftJoin(ROLE_MENU).on(ROLE_MENU.ROLE_ID.eq(ROLE_BRAND.ROLE_ID))
.leftJoin(MENU).on(MENU.ID.eq(ROLE_MENU.MENU_ID))
.where(STAFF.ID.eq(staffInfo.getString("id")))
.and(ROLE.ROLE_NAME.like(bo.getRoleName()))
.and(ROLE.STATUS.eq(bo.getStatus()))
.groupBy(ROLE.ID)
.orderBy(ROLE.ORDER_NO.asc())
, MallRolePageVo.class);
}
,RolePageVo.class);
return null;
/**
* @descriptions 新增角色
* @author DB
* @date 2023/10/12 10:48
* @param bo 请求参数
* @return: com.cpop.core.base.R<java.lang.Void>
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void insertMallRole(RoleBo bo) {
Role role = BeanUtils.mapToClass(bo, Role.class);
SpringUtils.getBean(RoleService.class).save(role);
//将菜单信息录入中间表
if (!bo.getMenuIds().isEmpty()) {
List<RoleMenu> roleMenus = new ArrayList<>();
bo.getMenuIds().forEach(item -> {
RoleMenu roleMenu = new RoleMenu();
roleMenu.setMenuId(item);
roleMenu.setRoleId(role.getId());
roleMenus.add(roleMenu);
});
SpringUtils.getBean(RoleMenuService.class).saveBatch(roleMenus);
}
//录入商城角色品牌表
RoleBrand roleBrand = new RoleBrand();
roleBrand.setRoleId(role.getId())
.setBrandId(bo.getBrandId());
this.save(roleBrand);
}
}

View File

@ -1,5 +1,6 @@
package com.cpop.mall.business.vo;
import com.cpop.core.annontation.StringArrayConvert;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.mybatisflex.annotation.Column;
import io.swagger.annotations.ApiModel;
@ -8,8 +9,7 @@ import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;
import java.time.LocalDateTime;
/**
* @author DB
@ -70,12 +70,13 @@ public class MallRolePageVo implements Serializable {
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "GMT+8")
@ApiModelProperty("更新时间")
private Timestamp updateTime;
private LocalDateTime updateTime;
/**
* 角色所属菜单id集合
*/
@StringArrayConvert
@ApiModelProperty("角色所属菜单id集合")
@Column(ignore = true)
private List<String> menuIds;
private String menuIds;
}

View File

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