[update] 总览视频封面图必填校验

This commit is contained in:
Liuyang 2025-02-05 16:28:26 +08:00
parent c7c648bbaf
commit 1cc30f38c2
3 changed files with 47 additions and 26 deletions

View File

@ -34,6 +34,7 @@ public interface ErrorCodeConstants {
ErrorCode LEARNING_RESOURCES_NOT_EXISTS = new ErrorCode(10015, "学习资源不存在");
ErrorCode LEARNING_RESOURCES_FILE_URL_NOT_NULL = new ErrorCode(10016, "文件地址不能为空");
ErrorCode VIDEO_COVER_IMAGE_EMPTY = new ErrorCode(10016_1, "视频封面图不能为空");
/*
ErrorCode DATASET_FILES_NOT_EXISTS = new ErrorCode(10016, "数据集文件资源不存在");
ErrorCode DATASET_QUESTION_NOT_EXISTS = new ErrorCode(10017, "数据集标准问题不存在");

View File

@ -23,11 +23,11 @@ public class LearningResourcesSaveReqVO {
@Schema(description = "文件ID", example = "6506")
private Long fileId;
@Schema(description = "文件URL地址、视频封面图", example = "https://www.iocoder.cn")
@Schema(description = "文件URL地址", example = "https://www.iocoder.cn")
@JsonDeserialize(using = cn.iocoder.yudao.module.llm.controller.admin.learningresources.vo.StringArrayDeserializer.class)
private String fileUrl;
@Schema(description = "文件名称,视频链接", example = "https://www.test.com")
@Schema(description = "文件名称,视频链接,视频封面图", example = "https://www.test.com")
private String fileName;
@Schema(description = "下载量", example = "0")

View File

@ -1,24 +1,22 @@
package cn.iocoder.yudao.module.llm.service.learningresources;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.llm.controller.admin.learningresources.vo.LearningResourcesPageReqVO;
import cn.iocoder.yudao.module.llm.controller.admin.learningresources.vo.LearningResourcesSaveReqVO;
import cn.iocoder.yudao.module.llm.dal.dataobject.learningresources.LearningResourcesDO;
import cn.iocoder.yudao.module.llm.dal.mysql.learningresources.LearningResourcesMapper;
import cn.iocoder.yudao.module.llm.service.basemodel.BaseModelService;
import cn.iocoder.yudao.module.llm.service.modelservice.ModelServiceService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
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.util.object.BeanUtils;
import cn.iocoder.yudao.module.llm.dal.mysql.learningresources.LearningResourcesMapper;
import javax.annotation.Resource;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.llm.enums.ErrorCodeConstants.*;
@ -42,10 +40,14 @@ public class LearningResourcesServiceImpl implements LearningResourcesService {
private ModelServiceService modelServiceService;
@Override
public Long createLearningResources(LearningResourcesSaveReqVO createReqVO) {
if (StringUtils.isBlank(createReqVO.getFileUrl())){
public Long createLearningResources (LearningResourcesSaveReqVO createReqVO) {
if (StringUtils.isBlank(createReqVO.getFileUrl())) {
throw exception(LEARNING_RESOURCES_FILE_URL_NOT_NULL);
}
// 校验视频封面图
validVideoCoverImage(createReqVO);
validateLearningResourcesNameExists(createReqVO);
// 插入
LearningResourcesDO learningResources = BeanUtils.toBean(createReqVO, LearningResourcesDO.class);
@ -54,58 +56,75 @@ public class LearningResourcesServiceImpl implements LearningResourcesService {
return learningResources.getId();
}
/**
* 校验视频封面图
*/
private static void validVideoCoverImage (LearningResourcesSaveReqVO createReqVO) {
if (createReqVO.getResourceCategory() == 1) {
if (StringUtils.isBlank(createReqVO.getFileName())) {
throw exception(VIDEO_COVER_IMAGE_EMPTY);
}
}
}
@Override
public void updateLearningResources(LearningResourcesSaveReqVO updateReqVO) {
public void updateLearningResources (LearningResourcesSaveReqVO updateReqVO) {
// 校验存在
validateLearningResourcesExists(updateReqVO.getId());
validateLearningResourcesNameExists(updateReqVO);
if (StringUtils.isBlank(updateReqVO.getFileUrl())){
if (StringUtils.isBlank(updateReqVO.getFileUrl())) {
throw exception(LEARNING_RESOURCES_FILE_URL_NOT_NULL);
}
// 校验视频封面图
validVideoCoverImage(updateReqVO);
// 更新
LearningResourcesDO updateObj = BeanUtils.toBean(updateReqVO, LearningResourcesDO.class);
learningResourcesMapper.updateById(updateObj);
}
@Override
public void deleteLearningResources(Long id) {
public void deleteLearningResources (Long id) {
// 校验存在
validateLearningResourcesExists(id);
// 删除
learningResourcesMapper.deleteById(id);
}
private void validateLearningResourcesExists(Long id) {
private void validateLearningResourcesExists (Long id) {
if (learningResourcesMapper.selectById(id) == null) {
throw exception(LEARNING_RESOURCES_NOT_EXISTS);
}
}
private void validateLearningResourcesNameExists(LearningResourcesSaveReqVO reqVO) {
private void validateLearningResourcesNameExists (LearningResourcesSaveReqVO reqVO) {
LambdaQueryWrapper<LearningResourcesDO> wrapper = new LambdaQueryWrapper<LearningResourcesDO>()
.eq(LearningResourcesDO::getResourceTitle, reqVO.getResourceTitle())
.eq(LearningResourcesDO::getResourceCategory, reqVO.getResourceCategory());
if (reqVO.getId() != null){
if (reqVO.getId() != null) {
wrapper.ne(LearningResourcesDO::getId, reqVO.getId());
}
List<LearningResourcesDO> learningResourcesDOS = learningResourcesMapper.selectList(wrapper);
if (CollectionUtils.isNotEmpty(learningResourcesDOS)){
if (CollectionUtils.isNotEmpty(learningResourcesDOS)) {
throw exception(LEARNING_RESOURCES_NAME_NOT_EXISTS);
}
}
@Override
public LearningResourcesDO getLearningResources(Long id) {
public LearningResourcesDO getLearningResources (Long id) {
return learningResourcesMapper.selectById(id);
}
@Override
public PageResult<LearningResourcesDO> getLearningResourcesPage(LearningResourcesPageReqVO pageReqVO) {
public PageResult<LearningResourcesDO> getLearningResourcesPage (LearningResourcesPageReqVO pageReqVO) {
return learningResourcesMapper.selectPage(pageReqVO);
}
@Override
public String downLearningResources(Long id){
public String downLearningResources (Long id) {
LearningResourcesDO learningResourcesDO = learningResourcesMapper.selectById(id);
learningResourcesMapper.updateDownCount(learningResourcesDO);
return learningResourcesDO.getFileUrl();
@ -118,7 +137,7 @@ public class LearningResourcesServiceImpl implements LearningResourcesService {
* @param updateReqVO 更新信息
*/
@Override
public void videoViewsUpdate(LearningResourcesSaveReqVO updateReqVO) {
public void videoViewsUpdate (LearningResourcesSaveReqVO updateReqVO) {
Long id = updateReqVO.getId();
if (id == null) {
@ -137,8 +156,9 @@ public class LearningResourcesServiceImpl implements LearningResourcesService {
/**
* 获得容器数量
* <p>
* 容器数量 = 模型服务管理 + 模型管理
* 容器数量 = 模型服务管理 + 模型管理
* </p>
*
* @return 容器数量
*/
@Override