package com.yem.wm.es.storagetrans.convert;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.ExtendedDataEntity;
import kd.bos.entity.botp.plugin.AbstractConvertPlugIn;
import kd.bos.entity.botp.plugin.args.AfterConvertEventArgs;

import java.math.BigDecimal;

/**
 * @author 张立攀
 * @version 1.0
 * @description   储运托单 下推装箱单
 * @date 2023-08-31 17:20
 */
public class StorgeTransToEncaseMentConvert extends AbstractConvertPlugIn {
    @Override
    public void afterConvert(AfterConvertEventArgs e) {
        String targetName = this.getTgtMainType().getName();
//        String name = this.getSrcMainType().getName();
        ExtendedDataEntity[] findByEntityKeys = e.getTargetExtDataEntitySet().FindByEntityKey(targetName);
        for(ExtendedDataEntity findByEntityKey : findByEntityKeys){
            DynamicObject dataEntity = findByEntityKey.getDataEntity();
            DynamicObjectCollection dynamicObjectCollection = dataEntity.getDynamicObjectCollection("yem_im_materialinfo_mi");
            DynamicObjectCollection collection = dataEntity.getDynamicObjectCollection("yem_im_packinginfor_pi");
            int rowCount = 1;
            for(DynamicObject temp:dynamicObjectCollection){
                DynamicObject yemBigcabinet = temp.getDynamicObject("yem_bigcabinet");
                BigDecimal yemBigcabinetnumbers = temp.getBigDecimal("yem_bigcabinetnumbers");
                DynamicObject yemmincabinet = temp.getDynamicObject("yem_mincabinet");
                BigDecimal yemmincabinetnumbers = temp.getBigDecimal("yem_mincabinetnumbers");
                for(int i = 1 ; i <= yemBigcabinetnumbers.intValue() ; i ++){
                    DynamicObject dynamicObject1 = collection.addNew();
                    dynamicObject1.set("yem_cabinettype",yemBigcabinet);
                    dynamicObject1.set("yem_contnum",String.valueOf(rowCount));
                    dynamicObject1.set("yem_wholecube", yemBigcabinet.getBigDecimal("yem_volume"));
                    rowCount ++;
                }
                for(int i = 1 ; i <= yemmincabinetnumbers.intValue() ; i ++){
                    DynamicObject dynamicObject = collection.addNew();
                    dynamicObject.set("yem_cabinettype",yemmincabinet);
                    dynamicObject.set("yem_contnum",String.valueOf(rowCount));
                    dynamicObject.set("yem_wholecube", yemmincabinet.getBigDecimal("yem_volume"));
                    rowCount ++;
                }
            }
        }
    }
}
