!14 存储桶改为private

* 后台 使用许可页面
* 优化:移除API访问地址配置
* 后台、pc、h5 删除无用配置
* docker部署优化
* 2.0 networkMode=bridge
* changelog
* 学员端权限为空报错
* h5 我的页面请求优化
* 缓存查询
* 后台 学员列表报错、线上课-上架时间字段优化
* 后台、pc、h5 使用签名地址
* 学员端接口修改
* 后台、pc 使用签名地址
* 后台 使用签名地址
* 上传接口
* 上传接口
* 系统配置
* 线上课封面
* bucket由public改为private
* 资源相关表实体及对象修改
* 统一数据库脚本
This commit is contained in:
白书科技
2025-05-22 07:23:06 +00:00
parent c206fa4bf2
commit 12daa31ab9
134 changed files with 10054 additions and 1231 deletions

View File

@@ -26,9 +26,9 @@ import java.util.Date;
import lombok.Data;
/**
* @TableName resources
* @TableName resource
*/
@TableName(value = "resources")
@TableName(value = "resource")
@Data
public class Resource implements Serializable {
/** */
@@ -54,16 +54,9 @@ public class Resource implements Serializable {
/** 存储磁盘 */
private String disk;
/** 文件id */
@JsonProperty("file_id")
private String fileId;
/** 相对地址 */
private String path;
/** URL地址 */
private String url;
/** */
@JsonProperty("created_at")
private Date createdAt;
@@ -109,15 +102,9 @@ public class Resource implements Serializable {
&& (this.getDisk() == null
? other.getDisk() == null
: this.getDisk().equals(other.getDisk()))
&& (this.getFileId() == null
? other.getFileId() == null
: this.getFileId().equals(other.getFileId()))
&& (this.getPath() == null
? other.getPath() == null
: this.getPath().equals(other.getPath()))
&& (this.getUrl() == null
? other.getUrl() == null
: this.getUrl().equals(other.getUrl()))
&& (this.getCreatedAt() == null
? other.getCreatedAt() == null
: this.getCreatedAt().equals(other.getCreatedAt()))
@@ -140,9 +127,7 @@ public class Resource implements Serializable {
result = prime * result + ((getExtension() == null) ? 0 : getExtension().hashCode());
result = prime * result + ((getSize() == null) ? 0 : getSize().hashCode());
result = prime * result + ((getDisk() == null) ? 0 : getDisk().hashCode());
result = prime * result + ((getFileId() == null) ? 0 : getFileId().hashCode());
result = prime * result + ((getPath() == null) ? 0 : getPath().hashCode());
result = prime * result + ((getUrl() == null) ? 0 : getUrl().hashCode());
result = prime * result + ((getCreatedAt() == null) ? 0 : getCreatedAt().hashCode());
result = prime * result + ((getParentId() == null) ? 0 : getParentId().hashCode());
result = prime * result + ((getIsHidden() == null) ? 0 : getIsHidden().hashCode());
@@ -162,9 +147,7 @@ public class Resource implements Serializable {
sb.append(", extension=").append(extension);
sb.append(", size=").append(size);
sb.append(", disk=").append(disk);
sb.append(", fileId=").append(fileId);
sb.append(", path=").append(path);
sb.append(", url=").append(url);
sb.append(", createdAt=").append(createdAt);
sb.append(", parentId=").append(parentId);
sb.append(", isHidden=").append(isHidden);

View File

@@ -19,29 +19,33 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.io.Serializable;
import java.util.Date;
import lombok.Data;
/**
* @TableName resource_videos
* @TableName resource_extra
*/
@TableName(value = "resource_videos")
@Data
public class ResourceVideo implements Serializable {
@TableName(value = "resource_extra")
public class ResourceExtra implements Serializable {
/** */
@TableId(type = IdType.AUTO)
private Integer id;
/** */
@TableId(type = IdType.NONE)
private Integer rid;
/** 封面 */
private String poster;
private Integer poster;
/** 频时长[s] */
/** 频时长[s] */
private Integer duration;
/** 创建时间 */
@JsonIgnore private Date createdAt;
@JsonProperty("created_at")
private Date createdAt;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
@@ -57,8 +61,9 @@ public class ResourceVideo implements Serializable {
if (getClass() != that.getClass()) {
return false;
}
ResourceVideo other = (ResourceVideo) that;
return (this.getRid() == null
ResourceExtra other = (ResourceExtra) that;
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
&& (this.getRid() == null
? other.getRid() == null
: this.getRid().equals(other.getRid()))
&& (this.getPoster() == null
@@ -76,6 +81,7 @@ public class ResourceVideo implements Serializable {
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
result = prime * result + ((getRid() == null) ? 0 : getRid().hashCode());
result = prime * result + ((getPoster() == null) ? 0 : getPoster().hashCode());
result = prime * result + ((getDuration() == null) ? 0 : getDuration().hashCode());
@@ -89,6 +95,7 @@ public class ResourceVideo implements Serializable {
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", rid=").append(rid);
sb.append(", poster=").append(poster);
sb.append(", duration=").append(duration);

View File

@@ -17,7 +17,7 @@ package xyz.playedu.resource.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import xyz.playedu.resource.domain.ResourceVideo;
import xyz.playedu.resource.domain.ResourceExtra;
/**
* @author tengteng
@@ -25,4 +25,4 @@ import xyz.playedu.resource.domain.ResourceVideo;
* @createDate 2023-03-08 13:39:06
*/
@Mapper
public interface ResourceVideoMapper extends BaseMapper<ResourceVideo> {}
public interface ResourceExtraMapper extends BaseMapper<ResourceExtra> {}

View File

@@ -23,7 +23,7 @@ import xyz.playedu.resource.domain.Resource;
/**
* @author tengteng
* @description 针对表【resources】的数据库操作Mapper
* @description 针对表【resource】的数据库操作Mapper
* @createDate 2023-03-13 10:25:30
*/
@Mapper

View File

@@ -17,18 +17,18 @@ package xyz.playedu.resource.service;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
import xyz.playedu.resource.domain.ResourceVideo;
import xyz.playedu.resource.domain.ResourceExtra;
/**
* @author tengteng
* @description 针对表resource_videos的数据库操作Service
* @createDate 2023-03-02 15:13:03
*/
public interface ResourceVideoService extends IService<ResourceVideo> {
public interface ResourceExtraService extends IService<ResourceExtra> {
void create(Integer resourceId, Integer duration, String poster);
void create(Integer resourceId, Integer duration, Integer poster);
void removeByRid(Integer resourceId);
List<ResourceVideo> chunksByRids(List<Integer> resourceIds);
List<ResourceExtra> chunksByRids(List<Integer> resourceIds);
}

View File

@@ -17,6 +17,7 @@ package xyz.playedu.resource.service;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
import java.util.Map;
import xyz.playedu.common.exception.NotFoundException;
import xyz.playedu.common.types.paginate.PaginationResult;
import xyz.playedu.common.types.paginate.ResourcePaginateFilter;
@@ -36,16 +37,25 @@ public interface ResourceService extends IService<Resource> {
String ext,
Long size,
String disk,
String fileId,
String path,
String url);
Integer parentId,
Integer isHidden);
void update(
Resource resource,
Integer adminId,
String categoryIds,
String type,
String filename,
String ext,
Long size,
String disk,
String path,
Integer parentId,
Integer isHidden);
Resource findOrFail(Integer id) throws NotFoundException;
void changeParentId(Integer id, Integer parentId);
void storeResourceVideo(Integer rid, Integer duration, String poster);
List<Resource> chunks(List<Integer> ids);
List<Resource> chunks(List<Integer> ids, List<String> fields);
@@ -59,4 +69,8 @@ public interface ResourceService extends IService<Resource> {
List<Integer> categoryIds(Integer resourceId);
Integer total(List<String> types);
Map<Integer, String> chunksPreSignUrlByIds(List<Integer> ids);
Map<Integer, String> downloadResById(Integer id);
}

View File

@@ -16,9 +16,9 @@
package xyz.playedu.resource.service;
import org.springframework.web.multipart.MultipartFile;
import xyz.playedu.common.domain.UserUploadImageLog;
import xyz.playedu.common.exception.ServiceException;
import xyz.playedu.common.types.UploadFileInfo;
import xyz.playedu.common.types.config.S3Config;
import xyz.playedu.resource.domain.Resource;
/**
@@ -28,14 +28,10 @@ import xyz.playedu.resource.domain.Resource;
*/
public interface UploadService {
UploadFileInfo upload(MultipartFile file, String dir) throws ServiceException;
Resource storeMinio(String disk, Integer adminId, MultipartFile file, String categoryIds)
UploadFileInfo upload(S3Config s3Config, MultipartFile file, String dir)
throws ServiceException;
Resource storeBase64Image(String disk, Integer adminId, String content, String categoryIds)
Resource storeBase64Image(
S3Config s3Config, Integer adminId, String content, String categoryIds)
throws ServiceException;
UserUploadImageLog userAvatar(
String disk, Integer userId, MultipartFile file, String typed, String scene);
}

View File

@@ -20,9 +20,9 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.springframework.stereotype.Service;
import xyz.playedu.resource.domain.ResourceVideo;
import xyz.playedu.resource.mapper.ResourceVideoMapper;
import xyz.playedu.resource.service.ResourceVideoService;
import xyz.playedu.resource.domain.ResourceExtra;
import xyz.playedu.resource.mapper.ResourceExtraMapper;
import xyz.playedu.resource.service.ResourceExtraService;
/**
* @author tengteng
@@ -30,11 +30,11 @@ import xyz.playedu.resource.service.ResourceVideoService;
* @createDate 2023-03-02 15:13:03
*/
@Service
public class ResourceVideoServiceImpl extends ServiceImpl<ResourceVideoMapper, ResourceVideo>
implements ResourceVideoService {
public class ResourceExtraServiceImpl extends ServiceImpl<ResourceExtraMapper, ResourceExtra>
implements ResourceExtraService {
@Override
public void create(Integer resourceId, Integer duration, String poster) {
ResourceVideo video = new ResourceVideo();
public void create(Integer resourceId, Integer duration, Integer poster) {
ResourceExtra video = new ResourceExtra();
video.setRid(resourceId);
video.setDuration(duration);
video.setPoster(poster);
@@ -48,7 +48,7 @@ public class ResourceVideoServiceImpl extends ServiceImpl<ResourceVideoMapper, R
}
@Override
public List<ResourceVideo> chunksByRids(List<Integer> resourceIds) {
public List<ResourceExtra> chunksByRids(List<Integer> resourceIds) {
if (resourceIds == null || resourceIds.size() == 0) {
return new ArrayList<>();
}

View File

@@ -21,29 +21,34 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import xyz.playedu.common.exception.NotFoundException;
import xyz.playedu.common.service.AppConfigService;
import xyz.playedu.common.types.paginate.PaginationResult;
import xyz.playedu.common.types.paginate.ResourcePaginateFilter;
import xyz.playedu.common.util.S3Util;
import xyz.playedu.common.util.StringUtil;
import xyz.playedu.resource.domain.Resource;
import xyz.playedu.resource.domain.ResourceCategory;
import xyz.playedu.resource.domain.ResourceVideo;
import xyz.playedu.resource.domain.ResourceExtra;
import xyz.playedu.resource.mapper.ResourceMapper;
import xyz.playedu.resource.service.ResourceCategoryService;
import xyz.playedu.resource.service.ResourceExtraService;
import xyz.playedu.resource.service.ResourceService;
import xyz.playedu.resource.service.ResourceVideoService;
/**
* @author tengteng
* @description 针对表【resources】的数据库操作Service实现
* @description 针对表【resource】的数据库操作Service实现
* @createDate 2023-02-23 10:50:26
*/
@Service
public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource>
implements ResourceService {
@Autowired private ResourceVideoService resourceVideoService;
@Autowired private ResourceExtraService resourceExtraService;
@Autowired private ResourceCategoryService relationService;
@Autowired private AppConfigService appConfigService;
@Override
public PaginationResult<Resource> paginate(int page, int size, ResourcePaginateFilter filter) {
PaginationResult<Resource> pageResult = new PaginationResult<>();
@@ -72,9 +77,9 @@ public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource>
String ext,
Long size,
String disk,
String fileId,
String path,
String url) {
Integer parentId,
Integer isHidden) {
Resource resource = new Resource();
resource.setAdminId(adminId);
resource.setType(type);
@@ -82,10 +87,10 @@ public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource>
resource.setExtension(ext);
resource.setSize(size);
resource.setDisk(disk);
resource.setFileId(fileId);
resource.setPath(path);
resource.setUrl(url);
resource.setCreatedAt(new Date());
resource.setParentId(parentId);
resource.setIsHidden(isHidden);
save(resource);
if (categoryIds != null && categoryIds.trim().length() > 0) {
@@ -109,6 +114,52 @@ public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource>
return resource;
}
@Override
@Transactional
public void update(
Resource resource,
Integer adminId,
String categoryIds,
String type,
String filename,
String ext,
Long size,
String disk,
String path,
Integer parentId,
Integer isHidden) {
resource.setAdminId(adminId);
resource.setType(type);
resource.setName(filename);
resource.setExtension(ext);
resource.setSize(size);
resource.setDisk(disk);
resource.setPath(path);
resource.setCreatedAt(new Date());
resource.setParentId(parentId);
resource.setIsHidden(isHidden);
updateById(resource);
if (categoryIds != null && categoryIds.trim().length() > 0) {
String[] idArray = categoryIds.split(",");
List<ResourceCategory> relations = new ArrayList<>();
for (String s : idArray) {
int tmpId = Integer.parseInt(s);
if (tmpId == 0) {
continue;
}
relations.add(
new ResourceCategory() {
{
setCid(tmpId);
setRid(resource.getId());
}
});
}
relationService.saveBatch(relations);
}
}
@Override
public Resource findOrFail(Integer id) throws NotFoundException {
Resource resource = getById(id);
@@ -118,20 +169,6 @@ public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource>
return resource;
}
@Override
public void changeParentId(Integer id, Integer parentId) {
Resource resource = new Resource();
resource.setId(id);
resource.setParentId(parentId);
resource.setIsHidden(1);
updateById(resource);
}
@Override
public void storeResourceVideo(Integer rid, Integer duration, String poster) {
resourceVideoService.create(rid, duration, poster);
}
@Override
public List<Resource> chunks(List<Integer> ids) {
return list(query().getWrapper().in("id", ids));
@@ -149,13 +186,13 @@ public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource>
@Override
public Integer duration(Integer id) {
ResourceVideo resourceVideo =
resourceVideoService.getOne(
resourceVideoService.query().getWrapper().eq("rid", id));
if (resourceVideo == null) {
ResourceExtra resourceExtra =
resourceExtraService.getOne(
resourceExtraService.query().getWrapper().eq("rid", id));
if (resourceExtra == null) {
return null;
}
return resourceVideo.getDuration();
return resourceExtra.getDuration();
}
@Override
@@ -188,4 +225,46 @@ public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource>
public Integer total(List<String> types) {
return Math.toIntExact(count(query().getWrapper().in("type", types).eq("is_hidden", 0)));
}
@Override
public Map<Integer, String> chunksPreSignUrlByIds(List<Integer> ids) {
if (StringUtil.isEmpty(ids)) {
return new HashMap<>();
}
S3Util s3Util = new S3Util(appConfigService.getS3Config());
Map<Integer, String> preSignUrlMap = new HashMap<>();
List<Resource> resourceList = list(query().getWrapper().in("id", ids));
if (StringUtil.isNotEmpty(resourceList)) {
resourceList.forEach(
resource -> {
String path = resource.getPath();
try {
String url = s3Util.generateEndpointPreSignUrl(path, "");
if (StringUtil.isNotEmpty(url)) {
preSignUrlMap.put(resource.getId(), url);
}
} catch (Exception e) {
log.error(e.getMessage());
}
});
}
return preSignUrlMap;
}
@Override
public Map<Integer, String> downloadResById(Integer id) {
Map<Integer, String> preSignUrlMap = new HashMap<>();
Resource resource = getById(id);
if (StringUtil.isNotNull(resource)) {
String name = resource.getName() + "." + resource.getExtension();
String url =
new S3Util(appConfigService.getS3Config())
.generateEndpointPreSignUrl(resource.getPath(), name);
if (StringUtil.isNotEmpty(url)) {
preSignUrlMap.put(resource.getId(), url);
}
}
return preSignUrlMap;
}
}

View File

@@ -15,22 +15,21 @@
*/
package xyz.playedu.resource.service.impl;
import java.util.Date;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import xyz.playedu.common.constant.BackendConstant;
import xyz.playedu.common.constant.FrontendConstant;
import xyz.playedu.common.domain.UserUploadImageLog;
import xyz.playedu.common.constant.CommonConstant;
import xyz.playedu.common.exception.ServiceException;
import xyz.playedu.common.service.AppConfigService;
import xyz.playedu.common.service.UserUploadImageLogService;
import xyz.playedu.common.types.UploadFileInfo;
import xyz.playedu.common.types.config.S3Config;
import xyz.playedu.common.util.Base64Util;
import xyz.playedu.common.util.HelperUtil;
import xyz.playedu.common.util.S3Util;
import xyz.playedu.common.util.StringUtil;
import xyz.playedu.resource.domain.Resource;
import xyz.playedu.resource.service.ResourceService;
import xyz.playedu.resource.service.UploadService;
@@ -43,12 +42,10 @@ public class UploadServiceImpl implements UploadService {
@Autowired private AppConfigService appConfigService;
@Autowired private UserUploadImageLogService userUploadImageLogService;
@Override
@SneakyThrows
public UploadFileInfo upload(MultipartFile file, String dir) {
if (file == null || file.isEmpty() || file.getOriginalFilename() == null) {
public UploadFileInfo upload(S3Config s3Config, MultipartFile file, String dir) {
if (file == null || file.isEmpty() || StringUtil.isEmpty(file.getOriginalFilename())) {
throw new ServiceException("请上传文件");
}
@@ -59,12 +56,17 @@ public class UploadServiceImpl implements UploadService {
// 文件大小
fileInfo.setSize(file.getSize());
// 解析扩展名
fileInfo.setExtension(HelperUtil.fileExt(filename));
fileInfo.setExtension(HelperUtil.fileExt(filename).toLowerCase());
// 解析扩展名称对应的系统资源类型
fileInfo.setResourceType(BackendConstant.RESOURCE_EXT_2_TYPE.get(fileInfo.getExtension()));
String type = BackendConstant.RESOURCE_EXT_2_TYPE.get(fileInfo.getExtension());
// 附件模块上传文件 非系统格式统一为OTHER
if (StringUtil.isEmpty(type)) {
type = BackendConstant.RESOURCE_TYPE_OTHER;
}
fileInfo.setResourceType(type);
// 检测是否为系统不支持的资源类型
if (fileInfo.getResourceType() == null) {
throw new ServiceException("当前资源扩展不支持上传");
if (StringUtil.isEmpty(fileInfo.getResourceType())) {
throw new ServiceException("当前格式不支持");
}
// 上传原文件的文件名
@@ -72,45 +74,24 @@ public class UploadServiceImpl implements UploadService {
// 自定义新的存储文件名
fileInfo.setSaveName(HelperUtil.randomString(32) + "." + fileInfo.getExtension());
// 生成保存的相对路径
if (dir == null || dir.isEmpty()) {
if (StringUtil.isEmpty(dir)) {
dir = BackendConstant.RESOURCE_TYPE_2_DIR.get(fileInfo.getResourceType());
}
fileInfo.setSavePath(dir + fileInfo.getSaveName());
// 保存文件并生成访问url
S3Util s3Util = new S3Util(appConfigService.getS3Config());
String url =
s3Util.saveFile(
// 保存文件
new S3Util(s3Config)
.saveFile(
file,
fileInfo.getSavePath(),
BackendConstant.RESOURCE_EXT_2_CONTENT_TYPE.get(fileInfo.getExtension()));
fileInfo.setUrl(url);
fileInfo.setDisk("");
return fileInfo;
}
@Override
@SneakyThrows
public Resource storeMinio(
String disk, Integer adminId, MultipartFile file, String categoryIds) {
UploadFileInfo info = upload(file, null);
return resourceService.create(
adminId,
categoryIds,
info.getResourceType(),
info.getOriginalName(),
info.getExtension(),
file.getSize(),
disk,
"",
info.getSavePath(),
info.getUrl());
}
@Override
@SneakyThrows
public Resource storeBase64Image(
String disk, Integer adminId, String content, String categoryIds) {
S3Config s3Config, Integer adminId, String content, String categoryIds) {
// data:image/jpeg;base64,
String[] base64Rows = content.split(",");
// 解析出content-type
@@ -121,8 +102,8 @@ public class UploadServiceImpl implements UploadService {
// 通过文件格式解析资源类型
String type = BackendConstant.RESOURCE_EXT_2_TYPE.get(ext);
// 资源类型必须存在
if (type == null) {
throw new ServiceException("资源类型不支持");
if (StringUtil.isEmpty(type)) {
throw new ServiceException("当前格式不支持");
}
byte[] binary = Base64Util.decode(base64Rows[1]);
@@ -130,10 +111,9 @@ public class UploadServiceImpl implements UploadService {
String savePath = BackendConstant.RESOURCE_TYPE_2_DIR.get(type) + filename;
// 保存文件
S3Util s3Util = new S3Util(appConfigService.getS3Config());
String url =
s3Util.saveBytes(
binary, savePath, BackendConstant.RESOURCE_EXT_2_CONTENT_TYPE.get(ext));
new S3Util(s3Config)
.saveBytes(binary, savePath, BackendConstant.RESOURCE_EXT_2_CONTENT_TYPE.get(ext));
// 上传记录
return resourceService.create(
adminId,
@@ -142,28 +122,9 @@ public class UploadServiceImpl implements UploadService {
filename,
ext,
(long) binary.length,
disk,
"",
savePath,
url);
}
@Override
@SneakyThrows
public UserUploadImageLog userAvatar(
String disk, Integer userId, MultipartFile file, String typed, String scene) {
UploadFileInfo info = upload(file, FrontendConstant.DIR_AVATAR);
UserUploadImageLog log = new UserUploadImageLog();
log.setUserId(userId);
log.setTyped(typed);
log.setScene(scene);
log.setSize(info.getSize());
log.setDriver(disk);
log.setPath(info.getSavePath());
log.setUrl(info.getUrl());
log.setName(info.getOriginalName());
log.setCreatedAt(new Date());
userUploadImageLogService.save(log);
return log;
CommonConstant.ZERO,
CommonConstant.ONE);
}
}

View File

@@ -12,9 +12,7 @@
<result property="extension" column="extension" jdbcType="VARCHAR"/>
<result property="size" column="size" jdbcType="BIGINT"/>
<result property="disk" column="disk" jdbcType="VARCHAR"/>
<result property="fileId" column="file_id" jdbcType="VARCHAR"/>
<result property="path" column="path" jdbcType="VARCHAR"/>
<result property="url" column="url" jdbcType="VARCHAR"/>
<result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
<result property="parentId" column="parent_id" jdbcType="INTEGER"/>
<result property="isHidden" column="is_hidden" jdbcType="TINYINT"/>
@@ -24,75 +22,74 @@
id
,admin_id,type,
name,extension,size,
disk,file_id,path,
url,created_at,parent_id,
disk,path,created_at,parent_id,
is_hidden
</sql>
<select id="paginate" resultType="xyz.playedu.resource.domain.Resource">
SELECT `resources`.*
FROM `resources`
SELECT `resource`.*
FROM `resource`
<choose>
<when test="categoryIds != null and !categoryIds.isEmpty()">
<choose>
<when test="categoryIds.get(0) == 0">
LEFT JOIN `resource_category` ON `resource_category`.`rid` = `resources`.`id`
WHERE `resources`.`is_hidden` = 0
LEFT JOIN `resource_category` ON `resource_category`.`rid` = `resource`.`id`
WHERE `resource`.`is_hidden` = 0
AND `resource_category`.`cid` IS NULL
</when>
<otherwise>
INNER JOIN `resource_category` ON `resource_category`.`rid` = `resources`.`id`
WHERE `resources`.`is_hidden` = 0
INNER JOIN `resource_category` ON `resource_category`.`rid` = `resource`.`id`
WHERE `resource`.`is_hidden` = 0
AND `resource_category`.`cid` IN (<foreach collection="categoryIds" item="tmpId" separator=",">
#{tmpId}</foreach>)
</otherwise>
</choose>
</when>
<otherwise>
WHERE `resources`.`is_hidden` = 0
WHERE `resource`.`is_hidden` = 0
</otherwise>
</choose>
<if test="name != null and name != ''">
AND `resources`.`name` LIKE concat('%',#{name},'%')
AND `resource`.`name` LIKE concat('%',#{name},'%')
</if>
<if test="disk != null and disk != ''">
AND `resources`.`disk` = #{disk}
AND `resource`.`disk` = #{disk}
</if>
<if test="extension != null and extension != ''">
AND `resources`.`extension` = #{extension}
AND `resource`.`extension` = #{extension}
</if>
<if test="type != null and type != ''">
AND `resources`.`type` IN
AND `resource`.`type` IN
<foreach item="item" collection="type.split(',')" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="adminId != null and adminId != 0">
AND `resources`.`admin_id` = #{adminId}
AND `resource`.`admin_id` = #{adminId}
</if>
<if test="sortAlgo == 'asc'">
<choose>
<when test="sortField == 'size'">
ORDER BY `resources`.`size` ASC
ORDER BY `resource`.`size` ASC
</when>
<when test="sortField == 'created_at'">
ORDER BY `resources`.`created_at` ASC
ORDER BY `resource`.`created_at` ASC
</when>
<otherwise>
ORDER BY `resources`.`id` ASC
ORDER BY `resource`.`id` ASC
</otherwise>
</choose>
</if>
<if test="sortAlgo != 'asc'">
<choose>
<when test="sortField == 'size'">
ORDER BY `resources`.`size` DESC
ORDER BY `resource`.`size` DESC
</when>
<when test="sortField == 'created_at'">
ORDER BY `resources`.`created_at` DESC
ORDER BY `resource`.`created_at` DESC
</when>
<otherwise>
ORDER BY `resources`.`id` DESC
ORDER BY `resource`.`id` DESC
</otherwise>
</choose>
</if>
@@ -101,87 +98,87 @@
<select id="paginateCount" resultType="java.lang.Long">
SELECT count(1)
FROM `resources`
FROM `resource`
<choose>
<when test="categoryIds != null and !categoryIds.isEmpty()">
<choose>
<when test="categoryIds.get(0) == 0">
LEFT JOIN `resource_category` ON `resource_category`.`rid` = `resources`.`id`
WHERE `resources`.`is_hidden` = 0
LEFT JOIN `resource_category` ON `resource_category`.`rid` = `resource`.`id`
WHERE `resource`.`is_hidden` = 0
AND `resource_category`.`cid` IS NULL
</when>
<otherwise>
INNER JOIN `resource_category` ON `resource_category`.`rid` = `resources`.`id`
WHERE `resources`.`is_hidden` = 0
INNER JOIN `resource_category` ON `resource_category`.`rid` = `resource`.`id`
WHERE `resource`.`is_hidden` = 0
AND `resource_category`.`cid` IN (<foreach collection="categoryIds" item="tmpId" separator=",">
#{tmpId}</foreach>)
</otherwise>
</choose>
</when>
<otherwise>
WHERE `resources`.`is_hidden` = 0
WHERE `resource`.`is_hidden` = 0
</otherwise>
</choose>
<if test="name != null and name != ''">
AND `resources`.`name` LIKE concat('%',#{name},'%')
AND `resource`.`name` LIKE concat('%',#{name},'%')
</if>
<if test="disk != null and disk != ''">
AND `resources`.`disk` = #{disk}
AND `resource`.`disk` = #{disk}
</if>
<if test="extension != null and extension != ''">
AND `resources`.`extension` = #{extension}
AND `resource`.`extension` = #{extension}
</if>
<if test="type != null and type != ''">
AND `resources`.`type` IN
AND `resource`.`type` IN
<foreach item="item" collection="type.split(',')" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="adminId != null and adminId != 0">
AND `resources`.`admin_id` = #{adminId}
AND `resource`.`admin_id` = #{adminId}
</if>
</select>
<select id="paginateType" resultType="java.lang.String">
SELECT DISTINCT ( `resources`.`type` )
FROM `resources`
SELECT DISTINCT ( `resource`.`type` )
FROM `resource`
<choose>
<when test="categoryIds != null and !categoryIds.isEmpty()">
<choose>
<when test="categoryIds.get(0) == 0">
LEFT JOIN `resource_category` ON `resource_category`.`rid` = `resources`.`id`
WHERE `resources`.`is_hidden` = 0
LEFT JOIN `resource_category` ON `resource_category`.`rid` = `resource`.`id`
WHERE `resource`.`is_hidden` = 0
AND `resource_category`.`cid` IS NULL
</when>
<otherwise>
INNER JOIN `resource_category` ON `resource_category`.`rid` = `resources`.`id`
WHERE `resources`.`is_hidden` = 0
INNER JOIN `resource_category` ON `resource_category`.`rid` = `resource`.`id`
WHERE `resource`.`is_hidden` = 0
AND `resource_category`.`cid` IN (<foreach collection="categoryIds" item="tmpId" separator=",">
#{tmpId}</foreach>)
</otherwise>
</choose>
</when>
<otherwise>
WHERE `resources`.`is_hidden` = 0
WHERE `resource`.`is_hidden` = 0
</otherwise>
</choose>
<if test="name != null and name != ''">
AND `resources`.`name` LIKE concat('%',#{name},'%')
AND `resource`.`name` LIKE concat('%',#{name},'%')
</if>
<if test="disk != null and disk != ''">
AND `resources`.`disk` = #{disk}
AND `resource`.`disk` = #{disk}
</if>
<if test="extension != null and extension != ''">
AND `resources`.`extension` = #{extension}
AND `resource`.`extension` = #{extension}
</if>
<if test="type != null and type != ''">
AND `resources`.`type` IN
AND `resource`.`type` IN
<foreach item="item" collection="type.split(',')" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="adminId != null and adminId != 0">
AND `resources`.`admin_id` = #{adminId}
AND `resource`.`admin_id` = #{adminId}
</if>
</select>

View File

@@ -2,9 +2,9 @@
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="xyz.playedu.resource.mapper.ResourceVideoMapper">
<mapper namespace="xyz.playedu.resource.mapper.ResourceExtraMapper">
<resultMap id="BaseResultMap" type="xyz.playedu.resource.domain.ResourceVideo">
<resultMap id="BaseResultMap" type="xyz.playedu.resource.domain.ResourceExtra">
<result property="rid" column="rid" jdbcType="INTEGER"/>
<result property="poster" column="poster" jdbcType="VARCHAR"/>
<result property="duration" column="duration" jdbcType="INTEGER"/>