1.指定到人
@Override @Transactional(rollbackFor = Exception.class) // @GlobalTransactional public boolean startProcess(ProcessPurchaseOrder bean) { //是否启动流程 boolean isStartProcess = false; //是否新增数据 boolean isAdd = false; if (bean != null) { if (Func.isEmpty(bean.getProcessInstanceId())) { isStartProcess = true; } if (Func.isEmpty(bean.getId())) { isAdd = true; } //更新业务数据 if (isAdd) { Date now = new Date(); SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); String dateStr = format.format(now); if(Func.isNull(bean.getOrderNumber())){ bean.setOrderNumber(oaSerialService.getSerial(bean.getTenantId(),"purchaseOrder",dateStr,dateStr,5)); } //第一次发起 保存数据到采购订单表和订单详情表 save(bean); //采购订单明细进入明细表 saveDetail(bean.getPurchaseOrderDetail(), bean.getOrderNumber()); } else { updateById(bean); //从新发起修改采购订单详细表1.先删除以前的数据,2.从新插入新的订单详情 deleteOrderDetail(bean.getOrderNumber()); saveDetail(bean.getPurchaseOrderDetail(), bean.getOrderNumber()); } //更新附件信息 oaAttachmentService.saveOrUpdateOaAttachment(bean.getAttachments(),bean.getId(),bean.getProcessInstanceId(),bean.getTenantId(),"purchaseOrder"); } //除了茶叶 原物料 都走主管 经理审批 bean.setChanges("01"); System.out.println("urchaseType=================="+bean.getPurchaseType()); //茶叶 原物料 价格没有变动 只走主管审批 if(bean.getPurchaseType().equals("茶叶") || bean.getPurchaseType().equals("原物料")){ if (null != bean.getPurchaseOrderDetail() && bean.getPurchaseOrderDetail().size() > 0) { for (ProcessPurchaseOrderDetail processPurchaseOrderDetail : bean.getPurchaseOrderDetail()) { System.out.println("processPurchaseOrderDetail.getPriceChange()====" + processPurchaseOrderDetail.getPriceChange()); if (processPurchaseOrderDetail.getPriceChange().equals("1")) {//01价格有变动 02没有变动 bean.setChanges("01"); break; }else{ bean.setChanges("02"); } } } } //获取发起人部门id Long curDeptId = DeskUtil.getCurDeptId(bean.getCreateDept()); //获取经理职位 Long managerUser=null; String roleId=deptUserUtil.getRoleId(AuthUtil.getTenantId(), "经理"); List<User>users=deptUserUtil.getUserListByRoleIdAndDeptId(roleId,String.valueOf(curDeptId),false); if(!Func.isEmpty(users)){ managerUser=users.get(0).getId(); } log.info("获取经理职位roleId====="+roleId+"------users========================"+users); //获取部门总监 String majorRoleId=deptUserUtil.getRoleId(AuthUtil.getTenantId(), "总监"); List<User>majordomoUsers=deptUserUtil.getUserListByRoleIdAndDeptId(majorRoleId,String.valueOf(curDeptId),true); Long generalManager=null; if(null!=majordomoUsers && majordomoUsers.size()>0){ generalManager =majordomoUsers.get(0).getId(); } log.info("获取总监majorRoleId===="+majorRoleId+"-----majordomoUsers========================"+majordomoUsers); //获取总经理 String companyBossPostId=deptUserUtil.getPostId("总经理",bean.getTenantId()); List<User>companyBossUsers=deptUserUtil.getUserListByPostId(companyBossPostId);//总经理不属于某个部门,不用根据部门id查询 Long companyBoss=null; if(null!=companyBossUsers && companyBossUsers.size()>0){ companyBoss=companyBossUsers.get(0).getId(); } log.info("获取总经理companyBossPostId====="+companyBossPostId+"-------companyBossUsers========================"+companyBossUsers); //上级主管 roleId = deptUserUtil.getRoleId(AuthUtil.getTenantId(),"主管"); boolean isManager = Func.isNotEmpty(AuthUtil.getUserRole())&&AuthUtil.getUserRole().contains("主管")?true:false; Long lastManagerUserId = null; if(isManager){ users = deptUserUtil.getUserListByRoleIdAndDeptId(roleId,String.valueOf(curDeptId),true,AuthUtil.getUserId()); lastManagerUserId = Func.isEmpty(users)?null:users.get(0).getId(); } /** * 判断条件 */ //如果发起人是总监或者经理不是部门最高领导 没有的职位跳过经理职位 if(null!=managerUser){ if(AuthUtil.getUser().getUserId().longValue()==managerUser.longValue()){ managerUser=null;//经理 } } //跳过总监 if(null!=generalManager){ //跳过总监 if(AuthUtil.getUser().getUserId().longValue()==generalManager.longValue()){ //跳过经理 managerUser=null;//经理 //跳过总监职位 generalManager=null; } } Kv variables =DeskUtil.createKV(curDeptId,"采购订单",bean.getOrderNumber(),bean.getApplicantName(),isManager,bean.getCcUser(),bean.getCcUserName()) .set("taskUser", TaskUtil.getTaskUser(AuthUtil.getUser().getUserId().toString())) .set("category", bean.getCategory())//申请类型 .set("changes", bean.getChanges())//价格是否变动 .set("managerSkip", Func.isEmpty(managerUser)) .set("managerUser",TaskUtil.getTaskUser(String.valueOf(managerUser==null ? "" : managerUser)))//经理 .set("generalManagerSkip", Func.isEmpty(generalManager)) .set("generalManager",TaskUtil.getTaskUser(String.valueOf(generalManager==null ? "" : generalManager)))//总监 .set("companyBossSkip",Func.isEmpty(companyBoss)) .set("companyBossUser", TaskUtil.getTaskUser(String.valueOf(companyBoss==null ? "" : companyBoss)))//总经理 .set("lastManagerSkip",Func.isEmpty(lastManagerUserId)) .set("lastManagerUser",TaskUtil.getTaskUser(String.valueOf(lastManagerUserId))); //开启流程 if (isStartProcess) { String businessTable = FlowUtil.getBusinessTable(ProcessConstant.PURCHASE_ORDER_KEY);//获取表名 R<BladeFlow> result = flowClient.startProcessInstanceById(bean.getProcessDefinitionId(), FlowUtil.getBusinessKey(businessTable, String.valueOf(bean.getId())), variables); if (result.isSuccess()) { log.debug("流程已启动,流程ID:" + result.getData().getProcessInstanceId()); // 返回流程id写入leave bean.setProcessInstanceId(result.getData().getProcessInstanceId()); updateById(bean); } else { throw new ServiceException("开启流程失败"); } } else { //开启流程 TaskId ProcessInstanceId if(!Func.isEmpty(bean.getFlow())&&!Func.isEmpty(bean.getFlow().getTaskId())&&!Func.isEmpty(bean.getProcessInstanceId())){ variables.put(ProcessConstant.PASS_KEY, true); flowClient.completeTask(bean.getFlow().getTaskId(),bean.getProcessInstanceId(),bean.getFlow().getComment(),variables); } } return true; }
//2.指定到角色
/* * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the dreamlu.net developer nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: Chill 庄骞 (smallchill@163.com) */ package org.springblade.desk.management.service.impl; import com.alibaba.fastjson.JSONObject; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.api.R; import org.springblade.core.tool.support.Kv; import org.springblade.core.tool.utils.Func; import org.springblade.desk.management.constant.AuthorityConstant; import org.springblade.desk.management.entity.OaAuthorityManagement; import org.springblade.desk.management.mapper.OaAuthorityManagementMapper; import org.springblade.desk.management.service.IOaAuthorityManagementService; import org.springblade.desk.service.impl.AdjustPriceDetailServiceImpl; import org.springblade.desk.service.impl.OaSerialServiceImpl; import org.springblade.desk.utils.DeptUserUtil; import org.springblade.desk.utils.DeskUtil; import org.springblade.flow.core.constant.ProcessConstant; import org.springblade.flow.core.entity.BladeFlow; import org.springblade.flow.core.feign.IFlowClient; import org.springblade.flow.core.utils.FlowUtil; import org.springblade.flow.core.utils.TaskUtil; import org.springblade.system.user.entity.User; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; /** * 权限申请单 * * @author pei */ @Slf4j @Service @AllArgsConstructor public class OaAuthorityManagementServiceImpl extends BaseServiceImpl<OaAuthorityManagementMapper, OaAuthorityManagement> implements IOaAuthorityManagementService { private IFlowClient flowClient; private OaSerialServiceImpl oaSerialService; private AdjustPriceDetailServiceImpl adjustPriceDetailServiceImpl; private DeptUserUtil deptUserUtil; @Override @Transactional(rollbackFor = Exception.class) public boolean startProcess(OaAuthorityManagement bean) { log.info("权限申请单开启流程bean============="+bean); //是否启动流程 boolean isStartProcess = false; //是否新增数据 boolean isAdd = false; if(bean!=null){ if(Func.isEmpty(bean.getProcessInstanceId())){ isStartProcess = true; } if(Func.isEmpty(bean.getId())){ isAdd = true; bean.setTenantId(AuthUtil.getTenantId()); } //更新业务数据 if(isAdd){ Date now = new Date(); SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); String dateStr = format.format(now); if(Func.isEmpty(bean.getAuthorityManagementNumber())){ bean.setAuthorityManagementNumber(oaSerialService.getSerial(AuthUtil.getTenantId(),"OaAuthorityManagement",dateStr,dateStr,5)); } } if(Func.isNotEmpty(bean.getObjIfo())){ //将系统权限数据转换成string保存入库 String str= JSONObject.toJSONString(bean.getObjIfo()); bean.setApplicationSystemValue(str); } saveOrUpdate(bean); } Long curDeptId = DeskUtil.getCurDeptId(bean.getCreateDept()); //获取主管 Long managerUser=null; String roleId=deptUserUtil.getRoleId(AuthUtil.getTenantId(), "主管"); List<User> users=deptUserUtil.getUserListByRoleIdAndDeptId(roleId,String.valueOf(curDeptId),false,AuthUtil.getUserId()); if(!Func.isEmpty(users)){ managerUser=users.get(0).getId(); } log.info("获取主管职位roleId====="+roleId+"------users========================"+users); //获取it部门审批人 //1.根据部门名称获取部门id IT部 String deptId= deptUserUtil.getDeptId(AuthUtil.getTenantId(),AuthorityConstant.IT_DEPT_NAME); String itRoleId=deptUserUtil.getRoleId(AuthUtil.getTenantId(), AuthorityConstant.IT_ROLE_NAME); List<User>itRoleUsers=deptUserUtil.getUserListByRoleIdAndDeptId(itRoleId,String.valueOf(deptId)); log.info("获取it部门审批人itRoleUsers================="+itRoleUsers); Long itRoleManager=null; if(null!=itRoleUsers && itRoleUsers.size()>0){ itRoleManager =itRoleUsers.get(0).getId(); } boolean isManager = Func.isNotEmpty(AuthUtil.getUserRole())&&AuthUtil.getUserRole().contains("主管")?true:false; // 启动流程 Kv variables =DeskUtil.createKV(curDeptId,"权限申请单",bean.getAuthorityManagementNumber(),bean.getApplicationSystem()+","+bean.getRemark(),isManager,bean.getCcUser(),bean.getCcUserName()) .set("taskUser", TaskUtil.getTaskUser(AuthUtil.getUser().getUserId().toString())) .set("managerSkip", Func.isEmpty(managerUser)) .set("managerUser",TaskUtil.getTaskUser(String.valueOf(managerUser==null ? "" : managerUser)))//主管 .set("itRoleManager",AuthorityConstant.IT_ROLE_NAME);//IT审批人(角色名称) //启动流程 isStartProcess if (isStartProcess) {//先不开启流程 String businessTable = FlowUtil.getBusinessTable(ProcessConstant.OA_AUTHORITY_MANAGEMENT); R<BladeFlow> result = flowClient.startProcessInstanceById(bean.getProcessDefinitionId(), FlowUtil.getBusinessKey(businessTable, String.valueOf(bean.getId())), variables); if (result.isSuccess()) { log.debug("流程已启动,流程ID:" + result.getData().getProcessInstanceId()); // 返回流程id写入业务表中 bean.setProcessInstanceId(result.getData().getProcessInstanceId()); updateById(bean); } else { throw new ServiceException("开启流程失败"); } } else{ if(!Func.isEmpty(bean.getFlow())&&!Func.isEmpty(bean.getFlow().getTaskId())&&!Func.isEmpty(bean.getProcessInstanceId())){ variables.put(ProcessConstant.PASS_KEY, true); flowClient.completeTask(bean.getFlow().getTaskId(),bean.getProcessInstanceId(),bean.getFlow().getComment(),variables); } } return true; } }
package org.springblade.desk.management.constant; /** * 2021-01-08 */ public interface AuthorityConstant { /** * 部门名称 */ String IT_DEPT_NAME="IT部"; /** * IT部门角色 */ String IT_ROLE_NAME="IT系统权限"; }