| | |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ycl.common.base.Result; |
| | | import com.ycl.common.core.domain.entity.SysDept; |
| | | import com.ycl.common.core.domain.entity.SysRole; |
| | | import com.ycl.common.core.domain.entity.SysUser; |
| | | import com.ycl.common.enums.business.HandlerTypeEnum; |
| | | import com.ycl.common.enums.business.ProcessLogEventTypeEnum; |
| | | import com.ycl.domain.entity.ProcessLog; |
| | | import com.ycl.domain.json.DelegateData; |
| | | import com.ycl.domain.json.JumpData; |
| | | import com.ycl.domain.json.RejectData; |
| | | import com.ycl.domain.json.SuperviseData; |
| | | import com.ycl.domain.json.*; |
| | | import com.ycl.domain.query.ProcessLogQuery; |
| | | import com.ycl.domain.vo.ProcessLogVO; |
| | | import com.ycl.framework.utils.PageUtil; |
| | | import com.ycl.mapper.ProcessLogMapper; |
| | | import com.ycl.service.ProcessLogService; |
| | | import com.ycl.system.service.ISysDeptService; |
| | | import com.ycl.system.service.ISysRoleService; |
| | | import com.ycl.system.service.ISysUserService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.Assert; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | public class ProcessLogServiceImpl extends ServiceImpl<ProcessLogMapper, ProcessLog> implements ProcessLogService { |
| | | |
| | | private final ProcessLogMapper processLogMapper; |
| | | private final ISysUserService userService; |
| | | private final ISysDeptService deptService; |
| | | private final ISysRoleService roleService; |
| | | |
| | | /** |
| | | * 添加日志 |
| | |
| | | * @param eventDataJson json扩展内容 |
| | | */ |
| | | @Override |
| | | public void add(String taskId, String flowInsId, ProcessLogEventTypeEnum eventType, Long projectId, String eventDataJson) { |
| | | public void add(String taskId, String flowInsId, ProcessLogEventTypeEnum eventType, String projectId, String eventDataJson) { |
| | | ProcessLog log = new ProcessLog(); |
| | | log.setTaskId(taskId); |
| | | log.setProcessInsId(flowInsId); |
| | |
| | | return CollectionUtils.isNotEmpty(list); |
| | | } |
| | | |
| | | @Override |
| | | public Boolean taskIsHangup(String taskId, String processInsId) { |
| | | Long num = new LambdaQueryChainWrapper<>(baseMapper) |
| | | .eq(ProcessLog::getProcessInsId, processInsId) |
| | | .eq(ProcessLog::getTaskId, taskId) |
| | | .in(ProcessLog::getEventType, ProcessLogEventTypeEnum.HANGUP, ProcessLogEventTypeEnum.CANCEL_HANGUP) |
| | | .count(); |
| | | return num % 2 != 0; |
| | | } |
| | | |
| | | @Override |
| | | public Result projectProcessLogPage(ProcessLogQuery query) { |
| | | List<ProcessLogVO> list = baseMapper.projectProcessLogPage(query); |
| | | public Boolean taskIsWait(String taskId, String processInsId) { |
| | | List<ProcessLog> list = new LambdaQueryChainWrapper<>(baseMapper) |
| | | .eq(ProcessLog::getProcessInsId, processInsId) |
| | | .eq(ProcessLog::getTaskId, taskId) |
| | | .list(); |
| | | return list.stream().anyMatch(log -> ProcessLogEventTypeEnum.WAIT.equals(log.getEventType())) |
| | | && list.stream().filter(log -> ProcessLogEventTypeEnum.FINISHED.equals(log.getEventType())).count() < 1; |
| | | } |
| | | |
| | | @Override |
| | | public Boolean taskIsJump(String taskId, String processInsId) { |
| | | List<ProcessLog> list = new LambdaQueryChainWrapper<>(baseMapper) |
| | | .eq(ProcessLog::getProcessInsId, processInsId) |
| | | .eq(ProcessLog::getTaskId, taskId) |
| | | .eq(ProcessLog::getEventType, ProcessLogEventTypeEnum.JUMP) |
| | | .list(); |
| | | return list.size() > 0; |
| | | } |
| | | |
| | | @Override |
| | | public Boolean taskIsTeamwork(String taskId, String processInsId) { |
| | | ProcessLog log = new LambdaQueryChainWrapper<>(baseMapper) |
| | | .eq(ProcessLog::getProcessInsId, processInsId) |
| | | .eq(ProcessLog::getTaskId, taskId) |
| | | .eq(ProcessLog::getEventType, ProcessLogEventTypeEnum.TEAM_WORK) |
| | | .one(); |
| | | if (Objects.isNull(log)) { |
| | | return Boolean.FALSE; |
| | | } else { |
| | | // 判断协同人是否全部完成了协同。TODO |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public Result projectProcessLogList(ProcessLogQuery query) { |
| | | List<ProcessLogVO> list = baseMapper.projectProcessLogList(query); |
| | | // json反序列化 |
| | | list.stream().forEach(log -> { |
| | | if (StringUtils.isNotBlank(log.getEventDataJson())) { |
| | | if (ProcessLogEventTypeEnum.DELEGATE.equals(log.getEventType())) { |
| | | log.setEventDataObj(JSON.parseObject(log.getEventDataJson(), DelegateData.class)); |
| | | DelegateData delegateData = JSON.parseObject(log.getEventDataJson(), DelegateData.class); |
| | | // 查询转办后的处理人名称 |
| | | List<String> names = new ArrayList<>(2); |
| | | List<Long> ids = delegateData.getAfterHandlerIds().stream().map(Long::parseLong).collect(Collectors.toList()); |
| | | this.getName(delegateData.getAfterHandlerType(), ids, names); |
| | | delegateData.setAfterHandlerNames(names); |
| | | log.setEventDataObj(delegateData); |
| | | } else if (ProcessLogEventTypeEnum.JUMP.equals(log.getEventType())) { |
| | | log.setEventDataObj(JSON.parseObject(log.getEventDataJson(), JumpData.class)); |
| | | } else if (ProcessLogEventTypeEnum.WAIT.equals(log.getEventType())) { |
| | | log.setEventDataObj(JSON.parseObject(log.getEventDataJson(), WaitData.class)); |
| | | } else if (ProcessLogEventTypeEnum.REJECT.equals(log.getEventType())) { |
| | | log.setEventDataObj(JSON.parseObject(log.getEventDataJson(), RejectData.class)); |
| | | } else if (ProcessLogEventTypeEnum.SUPERVISE.equals(log.getEventType())) { |
| | | log.setEventDataObj(JSON.parseObject(log.getEventDataJson(), SuperviseData.class)); |
| | | List<SuperviseData> superviseDataList = JSON.parseArray(log.getEventDataJson(), SuperviseData.class); |
| | | if (CollectionUtils.isNotEmpty(superviseDataList)) { |
| | | SysUser user = userService.selectUserById(Long.parseLong(superviseDataList.get(0).getSenderId())); |
| | | if (Objects.nonNull(user)) { |
| | | superviseDataList.get(0).setSenderName(user.getNickName() + "(" + (Objects.nonNull(user.getDept()) ? user.getDept().getDeptName() : "无部门") + ")"); |
| | | } |
| | | log.setEventDataObj(superviseDataList.get(0)); |
| | | } |
| | | |
| | | } else if (ProcessLogEventTypeEnum.HANGUP.equals(log.getEventType())) { |
| | | log.setEventDataObj(JSON.parseObject(log.getEventDataJson(), HangupData.class)); |
| | | } |
| | | } |
| | | }); |
| | | return Result.ok().data(list); |
| | | } |
| | | |
| | | @Override |
| | | public Result projectProcessLogPage(ProcessLogQuery query) { |
| | | IPage<ProcessLogVO> page = PageUtil.getPage(query, ProcessLogVO.class); |
| | | baseMapper.projectProcessLogPage(page, query); |
| | | return Result.ok().data(page.getRecords()).total(page.getTotal()); |
| | | } |
| | | |
| | | /** |
| | | * 解析流程日志中的数据-名称 |
| | | * |
| | | * @param handlerType |
| | | * @param ids |
| | | * @param names |
| | | */ |
| | | private void getName(HandlerTypeEnum handlerType, List<Long> ids, List<String> names) { |
| | | if (HandlerTypeEnum.FIX_USER.equals(handlerType)) { |
| | | SysUser user = userService.selectUserById(ids.get(0)); |
| | | if (Objects.nonNull(user)) { |
| | | names.add(user.getNickName() + "(" + (Objects.nonNull(user.getDept()) ? user.getDept().getDeptName() : "无部门") + ")"); |
| | | } |
| | | } else if (HandlerTypeEnum.USER.equals(handlerType)) { |
| | | List<SysUser> users = userService.selectUserByIds(ids); |
| | | names.addAll(users.stream().map(user -> user.getNickName() + "(" + (Objects.nonNull(user.getDept()) ? user.getDept().getDeptName() : "无部门") + ")").collect(Collectors.toList())); |
| | | } else if (HandlerTypeEnum.DEPT.equals(handlerType)) { |
| | | List<SysDept> depts = deptService.selectDeptByIds(ids); |
| | | names.addAll(depts.stream().map(SysDept::getDeptName).collect(Collectors.toList())); |
| | | } else if (HandlerTypeEnum.ROLE.equals(handlerType)) { |
| | | List<SysRole> roles = roleService.selectRoleByIds(ids); |
| | | names.addAll(roles.stream().map(SysRole::getRoleName).collect(Collectors.toList())); |
| | | } |
| | | } |
| | | } |