package nckd.jimin.jyyy.hr.tsrsc.plugin.operate;


import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.PreparePropertysEventArgs;
import kd.bos.entity.plugin.args.BeginOperationTransactionArgs;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.orm.query.QFilter;
import kd.swc.hsbp.business.servicehelper.SWCDataServiceHelper;

import java.util.ArrayList;
import java.util.List;


/**
 * Module           :人才供应云-招聘直通车-首页-年度招聘计划
 * Description      :审批流按钮操作插件
 * @author Tyx
 * @date  2025/5/8
 * 标识 nckd_yearapply
 */


public class YearCrApplyPlanWorkFlowPlugin extends AbstractOperationServicePlugIn {

    private static Log logger = LogFactory.getLog(YearCrApplyPlanWorkFlowPlugin.class);


    public void beginOperationTransaction(BeginOperationTransactionArgs args) {
        super.beginOperationTransaction(args);
        DynamicObject[] regBillObjs = args.getDataEntities();

        SWCDataServiceHelper helper = new SWCDataServiceHelper("nckd_yearcasreplan");

        switch (args.getOperationKey()) {
            case "wfauditnotpass":
                this.setApproveStatus(regBillObjs, "E");
                break;
            case "wfrejecttosubmit":
                this.setApproveStatus(regBillObjs, "A");
                break;
            case "wfauditing":
                this.setApproveStatus(regBillObjs, "D");
                break;
            case "wfauditpass":
                this.setApproveStatus(regBillObjs, "C");
                break;
            default:
                break;
        }
        helper.update(regBillObjs);
    }

    private void setApproveStatus(DynamicObject[] regBillObjs, String billstatus) {
        DynamicObject[] var3 = regBillObjs;
        int var4 = regBillObjs.length;
        for(int var5 = 0; var5 < var4; ++var5) {
            DynamicObject dynamicObject = var3[var5];
            dynamicObject.set("billstatus", billstatus);
        }
    }

    @Override
    public void onPreparePropertys(PreparePropertysEventArgs e) {
        super.onPreparePropertys(e);
        // 提前加载表单里的字段
        List<String> fieldKeys = e.getFieldKeys();
        fieldKeys.addAll(this.billEntityType.getAllFields().keySet());
    }
}

