增加 modal 更新

This commit is contained in:
cherishsince 2024-04-24 20:25:46 +08:00
parent 77f3226d27
commit e4eadd8c99
5 changed files with 33 additions and 0 deletions

View File

@ -28,4 +28,7 @@ public interface ErrorCodeConstants {
ErrorCode AI_MODAL_NOT_EXIST = new ErrorCode(1_022_000_060, "ai模型不存在!");
} }

View File

@ -51,5 +51,12 @@ public class AiChatModalController {
return CommonResult.success(null); return CommonResult.success(null);
} }
@Operation(summary = "ai模型 - 修改")
@PostMapping("/modal/{id}")
public CommonResult update(@PathVariable Long id,
@RequestBody @Validated AiChatModalAddReq req) {
aiChatModalService.update(id, req);
return CommonResult.success(null);
}
} }

View File

@ -17,4 +17,6 @@ public interface AiChatModalService {
PageResult<AiChatModalListRes> list(AiChatModalListReq req); PageResult<AiChatModalListRes> list(AiChatModalListReq req);
void add(AiChatModalAddReq req); void add(AiChatModalAddReq req);
void update(Long id, AiChatModalAddReq req);
} }

View File

@ -1,8 +1,10 @@
package cn.iocoder.yudao.module.ai.service.impl; package cn.iocoder.yudao.module.ai.service.impl;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.ai.ErrorCodeConstants;
import cn.iocoder.yudao.module.ai.convert.ChatModalConvert; import cn.iocoder.yudao.module.ai.convert.ChatModalConvert;
import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatModalDO; import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatModalDO;
import cn.iocoder.yudao.module.ai.enums.AiChatModalDisableEnum; import cn.iocoder.yudao.module.ai.enums.AiChatModalDisableEnum;
@ -56,4 +58,22 @@ public class AiChatModalServiceImpl implements AiChatModalService {
// 保存数据库 // 保存数据库
aiChatModalMapper.insert(insertChatModalDO); aiChatModalMapper.insert(insertChatModalDO);
} }
@Override
public void update(Long id, AiChatModalAddReq req) {
// 校验模型是否存在
validateChatModalExists(id);
// 转换 updateChatModalDO
AiChatModalDO updateChatModalDO = ChatModalConvert.INSTANCE.convertAiChatModalDO(req);
updateChatModalDO.setId(id);
// 更新数据库
aiChatModalMapper.updateById(updateChatModalDO);
}
private void validateChatModalExists(Long id) {
AiChatModalDO aiChatModalDO = aiChatModalMapper.selectById(id);
if (aiChatModalDO == null) {
throw ServiceExceptionUtil.exception(ErrorCodeConstants.AI_MODAL_NOT_EXIST);
}
}
} }

View File

@ -18,4 +18,5 @@ public class AiChatModalListReq extends PageParam {
@Schema(description = "名字搜搜") @Schema(description = "名字搜搜")
private String search; private String search;
} }