|
|
@ -15,19 +15,14 @@ import cn.jyjz.xiaoyao.common.base.util.RequestBaseUtil;
|
|
|
|
import cn.jyjz.xiaoyao.common.base.util.SpringUtils;
|
|
|
|
import cn.jyjz.xiaoyao.common.base.util.SpringUtils;
|
|
|
|
import cn.jyjz.xiaoyao.common.base.util.StringUtils;
|
|
|
|
import cn.jyjz.xiaoyao.common.base.util.StringUtils;
|
|
|
|
import cn.jyjz.xiaoyao.common.base.vo.UserToken;
|
|
|
|
import cn.jyjz.xiaoyao.common.base.vo.UserToken;
|
|
|
|
import cn.jyjz.xiaoyao.framework.security.model.AdminUserModel;
|
|
|
|
|
|
|
|
import cn.jyjz.xiaoyao.framework.security.service.FlowableUserLoginService;
|
|
|
|
|
|
|
|
import cn.jyjz.xiaoyao.oa.from.service.UserViewapproeService;
|
|
|
|
import cn.jyjz.xiaoyao.oa.from.service.UserViewapproeService;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.flowable.bpmn.model.*;
|
|
|
|
|
|
|
|
import org.flowable.engine.RepositoryService;
|
|
|
|
import org.flowable.engine.RepositoryService;
|
|
|
|
import org.flowable.engine.impl.bpmn.behavior.ParallelMultiInstanceBehavior;
|
|
|
|
|
|
|
|
import org.flowable.engine.repository.ProcessDefinition;
|
|
|
|
import org.flowable.engine.repository.ProcessDefinition;
|
|
|
|
import org.flowable.engine.runtime.ProcessInstance;
|
|
|
|
import org.flowable.engine.runtime.ProcessInstance;
|
|
|
|
import org.flowable.task.api.Task;
|
|
|
|
import org.flowable.task.api.Task;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
@ -48,148 +43,154 @@ public class FlowInstanceServiceImpl extends FlowServiceFactory implements IFlow
|
|
|
|
private IFlowTaskService flowTaskService;
|
|
|
|
private IFlowTaskService flowTaskService;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private UserViewapproeService userViewApproeService;
|
|
|
|
private UserViewapproeService userViewApproeService;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean startProcessInstanceById(String procDefId, Map<String, Object> variables, HttpServletRequest request,String formid,String servicename) {
|
|
|
|
public boolean startProcessInstanceById(String procDefId, Map<String, Object> variables, HttpServletRequest request, String formid, String servicename) {
|
|
|
|
|
|
|
|
|
|
|
|
IFormCustomService iFormCustomService = null;
|
|
|
|
IFormCustomService iFormCustomService = null;
|
|
|
|
if(StringUtils.isNotBlank(servicename)){
|
|
|
|
if (StringUtils.isNotBlank(servicename)) {
|
|
|
|
iFormCustomService = SpringUtils.getBean(servicename);
|
|
|
|
iFormCustomService = SpringUtils.getBean(servicename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(StringUtils.isBlank(formid) ){
|
|
|
|
if (StringUtils.isBlank(formid)) {
|
|
|
|
//表单主键
|
|
|
|
//表单主键
|
|
|
|
formid = iFormCustomService.saveForm(request);
|
|
|
|
formid = iFormCustomService.saveForm(request);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String token = RequestBaseUtil.getToken(request);
|
|
|
|
UserToken userToken = this.userTokenService.getUserToken(RequestBaseUtil.getToken(request));
|
|
|
|
String userName = "";
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(token)) {
|
|
|
|
|
|
|
|
userName = "admin";
|
|
|
|
String userName = userToken.getLoginname();
|
|
|
|
} else {
|
|
|
|
|
|
|
|
UserToken userToken = this.userTokenService.getUserToken(token);
|
|
|
|
|
|
|
|
userName = userToken.getLoginname();
|
|
|
|
|
|
|
|
}
|
|
|
|
// 绑定当前认证的账号 我们的认证系统如果使用的是 SpringSecurity的话,默认就会设置当前登录的账号
|
|
|
|
// 绑定当前认证的账号 我们的认证系统如果使用的是 SpringSecurity的话,默认就会设置当前登录的账号
|
|
|
|
//identityService.setAuthenticatedUserId(userName);
|
|
|
|
//identityService.setAuthenticatedUserId(userName);
|
|
|
|
if(null == variables){
|
|
|
|
if (null == variables) {
|
|
|
|
variables = new HashMap<>();
|
|
|
|
variables = new HashMap<>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
variables.put("loginUser",userName);
|
|
|
|
variables.put("loginUser", userName);
|
|
|
|
//根据流程定义信息
|
|
|
|
//根据流程定义信息
|
|
|
|
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(procDefId).singleResult();
|
|
|
|
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(procDefId).singleResult();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//业务key 用于待办已办 扩展字段 展示使用
|
|
|
|
//业务key 用于待办已办 扩展字段 展示使用
|
|
|
|
//我这里以 流程定义key(oa_category_t定义的关键字,逻辑唯一) + 业务表主键(请假表、调岗表等) + 业务表对应的servicename
|
|
|
|
//我这里以 流程定义key(oa_category_t定义的关键字,逻辑唯一) + 业务表主键(请假表、调岗表等) + 业务表对应的servicename
|
|
|
|
String businessKey= userToken.getLoginname() + SystemConstantsOa.OA_BUSSINESS_KEY_SPLIT+ formid + SystemConstantsOa.OA_BUSSINESS_KEY_SPLIT+ servicename;
|
|
|
|
String businessKey = userName + SystemConstantsOa.OA_BUSSINESS_KEY_SPLIT + formid + SystemConstantsOa.OA_BUSSINESS_KEY_SPLIT + servicename;
|
|
|
|
|
|
|
|
|
|
|
|
ProcessInstance processInstance = null;
|
|
|
|
ProcessInstance processInstance = null;
|
|
|
|
|
|
|
|
|
|
|
|
//启动了一个流程实例
|
|
|
|
//启动了一个流程实例
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
|
variables.put("businessKey",businessKey);
|
|
|
|
variables.put("businessKey", businessKey);
|
|
|
|
processInstance = runtimeService.startProcessInstanceById(procDefId,businessKey,variables) ;
|
|
|
|
processInstance = runtimeService.startProcessInstanceById(procDefId, businessKey, variables);
|
|
|
|
|
|
|
|
|
|
|
|
if(null != iFormCustomService){
|
|
|
|
if (null != iFormCustomService) {
|
|
|
|
FlowTaskCompleteVO flowTaskCompleteVO = flowTaskService.updateNowTaskAssignee(processInstance.getProcessInstanceId(),processInstance.getProcessDefinitionId());
|
|
|
|
FlowTaskCompleteVO flowTaskCompleteVO = flowTaskService.updateNowTaskAssignee(processInstance.getProcessInstanceId(), processInstance.getProcessDefinitionId());
|
|
|
|
|
|
|
|
|
|
|
|
if(null == flowTaskCompleteVO){
|
|
|
|
if (null == flowTaskCompleteVO) {
|
|
|
|
throw new ServiceException("没有审批人,请联系管理员,流程定义:" + businessKey);
|
|
|
|
throw new ServiceException("没有审批人,请联系管理员,流程定义:" + businessKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<Task> list = this.flowTaskService.nowRunTask(processInstance.getProcessInstanceId(),processInstance.getProcessDefinitionId());
|
|
|
|
List<Task> list = this.flowTaskService.nowRunTask(processInstance.getProcessInstanceId(), processInstance.getProcessDefinitionId());
|
|
|
|
String taskname = "";
|
|
|
|
String taskname = "";
|
|
|
|
if(null != list && !list.isEmpty()){
|
|
|
|
if (null != list && !list.isEmpty()) {
|
|
|
|
taskname = list.get(0).getName();
|
|
|
|
taskname = list.get(0).getName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//保存instanceId到数据库,需要根据流程分类进行,判断更新
|
|
|
|
//保存instanceId到数据库,需要根据流程分类进行,判断更新
|
|
|
|
boolean isupdate = iFormCustomService.updateForm(formid,processDefinition.getDeploymentId(),processDefinition.getId(),flowTaskCompleteVO.getAssignee(),flowTaskCompleteVO.getTaskId(),processInstance.getProcessInstanceId(),taskname);
|
|
|
|
boolean isupdate = iFormCustomService.updateForm(formid, processDefinition.getDeploymentId(), processDefinition.getId(), flowTaskCompleteVO.getAssignee(), flowTaskCompleteVO.getTaskId(), processInstance.getProcessInstanceId(), taskname);
|
|
|
|
if(isupdate){
|
|
|
|
if (isupdate) {
|
|
|
|
FlowModelVO flowModelVO = iFormCustomService.getForm(formid);
|
|
|
|
FlowModelVO flowModelVO = iFormCustomService.getForm(formid);
|
|
|
|
//增加未查看记录
|
|
|
|
//增加未查看记录
|
|
|
|
userViewApproeService.saveUserViewApproe(flowTaskCompleteVO.getAssignee(),formid,flowModelVO.getTenantid().toString());
|
|
|
|
userViewApproeService.saveUserViewApproe(flowTaskCompleteVO.getAssignee(), formid, flowModelVO.getTenantid().toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
log.info("流程启动成功:procDefId:{}",procDefId);
|
|
|
|
log.info("流程启动成功:procDefId:{}", procDefId);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}catch (Exception e){
|
|
|
|
} catch (Exception e) {
|
|
|
|
log.error("流程启动失败:procDefId:{}",procDefId);
|
|
|
|
log.error("流程启动失败:procDefId:{}", procDefId);
|
|
|
|
log.error("流程启动失败:e:{}",e);
|
|
|
|
log.error("流程启动失败:e:{}", e);
|
|
|
|
|
|
|
|
|
|
|
|
//删除流程
|
|
|
|
//删除流程
|
|
|
|
if(null != processInstance){
|
|
|
|
if (null != processInstance) {
|
|
|
|
runtimeService.deleteProcessInstance(processInstance.getProcessInstanceId(), SystemMessage.SYS_OA_START_ERROR);
|
|
|
|
runtimeService.deleteProcessInstance(processInstance.getProcessInstanceId(), SystemMessage.SYS_OA_START_ERROR);
|
|
|
|
historyService.deleteHistoricProcessInstance(processInstance.getProcessInstanceId());
|
|
|
|
historyService.deleteHistoricProcessInstance(processInstance.getProcessInstanceId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(StringUtils.isNotBlank(servicename) && StringUtils.isNotBlank(formid)){
|
|
|
|
if (StringUtils.isNotBlank(servicename) && StringUtils.isNotBlank(formid)) {
|
|
|
|
iFormCustomService.delForm(formid);
|
|
|
|
iFormCustomService.delForm(formid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}finally {
|
|
|
|
|
|
|
|
RequestContextHolder.resetRequestAttributes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean startProcessInstanceById(String procDefId, String userName,String createuser, String formid,String servicename) {
|
|
|
|
public boolean startProcessInstanceById(String procDefId, String userName, String createuser, String formid, String servicename) {
|
|
|
|
|
|
|
|
|
|
|
|
IFormCustomService iFormCustomService = null;
|
|
|
|
IFormCustomService iFormCustomService = null;
|
|
|
|
if(StringUtils.isNotBlank(servicename)){
|
|
|
|
if (StringUtils.isNotBlank(servicename)) {
|
|
|
|
iFormCustomService = SpringUtils.getBean(servicename);
|
|
|
|
iFormCustomService = SpringUtils.getBean(servicename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(StringUtils.isBlank(formid) ){
|
|
|
|
if (StringUtils.isBlank(formid)) {
|
|
|
|
//表单主键
|
|
|
|
//表单主键
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> variables = new HashMap<>();
|
|
|
|
Map<String, Object> variables = new HashMap<>();
|
|
|
|
variables.put("loginUser",userName);
|
|
|
|
variables.put("loginUser", userName);
|
|
|
|
//根据流程定义信息
|
|
|
|
//根据流程定义信息
|
|
|
|
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(procDefId).singleResult();
|
|
|
|
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(procDefId).singleResult();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//业务key 用于待办已办 扩展字段 展示使用
|
|
|
|
//业务key 用于待办已办 扩展字段 展示使用
|
|
|
|
//我这里以 流程定义key(oa_category_t定义的关键字,逻辑唯一) + 业务表主键(请假表、调岗表等) + 业务表对应的servicename
|
|
|
|
//我这里以 流程定义key(oa_category_t定义的关键字,逻辑唯一) + 业务表主键(请假表、调岗表等) + 业务表对应的servicename
|
|
|
|
String businessKey= createuser + SystemConstantsOa.OA_BUSSINESS_KEY_SPLIT+ formid + SystemConstantsOa.OA_BUSSINESS_KEY_SPLIT+ servicename;
|
|
|
|
String businessKey = createuser + SystemConstantsOa.OA_BUSSINESS_KEY_SPLIT + formid + SystemConstantsOa.OA_BUSSINESS_KEY_SPLIT + servicename;
|
|
|
|
|
|
|
|
|
|
|
|
ProcessInstance processInstance = null;
|
|
|
|
ProcessInstance processInstance = null;
|
|
|
|
|
|
|
|
|
|
|
|
//启动了一个流程实例
|
|
|
|
//启动了一个流程实例
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
|
variables.put("businessKey",businessKey);
|
|
|
|
variables.put("businessKey", businessKey);
|
|
|
|
processInstance = runtimeService.startProcessInstanceById(procDefId,businessKey,variables) ;
|
|
|
|
processInstance = runtimeService.startProcessInstanceById(procDefId, businessKey, variables);
|
|
|
|
|
|
|
|
|
|
|
|
if(null != iFormCustomService){
|
|
|
|
if (null != iFormCustomService) {
|
|
|
|
FlowTaskCompleteVO flowTaskCompleteVO = flowTaskService.updateNowTaskAssignee(processInstance.getProcessInstanceId(),processInstance.getProcessDefinitionId());
|
|
|
|
FlowTaskCompleteVO flowTaskCompleteVO = flowTaskService.updateNowTaskAssignee(processInstance.getProcessInstanceId(), processInstance.getProcessDefinitionId());
|
|
|
|
|
|
|
|
|
|
|
|
if(null == flowTaskCompleteVO){
|
|
|
|
if (null == flowTaskCompleteVO) {
|
|
|
|
throw new ServiceException("没有审批人,请联系管理员,流程定义:" + businessKey);
|
|
|
|
throw new ServiceException("没有审批人,请联系管理员,流程定义:" + businessKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<Task> list = this.flowTaskService.nowRunTask(processInstance.getProcessInstanceId(),processInstance.getProcessDefinitionId());
|
|
|
|
List<Task> list = this.flowTaskService.nowRunTask(processInstance.getProcessInstanceId(), processInstance.getProcessDefinitionId());
|
|
|
|
String taskname = "";
|
|
|
|
String taskname = "";
|
|
|
|
if(null != list && !list.isEmpty()){
|
|
|
|
if (null != list && !list.isEmpty()) {
|
|
|
|
taskname = list.get(0).getName();
|
|
|
|
taskname = list.get(0).getName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//保存instanceId到数据库,需要根据流程分类进行,判断更新
|
|
|
|
//保存instanceId到数据库,需要根据流程分类进行,判断更新
|
|
|
|
boolean isupdate = iFormCustomService.updateForm(formid,processDefinition.getDeploymentId(),processDefinition.getId(),flowTaskCompleteVO.getAssignee(),flowTaskCompleteVO.getTaskId(),processInstance.getProcessInstanceId(),taskname);
|
|
|
|
boolean isupdate = iFormCustomService.updateForm(formid, processDefinition.getDeploymentId(), processDefinition.getId(), flowTaskCompleteVO.getAssignee(), flowTaskCompleteVO.getTaskId(), processInstance.getProcessInstanceId(), taskname);
|
|
|
|
if(isupdate){
|
|
|
|
if (isupdate) {
|
|
|
|
FlowModelVO flowModelVO = iFormCustomService.getForm(formid);
|
|
|
|
FlowModelVO flowModelVO = iFormCustomService.getForm(formid);
|
|
|
|
//增加未查看记录
|
|
|
|
//增加未查看记录
|
|
|
|
userViewApproeService.saveUserViewApproe(flowTaskCompleteVO.getAssignee(),formid,flowModelVO.getTenantid().toString());
|
|
|
|
userViewApproeService.saveUserViewApproe(flowTaskCompleteVO.getAssignee(), formid, flowModelVO.getTenantid().toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
log.info("流程启动成功:procDefId:{}",procDefId);
|
|
|
|
log.info("流程启动成功:procDefId:{}", procDefId);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}catch (Exception e){
|
|
|
|
} catch (Exception e) {
|
|
|
|
log.error("流程启动失败:procDefId:{}",procDefId);
|
|
|
|
log.error("流程启动失败:procDefId:{}", procDefId);
|
|
|
|
log.error("流程启动失败:e:{}",e);
|
|
|
|
log.error("流程启动失败:e:{}", e);
|
|
|
|
|
|
|
|
|
|
|
|
//删除流程
|
|
|
|
//删除流程
|
|
|
|
if(null != processInstance){
|
|
|
|
if (null != processInstance) {
|
|
|
|
runtimeService.deleteProcessInstance(processInstance.getProcessInstanceId(), SystemMessage.SYS_OA_START_ERROR);
|
|
|
|
runtimeService.deleteProcessInstance(processInstance.getProcessInstanceId(), SystemMessage.SYS_OA_START_ERROR);
|
|
|
|
historyService.deleteHistoricProcessInstance(processInstance.getProcessInstanceId());
|
|
|
|
historyService.deleteHistoricProcessInstance(processInstance.getProcessInstanceId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(StringUtils.isNotBlank(servicename) && StringUtils.isNotBlank(formid)){
|
|
|
|
if (StringUtils.isNotBlank(servicename) && StringUtils.isNotBlank(formid)) {
|
|
|
|
iFormCustomService.delForm(formid);
|
|
|
|
iFormCustomService.delForm(formid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|