diff --git a/src/main/java/net/geedge/asw/module/app/controller/ApplicationController.java b/src/main/java/net/geedge/asw/module/app/controller/ApplicationController.java index a182067..1d43628 100644 --- a/src/main/java/net/geedge/asw/module/app/controller/ApplicationController.java +++ b/src/main/java/net/geedge/asw/module/app/controller/ApplicationController.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 jakarta.servlet.http.HttpServletResponse; import net.geedge.asw.common.util.ASWException; @@ -18,7 +19,7 @@ import java.util.List; import java.util.Map; @RestController -@RequestMapping("/api/v1/application") +@RequestMapping("/api/v1/{workspaceId}/application") public class ApplicationController { @Autowired @@ -28,9 +29,12 @@ public class ApplicationController { private ISysUserService userService; @GetMapping("/{id}") - public R detail(@PathVariable String id) { - ApplicationEntity entity = applicationService.getById(id); - if (T.ObjectUtil.isNull(entity)){ + public R detail(@PathVariable String workspaceId, + @PathVariable String id) { + ApplicationEntity entity = applicationService.getOne(new LambdaQueryWrapper() + .eq(ApplicationEntity::getId, id) + .eq(ApplicationEntity::getWorkspaceId, workspaceId)); + if (T.ObjectUtil.isNull(entity)) { throw new ASWException(RCode.APP_NOT_EXIST); } SysUserEntity createUser = userService.getById(entity.getCreateUserId()); @@ -41,13 +45,11 @@ public class ApplicationController { } @GetMapping("/{id}/{version}") - public R detail(@PathVariable String id, + public R detail(@PathVariable String workspaceId, + @PathVariable String id, @PathVariable(required = false) String version) { - ApplicationEntity entity = applicationService.getById(id); - if (T.StrUtil.isNotEmpty(version)){ - entity = applicationService.queryByApplicationAndLog(id, version); - } - if (T.ObjectUtil.isNull(entity)){ + ApplicationEntity entity = applicationService.queryByApplicationAndLog(id, version, workspaceId); + if (T.ObjectUtil.isNull(entity)) { throw new ASWException(RCode.APP_NOT_EXIST); } SysUserEntity createUser = userService.getById(entity.getCreateUserId()); @@ -59,29 +61,34 @@ public class ApplicationController { @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 = applicationService.queryList(params); return R.ok(page); } @PostMapping - public R add(@RequestBody ApplicationEntity entity) { + public R add(@PathVariable String workspaceId, + @RequestBody ApplicationEntity entity) { T.VerifyUtil.is(entity).notNull() .and(entity.getName()).notEmpty(RCode.APP_NAME_CANNOT_EMPTY) //.and(entity.getLongName()).notEmpty(RCode.APP_LONGNAME_CANNOT_EMPTY) //.and(entity.getProperties()).notEmpty(RCode.APP_PROPERTIES_CANNOT_EMPTY) //.and(entity.getSurrogates()).notEmpty(RCode.APP_SURROGATES_CANNOT_EMPTY) //.and(entity.getDescription()).notEmpty(RCode.APP_DESCRIPTION_CANNOT_EMPTY) - .and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY); + .and(workspaceId).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY); + entity.setWorkspaceId(workspaceId); ApplicationEntity applicationEntity = applicationService.saveApplication(entity); return R.ok().putData("id", applicationEntity.getId()); } @PutMapping - public R update(@RequestBody ApplicationEntity entity) { + public R update(@PathVariable String workspaceId, + @RequestBody ApplicationEntity entity) { T.VerifyUtil.is(entity).notNull() .and(entity.getId()).notEmpty(RCode.ID_CANNOT_EMPTY) .and(entity.getName()).notEmpty(RCode.NAME_CANNOT_EMPTY) @@ -89,44 +96,48 @@ public class ApplicationController { //.and(entity.getProperties()).notEmpty(RCode.APP_PROPERTIES_CANNOT_EMPTY) //.and(entity.getSurrogates()).notEmpty(RCode.APP_SURROGATES_CANNOT_EMPTY) //.and(entity.getDescription()).notEmpty(RCode.APP_DESCRIPTION_CANNOT_EMPTY) - .and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY); - + .and(workspaceId).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY); + entity.setWorkspaceId(workspaceId); ApplicationEntity applicationEntity = applicationService.updateApplication(entity); return R.ok().putData("id", applicationEntity.getId()); } @DeleteMapping - public R delete(String[] ids) { + public R delete(@PathVariable String workspaceId, + String[] ids) { T.VerifyUtil.is(ids).notEmpty(); - applicationService.removeApplication(T.ListUtil.of(ids)); + applicationService.removeApplication(T.ListUtil.of(ids), workspaceId); return R.ok(); } @GetMapping("/{id}/log") - public R queryLogList(@PathVariable("id") String id) { - List applicationEntityList = applicationService.queryLogList(id); + public R queryLogList(@PathVariable String workspaceId, + @PathVariable("id") String id) { + List applicationEntityList = applicationService.queryLogList(id, workspaceId); return R.ok().putData("record", applicationEntityList); } @GetMapping("/{id}/{oldVersion}/{newVersion}") - public R applicationCompare(@PathVariable("id") String id, + public R applicationCompare(@PathVariable String workspaceId, + @PathVariable("id") String id, @PathVariable("oldVersion") String oldVersion, @PathVariable("newVersion") String newVersion) { - List list = applicationService.compare(id, oldVersion, newVersion); + List list = applicationService.compare(id, oldVersion, newVersion,workspaceId); return R.ok().putData("record", list); } @PostMapping("/{id}/{version}/restore") - public R restore(@PathVariable("id") String id, + public R restore(@PathVariable String workspaceId, + @PathVariable("id") String id, @PathVariable("version") String version) { - applicationService.restore(id, version); + applicationService.restore(id, version, workspaceId); return R.ok(); } @GetMapping("/analyze") - public void analyze(@RequestParam String workspaceId, + public void analyze(@PathVariable String workspaceId, @RequestParam String pcapIds, HttpServletResponse response) throws IOException { applicationService.redirectDiscoverPage(workspaceId, pcapIds, response); diff --git a/src/main/java/net/geedge/asw/module/app/dao/ApplicationDao.java b/src/main/java/net/geedge/asw/module/app/dao/ApplicationDao.java index 4044f01..c7061a4 100644 --- a/src/main/java/net/geedge/asw/module/app/dao/ApplicationDao.java +++ b/src/main/java/net/geedge/asw/module/app/dao/ApplicationDao.java @@ -15,10 +15,10 @@ public interface ApplicationDao extends BaseMapper{ List queryList(Page page, Map params); - @Select("select * from ( select * from application union select * from application_log ) app where app.id = #{id} and app.op_version = #{version}") - ApplicationEntity queryByApplicationAndLog(String id, String version); + @Select("select * from ( select * from application union select * from application_log ) app where app.id = #{id} and app.op_version = #{version} and app.workspace_id = #{workspaceId}") + ApplicationEntity queryByApplicationAndLog(String id, String version, String workspaceId); - List queryLogList(String id); + List queryLogList(String id, String workspaceId); List compare(@Param("params") Map params); diff --git a/src/main/java/net/geedge/asw/module/app/service/IApplicationService.java b/src/main/java/net/geedge/asw/module/app/service/IApplicationService.java index 032e55f..6dd7b86 100644 --- a/src/main/java/net/geedge/asw/module/app/service/IApplicationService.java +++ b/src/main/java/net/geedge/asw/module/app/service/IApplicationService.java @@ -17,15 +17,15 @@ public interface IApplicationService extends IService{ ApplicationEntity updateApplication(ApplicationEntity entity); - void removeApplication(List ids); + void removeApplication(List ids, String workspaceId); - ApplicationEntity queryByApplicationAndLog(String id, String version); + ApplicationEntity queryByApplicationAndLog(String id, String version, String workspaceId); - List compare(String id, String oldVersion, String newVersion); + List compare(String id, String oldVersion, String newVersion, String workspaceId); - List queryLogList(String id); + List queryLogList(String id, String workspaceId); - void restore(String id, String version); + void restore(String id, String version, String workspaceId); void redirectDiscoverPage(String workspaceId, String pcapIds, HttpServletResponse response) throws IOException; diff --git a/src/main/java/net/geedge/asw/module/app/service/impl/ApplicationServiceImpl.java b/src/main/java/net/geedge/asw/module/app/service/impl/ApplicationServiceImpl.java index 66b1ead..0326d67 100644 --- a/src/main/java/net/geedge/asw/module/app/service/impl/ApplicationServiceImpl.java +++ b/src/main/java/net/geedge/asw/module/app/service/impl/ApplicationServiceImpl.java @@ -56,8 +56,8 @@ public class ApplicationServiceImpl extends ServiceImpl ids) { + public void removeApplication(List ids, String workspaceId) { // remove - this.removeBatchByIds(ids); - applicationLogService.removeBatchByIds(ids); + this.remove(new LambdaQueryWrapper() + .in(ApplicationEntity::getId, ids) + .eq(ApplicationEntity::getWorkspaceId, workspaceId)); + applicationLogService.remove(new LambdaQueryWrapper() + .in(ApplicationLogEntity::getId, ids) + .eq(ApplicationLogEntity::getWorkspaceId, workspaceId)); } @Override - public List queryLogList(String id) { - List packageList = this.getBaseMapper().queryLogList(id); + public List queryLogList(String id, String workspaceId) { + List packageList = this.getBaseMapper().queryLogList(id, workspaceId); return packageList; } @Override - public List compare(String id, String oldVersion, String newVersion) { - Map params = Map.of("id", id, "versions", Arrays.asList(oldVersion, newVersion)); + public List compare(String id, String oldVersion, String newVersion, String workspaceId) { + Map params = Map.of("id", id, "versions", Arrays.asList(oldVersion, newVersion),"workspaceId",workspaceId); List packageList = this.getBaseMapper().compare(params); return packageList; } @@ -144,13 +148,16 @@ public class ApplicationServiceImpl extends ServiceImpl() + .eq(ApplicationEntity::getId, id) + .eq(ApplicationEntity::getWorkspaceId, workspaceId)); this.saveApplcationToLog(curApplication); // restore ApplicationLogEntity oldApplication = applicationLogService.getOne(new LambdaQueryWrapper() .eq(ApplicationLogEntity::getId, id) + .eq(ApplicationLogEntity::getWorkspaceId, workspaceId) .eq(ApplicationLogEntity::getOpVersion, version)); oldApplication.setUpdateTimestamp(System.currentTimeMillis()); diff --git a/src/main/resources/db/mapper/app/ApplicationMapper.xml b/src/main/resources/db/mapper/app/ApplicationMapper.xml index 3761a72..58e46bd 100644 --- a/src/main/resources/db/mapper/app/ApplicationMapper.xml +++ b/src/main/resources/db/mapper/app/ApplicationMapper.xml @@ -76,6 +76,9 @@ AND app.id = #{id} + + AND app.workspace_id = #{workspaceId} + ORDER BY app.op_version DESC @@ -101,6 +104,9 @@ AND app.id = #{params.id} + + AND app.workspace_id = #{params.workspaceId} +