diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/file/FileCreateRespVo.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/file/FileCreateRespVo.java index f8eec5d6c..e629e7623 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/file/FileCreateRespVo.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/file/FileCreateRespVo.java @@ -12,4 +12,5 @@ import lombok.NoArgsConstructor; public class FileCreateRespVo { private String url; private Long id; + private String fileName; } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java index 417112421..82e10cb1b 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java @@ -142,6 +142,7 @@ public class FileServiceImpl implements FileService { FileCreateRespVo fileCreateRespVo = new FileCreateRespVo(); fileCreateRespVo.setUrl(url); fileCreateRespVo.setId(file.getId()); + fileCreateRespVo.setFileName(name); return fileCreateRespVo; } } diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/learningresources/LearningResourcesController.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/learningresources/LearningResourcesController.java new file mode 100644 index 000000000..6c4ed8523 --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/learningresources/LearningResourcesController.java @@ -0,0 +1,103 @@ +package cn.iocoder.yudao.module.llm.controller.admin.learningresources; + +import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.security.access.prepost.PreAuthorize; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Operation; + +import javax.annotation.security.PermitAll; +import javax.validation.constraints.*; +import javax.validation.*; +import javax.servlet.http.*; +import java.util.*; +import java.io.IOException; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; + +import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; +import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*; + +import cn.iocoder.yudao.module.llm.controller.admin.learningresources.vo.*; +import cn.iocoder.yudao.module.llm.dal.dataobject.learningresources.LearningResourcesDO; +import cn.iocoder.yudao.module.llm.service.learningresources.LearningResourcesService; + +@Tag(name = "管理后台 - 学习资源") +@RestController +@RequestMapping("/llm/learning-resources") +@Validated +public class LearningResourcesController { + + @Resource + private LearningResourcesService learningResourcesService; + + @PostMapping("/create") + @Operation(summary = "创建学习资源") + @PreAuthorize("@ss.hasPermission('llm:learning-resources:create')") + public CommonResult createLearningResources(@Valid @RequestBody LearningResourcesSaveReqVO createReqVO) { + return success(learningResourcesService.createLearningResources(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新学习资源") + @PreAuthorize("@ss.hasPermission('llm:learning-resources:update')") + public CommonResult updateLearningResources(@Valid @RequestBody LearningResourcesSaveReqVO updateReqVO) { + learningResourcesService.updateLearningResources(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除学习资源") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('llm:learning-resources:delete')") + public CommonResult deleteLearningResources(@RequestParam("id") Long id) { + learningResourcesService.deleteLearningResources(id); + return success(true); + } + + @GetMapping("/down/{id}") + @Operation(summary = "学习资源下载") + @PermitAll + public CommonResult downLearningResources(@PathVariable Long id) { + return success(learningResourcesService.downLearningResources(id)); + } + @GetMapping("/get") + @Operation(summary = "获得学习资源") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('llm:learning-resources:query')") + public CommonResult getLearningResources(@RequestParam("id") Long id) { + + LearningResourcesDO learningResources = learningResourcesService.getLearningResources(id); + return success(BeanUtils.toBean(learningResources, LearningResourcesRespVO.class)); + } + + @GetMapping("/page") + @Operation(summary = "获得学习资源分页") + @PreAuthorize("@ss.hasPermission('llm:learning-resources:query')") + public CommonResult> getLearningResourcesPage(@Valid LearningResourcesPageReqVO pageReqVO) { + PageResult pageResult = learningResourcesService.getLearningResourcesPage(pageReqVO); + return success(BeanUtils.toBean(pageResult, LearningResourcesRespVO.class)); + } + + @GetMapping("/export-excel") + @Operation(summary = "导出学习资源 Excel") + @PreAuthorize("@ss.hasPermission('llm:learning-resources:export')") + @ApiAccessLog(operateType = EXPORT) + public void exportLearningResourcesExcel(@Valid LearningResourcesPageReqVO pageReqVO, + HttpServletResponse response) throws IOException { + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = learningResourcesService.getLearningResourcesPage(pageReqVO).getList(); + // 导出 Excel + ExcelUtils.write(response, "学习资源.xls", "数据", LearningResourcesRespVO.class, + BeanUtils.toBean(list, LearningResourcesRespVO.class)); + } + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/learningresources/vo/LearningResourcesPageReqVO.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/learningresources/vo/LearningResourcesPageReqVO.java new file mode 100644 index 000000000..ff4407cb7 --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/learningresources/vo/LearningResourcesPageReqVO.java @@ -0,0 +1,37 @@ +package cn.iocoder.yudao.module.llm.controller.admin.learningresources.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +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 = "管理后台 - 学习资源分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class LearningResourcesPageReqVO extends PageParam { + + @Schema(description = "资源类型,使用字典(llm_learning_resource)") + private Integer resourceCategory; + + @Schema(description = "资源标题") + private String resourceTitle; + + @Schema(description = "资源简介") + private String resourceIntro; + + @Schema(description = "文件ID", example = "6506") + private Long fileId; + + @Schema(description = "文件URL地址", example = "https://www.iocoder.cn") + private String fileUrl; + + @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-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/learningresources/vo/LearningResourcesRespVO.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/learningresources/vo/LearningResourcesRespVO.java new file mode 100644 index 000000000..ade27ae34 --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/learningresources/vo/LearningResourcesRespVO.java @@ -0,0 +1,50 @@ +package cn.iocoder.yudao.module.llm.controller.admin.learningresources.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; +import com.alibaba.excel.annotation.*; + +@Schema(description = "管理后台 - 学习资源 Response VO") +@Data +@ExcelIgnoreUnannotated +public class LearningResourcesRespVO { + + @Schema(description = "学习资源ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "8718") + @ExcelProperty("学习资源ID") + private Long id; + + @Schema(description = "资源类型,使用字典(llm_learning_resource)") + @ExcelProperty("资源类型,使用字典(llm_learning_resource)") + private Integer resourceCategory; + + @Schema(description = "资源标题") + @ExcelProperty("资源标题") + private String resourceTitle; + + @Schema(description = "资源简介") + @ExcelProperty("资源简介") + private String resourceIntro; + + @Schema(description = "文件ID", example = "6506") + @ExcelProperty("文件ID") + private Long fileId; + + @Schema(description = "文件URL地址,视频封面图", example = "https://www.iocoder.cn") + @ExcelProperty("文件URL地址") + private String fileUrl; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") + private LocalDateTime createTime; + + @Schema(description = "文件名称,视频链接",example = "https://www.test.com/ll/l1.png") + private String fileName; + + @Schema(description = "下载量",example = "0") + @ExcelProperty("下载量") + private Integer downCount; + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/learningresources/vo/LearningResourcesSaveReqVO.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/learningresources/vo/LearningResourcesSaveReqVO.java new file mode 100644 index 000000000..d0440c355 --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/learningresources/vo/LearningResourcesSaveReqVO.java @@ -0,0 +1,36 @@ +package cn.iocoder.yudao.module.llm.controller.admin.learningresources.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import javax.validation.constraints.*; + +@Schema(description = "管理后台 - 学习资源新增/修改 Request VO") +@Data +public class LearningResourcesSaveReqVO { + + @Schema(description = "学习资源ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "8718") + private Long id; + + @Schema(description = "资源类型,使用字典(llm_learning_resource)") + private Integer resourceCategory; + + @Schema(description = "资源标题") + private String resourceTitle; + + @Schema(description = "资源简介") + private String resourceIntro; + + @Schema(description = "文件ID", example = "6506") + private Long fileId; + + @Schema(description = "文件URL地址,视频封面图", example = "https://www.iocoder.cn") + private String fileUrl; + + @Schema(description = "文件名称,视频链接",example = "https://www.test.com") + private String fileName; + + @Schema(description = "下载量",example = "0") + private Integer downCount; + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/dataobject/learningresources/LearningResourcesDO.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/dataobject/learningresources/LearningResourcesDO.java new file mode 100644 index 000000000..f514cf3aa --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/dataobject/learningresources/LearningResourcesDO.java @@ -0,0 +1,62 @@ +package cn.iocoder.yudao.module.llm.dal.dataobject.learningresources; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import com.baomidou.mybatisplus.annotation.*; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; + +/** + * 学习资源 DO + * + * @author 华大大模型 + */ +@TableName("llm_learning_resources") +@KeySequence("llm_learning_resources_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class LearningResourcesDO extends BaseDO { + + /** + * 学习资源ID + */ + @TableId + private Long id; + /** + * 资源类型,使用字典(llm_learning_resource) + */ + private Integer resourceCategory; + /** + * 资源标题 + */ + private String resourceTitle; + /** + * 资源简介 + */ + private String resourceIntro; + /** + * 文件ID + */ + private Long fileId; + /** + * 文件URL地址 + */ + private String fileUrl; + + /** + * 视频封面图 + */ + private String fileName;; + + /** + * 下载量 + */ + private Integer downCount; + +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/mysql/learningresources/LearningResourcesMapper.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/mysql/learningresources/LearningResourcesMapper.java new file mode 100644 index 000000000..892f7e5b0 --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/dal/mysql/learningresources/LearningResourcesMapper.java @@ -0,0 +1,33 @@ +package cn.iocoder.yudao.module.llm.dal.mysql.learningresources; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.llm.dal.dataobject.learningresources.LearningResourcesDO; +import org.apache.ibatis.annotations.Mapper; +import cn.iocoder.yudao.module.llm.controller.admin.learningresources.vo.*; +import org.apache.ibatis.annotations.Update; + +/** + * 学习资源 Mapper + * + * @author 华大大模型 + */ +@Mapper +public interface LearningResourcesMapper extends BaseMapperX { + + default PageResult selectPage(LearningResourcesPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(LearningResourcesDO::getResourceCategory, reqVO.getResourceCategory()) + .eqIfPresent(LearningResourcesDO::getResourceTitle, reqVO.getResourceTitle()) + .eqIfPresent(LearningResourcesDO::getResourceIntro, reqVO.getResourceIntro()) + .eqIfPresent(LearningResourcesDO::getFileId, reqVO.getFileId()) + .eqIfPresent(LearningResourcesDO::getFileUrl, reqVO.getFileUrl()) + .betweenIfPresent(LearningResourcesDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(LearningResourcesDO::getId)); + } + @Update("update llm_learning_resources set down_count = down_count + 1 where id = #{id}") + void updateDownCount(LearningResourcesDO learningResourcesDO); +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/learningresources/LearningResourcesService.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/learningresources/LearningResourcesService.java new file mode 100644 index 000000000..e3b3d75ce --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/learningresources/LearningResourcesService.java @@ -0,0 +1,57 @@ +package cn.iocoder.yudao.module.llm.service.learningresources; + +import java.util.*; +import javax.servlet.http.HttpServletResponse; +import javax.validation.*; +import cn.iocoder.yudao.module.llm.controller.admin.learningresources.vo.*; +import cn.iocoder.yudao.module.llm.dal.dataobject.learningresources.LearningResourcesDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; + +/** + * 学习资源 Service 接口 + * + * @author 华大大模型 + */ +public interface LearningResourcesService { + + /** + * 创建学习资源 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createLearningResources(@Valid LearningResourcesSaveReqVO createReqVO); + + /** + * 更新学习资源 + * + * @param updateReqVO 更新信息 + */ + void updateLearningResources(@Valid LearningResourcesSaveReqVO updateReqVO); + + /** + * 删除学习资源 + * + * @param id 编号 + */ + void deleteLearningResources(Long id); + + /** + * 获得学习资源 + * + * @param id 编号 + * @return 学习资源 + */ + LearningResourcesDO getLearningResources(Long id); + + /** + * 获得学习资源分页 + * + * @param pageReqVO 分页查询 + * @return 学习资源分页 + */ + PageResult getLearningResourcesPage(LearningResourcesPageReqVO pageReqVO); + + String downLearningResources(Long id); +} \ No newline at end of file diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/learningresources/LearningResourcesServiceImpl.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/learningresources/LearningResourcesServiceImpl.java new file mode 100644 index 000000000..d4dc60b8a --- /dev/null +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/learningresources/LearningResourcesServiceImpl.java @@ -0,0 +1,86 @@ +package cn.iocoder.yudao.module.llm.service.learningresources; + +import cn.hutool.core.util.StrUtil; +import cn.hutool.core.util.URLUtil; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.validation.annotation.Validated; +import org.springframework.transaction.annotation.Transactional; + +import java.util.*; +import cn.iocoder.yudao.module.llm.controller.admin.learningresources.vo.*; +import cn.iocoder.yudao.module.llm.dal.dataobject.learningresources.LearningResourcesDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; + +import cn.iocoder.yudao.module.llm.dal.mysql.learningresources.LearningResourcesMapper; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.llm.enums.ErrorCodeConstants.*; +import static jdk.nashorn.internal.runtime.regexp.joni.Config.log; + +/** + * 学习资源 Service 实现类 + * + * @author 华大大模型 + */ +@Service +@Validated +public class LearningResourcesServiceImpl implements LearningResourcesService { + + @Resource + private LearningResourcesMapper learningResourcesMapper; + + @Override + public Long createLearningResources(LearningResourcesSaveReqVO createReqVO) { + // 插入 + LearningResourcesDO learningResources = BeanUtils.toBean(createReqVO, LearningResourcesDO.class); + learningResourcesMapper.insert(learningResources); + // 返回 + return learningResources.getId(); + } + + @Override + public void updateLearningResources(LearningResourcesSaveReqVO updateReqVO) { + // 校验存在 + validateLearningResourcesExists(updateReqVO.getId()); + // 更新 + LearningResourcesDO updateObj = BeanUtils.toBean(updateReqVO, LearningResourcesDO.class); + learningResourcesMapper.updateById(updateObj); + } + + @Override + public void deleteLearningResources(Long id) { + // 校验存在 + validateLearningResourcesExists(id); + // 删除 + learningResourcesMapper.deleteById(id); + } + + private void validateLearningResourcesExists(Long id) { + if (learningResourcesMapper.selectById(id) == null) { + throw exception(LEARNING_RESOURCES_NOT_EXISTS); + } + } + + @Override + public LearningResourcesDO getLearningResources(Long id) { + return learningResourcesMapper.selectById(id); + } + + @Override + public PageResult getLearningResourcesPage(LearningResourcesPageReqVO pageReqVO) { + return learningResourcesMapper.selectPage(pageReqVO); + } + + @Override + public String downLearningResources(Long id){ + LearningResourcesDO learningResourcesDO = learningResourcesMapper.selectById(id); + learningResourcesMapper.updateDownCount(learningResourcesDO); + return learningResourcesDO.getFileUrl(); + } +} \ No newline at end of file