package yem.wmc.ydn.formplugin.form;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.datamodel.IDataModel;
import kd.bos.form.IFormView;
import kd.bos.form.events.AfterDoOperationEventArgs;
import kd.bos.form.plugin.AbstractFormPlugin;
import yem.wmc.ydn.utils.SeaTransportationUtils;

import java.util.Date;

/**
 * @author 金亮
 * @date 2024/5/6 14:22
 * @relevantfile 提单（yem_ydn_testbilllad）
 * @description
 * @versions 1.0
 */
public class TestBillladEdit extends AbstractFormPlugin {
    @Override
    public void afterDoOperation(AfterDoOperationEventArgs e) {
        super.afterDoOperation(e);
        String key = e.getOperateKey();
        IDataModel model = this.getModel();
        IFormView view = this.getView();
        DynamicObject bill = model.getDataEntity(true);
        switch (key){
            case "portofcall": //船舶历史挂港
                Date yemPoldate = bill.getDate("yem_poldate");//启运时间(开始时间)
                Date yemDtpdate = bill.getDate("yem_dtpdate");//到港时间(结束时间)
                String yemMmsi = bill.getString("yem_mmsi");//MMSI号
                view.showMessage(SeaTransportationUtils.getPortofcall(yemPoldate, yemDtpdate, yemMmsi));
                break;
            case "portdatabooking"://港区数据订阅
                Object pkValue = bill.getPkValue();//公司自定义主键
                String yemReferenceno = bill.getString("yem_referenceno");//港区提单/订舱号
                String yemIeid = bill.getString("yem_ieid");//进出口标识
                DynamicObject yemPortcd = bill.getDynamicObject("yem_portcd");//云当港口代码
                view.showMessage(SeaTransportationUtils.getPortdatabooking(pkValue, yemReferenceno, yemIeid, yemPortcd));
                break;
            case "portdata"://港区数据订阅下载
                String yemReferencenoPO = bill.getString("yem_referenceno");//港区提单/订舱号
                DynamicObject yemPortcdPO = bill.getDynamicObject("yem_portcd");//云当港口代码
                view.showMessage(SeaTransportationUtils.getPortdata(yemReferencenoPO,yemPortcdPO));
                break;
            case "shiptracking"://海运跟踪订阅
                Object pkValueSH = bill.getPkValue();//keyid
                String yemReferencenoSH = bill.getString("yem_referenceno");//港区提单/订舱号
                String yemCtnrnoSH = bill.getString("yem_ctnrno");//上传订阅的箱号
                String yemPortcdSH = bill.getString("yem_carriercd");//船东代码
                //DynamicObject yemPortcdSH = bill.getDynamicObject("yem_portcd");//船东代码（云当代码）
                DynamicObject yemPolSH = bill.getDynamicObject("yem_pol");//启运港
                DynamicObject yemDtpSH = bill.getDynamicObject("yem_dtp");//目的港
                view.showMessage(SeaTransportationUtils.getShiptracking(pkValueSH,yemReferencenoSH,yemCtnrnoSH,yemPortcdSH,yemPolSH,yemDtpSH));
                break;
            case "shipdownload"://海运跟踪
                Object pkValueLO = bill.getPkValue();//keyid
                String yemReferencenoLO = bill.getString("yem_referenceno");//港区提单/订舱号
                String yemCtnrnoLO = bill.getString("yem_ctnrno");//上传订阅的箱号
                String yemPortcdLO = bill.getString("yem_carriercd");//船东代码
                //DynamicObject yemPortcdLO = bill.getDynamicObject("yem_portcd");//船东代码（云当代码）
                DynamicObject yemPolLO = bill.getDynamicObject("yem_pol");//启运港
                DynamicObject yemDtpLO = bill.getDynamicObject("yem_dtp");//目的港
                view.showMessage(SeaTransportationUtils.getShipdownload(pkValueLO,yemReferencenoLO,yemCtnrnoLO,yemPortcdLO,yemPolLO,yemDtpLO));
                break;
            default :
                break;
        }
    }
}
