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 9f1777b..c11b66e 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 @@ -22,7 +22,7 @@ import java.util.Map; import java.util.stream.Collectors; @RestController -@RequestMapping("/api/v1/application") +@RequestMapping("/api/v1/workspace") public class ApplicationController { private static final Log log = Log.get(); @@ -33,244 +33,11 @@ public class ApplicationController { @Autowired private IApplicationService applicationService; - /*@Autowired - private IApplicationSignatureService signatureService; - - @Autowired - private IApplicationNoteService noteService; - - @Autowired - private IApplicationHrefService hrefService; - - @Autowired - private IApplicationAttachmentService attachmentService; - - @GetMapping("/{id}") - public R detail(@PathVariable("id") String id, String workspaceId) { - T.VerifyUtil.is(workspaceId).notNull(); - ApplicationEntity entity = applicationService.detail(id, workspaceId); - if (T.ObjectUtil.isNull(entity)) { - throw new ASWException(RCode.APP_NOT_EXIST); - } - return R.ok().putData("record", entity); - } - - - @GetMapping - public R list(@RequestParam Map params) { - T.VerifyUtil.is(params).notNull() - .and(T.MapUtil.getStr(params, "workspaceId")).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY); - Page page = applicationService.queryList(params); - return R.ok(page); - } - - @PostMapping - @Transactional(rollbackFor = Exception.class) - public R add(@RequestParam(required = true) String basic, - @RequestParam(required = false) String signature, - @RequestParam(required = false) String note, - @RequestParam(required = false) String hrefs, - @RequestParam(required = false, value = "files") List fileList) { - // validate - ApplicationEntity entity; - try { - entity = T.JSONUtil.toBean(basic, ApplicationEntity.class); - - if (T.StrUtil.isNotEmpty(signature)) { - ApplicationSignatureEntity signatureEntity = T.JSONUtil.toBean(signature, ApplicationSignatureEntity.class); - entity.setSignature(signatureEntity); - } - - if (T.StrUtil.isNotEmpty(note)) { - ApplicationNoteEntity noteEntity = T.JSONUtil.toBean(note, ApplicationNoteEntity.class); - entity.setNote(noteEntity); - } - - if (T.StrUtil.isNotEmpty(hrefs)) { - T.JSONUtil.toList(hrefs, ApplicationHrefEntity.class); - } - } catch (Exception e) { - log.error(e, "[add] [param format error]"); - throw new ASWException(RCode.ERROR); - } - - T.VerifyUtil.is(entity).notNull() - .and(entity.getName()).notEmpty(RCode.APP_NAME_CANNOT_EMPTY) - .and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY); - - // save application - ApplicationEntity applicationEntity = applicationService.saveApplication(entity); - - // save attachment - fileList = T.CollUtil.defaultIfEmpty(fileList, new ArrayList<>()); - for (MultipartFile file : fileList) { - attachmentService.saveAttachment(file.getResource(), applicationEntity.getId()); - } - - // save href - if (T.StrUtil.isNotEmpty(hrefs)) { - List hrefList = T.JSONUtil.toList(hrefs, ApplicationHrefEntity.class); - hrefService.updateBatchHref(applicationEntity.getId(), hrefList); - } - return R.ok().putData("id", applicationEntity.getId()); - } - - @PutMapping - public R update(@RequestBody ApplicationEntity entity) { - T.VerifyUtil.is(entity).notNull() - .and(entity.getId()).notEmpty(RCode.ID_CANNOT_EMPTY) - .and(entity.getName()).notEmpty(RCode.NAME_CANNOT_EMPTY) - //.and(entity.getSignature()).notEmpty(RCode.APP_SURROGATES_CANNOT_EMPTY) - //.and(entity.getNote()).notEmpty(RCode.APP_PROPERTIES_CANNOT_EMPTY) - .and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY); - - ApplicationEntity applicationEntity = applicationService.updateApplication(entity); - return R.ok().putData("id", applicationEntity.getId()); - } - - - @PutMapping("/{id}/basic") - public R basic(@PathVariable String id, @RequestBody ApplicationEntity entity) { - T.VerifyUtil.is(entity).notNull() - .and(entity.getName()).notEmpty(RCode.NAME_CANNOT_EMPTY) - .and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY); - entity.setId(id); - ApplicationEntity app = applicationService.updateBasic(entity); - return R.ok().putData("id", app.getId()); - } - - @PutMapping("/{applicationId}/signature") - public R updateSignature(@PathVariable("applicationId") String applicationId, @RequestBody ApplicationSignatureEntity signature) { - T.VerifyUtil.is(signature).notNull() - .and(signature.getContent()).notEmpty(RCode.APP_SURROGATES_CANNOT_EMPTY) - .and(signature.getContent()).json(RCode.APP_SURROGATES_CANNOT_EMPTY); - - signatureService.saveSignature(signature, applicationId); - return R.ok().putData("id", signature.getId()); - } - - @PutMapping("/{applicationId}/note") - public R updateNote(@PathVariable("applicationId") String applicationId, @RequestBody ApplicationNoteEntity note) { - T.VerifyUtil.is(note).notNull(); - //.and(note.getContent()).notEmpty(RCode.APP_NOTE_CONTENT_CANNOT_EMPTY); - - noteService.saveNote(note, applicationId); - return R.ok().putData("id", note.getId()); - } - - @DeleteMapping - public R delete(String[] ids) { - T.VerifyUtil.is(ids).notEmpty(); - applicationService.removeApplication(T.ListUtil.of(ids)); - return R.ok(); - } - - - @GetMapping("/{applicationId}/attachment") - public R queryAttachment(@PathVariable String applicationId) { - T.VerifyUtil.is(applicationId).notNull(); - - List list = attachmentService.list(new LambdaQueryWrapper().eq(ApplicationAttachmentEntity::getApplicationId, applicationId)); - return R.ok().putData("records", list); - } - - - @GetMapping("/{applicationId}/attachment/{attachmentId}") - public void downloadAttachment(HttpServletResponse response, @PathVariable String applicationId, @PathVariable String attachmentId) throws IOException { - T.VerifyUtil.is(applicationId).notNull() - .and(attachmentId).notNull(); - - attachmentService.download(response, applicationId, attachmentId); - } - - @PostMapping("/{applicationId}/attachment") - public R uploadAttachment(@PathVariable String applicationId, @RequestParam("files") List fileList) { - - List recordList = T.ListUtil.list(true); - for (int i = 0; i < fileList.size(); i++) { - MultipartFile file = fileList.get(i); - ApplicationAttachmentEntity attachmentEntity = attachmentService.saveAttachment(file.getResource(), applicationId); - recordList.add(attachmentEntity); - } - return R.ok().putData("records", recordList); - } - - @DeleteMapping("/{applicationId}/attachment") - public R removedAttachment(@PathVariable String applicationId, @RequestParam String ids) { - - attachmentService.removedAttachment(applicationId, ids); - return R.ok(); - } - - - @GetMapping("/{applicationId}/signature") - public R querySignature(@PathVariable String applicationId) { - T.VerifyUtil.is(applicationId).notNull(); - List signatureList = signatureService.queryList(applicationId); - return R.ok().putData("records", signatureList); - } - - - @GetMapping("/{applicationId}/signature/{oldVersion}/{newVersion}") - public R signatureCompare(@PathVariable("applicationId") String applicationId, - @PathVariable("oldVersion") String oldVersion, - @PathVariable("newVersion") String newVersion) { - List list = signatureService.compare(applicationId, oldVersion, newVersion); - return R.ok().putData("records", list); - } - - - @PutMapping("/{applicationId}/signature/{version}/restore") - public R restore(@PathVariable("applicationId") String applicationId, - @PathVariable("version") String version) { - signatureService.restore(applicationId, version); - return R.ok(); - } - - - // application href - @GetMapping("/{applicationId}/href") - public R queryHref(@PathVariable String applicationId) { - List entityList = hrefService.queryList(applicationId); - return R.ok().putData("records", entityList); - } - - @RequestMapping(value = "/{applicationId}/href", method = {RequestMethod.POST, RequestMethod.PUT}) - public R updateBatchHref(@PathVariable String applicationId, @RequestBody List hrefList) { - // validate - ApplicationEntity application = applicationService.getById(applicationId); - T.VerifyUtil.is(application).notNull(RCode.APP_NOT_EXIST); - - for (ApplicationHrefEntity href : hrefList) { - T.VerifyUtil.is(href).notNull() - .and(href.getName()).notEmpty(RCode.NAME_CANNOT_EMPTY) - .and(href.getUrl()).notEmpty(RCode.PARAM_CANNOT_EMPTY); - - href.setApplicationId(applicationId); - } - - // save or update batch - List entityList = hrefService.updateBatchHref(hrefList); - List> records = entityList.stream() - .map(entity -> Map.of("id", entity.getId())) - .collect(Collectors.toList()); - return R.ok().putData("records", records); - } - - @DeleteMapping("/{applicationId}/href") - public R deleteHref(@PathVariable String applicationId, @RequestParam String[] ids) { - // remove - hrefService.remove(new LambdaQueryWrapper() - .eq(ApplicationHrefEntity::getApplicationId, applicationId) - .in(ApplicationHrefEntity::getId, T.ListUtil.of(ids))); - return R.ok(); - }*/ - - @PostMapping("/import") - public synchronized R importApplication(@RequestParam String workspaceId, - @RequestParam String branchName, - @RequestParam(defaultValue = "tsg2402") String format, - @RequestParam(value = "files") List fileList) { + @PostMapping("/{workspaceId}/branch/{branchName}/application/import") + public synchronized R importApplication(@PathVariable("workspaceId") String workspaceId, + @PathVariable("branchName") String branchName, + @RequestParam(defaultValue = "tsg2402") String format, + @RequestParam(value = "files") List fileList) { // validate WorkspaceEntity workspace = workspaceService.getById(workspaceId); T.VerifyUtil.is(workspace).notNull(RCode.WORKSPACE_NOT_EXIST); @@ -311,9 +78,9 @@ public class ApplicationController { return R.ok().putData("records", records); } - @GetMapping("/export") - public void exportApplication(@RequestParam String workspaceId, - @RequestParam String branchName, + @GetMapping("/{workspaceId}/branch/{branchName}/application/export") + public void exportApplication(@PathVariable("workspaceId") String workspaceId, + @PathVariable("branchName") String branchName, @RequestParam String names, @RequestParam(defaultValue = "tsg2402") String format, HttpServletResponse response) throws IOException {