package com.yem.em.bd.etcmanualim.op;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.PreparePropertysEventArgs;
import kd.bos.entity.plugin.args.EndOperationTransactionArgs;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;

import java.util.List;

/**
 * @author 夜子
 * @ClassName 设备导入 反审核插件
 * @description: TODO
 * @date 2023年08月29日
 * @version: 1.0
 */
public class EtcmanualImportUnAuditOp extends AbstractOperationServicePlugIn {

    @Override
    public void onPreparePropertys(PreparePropertysEventArgs e) {
        super.onPreparePropertys(e);
        List<String> keys = e.getFieldKeys();
        keys.add("yem_importstatus");
        keys.add("yem_componentsentity.yem_syncstatus");
        keys.add("yem_partentity.yem_syncstatusd");

    }

    public void endOperationTransaction(EndOperationTransactionArgs e) {
        if (e.getDataEntities() != null && e.getDataEntities().length != 0) {
            DynamicObject[] bills = e.getDataEntities();
            for (DynamicObject bill : bills) {
                bill = BusinessDataServiceHelper.loadSingle(bill.getPkValue(), bill.getDynamicObjectType().getName());
                bill.set("yem_importstatus","N");
                DynamicObjectCollection componentsentityCol=  bill.getDynamicObjectCollection("yem_componentsentity");
                for(DynamicObject componentsentity:componentsentityCol){
                    componentsentity.set("yem_syncstatus","N");
                }
                DynamicObjectCollection partentityCol=  bill.getDynamicObjectCollection("yem_partentity");
                for(DynamicObject partentity:partentityCol){
                    partentity.set("yem_syncstatusd","N");
                }
                SaveServiceHelper.update(bill);
            }
        }
    }
}
