7 changed files with 316 additions and 0 deletions
@ -0,0 +1,52 @@ |
|||||
|
package com.ruoyi.web.controller.system; |
||||
|
|
||||
|
import com.ruoyi.common.core.controller.BaseController; |
||||
|
import com.ruoyi.common.core.domain.AjaxResult; |
||||
|
import com.ruoyi.system.domain.SysUserMenuConfig; |
||||
|
import com.ruoyi.system.service.ISysUserMenuConfigService; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
|
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* 用户左侧菜单配置(当前登录用户自己的配置) |
||||
|
* |
||||
|
* @author ruoyi |
||||
|
*/ |
||||
|
@RestController |
||||
|
@RequestMapping("/system/user/menuConfig") |
||||
|
public class SysUserMenuConfigController extends BaseController { |
||||
|
|
||||
|
@Autowired |
||||
|
private ISysUserMenuConfigService menuConfigService; |
||||
|
|
||||
|
/** |
||||
|
* 获取当前用户的左侧菜单配置 |
||||
|
*/ |
||||
|
@GetMapping |
||||
|
public AjaxResult getMyConfig() { |
||||
|
Long userId = getUserId(); |
||||
|
SysUserMenuConfig config = menuConfigService.selectByUserId(userId); |
||||
|
if (config == null) { |
||||
|
return success(null); |
||||
|
} |
||||
|
return success(config); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 保存当前用户的左侧菜单配置 |
||||
|
* 请求体: { "menuItems": "[{...}]", "position": "left" } |
||||
|
*/ |
||||
|
@PutMapping |
||||
|
public AjaxResult saveMyConfig(@RequestBody Map<String, Object> body) { |
||||
|
Long userId = getUserId(); |
||||
|
String menuItems = body != null && body.get("menuItems") != null ? body.get("menuItems").toString() : null; |
||||
|
String position = body != null && body.get("position") != null ? body.get("position").toString() : "left"; |
||||
|
if (menuItems == null) { |
||||
|
return error("菜单项不能为空"); |
||||
|
} |
||||
|
int rows = menuConfigService.saveConfig(userId, menuItems, position, getUsername()); |
||||
|
return toAjax(rows); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,63 @@ |
|||||
|
package com.ruoyi.system.domain; |
||||
|
|
||||
|
import javax.validation.constraints.Size; |
||||
|
import com.ruoyi.common.annotation.Excel; |
||||
|
import com.ruoyi.common.core.domain.BaseEntity; |
||||
|
|
||||
|
/** |
||||
|
* 用户左侧菜单配置对象 sys_user_menu_config |
||||
|
* |
||||
|
* @author ruoyi |
||||
|
*/ |
||||
|
public class SysUserMenuConfig extends BaseEntity { |
||||
|
|
||||
|
private static final long serialVersionUID = 1L; |
||||
|
|
||||
|
/** 配置主键 */ |
||||
|
private Long configId; |
||||
|
|
||||
|
/** 用户ID */ |
||||
|
@Excel(name = "用户ID") |
||||
|
private Long userId; |
||||
|
|
||||
|
/** 菜单项JSON数组 */ |
||||
|
@Excel(name = "菜单项") |
||||
|
private String menuItems; |
||||
|
|
||||
|
/** 菜单位置 left/top/bottom */ |
||||
|
@Excel(name = "菜单位置") |
||||
|
@Size(max = 20) |
||||
|
private String position; |
||||
|
|
||||
|
public Long getConfigId() { |
||||
|
return configId; |
||||
|
} |
||||
|
|
||||
|
public void setConfigId(Long configId) { |
||||
|
this.configId = configId; |
||||
|
} |
||||
|
|
||||
|
public Long getUserId() { |
||||
|
return userId; |
||||
|
} |
||||
|
|
||||
|
public void setUserId(Long userId) { |
||||
|
this.userId = userId; |
||||
|
} |
||||
|
|
||||
|
public String getMenuItems() { |
||||
|
return menuItems; |
||||
|
} |
||||
|
|
||||
|
public void setMenuItems(String menuItems) { |
||||
|
this.menuItems = menuItems; |
||||
|
} |
||||
|
|
||||
|
public String getPosition() { |
||||
|
return position; |
||||
|
} |
||||
|
|
||||
|
public void setPosition(String position) { |
||||
|
this.position = position; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,35 @@ |
|||||
|
package com.ruoyi.system.mapper; |
||||
|
|
||||
|
import com.ruoyi.system.domain.SysUserMenuConfig; |
||||
|
|
||||
|
/** |
||||
|
* 用户左侧菜单配置 数据层 |
||||
|
* |
||||
|
* @author ruoyi |
||||
|
*/ |
||||
|
public interface SysUserMenuConfigMapper { |
||||
|
|
||||
|
/** |
||||
|
* 根据用户ID查询配置 |
||||
|
* |
||||
|
* @param userId 用户ID |
||||
|
* @return 配置信息 |
||||
|
*/ |
||||
|
SysUserMenuConfig selectByUserId(Long userId); |
||||
|
|
||||
|
/** |
||||
|
* 新增配置 |
||||
|
* |
||||
|
* @param config 配置信息 |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
int insertConfig(SysUserMenuConfig config); |
||||
|
|
||||
|
/** |
||||
|
* 更新配置 |
||||
|
* |
||||
|
* @param config 配置信息 |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
int updateConfig(SysUserMenuConfig config); |
||||
|
} |
||||
@ -0,0 +1,30 @@ |
|||||
|
package com.ruoyi.system.service; |
||||
|
|
||||
|
import com.ruoyi.system.domain.SysUserMenuConfig; |
||||
|
|
||||
|
/** |
||||
|
* 用户左侧菜单配置 服务层 |
||||
|
* |
||||
|
* @author ruoyi |
||||
|
*/ |
||||
|
public interface ISysUserMenuConfigService { |
||||
|
|
||||
|
/** |
||||
|
* 根据当前登录用户ID查询配置 |
||||
|
* |
||||
|
* @param userId 用户ID |
||||
|
* @return 配置信息,无则返回 null |
||||
|
*/ |
||||
|
SysUserMenuConfig selectByUserId(Long userId); |
||||
|
|
||||
|
/** |
||||
|
* 保存当前用户的菜单配置(有则更新,无则新增) |
||||
|
* |
||||
|
* @param userId 用户ID |
||||
|
* @param menuItems 菜单项JSON字符串 |
||||
|
* @param position 菜单位置 |
||||
|
* @param operator 操作人(createBy/updateBy) |
||||
|
* @return 结果 |
||||
|
*/ |
||||
|
int saveConfig(Long userId, String menuItems, String position, String operator); |
||||
|
} |
||||
@ -0,0 +1,55 @@ |
|||||
|
package com.ruoyi.system.service.impl; |
||||
|
|
||||
|
import com.ruoyi.common.utils.StringUtils; |
||||
|
import com.ruoyi.system.domain.SysUserMenuConfig; |
||||
|
import com.ruoyi.system.mapper.SysUserMenuConfigMapper; |
||||
|
import com.ruoyi.system.service.ISysUserMenuConfigService; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
/** |
||||
|
* 用户左侧菜单配置 服务层实现 |
||||
|
* |
||||
|
* @author ruoyi |
||||
|
*/ |
||||
|
@Service |
||||
|
public class SysUserMenuConfigServiceImpl implements ISysUserMenuConfigService { |
||||
|
|
||||
|
@Autowired |
||||
|
private SysUserMenuConfigMapper menuConfigMapper; |
||||
|
|
||||
|
@Override |
||||
|
public SysUserMenuConfig selectByUserId(Long userId) { |
||||
|
if (userId == null) { |
||||
|
return null; |
||||
|
} |
||||
|
return menuConfigMapper.selectByUserId(userId); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public int saveConfig(Long userId, String menuItems, String position, String operator) { |
||||
|
if (userId == null) { |
||||
|
return 0; |
||||
|
} |
||||
|
SysUserMenuConfig existing = menuConfigMapper.selectByUserId(userId); |
||||
|
if (existing != null) { |
||||
|
existing.setMenuItems(menuItems); |
||||
|
if (StringUtils.isNotEmpty(position)) { |
||||
|
existing.setPosition(position); |
||||
|
} |
||||
|
if (StringUtils.isNotEmpty(operator)) { |
||||
|
existing.setUpdateBy(operator); |
||||
|
} |
||||
|
return menuConfigMapper.updateConfig(existing); |
||||
|
} else { |
||||
|
SysUserMenuConfig config = new SysUserMenuConfig(); |
||||
|
config.setUserId(userId); |
||||
|
config.setMenuItems(menuItems); |
||||
|
config.setPosition(StringUtils.isEmpty(position) ? "left" : position); |
||||
|
if (StringUtils.isNotEmpty(operator)) { |
||||
|
config.setCreateBy(operator); |
||||
|
} |
||||
|
return menuConfigMapper.insertConfig(config); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,58 @@ |
|||||
|
<?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.ruoyi.system.mapper.SysUserMenuConfigMapper"> |
||||
|
|
||||
|
<resultMap type="com.ruoyi.system.domain.SysUserMenuConfig" id="SysUserMenuConfigResult"> |
||||
|
<id property="configId" column="config_id" /> |
||||
|
<result property="userId" column="user_id" /> |
||||
|
<result property="menuItems" column="menu_items" /> |
||||
|
<result property="position" column="position" /> |
||||
|
<result property="createBy" column="create_by" /> |
||||
|
<result property="createTime" column="create_time" /> |
||||
|
<result property="updateBy" column="update_by" /> |
||||
|
<result property="updateTime" column="update_time" /> |
||||
|
<result property="remark" column="remark" /> |
||||
|
</resultMap> |
||||
|
|
||||
|
<sql id="selectVo"> |
||||
|
select config_id, user_id, menu_items, position, create_by, create_time, update_by, update_time, remark |
||||
|
from sys_user_menu_config |
||||
|
</sql> |
||||
|
|
||||
|
<select id="selectByUserId" parameterType="Long" resultMap="SysUserMenuConfigResult"> |
||||
|
<include refid="selectVo"/> |
||||
|
where user_id = #{userId} limit 1 |
||||
|
</select> |
||||
|
|
||||
|
<insert id="insertConfig" parameterType="com.ruoyi.system.domain.SysUserMenuConfig"> |
||||
|
insert into sys_user_menu_config ( |
||||
|
user_id, |
||||
|
menu_items, |
||||
|
position, |
||||
|
<if test="createBy != null and createBy != ''">create_by,</if> |
||||
|
<if test="remark != null and remark != ''">remark,</if> |
||||
|
create_time |
||||
|
) values ( |
||||
|
#{userId}, |
||||
|
#{menuItems}, |
||||
|
#{position}, |
||||
|
<if test="createBy != null and createBy != ''">#{createBy},</if> |
||||
|
<if test="remark != null and remark != ''">#{remark},</if> |
||||
|
sysdate() |
||||
|
) |
||||
|
</insert> |
||||
|
|
||||
|
<update id="updateConfig" parameterType="com.ruoyi.system.domain.SysUserMenuConfig"> |
||||
|
update sys_user_menu_config |
||||
|
<set> |
||||
|
<if test="menuItems != null">menu_items = #{menuItems},</if> |
||||
|
<if test="position != null and position != ''">position = #{position},</if> |
||||
|
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if> |
||||
|
<if test="remark != null">remark = #{remark},</if> |
||||
|
update_time = sysdate() |
||||
|
</set> |
||||
|
where user_id = #{userId} |
||||
|
</update> |
||||
|
</mapper> |
||||
@ -0,0 +1,23 @@ |
|||||
|
import request from '@/utils/request' |
||||
|
|
||||
|
/** |
||||
|
* 获取当前用户的左侧菜单配置 |
||||
|
*/ |
||||
|
export function getMenuConfig() { |
||||
|
return request({ |
||||
|
url: '/system/user/menuConfig', |
||||
|
method: 'get' |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 保存当前用户的左侧菜单配置 |
||||
|
* @param {Object} data - { menuItems: string (JSON), position: string } |
||||
|
*/ |
||||
|
export function saveMenuConfig(data) { |
||||
|
return request({ |
||||
|
url: '/system/user/menuConfig', |
||||
|
method: 'put', |
||||
|
data: data |
||||
|
}) |
||||
|
} |
||||
Loading…
Reference in new issue