package com.jeelowcode.module.biz.listener;


import com.jeelowcode.core.framework.service.IDbformDataService;
import com.jeelowcode.service.bpm.controller.vo.instance.BpmProcessInstanceRespVO;
import com.jeelowcode.service.bpm.service.IBpmProcessInstanceService;
import org.flowable.engine.delegate.TaskListener;
import org.flowable.task.service.delegate.DelegateTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

//任务监听器
@Component
public class DemoDelegateClassTaskListener implements TaskListener {

    @Autowired
    private IBpmProcessInstanceService processInstanceService;

    @Autowired
    private IDbformDataService dbformDataService;

    private static DemoDelegateClassTaskListener AU;

    @PostConstruct
    public void init(){
        AU = this;
    }

    @Override
    public void notify(DelegateTask delegateTask) {
        Map<String,Object> map = new HashMap<>();
        //流程实例id
        String processInstanceId = delegateTask.getProcessInstanceId();
        BpmProcessInstanceRespVO vo = AU.processInstanceService.getProcessInstanceVO(processInstanceId);
        //获取到的自定义表单数据id
        String id = vo.getFormVariables().get("id").toString();
        //数据表id
        Long formId = vo.getProcessDefinition().getFormId();
        //实例状态 （1:审批中, 2：审批通过, 3:审批不通过, 4:已取消）
        Integer status = vo.getStatus();
//        Map<String,Object> json = new HashMap<>();
//        json.put("status", status);
//        AU.dbformDataService.editJsonData(formId, new JSONObject(json));
//        AU.dbformDataService.update("sc_zuoye",id,json);
    }
}
