package com.highdatas.mdm.controller; import com.fasterxml.jackson.databind.node.ObjectNode; import com.highdatas.mdm.pojo.CodeMsg; import com.highdatas.mdm.pojo.Result; import com.highdatas.mdm.service.ModelEditorService; import com.highdatas.mdm.service.act.IdentityService; import com.highdatas.mdm.service.act.RepositoryService; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; /** * @author kimi * @description 流程设计器接口 * @date 2019-12-11 11:00 */ @RestController @RequestMapping("/designer") public class ActivitiDesignerController { @Autowired ModelEditorService modelEditorService; @Autowired RepositoryService repositoryService; @Autowired IdentityService identityService; /** * * @description: 创建一个新流程 * @return: Result 返回创建的model id * */ @RequestMapping(value = "/create", method = RequestMethod.GET) public String createModel() { String modelId = modelEditorService.createModel(); return modelId; } /** * * @description: 返回带有model信息的编辑器界面 * @param: modelId model Id * @param: userId 用户id * @return: 流程编辑器页面 * */ @RequestMapping(value = "/edit", method = RequestMethod.GET) public String getModel(HttpServletResponse response, String modelId) throws IOException { if (StringUtils.isEmpty(modelId)) { modelId = modelEditorService.createModel(); } return "./process/modeler.html?modelId=" + modelId; } /** * * @description: 保存model信息 * @param: modelId model Id * @return: Result 是否保存成功 * */ @RequestMapping(value="/model/{modelId}/save", method = RequestMethod.PUT) public Result saveModel(@PathVariable String modelId, HttpServletRequest request) { boolean saved = repositoryService.saveModel(modelId, request); if (saved) { return Result.success(null); } else { return Result.error(new CodeMsg(1000, "未检测到任一标签")); } } /** * * @description: 删除model信息 * @param: modelId model Id * @return: Result 是否删除model信息 * */ @RequestMapping(value="/model/{modelId}/delete", method = RequestMethod.PUT) @ResponseStatus(value = HttpStatus.OK) public void deleteModel(@PathVariable String modelId) { repositoryService.deleteModel(modelId); } /** * * @description: 通过model ID 获取流程编辑器使用的 Edit json信息 * @param: modelId model Id * @return: Result Edit json信息 * */ @RequestMapping(value="/model/{modelId}/json", method = RequestMethod.GET, produces = "application/json") public ObjectNode getEditorJson(@PathVariable String modelId) { return modelEditorService.getEditorJson(modelId); } /** * * @description: 获取stencilset.json 流程编辑器使用 * @return: 返回stencilset.json * */ @RequestMapping(value="/editor/stencilset", method = RequestMethod.GET, produces = "application/json;charset=utf-8") public @ResponseBody String getStencilset() { return modelEditorService.getStencilset(); } }