package com.hotent.bpmModel.controller; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.hotent.base.exception.BaseException; import org.springframework.beans.factory.annotation.Autowired; 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.RestController; import org.springframework.web.servlet.ModelAndView; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; import com.hotent.base.annotation.ApiGroup; import com.hotent.base.annotation.NewVersion; import com.hotent.base.constants.ApiGroupConsts; import com.hotent.base.feign.FormFeignService; import com.hotent.base.model.CommonResult; import com.hotent.base.query.PageList; import com.hotent.base.util.AppUtil; import com.hotent.base.util.BeanUtils; import com.hotent.base.util.JsonUtil; import com.hotent.base.util.StringUtil; import com.hotent.bpm.api.constant.ScriptType; import com.hotent.bpm.api.helper.identity.UserQueryPluginHelper; import com.hotent.bpm.api.model.process.def.BpmProcessDef; import com.hotent.bpm.api.model.process.def.BpmProcessDefExt; import com.hotent.bpm.api.model.process.def.BpmSubTableRight; import com.hotent.bpm.api.model.process.def.BpmVariableDef; import com.hotent.bpm.api.model.process.nodedef.BpmNodeDef; import com.hotent.bpm.api.model.process.nodedef.ext.AutoTaskDef; import com.hotent.bpm.api.model.process.nodedef.ext.SignNodeDef; import com.hotent.bpm.api.model.process.nodedef.ext.UserTaskNodeDef; import com.hotent.bpm.api.model.process.nodedef.ext.extmodel.DefaultJumpRule; import com.hotent.bpm.api.model.process.nodedef.ext.extmodel.PrivilegeItem; import com.hotent.bpm.api.model.process.nodedef.ext.extmodel.SignRule; import com.hotent.bpm.api.plugin.core.context.BpmPluginContext; import com.hotent.bpm.api.service.BpmDefinitionAccessor; import com.hotent.bpm.api.service.BpmDefinitionService; import com.hotent.bpm.engine.def.impl.handler.ServiceNodeBpmDefXmlHandler; import com.hotent.bpm.persistence.model.DefaultBpmProcessDefExt; import com.hotent.bpm.plugin.core.util.UserAssignRuleParser; import com.hotent.bpmModel.manager.BpmNodeService; import com.hotent.bpmModel.params.DefConfSaveVo; import com.hotent.bpmModel.params.NodeConfCopyVo; import com.hotent.bpmModel.params.NodeConfSaveVo; import com.hotent.bpmModel.params.VarTreeGetVo; import com.hotent.uc.api.model.IUser; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; /** * 描述:流程节点设置管理 * @company 广州宏天软件有限公司 * @author wanghb * @email wanghb@jee-soft.cn * @date 2018年6月26日 */ @RestController @RequestMapping("/flow/node/v1/") @Api(tags="流程节点设置") @ApiGroup(group= {ApiGroupConsts.GROUP_BPM}) @NewVersion public class NodeController { @Resource BpmDefinitionService bpmDefinitionService; @Resource BpmDefinitionAccessor bpmDefinitionAccessor; @Resource private UserQueryPluginHelper userQueryPluginHelper; @Autowired FormFeignService formFeignService; @Autowired private BpmNodeService nodeService; @RequestMapping(value="saveSub", method=RequestMethod.POST, produces={"application/json; charset=utf-8" }) @ApiOperation(value = "保存表单权限配置", httpMethod = "POST", notes = "获取表单权限") public CommonResult saveSub(@ApiParam(name="nodeId",value="节点ID")@RequestParam String nodeId, @ApiParam(name="defId",value="权限类型 ")@RequestParam String defId, @ApiParam(name="parentDefKey",value="父流程定义")@RequestParam String parentDefKey,HttpServletRequest request) throws Exception { CommonResult res=nodeService.saveSub(nodeId,defId,parentDefKey,request); return res; } @RequestMapping(value="initSub", method=RequestMethod.GET, produces={"application/json; charset=utf-8" }) @ApiOperation(value = "显示表单权限配置", httpMethod = "GET", notes = "显示表单权限配置") public Object initSub(@ApiParam(name="nodeId",value="节点ID")@RequestParam String nodeId, @ApiParam(name="defId",value="权限类型 ")@RequestParam String defId, @ApiParam(name="parentDefKey",value="父流程定义")@RequestParam String parentDefKey) throws Exception { Map map = new HashMap<>(); BpmNodeDef nodeDef = bpmDefinitionAccessor.getBpmNodeDef(defId, nodeId); UserTaskNodeDef utnd = (UserTaskNodeDef) nodeDef; for (BpmSubTableRight bsr : utnd.getBpmSubTableRightByParentDefKey(parentDefKey)) { map.put(bsr.getTableName(),JsonUtil.toJsonNode(bsr)); } return map; } /** * 编辑节点规则页面初始化数据 */ @RequestMapping(value="ruleEdit", method=RequestMethod.GET, produces={"application/json; charset=utf-8" }) @ApiOperation(value = "编辑节点规则页面初始化数据", httpMethod = "GET", notes = "编辑节点规则页面初始化数据") public Map ruleEdit( @ApiParam(name="definitionId",value="流程定义id")@RequestParam String definitionId, @ApiParam(name="nodeId",value="节点id")@RequestParam String nodeId) throws Exception { Map res=nodeService.ruleEdit(definitionId,nodeId); return res; } /** * 节点规则列表 */ @SuppressWarnings("unchecked") @RequestMapping(value="ruleListJson", method=RequestMethod.POST, produces={"application/json; charset=utf-8" }) @ApiOperation(value = "节点规则列表", httpMethod = "POST", notes = "节点规则列表") public PageList ruleListJson( @ApiParam(name="definitionId",value="流程定义id")@RequestParam String definitionId, @ApiParam(name="nodeId",value="节点id")@RequestParam String nodeId) throws Exception { UserTaskNodeDef nodeDef = (UserTaskNodeDef) bpmDefinitionService.getBpmNodeDefByDefIdNodeId(definitionId, nodeId); List rules = nodeDef.getJumpRuleList(); if(rules == null)rules = Collections.EMPTY_LIST; return new PageList(rules); } /** * 判断当前节点是否是子流程中的节点,并且还不能是第一个节点 */ @RequestMapping(value="isSubFirstNode", method=RequestMethod.GET, produces={"application/json; charset=utf-8" }) @ApiOperation(value = "是否是子流程中非第一节点", httpMethod = "GET", notes = "节点规则列表") public CommonResult isSubFirstNode( @ApiParam(name="definitionId",value="流程定义id")@RequestParam String definitionId, @ApiParam(name="nodeId",value="节点id")@RequestParam String nodeId, @ApiParam(name="parentKey",value="父流程Key")@RequestParam String parentKey) throws Exception { return nodeService.isSubFirstNode(definitionId,nodeId,parentKey); } /** * 保存节点的跳转规则 */ @SuppressWarnings("unchecked") @RequestMapping(value="ruleSave",method=RequestMethod.POST, produces = { "application/json; charset=utf-8" }) @ApiOperation(value = "保存节点的跳转规则", httpMethod = "POST", notes = "保存节点的跳转规则") public CommonResult ruleSave( @ApiParam(name="nodeId",value="节点id", required = true) @RequestParam String nodeId, @ApiParam(name="defId",value="流程定义id", required = true) @RequestParam String defId, @ApiParam(name="nodeList",value="节点规则json", required = true) @RequestBody List nodeList) throws Exception { CommonResult res=nodeService.ruleSave(nodeId,defId,nodeList); return res; } /** * 保存节点json 配置 * * @param request * @param response * @throws Exception */ @RequestMapping(value="nodeUserConditionSave", method=RequestMethod.POST, produces={"application/json; charset=utf-8" }) @ApiOperation(value = "保存节点json 配置", httpMethod = "POST", notes = "保存节点json 配置") public CommonResult nodeUserConditionSave(@ApiParam(name="vo",value="节点保存对象")@RequestBody NodeConfSaveVo vo) throws Exception { CommonResult res=nodeService.nodeUserConditionSave(vo); return res; } /** * 节点规则脚本设置 */ @RequestMapping(value="eventScriptEdit", method=RequestMethod.GET, produces={"application/json; charset=utf-8" }) @ApiOperation(value = "节点规则脚本设置", httpMethod = "GET", notes = "节点规则脚本设置") public Map eventScriptEdit( @ApiParam(name="defId",value="流程定义id")@RequestParam String defId, @ApiParam(name="nodeId",value="节点id")@RequestParam String nodeId) throws Exception { BpmNodeDef bpmNodeDef = bpmDefinitionAccessor.getBpmNodeDef(defId, nodeId); Map scriptMap = bpmNodeDef.getScripts(); Map resMap=new HashMap<>(); resMap.put("bpmNodeDef", bpmNodeDef); resMap.put("eventScriptMap", scriptMap); return resMap; } /** * 节点事件脚本保存 */ @RequestMapping(value="eventScriptSave", method=RequestMethod.POST, produces={"application/json; charset=utf-8" }) @ApiOperation(value = "节点事件脚本保存", httpMethod = "POST", notes = "节点事件脚本保存") public CommonResult eventScriptSave(@ApiParam(name="vo",value="节点配置保存对象")@RequestBody NodeConfSaveVo vo) throws Exception { CommonResult res=nodeService.eventScriptSave(vo); return res; } /** * 获取分支设置信息 */ @RequestMapping(value="branchConditionEdit", method=RequestMethod.GET, produces={"application/json; charset=utf-8" }) @ApiOperation(value = "获取分支设置信息", httpMethod = "GET", notes = "获取分支设置信息") public Map branchConditionEdit( @ApiParam(name="nodeId",value="节点id", required = true) @RequestParam String nodeId, @ApiParam(name="defId",value="流程定义id", required = true) @RequestParam String defId) throws Exception { Map res=nodeService.branchConditionEdit(nodeId,defId); return res; } /** * 分支节点规则脚本保存 */ @RequestMapping(value="branchConditionSave", method=RequestMethod.POST, produces={"application/json; charset=utf-8" }) @ApiOperation(value = "分支节点规则脚本保存", httpMethod = "POST", notes = "分支节点规则脚本保存") public CommonResult branchConditionSave(@ApiParam(name="vo",value="节点配置保存对象")@RequestBody NodeConfSaveVo vo) throws Exception { CommonResult res=nodeService.branchConditionSave(vo); return res; } /** * 自动任务管理 */ @RequestMapping(value="autoTaskManager", method=RequestMethod.GET, produces={"application/json; charset=utf-8" }) @ApiOperation(value = "自动任务管理", httpMethod = "GET", notes = "自动任务管理") public Map autoTaskManager( @ApiParam(name="defId",value="流程定义id")@RequestParam String defId, @ApiParam(name="nodeId",value="节点id")@RequestParam String nodeId) throws Exception { Map data= new HashMap<>(); AutoTaskDef autoTaskDef = (AutoTaskDef) bpmDefinitionAccessor.getBpmNodeDef(defId, nodeId); BpmPluginContext bpmPluginContext = autoTaskDef.getAutoTaskBpmPluginContext(); data.put("bpmPluginContext", bpmPluginContext); return data; } /** * 自动节点,获取插件数据 */ @RequestMapping("autoTaskPluginGet") public Map autoTaskPluginGet( @ApiParam(name="defId",value="流程定义id")@RequestParam String defId, @ApiParam(name="nodeId",value="节点id")@RequestParam String nodeId, @ApiParam(name="pluginType",value="插件类型")@RequestParam String pluginType) throws Exception { Map res=nodeService.autoTaskPluginGet(defId,nodeId,pluginType); return res; } /** * 自动节点保存json 配置 * * @param request * @param response * @throws Exception */ @RequestMapping(value="autoTaskPluginSave", method=RequestMethod.POST, produces={"application/json; charset=utf-8" }) @ApiOperation(value = "自动节点保存json 配置", httpMethod = "POST", notes = "自动节点保存json 配置") public CommonResult autoTaskPluginSave(@ApiParam(name="vo",value="节点配置保存对象")@RequestBody NodeConfSaveVo vo) throws Exception { String defId = vo.getDefId(); String nodeId = vo.getNodeId(); String jsonStr = vo.getJsonStr(); try { if (StringUtil.isNotEmpty(nodeId)) { ServiceNodeBpmDefXmlHandler serviceNodeDefXmlHandler = AppUtil.getBean(ServiceNodeBpmDefXmlHandler.class); serviceNodeDefXmlHandler.saveNodeXml(defId, nodeId, jsonStr); } return new CommonResult("更新节点配置成功"); } catch (Exception e) { e.printStackTrace(); return new CommonResult(false,"更新节点配置失败:"+e.getMessage()); } } /** * 获取会签规则特权配置 */ @RequestMapping(value="getSignConfig", method=RequestMethod.GET, produces={"application/json; charset=utf-8" }) @ApiOperation(value = "获取会签规则特权配置", httpMethod = "GET", notes = "获取会签规则特权配置") public Object getSignConfig( @ApiParam(name="defId",value="流程定义id")@RequestParam String defId, @ApiParam(name="nodeId",value="节点id")@RequestParam String nodeId) throws Exception { SignNodeDef signNodeDef = (SignNodeDef) bpmDefinitionAccessor.getBpmNodeDef(defId, nodeId); List privilegeList = signNodeDef.getPrivilegeList(); SignRule signRule = signNodeDef.getSignRule(); Map map = new HashMap(); map.put("privilegeList", getPrivilegeListJson(privilegeList)); map.put("signRule", SignRule.toJson(signRule)); return map; } /** 将PrivilegeList 转化成json * @throws IOException */ @SuppressWarnings({ }) private ObjectNode getPrivilegeListJson(List privilegeList) throws IOException { ObjectNode ObjectNode = JsonUtil.getMapper().createObjectNode(); if (BeanUtils.isEmpty(privilegeList)) return ObjectNode; for (PrivilegeItem privilege : privilegeList) { ArrayNode config=JsonUtil.getMapper().createArrayNode(); UserAssignRuleParser.handJsonConfig(config, privilege.getUserRuleList()); ObjectNode.set(privilege.getPrivilegeMode().getKey(), config); } String json = ObjectNode.toString().replaceAll("null,", "\"\","); return (ObjectNode) JsonUtil.toJsonNode(json); } /** * 会签规则特权配置 */ @RequestMapping(value="signConfigSave", method=RequestMethod.POST, produces={"application/json; charset=utf-8" }) @ApiOperation(value = "会签规则特权配置", httpMethod = "POST", notes = "获取会签规则特权配置") public Object signConfigSave(@ApiParam(name="vo",value="节点配置保存对象")@RequestBody NodeConfSaveVo vo) throws Exception { Object res=nodeService.signConfigSave(vo); return res; } /** * 预览人员条件 * * @param request * @param response * @throws Exception */ @SuppressWarnings("unchecked") @RequestMapping(value="previewCondition",method=RequestMethod.GET, produces = { "application/json; charset=utf-8" }) @ApiOperation(value = "预览人员条件", httpMethod = "GET", notes = "添加bo定义") public PageList previewCondition( @ApiParam(name="conditionArray",value="人员条件数组", required = true)@RequestParam String conditionArray, @ApiParam(name="variables",value="变量", required = true)@RequestParam String variables) throws Exception { ObjectNode obj = (ObjectNode) JsonUtil.toJsonNode(variables); Map map = (Map) obj; List users = userQueryPluginHelper.queryUsersByConditions(conditionArray, map); return (PageList) users; } /** * 获取流程节点的流程变量 bo变量,流程变量 */ /*@RequestMapping("flowVarDialog") public ModelAndView flowVarDialog(HttpServletRequest request, HttpServletResponse response) throws Exception { String defId = RequestUtil.getString(request, "defId"); String nodeId = RequestUtil.getString(request, "nodeId"); List dimensionList = userGroupService.getGroupTypes(); return getAutoView().addObject("defId", defId).addObject("nodeId", nodeId).addObject("dimensionList", dimensionList); }*/ /** * 该节点能用的所有变量 * @throws Exception */ private List getAllBpmVariableDef(String defId, String nodeId) throws Exception { List bpmVariableList = new ArrayList(); // 全局变量 BpmProcessDef bpmProcessDefExt = bpmDefinitionAccessor.getBpmProcessDef(defId); DefaultBpmProcessDefExt defExt = (DefaultBpmProcessDefExt) bpmProcessDefExt.getProcessDefExt(); if (defExt.getVariableList() != null) { bpmVariableList.addAll(defExt.getVariableList()); } List list = bpmProcessDefExt.getBpmnNodeDefs(); for (BpmNodeDef node : list) { if (!node.getNodeId().equals(nodeId)) continue; if (!node.getType().toString().equalsIgnoreCase("usertask")) continue; UserTaskNodeDef targetNodeDef = (UserTaskNodeDef) node; if (targetNodeDef.getVariableList() != null) { bpmVariableList.addAll(targetNodeDef.getVariableList()); } } return bpmVariableList; } /** * 规则选择框 */ @RequestMapping("userAssignConditionDialog") public ModelAndView userAssignConditionDialog(HttpServletRequest request, HttpServletResponse response, String defId, String nodeId) throws Exception { return new ModelAndView("/flow/def/userAssignConditionDialog.jsp").addObject("defId", defId).addObject("nodeId", nodeId); } /** * 验证handler。 输入格式为 serviceId +"." + 方法名。 * * @param request * @param response * @throws IOException */ @RequestMapping(value="validHandler",method=RequestMethod.GET, produces = { "application/json; charset=utf-8" }) @ApiOperation(value = "验证handler。 输入格式为 serviceId +.法名", httpMethod = "GET", notes = "验证handler。 输入格式为 serviceId +.法名") public Object validHandler(@ApiParam(name="handler",value="handler字符串", required = true) @RequestParam String handler) throws IOException { Object res=nodeService.validHandler(handler); return res; } /** * 流程变量对话框的树 其中包含:bodef的字段,流程变量,流程常量(发起人,当前用户,...) * * @param request * @param response * @return * @throws Exception * Object * @exception * @since 1.0.0 */ @RequestMapping(value="varTree",method=RequestMethod.POST, produces = { "application/json; charset=utf-8" }) @ApiOperation(value = "流程变量对话框的树 其中包含:bodef的字段,流程变量,流程常量(发起人,当前用户,...)", httpMethod = "POST", notes = "流程变量对话框的树 其中包含:bodef的字段,流程变量,流程常量(发起人,当前用户,...)") public Object varTree(@ApiParam(name="vo",value="获取流程变量参数", required = true) @RequestBody VarTreeGetVo vo)throws Exception { Object res=nodeService.varTree(vo); return res; } /** * 获取流程节点的列表 一些基本信息而已 * * @param request * @param response * @return * @throws Exception * Object * @exception * @since 1.0.0 */ @RequestMapping(value="getNodes",method=RequestMethod.GET, produces = { "application/json; charset=utf-8" }) @ApiOperation(value = "获取流程节点的列表 一些基本信息而已", httpMethod = "GET", notes = "获取流程节点的列表 一些基本信息而已") public Object getNodes(@ApiParam(name="defId",value="流程定义id", required = true) @RequestParam String defId) throws Exception { Object res=nodeService.getNodes(defId); return res; } /** * 流程定义节点配置页面json数据 * @return json * @throws Exception */ @RequestMapping(value="getDefSetting",method=RequestMethod.GET, produces = { "application/json; charset=utf-8" }) @ApiOperation(value = "流程定义节点配置页面json数据", httpMethod = "GET", notes = "流程定义节点配置页面json数据") public Map nodeDefSetting( @ApiParam(name="defId",value="流程定义id", required = true) @RequestParam String defId, @ApiParam(name="topDefKey",value="父流程定义key", required = true) @RequestParam String topDefKey) throws Exception { Map res=nodeService.nodeDefSetting(defId,topDefKey); return res; } /**流程定义节点配置页面json数据 * @return json * @throws IOException * @throws Exception *//* @RequestMapping(value="getDefSetting",method=RequestMethod.GET, produces = { "application/json; charset=utf-8" }) @ApiOperation(value = "流程定义设置json数据", httpMethod = "GET", notes = "流程定义设置json数据") public Map getDefSetting( @ApiParam(name="defId",value="流程定义id", required = true) @RequestParam String defId, @ApiParam(name="topDefKey",value="父流程定义key", required = true) @RequestParam String topDefKey) throws Exception { return returnData; }*/ /** * 保存流程配置 * * @param request * @param reponse * @throws Exception */ @SuppressWarnings({ }) @RequestMapping(value="saveDefConf", method=RequestMethod.POST, produces={"application/json; charset=utf-8" }) @ApiOperation(value = "保存流程配置", httpMethod = "POST", notes = "保存流程配置") public CommonResult saveDefConf(@ApiParam(name="vo",value="流程设置保存对象")@RequestBody DefConfSaveVo vo) throws Exception { CommonResult res=nodeService.saveDefConf(vo); return res; } /** * 取得当前节点的所有出口节点集合 * @param defId * @param nodeId * @return * @throws Exception */ @RequestMapping(value="getNodeOutcomes",method=RequestMethod.GET, produces = { "application/json; charset=utf-8" }) @ApiOperation(value = "取得当前节点的所有出口节点集合", httpMethod = "GET", notes = "取得当前节点的所有出口节点集合") public Map getNodeOutcomes( @ApiParam(name="defId",value="流程定义id", required = true) @RequestParam String defId, @ApiParam(name="nodeId",value="节点id", required = true) @RequestParam String nodeId) throws Exception{ Map res=nodeService.getNodeOutcomes(defId,nodeId); return res; } /** * 自动任务信息明细 */ @RequestMapping(value="getNodeAutoTask",method=RequestMethod.GET, produces = { "application/json; charset=utf-8" }) @ApiOperation(value = "自动任务信息明细", httpMethod = "GET", notes = "自动任务信息明细") public Object getNodeAutoTask( @ApiParam(name="defId",value="流程定义id", required = true) @RequestParam String defId, @ApiParam(name="nodeId",value="节点id", required = true) @RequestParam String nodeId) throws Exception { Object res=nodeService.getNodeAutoTask(defId,nodeId); return res; } /** * 根据流程定义ID获取全局表单 * */ @RequestMapping(value="getGlobalForm",method=RequestMethod.GET, produces = { "application/json; charset=utf-8" }) @ApiOperation(value = "根据流程定义ID获取全局表单", httpMethod = "GET", notes = "根据流程定义ID获取全局表单") public ObjectNode getGlobalForm(@ApiParam(name = "defId",value = "流程定义ID")@RequestParam String defId, @ApiParam(name = "type", value = "表单类型(PC或者mobile)")@RequestParam String type)throws Exception{ try{ return nodeService.getGlobalForm(defId,type); }catch (BaseException e){ e.setMessage("url表单配置除外");//修改提示 throw e; } } /** * 节点配置复制 * * @param request * @param reponse * @throws Exception */ @RequestMapping(value="copyNodeConf", method=RequestMethod.POST, produces={"application/json; charset=utf-8" }) @ApiOperation(value = "节点配置复制", httpMethod = "POST", notes = "节点配置复制") public CommonResult copyNodeConf(@ApiParam(name="vo",value="节点复制对象")@RequestBody NodeConfCopyVo vo) throws Exception { CommonResult res=nodeService.copyNodeConf(vo); return res; } @RequestMapping(value="getDefSettingByDefKey",method=RequestMethod.GET, produces = { "application/json; charset=utf-8" }) @ApiOperation(value = "根据流程定义Key获取流程定义节点配置页面json数据", httpMethod = "GET", notes = "根据流程定义Key获取流程定义节点配置页面json数据") public Map getDefSettingByDefKey( @ApiParam(name="defKey",value="流程定义key", required = true) @RequestParam String defKey, @ApiParam(name="topDefKey",value="父流程定义key", required = true) @RequestParam String topDefKey) throws Exception { Map res=nodeService.getDefSettingByDefKey(defKey,topDefKey); return res; } }