diff --git a/src/main/java/net/geedge/asw/module/runner/controller/PlaybookController.java b/src/main/java/net/geedge/asw/module/runner/controller/PlaybookController.java index 9fe092c..ddc38f4 100644 --- a/src/main/java/net/geedge/asw/module/runner/controller/PlaybookController.java +++ b/src/main/java/net/geedge/asw/module/runner/controller/PlaybookController.java @@ -40,8 +40,9 @@ public class PlaybookController { public R save(@PathVariable("workspaceId") String workspaceId, @RequestParam("file") MultipartFile file, @RequestParam("name") String name, + @RequestParam("type") String type, @RequestParam(value = "description", required = false) String description) { - PlaybookEntity playbook = playbookService.savePlaybook(workspaceId, file, name, description); + PlaybookEntity playbook = playbookService.savePlaybook(workspaceId, file, name, type, description); return R.ok().put("record", playbook); } diff --git a/src/main/java/net/geedge/asw/module/runner/entity/PlaybookEntity.java b/src/main/java/net/geedge/asw/module/runner/entity/PlaybookEntity.java index 2eda2a3..489031a 100644 --- a/src/main/java/net/geedge/asw/module/runner/entity/PlaybookEntity.java +++ b/src/main/java/net/geedge/asw/module/runner/entity/PlaybookEntity.java @@ -14,6 +14,7 @@ public class PlaybookEntity { @TableId(type = IdType.ASSIGN_UUID) private String id; private String name; + private String type; private String tags; private String path; private String description; diff --git a/src/main/java/net/geedge/asw/module/runner/service/IPlaybookService.java b/src/main/java/net/geedge/asw/module/runner/service/IPlaybookService.java index b04acbb..c6d4dcd 100644 --- a/src/main/java/net/geedge/asw/module/runner/service/IPlaybookService.java +++ b/src/main/java/net/geedge/asw/module/runner/service/IPlaybookService.java @@ -13,7 +13,7 @@ public interface IPlaybookService extends IService{ Page queryList(String workspaceId, Map params); - PlaybookEntity savePlaybook(String workspaceId, MultipartFile file, String name, String description); + PlaybookEntity savePlaybook(String workspaceId, MultipartFile file, String name, String type, String description); void delete(String workspaceId, String ids); } diff --git a/src/main/java/net/geedge/asw/module/runner/service/impl/PlaybookServiceImpl.java b/src/main/java/net/geedge/asw/module/runner/service/impl/PlaybookServiceImpl.java index 8d13529..24fb810 100644 --- a/src/main/java/net/geedge/asw/module/runner/service/impl/PlaybookServiceImpl.java +++ b/src/main/java/net/geedge/asw/module/runner/service/impl/PlaybookServiceImpl.java @@ -40,14 +40,13 @@ public class PlaybookServiceImpl extends ServiceImpl playbookList = this.baseMapper.selectList(new LambdaQueryWrapper().eq(PlaybookEntity::getWorkspaceId, workspaceId).eq(PlaybookEntity::getName, name)); if (T.CollUtil.isNotEmpty(playbookList)) { throw new ASWException(RCode.PLAYBOOK_NAME_DUPLICATE); } - PlaybookEntity playbook = new PlaybookEntity(); String playbookId = T.StrUtil.uuid(); String fileExtName = T.StrUtil.emptyToDefault(T.FileUtil.extName(file.getName()), "zip"); @@ -66,22 +65,23 @@ public class PlaybookServiceImpl extends ServiceImpl fileList = Arrays.stream(unzip.listFiles()).toList(); + if (T.CollUtil.isEmpty(fileList) || fileList.size() != 1) { + throw new ASWException(RCode.PLAYBOOK_INVALID_FILE); + } - unzip = T.ZipUtil.unzip(destination); - List fileList = Arrays.stream(unzip.listFiles()).toList(); - if (T.CollUtil.isEmpty(fileList) || fileList.size() != 1) { - throw new ASWException(RCode.PLAYBOOK_INVALID_FILE); - } - - File playbookDir = fileList.getFirst(); - String dirName = playbookDir.getName(); - if (!dirName.endsWith(".air")) { - throw new ASWException(RCode.PLAYBOOK_INVALID_FILE); - } - String pyName = dirName.replace("air", "py"); - List fileNameList = Arrays.stream(playbookDir.list()).toList(); - if (T.CollUtil.isEmpty(fileNameList) || !fileNameList.contains(pyName)) { - throw new ASWException(RCode.PLAYBOOK_INVALID_FILE); + File playbookDir = fileList.getFirst(); + String dirName = playbookDir.getName(); + if (!dirName.endsWith(".air")) { + throw new ASWException(RCode.PLAYBOOK_INVALID_FILE); + } + String pyName = dirName.replace("air", "py"); + List fileNameList = Arrays.stream(playbookDir.list()).toList(); + if (T.CollUtil.isEmpty(fileNameList) || !fileNameList.contains(pyName)) { + throw new ASWException(RCode.PLAYBOOK_INVALID_FILE); + } } this.save(playbook); } catch (Exception e) { diff --git a/src/main/resources/db/mapper/runner/PlaybookMapper.xml b/src/main/resources/db/mapper/runner/PlaybookMapper.xml index 942c218..ed0948c 100644 --- a/src/main/resources/db/mapper/runner/PlaybookMapper.xml +++ b/src/main/resources/db/mapper/runner/PlaybookMapper.xml @@ -5,6 +5,7 @@ + @@ -73,6 +74,10 @@ AND ( locate(#{params.q}, pb.name) OR locate(#{params.q}, pb.description) ) + + AND pb.type = #{params.type} + + AND pb.workspace_id = #{workspaceId} diff --git a/src/main/resources/db/migration/V1.0.01__INIT_TABLES.sql b/src/main/resources/db/migration/V1.0.01__INIT_TABLES.sql index 357cd58..f63cb25 100644 --- a/src/main/resources/db/migration/V1.0.01__INIT_TABLES.sql +++ b/src/main/resources/db/migration/V1.0.01__INIT_TABLES.sql @@ -181,6 +181,7 @@ DROP TABLE IF EXISTS `playbook`; CREATE TABLE `playbook` ( `id` varchar(64) NOT NULL COMMENT '主键', `name` varchar(256) NOT NULL DEFAULT '' COMMENT '名称', + `type` varchar(256) NOT NULL DEFAULT 'airtest_script' COMMENT '脚本类型', `tags` varchar(256) NOT NULL DEFAULT '' COMMENT '标签', `path` text NOT NULL COMMENT '脚本文件路径', `description` text NOT NULL DEFAULT '' COMMENT '描述信息',