资源分类可选

This commit is contained in:
none 2023-03-06 10:40:00 +08:00
parent b4db9d67b2
commit 9aa63dba66
8 changed files with 48 additions and 24 deletions

View File

@ -42,11 +42,17 @@ public class ResourceController {
String sortField = MapUtils.getString(params, "sort_field"); String sortField = MapUtils.getString(params, "sort_field");
String sortAlgo = MapUtils.getString(params, "sort_algo"); String sortAlgo = MapUtils.getString(params, "sort_algo");
String name = MapUtils.getString(params, "name"); String name = MapUtils.getString(params, "name");
String type = MapUtils.getString(params, "type");
String categoryIdsStr = MapUtils.getString(params, "category_ids"); String categoryIdsStr = MapUtils.getString(params, "category_ids");
if (type == null || type.trim().length() == 0) {
return JsonResponse.error("请选择资源类型");
}
ResourcePaginateFilter filter = new ResourcePaginateFilter(); ResourcePaginateFilter filter = new ResourcePaginateFilter();
filter.setSortAlgo(sortAlgo); filter.setSortAlgo(sortAlgo);
filter.setSortField(sortField); filter.setSortField(sortField);
filter.setType(type);
if (name != null && name.length() > 0) { if (name != null && name.length() > 0) {
filter.setName(name); filter.setName(name);
} }
@ -96,7 +102,7 @@ public class ResourceController {
} }
} }
Resource res = resourceService.create(categoryId, req.getName(), extension, req.getSize(), disk, req.getFileId(), req.getPath(), req.getUrl()); Resource res = resourceService.create(categoryId, type, req.getName(), extension, req.getSize(), disk, req.getFileId(), req.getPath(), req.getUrl());
if (isVideoType) { if (isVideoType) {
resourceVideoService.create(res.getId(), duration); resourceVideoService.create(res.getId(), duration);

View File

@ -53,8 +53,8 @@ public class UploadController {
return JsonResponse.error("格式不支持"); return JsonResponse.error("格式不支持");
} }
Integer categoryId = MapUtils.getInteger(params, "category_id", 0); Integer categoryId = MapUtils.getInteger(params, "category_id");
if (resourceCategoryService.getById(categoryId) == null) { if (categoryId != null && !categoryId.equals(0) && resourceCategoryService.getById(categoryId) == null) {
return JsonResponse.error("分类不存在"); return JsonResponse.error("分类不存在");
} }
@ -80,7 +80,7 @@ public class UploadController {
String url = minioConfig.getDomain() + minioConfig.getBucket() + "/" + savePath; String url = minioConfig.getDomain() + minioConfig.getBucket() + "/" + savePath;
Resource res = resourceService.create(categoryId, oldFilename, ext, file.getSize(), "minio", "", savePath, url); Resource res = resourceService.create(categoryId, BackendConstant.RESOURCE_TYPE_IMAGE, oldFilename, ext, file.getSize(), "minio", "", savePath, url);
return JsonResponse.data(res); return JsonResponse.data(res);
} catch (Exception e) { } catch (Exception e) {
return JsonResponse.error("系统错误"); return JsonResponse.error("系统错误");

View File

@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
@ -12,9 +11,10 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data; import lombok.Data;
/** /**
*
* @TableName resources * @TableName resources
*/ */
@TableName(value = "resources") @TableName(value ="resources")
@Data @Data
public class Resource implements Serializable { public class Resource implements Serializable {
/** /**
@ -23,6 +23,11 @@ public class Resource implements Serializable {
@TableId(type = IdType.AUTO) @TableId(type = IdType.AUTO)
private Integer id; private Integer id;
/**
* 类型
*/
private String type;
/** /**
* 分类id * 分类id
*/ */
@ -65,6 +70,9 @@ public class Resource implements Serializable {
*/ */
private String url; private String url;
/**
*
*/
@JsonProperty("created_at") @JsonProperty("created_at")
private Date createdAt; private Date createdAt;
@ -84,6 +92,7 @@ public class Resource implements Serializable {
} }
Resource other = (Resource) that; Resource other = (Resource) that;
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
&& (this.getType() == null ? other.getType() == null : this.getType().equals(other.getType()))
&& (this.getCategoryId() == null ? other.getCategoryId() == null : this.getCategoryId().equals(other.getCategoryId())) && (this.getCategoryId() == null ? other.getCategoryId() == null : this.getCategoryId().equals(other.getCategoryId()))
&& (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName())) && (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
&& (this.getExtension() == null ? other.getExtension() == null : this.getExtension().equals(other.getExtension())) && (this.getExtension() == null ? other.getExtension() == null : this.getExtension().equals(other.getExtension()))
@ -100,6 +109,7 @@ public class Resource implements Serializable {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
result = prime * result + ((getType() == null) ? 0 : getType().hashCode());
result = prime * result + ((getCategoryId() == null) ? 0 : getCategoryId().hashCode()); result = prime * result + ((getCategoryId() == null) ? 0 : getCategoryId().hashCode());
result = prime * result + ((getName() == null) ? 0 : getName().hashCode()); result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
result = prime * result + ((getExtension() == null) ? 0 : getExtension().hashCode()); result = prime * result + ((getExtension() == null) ? 0 : getExtension().hashCode());
@ -119,6 +129,7 @@ public class Resource implements Serializable {
sb.append(" ["); sb.append(" [");
sb.append("Hash = ").append(hashCode()); sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id); sb.append(", id=").append(id);
sb.append(", type=").append(type);
sb.append(", categoryId=").append(categoryId); sb.append(", categoryId=").append(categoryId);
sb.append(", name=").append(name); sb.append(", name=").append(name);
sb.append(", extension=").append(extension); sb.append(", extension=").append(extension);

View File

@ -7,7 +7,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/** /**
* @author tengteng * @author tengteng
* @description 针对表resources的数据库操作Mapper * @description 针对表resources的数据库操作Mapper
* @createDate 2023-02-23 10:50:26 * @createDate 2023-03-06 10:06:57
* @Entity xyz.playedu.api.domain.Resource * @Entity xyz.playedu.api.domain.Resource
*/ */
@Mapper @Mapper

View File

@ -14,6 +14,6 @@ public interface ResourceService extends IService<Resource> {
PaginationResult<Resource> paginate(int page, int size, ResourcePaginateFilter filter); PaginationResult<Resource> paginate(int page, int size, ResourcePaginateFilter filter);
Resource create(Integer categoryId, String filename, String ext, Long size, String disk, String fileId, String path, String url); Resource create(Integer categoryId, String type, String filename, String ext, Long size, String disk, String fileId, String path, String url);
} }

View File

@ -36,6 +36,9 @@ public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource> i
if (filter.getExtension() != null) { if (filter.getExtension() != null) {
wrapper.eq("extension", filter.getExtension()); wrapper.eq("extension", filter.getExtension());
} }
if (filter.getType() != null) {
wrapper.eq("type", filter.getType());
}
if (filter.getCategoryIds() != null && filter.getCategoryIds().length > 0) { if (filter.getCategoryIds() != null && filter.getCategoryIds().length > 0) {
wrapper.in("category_id", Arrays.asList(filter.getCategoryIds())); wrapper.in("category_id", Arrays.asList(filter.getCategoryIds()));
} }
@ -65,8 +68,9 @@ public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource> i
} }
@Override @Override
public Resource create(Integer categoryId, String filename, String ext, Long size, String disk, String fileId, String path, String url) { public Resource create(Integer categoryId, String type, String filename, String ext, Long size, String disk, String fileId, String path, String url) {
Resource resource = new Resource(); Resource resource = new Resource();
resource.setType(type);
resource.setCategoryId(categoryId); resource.setCategoryId(categoryId);
resource.setName(filename); resource.setName(filename);
resource.setExtension(ext); resource.setExtension(ext);

View File

@ -21,4 +21,6 @@ public class ResourcePaginateFilter {
private Integer[] categoryIds; private Integer[] categoryIds;
private String type;
} }

View File

@ -5,7 +5,8 @@
<mapper namespace="xyz.playedu.api.mapper.ResourceMapper"> <mapper namespace="xyz.playedu.api.mapper.ResourceMapper">
<resultMap id="BaseResultMap" type="xyz.playedu.api.domain.Resource"> <resultMap id="BaseResultMap" type="xyz.playedu.api.domain.Resource">
<id property="id" column="id" jdbcType="BIGINT"/> <id property="id" column="id" jdbcType="INTEGER"/>
<result property="type" column="type" jdbcType="VARCHAR"/>
<result property="categoryId" column="category_id" jdbcType="INTEGER"/> <result property="categoryId" column="category_id" jdbcType="INTEGER"/>
<result property="name" column="name" jdbcType="VARCHAR"/> <result property="name" column="name" jdbcType="VARCHAR"/>
<result property="extension" column="extension" jdbcType="VARCHAR"/> <result property="extension" column="extension" jdbcType="VARCHAR"/>
@ -18,9 +19,9 @@
</resultMap> </resultMap>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id,category_id,name, id,type,category_id,
extension,size,disk, name,extension,size,
file_id,path,url, disk,file_id,path,
created_at url,created_at
</sql> </sql>
</mapper> </mapper>