学习资源增加
This commit is contained in:
parent
c7d2dda504
commit
505509b4a3
@ -12,4 +12,5 @@ import lombok.NoArgsConstructor;
|
||||
public class FileCreateRespVo {
|
||||
private String url;
|
||||
private Long id;
|
||||
private String fileName;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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<Long> createLearningResources(@Valid @RequestBody LearningResourcesSaveReqVO createReqVO) {
|
||||
return success(learningResourcesService.createLearningResources(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新学习资源")
|
||||
@PreAuthorize("@ss.hasPermission('llm:learning-resources:update')")
|
||||
public CommonResult<Boolean> 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<Boolean> deleteLearningResources(@RequestParam("id") Long id) {
|
||||
learningResourcesService.deleteLearningResources(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/down/{id}")
|
||||
@Operation(summary = "学习资源下载")
|
||||
@PermitAll
|
||||
public CommonResult<String> 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<LearningResourcesRespVO> 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<PageResult<LearningResourcesRespVO>> getLearningResourcesPage(@Valid LearningResourcesPageReqVO pageReqVO) {
|
||||
PageResult<LearningResourcesDO> 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<LearningResourcesDO> list = learningResourcesService.getLearningResourcesPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "学习资源.xls", "数据", LearningResourcesRespVO.class,
|
||||
BeanUtils.toBean(list, LearningResourcesRespVO.class));
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
|
||||
}
|
@ -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;
|
||||
|
||||
}
|
@ -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;
|
||||
|
||||
}
|
@ -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;
|
||||
|
||||
}
|
@ -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<LearningResourcesDO> {
|
||||
|
||||
default PageResult<LearningResourcesDO> selectPage(LearningResourcesPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<LearningResourcesDO>()
|
||||
.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);
|
||||
}
|
@ -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<LearningResourcesDO> getLearningResourcesPage(LearningResourcesPageReqVO pageReqVO);
|
||||
|
||||
String downLearningResources(Long id);
|
||||
}
|
@ -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<LearningResourcesDO> getLearningResourcesPage(LearningResourcesPageReqVO pageReqVO) {
|
||||
return learningResourcesMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String downLearningResources(Long id){
|
||||
LearningResourcesDO learningResourcesDO = learningResourcesMapper.selectById(id);
|
||||
learningResourcesMapper.updateDownCount(learningResourcesDO);
|
||||
return learningResourcesDO.getFileUrl();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user