新增ai角色设定
This commit is contained in:
parent
2753063e70
commit
a029f1f0fc
|
|
@ -35,4 +35,5 @@ build/
|
|||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
||||
.DS_Store
|
||||
*.log
|
||||
|
|
@ -0,0 +1,111 @@
|
|||
package cn.qihangerp.erp.controller;
|
||||
|
||||
import java.util.List;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import cn.qihangerp.security.LoginUser;
|
||||
import cn.qihangerp.security.TokenService;
|
||||
import cn.qihangerp.model.entity.AiUserRole;
|
||||
import cn.qihangerp.service.IAiUserRoleService;
|
||||
|
||||
/**
|
||||
* 用户AI角色Controller
|
||||
*
|
||||
* @author qihang
|
||||
* @date 2024-06-20
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/ai/user-role")
|
||||
public class AiUserRoleController {
|
||||
@Autowired
|
||||
private IAiUserRoleService aiUserRoleService;
|
||||
|
||||
@Autowired
|
||||
private TokenService tokenService;
|
||||
|
||||
/**
|
||||
* 获取当前用户所有角色
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public ResponseEntity<List<AiUserRole>> list(HttpServletRequest request) {
|
||||
LoginUser loginUser = tokenService.getLoginUser(request);
|
||||
List<AiUserRole> list = aiUserRoleService.selectAiUserRolesByUserId(loginUser.getUserId());
|
||||
return ResponseEntity.ok(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户默认角色
|
||||
*/
|
||||
@GetMapping("/default")
|
||||
public ResponseEntity<AiUserRole> getDefault(HttpServletRequest request) {
|
||||
LoginUser loginUser = tokenService.getLoginUser(request);
|
||||
AiUserRole aiUserRole = aiUserRoleService.selectDefaultAiUserRoleByUserId(loginUser.getUserId());
|
||||
return ResponseEntity.ok(aiUserRole);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增用户AI角色
|
||||
*/
|
||||
@PostMapping
|
||||
public ResponseEntity<Integer> add(@RequestBody AiUserRole aiUserRole, HttpServletRequest request) {
|
||||
LoginUser loginUser = tokenService.getLoginUser(request);
|
||||
aiUserRole.setUserId(loginUser.getUserId());
|
||||
int result = aiUserRoleService.insertAiUserRole(aiUserRole);
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户AI角色
|
||||
*/
|
||||
@PutMapping
|
||||
public ResponseEntity<Integer> edit(@RequestBody AiUserRole aiUserRole, HttpServletRequest request) {
|
||||
LoginUser loginUser = tokenService.getLoginUser(request);
|
||||
// 验证角色是否属于当前用户
|
||||
AiUserRole existingRole = aiUserRoleService.selectAiUserRoleById(aiUserRole.getId());
|
||||
if (existingRole == null || !existingRole.getUserId().equals(loginUser.getUserId())) {
|
||||
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(0);
|
||||
}
|
||||
int result = aiUserRoleService.updateAiUserRole(aiUserRole);
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户AI角色
|
||||
*/
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Integer> remove(@PathVariable Long id, HttpServletRequest request) {
|
||||
LoginUser loginUser = tokenService.getLoginUser(request);
|
||||
// 验证角色是否属于当前用户
|
||||
AiUserRole existingRole = aiUserRoleService.selectAiUserRoleById(id);
|
||||
if (existingRole == null || !existingRole.getUserId().equals(loginUser.getUserId())) {
|
||||
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(0);
|
||||
}
|
||||
int result = aiUserRoleService.deleteAiUserRoleById(id);
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置默认角色
|
||||
*/
|
||||
@PutMapping("/set-default/{roleId}")
|
||||
public ResponseEntity<Integer> setDefault(@PathVariable Long roleId, HttpServletRequest request) {
|
||||
LoginUser loginUser = tokenService.getLoginUser(request);
|
||||
// 验证角色是否属于当前用户
|
||||
AiUserRole existingRole = aiUserRoleService.selectAiUserRoleById(roleId);
|
||||
if (existingRole == null || !existingRole.getUserId().equals(loginUser.getUserId())) {
|
||||
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(0);
|
||||
}
|
||||
int result = aiUserRoleService.setDefaultAiUserRole(loginUser.getUserId(), roleId);
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
-- 用户AI角色表
|
||||
CREATE TABLE `ai_user_role` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键id,自增',
|
||||
`user_id` bigint(20) NOT NULL COMMENT '用户id',
|
||||
`role_name` varchar(255) NOT NULL COMMENT '角色名称',
|
||||
`description` varchar(500) DEFAULT NULL COMMENT '角色描述',
|
||||
`system_prompt` text NOT NULL COMMENT '角色系统提示词',
|
||||
`is_default` int(11) NOT NULL DEFAULT '0' COMMENT '是否为默认角色:0-否,1-是',
|
||||
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_user_id` (`user_id`),
|
||||
KEY `idx_is_default` (`is_default`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户AI角色表';
|
||||
|
||||
-- 添加默认角色示例数据
|
||||
INSERT INTO `ai_user_role` (`user_id`, `role_name`, `description`, `system_prompt`, `is_default`) VALUES
|
||||
(1, '默认ERP助手', '默认的ERP智能助手,用于查询订单、商品、库存等信息', '你是一个智能ERP助手,名叫启航助手,专门为电商企业提供服务。\n你的职责是帮助用户查询订单、商品、库存等信息,以及执行其他ERP相关操作。\n你可以使用提供的工具来获取实时数据,工具返回的结果要以用户友好的方式呈现。\n如果用户的请求超出你的能力范围,你应该礼貌地拒绝。\n回答问题时要简洁明了,避免使用过于技术化的术语。', 1);
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
package cn.qihangerp.mapper;
|
||||
|
||||
import cn.qihangerp.model.entity.AiUserRole;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户AI角色表Mapper接口
|
||||
*
|
||||
* @author qihang
|
||||
*/
|
||||
@Mapper
|
||||
public interface AiUserRoleMapper extends BaseMapper<AiUserRole>
|
||||
{
|
||||
/**
|
||||
* 查询用户AI角色表
|
||||
*
|
||||
* @param id 用户AI角色表主键
|
||||
* @return 用户AI角色表
|
||||
*/
|
||||
public AiUserRole selectAiUserRoleById(@Param("id") Long id);
|
||||
|
||||
/**
|
||||
* 查询用户AI角色表列表
|
||||
*
|
||||
* @param aiUserRole 用户AI角色表
|
||||
* @return 用户AI角色表集合
|
||||
*/
|
||||
public List<AiUserRole> selectAiUserRoleList(@Param("aiUserRole") AiUserRole aiUserRole);
|
||||
|
||||
/**
|
||||
* 查询用户的所有角色
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 用户角色集合
|
||||
*/
|
||||
public List<AiUserRole> selectAiUserRolesByUserId(@Param("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 查询用户的默认角色
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 默认角色
|
||||
*/
|
||||
public AiUserRole selectDefaultAiUserRoleByUserId(@Param("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 新增用户AI角色表
|
||||
*
|
||||
* @param aiUserRole 用户AI角色表
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertAiUserRole(@Param("aiUserRole") AiUserRole aiUserRole);
|
||||
|
||||
/**
|
||||
* 修改用户AI角色表
|
||||
*
|
||||
* @param aiUserRole 用户AI角色表
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateAiUserRole(@Param("aiUserRole") AiUserRole aiUserRole);
|
||||
|
||||
/**
|
||||
* 删除用户AI角色表
|
||||
*
|
||||
* @param id 用户AI角色表主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteAiUserRoleById(@Param("id") Long id);
|
||||
|
||||
/**
|
||||
* 批量删除用户AI角色表
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteAiUserRoleByIds(@Param("ids") Long[] ids);
|
||||
|
||||
/**
|
||||
* 更新用户的非默认角色
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateNonDefaultRolesByUserId(@Param("userId") Long userId);
|
||||
}
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
<?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="cn.qihangerp.mapper.AiUserRoleMapper">
|
||||
<resultMap type="cn.qihangerp.model.entity.AiUserRole" id="AiUserRoleResult">
|
||||
<id property="id" column="id"/>
|
||||
<result property="userId" column="user_id"/>
|
||||
<result property="roleName" column="role_name"/>
|
||||
<result property="systemPrompt" column="system_prompt"/>
|
||||
<result property="isDefault" column="is_default"/>
|
||||
<result property="createTime" column="create_time"/>
|
||||
<result property="updateTime" column="update_time"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectAiUserRoleVo">
|
||||
select id, user_id, role_name, system_prompt, is_default, create_time, update_time from ai_user_role
|
||||
</sql>
|
||||
|
||||
<select id="selectAiUserRoleById" parameterType="Long" resultMap="AiUserRoleResult">
|
||||
<include refid="selectAiUserRoleVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="selectAiUserRoleList" parameterType="cn.qihangerp.model.entity.AiUserRole" resultMap="AiUserRoleResult">
|
||||
<include refid="selectAiUserRoleVo"/>
|
||||
<where>
|
||||
<if test="roleName != null and roleName != ''">
|
||||
AND role_name LIKE CONCAT('%', #{roleName}, '%')
|
||||
</if>
|
||||
<if test="userId != null">
|
||||
AND user_id = #{userId}
|
||||
</if>
|
||||
<if test="isDefault != null">
|
||||
AND is_default = #{isDefault}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectAiUserRolesByUserId" parameterType="Long" resultMap="AiUserRoleResult">
|
||||
<include refid="selectAiUserRoleVo"/>
|
||||
where user_id = #{userId}
|
||||
order by is_default desc, create_time desc
|
||||
</select>
|
||||
|
||||
<select id="selectDefaultAiUserRoleByUserId" parameterType="Long" resultMap="AiUserRoleResult">
|
||||
<include refid="selectAiUserRoleVo"/>
|
||||
where user_id = #{userId} and is_default = 1
|
||||
</select>
|
||||
|
||||
<insert id="insertAiUserRole" parameterType="cn.qihangerp.model.entity.AiUserRole" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into ai_user_role
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="userId != null">user_id,</if>
|
||||
<if test="roleName != null">role_name,</if>
|
||||
<if test="systemPrompt != null">system_prompt,</if>
|
||||
<if test="isDefault != null">is_default,</if>
|
||||
create_time,
|
||||
update_time
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="userId != null">#{userId},</if>
|
||||
<if test="roleName != null">#{roleName},</if>
|
||||
<if test="systemPrompt != null">#{systemPrompt},</if>
|
||||
<if test="isDefault != null">#{isDefault},</if>
|
||||
now(),
|
||||
now()
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateAiUserRole" parameterType="cn.qihangerp.model.entity.AiUserRole">
|
||||
update ai_user_role
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="roleName != null">role_name = #{roleName},</if>
|
||||
<if test="systemPrompt != null">system_prompt = #{systemPrompt},</if>
|
||||
<if test="isDefault != null">is_default = #{isDefault},</if>
|
||||
update_time = now()
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="updateNonDefaultRolesByUserId" parameterType="Long">
|
||||
update ai_user_role
|
||||
set is_default = 0, update_time = now()
|
||||
where user_id = #{userId}
|
||||
</update>
|
||||
|
||||
<delete id="deleteAiUserRoleById" parameterType="Long">
|
||||
delete from ai_user_role where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteAiUserRoleByIds" parameterType="Long">
|
||||
delete from ai_user_role where id in
|
||||
<foreach collection="array" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
package cn.qihangerp.model.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 用户AI角色表
|
||||
* @TableName ai_user_role
|
||||
*/
|
||||
@TableName(value = "ai_user_role")
|
||||
@Data
|
||||
public class AiUserRole implements Serializable {
|
||||
/**
|
||||
* 主键id,自增
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 角色名称
|
||||
*/
|
||||
private String roleName;
|
||||
|
||||
/**
|
||||
* 角色描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 角色系统提示词
|
||||
*/
|
||||
private String systemPrompt;
|
||||
|
||||
/**
|
||||
* 是否为默认角色:0-否,1-是
|
||||
*/
|
||||
private Integer isDefault;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
package cn.qihangerp.service;
|
||||
|
||||
import cn.qihangerp.model.entity.AiUserRole;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户AI角色Service接口
|
||||
*
|
||||
* @author qihang
|
||||
* @date 2024-05-21
|
||||
*/
|
||||
public interface IAiUserRoleService extends IService<AiUserRole>
|
||||
{
|
||||
/**
|
||||
* 查询用户AI角色
|
||||
*
|
||||
* @param id 用户AI角色主键
|
||||
* @return 用户AI角色
|
||||
*/
|
||||
public AiUserRole selectAiUserRoleById(Long id);
|
||||
|
||||
/**
|
||||
* 查询用户AI角色列表
|
||||
*
|
||||
* @param aiUserRole 用户AI角色
|
||||
* @return 用户AI角色集合
|
||||
*/
|
||||
public List<AiUserRole> selectAiUserRoleList(AiUserRole aiUserRole);
|
||||
|
||||
/**
|
||||
* 根据用户ID查询用户AI角色列表
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 用户AI角色集合
|
||||
*/
|
||||
public List<AiUserRole> selectAiUserRolesByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 根据用户ID查询默认用户AI角色
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 用户AI角色
|
||||
*/
|
||||
public AiUserRole selectDefaultAiUserRoleByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 新增用户AI角色
|
||||
*
|
||||
* @param aiUserRole 用户AI角色
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertAiUserRole(AiUserRole aiUserRole);
|
||||
|
||||
/**
|
||||
* 修改用户AI角色
|
||||
*
|
||||
* @param aiUserRole 用户AI角色
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateAiUserRole(AiUserRole aiUserRole);
|
||||
|
||||
/**
|
||||
* 批量删除用户AI角色
|
||||
*
|
||||
* @param ids 需要删除的用户AI角色主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteAiUserRoleByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除用户AI角色信息
|
||||
*
|
||||
* @param id 用户AI角色主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteAiUserRoleById(Long id);
|
||||
|
||||
/**
|
||||
* 设置默认角色
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param roleId 角色ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int setDefaultAiUserRole(Long userId, Long roleId);
|
||||
}
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
package cn.qihangerp.service.impl;
|
||||
|
||||
import cn.qihangerp.mapper.AiUserRoleMapper;
|
||||
import cn.qihangerp.model.entity.AiUserRole;
|
||||
import cn.qihangerp.service.IAiUserRoleService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户AI角色Service业务层处理
|
||||
*
|
||||
* @author qihang
|
||||
* @date 2024-05-21
|
||||
*/
|
||||
@Service
|
||||
public class AiUserRoleServiceImpl extends ServiceImpl<AiUserRoleMapper, AiUserRole> implements IAiUserRoleService
|
||||
{
|
||||
@Override
|
||||
public AiUserRole selectAiUserRoleById(Long id)
|
||||
{
|
||||
return baseMapper.selectAiUserRoleById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AiUserRole> selectAiUserRoleList(AiUserRole aiUserRole)
|
||||
{
|
||||
return baseMapper.selectAiUserRoleList(aiUserRole);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AiUserRole> selectAiUserRolesByUserId(Long userId)
|
||||
{
|
||||
return baseMapper.selectAiUserRolesByUserId(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AiUserRole selectDefaultAiUserRoleByUserId(Long userId)
|
||||
{
|
||||
return baseMapper.selectDefaultAiUserRoleByUserId(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insertAiUserRole(AiUserRole aiUserRole)
|
||||
{
|
||||
// 如果设置为默认角色,则先将该用户的其他角色设置为非默认
|
||||
if (aiUserRole.getIsDefault() != null && aiUserRole.getIsDefault() == 1)
|
||||
{
|
||||
baseMapper.updateNonDefaultRolesByUserId(aiUserRole.getUserId());
|
||||
}
|
||||
return baseMapper.insertAiUserRole(aiUserRole);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateAiUserRole(AiUserRole aiUserRole)
|
||||
{
|
||||
// 如果设置为默认角色,则先将该用户的其他角色设置为非默认
|
||||
if (aiUserRole.getIsDefault() != null && aiUserRole.getIsDefault() == 1)
|
||||
{
|
||||
baseMapper.updateNonDefaultRolesByUserId(aiUserRole.getUserId());
|
||||
}
|
||||
return baseMapper.updateAiUserRole(aiUserRole);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteAiUserRoleById(Long id)
|
||||
{
|
||||
return baseMapper.deleteAiUserRoleById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteAiUserRoleByIds(Long[] ids)
|
||||
{
|
||||
return baseMapper.deleteAiUserRoleByIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int setDefaultAiUserRole(Long userId, Long roleId)
|
||||
{
|
||||
// 先将该用户的所有角色设置为非默认
|
||||
baseMapper.updateNonDefaultRolesByUserId(userId);
|
||||
// 再将指定角色设置为默认
|
||||
AiUserRole aiUserRole = new AiUserRole();
|
||||
aiUserRole.setId(roleId);
|
||||
aiUserRole.setIsDefault(1);
|
||||
return baseMapper.updateAiUserRole(aiUserRole);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
import request from '@/utils/request'
|
||||
|
||||
// 查询用户AI角色列表
|
||||
export function listAiUserRole(query) {
|
||||
return request({
|
||||
url: '/api/ai-agent/aiUserRole/list',
|
||||
method: 'get',
|
||||
params: query
|
||||
})
|
||||
}
|
||||
|
||||
// 查询用户AI角色详细
|
||||
export function getAiUserRole(id) {
|
||||
return request({
|
||||
url: '/api/ai-agent/aiUserRole/' + id,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
// 新增用户AI角色
|
||||
export function addAiUserRole(data) {
|
||||
return request({
|
||||
url: '/api/ai-agent/aiUserRole',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 修改用户AI角色
|
||||
export function updateAiUserRole(data) {
|
||||
return request({
|
||||
url: '/api/ai-agent/aiUserRole',
|
||||
method: 'put',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 删除用户AI角色
|
||||
export function delAiUserRole(id) {
|
||||
return request({
|
||||
url: '/api/ai-agent/aiUserRole/' + id,
|
||||
method: 'delete'
|
||||
})
|
||||
}
|
||||
|
||||
// 批量删除用户AI角色
|
||||
export function delAiUserRoles(ids) {
|
||||
return request({
|
||||
url: '/api/ai-agent/aiUserRole/' + ids,
|
||||
method: 'delete'
|
||||
})
|
||||
}
|
||||
|
||||
// 设置默认角色
|
||||
export function setDefaultRole(id) {
|
||||
return request({
|
||||
url: '/api/ai-agent/aiUserRole/setDefault/' + id,
|
||||
method: 'put'
|
||||
})
|
||||
}
|
||||
|
|
@ -0,0 +1,351 @@
|
|||
<template>
|
||||
<div class="app-container">
|
||||
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
|
||||
<el-form-item label="用户名称" prop="userName">
|
||||
<el-input
|
||||
v-model="queryParams.userName"
|
||||
placeholder="请输入用户名称"
|
||||
clearable
|
||||
style="width: 240px"
|
||||
@keyup.enter.native="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="角色名称" prop="roleName">
|
||||
<el-input
|
||||
v-model="queryParams.roleName"
|
||||
placeholder="请输入角色名称"
|
||||
clearable
|
||||
style="width: 240px"
|
||||
@keyup.enter.native="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="是否默认" prop="isDefault">
|
||||
<el-select
|
||||
v-model="queryParams.isDefault"
|
||||
placeholder="是否默认角色"
|
||||
clearable
|
||||
style="width: 240px"
|
||||
>
|
||||
<el-option label="是" value="1" />
|
||||
<el-option label="否" value="0" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
||||
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<el-row :gutter="10" class="mb8">
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="primary"
|
||||
plain
|
||||
icon="el-icon-plus"
|
||||
size="mini"
|
||||
@click="handleAdd"
|
||||
>新增</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="success"
|
||||
plain
|
||||
icon="el-icon-edit"
|
||||
size="mini"
|
||||
:disabled="single"
|
||||
@click="handleUpdate"
|
||||
>修改</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="danger"
|
||||
plain
|
||||
icon="el-icon-delete"
|
||||
size="mini"
|
||||
:disabled="multiple"
|
||||
@click="handleDelete"
|
||||
>删除</el-button>
|
||||
</el-col>
|
||||
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
|
||||
</el-row>
|
||||
|
||||
<el-table v-loading="loading" :data="aiUserRoleList" @selection-change="handleSelectionChange">
|
||||
<el-table-column type="selection" width="50" align="center" />
|
||||
<el-table-column label="角色编号" align="center" prop="id" v-if="columns[0].visible" />
|
||||
<el-table-column label="用户ID" align="center" prop="userId" v-if="columns[1].visible" />
|
||||
<el-table-column label="用户名称" align="center" prop="userName" v-if="columns[2].visible" :show-overflow-tooltip="true" />
|
||||
<el-table-column label="角色名称" align="center" prop="roleName" v-if="columns[3].visible" :show-overflow-tooltip="true" />
|
||||
<el-table-column label="角色描述" align="center" prop="description" v-if="columns[4].visible" :show-overflow-tooltip="true" />
|
||||
<el-table-column label="是否默认" align="center" prop="isDefault" v-if="columns[5].visible">
|
||||
<template slot-scope="scope">
|
||||
<el-tag :type="scope.row.isDefault === 1 ? 'success' : 'info'">
|
||||
{{ scope.row.isDefault === 1 ? '是' : '否' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="创建时间" align="center" prop="createTime" v-if="columns[6].visible" width="160">
|
||||
<template slot-scope="scope">
|
||||
<span>{{ parseTime(scope.row.createTime) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
label="操作"
|
||||
align="center"
|
||||
width="180"
|
||||
class-name="small-padding fixed-width"
|
||||
>
|
||||
<template slot-scope="scope">
|
||||
<el-button
|
||||
size="mini"
|
||||
type="text"
|
||||
icon="el-icon-edit"
|
||||
@click="handleUpdate(scope.row)"
|
||||
>修改</el-button>
|
||||
<el-button
|
||||
size="mini"
|
||||
type="text"
|
||||
icon="el-icon-delete"
|
||||
@click="handleDelete(scope.row.id)"
|
||||
>删除</el-button>
|
||||
<el-button
|
||||
v-if="scope.row.isDefault !== 1"
|
||||
size="mini"
|
||||
type="text"
|
||||
icon="el-icon-star-on"
|
||||
@click="handleSetDefault(scope.row.id)"
|
||||
>设为默认</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<pagination
|
||||
v-show="total>0"
|
||||
:total="total"
|
||||
:page.sync="queryParams.pageNum"
|
||||
:limit.sync="queryParams.pageSize"
|
||||
@pagination="getList"
|
||||
/>
|
||||
|
||||
<!-- 添加或修改用户AI角色对话框 -->
|
||||
<el-dialog
|
||||
:title="title"
|
||||
:visible.sync="open"
|
||||
width="500px"
|
||||
append-to-body
|
||||
>
|
||||
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
|
||||
<el-form-item label="用户ID" prop="userId">
|
||||
<el-input v-model="form.userId" placeholder="请输入用户ID" />
|
||||
</el-form-item>
|
||||
<el-form-item label="角色名称" prop="roleName">
|
||||
<el-input v-model="form.roleName" placeholder="请输入角色名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="角色描述" prop="description">
|
||||
<el-input v-model="form.description" type="textarea" placeholder="请输入角色描述" :rows="3" />
|
||||
</el-form-item>
|
||||
<el-form-item label="是否默认">
|
||||
<el-switch v-model="form.isDefault" active-value="1" inactive-value="0" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button type="primary" @click="submitForm">确 定</el-button>
|
||||
<el-button @click="cancel">取 消</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { listAiUserRole, getAiUserRole, addAiUserRole, updateAiUserRole, delAiUserRole, setDefaultRole } from '@/api/ai/userRole'
|
||||
|
||||
export default {
|
||||
name: 'AiUserRole',
|
||||
data() {
|
||||
return {
|
||||
// 遮罩层
|
||||
loading: true,
|
||||
// 显示搜索条件
|
||||
showSearch: true,
|
||||
// 总条数
|
||||
total: 0,
|
||||
// 用户AI角色表格数据
|
||||
aiUserRoleList: [],
|
||||
// 弹出层标题
|
||||
title: '',
|
||||
// 是否显示弹出层
|
||||
open: false,
|
||||
// 查询参数
|
||||
queryParams: {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
userName: null,
|
||||
roleName: null,
|
||||
isDefault: null
|
||||
},
|
||||
// 表单参数
|
||||
form: {},
|
||||
// 表单校验
|
||||
rules: {
|
||||
userId: [
|
||||
{ required: true, message: '用户ID不能为空', trigger: 'blur' }
|
||||
],
|
||||
roleName: [
|
||||
{ required: true, message: '角色名称不能为空', trigger: 'blur' },
|
||||
{ min: 1, max: 200, message: '角色名称长度不能超过200个字符', trigger: 'blur' }
|
||||
],
|
||||
description: [
|
||||
{ max: 500, message: '角色描述长度不能超过500个字符', trigger: 'blur' }
|
||||
]
|
||||
},
|
||||
// 选中数组
|
||||
ids: [],
|
||||
// 非单个禁用
|
||||
single: true,
|
||||
// 非多个禁用
|
||||
multiple: true,
|
||||
// 显示列
|
||||
columns: [
|
||||
{ label: '角色编号', prop: 'id', visible: true },
|
||||
{ label: '用户ID', prop: 'userId', visible: true },
|
||||
{ label: '用户名称', prop: 'userName', visible: true },
|
||||
{ label: '角色名称', prop: 'roleName', visible: true },
|
||||
{ label: '角色描述', prop: 'description', visible: true },
|
||||
{ label: '是否默认', prop: 'isDefault', visible: true },
|
||||
{ label: '创建时间', prop: 'createTime', visible: true }
|
||||
]
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.getList()
|
||||
},
|
||||
methods: {
|
||||
/** 查询用户AI角色列表 */
|
||||
getList() {
|
||||
this.loading = true
|
||||
listAiUserRole(this.queryParams).then(response => {
|
||||
this.aiUserRoleList = response.rows
|
||||
this.total = response.total
|
||||
this.loading = false
|
||||
})
|
||||
},
|
||||
/** 搜索按钮操作 */
|
||||
handleQuery() {
|
||||
this.queryParams.pageNum = 1
|
||||
this.getList()
|
||||
},
|
||||
/** 重置按钮操作 */
|
||||
resetQuery() {
|
||||
this.$refs.queryForm.resetFields()
|
||||
this.handleQuery()
|
||||
},
|
||||
// 多选框选中数据
|
||||
handleSelectionChange(selection) {
|
||||
this.ids = selection.map(item => item.id)
|
||||
this.single = selection.length !== 1
|
||||
this.multiple = !selection.length
|
||||
},
|
||||
/** 新增按钮操作 */
|
||||
handleAdd() {
|
||||
this.reset()
|
||||
this.open = true
|
||||
this.title = '新增用户AI角色'
|
||||
},
|
||||
/** 修改按钮操作 */
|
||||
handleUpdate(row) {
|
||||
this.reset()
|
||||
const id = row.id || this.ids
|
||||
getAiUserRole(id).then(response => {
|
||||
this.form = response.data
|
||||
this.open = true
|
||||
this.title = '修改用户AI角色'
|
||||
})
|
||||
},
|
||||
/** 设置默认角色 */
|
||||
handleSetDefault(id) {
|
||||
this.$confirm('是否确认将该角色设置为默认角色?', '警告', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(function() {
|
||||
return setDefaultRole(id)
|
||||
}).then(() => {
|
||||
this.getList()
|
||||
this.$message({
|
||||
message: '设置成功',
|
||||
type: 'success'
|
||||
})
|
||||
}).catch(() => {
|
||||
this.$message({
|
||||
type: 'info',
|
||||
message: '已取消设置'
|
||||
})
|
||||
})
|
||||
},
|
||||
/** 表单重置 */
|
||||
reset() {
|
||||
this.form = {
|
||||
id: null,
|
||||
userId: null,
|
||||
userName: null,
|
||||
roleName: null,
|
||||
description: null,
|
||||
isDefault: 0
|
||||
}
|
||||
this.resetForm('form')
|
||||
},
|
||||
/** 提交按钮 */
|
||||
submitForm() {
|
||||
this.$refs['form'].validate(valid => {
|
||||
if (valid) {
|
||||
if (this.form.id != null) {
|
||||
updateAiUserRole(this.form).then(response => {
|
||||
this.$message({
|
||||
message: '修改成功',
|
||||
type: 'success'
|
||||
})
|
||||
this.open = false
|
||||
this.getList()
|
||||
})
|
||||
} else {
|
||||
addAiUserRole(this.form).then(response => {
|
||||
this.$message({
|
||||
message: '新增成功',
|
||||
type: 'success'
|
||||
})
|
||||
this.open = false
|
||||
this.getList()
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
/** 删除按钮操作 */
|
||||
handleDelete(id) {
|
||||
const ids = id || this.ids
|
||||
this.$confirm('是否确认删除用户AI角色?', '警告', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(function() {
|
||||
return delAiUserRole(ids)
|
||||
}).then(() => {
|
||||
this.getList()
|
||||
this.$message({
|
||||
message: '删除成功',
|
||||
type: 'success'
|
||||
})
|
||||
}).catch(() => {
|
||||
this.$message({
|
||||
type: 'info',
|
||||
message: '已取消删除'
|
||||
})
|
||||
})
|
||||
},
|
||||
/** 取消按钮 */
|
||||
cancel() {
|
||||
this.open = false
|
||||
this.reset()
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
Loading…
Reference in New Issue