diff --git a/len-activiti/src/main/java/com/len/actlistener/ActNodeListener.java b/len-activiti/src/main/java/com/len/actlistener/ActNodeListener.java index 0fdb201..7419cd7 100644 --- a/len-activiti/src/main/java/com/len/actlistener/ActNodeListener.java +++ b/len-activiti/src/main/java/com/len/actlistener/ActNodeListener.java @@ -5,7 +5,9 @@ import com.len.service.ActAssigneeService; import com.len.service.impl.ActAssigneeServiceImpl; import com.len.util.AssigneeType; import com.len.util.SpringUtil; + import java.util.List; + import org.activiti.engine.delegate.DelegateTask; import org.activiti.engine.delegate.TaskListener; @@ -13,25 +15,26 @@ import org.activiti.engine.delegate.TaskListener; * @author zhuxiaomeng * @date 2018/1/20. * @email 154040976@qq.com - * + *

* 流程监听器 动态注入节点办理人 */ -public class ActNodeListener implements TaskListener{ +public class ActNodeListener implements TaskListener { - @Override - public void notify(DelegateTask delegateTask) { - String nodeId=delegateTask.getTaskDefinitionKey();//key - ActAssigneeService actAssigneeService= SpringUtil.getBean(ActAssigneeServiceImpl.class); - List assigneeList=actAssigneeService.selectListByPage(new ActAssignee(nodeId)); - for(ActAssignee assignee:assigneeList){ - switch (assignee.getAssigneeType()){ - case AssigneeType.GROUP_TYPE: - delegateTask.addCandidateGroup(assignee.getRoleId()); - break; - case AssigneeType.USER_TYPE: - delegateTask.addCandidateUser(assignee.getAssignee()); - break; + @Override + public void notify(DelegateTask delegateTask) { + //KEY + String nodeId = delegateTask.getTaskDefinitionKey(); + ActAssigneeService actAssigneeService = SpringUtil.getBean(ActAssigneeServiceImpl.class); + List assigneeList = actAssigneeService.selectListByPage(new ActAssignee(nodeId)); + for (ActAssignee assignee : assigneeList) { + switch (assignee.getAssigneeType()) { + case AssigneeType.GROUP_TYPE: + delegateTask.addCandidateGroup(assignee.getRoleId()); + break; + case AssigneeType.USER_TYPE: + delegateTask.addCandidateUser(assignee.getAssignee()); + break; + } + } } - } - } } diff --git a/len-activiti/src/main/java/com/len/actlistener/LeaveListenerImpl.java b/len-activiti/src/main/java/com/len/actlistener/LeaveListenerImpl.java index 87756c8..e90ff28 100644 --- a/len-activiti/src/main/java/com/len/actlistener/LeaveListenerImpl.java +++ b/len-activiti/src/main/java/com/len/actlistener/LeaveListenerImpl.java @@ -1,26 +1,26 @@ package com.len.actlistener; import com.len.entity.UserLeave; + import java.util.Map; + import org.activiti.engine.delegate.DelegateTask; /** * @author zhuxiaomeng * @date 2018/1/25. * @email 154040976@qq.com - * + *

* 自定义请假流程 监听器 */ public class LeaveListenerImpl extends ActNodeListener { - @Override - public void notify(DelegateTask delegateTask) { - super.notify(delegateTask); - String taskId=delegateTask.getId(); - System.out.println(taskId); - Map map =delegateTask.getVariables(); - UserLeave userLeave= (UserLeave) map.get("userLeave"); - delegateTask.addCandidateUser(userLeave.getUserId()); - System.out.println(userLeave); - } + @Override + public void notify(DelegateTask delegateTask) { + super.notify(delegateTask); + String taskId = delegateTask.getId(); + Map map = delegateTask.getVariables(); + UserLeave userLeave = (UserLeave) map.get("userLeave"); + delegateTask.addCandidateUser(userLeave.getUserId()); + } } diff --git a/len-activiti/src/main/java/com/len/actlistener/ListenUserRole.java b/len-activiti/src/main/java/com/len/actlistener/ListenUserRole.java index e89910c..3149bd3 100644 --- a/len-activiti/src/main/java/com/len/actlistener/ListenUserRole.java +++ b/len-activiti/src/main/java/com/len/actlistener/ListenUserRole.java @@ -6,9 +6,11 @@ import com.len.entity.SysUser; import com.len.service.ActAssigneeService; import com.len.service.SysUserService; import com.len.util.JsonUtil; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; + import org.activiti.engine.IdentityService; import org.activiti.engine.identity.Group; import org.activiti.engine.identity.User; @@ -26,157 +28,153 @@ import org.springframework.stereotype.Component; * @author zhuxiaomeng * @date 2018/1/25. * @email 154040976@qq.com - * + *

* 切入实现系统用户 角色 用户-角色 同步到 activiti 用户 组 用户组 同步到工作流,模块化 无侵入 - * - * */ @Aspect @Component public class ListenUserRole { - @Autowired - IdentityService identityService; + @Autowired + IdentityService identityService; - @Autowired - SysUserService userService; + @Autowired + SysUserService userService; - /**********************用户处理begin***************************/ - /** - * 明确切入方法的参数 - * @param joinPoint - */ - @Around("execution(com.len.util.JsonUtil com.len.controller.UserController.updateUser(*,String[]))") - public Object listenerUserUpdate(ProceedingJoinPoint joinPoint) throws Throwable{ - Object o=new Object(); - //更新前拿到用户-角色数据 - SysRoleUser sysRoleUser =new SysRoleUser(); - Object[] args = joinPoint.getArgs(); - sysRoleUser.setUserId(((SysUser)args[0]).getId()); - List keyList=userService.selectByCondition(sysRoleUser); - List strings=new ArrayList<>(); - keyList.forEach(sysRoleUser1 -> strings.add(sysRoleUser1.getRoleId())); - o = joinPoint.proceed(joinPoint.getArgs()); - JsonUtil jsonUtil= (JsonUtil) o; - if(jsonUtil.isFlag()){ - changeUser(args,strings); - } - return o; - } - - /** - * 新增用户监听 同步工作流用户表 环绕注解能得到 插入用户id 啊哈哈 - * @param joinPoint - */ - @Around("execution(com.len.util.JsonUtil com.len.controller.UserController.addUser(*,String[]))") - public Object listenerUserInsert(ProceedingJoinPoint joinPoint) throws Throwable{ - Object o=new Object(); - o = joinPoint.proceed(joinPoint.getArgs()); - Object[] args = joinPoint.getArgs(); - if(args.length==2){ - JsonUtil jsonUtil= (JsonUtil) o; - if(jsonUtil.isFlag()){ - changeUser(args, Arrays.asList((String[]) args[1])); - } - } - return o; - } - - @Around("execution(com.len.util.JsonUtil com.len.controller.UserController.del(..))") - public Object listenDelUser(ProceedingJoinPoint point) throws Throwable{ - Object o=new Object(); - o = point.proceed(point.getArgs()); - JsonUtil util= (JsonUtil) o; - if(util.isFlag()){ - Object[] args = point.getArgs(); - identityService.deleteUser((String) args[0]); - } - return o; - } - - - /** - * 保存进 activiti 用户 角色 用户角色中间表 - * @param obj - */ - private void changeUser(Object[] obj,List strings){ - SysUser user= (SysUser) obj[0]; - identityService.deleteUser(user.getId()); - User au =new UserEntity(); - au.setId(user.getId()); - au.setFirstName(user.getRealName()); - au.setEmail(user.getEmail()); - identityService.saveUser(au); - - //删除用户-组关联 - for(String roleId:strings){ - identityService.deleteMembership(user.getId(),roleId); - } - //再次关联 - if(!strings.isEmpty()){ - for(String roleId:strings){ - identityService.createMembership(user.getId(),roleId); - } - } - } - - /**********************用户处理end***************************/ - - - - /**********************角色处理begin***************************/ - @Around("execution(com.len.util.JsonUtil com.len.controller.RoleController.addRole(*,String[]))") - public Object listenRoleInsert(ProceedingJoinPoint joinPoint)throws Throwable{ - Object o=null; - o=joinPoint.proceed(joinPoint.getArgs()); - JsonUtil j=(JsonUtil)o; - if(j.isFlag()){ + /**********************用户处理begin***************************/ + /** + * 明确切入方法的参数 + * + * @param joinPoint + */ + @Around("execution(com.len.util.JsonUtil com.len.controller.UserController.updateUser(*,String[]))") + public Object listenerUserUpdate(ProceedingJoinPoint joinPoint) throws Throwable { + Object o = new Object(); + //更新前拿到用户-角色数据 + SysRoleUser sysRoleUser = new SysRoleUser(); Object[] args = joinPoint.getArgs(); - if(args.length==2){ - changeRole(args); + sysRoleUser.setUserId(((SysUser) args[0]).getId()); + List keyList = userService.selectByCondition(sysRoleUser); + List strings = new ArrayList<>(); + keyList.forEach(sysRoleUser1 -> strings.add(sysRoleUser1.getRoleId())); + o = joinPoint.proceed(joinPoint.getArgs()); + JsonUtil jsonUtil = (JsonUtil) o; + if (jsonUtil.isFlag()) { + changeUser(args, strings); } - } - return o; - } + return o; + } - @Around("execution(com.len.util.JsonUtil com.len.controller.RoleController.updateUser(*,String[]))") - public Object listenRoleUpdate(ProceedingJoinPoint joinPoint) throws Throwable{ - Object o=null; - o=joinPoint.proceed(joinPoint.getArgs()); - Object[] args = joinPoint.getArgs(); - if(args.length==2){ - if(((JsonUtil)o).isFlag()){ - changeRole(args); + /** + * 新增用户监听 同步工作流用户表 环绕注解能得到 插入用户id 啊哈哈 + * + * @param joinPoint + */ + @Around("execution(com.len.util.JsonUtil com.len.controller.UserController.addUser(*,String[]))") + public Object listenerUserInsert(ProceedingJoinPoint joinPoint) throws Throwable { + Object o = joinPoint.proceed(joinPoint.getArgs()); + Object[] args = joinPoint.getArgs(); + if (args.length == 2) { + JsonUtil jsonUtil = (JsonUtil) o; + if (jsonUtil.isFlag()) { + changeUser(args, Arrays.asList((String[]) args[1])); + } } - } + return o; + } - return o; - } + @Around("execution(com.len.util.JsonUtil com.len.controller.UserController.del(..))") + public Object listenDelUser(ProceedingJoinPoint point) throws Throwable { + Object o = point.proceed(point.getArgs()); + JsonUtil util = (JsonUtil) o; + if (util.isFlag()) { + Object[] args = point.getArgs(); + identityService.deleteUser((String) args[0]); + } + return o; + } - @Around("execution(com.len.util.JsonUtil com.len.controller.RoleController.del(..))") - public Object listenDelRole(ProceedingJoinPoint point) throws Throwable{ - Object o=new Object(); - o = point.proceed(point.getArgs()); - JsonUtil util= (JsonUtil) o; - if(util.isFlag()){ - Object[] args = point.getArgs(); - identityService.deleteGroup((String) args[0]); - } - return o; - } - /** - * 更新进组 - * @param obj - */ - public void changeRole(Object[] obj){ - SysRole role = (SysRole) obj[0]; - identityService.deleteGroup(role.getId()); - Group group=new GroupEntity(); - group.setId(role.getId()); - group.setName(role.getRoleName()); - identityService.saveGroup(group); - } + /** + * 保存进 activiti 用户 角色 用户角色中间表 + * + * @param obj + */ + private void changeUser(Object[] obj, List strings) { + SysUser user = (SysUser) obj[0]; + identityService.deleteUser(user.getId()); + User au = new UserEntity(); + au.setId(user.getId()); + au.setFirstName(user.getRealName()); + au.setEmail(user.getEmail()); + identityService.saveUser(au); - /**********************角色处理end***************************/ + //删除用户-组关联 + for (String roleId : strings) { + identityService.deleteMembership(user.getId(), roleId); + } + //再次关联 + if (!strings.isEmpty()) { + for (String roleId : strings) { + identityService.createMembership(user.getId(), roleId); + } + } + } + + /**********************用户处理end***************************/ + + + /**********************角色处理begin***************************/ + @Around("execution(com.len.util.JsonUtil com.len.controller.RoleController.addRole(*,String[]))") + public Object listenRoleInsert(ProceedingJoinPoint joinPoint) throws Throwable { + Object o = joinPoint.proceed(joinPoint.getArgs()); + JsonUtil j = (JsonUtil) o; + if (j.isFlag()) { + Object[] args = joinPoint.getArgs(); + if (args.length == 2) { + changeRole(args); + } + } + return o; + } + + @Around("execution(com.len.util.JsonUtil com.len.controller.RoleController.updateUser(*,String[]))") + public Object listenRoleUpdate(ProceedingJoinPoint joinPoint) throws Throwable { + Object o = joinPoint.proceed(joinPoint.getArgs()); + Object[] args = joinPoint.getArgs(); + if (args.length == 2) { + if (((JsonUtil) o).isFlag()) { + changeRole(args); + } + } + + return o; + } + + @Around("execution(com.len.util.JsonUtil com.len.controller.RoleController.del(..))") + public Object listenDelRole(ProceedingJoinPoint point) throws Throwable { + Object o = point.proceed(point.getArgs()); + JsonUtil util = (JsonUtil) o; + if (util.isFlag()) { + Object[] args = point.getArgs(); + identityService.deleteGroup((String) args[0]); + } + return o; + } + + /** + * 更新进组 + * + * @param obj + */ + public void changeRole(Object[] obj) { + SysRole role = (SysRole) obj[0]; + identityService.deleteGroup(role.getId()); + Group group = new GroupEntity(); + group.setId(role.getId()); + group.setName(role.getRoleName()); + identityService.saveGroup(group); + } + + /**********************角色处理end***************************/ } diff --git a/len-activiti/src/main/java/com/len/config/ActivitiConfig.java b/len-activiti/src/main/java/com/len/config/ActivitiConfig.java index 48d12b1..ad94547 100644 --- a/len-activiti/src/main/java/com/len/config/ActivitiConfig.java +++ b/len-activiti/src/main/java/com/len/config/ActivitiConfig.java @@ -1,7 +1,9 @@ package com.len.config; import com.fasterxml.jackson.databind.ObjectMapper; + import javax.sql.DataSource; + import org.activiti.engine.DynamicBpmnService; import org.activiti.engine.FormService; import org.activiti.engine.HistoryService; @@ -28,9 +30,11 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter @Configuration public class ActivitiConfig { - /**spring 集成 activiti*/ + /** + * spring 集成 activiti + */ @Bean - public ProcessEngineConfiguration processEngineConfiguration(DataSource dataSource, PlatformTransactionManager transactionManager){ + public ProcessEngineConfiguration processEngineConfiguration(DataSource dataSource, PlatformTransactionManager transactionManager) { SpringProcessEngineConfiguration processEngineConfiguration = new SpringProcessEngineConfiguration(); processEngineConfiguration.setDataSource(dataSource); //表不存在创建表 @@ -50,54 +54,54 @@ public class ActivitiConfig { //流程引擎,与spring整合使用factoryBean @Bean - public ProcessEngineFactoryBean processEngine(ProcessEngineConfiguration processEngineConfiguration){ + public ProcessEngineFactoryBean processEngine(ProcessEngineConfiguration processEngineConfiguration) { ProcessEngineFactoryBean processEngineFactoryBean = new ProcessEngineFactoryBean(); processEngineFactoryBean.setProcessEngineConfiguration((ProcessEngineConfigurationImpl) processEngineConfiguration); return processEngineFactoryBean; } @Bean - public RepositoryService repositoryService(ProcessEngine processEngine){ + public RepositoryService repositoryService(ProcessEngine processEngine) { return processEngine.getRepositoryService(); } @Bean - public RuntimeService runtimeService(ProcessEngine processEngine){ + public RuntimeService runtimeService(ProcessEngine processEngine) { return processEngine.getRuntimeService(); } @Bean - public TaskService taskService(ProcessEngine processEngine){ + public TaskService taskService(ProcessEngine processEngine) { return processEngine.getTaskService(); } @Bean - public HistoryService historyService(ProcessEngine processEngine){ + public HistoryService historyService(ProcessEngine processEngine) { return processEngine.getHistoryService(); } @Bean - public FormService formService(ProcessEngine processEngine){ + public FormService formService(ProcessEngine processEngine) { return processEngine.getFormService(); } @Bean - public IdentityService identityService(ProcessEngine processEngine){ + public IdentityService identityService(ProcessEngine processEngine) { return processEngine.getIdentityService(); } @Bean - public ManagementService managementService(ProcessEngine processEngine){ + public ManagementService managementService(ProcessEngine processEngine) { return processEngine.getManagementService(); } @Bean - public DynamicBpmnService dynamicBpmnService(ProcessEngine processEngine){ + public DynamicBpmnService dynamicBpmnService(ProcessEngine processEngine) { return processEngine.getDynamicBpmnService(); } @Bean - public ObjectMapper objectMapper(){ + public ObjectMapper objectMapper() { return new ObjectMapper(); } } diff --git a/len-activiti/src/main/java/com/len/controller/ActivitiController.java b/len-activiti/src/main/java/com/len/controller/ActivitiController.java index 6c86d64..a4501ff 100644 --- a/len-activiti/src/main/java/com/len/controller/ActivitiController.java +++ b/len-activiti/src/main/java/com/len/controller/ActivitiController.java @@ -21,6 +21,7 @@ import com.len.service.SysUserService; import com.len.util.Checkbox; import com.len.util.JsonUtil; import com.len.util.ReType; + import java.io.ByteArrayInputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -33,6 +34,7 @@ import java.util.List; import java.util.Map; import java.util.Properties; import javax.servlet.http.HttpServletRequest; + import org.activiti.bpmn.converter.BpmnXMLConverter; import org.activiti.bpmn.model.BpmnModel; import org.activiti.editor.constants.ModelDataJsonConstants; @@ -67,375 +69,380 @@ import org.springframework.web.bind.annotation.ResponseBody; * @author zhuxiaomeng * @date 2018/1/13. * @email 154040976@qq.com - * + *

* 流程管理 流程创建、发布 流程节点绑定角色/用户(绑定用户 开始ing) */ @Controller @RequestMapping(value = "/act") public class ActivitiController extends BaseController { - @Autowired - RepositoryService repositoryService; + @Autowired + RepositoryService repositoryService; - @Autowired - ObjectMapper objectMapper; + @Autowired + ObjectMapper objectMapper; - @Autowired - RuntimeService runtimeService; + @Autowired + RuntimeService runtimeService; - @Autowired - IdentityService identityService; + @Autowired + IdentityService identityService; - @Autowired - SysUserService userService; + @Autowired + SysUserService userService; - @Autowired - RoleService roleService; + @Autowired + RoleService roleService; - @Autowired - RoleUserService roleUserService; + @Autowired + RoleUserService roleUserService; - @Autowired - ActAssigneeService actAssigneeService; + @Autowired + ActAssigneeService actAssigneeService; - /** - * 同步用户 角色 用户角色到activiti表中 - */ - @PostMapping(value = "syncdata") - @ResponseBody - public JsonUtil syncdata() { - JsonUtil j = new JsonUtil(); - try { - List userList = userService.selectListByPage(new SysUser()); - User au = null; - for (SysUser user : userList) { - au = new UserEntity(); - au.setId(user.getId()); - au.setFirstName(user.getRealName()); - au.setEmail(user.getEmail()); - identityService.deleteUser(au.getId()); - identityService.saveUser(au); - } - List sysRoleList = roleService.selectListByPage(new SysRole()); - Group group = null; - for (SysRole role : sysRoleList) { - group = new GroupEntity(); - group.setId(role.getId()); - group.setName(role.getRoleName()); - identityService.deleteGroup(group.getId()); - identityService.saveGroup(group); - } - List roleUserList = roleUserService.selectByCondition(new SysRoleUser()); + /** + * 同步用户 角色 用户角色到activiti表中 + */ + @PostMapping(value = "syncdata") + @ResponseBody + public JsonUtil syncdata() { + JsonUtil j = new JsonUtil(); + try { + List userList = userService.selectListByPage(new SysUser()); + User au = null; + for (SysUser user : userList) { + au = new UserEntity(); + au.setId(user.getId()); + au.setFirstName(user.getRealName()); + au.setEmail(user.getEmail()); + identityService.deleteUser(au.getId()); + identityService.saveUser(au); + } + List sysRoleList = roleService.selectListByPage(new SysRole()); + Group group = null; + for (SysRole role : sysRoleList) { + group = new GroupEntity(); + group.setId(role.getId()); + group.setName(role.getRoleName()); + identityService.deleteGroup(group.getId()); + identityService.saveGroup(group); + } + List roleUserList = roleUserService.selectByCondition(new SysRoleUser()); - for (SysRoleUser sysRoleUser : roleUserList) { - identityService.deleteMembership(sysRoleUser.getUserId(), sysRoleUser.getRoleId()); - identityService.createMembership(sysRoleUser.getUserId(), sysRoleUser.getRoleId()); - } - j.setMsg("同步成功"); - } catch (MyException e) { - j.setFlag(false); - j.setMsg("同步失败"); - e.printStackTrace(); - } - return j; - } - /**方法此有所参考 感谢我参考原作者:liuruijie - * - */ - @GetMapping(value = "goActiviti") - public String goActiviti() throws UnsupportedEncodingException { - Model model = repositoryService.newModel(); - - String name = "新建流程"; - String description = ""; - int revision = 1; - String key = "processKey"; - - ObjectNode modelNode = objectMapper.createObjectNode(); - modelNode.put(ModelDataJsonConstants.MODEL_NAME, name); - modelNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, description); - modelNode.put(ModelDataJsonConstants.MODEL_REVISION, revision); - - model.setName(name); - model.setKey(key); - model.setMetaInfo(modelNode.toString()); - - repositoryService.saveModel(model); - String id = model.getId(); - - //完善ModelEditorSource - 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); - repositoryService.addModelEditorSource(id, editorNode.toString().getBytes("utf-8")); - return "redirect:/static/modeler.html?modelId=" + id; - } - - @GetMapping("actUpdate/{id}") - public String actUpdate(@PathVariable String id){ - return "redirect:/static/modeler.html?modelId=" + id; - } - - @GetMapping(value = "goAct") - public String goAct(org.springframework.ui.Model model) { - return "/actList"; - } - - /** - * 部署列表 - */ - @GetMapping(value = "showAct") - @ResponseBody - public String showAct(org.springframework.ui.Model model, ProcessDefinition definition, - String page, String limit) { - ProcessDefinitionQuery processDefinitionQuery = repositoryService - .createProcessDefinitionQuery(); - List processDefinitionList=null; - if(definition!=null){ - if(!StringUtils.isEmpty(definition.getDeploymentId())){ - processDefinitionQuery.deploymentId(definition.getDeploymentId()); - } - if(!StringUtils.isEmpty(definition.getName())){ - processDefinitionQuery.processDefinitionNameLike("%"+definition.getName()+"%"); - - } - } - processDefinitionList = processDefinitionQuery.listPage(Integer.valueOf(limit) * (Integer.valueOf(page) - 1), Integer.valueOf(limit)); - long count = repositoryService.createDeploymentQuery().count(); - List list = new ArrayList<>(); - processDefinitionList - .forEach(processDefinition -> list.add(new ProcessDefinition(processDefinition))); - ReType reType = new ReType(count, list); - return JSON.toJSONString(reType); - } - - - @GetMapping(value = "goActModel") - public String goActModel(org.springframework.ui.Model model) { - return "/actModelList"; - } - - /** - * 模型列表 - */ - @GetMapping(value = "showAm") - @ResponseBody - public String showModel(org.springframework.ui.Model model, ActModel actModel, String page, - String limit) { - ModelQuery modelQuery = repositoryService.createModelQuery(); - if(actModel!=null){ - if(!StringUtils.isEmpty(actModel.getKey())){ - modelQuery.modelKey(actModel.getKey()); - } - if(!StringUtils.isEmpty(actModel.getName())){ - modelQuery.modelNameLike("%"+actModel.getName()+"%"); - } - } - List models = modelQuery - .listPage(Integer.valueOf(limit) * (Integer.valueOf(page) - 1), Integer.valueOf(limit)); - long count = repositoryService.createModelQuery().count(); - List list = new ArrayList<>(); - models.forEach(mo -> list.add(new ActModel(mo))); - ReType reType = new ReType(count, list); - return JSON.toJSONString(reType); - } - - /** - * 发布流程 - */ - @PostMapping(value = "open") - @ResponseBody - public JsonUtil open(String id) { - String msg = "发布成功"; - JsonUtil j = new JsonUtil(); - try { - Model modelData = repositoryService.getModel(id); - byte[] bytes = repositoryService.getModelEditorSource(modelData.getId()); - - if (bytes == null) { - return JsonUtil.error("模型为空"); - } - JsonNode modelNode = null; - modelNode = new ObjectMapper().readTree(bytes); - BpmnModel model = new BpmnJsonConverter().convertToBpmnModel(modelNode); - if (model.getProcesses().size() == 0) { - return JsonUtil.error("数据不符合要求"); - } - byte[] bpmnBytes = new BpmnXMLConverter().convertToXML(model); - //发布流程 - String processName = modelData.getName() + ".bpmn20.xml"; - String convertToXML = new String(bpmnBytes); - - System.out.println(convertToXML); - Deployment deployment = repositoryService.createDeployment() - .name(modelData.getName()) - .addString(processName, new String(bpmnBytes, "UTF-8")) - .deploy(); - modelData.setDeploymentId(deployment.getId()); - repositoryService.saveModel(modelData); - } catch (MyException e) { - msg = "发布数失败"; - j.setFlag(false); - } catch (IOException e) { - e.printStackTrace(); - } - j.setMsg(msg); - return j; - } - - public List getActivityList(String deploymentId){ - org.activiti.engine.repository.ProcessDefinition processDefinition = repositoryService - .createProcessDefinitionQuery().deploymentId(deploymentId).singleResult(); - ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService) - .getDeployedProcessDefinition(processDefinition.getId()); - return processDefinitionEntity.getActivities(); - - } - - /** - * 根据流程部署id获取节点并且传到前端 - * @param deploymentId 部署id - * @param model - * @return - */ - @GetMapping("goAssignee/{id}") - public String goAssignee(@PathVariable("id") String deploymentId, - org.springframework.ui.Model model) { - - /**根据流程实例id查询出所有流程节点*/ - List activityList=getActivityList(deploymentId); - - /**角色和节点关系封装成list*/ - List roleList = roleService.selectListByPage(new SysRole()); - List checkboxes=new ArrayList<>(); - Checkbox checkbox = null; - Map map = null; - List> mapList = new ArrayList<>(); - List assigneeList = null; - List checkboxList =null; - for (ActivityImpl activiti : activityList) { - map = new HashMap<>(); - String name = (String) activiti.getProperty("name"); - if (StringUtils.isEmpty(name)||"start".equals(name) || "end".equals(name)) { - continue; - } - //节点id 、name、节点目前关联的角色 封装成进map - String nodeId=activiti.getId(); - assigneeList= actAssigneeService.selectListByPage( new ActAssignee(nodeId)); - List strings = new ArrayList<>(); - assigneeList.forEach(actAssignee1 -> strings.add(actAssignee1.getRoleId())); - map.put("id", nodeId); - map.put("name", name); - checkboxList = new ArrayList<>(); - for (SysRole role : roleList) { - checkbox = new Checkbox(); - checkbox.setId(role.getId()); - checkbox.setName(role.getRoleName()); - if(strings.contains(role.getId())){ - checkbox.setCheck(true); + for (SysRoleUser sysRoleUser : roleUserList) { + identityService.deleteMembership(sysRoleUser.getUserId(), sysRoleUser.getRoleId()); + identityService.createMembership(sysRoleUser.getUserId(), sysRoleUser.getRoleId()); + } + j.setMsg("同步成功"); + } catch (MyException e) { + j.setFlag(false); + j.setMsg("同步失败"); + e.printStackTrace(); } - checkboxList.add(checkbox); - } - map.put("boxJson",checkboxList); - mapList.add(map); + return j; } - model.addAttribute("actList", mapList); - return "act/deploy/act-node"; - } + /** + * 方法此有所参考 感谢我参考原作者:liuruijie + */ + @GetMapping(value = "goActiviti") + public String goActiviti() throws UnsupportedEncodingException { + Model model = repositoryService.newModel(); - /** - * 节点更新配置办理者(人/组) - * @param request - * @return - */ - @PostMapping("goAssignee/updateNode") - @ResponseBody - public JsonUtil updateNode(HttpServletRequest request){ - JsonUtil j=new JsonUtil(); + String name = "新建流程"; + String description = ""; + int revision = 1; + String key = "processKey"; - Map map=request.getParameterMap(); - List assigneeList=new ArrayList<>(); - ActAssignee assignee=null; - for(Map.Entry entry:map.entrySet()){ - assignee=new ActAssignee(); - int sub=entry.getKey().lastIndexOf("_"); - String nodeId=entry.getKey().substring(0,sub); - nodeId=nodeId.substring(nodeId.lastIndexOf("_")+1,nodeId.length()); - String nodeName=entry.getKey().substring(entry.getKey().lastIndexOf("_")+1,entry.getKey().length()); - //更新进list - assignee.setAssigneeType(3); - assignee.setRoleId(entry.getValue()[0]); - assignee.setSid(nodeId); - assignee.setActivtiName(nodeName); - //先清除 - actAssigneeService.deleteByNodeId(nodeId); - assigneeList.add(assignee); + ObjectNode modelNode = objectMapper.createObjectNode(); + modelNode.put(ModelDataJsonConstants.MODEL_NAME, name); + modelNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, description); + modelNode.put(ModelDataJsonConstants.MODEL_REVISION, revision); + + model.setName(name); + model.setKey(key); + model.setMetaInfo(modelNode.toString()); + + repositoryService.saveModel(model); + String id = model.getId(); + + //完善ModelEditorSource + 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); + repositoryService.addModelEditorSource(id, editorNode.toString().getBytes("utf-8")); + return "redirect:/static/modeler.html?modelId=" + id; } - //后添加 在map循环里添加 多角色会导致添加了的再次被删除 so 要拿出来 - for(ActAssignee actAssignee:assigneeList){ - actAssigneeService.insertSelective(actAssignee); - } - j.setMsg("更新成功"); - return j; - } - /** - * 删除流程定义 级联 删除 流程节点绑定信息 - * @param model - * @param id - * @return - */ - @PostMapping("delDeploy") - @ResponseBody - public JsonUtil delDeploy(org.springframework.ui.Model model,String id){ - JsonUtil j=new JsonUtil(); - try { - List activityList=getActivityList(id); - for(ActivityImpl activity:activityList){ - String nodeId=activity.getId(); - if (StringUtils.isEmpty(nodeId)||"start".equals(nodeId) || "end".equals(nodeId)) { - continue; + @GetMapping("actUpdate/{id}") + public String actUpdate(@PathVariable String id) { + return "redirect:/static/modeler.html?modelId=" + id; + } + + @GetMapping(value = "goAct") + public String goAct(org.springframework.ui.Model model) { + return "/actList"; + } + + /** + * 部署列表 + */ + @GetMapping(value = "showAct") + @ResponseBody + public String showAct(org.springframework.ui.Model model, ProcessDefinition definition, + String page, String limit) { + ProcessDefinitionQuery processDefinitionQuery = repositoryService + .createProcessDefinitionQuery(); + List processDefinitionList = null; + if (definition != null) { + if (!StringUtils.isEmpty(definition.getDeploymentId())) { + processDefinitionQuery.deploymentId(definition.getDeploymentId()); + } + if (!StringUtils.isEmpty(definition.getName())) { + processDefinitionQuery.processDefinitionNameLike("%" + definition.getName() + "%"); + + } } - /**接触节点和代办关联*/ - actAssigneeService.deleteByNodeId(nodeId); - } - repositoryService.deleteDeployment(id, true); - j.setMsg("删除成功"); - }catch (MyException e){ - j.setMsg("删除失败"); - j.setFlag(false); - e.printStackTrace(); + processDefinitionList = processDefinitionQuery.listPage(Integer.valueOf(limit) * (Integer.valueOf(page) - 1), Integer.valueOf(limit)); + long count = repositoryService.createDeploymentQuery().count(); + List list = new ArrayList<>(); + processDefinitionList + .forEach(processDefinition -> list.add(new ProcessDefinition(processDefinition))); + ReType reType = new ReType(count, list); + return JSON.toJSONString(reType); } - return j; - } - @Autowired - ActPropertiesConfig actPropertiesConfig; - @PostMapping("delModel") - @ResponseBody - public JsonUtil delModel(org.springframework.ui.Model model,String id){ - FileInputStream inputStream=null; - String modelId=actPropertiesConfig.getModelId(); - if (id.equals(modelId)){ - return JsonUtil.error("演示禁止删除"); - } - JsonUtil j=new JsonUtil(); - try { - repositoryService.deleteModel(id); - j.setMsg("删除成功"); - }catch (MyException e){ - j.setMsg("删除失败"); - j.setFlag(false); - e.printStackTrace(); + + @GetMapping(value = "goActModel") + public String goActModel(org.springframework.ui.Model model) { + return "/actModelList"; + } + + /** + * 模型列表 + */ + @GetMapping(value = "showAm") + @ResponseBody + public String showModel(org.springframework.ui.Model model, ActModel actModel, String page, + String limit) { + ModelQuery modelQuery = repositoryService.createModelQuery(); + if (actModel != null) { + if (!StringUtils.isEmpty(actModel.getKey())) { + modelQuery.modelKey(actModel.getKey()); + } + if (!StringUtils.isEmpty(actModel.getName())) { + modelQuery.modelNameLike("%" + actModel.getName() + "%"); + } + } + List models = modelQuery + .listPage(Integer.valueOf(limit) * (Integer.valueOf(page) - 1), Integer.valueOf(limit)); + long count = repositoryService.createModelQuery().count(); + List list = new ArrayList<>(); + models.forEach(mo -> list.add(new ActModel(mo))); + ReType reType = new ReType(count, list); + return JSON.toJSONString(reType); + } + + /** + * 发布流程 + */ + @PostMapping(value = "open") + @ResponseBody + public JsonUtil open(String id) { + String msg = "发布成功"; + JsonUtil j = new JsonUtil(); + try { + Model modelData = repositoryService.getModel(id); + byte[] bytes = repositoryService.getModelEditorSource(modelData.getId()); + + if (bytes == null) { + return JsonUtil.error("模型为空"); + } + JsonNode modelNode = null; + modelNode = new ObjectMapper().readTree(bytes); + BpmnModel model = new BpmnJsonConverter().convertToBpmnModel(modelNode); + if (model.getProcesses().size() == 0) { + return JsonUtil.error("数据不符合要求"); + } + byte[] bpmnBytes = new BpmnXMLConverter().convertToXML(model); + //发布流程 + String processName = modelData.getName() + ".bpmn20.xml"; + String convertToXML = new String(bpmnBytes); + + System.out.println(convertToXML); + Deployment deployment = repositoryService.createDeployment() + .name(modelData.getName()) + .addString(processName, new String(bpmnBytes, "UTF-8")) + .deploy(); + modelData.setDeploymentId(deployment.getId()); + repositoryService.saveModel(modelData); + } catch (MyException e) { + msg = "发布数失败"; + j.setFlag(false); + } catch (IOException e) { + e.printStackTrace(); + } + j.setMsg(msg); + return j; + } + + public List getActivityList(String deploymentId) { + org.activiti.engine.repository.ProcessDefinition processDefinition = repositoryService + .createProcessDefinitionQuery().deploymentId(deploymentId).singleResult(); + ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService) + .getDeployedProcessDefinition(processDefinition.getId()); + return processDefinitionEntity.getActivities(); + + } + + /** + * 根据流程部署id获取节点并且传到前端 + * + * @param deploymentId 部署id + * @param model + * @return + */ + @GetMapping("goAssignee/{id}") + public String goAssignee(@PathVariable("id") String deploymentId, + org.springframework.ui.Model model) { + + /**根据流程实例id查询出所有流程节点*/ + List activityList = getActivityList(deploymentId); + + /**角色和节点关系封装成list*/ + List roleList = roleService.selectListByPage(new SysRole()); + List checkboxes = new ArrayList<>(); + Checkbox checkbox = null; + Map map = null; + List> mapList = new ArrayList<>(); + List assigneeList = null; + List checkboxList = null; + for (ActivityImpl activiti : activityList) { + map = new HashMap<>(); + String name = (String) activiti.getProperty("name"); + if (StringUtils.isEmpty(name) || "start".equals(name) || "end".equals(name)) { + continue; + } + //节点id 、name、节点目前关联的角色 封装成进map + String nodeId = activiti.getId(); + assigneeList = actAssigneeService.selectListByPage(new ActAssignee(nodeId)); + List strings = new ArrayList<>(); + assigneeList.forEach(actAssignee1 -> strings.add(actAssignee1.getRoleId())); + map.put("id", nodeId); + map.put("name", name); + checkboxList = new ArrayList<>(); + for (SysRole role : roleList) { + checkbox = new Checkbox(); + checkbox.setId(role.getId()); + checkbox.setName(role.getRoleName()); + if (strings.contains(role.getId())) { + checkbox.setCheck(true); + } + checkboxList.add(checkbox); + } + map.put("boxJson", checkboxList); + mapList.add(map); + } + model.addAttribute("actList", mapList); + + return "act/deploy/act-node"; + } + + /** + * 节点更新配置办理者(人/组) + * + * @param request + * @return + */ + @PostMapping("goAssignee/updateNode") + @ResponseBody + public JsonUtil updateNode(HttpServletRequest request) { + JsonUtil j = new JsonUtil(); + + Map map = request.getParameterMap(); + List assigneeList = new ArrayList<>(); + ActAssignee assignee = null; + for (Map.Entry entry : map.entrySet()) { + assignee = new ActAssignee(); + int sub = entry.getKey().lastIndexOf("_"); + String nodeId = entry.getKey().substring(0, sub); + nodeId = nodeId.substring(nodeId.lastIndexOf("_") + 1, nodeId.length()); + String nodeName = entry.getKey().substring(entry.getKey().lastIndexOf("_") + 1, entry.getKey().length()); + //更新进list + assignee.setAssigneeType(3); + assignee.setRoleId(entry.getValue()[0]); + assignee.setSid(nodeId); + assignee.setActivtiName(nodeName); + //先清除 + actAssigneeService.deleteByNodeId(nodeId); + assigneeList.add(assignee); + } + //后添加 在map循环里添加 多角色会导致添加了的再次被删除 so 要拿出来 + for (ActAssignee actAssignee : assigneeList) { + actAssigneeService.insertSelective(actAssignee); + } + j.setMsg("更新成功"); + return j; + } + + /** + * 删除流程定义 级联 删除 流程节点绑定信息 + * + * @param model + * @param id + * @return + */ + @PostMapping("delDeploy") + @ResponseBody + public JsonUtil delDeploy(org.springframework.ui.Model model, String id) { + JsonUtil j = new JsonUtil(); + try { + List activityList = getActivityList(id); + for (ActivityImpl activity : activityList) { + String nodeId = activity.getId(); + if (StringUtils.isEmpty(nodeId) || "start".equals(nodeId) || "end".equals(nodeId)) { + continue; + } + /**接触节点和代办关联*/ + actAssigneeService.deleteByNodeId(nodeId); + } + repositoryService.deleteDeployment(id, true); + j.setMsg("删除成功"); + } catch (MyException e) { + j.setMsg("删除失败"); + j.setFlag(false); + e.printStackTrace(); + } + return j; + } + + @Autowired + ActPropertiesConfig actPropertiesConfig; + + @PostMapping("delModel") + @ResponseBody + public JsonUtil delModel(org.springframework.ui.Model model, String id) { + FileInputStream inputStream = null; + String modelId = actPropertiesConfig.getModelId(); + if (id.equals(modelId)) { + return JsonUtil.error("演示禁止删除"); + } + JsonUtil j = new JsonUtil(); + try { + repositoryService.deleteModel(id); + j.setMsg("删除成功"); + } catch (MyException e) { + j.setMsg("删除失败"); + j.setFlag(false); + e.printStackTrace(); + } + return j; } - return j; - } } diff --git a/len-activiti/src/main/java/com/len/controller/UserLeaveController.java b/len-activiti/src/main/java/com/len/controller/UserLeaveController.java index 51436e1..1bc401b 100644 --- a/len-activiti/src/main/java/com/len/controller/UserLeaveController.java +++ b/len-activiti/src/main/java/com/len/controller/UserLeaveController.java @@ -14,6 +14,7 @@ import com.len.util.BeanUtil; import com.len.util.CommonUtil; import com.len.util.JsonUtil; import com.len.util.ReType; + import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; @@ -24,6 +25,7 @@ import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + import org.activiti.bpmn.model.BpmnModel; import org.activiti.engine.*; import org.activiti.engine.history.HistoricActivityInstance; @@ -51,300 +53,305 @@ import org.springframework.web.bind.annotation.ResponseBody; * @author zhuxiaomeng * @date 2018/1/21. * @email 154040976@qq.com - * + *

* 请假流程示例 */ @Controller @RequestMapping("/leave") public class UserLeaveController extends BaseController { - @Autowired - UserLeaveService leaveService; + @Autowired + UserLeaveService leaveService; - @Autowired - RuntimeService runtimeService; + @Autowired + RuntimeService runtimeService; - @Autowired - TaskService taskService; + @Autowired + TaskService taskService; - @Autowired - IdentityService identityService; + @Autowired + IdentityService identityService; - @Autowired - RepositoryService repositoryService; + @Autowired + RepositoryService repositoryService; - @Autowired - ProcessEngineFactoryBean processEngine; + @Autowired + ProcessEngineFactoryBean processEngine; - @Autowired - ProcessEngineConfiguration processEngineConfiguration; + @Autowired + ProcessEngineConfiguration processEngineConfiguration; - private String leaveOpinionList="leaveOpinionList"; + private String leaveOpinionList = "leaveOpinionList"; - @GetMapping(value = "showLeave") - public String showUser(Model model) { - return "/act/leave/leaveList"; - } - - @GetMapping(value = "showLeaveList") - @ResponseBody - public String showLeaveList(Model model, UserLeave userLeave, String page, String limit) { - String userId=CommonUtil.getUser().getId(); - userLeave.setUserId(userId); - List tList=null; - Page tPage= PageHelper.startPage(Integer.valueOf(page),Integer.valueOf(limit)); - try{ - tList=leaveService.selectListByPage(userLeave); - for(UserLeave leave:tList){ - ProcessInstance instance= runtimeService.createProcessInstanceQuery() - .processInstanceId(leave.getProcessInstanceId()).singleResult(); - //保证运行ing - if(instance!=null){ - Task task = this.taskService.createTaskQuery().processInstanceId(leave.getProcessInstanceId()).singleResult(); - leave.setTaskName(task.getName()); - } - } - }catch (MyException e){ - e.printStackTrace(); + @GetMapping(value = "showLeave") + public String showUser(Model model) { + return "/act/leave/leaveList"; } - ReType reType=new ReType(tPage.getTotal(),tList); - return JSON.toJSONString(reType); - } - /** - * 根据 执行对象id获取审批信息 - * @param model - * @param processId - * @return - */ - @GetMapping("leaveDetail") - public String leaveDetail(Model model,String processId){ - ProcessInstance instance= runtimeService.createProcessInstanceQuery() - .processInstanceId(processId).singleResult(); - //保证运行ing - List leaveList=null; - List historicActivityInstanceList=new ArrayList<>(); - if(instance!=null){ - Task task = this.taskService.createTaskQuery().processInstanceId(processId).singleResult(); - Map variables = taskService.getVariables(task.getId()); - Object o = variables.get(leaveOpinionList); - if(o!=null){ + @GetMapping(value = "showLeaveList") + @ResponseBody + public String showLeaveList(Model model, UserLeave userLeave, String page, String limit) { + String userId = CommonUtil.getUser().getId(); + userLeave.setUserId(userId); + List tList = null; + Page tPage = PageHelper.startPage(Integer.valueOf(page), Integer.valueOf(limit)); + try { + tList = leaveService.selectListByPage(userLeave); + for (UserLeave leave : tList) { + ProcessInstance instance = runtimeService.createProcessInstanceQuery() + .processInstanceId(leave.getProcessInstanceId()).singleResult(); + //保证运行ing + if (instance != null) { + Task task = this.taskService.createTaskQuery().processInstanceId(leave.getProcessInstanceId()).singleResult(); + leave.setTaskName(task.getName()); + } + } + } catch (MyException e) { + e.printStackTrace(); + } + ReType reType = new ReType(tPage.getTotal(), tList); + return JSON.toJSONString(reType); + } + + /** + * 根据 执行对象id获取审批信息 + * + * @param model + * @param processId + * @return + */ + @GetMapping("leaveDetail") + public String leaveDetail(Model model, String processId) { + ProcessInstance instance = runtimeService.createProcessInstanceQuery() + .processInstanceId(processId).singleResult(); + //保证运行ing + List leaveList = null; + List historicActivityInstanceList = new ArrayList<>(); + if (instance != null) { + Task task = this.taskService.createTaskQuery().processInstanceId(processId).singleResult(); + Map variables = taskService.getVariables(task.getId()); + Object o = variables.get(leaveOpinionList); + if (o != null) { /*获取历史审核信息*/ - leaveList= ( List) o; - } - }else{ - leaveList=new ArrayList<>(); - List list = historyService.createHistoricDetailQuery(). - processInstanceId(processId).list(); - HistoricVariableUpdate variable=null; - for(HistoricDetail historicDetail:list){ - variable= (HistoricVariableUpdate) historicDetail; - String variableName = variable.getVariableName(); - if(leaveOpinionList.equals(variable.getVariableName())){ - leaveList.clear(); - leaveList.addAll((List)variable.getValue()); + leaveList = (List) o; + } + } else { + leaveList = new ArrayList<>(); + List list = historyService.createHistoricDetailQuery(). + processInstanceId(processId).list(); + HistoricVariableUpdate variable = null; + for (HistoricDetail historicDetail : list) { + variable = (HistoricVariableUpdate) historicDetail; + String variableName = variable.getVariableName(); + if (leaveOpinionList.equals(variable.getVariableName())) { + leaveList.clear(); + leaveList.addAll((List) variable.getValue()); + } } } - } - model.addAttribute("leaveDetail",JSON.toJSONString(leaveList)); - return "/act/leave/leaveDetail"; - } - - @GetMapping("addLeave") - public String addLeave(){ - return "/act/leave/add-leave"; - } - - @GetMapping("updateLeave/{taskId}") - public String updateLeave(Model model,@PathVariable String taskId){ - Map variables = taskService.getVariables(taskId); - UserLeave leave= (UserLeave) variables.get("userLeave"); - leave=leaveService.selectByPrimaryKey(leave.getId()); - model.addAttribute("leave",leave); - model.addAttribute("taskId",taskId); - return "/act/leave/update-leave"; - } - - @PostMapping("updateLeave/updateLeave/{taskId}/{id}/{flag}") - @ResponseBody - public JsonUtil updateLeave(UserLeave leave,@PathVariable String taskId,@PathVariable String id,@PathVariable boolean flag){ - JsonUtil j=new JsonUtil(); - try { - UserLeave oldLeave = leaveService.selectByPrimaryKey(leave.getId()); - BeanUtil.copyNotNullBean(leave, oldLeave); - leaveService.updateByPrimaryKeySelective(oldLeave); - - Map variables = taskService.getVariables(taskId); - UserLeave userLeave= (UserLeave) variables.get("userLeave"); - Map map=new HashMap<>(); - if(flag){ - map.put("flag",true); - }else{ - map.put("flag",false); - } - taskService.complete(taskId,map); - j.setMsg("保存成功"); - }catch (MyException e){ - j.setMsg("保存失败"); - j.setFlag(false); - e.printStackTrace(); - } - return j; - } - - - @PostMapping("addLeave") - @ResponseBody - public JsonUtil addLeave(Model model,UserLeave userLeave){ - JsonUtil j=new JsonUtil(); - if(userLeave==null){ - return JsonUtil.error("获取数据失败"); - } - userLeave.setDays(3); - CurrentUser user = CommonUtil.getUser(); - userLeave.setUserId(user.getId()); - userLeave.setUserName(user.getUsername()); - userLeave.setProcessInstanceId("2018");//模拟数据 - - leaveService.insertSelective(userLeave); - Map map=new HashedMap(); - map.put("userLeave",userLeave); - ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process_leave",map); - userLeave.setProcessInstanceId(processInstance.getId()); - UserLeave userLeave1=leaveService.selectByPrimaryKey(userLeave.getId()); - BeanUtil.copyNotNullBean(userLeave, userLeave1); - leaveService.updateByPrimaryKeySelective(userLeave1); - if (processInstance == null) { - return JsonUtil.error("未识别key"); - } - j.setMsg("请假申请成功"); - return j; - } - - /**---------我的任务---------*/ - @GetMapping(value = "showTask") - public String showTask(Model model){ - return "/act/task/taskList"; - } - - @GetMapping(value = "showTaskList") - @ResponseBody - public String showTaskList(Model model, com.len.entity.Task task, String page, String limit) { - CurrentUser user = CommonUtil.getUser(); - List taskList = taskService.createTaskQuery().taskCandidateUser(user.getId()).list(); - List tasks=new ArrayList<>(); - Map map=new HashMap<>(); - com.len.entity.Task taskEntity=null; - - Map> mapMap=new HashMap<>(); - Map objectMap=null; - for(Task task1:taskList){ - objectMap=new HashMap<>(); - map=taskService.getVariables(task1.getId()); - UserLeave userLeave= (UserLeave) map.get("userLeave"); - - taskEntity=new com.len.entity.Task(task1); - taskEntity.setUserName(userLeave.getUserName()); - taskEntity.setReason(userLeave.getReason()); - /**如果是自己*/ - if(user.getId().equals(userLeave.getUserId())&&!(boolean) map.get("flag")){ - objectMap.put("flag",true); - }else{ - objectMap.put("flag",false); - } - mapMap.put(taskEntity.getId(),objectMap); - tasks.add(taskEntity); - } - return ReType.jsonStrng(taskList.size(),tasks,mapMap,"id"); - } - - @GetMapping("agent/{id}") - public String agent(Model model,@PathVariable("id") String taskId){ - Map variables = taskService.getVariables(taskId); - UserLeave userLeave= (UserLeave) variables.get("userLeave"); - userLeave=leaveService.selectByPrimaryKey(userLeave.getId()); - model.addAttribute("leave",userLeave); - model.addAttribute("taskId",taskId); - return "/act/task/task-agent"; - } - - @PostMapping("agent/complete") - @ResponseBody - public JsonUtil complete(LeaveOpinion op,HttpServletRequest request){ - Map variables = taskService.getVariables(op.getTaskId()); - UserLeave userLeave= (UserLeave) variables.get("userLeave"); - CurrentUser user= ShiroUtil.getCurrentUse(); - op.setCreateTime(new Date()); - op.setOpId(user.getId()); - op.setOpName(user.getRealName()); - JsonUtil j=new JsonUtil(); - Map map=new HashMap<>(); - map.put("flag",op.isFlag()); - //审批信息叠加 - List leaveList=new ArrayList<>(); - Object o = variables.get(leaveOpinionList); - if(o!=null){ - leaveList= (List) o; - } - leaveList.add(op); - map.put(leaveOpinionList,leaveList); - j.setMsg("审核成功"+(op.isFlag()?"[通过]":"[未通过]")); - taskService.complete(op.getTaskId(),map); - return j; - } - - @Autowired - HistoryService historyService; - /** - * 追踪图片成图 - * @param request - * @param resp - * @param processInstanceId - * @throws IOException - */ - @GetMapping("getProcImage") - public void getProcImage(HttpServletRequest request, HttpServletResponse resp,String processInstanceId) - throws IOException { - ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); - HistoricProcessInstance historicProcessInstance = - historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); - String processDefinitionId=null; - List executedActivityIdList = new ArrayList(); - if(processInstance!=null){ - processDefinitionId=processInstance.getProcessDefinitionId(); - executedActivityIdList=this.runtimeService.getActiveActivityIds(processInstance.getId()); - }else if(historicProcessInstance!=null){ - processDefinitionId=historicProcessInstance.getProcessDefinitionId(); - List historicActivityInstanceList = - historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstanceId).orderByHistoricActivityInstanceId().asc().list(); - for (HistoricActivityInstance activityInstance : historicActivityInstanceList) { - executedActivityIdList.add(activityInstance.getActivityId()); - } + model.addAttribute("leaveDetail", JSON.toJSONString(leaveList)); + return "/act/leave/leaveDetail"; } - if(StringUtils.isEmpty(processDefinitionId)||executedActivityIdList.isEmpty()){ - return; + @GetMapping("addLeave") + public String addLeave() { + return "/act/leave/add-leave"; } - BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId); - //List activeActivityIds = runtimeService.getActiveActivityIds(processInstanceId); - processEngineConfiguration = processEngine.getProcessEngineConfiguration(); - Context.setProcessEngineConfiguration((ProcessEngineConfigurationImpl) processEngineConfiguration); - ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator(); - //List activeIds = this.runtimeService.getActiveActivityIds(processInstance.getId()); - InputStream imageStream=diagramGenerator.generateDiagram( - bpmnModel, "png", - executedActivityIdList, Collections.emptyList(), - processEngine.getProcessEngineConfiguration().getActivityFontName(), - processEngine.getProcessEngineConfiguration().getLabelFontName(), - "宋体", - null, 1.0); - byte[] b = new byte[1024]; - int len; - while ((len = imageStream.read(b, 0, 1024)) != -1) { - resp.getOutputStream().write(b,0,len); + @GetMapping("updateLeave/{taskId}") + public String updateLeave(Model model, @PathVariable String taskId) { + Map variables = taskService.getVariables(taskId); + UserLeave leave = (UserLeave) variables.get("userLeave"); + leave = leaveService.selectByPrimaryKey(leave.getId()); + model.addAttribute("leave", leave); + model.addAttribute("taskId", taskId); + return "/act/leave/update-leave"; + } + + @PostMapping("updateLeave/updateLeave/{taskId}/{id}/{flag}") + @ResponseBody + public JsonUtil updateLeave(UserLeave leave, @PathVariable String taskId, @PathVariable String id, @PathVariable boolean flag) { + JsonUtil j = new JsonUtil(); + try { + UserLeave oldLeave = leaveService.selectByPrimaryKey(leave.getId()); + BeanUtil.copyNotNullBean(leave, oldLeave); + leaveService.updateByPrimaryKeySelective(oldLeave); + + Map variables = taskService.getVariables(taskId); + UserLeave userLeave = (UserLeave) variables.get("userLeave"); + Map map = new HashMap<>(); + if (flag) { + map.put("flag", true); + } else { + map.put("flag", false); + } + taskService.complete(taskId, map); + j.setMsg("保存成功"); + } catch (MyException e) { + j.setMsg("保存失败"); + j.setFlag(false); + e.printStackTrace(); + } + return j; + } + + + @PostMapping("addLeave") + @ResponseBody + public JsonUtil addLeave(Model model, UserLeave userLeave) { + JsonUtil j = new JsonUtil(); + if (userLeave == null) { + return JsonUtil.error("获取数据失败"); + } + userLeave.setDays(3); + CurrentUser user = CommonUtil.getUser(); + userLeave.setUserId(user.getId()); + userLeave.setUserName(user.getUsername()); + userLeave.setProcessInstanceId("2018");//模拟数据 + + leaveService.insertSelective(userLeave); + Map map = new HashedMap(); + map.put("userLeave", userLeave); + ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("process_leave", map); + userLeave.setProcessInstanceId(processInstance.getId()); + UserLeave userLeave1 = leaveService.selectByPrimaryKey(userLeave.getId()); + BeanUtil.copyNotNullBean(userLeave, userLeave1); + leaveService.updateByPrimaryKeySelective(userLeave1); + if (processInstance == null) { + return JsonUtil.error("未识别key"); + } + j.setMsg("请假申请成功"); + return j; + } + + /** + * ---------我的任务--------- + */ + @GetMapping(value = "showTask") + public String showTask(Model model) { + return "/act/task/taskList"; + } + + @GetMapping(value = "showTaskList") + @ResponseBody + public String showTaskList(Model model, com.len.entity.Task task, String page, String limit) { + CurrentUser user = CommonUtil.getUser(); + List taskList = taskService.createTaskQuery().taskCandidateUser(user.getId()).list(); + List tasks = new ArrayList<>(); + Map map = new HashMap<>(); + com.len.entity.Task taskEntity = null; + + Map> mapMap = new HashMap<>(); + Map objectMap = null; + for (Task task1 : taskList) { + objectMap = new HashMap<>(); + map = taskService.getVariables(task1.getId()); + UserLeave userLeave = (UserLeave) map.get("userLeave"); + + taskEntity = new com.len.entity.Task(task1); + taskEntity.setUserName(userLeave.getUserName()); + taskEntity.setReason(userLeave.getReason()); + /**如果是自己*/ + if (user.getId().equals(userLeave.getUserId()) && !(boolean) map.get("flag")) { + objectMap.put("flag", true); + } else { + objectMap.put("flag", false); + } + mapMap.put(taskEntity.getId(), objectMap); + tasks.add(taskEntity); + } + return ReType.jsonStrng(taskList.size(), tasks, mapMap, "id"); + } + + @GetMapping("agent/{id}") + public String agent(Model model, @PathVariable("id") String taskId) { + Map variables = taskService.getVariables(taskId); + UserLeave userLeave = (UserLeave) variables.get("userLeave"); + userLeave = leaveService.selectByPrimaryKey(userLeave.getId()); + model.addAttribute("leave", userLeave); + model.addAttribute("taskId", taskId); + return "/act/task/task-agent"; + } + + @PostMapping("agent/complete") + @ResponseBody + public JsonUtil complete(LeaveOpinion op, HttpServletRequest request) { + Map variables = taskService.getVariables(op.getTaskId()); + UserLeave userLeave = (UserLeave) variables.get("userLeave"); + CurrentUser user = ShiroUtil.getCurrentUse(); + op.setCreateTime(new Date()); + op.setOpId(user.getId()); + op.setOpName(user.getRealName()); + JsonUtil j = new JsonUtil(); + Map map = new HashMap<>(); + map.put("flag", op.isFlag()); + //审批信息叠加 + List leaveList = new ArrayList<>(); + Object o = variables.get(leaveOpinionList); + if (o != null) { + leaveList = (List) o; + } + leaveList.add(op); + map.put(leaveOpinionList, leaveList); + j.setMsg("审核成功" + (op.isFlag() ? "[通过]" : "[未通过]")); + taskService.complete(op.getTaskId(), map); + return j; + } + + @Autowired + HistoryService historyService; + + /** + * 追踪图片成图 + * + * @param request + * @param resp + * @param processInstanceId + * @throws IOException + */ + @GetMapping("getProcImage") + public void getProcImage(HttpServletRequest request, HttpServletResponse resp, String processInstanceId) + throws IOException { + ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); + HistoricProcessInstance historicProcessInstance = + historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); + String processDefinitionId = null; + List executedActivityIdList = new ArrayList(); + if (processInstance != null) { + processDefinitionId = processInstance.getProcessDefinitionId(); + executedActivityIdList = this.runtimeService.getActiveActivityIds(processInstance.getId()); + } else if (historicProcessInstance != null) { + processDefinitionId = historicProcessInstance.getProcessDefinitionId(); + List historicActivityInstanceList = + historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstanceId).orderByHistoricActivityInstanceId().asc().list(); + for (HistoricActivityInstance activityInstance : historicActivityInstanceList) { + executedActivityIdList.add(activityInstance.getActivityId()); + } + } + + if (StringUtils.isEmpty(processDefinitionId) || executedActivityIdList.isEmpty()) { + return; + } + BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId); + //List activeActivityIds = runtimeService.getActiveActivityIds(processInstanceId); + processEngineConfiguration = processEngine.getProcessEngineConfiguration(); + Context.setProcessEngineConfiguration((ProcessEngineConfigurationImpl) processEngineConfiguration); + ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator(); + //List activeIds = this.runtimeService.getActiveActivityIds(processInstance.getId()); + + InputStream imageStream = diagramGenerator.generateDiagram( + bpmnModel, "png", + executedActivityIdList, Collections.emptyList(), + processEngine.getProcessEngineConfiguration().getActivityFontName(), + processEngine.getProcessEngineConfiguration().getLabelFontName(), + "宋体", + null, 1.0); + byte[] b = new byte[1024]; + int len; + while ((len = imageStream.read(b, 0, 1024)) != -1) { + resp.getOutputStream().write(b, 0, len); + } } - } }