新增: 资源名称和分类编辑接口

This commit is contained in:
none
2023-06-13 09:57:11 +08:00
parent 147da9f38a
commit 12056f648f
11 changed files with 91 additions and 97 deletions

View File

@@ -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);
}

View File

@@ -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);
}
});
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}