| | |
| | | package org.dromara.workflow.service.impl; |
| | | |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.map.MapUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | 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.ProcessDeleteEvent; |
| | | import org.dromara.common.core.domain.event.ProcessEvent; |
| | | import org.dromara.common.core.domain.event.ProcessTaskEvent; |
| | | import org.dromara.common.core.enums.BusinessStatusEnum; |
| | | 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.common.mybatis.core.domain.BaseEntity; |
| | | import org.dromara.common.mybatis.core.page.PageQuery; |
| | | import org.dromara.common.mybatis.core.page.TableDataInfo; |
| | | import org.dromara.workflow.common.ConditionalOnEnable; |
| | | import org.dromara.workflow.domain.TestLeave; |
| | | import org.dromara.workflow.domain.bo.TestLeaveBo; |
| | | import org.dromara.workflow.domain.vo.TestLeaveVo; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.Collection; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 请假Service业务层处理 |
| | |
| | | * @author may |
| | | * @date 2023-07-21 |
| | | */ |
| | | @ConditionalOnEnable |
| | | @RequiredArgsConstructor |
| | | @Service |
| | | @Slf4j |
| | |
| | | */ |
| | | @Override |
| | | public TestLeaveVo insertByBo(TestLeaveBo bo) { |
| | | long day = DateUtil.betweenDay(bo.getStartDate(), bo.getEndDate(), true); |
| | | // 截止日期也算一天 |
| | | bo.setLeaveDays((int) day + 1); |
| | | TestLeave add = MapstructUtils.convert(bo, TestLeave.class); |
| | | if (StringUtils.isBlank(add.getStatus())) { |
| | | add.setStatus(BusinessStatusEnum.DRAFT.getStatus()); |
| | |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean deleteWithValidByIds(Collection<Long> ids) { |
| | | List<String> idList = StreamUtils.toList(ids, String::valueOf); |
| | | workflowService.deleteRunAndHisInstance(idList); |
| | | public Boolean deleteWithValidByIds(List<Long> ids) { |
| | | workflowService.deleteInstance(ids); |
| | | return baseMapper.deleteByIds(ids) > 0; |
| | | } |
| | | |
| | | /** |
| | | * 总体流程监听(例如: 提交 退回 撤销 终止 作废等) |
| | | * 正常使用只需#processEvent.key=='leave1' |
| | | * 总体流程监听(例如: 草稿,撤销,退回,作废,终止,已完成等) |
| | | * 正常使用只需#processEvent.flowCode=='leave1' |
| | | * 示例为了方便则使用startsWith匹配了全部示例key |
| | | * |
| | | * @param processEvent 参数 |
| | | */ |
| | | @EventListener(condition = "#processEvent.key.startsWith('leave')") |
| | | @EventListener(condition = "#processEvent.flowCode.startsWith('leave')") |
| | | public void processHandler(ProcessEvent processEvent) { |
| | | log.info("当前任务执行了{}", processEvent.toString()); |
| | | TestLeave testLeave = baseMapper.selectById(Long.valueOf(processEvent.getBusinessKey())); |
| | | TestLeave testLeave = baseMapper.selectById(Long.valueOf(processEvent.getBusinessId())); |
| | | testLeave.setStatus(processEvent.getStatus()); |
| | | // 用于例如审批附件 审批意见等 存储到业务表内 自行根据业务实现存储流程 |
| | | Map<String, Object> params = processEvent.getParams(); |
| | | if (MapUtil.isNotEmpty(params)) { |
| | | // 历史任务扩展(通常为附件) |
| | | String hisTaskExt = Convert.toStr(params.get("hisTaskExt")); |
| | | // 办理人 |
| | | String handler = Convert.toStr(params.get("handler")); |
| | | // 办理意见 |
| | | String message = Convert.toStr(params.get("message")); |
| | | } |
| | | if (processEvent.isSubmit()) { |
| | | testLeave.setStatus(BusinessStatusEnum.WAITING.getStatus()); |
| | | } |
| | |
| | | |
| | | /** |
| | | * 执行办理任务监听 |
| | | * 示例:也可通过 @EventListener(condition = "#processTaskEvent.key=='leave1'")进行判断 |
| | | * 示例:也可通过 @EventListener(condition = "#processTaskEvent.flowCode=='leave1'")进行判断 |
| | | * 在方法中判断流程节点key |
| | | * if ("xxx".equals(processTaskEvent.getTaskDefinitionKey())) { |
| | | * if ("xxx".equals(processTaskEvent.getNodeCode())) { |
| | | * //执行业务逻辑 |
| | | * } |
| | | * |
| | | * @param processTaskEvent 参数 |
| | | */ |
| | | @EventListener(condition = "#processTaskEvent.key=='leave1' && #processTaskEvent.taskDefinitionKey=='Activity_14633hx'") |
| | | @EventListener(condition = "#processTaskEvent.flowCode.startsWith('leave')") |
| | | public void processTaskHandler(ProcessTaskEvent processTaskEvent) { |
| | | log.info("当前任务执行了{}", processTaskEvent.toString()); |
| | | TestLeave testLeave = baseMapper.selectById(Long.valueOf(processTaskEvent.getBusinessKey())); |
| | | TestLeave testLeave = baseMapper.selectById(Long.valueOf(processTaskEvent.getBusinessId())); |
| | | testLeave.setStatus(BusinessStatusEnum.WAITING.getStatus()); |
| | | baseMapper.updateById(testLeave); |
| | | } |
| | | |
| | | /** |
| | | * 监听删除流程事件 |
| | | * 正常使用只需#processDeleteEvent.flowCode=='leave1' |
| | | * 示例为了方便则使用startsWith匹配了全部示例key |
| | | * |
| | | * @param processDeleteEvent 参数 |
| | | */ |
| | | @EventListener(condition = "#processDeleteEvent.flowCode.startsWith('leave')") |
| | | public void processDeleteHandler(ProcessDeleteEvent processDeleteEvent) { |
| | | log.info("监听删除流程事件,当前任务执行了{}", processDeleteEvent.toString()); |
| | | TestLeave testLeave = baseMapper.selectById(Long.valueOf(processDeleteEvent.getBusinessId())); |
| | | if (ObjectUtil.isNull(testLeave)) { |
| | | return; |
| | | } |
| | | baseMapper.deleteById(testLeave.getId()); |
| | | } |
| | | |
| | | } |