视频增加封面

This commit is contained in:
none 2023-03-08 13:42:25 +08:00
parent 5e9a8ecd40
commit 1486e518cc
7 changed files with 34 additions and 14 deletions

View File

@ -76,9 +76,9 @@ public class ResourceController {
data.put("result", result);
if (type.equals(BackendConstant.RESOURCE_TYPE_VIDEO)) {
List<ResourceVideo> resourceVideos = resourceVideoService.chunksByResourceIds(result.getData().stream().map(Resource::getId).collect(Collectors.toList()));
Map<Integer, Integer> resourceVideosMap = resourceVideos.stream().collect(Collectors.toMap(ResourceVideo::getRid, ResourceVideo::getDuration));
data.put("video_duration", resourceVideosMap);
List<ResourceVideo> resourceVideos = resourceVideoService.chunksByRids(result.getData().stream().map(Resource::getId).toList());
Map<Integer, ResourceVideo> resourceVideosExtra = resourceVideos.stream().collect(Collectors.toMap(ResourceVideo::getRid, e -> e));
data.put("videos_extra", resourceVideosExtra);
}
return JsonResponse.data(data);
@ -109,17 +109,21 @@ public class ResourceController {
// 如果是视频则必须传递duration参数
Integer duration = req.getDuration();
String poster = req.getPoster();
boolean isVideoType = BackendConstant.RESOURCE_TYPE_VIDEO.equals(type);
if (isVideoType) {
if (duration == null || duration == 0) {
return JsonResponse.error("duration参数必须存在且大于0");
}
if (poster == null || poster.trim().length() == 0) {
return JsonResponse.error("视频封面为空");
}
}
Resource res = resourceService.create(req.getCategoryId(), type, req.getName(), extension, req.getSize(), disk, req.getFileId(), req.getPath(), req.getUrl());
if (isVideoType) {
resourceVideoService.create(res.getId(), duration);
resourceVideoService.create(res.getId(), duration, poster);
}
return JsonResponse.data(res);

View File

@ -7,27 +7,36 @@ import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/**
*
*
* @TableName resource_videos
*/
@TableName(value ="resource_videos")
@Data
public class ResourceVideo implements Serializable {
/**
*
*
*/
private Integer rid;
/**
* 封面
*/
private String poster;
/**
* 视频时长[s]
*/
private Integer duration;
@JsonProperty("created_at")
/**
* 创建时间
*/
@JsonIgnore
private Date createdAt;
@TableField(exist = false)
@ -46,6 +55,7 @@ public class ResourceVideo implements Serializable {
}
ResourceVideo other = (ResourceVideo) that;
return (this.getRid() == null ? other.getRid() == null : this.getRid().equals(other.getRid()))
&& (this.getPoster() == null ? other.getPoster() == null : this.getPoster().equals(other.getPoster()))
&& (this.getDuration() == null ? other.getDuration() == null : this.getDuration().equals(other.getDuration()))
&& (this.getCreatedAt() == null ? other.getCreatedAt() == null : this.getCreatedAt().equals(other.getCreatedAt()));
}
@ -55,6 +65,7 @@ public class ResourceVideo implements Serializable {
final int prime = 31;
int result = 1;
result = prime * result + ((getRid() == null) ? 0 : getRid().hashCode());
result = prime * result + ((getPoster() == null) ? 0 : getPoster().hashCode());
result = prime * result + ((getDuration() == null) ? 0 : getDuration().hashCode());
result = prime * result + ((getCreatedAt() == null) ? 0 : getCreatedAt().hashCode());
return result;
@ -67,6 +78,7 @@ public class ResourceVideo implements Serializable {
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", rid=").append(rid);
sb.append(", poster=").append(poster);
sb.append(", duration=").append(duration);
sb.append(", createdAt=").append(createdAt);
sb.append(", serialVersionUID=").append(serialVersionUID);

View File

@ -7,7 +7,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @author tengteng
* @description 针对表resource_videos的数据库操作Mapper
* @createDate 2023-03-02 15:13:03
* @createDate 2023-03-08 13:39:06
* @Entity xyz.playedu.api.domain.ResourceVideo
*/
@Mapper

View File

@ -47,4 +47,6 @@ public class ResourceRequest {
private Integer duration;
private String poster;
}

View File

@ -4,7 +4,6 @@ import xyz.playedu.api.domain.ResourceVideo;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
import java.util.Map;
/**
* @author tengteng
@ -13,9 +12,9 @@ import java.util.Map;
*/
public interface ResourceVideoService extends IService<ResourceVideo> {
void create(Integer resourceId, Integer duration);
void create(Integer resourceId, Integer duration, String poster);
void removeByRid(Integer resourceId);
List<ResourceVideo> chunksByResourceIds(List<Integer> resourceIds);
List<ResourceVideo> chunksByRids(List<Integer> resourceIds);
}

View File

@ -18,10 +18,11 @@ import java.util.Map;
@Service
public class ResourceVideoServiceImpl extends ServiceImpl<ResourceVideoMapper, ResourceVideo> implements ResourceVideoService {
@Override
public void create(Integer resourceId, Integer duration) {
public void create(Integer resourceId, Integer duration, String poster) {
ResourceVideo video = new ResourceVideo();
video.setRid(resourceId);
video.setDuration(duration);
video.setPoster(poster);
video.setCreatedAt(new Date());
save(video);
}
@ -32,7 +33,7 @@ public class ResourceVideoServiceImpl extends ServiceImpl<ResourceVideoMapper, R
}
@Override
public List<ResourceVideo> chunksByResourceIds(List<Integer> resourceIds) {
public List<ResourceVideo> chunksByRids(List<Integer> resourceIds) {
return list(query().getWrapper().in("rid", resourceIds));
}
}

View File

@ -6,11 +6,13 @@
<resultMap id="BaseResultMap" type="xyz.playedu.api.domain.ResourceVideo">
<result property="rid" column="rid" jdbcType="INTEGER"/>
<result property="poster" column="poster" jdbcType="VARCHAR"/>
<result property="duration" column="duration" jdbcType="INTEGER"/>
<result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
rid,duration,created_at
rid,poster,duration,
created_at
</sql>
</mapper>