package com.srs.flowable.service.impl;

import com.srs.flowable.domain.frontdto.RespBean;
import com.srs.flowable.domain.frontdto.TestFlow;
import com.srs.flowable.service.IAskForLeaveService;
import org.flowable.engine.RuntimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

@Service
public class AskForLeaveService implements IAskForLeaveService
{

    @Autowired
    RuntimeService runtimeService;

    @Transactional
    public RespBean askForLeave(TestFlow askForLeaveVO) {
        Map<String, Object> variables = new HashMap<>();
        variables.put("name", askForLeaveVO.getName());
        variables.put("days", askForLeaveVO.getDays());
        variables.put("reason", askForLeaveVO.getReason());
        try {
            runtimeService.startProcessInstanceByKey("flow_ks2lyz4c", askForLeaveVO.getName(), variables);
            return RespBean.ok("已提交请假申请");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return RespBean.error("提交申请失败");
    }
}

