From e39a6c3467489af442f8b4e54d20b3c9d5f11c46 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 10 Jul 2024 23:01:24 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BB=A3=E7=A0=81=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E3=80=91AI=EF=BC=9A=E5=86=99=E4=BD=9C=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-module-ai/yudao-module-ai-biz/pom.xml | 4 ++ .../admin/write/AiWriteController.java | 32 +++++++++-- .../admin/write/vo/AiWritePageReqVO.java | 33 ++++++++++++ .../admin/write/vo/AiWriteRespVO.java | 54 +++++++++++++++++++ .../ai/dal/mysql/write/AiWriteMapper.java | 15 +++++- .../ai/service/write/AiWriteService.java | 18 +++++++ .../ai/service/write/AiWriteServiceImpl.java | 23 ++++++++ 7 files changed, 174 insertions(+), 5 deletions(-) create mode 100644 yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/write/vo/AiWritePageReqVO.java create mode 100644 yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/write/vo/AiWriteRespVO.java diff --git a/yudao-module-ai/yudao-module-ai-biz/pom.xml b/yudao-module-ai/yudao-module-ai-biz/pom.xml index 7c529f118..a537b3db7 100644 --- a/yudao-module-ai/yudao-module-ai-biz/pom.xml +++ b/yudao-module-ai/yudao-module-ai-biz/pom.xml @@ -60,5 +60,9 @@ cn.iocoder.boot yudao-spring-boot-starter-test + + cn.iocoder.boot + yudao-spring-boot-starter-excel + \ No newline at end of file diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/write/AiWriteController.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/write/AiWriteController.java index c9023552e..d27204d21 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/write/AiWriteController.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/write/AiWriteController.java @@ -1,20 +1,25 @@ package cn.iocoder.yudao.module.ai.controller.admin.write; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.ai.controller.admin.write.vo.AiWriteGenerateReqVO; +import cn.iocoder.yudao.module.ai.controller.admin.write.vo.AiWritePageReqVO; +import cn.iocoder.yudao.module.ai.controller.admin.write.vo.AiWriteRespVO; +import cn.iocoder.yudao.module.ai.dal.dataobject.write.AiWriteDO; import cn.iocoder.yudao.module.ai.service.write.AiWriteService; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; import jakarta.annotation.security.PermitAll; import jakarta.validation.Valid; import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; import reactor.core.publisher.Flux; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; @Tag(name = "管理后台 - AI 写作") @@ -32,4 +37,23 @@ public class AiWriteController { return writeService.generateWriteContent(generateReqVO, getLoginUserId()); } + // ================ 写作管理 ================ + + @DeleteMapping("/delete") + @Operation(summary = "删除写作") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('ai:write:delete')") + public CommonResult deleteWrite(@RequestParam("id") Long id) { + writeService.deleteWrite(id); + return success(true); + } + + @GetMapping("/page") + @Operation(summary = "获得写作分页") + @PreAuthorize("@ss.hasPermission('ai:write:query')") + public CommonResult> getWritePage(@Valid AiWritePageReqVO pageReqVO) { + PageResult pageResult = writeService.getWritePage(pageReqVO); + return success(BeanUtils.toBean(pageResult, AiWriteRespVO.class)); + } + } diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/write/vo/AiWritePageReqVO.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/write/vo/AiWritePageReqVO.java new file mode 100644 index 000000000..047380e42 --- /dev/null +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/write/vo/AiWritePageReqVO.java @@ -0,0 +1,33 @@ +package cn.iocoder.yudao.module.ai.controller.admin.write.vo; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +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") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class AiWritePageReqVO extends PageParam { + + @Schema(description = "用户编号", example = "28404") + private Long userId; + + @Schema(description = "写作类型", example = "1") + private Integer type; + + @Schema(description = "平台", example = "TongYi") + private String platform; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + +} \ No newline at end of file diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/write/vo/AiWriteRespVO.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/write/vo/AiWriteRespVO.java new file mode 100644 index 000000000..4160de9ad --- /dev/null +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/write/vo/AiWriteRespVO.java @@ -0,0 +1,54 @@ +package cn.iocoder.yudao.module.ai.controller.admin.write.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.LocalDateTime; + +@Schema(description = "管理后台 - AI 写作 Response VO") +@Data +public class AiWriteRespVO { + + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "5311") + private Long id; + + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "28404") + private Long userId; + + @Schema(description = "写作类型", example = "1") + private Integer type; + + @Schema(description = "平台", requiredMode = Schema.RequiredMode.REQUIRED, example = "TongYi") + private String platform; + + @Schema(description = "模型", requiredMode = Schema.RequiredMode.REQUIRED, example = "qwen") + private String model; + + @Schema(description = "生成内容提示", requiredMode = Schema.RequiredMode.REQUIRED, example = "撰写:田忌赛马") + private String prompt; + + @Schema(description = "生成的内容", example = "你非常不错") + private String generatedContent; + + @Schema(description = "原文", example = "真的么?") + private String originalContent; + + @Schema(description = "长度提示词", example = "1") + private Integer length; + + @Schema(description = "格式提示词", example = "2") + private Integer format; + + @Schema(description = "语气提示词", example = "3") + private Integer tone; + + @Schema(description = "语言提示词", example = "4") + private Integer language; + + @Schema(description = "错误信息") + private String errorMessage; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + private LocalDateTime createTime; + +} \ No newline at end of file diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/write/AiWriteMapper.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/write/AiWriteMapper.java index 9564466eb..c4983eb44 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/write/AiWriteMapper.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/write/AiWriteMapper.java @@ -1,14 +1,27 @@ package cn.iocoder.yudao.module.ai.dal.mysql.write; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.ai.controller.admin.write.vo.AiWritePageReqVO; import cn.iocoder.yudao.module.ai.dal.dataobject.write.AiWriteDO; import org.apache.ibatis.annotations.Mapper; /** - * AI 音乐 Mapper + * AI 写作 Mapper * * @author xiaoxin */ @Mapper public interface AiWriteMapper extends BaseMapperX { + + default PageResult selectPage(AiWritePageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(AiWriteDO::getUserId, reqVO.getUserId()) + .eqIfPresent(AiWriteDO::getType, reqVO.getType()) + .eqIfPresent(AiWriteDO::getPlatform, reqVO.getPlatform()) + .betweenIfPresent(AiWriteDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(AiWriteDO::getId)); + } + } diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/write/AiWriteService.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/write/AiWriteService.java index b92c9c151..f2dd489ff 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/write/AiWriteService.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/write/AiWriteService.java @@ -1,7 +1,10 @@ package cn.iocoder.yudao.module.ai.service.write; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.ai.controller.admin.write.vo.AiWriteGenerateReqVO; +import cn.iocoder.yudao.module.ai.controller.admin.write.vo.AiWritePageReqVO; +import cn.iocoder.yudao.module.ai.dal.dataobject.write.AiWriteDO; import reactor.core.publisher.Flux; /** @@ -20,4 +23,19 @@ public interface AiWriteService { */ Flux> generateWriteContent(AiWriteGenerateReqVO generateReqVO, Long userId); + /** + * 删除写作 + * + * @param id 编号 + */ + void deleteWrite(Long id); + + /** + * 获得写作分页 + * + * @param pageReqVO 分页查询 + * @return AI 写作分页 + */ + PageResult getWritePage(AiWritePageReqVO pageReqVO); + } diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/write/AiWriteServiceImpl.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/write/AiWriteServiceImpl.java index 5d23f1c12..b03a90ab7 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/write/AiWriteServiceImpl.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/write/AiWriteServiceImpl.java @@ -5,9 +5,11 @@ import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.ai.core.enums.AiPlatformEnum; import cn.iocoder.yudao.framework.ai.core.util.AiUtils; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; import cn.iocoder.yudao.module.ai.controller.admin.write.vo.AiWriteGenerateReqVO; +import cn.iocoder.yudao.module.ai.controller.admin.write.vo.AiWritePageReqVO; import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModelDO; import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatRoleDO; import cn.iocoder.yudao.module.ai.dal.dataobject.write.AiWriteDO; @@ -36,8 +38,10 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.error; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.module.ai.enums.ErrorCodeConstants.WRITE_NOT_EXISTS; /** * AI 写作 Service 实现类 @@ -132,4 +136,23 @@ public class AiWriteServiceImpl implements AiWriteService { } } + @Override + public void deleteWrite(Long id) { + // 校验存在 + validateWriteExists(id); + // 删除 + writeMapper.deleteById(id); + } + + private void validateWriteExists(Long id) { + if (writeMapper.selectById(id) == null) { + throw exception(WRITE_NOT_EXISTS); + } + } + + @Override + public PageResult getWritePage(AiWritePageReqVO pageReqVO) { + return writeMapper.selectPage(pageReqVO); + } + }