package com.yem.ia.intebilllogon.op;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.PreparePropertysEventArgs;
import kd.bos.entity.plugin.args.BeforeOperationArgs;
import kd.bos.servicehelper.operation.SaveServiceHelper;

import java.util.List;

public class IntebilllogonEnableOp extends AbstractOperationServicePlugIn {
    @Override
    public void onPreparePropertys(PreparePropertysEventArgs e) {
        List<String> keys = e.getFieldKeys();
        keys.add("yem_isdisable");
        super.onPreparePropertys(e);
    }


    @Override
    public void beforeExecuteOperationTransaction(BeforeOperationArgs e) {
        super.beforeExecuteOperationTransaction(e);
        DynamicObject[] dataEntities = e.getDataEntities();
        String key = e.getOperationKey();
        if ("enable".equals(key)||"disenable".equals(key)) {
            for (DynamicObject obj : dataEntities) {
                if("enable".equals(key))obj.set("yem_isdisable",false);
                if("disenable".equals(key))obj.set("yem_isdisable",true);
                SaveServiceHelper.update(obj);
            }
        }
    }
}
