diff --git a/src/main/java/net/geedge/asw/module/app/controller/PackageController.java b/src/main/java/net/geedge/asw/module/app/controller/PackageController.java index a7f2ebf..0e4a3e9 100644 --- a/src/main/java/net/geedge/asw/module/app/controller/PackageController.java +++ b/src/main/java/net/geedge/asw/module/app/controller/PackageController.java @@ -1,5 +1,6 @@ package net.geedge.asw.module.app.controller; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import net.geedge.asw.common.util.R; import net.geedge.asw.common.util.RCode; @@ -12,53 +13,63 @@ import org.springframework.web.bind.annotation.*; import java.util.Map; @RestController -@RequestMapping("/api/v1/package") +@RequestMapping("/api/v1/{workspaceId}/package") public class PackageController { @Autowired private IPackageService packageService; @GetMapping("/{id}") - public R detail(@PathVariable("id") String id) { - PackageEntity entity = packageService.getById(id); + public R detail(@PathVariable String workspaceId, + @PathVariable("id") String id) { + PackageEntity entity = packageService.getOne(new LambdaQueryWrapper() + .eq(PackageEntity::getId, id) + .eq(PackageEntity::getWorkspaceId, workspaceId)); return R.ok().putData("record", entity); } @GetMapping - public R list(@RequestParam Map params) { + public R list(@PathVariable String workspaceId, + @RequestParam Map params) { T.VerifyUtil.is(params).notNull() - .and(T.MapUtil.getStr(params, "workspaceId")).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY); + .and(workspaceId).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY); + params.put("workspaceId", workspaceId); Page page = packageService.queryList(params); return R.ok(page); } @PostMapping - public R add(@RequestBody PackageEntity entity) { + public R add(@PathVariable String workspaceId, + @RequestBody PackageEntity entity) { T.VerifyUtil.is(entity).notNull() .and(entity.getName()).notEmpty(RCode.NAME_CANNOT_EMPTY) .and(entity.getDescription()).notEmpty(RCode.PACKAGE_DESCRIPTION_CANNOT_EMPTY) - .and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY); + .and(workspaceId).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY); + entity.setWorkspaceId(workspaceId); PackageEntity pkgEntity = packageService.savePackage(entity); return R.ok().putData("id", pkgEntity.getId()); } @PutMapping - public R update(@RequestBody PackageEntity entity) { + public R update(@PathVariable String workspaceId, + @RequestBody PackageEntity entity) { T.VerifyUtil.is(entity).notNull() .and(entity.getId()).notEmpty(RCode.ID_CANNOT_EMPTY) .and(entity.getName()).notEmpty(RCode.NAME_CANNOT_EMPTY) .and(entity.getDescription()).notEmpty(RCode.PACKAGE_DESCRIPTION_CANNOT_EMPTY) - .and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY); + .and(workspaceId).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY); + entity.setWorkspaceId(workspaceId); PackageEntity pkgEntity = packageService.updatePackage(entity); return R.ok().putData("id", pkgEntity.getId()); } @DeleteMapping - public R delete(String[] ids) { + public R delete(@PathVariable String workspaceId, + String[] ids) { T.VerifyUtil.is(ids).notEmpty(); - packageService.removePackage(T.ListUtil.of(ids)); + packageService.removePackage(T.ListUtil.of(ids), workspaceId); return R.ok(); } diff --git a/src/main/java/net/geedge/asw/module/app/service/IPackageService.java b/src/main/java/net/geedge/asw/module/app/service/IPackageService.java index c86eb03..c09fe7b 100644 --- a/src/main/java/net/geedge/asw/module/app/service/IPackageService.java +++ b/src/main/java/net/geedge/asw/module/app/service/IPackageService.java @@ -15,5 +15,5 @@ public interface IPackageService extends IService{ PackageEntity updatePackage(PackageEntity entity); - void removePackage(List ids); + void removePackage(List ids, String workspaceId); } diff --git a/src/main/java/net/geedge/asw/module/app/service/impl/PackageServiceImpl.java b/src/main/java/net/geedge/asw/module/app/service/impl/PackageServiceImpl.java index d36084a..7a41422 100644 --- a/src/main/java/net/geedge/asw/module/app/service/impl/PackageServiceImpl.java +++ b/src/main/java/net/geedge/asw/module/app/service/impl/PackageServiceImpl.java @@ -80,9 +80,11 @@ public class PackageServiceImpl extends ServiceImpl i @Override @Transactional(rollbackFor = Exception.class) - public void removePackage(List ids) { + public void removePackage(List ids, String workspaceId) { // remove - this.removeBatchByIds(ids); + this.remove(new LambdaQueryWrapper() + .eq(PackageEntity::getWorkspaceId, workspaceId) + .in(PackageEntity::getId, ids)); // workbook resource workbookResourceService.removeResource(ids, WorkbookConstant.ResourceType.PACKAGE.getValue()); }