mirror of
https://github.com/dromara/RuoYi-Vue-Plus.git
synced 2025-09-24 20:26:39 +08:00
update 优化 增加请求流程后端发起demo案例
This commit is contained in:
parent
b815b8e574
commit
3a9bdb36f1
@ -82,6 +82,17 @@ public class TestLeaveController extends BaseController {
|
||||
return R.ok(testLeaveService.insertByBo(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交请假并提交流程
|
||||
*/
|
||||
@SaCheckPermission("workflow:leave:add")
|
||||
@Log(title = "请假", businessType = BusinessType.INSERT)
|
||||
@RepeatSubmit()
|
||||
@PostMapping("/submitAndFlowStart")
|
||||
public R<TestLeaveVo> submitAndFlowStart(@Validated(AddGroup.class) @RequestBody TestLeaveBo bo) {
|
||||
return R.ok(testLeaveService.submitAndFlowStart(bo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改请假
|
||||
*/
|
||||
|
@ -31,6 +31,11 @@ public class TestLeaveBo extends BaseEntity {
|
||||
@NotNull(message = "主键不能为空", groups = {EditGroup.class})
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 流程code
|
||||
*/
|
||||
private String flowCode;
|
||||
|
||||
/**
|
||||
* 请假类型
|
||||
*/
|
||||
|
@ -35,6 +35,11 @@ public interface ITestLeaveService {
|
||||
*/
|
||||
TestLeaveVo insertByBo(TestLeaveBo bo);
|
||||
|
||||
/**
|
||||
* 提交请假并发起流程
|
||||
*/
|
||||
TestLeaveVo submitAndFlowStart(TestLeaveBo bo);
|
||||
|
||||
/**
|
||||
* 修改请假
|
||||
*/
|
||||
|
@ -9,10 +9,14 @@ 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.dto.CompleteTaskDTO;
|
||||
import org.dromara.common.core.domain.dto.StartProcessDTO;
|
||||
import org.dromara.common.core.domain.dto.StartProcessReturnDTO;
|
||||
import org.dromara.common.core.domain.event.ProcessTaskEvent;
|
||||
import org.dromara.common.core.domain.event.ProcessDeleteEvent;
|
||||
import org.dromara.common.core.domain.event.ProcessEvent;
|
||||
import org.dromara.common.core.enums.BusinessStatusEnum;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.service.WorkflowService;
|
||||
import org.dromara.common.core.utils.MapstructUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
@ -115,6 +119,35 @@ public class TestLeaveServiceImpl implements ITestLeaveService {
|
||||
return MapstructUtils.convert(add, TestLeaveVo.class);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public TestLeaveVo submitAndFlowStart(TestLeaveBo bo) {
|
||||
long day = DateUtil.betweenDay(bo.getStartDate(), bo.getEndDate(), true);
|
||||
// 截止日期也算一天
|
||||
bo.setLeaveDays((int) day + 1);
|
||||
TestLeave leave = MapstructUtils.convert(bo, TestLeave.class);
|
||||
boolean flag = baseMapper.insertOrUpdate(leave);
|
||||
if (flag) {
|
||||
bo.setId(leave.getId());
|
||||
// 后端发起需要忽略权限
|
||||
bo.getParams().put("ignore", true);
|
||||
StartProcessReturnDTO result = workflowService.startWorkFlow(new StartProcessDTO() {{
|
||||
setBusinessId(leave.getId().toString());
|
||||
setFlowCode(StringUtils.isEmpty(bo.getFlowCode()) ? "leave1" : bo.getFlowCode());
|
||||
setVariables(bo.getParams());
|
||||
}});
|
||||
boolean flag1 = workflowService.completeTask(new CompleteTaskDTO() {{
|
||||
setTaskId(result.getTaskId());
|
||||
setMessageType(List.of("1"));
|
||||
setVariables(bo.getParams());
|
||||
}});
|
||||
if (!flag1) {
|
||||
throw new ServiceException("流程发起异常");
|
||||
}
|
||||
}
|
||||
return MapstructUtils.convert(leave, TestLeaveVo.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改请假
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user