| | |
| | | package com.java110.common.api; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.fasterxml.jackson.databind.node.ObjectNode; |
| | | import com.java110.common.bmo.workflow.IQueryWorkFlowFirstStaffBMO; |
| | | import com.java110.dto.workflow.WorkflowDto; |
| | | import org.activiti.editor.constants.ModelDataJsonConstants; |
| | | import com.java110.dto.oaWorkflow.WorkflowModelDto; |
| | | import com.java110.utils.util.BeanConvertUtil; |
| | | import org.activiti.engine.ActivitiException; |
| | | import org.activiti.engine.RepositoryService; |
| | | import org.activiti.engine.repository.Model; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import com.java110.core.log.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.ResponseStatus; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | @RestController |
| | | @RequestMapping("/workflow") |
| | | public class WorkflowApi { |
| | | |
| | | @Autowired |
| | | private IQueryWorkFlowFirstStaffBMO queryWorkFlowFirstStaffBMOImpl; |
| | | |
| | | @RequestMapping(value = "/getFirstStaff", method = RequestMethod.GET) |
| | | public ResponseEntity<String> getFirstStaff(@RequestParam(name = "flowType") String flowType, |
| | | @RequestParam(name = "communityId") String communityId, |
| | | @RequestHeader(value = "store-id") String storeId) { |
| | | WorkflowDto workflowDto = new WorkflowDto(); |
| | | workflowDto.setCommunityId(communityId); |
| | | workflowDto.setFlowType(flowType); |
| | | workflowDto.setStoreId(storeId); |
| | | return queryWorkFlowFirstStaffBMOImpl.query(workflowDto); |
| | | } |
| | | |
| | | private static final Logger logger = LoggerFactory.getLogger(ModelController.class); |
| | | private static final Logger logger = LoggerFactory.getLogger(WorkflowApi.class); |
| | | |
| | | @Autowired |
| | | private RepositoryService repositoryService; |
| | | |
| | | @Autowired |
| | | private ObjectMapper objectMapper; |
| | | |
| | | String MODEL_ID = "modelId"; |
| | | String MODEL_NAME = "name"; |
| | | String MODEL_REVISION = "revision"; |
| | | String MODEL_DESCRIPTION = "description"; |
| | | |
| | | @Autowired |
| | | private IQueryWorkFlowFirstStaffBMO queryWorkFlowFirstStaffBMOImpl; |
| | | |
| | | /** |
| | | * 创建模型 |
| | | * @param response |
| | | * @param name 模型名称 |
| | | * @param key 模型key |
| | | * 更新流程 |
| | | * |
| | | * @param reqString 模型ID |
| | | * @ServiceCode /workflow/saveModel |
| | | */ |
| | | @RequestMapping("/create") |
| | | @ResponseBody |
| | | public String create(HttpServletResponse response, String name, String key) throws IOException { |
| | | logger.info("创建模型入参name:{},key:{}",name,key); |
| | | Model model = repositoryService.newModel(); |
| | | ObjectNode modelNode = objectMapper.createObjectNode(); |
| | | modelNode.put(ModelDataJsonConstants.MODEL_NAME, name); |
| | | modelNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, ""); |
| | | modelNode.put(ModelDataJsonConstants.MODEL_REVISION, 1); |
| | | model.setName(name); |
| | | model.setKey(key); |
| | | model.setMetaInfo(modelNode.toString()); |
| | | repositoryService.saveModel(model); |
| | | createObjectNode(model.getId()); |
| | | logger.info("创建模型结束,返回模型ID:{}",model.getId()); |
| | | return model.getId(); |
| | | @RequestMapping(value = "/saveModel", method = RequestMethod.POST) |
| | | @ResponseStatus(value = HttpStatus.OK) |
| | | public ResponseEntity<String> saveModel(@RequestBody String reqString) { |
| | | JSONObject reqJson = JSONObject.parseObject(reqString); |
| | | WorkflowModelDto workflowModelDto = BeanConvertUtil.covertBean(reqJson, WorkflowModelDto.class); |
| | | //部署model |
| | | return queryWorkFlowFirstStaffBMOImpl.saveModel(workflowModelDto); |
| | | } |
| | | |
| | | /** |
| | | * 创建模型时完善ModelEditorSource |
| | | * 部署流程 |
| | | * |
| | | * @param reqString 模型ID |
| | | * @ServiceCode /workflow/deployModel |
| | | */ |
| | | @RequestMapping(value = "/deployModel", method = RequestMethod.POST) |
| | | @ResponseStatus(value = HttpStatus.OK) |
| | | public ResponseEntity<String> deployModel(@RequestBody String reqString) { |
| | | JSONObject reqJson = JSONObject.parseObject(reqString); |
| | | WorkflowModelDto workflowModelDto = BeanConvertUtil.covertBean(reqJson, WorkflowModelDto.class); |
| | | //部署model |
| | | return queryWorkFlowFirstStaffBMOImpl.deployModel(workflowModelDto); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取model的节点信息,编辑器根据返回的json进行绘图 |
| | | * |
| | | * @param modelId |
| | | * @return |
| | | * @ServiceCode /workflow/getEditorJson |
| | | */ |
| | | @SuppressWarnings("deprecation") |
| | | private void createObjectNode(String modelId){ |
| | | logger.info("创建模型完善ModelEditorSource入参模型ID:{}",modelId); |
| | | ObjectNode editorNode = objectMapper.createObjectNode(); |
| | | editorNode.put("id", "canvas"); |
| | | editorNode.put("resourceId", "canvas"); |
| | | ObjectNode stencilSetNode = objectMapper.createObjectNode(); |
| | | stencilSetNode.put("namespace","http://b3mn.org/stencilset/bpmn2.0#"); |
| | | editorNode.put("stencilset", stencilSetNode); |
| | | try { |
| | | repositoryService.addModelEditorSource(modelId,editorNode.toString().getBytes("utf-8")); |
| | | } catch (Exception e) { |
| | | logger.info("创建模型时完善ModelEditorSource服务异常:{}",e); |
| | | @RequestMapping(value = "/getEditorJson", method = RequestMethod.GET) |
| | | public ResponseEntity getEditorJson(@RequestParam(value = "modelId") String modelId) { |
| | | ObjectNode modelNode = null; |
| | | Model model = repositoryService.getModel(modelId); |
| | | if (model != null) { |
| | | try { |
| | | if (StringUtils.isNotEmpty(model.getMetaInfo())) { |
| | | modelNode = (ObjectNode) objectMapper.readTree(model.getMetaInfo()); |
| | | } else { |
| | | modelNode = objectMapper.createObjectNode(); |
| | | modelNode.put(MODEL_NAME, model.getName()); |
| | | } |
| | | modelNode.put(MODEL_ID, model.getId()); |
| | | ObjectNode editorJsonNode = (ObjectNode) objectMapper.readTree( |
| | | new String(repositoryService.getModelEditorSource(model.getId()), "utf-8")); |
| | | modelNode.put("model", editorJsonNode); |
| | | } catch (Exception e) { |
| | | logger.error("Error creating model JSON", e); |
| | | throw new ActivitiException("Error creating model JSON", e); |
| | | } |
| | | } |
| | | logger.info("创建模型完善ModelEditorSource结束"); |
| | | return new ResponseEntity(modelNode.toString(), HttpStatus.OK); |
| | | } |
| | | } |