package com.qdport.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.qdport.entity.PolicyStrive; import com.qdport.enums.QDPortEnum; import com.qdport.mapper.PolicyCaseMapper; import com.qdport.mapper.PolicyShareMapper; import com.qdport.mapper.PolicyStriveMapper; import com.qdport.modules.system.entity.SysUser; import com.qdport.modules.system.service.TSysUserService; import com.qdport.query.QueryWrapperBuilder; import com.qdport.service.PolicyShareService; import com.qdport.util.StringUtil; import com.qdport.vo.*; import com.qdport.workflow.core.utils.WfTaskUtil; import com.qdport.workflow.process.model.WfProcess; import com.qdport.workflow.process.service.IWfProcessService; import lombok.AllArgsConstructor; import com.qdport.entity.PolicyTodo; import com.qdport.query.PolicyTodoQuery; import com.qdport.mapper.PolicyTodoMapper; import com.qdport.service.PolicyTodoService; import com.qdport.wrapper.PolicyTodoWrapper; import com.qdport.core.tool.utils.BeanUtil; import org.flowable.engine.HistoryService; import org.flowable.task.api.history.HistoricTaskInstance; import org.flowable.task.api.history.HistoricTaskInstanceQuery; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import javax.annotation.Resource; import java.util.Date; import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.stream.Collectors; /** * 政策待办 * * @author yuheng * @since 1.0.0 2024-10-11 */ @Service public class PolicyTodoServiceImpl extends ServiceImpl implements PolicyTodoService { @Resource private IWfProcessService processService; @Resource private TSysUserService sysUserService; @Resource private PolicyShareMapper policyShareMapper; @Resource private PolicyStriveMapper policyStriveMapper; @Resource private PolicyCaseMapper policyCaseMapper; @Override public IPage page(PolicyTodoQuery query) { IPage page = new Page<>(query.getPage(), query.getSize()); page = baseMapper.selectPage(page, getWrapper(query)); return PolicyTodoWrapper.build().pageVO(page); } private QueryWrapper getWrapper(PolicyTodoQuery query) { QueryWrapper wrapper = QueryWrapperBuilder.buildQueryWrapper(query, PolicyTodo.class); wrapper.orderByDesc("CREATE_TIME"); return wrapper; } @Override public void save(PolicyTodoVO vo) { PolicyTodo entity = BeanUtil.copy(vo, PolicyTodo.class); baseMapper.insert(entity); } @Override @Transactional(rollbackFor = Exception.class) public void save(PolicyShareVO vo) throws ExecutionException, InterruptedException { QueryWrapper todoQueryWrapper = new QueryWrapper<>(); todoQueryWrapper.eq("REF_ID", vo.getId()); todoQueryWrapper.eq("REF_TYPE", QDPortEnum.POLICY_TODO_REFTYPE_POLICY_SHARE.getValue()); todoQueryWrapper.eq("TODO_TYPE", QDPortEnum.POLICY_TODO_TYPE_APPROVE.getValue()); todoQueryWrapper.eq("STATUS", QDPortEnum.POLICY_TODO_STATUS_ACTIVE.getValue()); PolicyTodo todo = new PolicyTodo(); todo.setStatus(QDPortEnum.POLICY_TODO_STATUS_DONE.getValue()); update(todo, todoQueryWrapper); Future> flowFuture = processService.historyFlowList(vo.getProcessInstanceId(), null, null); List ll = flowFuture.get(); List filter = ll.stream().filter(wfProcess -> QDPortEnum.POLICY_PROCESS_TYPE_USER_TASK.getValue().equals(wfProcess.getHistoryActivityType()) && StringUtil.isEmpty(wfProcess.getEndTime()) ).collect(Collectors.toList()); if (!filter.isEmpty()) { WfProcess process = filter.get(0); String[] assignNames = process.getAssigneeName().split("/"); for (String username : assignNames) { QueryWrapper sysUserWrapper = new QueryWrapper<>(); sysUserWrapper.eq("username", username); SysUser user = sysUserService.getOne(sysUserWrapper); todo = new PolicyTodo(); todo.setRefId(vo.getId()); todo.setRefType(QDPortEnum.POLICY_TODO_REFTYPE_POLICY_SHARE.getValue()); todo.setCreateTime(new Date()); todo.setStatus(QDPortEnum.POLICY_TODO_STATUS_ACTIVE.getValue()); todo.setTodoType(QDPortEnum.POLICY_TODO_TYPE_APPROVE.getValue()); todo.setTodoUserId(user.getId()); todo.setZcAbstractContent(vo.getAbstractContent()); todo.setZcContactPhone(vo.getContactPhone()); todo.setZcCreateId(vo.getCreateId()); todo.setZcCreateName(vo.getCreateName()); todo.setZcCreateTime(vo.getCreateTime()); todo.setZcName(vo.getName()); todo.setZcType(vo.getZcType()); baseMapper.insert(todo); } } else { vo.setStatus(QDPortEnum.POLICY_SHARE_STATUS_DONE.getValue()); vo.setUpdateTime(new Date()); policyShareMapper.updateById(vo); } } @Override @Transactional(rollbackFor = Exception.class) public void save(PolicyStriveVO vo) throws ExecutionException, InterruptedException { QueryWrapper todoQueryWrapper = new QueryWrapper<>(); todoQueryWrapper.eq("REF_ID", vo.getId()); todoQueryWrapper.eq("REF_TYPE", QDPortEnum.POLICY_TODO_REFTYPE_POLICY_STRIVE.getValue()); todoQueryWrapper.eq("TODO_TYPE", QDPortEnum.POLICY_TODO_TYPE_APPROVE.getValue()); todoQueryWrapper.eq("STATUS", QDPortEnum.POLICY_TODO_STATUS_ACTIVE.getValue()); PolicyTodo todo = new PolicyTodo(); todo.setStatus(QDPortEnum.POLICY_TODO_STATUS_DONE.getValue()); update(todo, todoQueryWrapper); Future> flowFuture = processService.historyFlowList(vo.getProcessInstanceId(), null, null); List ll = flowFuture.get(); List filter = ll.stream().filter(wfProcess -> QDPortEnum.POLICY_PROCESS_TYPE_USER_TASK.getValue().equals(wfProcess.getHistoryActivityType()) && StringUtil.isEmpty(wfProcess.getEndTime()) ).collect(Collectors.toList()); if (!filter.isEmpty()) { WfProcess process = filter.get(0); String[] assignNames = process.getAssigneeName().split("/"); for (String username : assignNames) { QueryWrapper sysUserWrapper = new QueryWrapper<>(); sysUserWrapper.eq("username", username); SysUser user = sysUserService.getOne(sysUserWrapper); todo = new PolicyTodo(); todo.setRefId(vo.getId()); todo.setRefType(QDPortEnum.POLICY_TODO_REFTYPE_POLICY_STRIVE.getValue()); todo.setCreateTime(new Date()); todo.setStatus(QDPortEnum.POLICY_TODO_STATUS_ACTIVE.getValue()); todo.setTodoType(QDPortEnum.POLICY_TODO_TYPE_APPROVE.getValue()); todo.setTodoUserId(user.getId()); todo.setZcAbstractContent(vo.getAbstractContent()); todo.setZcContactPhone(vo.getContactPhone()); todo.setZcCreateId(vo.getCreateId()); todo.setZcCreateName(vo.getCreateName()); todo.setZcCreateTime(vo.getCreateTime()); todo.setZcName(vo.getName()); todo.setZcType(vo.getZcType()); baseMapper.insert(todo); } } else { vo.setStatus(QDPortEnum.POLICY_SHARE_STATUS_DONE.getValue()); vo.setUpdateTime(new Date()); policyStriveMapper.updateById(vo); } } @Override public void save(PolicyCaseVO vo) throws ExecutionException, InterruptedException { QueryWrapper todoQueryWrapper = new QueryWrapper<>(); todoQueryWrapper.eq("REF_ID", vo.getId()); todoQueryWrapper.eq("REF_TYPE", QDPortEnum.POLICY_TODO_REFTYPE_POLICY_CASE.getValue()); todoQueryWrapper.eq("TODO_TYPE", QDPortEnum.POLICY_TODO_TYPE_APPROVE.getValue()); todoQueryWrapper.eq("STATUS", QDPortEnum.POLICY_TODO_STATUS_ACTIVE.getValue()); PolicyTodo todo = new PolicyTodo(); todo.setStatus(QDPortEnum.POLICY_TODO_STATUS_DONE.getValue()); update(todo, todoQueryWrapper); Future> flowFuture = processService.historyFlowList(vo.getProcessInstanceId(), null, null); List ll = flowFuture.get(); List filter = ll.stream().filter(wfProcess -> QDPortEnum.POLICY_PROCESS_TYPE_USER_TASK.getValue().equals(wfProcess.getHistoryActivityType()) && StringUtil.isEmpty(wfProcess.getEndTime()) ).collect(Collectors.toList()); PolicyStrive policyStrive = vo.getPolicyStrive(); if (!filter.isEmpty()) { WfProcess process = filter.get(0); String[] assignNames = process.getAssigneeName().split("/"); for (String username : assignNames) { QueryWrapper sysUserWrapper = new QueryWrapper<>(); sysUserWrapper.eq("username", username); SysUser user = sysUserService.getOne(sysUserWrapper); todo = new PolicyTodo(); todo.setRefId(vo.getId()); todo.setRefType(QDPortEnum.POLICY_TODO_REFTYPE_POLICY_CASE.getValue()); todo.setCreateTime(new Date()); todo.setStatus(QDPortEnum.POLICY_TODO_STATUS_ACTIVE.getValue()); todo.setTodoType(QDPortEnum.POLICY_TODO_TYPE_APPROVE.getValue()); todo.setTodoUserId(user.getId()); todo.setZcAbstractContent(policyStrive.getAbstractContent()); todo.setZcContactPhone(policyStrive.getContactPhone()); todo.setZcCreateId(policyStrive.getCreateId()); todo.setZcCreateName(policyStrive.getCreateName()); todo.setZcCreateTime(vo.getCreateTime()); todo.setZcName(policyStrive.getName()); todo.setZcType(policyStrive.getZcType()); baseMapper.insert(todo); } } else { vo.setStatus(QDPortEnum.POLICY_SHARE_STATUS_DONE.getValue()); vo.setUpdateTime(new Date()); policyCaseMapper.updateById(vo); } } @Override public void update(PolicyTodoVO vo) { PolicyTodo entity = BeanUtil.copy(vo, PolicyTodo.class); updateById(entity); } @Override @Transactional(rollbackFor = Exception.class) public void delete(List idList) { removeByIds(idList); } }