mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-07-24 02:09:35 +08:00
资源增加admin_id
This commit is contained in:
parent
c254a42cc6
commit
debcddc468
@ -18,7 +18,7 @@ public class PlayEduBContext {
|
||||
public PlayEduBContext() {
|
||||
}
|
||||
|
||||
public static void put(String key, Object val) {
|
||||
private static void put(String key, Object val) {
|
||||
LinkedHashMap<String, Object> hashMap = THREAD_LOCAL.get();
|
||||
if (hashMap == null) {
|
||||
hashMap = new LinkedHashMap<>();
|
||||
@ -27,7 +27,7 @@ public class PlayEduBContext {
|
||||
THREAD_LOCAL.set(hashMap);
|
||||
}
|
||||
|
||||
public static Object get(String key) {
|
||||
private static Object get(String key) {
|
||||
return THREAD_LOCAL.get().getOrDefault(key, null);
|
||||
}
|
||||
|
||||
|
@ -75,4 +75,16 @@ public class BackendBus {
|
||||
return PrivacyUtil.desValue(value, 1, 0, "*");
|
||||
}
|
||||
|
||||
public boolean isSuperAdmin() {
|
||||
AdminRole superRole = adminRoleService.getBySlug(BackendConstant.SUPER_ADMIN_ROLE);
|
||||
if (superRole == null) {
|
||||
return false;
|
||||
}
|
||||
List<Integer> roleIds = adminUserService.getRoleIdsByUserId(PlayEduBContext.getAdminUserID());
|
||||
if (roleIds.size() == 0) {
|
||||
return false;
|
||||
}
|
||||
return roleIds.contains(superRole.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ import org.apache.commons.collections4.MapUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import xyz.playedu.api.PlayEduBContext;
|
||||
import xyz.playedu.api.bus.BackendBus;
|
||||
import xyz.playedu.api.constant.BackendConstant;
|
||||
import xyz.playedu.api.domain.Resource;
|
||||
import xyz.playedu.api.domain.ResourceVideo;
|
||||
@ -35,6 +37,9 @@ public class ResourceController {
|
||||
@Autowired
|
||||
private MinioService minioService;
|
||||
|
||||
@Autowired
|
||||
private BackendBus backendBus;
|
||||
|
||||
@GetMapping("/index")
|
||||
public JsonResponse index(@RequestParam HashMap<String, Object> params) {
|
||||
Integer page = MapUtils.getInteger(params, "page", 1);
|
||||
@ -54,8 +59,10 @@ public class ResourceController {
|
||||
filter.setSortField(sortField);
|
||||
filter.setType(type);
|
||||
filter.setCategoryIds(categoryIds);
|
||||
if (name != null && name.length() > 0) {
|
||||
filter.setName(name);
|
||||
filter.setName(name);
|
||||
// 非超管只能读取它自己上传的资源
|
||||
if (!backendBus.isSuperAdmin()) {
|
||||
filter.setAdminId(PlayEduBContext.getAdminUserID());
|
||||
}
|
||||
|
||||
PaginationResult<Resource> result = resourceService.paginate(page, size, filter);
|
||||
|
@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import xyz.playedu.api.PlayEduBContext;
|
||||
import xyz.playedu.api.constant.BackendConstant;
|
||||
import xyz.playedu.api.domain.Resource;
|
||||
import xyz.playedu.api.exception.ServiceException;
|
||||
@ -39,7 +40,7 @@ public class UploadController {
|
||||
@PostMapping("/minio")
|
||||
public JsonResponse uploadMinio(@RequestParam HashMap<String, Object> params, MultipartFile file) throws ServiceException {
|
||||
String categoryIds = MapUtils.getString(params, "category_ids");
|
||||
Resource res = uploadService.storeMinio(file, categoryIds);
|
||||
Resource res = uploadService.storeMinio(PlayEduBContext.getAdminUserID(), file, categoryIds);
|
||||
return JsonResponse.data(res);
|
||||
}
|
||||
|
||||
@ -91,6 +92,7 @@ public class UploadController {
|
||||
|
||||
// 视频素材保存
|
||||
Resource videoResource = resourceService.create(
|
||||
PlayEduBContext.getAdminUserID(),
|
||||
req.getCategoryIds(),
|
||||
type,
|
||||
req.getOriginalFilename(),
|
||||
@ -102,7 +104,7 @@ public class UploadController {
|
||||
url
|
||||
);
|
||||
// 视频封面素材保存
|
||||
Resource posterResource = uploadService.storeBase64Image(req.getPoster(), null);
|
||||
Resource posterResource = uploadService.storeBase64Image(PlayEduBContext.getAdminUserID(), req.getPoster(), null);
|
||||
// 视频的封面素材改为[隐藏 && 属于视频的子素材]
|
||||
resourceService.changeParentId(posterResource.getId(), videoResource.getId());
|
||||
// 视频信息
|
||||
|
@ -4,25 +4,32 @@ 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 java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
*
|
||||
* @TableName resources
|
||||
*/
|
||||
@TableName(value = "resources")
|
||||
@TableName(value ="resources")
|
||||
@Data
|
||||
public class Resource implements Serializable {
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@JsonProperty("admin_id")
|
||||
private Integer adminId;
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
@ -64,16 +71,22 @@ public class Resource implements Serializable {
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@JsonProperty("created_at")
|
||||
private Date createdAt;
|
||||
|
||||
/**
|
||||
* 所属素材
|
||||
*/
|
||||
@JsonProperty("parent_id")
|
||||
private Integer parentId;
|
||||
|
||||
/**
|
||||
* 隐藏[0:否,1:是]
|
||||
*/
|
||||
@JsonProperty("is_hidden")
|
||||
@JsonIgnore
|
||||
private Integer isHidden;
|
||||
|
||||
@TableField(exist = false)
|
||||
@ -92,17 +105,18 @@ public class Resource implements Serializable {
|
||||
}
|
||||
Resource other = (Resource) that;
|
||||
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
|
||||
&& (this.getType() == null ? other.getType() == null : this.getType().equals(other.getType()))
|
||||
&& (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
|
||||
&& (this.getExtension() == null ? other.getExtension() == null : this.getExtension().equals(other.getExtension()))
|
||||
&& (this.getSize() == null ? other.getSize() == null : this.getSize().equals(other.getSize()))
|
||||
&& (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()))
|
||||
&& (this.getParentId() == null ? other.getParentId() == null : this.getParentId().equals(other.getParentId()))
|
||||
&& (this.getIsHidden() == null ? other.getIsHidden() == null : this.getIsHidden().equals(other.getIsHidden()));
|
||||
&& (this.getAdminId() == null ? other.getAdminId() == null : this.getAdminId().equals(other.getAdminId()))
|
||||
&& (this.getType() == null ? other.getType() == null : this.getType().equals(other.getType()))
|
||||
&& (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
|
||||
&& (this.getExtension() == null ? other.getExtension() == null : this.getExtension().equals(other.getExtension()))
|
||||
&& (this.getSize() == null ? other.getSize() == null : this.getSize().equals(other.getSize()))
|
||||
&& (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()))
|
||||
&& (this.getParentId() == null ? other.getParentId() == null : this.getParentId().equals(other.getParentId()))
|
||||
&& (this.getIsHidden() == null ? other.getIsHidden() == null : this.getIsHidden().equals(other.getIsHidden()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -110,6 +124,7 @@ public class Resource implements Serializable {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
|
||||
result = prime * result + ((getAdminId() == null) ? 0 : getAdminId().hashCode());
|
||||
result = prime * result + ((getType() == null) ? 0 : getType().hashCode());
|
||||
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
|
||||
result = prime * result + ((getExtension() == null) ? 0 : getExtension().hashCode());
|
||||
@ -131,6 +146,7 @@ public class Resource implements Serializable {
|
||||
sb.append(" [");
|
||||
sb.append("Hash = ").append(hashCode());
|
||||
sb.append(", id=").append(id);
|
||||
sb.append(", adminId=").append(adminId);
|
||||
sb.append(", type=").append(type);
|
||||
sb.append(", name=").append(name);
|
||||
sb.append(", extension=").append(extension);
|
||||
|
@ -7,7 +7,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【resources】的数据库操作Mapper
|
||||
* @createDate 2023-03-08 16:55:59
|
||||
* @createDate 2023-03-13 10:25:30
|
||||
* @Entity xyz.playedu.api.domain.Resource
|
||||
*/
|
||||
@Mapper
|
||||
|
@ -6,8 +6,6 @@ import xyz.playedu.api.exception.NotFoundException;
|
||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
import xyz.playedu.api.types.paginate.ResourcePaginateFilter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【resources】的数据库操作Service
|
||||
@ -17,7 +15,7 @@ public interface ResourceService extends IService<Resource> {
|
||||
|
||||
PaginationResult<Resource> paginate(int page, int size, ResourcePaginateFilter filter);
|
||||
|
||||
Resource create(String categoryIds, String type, String filename, String ext, Long size, String disk, String fileId, String path, String url);
|
||||
Resource create(Integer adminId, String categoryIds, String type, String filename, String ext, Long size, String disk, String fileId, String path, String url);
|
||||
|
||||
Resource findOrFail(Integer id) throws NotFoundException;
|
||||
|
||||
|
@ -9,7 +9,7 @@ import xyz.playedu.api.exception.ServiceException;
|
||||
* @create 2023/3/8 14:02
|
||||
*/
|
||||
public interface UploadService {
|
||||
Resource storeMinio(MultipartFile file, String categoryIds) throws ServiceException;
|
||||
Resource storeMinio(Integer adminId, MultipartFile file, String categoryIds) throws ServiceException;
|
||||
|
||||
Resource storeBase64Image(String content, String categoryIds) throws ServiceException;
|
||||
Resource storeBase64Image(Integer adminId, String content, String categoryIds) throws ServiceException;
|
||||
}
|
||||
|
@ -54,6 +54,9 @@ public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource> i
|
||||
if (filter.getType() != null) {
|
||||
wrapper.eq("type", filter.getType());
|
||||
}
|
||||
if (filter.getAdminId() != null && !filter.getAdminId().equals(0)) {
|
||||
wrapper.eq("admin_id", filter.getAdminId());
|
||||
}
|
||||
if (filter.getCategoryIds() != null && filter.getCategoryIds().trim().length() > 0) {
|
||||
List<Integer> categoryIds = Arrays.stream(filter.getCategoryIds().split(",")).map(Integer::valueOf).toList();
|
||||
List<Integer> ids = relationService.getRidsByCids(categoryIds);
|
||||
@ -89,8 +92,9 @@ public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource> i
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Resource create(String categoryIds, String type, String filename, String ext, Long size, String disk, String fileId, String path, String url) {
|
||||
public Resource create(Integer adminId, String categoryIds, String type, String filename, String ext, Long size, String disk, String fileId, String path, String url) {
|
||||
Resource resource = new Resource();
|
||||
resource.setAdminId(adminId);
|
||||
resource.setType(type);
|
||||
resource.setName(filename);
|
||||
resource.setExtension(ext);
|
||||
|
@ -8,14 +8,11 @@ import xyz.playedu.api.constant.BackendConstant;
|
||||
import xyz.playedu.api.domain.Resource;
|
||||
import xyz.playedu.api.exception.ServiceException;
|
||||
import xyz.playedu.api.service.MinioService;
|
||||
import xyz.playedu.api.service.ResourceCategoryService;
|
||||
import xyz.playedu.api.service.ResourceService;
|
||||
import xyz.playedu.api.service.UploadService;
|
||||
import xyz.playedu.api.util.Base64Util;
|
||||
import xyz.playedu.api.util.HelperUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
* @create 2023/3/8 14:02
|
||||
@ -31,7 +28,7 @@ public class UploadServiceImpl implements UploadService {
|
||||
private MinioService minioService;
|
||||
|
||||
@Override
|
||||
public Resource storeMinio(MultipartFile file, String categoryIds) throws ServiceException {
|
||||
public Resource storeMinio(Integer adminId, MultipartFile file, String categoryIds) throws ServiceException {
|
||||
if (file == null || file.isEmpty() || file.getOriginalFilename() == null) {
|
||||
throw new ServiceException("请上传文件");
|
||||
}
|
||||
@ -53,11 +50,11 @@ public class UploadServiceImpl implements UploadService {
|
||||
// 保存文件
|
||||
String url = minioService.saveFile(file, savePath, BackendConstant.RESOURCE_EXT_2_CONTENT_TYPE.get(ext));
|
||||
// 上传记录
|
||||
return resourceService.create(categoryIds, type, oFilename, ext, file.getSize(), BackendConstant.STORAGE_DRIVER_MINIO, "", savePath, url);
|
||||
return resourceService.create(adminId, categoryIds, type, oFilename, ext, file.getSize(), BackendConstant.STORAGE_DRIVER_MINIO, "", savePath, url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Resource storeBase64Image(String content, String categoryIds) throws ServiceException {
|
||||
public Resource storeBase64Image(Integer adminId, String content, String categoryIds) throws ServiceException {
|
||||
// data:image/jpeg;base64,
|
||||
String[] base64Rows = content.split(",");
|
||||
// 解析出content-type
|
||||
@ -78,6 +75,6 @@ public class UploadServiceImpl implements UploadService {
|
||||
// 保存文件
|
||||
String url = minioService.saveBytes(binary, savePath, BackendConstant.RESOURCE_EXT_2_CONTENT_TYPE.get(ext));
|
||||
// 上传记录
|
||||
return resourceService.create(categoryIds, type, filename, ext, (long) binary.length, BackendConstant.STORAGE_DRIVER_MINIO, "", savePath, url);
|
||||
return resourceService.create(adminId, categoryIds, type, filename, ext, (long) binary.length, BackendConstant.STORAGE_DRIVER_MINIO, "", savePath, url);
|
||||
}
|
||||
}
|
||||
|
@ -23,4 +23,6 @@ public class ResourcePaginateFilter {
|
||||
|
||||
private String type;
|
||||
|
||||
private Integer adminId;
|
||||
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
<resultMap id="BaseResultMap" type="xyz.playedu.api.domain.Resource">
|
||||
<id property="id" column="id" jdbcType="INTEGER"/>
|
||||
<result property="adminId" column="admin_id" jdbcType="INTEGER"/>
|
||||
<result property="type" column="type" jdbcType="VARCHAR"/>
|
||||
<result property="name" column="name" jdbcType="VARCHAR"/>
|
||||
<result property="extension" column="extension" jdbcType="VARCHAR"/>
|
||||
@ -20,9 +21,10 @@
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,type,name,
|
||||
extension,size,disk,
|
||||
file_id,path,url,
|
||||
created_at,parent_id,is_hidden
|
||||
id,admin_id,type,
|
||||
name,extension,size,
|
||||
disk,file_id,path,
|
||||
url,created_at,parent_id,
|
||||
is_hidden
|
||||
</sql>
|
||||
</mapper>
|
||||
|
Loading…
x
Reference in New Issue
Block a user