mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-12-25 20:35:35 +08:00
新增: 资源名称和分类编辑接口
This commit is contained in:
@@ -54,5 +54,5 @@ public interface ResourceService extends IService<Resource> {
|
||||
|
||||
Integer duration(Integer id);
|
||||
|
||||
void categoryChange(List<Integer> ids, Integer categoryId);
|
||||
void updateNameAndCategoryId(Integer id, String name, Integer categoryId);
|
||||
}
|
||||
|
||||
@@ -157,7 +157,19 @@ public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void categoryChange(List<Integer> ids, Integer categoryId) {
|
||||
relationService.rebuild(ids, categoryId);
|
||||
@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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,18 +31,21 @@ public class ResourceCategoryRelationServiceImpl
|
||||
extends ServiceImpl<ResourceCategoryRelationMapper, ResourceCategoryRelation>
|
||||
implements ResourceCategoryRelationService {
|
||||
@Override
|
||||
public void rebuild(List<Integer> ids, Integer categoryId) {
|
||||
remove(query().getWrapper().in("rid", ids));
|
||||
public void rebuild(Integer resourceId, List<Integer> categoryIds) {
|
||||
remove(query().getWrapper().eq("rid", resourceId));
|
||||
|
||||
List<ResourceCategoryRelation> data = new ArrayList<>();
|
||||
ids.forEach(
|
||||
(item) ->
|
||||
data.add(
|
||||
new ResourceCategoryRelation() {
|
||||
{
|
||||
setCid(categoryId);
|
||||
setRid(item);
|
||||
}
|
||||
}));
|
||||
categoryIds.forEach(
|
||||
categoryId -> {
|
||||
data.add(
|
||||
new ResourceCategoryRelation() {
|
||||
{
|
||||
setCid(categoryId);
|
||||
setRid(resourceId);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
saveBatch(data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,5 +22,5 @@ import xyz.playedu.api.domain.ResourceCategoryRelation;
|
||||
import java.util.List;
|
||||
|
||||
public interface ResourceCategoryRelationService extends IService<ResourceCategoryRelation> {
|
||||
public void rebuild(List<Integer> ids, Integer categoryId);
|
||||
void rebuild(Integer resourceId, List<Integer> categoryIds);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user