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 YearCrApplyWorkFlowPlugin extends AbstractOperationServicePlugIn {

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

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

    public void beginOperationTransaction(BeginOperationTransactionArgs args) {
        super.beginOperationTransaction(args);
        DynamicObject[] regBillObjs = args.getDataEntities();
//        List<Long> billIdList = new ArrayList(10);
//        DynamicObject[] var5 = regBillObjs;
//        int var6 = regBillObjs.length;
//
//        for(int var7 = 0; var7 < var6; ++var7) {
//            DynamicObject dynamicObject = var5[var7];
//            long id = dynamicObject.getLong("id");
//            billIdList.add(id);
//        }

        SWCDataServiceHelper helper = new SWCDataServiceHelper("nckd_yearapply");
//        QFilter filter = new QFilter("id", "in", billIdList);
//        DynamicObject[] needUpdateBillDy = helper.query("id,billstatus", new QFilter[]{filter});

        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.save(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);
        }
    }
}

