Merge #4 into master from cc_20251027_new2
fix:小程序菜单 * cc_20251027_new2: (3 commits squashed) - feat:小程序菜单配置 - Merge branch 'refs/heads/master' into cc_20251027_new2 - fix:小程序菜单 Signed-off-by: 王非凡 <accounts_67eba0c5fee9c49c80c8e2b4@mail.teambition.com> Reviewed-by: 苏竹红 <accounts_68551bf01395375227aee211@mail.teambition.com> Merged-by: 苏竹红 <accounts_68551bf01395375227aee211@mail.teambition.com> CR-link: https://codeup.aliyun.com/692ea314dec569489f6f167c/hangzhou/java/custom_zxjp/change/4
This commit is contained in:
@@ -60,4 +60,21 @@ public class SysRoleDao {
|
||||
return sysRoleDOS.stream().collect(Collectors.toMap(k->k.getId(), v->v.getRoleName(), (k1, k2)->k1));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询优先级最高的角色
|
||||
* @param userId 用户id
|
||||
* @return 角色
|
||||
*/
|
||||
public SysRoleDO getHighestPrioritySysRoleDoByUserId(String userId) {
|
||||
return sysRoleMapper.getHighestPrioritySysRoleDoByUserId(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据角色枚举查询角色
|
||||
* @param roleEnum 角色枚举
|
||||
* @return 角色
|
||||
*/
|
||||
public SysRoleDO getRoleByRoleEnum(String roleEnum) {
|
||||
return sysRoleMapper.getRoleByRoleEnum(roleEnum);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.cool.store.dao.menu;
|
||||
|
||||
import com.cool.store.entity.menu.MiniMenuConfigDO;
|
||||
import com.cool.store.mapper.menu.MiniMenuConfigMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 小程序菜单配置
|
||||
* </p>
|
||||
*
|
||||
* @author wangff
|
||||
* @since 2025/10/31
|
||||
*/
|
||||
@Repository
|
||||
@RequiredArgsConstructor
|
||||
public class MiniMenuConfigDAO {
|
||||
private final MiniMenuConfigMapper miniMenuConfigMapper;
|
||||
|
||||
/**
|
||||
* 根据角色id查询
|
||||
* @param roleId 角色id
|
||||
* @return 菜单配置列表
|
||||
*/
|
||||
public List<MiniMenuConfigDO> getListByRoleId(Long roleId) {
|
||||
return miniMenuConfigMapper.select(MiniMenuConfigDO.builder().roleId(roleId).build());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.cool.store.dao.menu;
|
||||
|
||||
import com.cool.store.entity.menu.MiniMenuDO;
|
||||
import com.cool.store.mapper.menu.MiniMenuMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import tk.mybatis.mapper.entity.Example;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 小程序菜单DAO
|
||||
* </p>
|
||||
*
|
||||
* @author wangff
|
||||
* @since 2025/11/28
|
||||
*/
|
||||
@Repository
|
||||
@RequiredArgsConstructor
|
||||
public class MiniMenuDAO {
|
||||
private final MiniMenuMapper miniMenuMapper;
|
||||
|
||||
public List<MiniMenuDO> getByIds(List<Long> ids) {
|
||||
if (CollectionUtils.isEmpty(ids)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
Example example = new Example(MiniMenuDO.class);
|
||||
example.createCriteria().andIn("id", ids);
|
||||
return miniMenuMapper.selectByExample(example);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.cool.store.mapper.menu;
|
||||
|
||||
import com.cool.store.entity.menu.MiniMenuConfigDO;
|
||||
import tk.mybatis.mapper.common.Mapper;
|
||||
|
||||
public interface MiniMenuConfigMapper extends Mapper<MiniMenuConfigDO> {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.cool.store.mapper.menu;
|
||||
|
||||
import com.cool.store.entity.menu.MiniMenuDO;
|
||||
import tk.mybatis.mapper.common.Mapper;
|
||||
|
||||
public interface MiniMenuMapper extends Mapper<MiniMenuDO> {
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.cool.store.mapper.menu.MiniMenuConfigMapper">
|
||||
<resultMap id="BaseResultMap" type="com.cool.store.entity.menu.MiniMenuConfigDO">
|
||||
<!--
|
||||
WARNING - @mbg.generated
|
||||
-->
|
||||
<id column="id" jdbcType="BIGINT" property="id" />
|
||||
<result column="role_id" jdbcType="BIGINT" property="roleId" />
|
||||
<result column="menu_id" jdbcType="BIGINT" property="menuId" />
|
||||
</resultMap>
|
||||
</mapper>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.cool.store.mapper.menu.MiniMenuMapper">
|
||||
<resultMap id="BaseResultMap" type="com.cool.store.entity.menu.MiniMenuDO">
|
||||
<!--
|
||||
WARNING - @mbg.generated
|
||||
-->
|
||||
<id column="id" jdbcType="BIGINT" property="id" />
|
||||
<result column="name" jdbcType="VARCHAR" property="name" />
|
||||
<result column="menu_key" jdbcType="VARCHAR" property="menuKey" />
|
||||
</resultMap>
|
||||
</mapper>
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.cool.store.entity.menu;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
* 小程序菜单配置
|
||||
*/
|
||||
@Table(name = "zxjp_mini_menu_config")
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class MiniMenuConfigDO {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 角色id
|
||||
*/
|
||||
@Column(name = "role_id")
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 菜单
|
||||
*/
|
||||
@Column(name = "menu_id")
|
||||
private Long menuId;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.cool.store.entity.menu;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Table(name = "zxjp_mini_menu")
|
||||
@Data
|
||||
public class MiniMenuDO {
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* key
|
||||
*/
|
||||
private String menuKey;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.cool.store.vo.menu;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 小程序菜单配置VO
|
||||
* </p>
|
||||
*
|
||||
* @author wangff
|
||||
* @since 2025/10/31
|
||||
*/
|
||||
@Data
|
||||
public class MiniMenuConfigVO {
|
||||
|
||||
@ApiModelProperty("菜单key")
|
||||
private String menuKey;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.cool.store.service.menu;
|
||||
|
||||
import com.cool.store.vo.menu.MiniMenuConfigVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 小程序菜单配置
|
||||
* </p>
|
||||
*
|
||||
* @author wangff
|
||||
* @since 2025/10/31
|
||||
*/
|
||||
public interface MiniMenuService {
|
||||
|
||||
/**
|
||||
* 获取用户小程序菜单配置
|
||||
* @return 小程序菜单配置
|
||||
*/
|
||||
List<MiniMenuConfigVO> getUserMiniMenu();
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.cool.store.service.menu.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollStreamUtil;
|
||||
import com.cool.store.context.PartnerUserHolder;
|
||||
import com.cool.store.dao.EnterpriseUserDAO;
|
||||
import com.cool.store.dao.SysRoleDao;
|
||||
import com.cool.store.dao.menu.MiniMenuConfigDAO;
|
||||
import com.cool.store.dao.menu.MiniMenuDAO;
|
||||
import com.cool.store.entity.EnterpriseUserDO;
|
||||
import com.cool.store.entity.SysRoleDO;
|
||||
import com.cool.store.entity.menu.MiniMenuConfigDO;
|
||||
import com.cool.store.entity.menu.MiniMenuDO;
|
||||
import com.cool.store.enums.AIEnum;
|
||||
import com.cool.store.enums.Role;
|
||||
import com.cool.store.service.menu.MiniMenuService;
|
||||
import com.cool.store.utils.BeanUtil;
|
||||
import com.cool.store.vo.PartnerUserInfoVO;
|
||||
import com.cool.store.vo.menu.MiniMenuConfigVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 小程序菜单配置 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author wangff
|
||||
* @since 2025/10/31
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class MiniMenuServiceImpl implements MiniMenuService {
|
||||
private final MiniMenuConfigDAO miniMenuConfigDAO;
|
||||
private final SysRoleDao sysRoleDao;
|
||||
private final EnterpriseUserDAO enterpriseUserDAO;
|
||||
private final MiniMenuDAO miniMenuDAO;
|
||||
|
||||
|
||||
@Override
|
||||
public List<MiniMenuConfigVO> getUserMiniMenu() {
|
||||
PartnerUserInfoVO user = PartnerUserHolder.getUser();
|
||||
if (StringUtils.isBlank(user.getMobile())) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
SysRoleDO highestRole = getHighestRoleByMobile(user.getMobile());
|
||||
if (Objects.isNull(highestRole)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<MiniMenuConfigDO> list = miniMenuConfigDAO.getListByRoleId(highestRole.getId());
|
||||
List<Long> menuIds = CollStreamUtil.toList(list, MiniMenuConfigDO::getMenuId);
|
||||
List<MiniMenuDO> menuList = miniMenuDAO.getByIds(menuIds);
|
||||
return BeanUtil.toList(menuList, MiniMenuConfigVO.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据手机号查询用户优先级最高的角色
|
||||
* @param mobile 手机号
|
||||
* @return 角色信息
|
||||
*/
|
||||
private SysRoleDO getHighestRoleByMobile(String mobile) {
|
||||
if (StringUtils.isBlank(mobile)) {
|
||||
return null;
|
||||
}
|
||||
EnterpriseUserDO userDO = enterpriseUserDAO.selectByMobile(mobile);
|
||||
if (Objects.isNull(userDO)) {
|
||||
return null;
|
||||
}
|
||||
return getHighestRole(userDO.getUserId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询当前用户优先级最高的角色
|
||||
* @param userId 用户id
|
||||
* @return 角色信息
|
||||
*/
|
||||
private SysRoleDO getHighestRole(String userId) {
|
||||
if(AIEnum.AI_USERID.getCode().equals(userId)){
|
||||
return sysRoleDao.getRoleByRoleEnum(Role.MASTER.getRoleEnum());
|
||||
}
|
||||
return sysRoleDao.getHighestPrioritySysRoleDoByUserId(userId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.cool.store.controller.webc;
|
||||
|
||||
import com.cool.store.response.ResponseResult;
|
||||
import com.cool.store.service.menu.MiniMenuService;
|
||||
import com.cool.store.vo.menu.MiniMenuConfigVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 小程序菜单配置 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author wangff
|
||||
* @since 2025/10/31
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping({"/mini/menu"})
|
||||
@Api(tags = "Mini菜单配置")
|
||||
@RequiredArgsConstructor
|
||||
public class MiniMenuController {
|
||||
private final MiniMenuService miniMenuService;
|
||||
|
||||
@ApiOperation("当前用户菜单配置")
|
||||
@GetMapping("/userConfig")
|
||||
public ResponseResult<List<MiniMenuConfigVO>> getCurrentUserConfig() {
|
||||
return ResponseResult.success(miniMenuService.getUserMiniMenu());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user