package nckd.jxccl.hr.gzbb;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.bos.workflow.api.AgentExecution;
import kd.bos.workflow.engine.extitf.IWorkflowPlugin;
import kd.sdk.plugin.Plugin;

/**
 * nckd_sjtbrw_gzbb
 * 流程被驳回时变更任务状态
 * 数据填报任务提交》进入节点时执行时》驳回进入时
 * duanyuqi
 * */
public class SjtbSubmitWorkflowPlugin implements Plugin, IWorkflowPlugin {

    @Override
    public void notify(AgentExecution execution) {
        String businessKey = execution.getBusinessKey();
        String entityNumber = execution.getEntityNumber();
        if ("nckd_sjtbrw".equals(entityNumber)) {
            Long pkValue = Long.parseLong(businessKey);
            DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(pkValue, "nckd_sjtbrw");
            String nckd_rwzt = dynamicObject.getString("nckd_rwzt");
            if (!"3".equals(nckd_rwzt)) {// 没有作废
                dynamicObject.set("nckd_rwzt", "1");// 待上报
                SaveServiceHelper.save(new DynamicObject[]{dynamicObject});
            }
        }
        IWorkflowPlugin.super.notify(execution);
    }

    @Override
    public void notifyByWithdraw(AgentExecution execution) {
        IWorkflowPlugin.super.notifyByWithdraw(execution);
    }
}
