移动到playedu-api目录

This commit is contained in:
xxx
2024-06-05 16:13:27 +08:00
parent 5b027dfa23
commit e97f0318e6
349 changed files with 209 additions and 209 deletions

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>xyz.playedu</groupId>
<artifactId>playedu</artifactId>
<version>1.2</version>
</parent>
<artifactId>playedu-resource</artifactId>
<dependencies>
<dependency>
<groupId>xyz.playedu</groupId>
<artifactId>playedu-common</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,177 @@
/*
* Copyright (C) 2023 杭州白书科技有限公司
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package xyz.playedu.resource.domain;
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 lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* @TableName resources
*/
@TableName(value = "resources")
@Data
public class Resource implements Serializable {
/** */
@TableId(type = IdType.AUTO)
private Integer id;
/** */
@JsonProperty("admin_id")
private Integer adminId;
/** 类型 */
private String type;
/** 资源名 */
private String name;
/** 文件类型 */
private String extension;
/** 大小[字节] */
private Long size;
/** 存储磁盘 */
private String disk;
/** 文件id */
@JsonProperty("file_id")
private String fileId;
/** 相对地址 */
private String path;
/** URL地址 */
private String url;
/** */
@JsonProperty("created_at")
private Date createdAt;
/** 所属素材 */
@JsonProperty("parent_id")
private Integer parentId;
/** 隐藏[0:否,1:是] */
@JsonIgnore private Integer isHidden;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
Resource other = (Resource) that;
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
&& (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
public int hashCode() {
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());
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());
return result;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
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);
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);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
return sb.toString();
}
}

View File

@@ -0,0 +1,81 @@
/*
* Copyright (C) 2023 杭州白书科技有限公司
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package xyz.playedu.resource.domain;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
/**
* @TableName resource_category
*/
@TableName(value = "resource_category")
@Data
public class ResourceCategory implements Serializable {
/** */
private Integer cid;
/** */
private Integer rid;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
ResourceCategory other = (ResourceCategory) that;
return (this.getCid() == null
? other.getCid() == null
: this.getCid().equals(other.getCid()))
&& (this.getRid() == null
? other.getRid() == null
: this.getRid().equals(other.getRid()));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getCid() == null) ? 0 : getCid().hashCode());
result = prime * result + ((getRid() == null) ? 0 : getRid().hashCode());
return result;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", cid=").append(cid);
sb.append(", rid=").append(rid);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
return sb.toString();
}
}

View File

@@ -0,0 +1,99 @@
/*
* Copyright (C) 2023 杭州白书科技有限公司
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package xyz.playedu.resource.domain;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* @TableName resource_videos
*/
@TableName(value = "resource_videos")
@Data
public class ResourceVideo implements Serializable {
/** */
private Integer rid;
/** 封面 */
private String poster;
/** 视频时长[s] */
private Integer duration;
/** 创建时间 */
@JsonIgnore private Date createdAt;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
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()));
}
@Override
public int hashCode() {
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;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
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);
sb.append("]");
return sb.toString();
}
}

View File

@@ -0,0 +1,30 @@
/*
* Copyright (C) 2023 杭州白书科技有限公司
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package xyz.playedu.resource.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import xyz.playedu.resource.domain.ResourceCategory;
/**
* @author tengteng
* @description 针对表【resource_category】的数据库操作Mapper
* @createDate 2023-03-08 16:54:56
*/
@Mapper
public interface ResourceCategoryMapper extends BaseMapper<ResourceCategory> {}

View File

@@ -0,0 +1,40 @@
/*
* Copyright (C) 2023 杭州白书科技有限公司
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package xyz.playedu.resource.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import xyz.playedu.common.types.paginate.ResourcePaginateFilter;
import xyz.playedu.resource.domain.Resource;
import java.util.List;
/**
* @author tengteng
* @description 针对表【resources】的数据库操作Mapper
* @createDate 2023-03-13 10:25:30
*/
@Mapper
public interface ResourceMapper extends BaseMapper<Resource> {
List<Resource> paginate(ResourcePaginateFilter filter);
Long paginateCount(ResourcePaginateFilter filter);
List<String> paginateType(ResourcePaginateFilter filter);
}

View File

@@ -0,0 +1,30 @@
/*
* Copyright (C) 2023 杭州白书科技有限公司
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package xyz.playedu.resource.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import xyz.playedu.resource.domain.ResourceVideo;
/**
* @author tengteng
* @description 针对表【resource_videos】的数据库操作Mapper
* @createDate 2023-03-08 13:39:06
*/
@Mapper
public interface ResourceVideoMapper extends BaseMapper<ResourceVideo> {}

View File

@@ -0,0 +1,28 @@
/*
* Copyright (C) 2023 杭州白书科技有限公司
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package xyz.playedu.resource.service;
import com.baomidou.mybatisplus.extension.service.IService;
import xyz.playedu.resource.domain.ResourceCategory;
import java.util.List;
public interface ResourceCategoryService extends IService<ResourceCategory> {
void rebuild(Integer resourceId, List<Integer> categoryIds);
List<Integer> getRidsByCategoryId(Integer id);
}

View File

@@ -0,0 +1,64 @@
/*
* Copyright (C) 2023 杭州白书科技有限公司
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package xyz.playedu.resource.service;
import com.baomidou.mybatisplus.extension.service.IService;
import xyz.playedu.common.exception.NotFoundException;
import xyz.playedu.common.types.paginate.PaginationResult;
import xyz.playedu.common.types.paginate.ResourcePaginateFilter;
import xyz.playedu.resource.domain.Resource;
import java.util.List;
public interface ResourceService extends IService<Resource> {
PaginationResult<Resource> paginate(int page, int size, ResourcePaginateFilter filter);
List<String> paginateType(ResourcePaginateFilter filter);
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;
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);
Integer total(String type);
Integer duration(Integer id);
void updateNameAndCategoryId(Integer id, String name, Integer categoryId);
List<Integer> categoryIds(Integer resourceId);
Integer total(List<String> types);
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright (C) 2023 杭州白书科技有限公司
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package xyz.playedu.resource.service;
import com.baomidou.mybatisplus.extension.service.IService;
import xyz.playedu.resource.domain.ResourceVideo;
import java.util.List;
/**
* @author tengteng
* @description 针对表【resource_videos】的数据库操作Service
* @createDate 2023-03-02 15:13:03
*/
public interface ResourceVideoService extends IService<ResourceVideo> {
void create(Integer resourceId, Integer duration, String poster);
void removeByRid(Integer resourceId);
List<ResourceVideo> chunksByRids(List<Integer> resourceIds);
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright (C) 2023 杭州白书科技有限公司
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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.resource.domain.Resource;
/**
* @Author 杭州白书科技有限公司
*
* @create 2023/3/8 14:02
*/
public interface UploadService {
UploadFileInfo upload(MultipartFile file, String dir) throws ServiceException;
Resource storeMinio(Integer adminId, MultipartFile file, String categoryIds)
throws ServiceException;
Resource storeBase64Image(Integer adminId, String content, String categoryIds)
throws ServiceException;
UserUploadImageLog userAvatar(Integer userId, MultipartFile file, String typed, String scene);
}

View File

@@ -0,0 +1,58 @@
/*
* Copyright (C) 2023 杭州白书科技有限公司
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package xyz.playedu.resource.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import xyz.playedu.resource.domain.ResourceCategory;
import xyz.playedu.resource.mapper.ResourceCategoryMapper;
import xyz.playedu.resource.service.ResourceCategoryService;
import java.util.ArrayList;
import java.util.List;
@Service
public class ResourceCategoryServiceImpl
extends ServiceImpl<ResourceCategoryMapper, ResourceCategory>
implements ResourceCategoryService {
@Override
public void rebuild(Integer resourceId, List<Integer> categoryIds) {
remove(query().getWrapper().eq("rid", resourceId));
List<ResourceCategory> data = new ArrayList<>();
categoryIds.forEach(
categoryId -> {
data.add(
new ResourceCategory() {
{
setCid(categoryId);
setRid(resourceId);
}
});
});
saveBatch(data);
}
@Override
public List<Integer> getRidsByCategoryId(Integer id) {
return list(query().getWrapper().in("cid", id)).stream()
.map(ResourceCategory::getRid)
.toList();
}
}

View File

@@ -0,0 +1,194 @@
/*
* Copyright (C) 2023 杭州白书科技有限公司
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package xyz.playedu.resource.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
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.types.paginate.PaginationResult;
import xyz.playedu.common.types.paginate.ResourcePaginateFilter;
import xyz.playedu.resource.domain.Resource;
import xyz.playedu.resource.domain.ResourceCategory;
import xyz.playedu.resource.domain.ResourceVideo;
import xyz.playedu.resource.mapper.ResourceMapper;
import xyz.playedu.resource.service.ResourceCategoryService;
import xyz.playedu.resource.service.ResourceService;
import xyz.playedu.resource.service.ResourceVideoService;
import java.util.*;
/**
* @author tengteng
* @description 针对表【resources】的数据库操作Service实现
* @createDate 2023-02-23 10:50:26
*/
@Service
public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource>
implements ResourceService {
@Autowired private ResourceVideoService resourceVideoService;
@Autowired private ResourceCategoryService relationService;
@Override
public PaginationResult<Resource> paginate(int page, int size, ResourcePaginateFilter filter) {
PaginationResult<Resource> pageResult = new PaginationResult<>();
filter.setPageStart((page - 1) * size);
filter.setPageSize(size);
pageResult.setData(getBaseMapper().paginate(filter));
pageResult.setTotal(getBaseMapper().paginateCount(filter));
return pageResult;
}
@Override
public List<String> paginateType(ResourcePaginateFilter filter) {
return getBaseMapper().paginateType(filter);
}
@Override
@Transactional
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);
resource.setSize(size);
resource.setDisk(disk);
resource.setFileId(fileId);
resource.setPath(path);
resource.setUrl(url);
resource.setCreatedAt(new Date());
save(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);
}
return resource;
}
@Override
public Resource findOrFail(Integer id) throws NotFoundException {
Resource resource = getById(id);
if (resource == null) {
throw new NotFoundException("资源不存在");
}
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));
}
@Override
public List<Resource> chunks(List<Integer> ids, List<String> fields) {
return list(query().getWrapper().in("id", ids).select(fields));
}
@Override
public Integer total(String type) {
return Math.toIntExact(count(query().getWrapper().eq("type", type).eq("is_hidden", 0)));
}
@Override
public Integer duration(Integer id) {
ResourceVideo resourceVideo =
resourceVideoService.getOne(
resourceVideoService.query().getWrapper().eq("rid", id));
if (resourceVideo == null) {
return null;
}
return resourceVideo.getDuration();
}
@Override
@Transactional
public void updateNameAndCategoryId(Integer id, String name, Integer categoryId) {
Resource resource = new Resource();
resource.setId(id);
resource.setName(name);
updateById(resource);
relationService.rebuild(
id,
new ArrayList<>() {
{
add(categoryId);
}
});
}
@Override
public List<Integer> categoryIds(Integer resourceId) {
return relationService
.list(relationService.query().getWrapper().eq("rid", resourceId))
.stream()
.map(ResourceCategory::getCid)
.toList();
}
@Override
public Integer total(List<String> types) {
return Math.toIntExact(count(query().getWrapper().in("type", types).eq("is_hidden", 0)));
}
}

View File

@@ -0,0 +1,60 @@
/*
* Copyright (C) 2023 杭州白书科技有限公司
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package xyz.playedu.resource.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import xyz.playedu.resource.domain.ResourceVideo;
import xyz.playedu.resource.mapper.ResourceVideoMapper;
import xyz.playedu.resource.service.ResourceVideoService;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* @author tengteng
* @description 针对表【resource_videos】的数据库操作Service实现
* @createDate 2023-03-02 15:13:03
*/
@Service
public class ResourceVideoServiceImpl extends ServiceImpl<ResourceVideoMapper, ResourceVideo>
implements ResourceVideoService {
@Override
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);
}
@Override
public void removeByRid(Integer resourceId) {
remove(query().getWrapper().eq("rid", resourceId));
}
@Override
public List<ResourceVideo> chunksByRids(List<Integer> resourceIds) {
if (resourceIds == null || resourceIds.size() == 0) {
return new ArrayList<>();
}
return list(query().getWrapper().in("rid", resourceIds));
}
}

View File

@@ -0,0 +1,170 @@
/*
* Copyright (C) 2023 杭州白书科技有限公司
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package xyz.playedu.resource.service.impl;
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.exception.ServiceException;
import xyz.playedu.common.service.AppConfigService;
import xyz.playedu.common.service.UserUploadImageLogService;
import xyz.playedu.common.types.UploadFileInfo;
import xyz.playedu.common.util.Base64Util;
import xyz.playedu.common.util.HelperUtil;
import xyz.playedu.common.util.S3Util;
import xyz.playedu.resource.domain.Resource;
import xyz.playedu.resource.service.ResourceService;
import xyz.playedu.resource.service.UploadService;
import java.util.Date;
@Service
@Slf4j
public class UploadServiceImpl implements UploadService {
@Autowired private ResourceService resourceService;
@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) {
throw new ServiceException("请上传文件");
}
// 上传上来的文件名名
String filename = file.getOriginalFilename();
UploadFileInfo fileInfo = new UploadFileInfo();
// 文件大小
fileInfo.setSize(file.getSize());
// 解析扩展名
fileInfo.setExtension(HelperUtil.fileExt(filename));
// 解析扩展名称对应的系统资源类型
fileInfo.setResourceType(BackendConstant.RESOURCE_EXT_2_TYPE.get(fileInfo.getExtension()));
// 检测是否为系统不支持的资源类型
if (fileInfo.getResourceType() == null) {
throw new ServiceException("当前资源扩展不支持上传");
}
// 上传原文件的文件名
fileInfo.setOriginalName(filename.replaceAll("(?i)." + fileInfo.getExtension(), ""));
// 自定义新的存储文件名
fileInfo.setSaveName(HelperUtil.randomString(32) + "." + fileInfo.getExtension());
// 生成保存的相对路径
if (dir == null || dir.isEmpty()) {
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(
file,
fileInfo.getSavePath(),
BackendConstant.RESOURCE_EXT_2_CONTENT_TYPE.get(fileInfo.getExtension()));
fileInfo.setUrl(url);
return fileInfo;
}
@Override
@SneakyThrows
public Resource storeMinio(Integer adminId, MultipartFile file, String categoryIds) {
UploadFileInfo info = upload(file, null);
return resourceService.create(
adminId,
categoryIds,
info.getResourceType(),
info.getOriginalName(),
info.getExtension(),
file.getSize(),
BackendConstant.STORAGE_DRIVER_MINIO,
"",
info.getSavePath(),
info.getUrl());
}
@Override
@SneakyThrows
public Resource storeBase64Image(Integer adminId, String content, String categoryIds) {
// data:image/jpeg;base64,
String[] base64Rows = content.split(",");
// 解析出content-type
String contentType =
base64Rows[0].replaceAll("data:", "").replaceAll(";base64", "").toLowerCase();
// 解析出文件格式
String ext = contentType.replaceAll("image/", "");
// 通过文件格式解析资源类型
String type = BackendConstant.RESOURCE_EXT_2_TYPE.get(ext);
// 资源类型必须存在
if (type == null) {
throw new ServiceException("资源类型不支持");
}
byte[] binary = Base64Util.decode(base64Rows[1]);
String filename = HelperUtil.randomString(32) + "." + ext;
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));
// 上传记录
return resourceService.create(
adminId,
categoryIds,
type,
filename,
ext,
(long) binary.length,
BackendConstant.STORAGE_DRIVER_MINIO,
"",
savePath,
url);
}
@Override
@SneakyThrows
public UserUploadImageLog userAvatar(
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(BackendConstant.STORAGE_DRIVER_MINIO);
log.setPath(info.getSavePath());
log.setUrl(info.getUrl());
log.setName(info.getOriginalName());
log.setCreatedAt(new Date());
userUploadImageLogService.save(log);
return log;
}
}

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="xyz.playedu.resource.mapper.ResourceCategoryMapper">
<resultMap id="BaseResultMap" type="xyz.playedu.resource.domain.ResourceCategory">
<result property="cid" column="cid" jdbcType="INTEGER"/>
<result property="rid" column="rid" jdbcType="INTEGER"/>
</resultMap>
<sql id="Base_Column_List">
cid,rid
</sql>
</mapper>

View File

@@ -0,0 +1,188 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="xyz.playedu.resource.mapper.ResourceMapper">
<resultMap id="BaseResultMap" type="xyz.playedu.resource.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"/>
<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"/>
</resultMap>
<sql id="Base_Column_List">
id
,admin_id,type,
name,extension,size,
disk,file_id,path,
url,created_at,parent_id,
is_hidden
</sql>
<select id="paginate" resultType="xyz.playedu.resource.domain.Resource">
SELECT `resources`.*
FROM `resources`
<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
AND `resource_category`.`cid` IS NULL
</when>
<otherwise>
INNER JOIN `resource_category` ON `resource_category`.`rid` = `resources`.`id`
WHERE `resources`.`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
</otherwise>
</choose>
<if test="name != null and name != ''">
AND `resources`.`name` LIKE concat('%',#{name},'%')
</if>
<if test="disk != null and disk != ''">
AND `resources`.`disk` = #{disk}
</if>
<if test="extension != null and extension != ''">
AND `resources`.`extension` = #{extension}
</if>
<if test="type != null and type != ''">
AND `resources`.`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}
</if>
<if test="sortAlgo == 'asc'">
<choose>
<when test="sortField == 'size'">
ORDER BY `resources`.`size` ASC
</when>
<when test="sortField == 'created_at'">
ORDER BY `resources`.`created_at` ASC
</when>
<otherwise>
ORDER BY `resources`.`id` ASC
</otherwise>
</choose>
</if>
<if test="sortAlgo != 'asc'">
<choose>
<when test="sortField == 'size'">
ORDER BY `resources`.`size` DESC
</when>
<when test="sortField == 'created_at'">
ORDER BY `resources`.`created_at` DESC
</when>
<otherwise>
ORDER BY `resources`.`id` DESC
</otherwise>
</choose>
</if>
LIMIT #{pageStart}, #{pageSize};
</select>
<select id="paginateCount" resultType="java.lang.Long">
SELECT count(1)
FROM `resources`
<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
AND `resource_category`.`cid` IS NULL
</when>
<otherwise>
INNER JOIN `resource_category` ON `resource_category`.`rid` = `resources`.`id`
WHERE `resources`.`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
</otherwise>
</choose>
<if test="name != null and name != ''">
AND `resources`.`name` LIKE concat('%',#{name},'%')
</if>
<if test="disk != null and disk != ''">
AND `resources`.`disk` = #{disk}
</if>
<if test="extension != null and extension != ''">
AND `resources`.`extension` = #{extension}
</if>
<if test="type != null and type != ''">
AND `resources`.`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}
</if>
</select>
<select id="paginateType" resultType="java.lang.String">
SELECT DISTINCT ( `resources`.`type` )
FROM `resources`
<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
AND `resource_category`.`cid` IS NULL
</when>
<otherwise>
INNER JOIN `resource_category` ON `resource_category`.`rid` = `resources`.`id`
WHERE `resources`.`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
</otherwise>
</choose>
<if test="name != null and name != ''">
AND `resources`.`name` LIKE concat('%',#{name},'%')
</if>
<if test="disk != null and disk != ''">
AND `resources`.`disk` = #{disk}
</if>
<if test="extension != null and extension != ''">
AND `resources`.`extension` = #{extension}
</if>
<if test="type != null and type != ''">
AND `resources`.`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}
</if>
</select>
</mapper>

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!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">
<resultMap id="BaseResultMap" type="xyz.playedu.resource.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,poster,duration,
created_at
</sql>
</mapper>