package com.yem.wm.sys.utils;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.dataentity.metadata.dynamicobject.DynamicObjectType;

/**
 * @author zhouc
 * @date 2024/1/25 17:33
 * @className SpecialProcessingHelper
 * @description 处理特殊数据逻辑公共类
 */
public class SpecialProcessingHelper {

    /**
     * 单据头特殊字段处理
     */
    public static void PrimaryData(DynamicObject to,String name, DynamicObject dataEntity) {
        String Typename = to.getDataEntityType().getName();
        if("yem_im_csrcreditline_inh".equals(Typename)){
            if ("yem_replylimit".equals(name)) {
                to.set("yem_orireplylimit", dataEntity.getBigDecimal("yem_replylimit"));
            }
        }
    }

    /**
     * 单据体特殊逻辑处理
     *
     * @param toType
     * @param to
     */
    public static void PrimaryInformation(DynamicObjectType toType, DynamicObject from,DynamicObject to) {
//        String name = toType.getParent().getName();
        if (toType.toString().equals("yem_pricelibrary_e")) {
            pricelibrary(to);
        }
        if (toType.toString().equals("yem_es_xsalesorder")) {
            xsalesorder(from,to);
        }
    }

    /**
     * 价格库分录增加源单信息
     *
     * @param dataEntity
     */
    public static void pricelibrary(DynamicObject dataEntity) {
        String name = dataEntity.getDataEntityType().getName();
        if ("yem_basicmodel".equals(name)) {
            //FOB（青岛）价
            dataEntity.set("yem_xpricefob", dataEntity.getBigDecimal("yem_pricefob"));
            //外贸价
            dataEntity.set("yem_xforeigntradeprice", dataEntity.getBigDecimal("yem_foreigntradeprice"));
        }
        //可选装
        if ("yem_optional".equals(name)) {
            //加装销售定价
            dataEntity.set("yem_xsalesmarkup_o", dataEntity.getBigDecimal("yem_salesmarkup_o"));
        }
        //可替换
        if ("yem_replaceable".equals(name)) {
            //替换销售定价
            dataEntity.set("yem_xsalesprice_re", dataEntity.getBigDecimal("yem_salesprice_re"));
            //替换销售加价
            dataEntity.set("yem_xsalesmarkup_re", dataEntity.getBigDecimal("yem_salesmarkup_re"));
        }
        //可加装
        if ("yem_retrofitting".equals(name)) {
            //加装销售定价
            dataEntity.set("yem_xsalesprice_rt", dataEntity.getBigDecimal("yem_salesprice_rt"));
            //原加装销售加价
            dataEntity.set("yem_xsalesmarkup_rt", dataEntity.getBigDecimal("yem_salesmarkup_rt"));
        }
        //配件信息
        if ("yem_accessory".equals(name)) {
            dataEntity.set("yem_xstandsalesprice", dataEntity.getBigDecimal("yem_standsalesprice"));
        }
    }

    /**
     * 外销合同变更单
     * @param dataEntity
     */
    public static  void xsalesorder(DynamicObject from,DynamicObject dataEntity){
        String name = dataEntity.getDataEntityType().getName();
        if("yem_es_materialinfo".equals(name)){
            dataEntity.set("yem_sourceentryid", from.getLong("id"));
        }
    }
}
