| | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.dromara.common.core.domain.event.ProcessEvent; |
| | | import org.dromara.common.core.domain.event.ProcessTaskEvent; |
| | | import org.dromara.common.core.service.WorkflowService; |
| | | import org.dromara.common.core.utils.MapstructUtils; |
| | | import org.dromara.common.core.utils.StreamUtils; |
| | | import org.dromara.common.core.utils.StringUtils; |
| | |
| | | import org.dromara.workflow.domain.bo.TestLeaveBo; |
| | | import org.dromara.workflow.domain.vo.TestLeaveVo; |
| | | import org.dromara.workflow.mapper.TestLeaveMapper; |
| | | import org.dromara.workflow.service.IActProcessInstanceService; |
| | | import org.dromara.workflow.service.ITestLeaveService; |
| | | import org.dromara.workflow.utils.WorkflowUtils; |
| | | import org.springframework.context.event.EventListener; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | */ |
| | | @RequiredArgsConstructor |
| | | @Service |
| | | @Slf4j |
| | | public class TestLeaveServiceImpl implements ITestLeaveService { |
| | | |
| | | private final TestLeaveMapper baseMapper; |
| | | private final IActProcessInstanceService iActProcessInstanceService; |
| | | private final WorkflowService workflowService; |
| | | |
| | | /** |
| | | * 查询请假 |
| | | */ |
| | | @Override |
| | | public TestLeaveVo queryById(Long id) { |
| | | return baseMapper.selectVoById(id); |
| | | TestLeaveVo testLeaveVo = baseMapper.selectVoById(id); |
| | | workflowService.setBusinessInstanceDTO(testLeaveVo, String.valueOf(id)); |
| | | return testLeaveVo; |
| | | } |
| | | |
| | | /** |
| | |
| | | List<TestLeaveVo> rows = build.getRows(); |
| | | if (CollUtil.isNotEmpty(rows)) { |
| | | List<String> ids = StreamUtils.toList(rows, e -> String.valueOf(e.getId())); |
| | | WorkflowUtils.setProcessInstanceListVo(rows, ids, "id"); |
| | | workflowService.setBusinessInstanceListDTO(rows, ids, "id"); |
| | | } |
| | | return build; |
| | | } |
| | |
| | | private LambdaQueryWrapper<TestLeave> buildQueryWrapper(TestLeaveBo bo) { |
| | | LambdaQueryWrapper<TestLeave> lqw = Wrappers.lambdaQuery(); |
| | | lqw.eq(StringUtils.isNotBlank(bo.getLeaveType()), TestLeave::getLeaveType, bo.getLeaveType()); |
| | | lqw.ge(bo.getStartLeaveDays() != null,TestLeave::getLeaveDays, bo.getStartLeaveDays()); |
| | | lqw.le(bo.getEndLeaveDays() != null,TestLeave::getLeaveDays, bo.getEndLeaveDays()); |
| | | lqw.ge(bo.getStartLeaveDays() != null, TestLeave::getLeaveDays, bo.getStartLeaveDays()); |
| | | lqw.le(bo.getEndLeaveDays() != null, TestLeave::getLeaveDays, bo.getEndLeaveDays()); |
| | | lqw.orderByDesc(BaseEntity::getCreateTime); |
| | | return lqw; |
| | | } |
| | |
| | | * 新增请假 |
| | | */ |
| | | @Override |
| | | public TestLeave insertByBo(TestLeaveBo bo) { |
| | | public TestLeaveVo insertByBo(TestLeaveBo bo) { |
| | | TestLeave add = MapstructUtils.convert(bo, TestLeave.class); |
| | | validEntityBeforeSave(add); |
| | | boolean flag = baseMapper.insert(add) > 0; |
| | | if (flag) { |
| | | bo.setId(add.getId()); |
| | | } |
| | | return add; |
| | | TestLeaveVo testLeaveVo = MapstructUtils.convert(add, TestLeaveVo.class); |
| | | workflowService.setBusinessInstanceDTO(testLeaveVo, String.valueOf(add.getId())); |
| | | return testLeaveVo; |
| | | } |
| | | |
| | | /** |
| | | * 修改请假 |
| | | */ |
| | | @Override |
| | | public TestLeave updateByBo(TestLeaveBo bo) { |
| | | public TestLeaveVo updateByBo(TestLeaveBo bo) { |
| | | TestLeave update = MapstructUtils.convert(bo, TestLeave.class); |
| | | validEntityBeforeSave(update); |
| | | return baseMapper.updateById(update) > 0 ? update : null; |
| | | } |
| | | |
| | | /** |
| | | * 保存前的数据校验 |
| | | */ |
| | | private void validEntityBeforeSave(TestLeave entity) { |
| | | //TODO 做一些数据校验,如唯一约束 |
| | | baseMapper.updateById(update); |
| | | TestLeaveVo testLeaveVo = MapstructUtils.convert(update, TestLeaveVo.class); |
| | | workflowService.setBusinessInstanceDTO(testLeaveVo, String.valueOf(update.getId())); |
| | | return testLeaveVo; |
| | | } |
| | | |
| | | /** |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean deleteWithValidByIds(Collection<Long> ids) { |
| | | List<String> idList = StreamUtils.toList(ids, String::valueOf); |
| | | iActProcessInstanceService.deleteRunAndHisInstanceByBusinessKeys(idList); |
| | | workflowService.deleteRunAndHisInstance(idList); |
| | | return baseMapper.deleteBatchIds(ids) > 0; |
| | | } |
| | | |
| | | /** |
| | | * 总体流程监听(例如: 提交 退回 撤销 终止 作废等) |
| | | * |
| | | * @param processEvent 参数 |
| | | */ |
| | | @EventListener(condition = "#processEvent.key=='leave1'") |
| | | public void processHandler(ProcessEvent processEvent) { |
| | | log.info("当前任务执行了{}", processEvent.toString()); |
| | | } |
| | | |
| | | /** |
| | | * 执行办理任务监听 |
| | | * |
| | | * @param processTaskEvent 参数 |
| | | */ |
| | | @EventListener(condition = "#processTaskEvent.keyNode=='leave1_Activity_14633hx'") |
| | | public void processTaskHandler(ProcessTaskEvent processTaskEvent) { |
| | | log.info("当前任务执行了{}", processTaskEvent.toString()); |
| | | } |
| | | |
| | | |
| | | } |