mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 18:28:43 +08:00 
			
		
		
		
	【代码新增】AI:写作管理界面
This commit is contained in:
		| @@ -60,5 +60,9 @@ | ||||
|             <groupId>cn.iocoder.boot</groupId> | ||||
|             <artifactId>yudao-spring-boot-starter-test</artifactId> | ||||
|         </dependency> | ||||
|         <dependency> | ||||
|             <groupId>cn.iocoder.boot</groupId> | ||||
|             <artifactId>yudao-spring-boot-starter-excel</artifactId> | ||||
|         </dependency> | ||||
|     </dependencies> | ||||
| </project> | ||||
| @@ -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<Boolean> deleteWrite(@RequestParam("id") Long id) { | ||||
|         writeService.deleteWrite(id); | ||||
|         return success(true); | ||||
|     } | ||||
|  | ||||
|     @GetMapping("/page") | ||||
|     @Operation(summary = "获得写作分页") | ||||
|     @PreAuthorize("@ss.hasPermission('ai:write:query')") | ||||
|     public CommonResult<PageResult<AiWriteRespVO>> getWritePage(@Valid AiWritePageReqVO pageReqVO) { | ||||
|         PageResult<AiWriteDO> pageResult = writeService.getWritePage(pageReqVO); | ||||
|         return success(BeanUtils.toBean(pageResult, AiWriteRespVO.class)); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -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; | ||||
|  | ||||
| } | ||||
| @@ -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; | ||||
|  | ||||
| } | ||||
| @@ -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<AiWriteDO> { | ||||
|  | ||||
|     default PageResult<AiWriteDO> selectPage(AiWritePageReqVO reqVO) { | ||||
|         return selectPage(reqVO, new LambdaQueryWrapperX<AiWriteDO>() | ||||
|                 .eqIfPresent(AiWriteDO::getUserId, reqVO.getUserId()) | ||||
|                 .eqIfPresent(AiWriteDO::getType, reqVO.getType()) | ||||
|                 .eqIfPresent(AiWriteDO::getPlatform, reqVO.getPlatform()) | ||||
|                 .betweenIfPresent(AiWriteDO::getCreateTime, reqVO.getCreateTime()) | ||||
|                 .orderByDesc(AiWriteDO::getId)); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -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<CommonResult<String>> generateWriteContent(AiWriteGenerateReqVO generateReqVO, Long userId); | ||||
|  | ||||
|     /** | ||||
|      * 删除写作 | ||||
|      * | ||||
|      * @param id 编号 | ||||
|      */ | ||||
|     void deleteWrite(Long id); | ||||
|  | ||||
|     /** | ||||
|      * 获得写作分页 | ||||
|      * | ||||
|      * @param pageReqVO 分页查询 | ||||
|      * @return AI 写作分页 | ||||
|      */ | ||||
|     PageResult<AiWriteDO> getWritePage(AiWritePageReqVO pageReqVO); | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -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<AiWriteDO> getWritePage(AiWritePageReqVO pageReqVO) { | ||||
|         return writeMapper.selectPage(pageReqVO); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV