【新增】AI:聊天角色管理(80%)

This commit is contained in:
YunaiV 2024-05-13 21:47:58 +08:00
parent 1676f671d8
commit 31453e19d4
9 changed files with 27 additions and 30 deletions

View File

@ -78,7 +78,8 @@ public class AiChatModelController {
@Parameter(name = "status", description = "状态", required = true, example = "1") @Parameter(name = "status", description = "状态", required = true, example = "1")
public CommonResult<List<AiChatModelRespVO>> getChatModelSimpleList(@RequestParam("status") Integer status) { public CommonResult<List<AiChatModelRespVO>> getChatModelSimpleList(@RequestParam("status") Integer status) {
List<AiChatModelDO> list = chatModelService.getChatModelList(status); List<AiChatModelDO> list = chatModelService.getChatModelList(status);
return success(convertList(list, model -> new AiChatModelRespVO().setId(model.getId()).setName(model.getName()))); return success(convertList(list, model -> new AiChatModelRespVO().setId(model.getId())
.setName(model.getName()).setModel(model.getModel())));
} }
} }

View File

@ -1,28 +1,22 @@
package cn.iocoder.yudao.module.ai.controller.admin.model; package cn.iocoder.yudao.module.ai.controller.admin.model;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.ai.controller.admin.model.vo.role.AiChatRolePageReqVO; import cn.iocoder.yudao.module.ai.controller.admin.model.vo.chatRole.AiChatRolePageReqVO;
import cn.iocoder.yudao.module.ai.controller.admin.model.vo.role.AiChatRoleRespVO; import cn.iocoder.yudao.module.ai.controller.admin.model.vo.chatRole.AiChatRoleRespVO;
import cn.iocoder.yudao.module.ai.controller.admin.model.vo.role.AiChatRoleSaveReqVO; import cn.iocoder.yudao.module.ai.controller.admin.model.vo.chatRole.AiChatRoleSaveReqVO;
import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatRoleDO; import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatRoleDO;
import cn.iocoder.yudao.module.ai.service.model.AiChatRoleService; import cn.iocoder.yudao.module.ai.service.model.AiChatRoleService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - AI 聊天角色") @Tag(name = "管理后台 - AI 聊天角色")

View File

@ -1,13 +1,8 @@
package cn.iocoder.yudao.module.ai.controller.admin.model.vo.role; package cn.iocoder.yudao.module.ai.controller.admin.model.vo.chatRole;
import lombok.*; import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - AI 聊天角色分页 Request VO") @Schema(description = "管理后台 - AI 聊天角色分页 Request VO")
@Data @Data

View File

@ -1,5 +1,9 @@
package cn.iocoder.yudao.module.ai.controller.admin.model.vo.role; package cn.iocoder.yudao.module.ai.controller.admin.model.vo.chatRole;
import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModelDO;
import com.fhs.core.trans.anno.Trans;
import com.fhs.core.trans.constant.TransType;
import com.fhs.core.trans.vo.VO;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
@ -7,7 +11,7 @@ import java.time.LocalDateTime;
@Schema(description = "管理后台 - AI 聊天角色 Response VO") @Schema(description = "管理后台 - AI 聊天角色 Response VO")
@Data @Data
public class AiChatRoleRespVO { public class AiChatRoleRespVO implements VO {
@Schema(description = "角色编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "32746") @Schema(description = "角色编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "32746")
private Long id; private Long id;
@ -16,7 +20,12 @@ public class AiChatRoleRespVO {
private Long userId; private Long userId;
@Schema(description = "模型编号", example = "17640") @Schema(description = "模型编号", example = "17640")
@Trans(type = TransType.SIMPLE, target = AiChatModelDO.class, fields = {"name", "model"}, refs = {"modelName", "model"})
private Long modelId; private Long modelId;
@Schema(description = "模型名字", example = "张三")
private String modelName;
@Schema(description = "模型标识", example = "gpt-3.5-turbo-0125")
private String model;
@Schema(description = "角色名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四") @Schema(description = "角色名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
private String name; private String name;

View File

@ -1,11 +1,11 @@
package cn.iocoder.yudao.module.ai.controller.admin.model.vo.role; package cn.iocoder.yudao.module.ai.controller.admin.model.vo.chatRole;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.validation.InEnum; import cn.iocoder.yudao.framework.common.validation.InEnum;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*; import lombok.*;
import java.util.*;
import jakarta.validation.constraints.*; import jakarta.validation.constraints.*;
import org.hibernate.validator.constraints.URL;
@Schema(description = "管理后台 - AI 聊天角色新增/修改 Request VO") @Schema(description = "管理后台 - AI 聊天角色新增/修改 Request VO")
@Data @Data
@ -23,6 +23,7 @@ public class AiChatRoleSaveReqVO {
@Schema(description = "角色头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png") @Schema(description = "角色头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png")
@NotEmpty(message = "角色头像不能为空") @NotEmpty(message = "角色头像不能为空")
@URL(message = "角色头像必须是 URL 格式")
private String avatar; private String avatar;
@Schema(description = "角色类别", requiredMode = Schema.RequiredMode.REQUIRED, example = "创作") @Schema(description = "角色类别", requiredMode = Schema.RequiredMode.REQUIRED, example = "创作")

View File

@ -3,10 +3,9 @@ package cn.iocoder.yudao.module.ai.dal.mysql;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.ai.controller.admin.model.vo.role.AiChatRolePageReqVO; import cn.iocoder.yudao.module.ai.controller.admin.model.vo.chatRole.AiChatRolePageReqVO;
import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatRoleDO; import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatRoleDO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
/** /**
* AI 聊天角色 Mapper * AI 聊天角色 Mapper
@ -21,7 +20,7 @@ public interface AiChatRoleMapper extends BaseMapperX<AiChatRoleDO> {
.likeIfPresent(AiChatRoleDO::getName, reqVO.getName()) .likeIfPresent(AiChatRoleDO::getName, reqVO.getName())
.eqIfPresent(AiChatRoleDO::getCategory, reqVO.getCategory()) .eqIfPresent(AiChatRoleDO::getCategory, reqVO.getCategory())
.eqIfPresent(AiChatRoleDO::getPublicStatus, reqVO.getPublicStatus()) .eqIfPresent(AiChatRoleDO::getPublicStatus, reqVO.getPublicStatus())
.orderByDesc(AiChatRoleDO::getId)); .orderByAsc(AiChatRoleDO::getSort));
} }
} }

View File

@ -95,8 +95,7 @@ public class AiChatModelServiceImpl implements AiChatModelService {
@Override @Override
public List<AiChatModelDO> getChatModelList(Integer status) { public List<AiChatModelDO> getChatModelList(Integer status) {
chatModelMapper.selectList(status); return chatModelMapper.selectList(status);
return null;
} }
@Override @Override

View File

@ -1,8 +1,8 @@
package cn.iocoder.yudao.module.ai.service.model; package cn.iocoder.yudao.module.ai.service.model;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.ai.controller.admin.model.vo.role.AiChatRolePageReqVO; import cn.iocoder.yudao.module.ai.controller.admin.model.vo.chatRole.AiChatRolePageReqVO;
import cn.iocoder.yudao.module.ai.controller.admin.model.vo.role.AiChatRoleSaveReqVO; import cn.iocoder.yudao.module.ai.controller.admin.model.vo.chatRole.AiChatRoleSaveReqVO;
import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatRoleDO; import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatRoleDO;
import jakarta.validation.Valid; import jakarta.validation.Valid;

View File

@ -1,11 +1,10 @@
package cn.iocoder.yudao.module.ai.service.model; package cn.iocoder.yudao.module.ai.service.model;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.ai.controller.admin.model.vo.role.AiChatRolePageReqVO; import cn.iocoder.yudao.module.ai.controller.admin.model.vo.chatRole.AiChatRolePageReqVO;
import cn.iocoder.yudao.module.ai.controller.admin.model.vo.role.AiChatRoleSaveReqVO; import cn.iocoder.yudao.module.ai.controller.admin.model.vo.chatRole.AiChatRoleSaveReqVO;
import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatRoleDO; import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatRoleDO;
import cn.iocoder.yudao.module.ai.dal.mysql.AiChatRoleMapper; import cn.iocoder.yudao.module.ai.dal.mysql.AiChatRoleMapper;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;