package com.xjrsoft.module.liteflow.node;

import cn.hutool.core.convert.Convert;
import com.xjrsoft.module.student.service.IBaseStudentScholarshipApplicantService;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.CompletableFuture;


/**
 * 申请奖学金流程数据赋值
 */
@Component("wf_scholarship_node")
public class WfScholarshipNode extends NodeComponent {
    @Autowired
    private IBaseStudentScholarshipApplicantService scholarshipApplicantService;
    @Override
    public void process() throws Exception {
        // 获取表单中数据编号
        Map<String, Object> params = this.getFirstContextBean();
        Object value = util.getFormDatKey(params,"id");
        Map<String,Object> form = util.getFormData(params);
        assert form != null;
        form.put("class_name","123123123123");
        Long formId = Convert.toLong(value);
        if (formId != null) {
            // 数据处理
            CompletableFuture.runAsync(() -> {
                try {
                    Thread.sleep(1000*30); // 暂停1分钟
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                scholarshipApplicantService.processDataHandler(formId);
                System.out.println("执行完成");
            });
        }
    }
}