|
|
@ -1,9 +1,12 @@ |
|
|
|
package com.easy.admin.modules.huzhou.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateUnit; |
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import cn.hutool.json.JSONObject; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.easy.admin.activiti.constant.ActivitiTaskStatusConst; |
|
|
|
import com.easy.admin.activiti.constant.status.ActivitiSuspensionStatus; |
|
|
@ -13,7 +16,10 @@ import com.easy.admin.activiti.model.ActivitiTask; |
|
|
|
import com.easy.admin.activiti.service.ActivitiModelService; |
|
|
|
import com.easy.admin.activiti.service.ActivitiProcessDefinitionService; |
|
|
|
import com.easy.admin.activiti.service.ActivitiTaskService; |
|
|
|
import com.easy.admin.auth.dao.SysUserRoleMapper; |
|
|
|
import com.easy.admin.auth.model.SysUser; |
|
|
|
import com.easy.admin.auth.model.SysUserRole; |
|
|
|
import com.easy.admin.auth.service.SysUserService; |
|
|
|
import com.easy.admin.common.api.vo.Result; |
|
|
|
|
|
|
|
import com.easy.admin.common.core.common.pagination.Page; |
|
|
@ -21,15 +27,12 @@ import com.easy.admin.common.core.common.select.Select; |
|
|
|
import com.easy.admin.common.core.util.ToolUtil; |
|
|
|
import com.easy.admin.modules.huzhou.dao.HuzhouProcessinfoMapper; |
|
|
|
import com.easy.admin.modules.huzhou.dao.WorkflowMapper; |
|
|
|
import com.easy.admin.modules.huzhou.entity.HuzhouProcessinfo; |
|
|
|
import com.easy.admin.modules.huzhou.entity.*; |
|
|
|
|
|
|
|
import com.easy.admin.modules.huzhou.entity.HuzhouProjectinfo; |
|
|
|
import com.easy.admin.modules.huzhou.service.IHuzhouProcessinfoService; |
|
|
|
import com.easy.admin.modules.huzhou.vo.WorkflowActionParamOV; |
|
|
|
import com.easy.admin.util.ShiroUtil; |
|
|
|
|
|
|
|
import com.easy.admin.modules.huzhou.entity.WorkFlow; |
|
|
|
import com.easy.admin.modules.huzhou.entity.WorkflowBaseInfo; |
|
|
|
import com.easy.admin.modules.huzhou.service.IWorkflowService; |
|
|
|
import org.activiti.bpmn.model.*; |
|
|
|
import org.activiti.engine.HistoryService; |
|
|
@ -39,6 +42,7 @@ import org.activiti.engine.TaskService; |
|
|
|
import org.activiti.engine.history.HistoricActivityInstance; |
|
|
|
import org.activiti.engine.history.HistoricTaskInstance; |
|
|
|
import org.activiti.engine.history.HistoricTaskInstanceQuery; |
|
|
|
import org.activiti.engine.history.HistoricVariableInstance; |
|
|
|
import org.activiti.engine.impl.identity.Authentication; |
|
|
|
import org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity; |
|
|
|
import org.activiti.engine.impl.pvm.PvmTransition; |
|
|
@ -57,6 +61,8 @@ import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
import java.util.regex.Matcher; |
|
|
|
import java.util.regex.Pattern; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
@Service |
|
|
@ -80,11 +86,14 @@ public class WorkflowServiceImpl implements IWorkflowService { |
|
|
|
@Autowired |
|
|
|
private WorkflowMapper workflowMapper; |
|
|
|
@Autowired |
|
|
|
|
|
|
|
private IHuzhouProcessinfoService processinfoService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ActivitiTaskMapper activitiTaskMapper; |
|
|
|
@Autowired |
|
|
|
private SysUserService sysUserService; |
|
|
|
@Autowired |
|
|
|
private SysUserRoleMapper userRoleMapper; |
|
|
|
public WorkFlow createFlow(String processDefinitionKey,String id){ |
|
|
|
String definitionId = activitiModelService.selectProcessDefinitionId(processDefinitionKey); |
|
|
|
ActivitiProcessDefinitionVO activitiProcessDefinitionVO = new ActivitiProcessDefinitionVO(); |
|
|
@ -215,10 +224,20 @@ public class WorkflowServiceImpl implements IWorkflowService { |
|
|
|
// outRes.put("showApprovalForm",true);
|
|
|
|
workflowActionParamOV.setShowApprovalForm(true); |
|
|
|
} |
|
|
|
if(filteredList.size()==0&&taskInstance.getProcessDefinitionId().contains("createURT")){ |
|
|
|
if(taskInstance.getName().equals("发起人")){ |
|
|
|
Select select = new Select(); |
|
|
|
select.setLabel("撤回"); |
|
|
|
select.setValue("2"); |
|
|
|
actionButtons.add(select); |
|
|
|
workflowActionParamOV.setButtons(actionButtons); |
|
|
|
workflowActionParamOV.setShowApprovalForm(true); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}else{ |
|
|
|
//代办 发起人可以作废,还要可以修改,加一个修改表示(前端也行)
|
|
|
|
workflowActionParamOV.setButtons(actionButtons); |
|
|
@ -428,4 +447,271 @@ public class WorkflowServiceImpl implements IWorkflowService { |
|
|
|
return page; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<HashMap<String, Object>> getprocessInfo(String processInstanceId, String projectid, String stage) { |
|
|
|
//通过项目id查询流程id
|
|
|
|
List<String> currentTaskName=new ArrayList<>(); |
|
|
|
if(projectid!=null){ |
|
|
|
LambdaQueryWrapper<HuzhouProcessinfo> queryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
queryWrapper.eq(HuzhouProcessinfo::getProjectid,projectid); |
|
|
|
queryWrapper.eq(HuzhouProcessinfo::getProcessName,stage); |
|
|
|
queryWrapper.orderByDesc(BaseEntity::getCreateDate); |
|
|
|
|
|
|
|
HuzhouProcessinfo huzhouProcessinfo = processinfoService.list(queryWrapper).get(0); |
|
|
|
processInstanceId=huzhouProcessinfo.getProcessinstanceid(); |
|
|
|
} |
|
|
|
List<HistoricTaskInstance> list = historyService.createHistoricTaskInstanceQuery() |
|
|
|
.processInstanceId(processInstanceId) |
|
|
|
.orderByTaskCreateTime().asc().list(); |
|
|
|
List<HashMap<String,Object>> approvalEntityList = new ArrayList<>(); |
|
|
|
String approvalSuggestion = ""; |
|
|
|
HistoricVariableInstance historicVariableInstance = null; |
|
|
|
List<Comment> commentList = null; |
|
|
|
for( int i =0;i<list.size();i++) { |
|
|
|
HistoricTaskInstance item = list.get(i); |
|
|
|
HashMap<String, Object> hashMap = new HashMap<>(); |
|
|
|
commentList = taskService.getTaskComments(item.getId()); |
|
|
|
if (commentList != null && !commentList.isEmpty()) { |
|
|
|
approvalSuggestion = commentList.get(0).getFullMessage(); |
|
|
|
} else { |
|
|
|
approvalSuggestion = ""; |
|
|
|
} |
|
|
|
Map<String, Object> taskLocalVariables = item.getTaskLocalVariables(); |
|
|
|
//获取当前节点的任务变量
|
|
|
|
List<HistoricVariableInstance> variablelist = historyService.createHistoricVariableInstanceQuery() |
|
|
|
.taskId(item.getId()) |
|
|
|
.list(); |
|
|
|
if (variablelist.size()>0) { |
|
|
|
for (HistoricVariableInstance hisvar:variablelist) { |
|
|
|
hashMap.put(hisvar.getVariableName(),hisvar.getValue());//approvalStatue
|
|
|
|
} |
|
|
|
}else{ |
|
|
|
//当前人在处理
|
|
|
|
hashMap.put("isdangqian","1"); |
|
|
|
currentTaskName.add(item.getName()); |
|
|
|
} |
|
|
|
hashMap.put("operateDate", item.getEndTime()); |
|
|
|
String assignee = item.getAssignee(); |
|
|
|
hashMap.put("operator", assignee); |
|
|
|
String nickname=""; |
|
|
|
if(com.alibaba.excel.util.StringUtils.isNotBlank(assignee)){ |
|
|
|
SysUser user = sysUserService.getById(assignee); |
|
|
|
nickname = user.getNickname(); |
|
|
|
String phoneNumber = user.getPhoneNumber(); |
|
|
|
|
|
|
|
hashMap.put("operator", nickname); |
|
|
|
hashMap.put("operatorPhone", phoneNumber); |
|
|
|
|
|
|
|
}else{ |
|
|
|
continue; |
|
|
|
} |
|
|
|
hashMap.put("taskName", item.getName()); |
|
|
|
hashMap.put("comment", approvalSuggestion); |
|
|
|
boolean isPut =true; |
|
|
|
for (HashMap<String,Object> hash: approvalEntityList) { |
|
|
|
String operator = hash.get("operator").toString(); |
|
|
|
if(com.alibaba.excel.util.StringUtils.isNotBlank(approvalSuggestion)&&approvalSuggestion.contains("撤回")){ |
|
|
|
if(operator.equals(nickname)){ |
|
|
|
hashMap.put("taskName",hash.get("taskName")); |
|
|
|
} |
|
|
|
} |
|
|
|
//是否重复
|
|
|
|
Date operateDate = (Date) hash.get("operateDate"); |
|
|
|
Date endTime = item.getEndTime(); |
|
|
|
if(endTime!=null&&operateDate!=null){ |
|
|
|
long between = DateUtil.between(operateDate, endTime, DateUnit.SECOND); |
|
|
|
if(operator.equals(nickname)&& between<5){ |
|
|
|
isPut =false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
if(isPut){ |
|
|
|
approvalEntityList.add(hashMap); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//获取未激活的审批人信息
|
|
|
|
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery() |
|
|
|
.processInstanceId(processInstanceId) |
|
|
|
.singleResult(); |
|
|
|
//说明流程未结束
|
|
|
|
if(processInstance!=null){ |
|
|
|
BpmnModel bpmnModel = repositoryService.getBpmnModel(processInstance.getProcessDefinitionId()); |
|
|
|
Collection<FlowElement> flowElements = bpmnModel.getProcesses().get(0).getFlowElements(); |
|
|
|
List<UserTask> userTaskList = new ArrayList<>(); |
|
|
|
for (FlowElement element : bpmnModel.getProcesses().get(0).getFlowElements()) { |
|
|
|
if (element instanceof UserTask) { |
|
|
|
UserTask userTask = (UserTask) element; |
|
|
|
userTaskList.add(userTask); |
|
|
|
} |
|
|
|
} |
|
|
|
for(HashMap<String, Object> lastUser:approvalEntityList){ |
|
|
|
if(processInstance.getProcessDefinitionKey().equals("createURT")){ |
|
|
|
if (!"1".equals(lastUser.get("approvalStatue"))) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
for (int i =0;i<userTaskList.size();i++ ) { |
|
|
|
UserTask task=userTaskList.get(i); |
|
|
|
// HashMap<String, Object> lastUser = approvalEntityList.get(approvalEntityList.size() - 1);//获取最后一个
|
|
|
|
Object taskName = lastUser.get("taskName"); |
|
|
|
boolean match = task.getName().equals(taskName); |
|
|
|
if(match){ |
|
|
|
userTaskList.remove(task); |
|
|
|
} |
|
|
|
// else{
|
|
|
|
// userTaskList.remove(task);
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// i--;
|
|
|
|
} |
|
|
|
}else{ |
|
|
|
// HistoricTaskInstance item = list.get(list.size()-1);
|
|
|
|
for (int i =0;i<userTaskList.size();i++ ) { |
|
|
|
UserTask task=userTaskList.get(i); |
|
|
|
// HashMap<String, Object> lastUser = approvalEntityList.get(approvalEntityList.size() - 1);//获取最后一个
|
|
|
|
Object taskName = lastUser.get("taskName"); |
|
|
|
boolean match = task.getName().equals(taskName); |
|
|
|
if(match){ |
|
|
|
userTaskList.remove(task); |
|
|
|
} |
|
|
|
else { |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for (UserTask userTask: userTaskList ) { |
|
|
|
HashMap<String, Object> hashMap = new HashMap<>(); |
|
|
|
List<String> candidateGroups = userTask.getCandidateGroups(); |
|
|
|
String assignee = userTask.getAssignee(); |
|
|
|
hashMap.put("taskName", userTask.getName()); |
|
|
|
if(currentTaskName.contains(userTask.getName())){ |
|
|
|
hashMap.put("isdangqian","1"); |
|
|
|
} |
|
|
|
if(candidateGroups.size()==0){ |
|
|
|
if(assignee==null){ |
|
|
|
//设置审批人名字
|
|
|
|
//说明任务没有被认领
|
|
|
|
//获取变量名称
|
|
|
|
List<String> candidateUsers = userTask.getCandidateUsers(); |
|
|
|
String candidateUsersString = candidateUsers.get(0);//${taskLeadingDepartment}
|
|
|
|
//正则表达式提取变量名
|
|
|
|
Pattern pattern = Pattern.compile("\\$\\{(.*?)\\}"); |
|
|
|
Matcher matcher = pattern.matcher(candidateUsersString); |
|
|
|
if (matcher.find()) { |
|
|
|
String groupName = matcher.group(1);// 提取大括号中的内容
|
|
|
|
// 获取所有变量
|
|
|
|
Map<String, Object> variables = runtimeService.getVariables(processInstanceId); |
|
|
|
Object variable = runtimeService.getVariable(processInstanceId, groupName); |
|
|
|
if(variable instanceof String){ |
|
|
|
String startUserid = (String)variable; |
|
|
|
SysUser user = sysUserService.getById(startUserid); |
|
|
|
String nickname = user.getNickname(); |
|
|
|
String phoneNumber = user.getPhoneNumber(); |
|
|
|
|
|
|
|
hashMap.put("operator", nickname); |
|
|
|
hashMap.put("operatorPhone", phoneNumber); |
|
|
|
}else{ |
|
|
|
List<String> variableValue = (List<String>)variable; |
|
|
|
String name = ""; |
|
|
|
String phone = ""; |
|
|
|
for (String id:variableValue |
|
|
|
) { |
|
|
|
SysUser user = sysUserService.getById(id); |
|
|
|
String nickname = user.getNickname(); |
|
|
|
String phoneNumber = user.getPhoneNumber(); |
|
|
|
name=name+nickname+","; |
|
|
|
phone=phone+phoneNumber+","; |
|
|
|
} |
|
|
|
hashMap.put("operator", name.substring(0,name.length()-1)); |
|
|
|
hashMap.put("operatorPhone", phone.substring(0,phone.length()-1)); |
|
|
|
|
|
|
|
if(userTask.getName().equals("总咨询单位")){ |
|
|
|
hashMap.put("operatorPhone", "18478831015"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
}else{ |
|
|
|
SysUser user = sysUserService.getById(assignee); |
|
|
|
String nickname = user.getNickname(); |
|
|
|
String phoneNumber = user.getPhoneNumber(); |
|
|
|
|
|
|
|
hashMap.put("operator", nickname); |
|
|
|
hashMap.put("operatorPhone", phoneNumber); |
|
|
|
} |
|
|
|
}else{ |
|
|
|
LambdaQueryWrapper<SysUserRole> queryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
queryWrapper.eq(SysUserRole::getRoleId,candidateGroups.get(0)); |
|
|
|
List<SysUserRole> sysUserRoles = userRoleMapper.selectList(queryWrapper); |
|
|
|
String name=""; |
|
|
|
String phone=""; |
|
|
|
if(sysUserRoles.size()>0){ |
|
|
|
for (SysUserRole userRole:sysUserRoles){ |
|
|
|
SysUser user = sysUserService.getById(userRole.getUserId()); |
|
|
|
String nickname = user.getNickname(); |
|
|
|
String phoneNumber = user.getPhoneNumber(); |
|
|
|
name=name+nickname+","; |
|
|
|
phone=phone+phoneNumber+","; |
|
|
|
} |
|
|
|
} |
|
|
|
if(com.alibaba.excel.util.StringUtils.isNotBlank(name)){ |
|
|
|
name=name.substring(0,name.length()-1); |
|
|
|
phone=phone.substring(0,phone.length()-1); |
|
|
|
} |
|
|
|
hashMap.put("operator", name); |
|
|
|
hashMap.put("operatorPhone", phone); |
|
|
|
if(userTask.getName().equals("总咨询单位")){ |
|
|
|
hashMap.put("operatorPhone", "18478831015"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
Boolean isrecall = true; |
|
|
|
for (HashMap<String,Object> hash: approvalEntityList) { |
|
|
|
String operator = hash.get("operator").toString();//历史任务
|
|
|
|
String nickname = hashMap.get("operator").toString();//当前任务
|
|
|
|
String taskName= hashMap.get("taskName").toString();//当前任务
|
|
|
|
if(operator.equals(nickname)&&hash.get("operateDate")==null&&taskName.equals(hash.get("taskName"))){ |
|
|
|
isrecall = false; |
|
|
|
} |
|
|
|
} |
|
|
|
if(isrecall){ |
|
|
|
approvalEntityList.add(hashMap); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 使用 Stream 对列表进行排序
|
|
|
|
List<HashMap<String, Object>> sortedList = approvalEntityList.stream() |
|
|
|
.sorted((o1, o2) -> { |
|
|
|
Date d1 = (Date) o1.get("operateDate"); |
|
|
|
Date d2 = (Date) o2.get("operateDate"); |
|
|
|
|
|
|
|
// 如果 d1 是 null 或不存在,排在后面
|
|
|
|
if (d1 == null && d2 != null) { |
|
|
|
return 1; |
|
|
|
} |
|
|
|
// 如果 d2 是 null 或不存在,排在后面
|
|
|
|
if (d1 != null && d2 == null) { |
|
|
|
return -1; |
|
|
|
} |
|
|
|
// 如果两者都为 null 或两者都不为 null,按照日期排序
|
|
|
|
if (d1 == null && d2 == null) { |
|
|
|
return 0; |
|
|
|
} |
|
|
|
return d1.compareTo(d2); |
|
|
|
}) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
// if(list.size()>0&&list.get(0).getProcessDefinitionId().contains("createURT")) {
|
|
|
|
// sortedList.forEach(hashMap -> {
|
|
|
|
// hashMap.put("operatorPhone", "");
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
return sortedList; |
|
|
|
} |
|
|
|
} |
|
|
|