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

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

import static com.yem.wm.es.salesorder.utils.SalesOrderUtils.getCustomShipDetailsBillno;

/**
 * @Description 外销合同下推发运明细
 * @Date 2024/1/29 17:30
 * @Created by ZZSLL
 */

public class SalesOrderToShipDetailsConvert extends AbstractConvertPlugIn
{
    @Override
    public void afterConvert(AfterConvertEventArgs e)
    {
        super.afterConvert(e);
        String targetName = this.getTgtMainType().getName();
        ExtendedDataEntity[] entities = e.getTargetExtDataEntitySet().FindByEntityKey(targetName);
        for (ExtendedDataEntity entity : entities) {
            DynamicObject dataEntity = entity.getDataEntity();
            long sourcebillid = dataEntity.getLong("yem_sourcebillid");
            DynamicObject single = BusinessDataServiceHelper.loadSingle(sourcebillid, "yem_es_salesorder");
            String billno = getCustomShipDetailsBillno(single);
            dataEntity.set("billno", billno);
        }
    }
}
