package com.awspaas.user.apps.bnbm.datalinkup.util;

import com.awspaas.user.apps.bnbm.datalinkup.service.impl.SaleDataSyncServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 采购模块工具类
 */
public class PurchaseUtil {
    private static final Logger LOGGER = LoggerFactory.getLogger(PurchaseUtil.class);

    /**
     * 判断物料名称所属分类
     * @param bkgs 板块名称
     * @param wlmc 物料名称
     * @param wlbm 物料编码
     * @param jldw 计量单位
     * @param djhyf 单价含运费
     * @param wlfl 物料分类
     * @return newWlmc 物料名称
     */
    public static String materialClassificationFiltering(String bkgs, String wlmc, String wlbm, String jldw, Double djhyf, String wlfl) {
        String newWlmc = "";
        try {
            // 脱硫石膏
            if (("龙牌".equals(bkgs) || "梦牌".equals(bkgs) || "泰山石膏".equals(bkgs)) && wlmc.contains("脱硫石膏")) {
                newWlmc = "脱硫石膏";
            }
            // 镀锌带钢
            else if ("泰山石膏".equals(bkgs) && wlmc.contains("镀锌带钢")) {
                newWlmc = "镀锌带钢";
            } else if (("龙牌".equals(bkgs) || "梦牌".equals(bkgs))
                    && (wlmc.equals("轻钢镀锌带钢") || wlmc.equals("镀锌带钢"))) {
                newWlmc = "镀锌带钢";
            }
            // 煤炭
            else if (("龙牌".equals(bkgs) || "梦牌".equals(bkgs))
                    && (wlmc.contains("煤炭") || wlmc.contains("籽煤") || wlmc.contains("褐煤"))) {
                newWlmc = "煤炭";
            } else if ("泰山石膏".equals(bkgs) && (wlmc.contains("原煤") || wlmc.contains("水洗精煤") || wlmc.contains("褐煤"))) {
                newWlmc = "煤炭";
            }
            // 护面纸
            else if (("龙牌".equals(bkgs) || "泰山石膏".equals(bkgs))
                    && wlmc.contains("护面纸")) {
                newWlmc = "护面纸";
            }
            // 乳液
            else if ("北新嘉宝莉".equals(bkgs) && wlbm.startsWith("11M")) {
                newWlmc = "乳液";
            } else if ("北新防水".equals(bkgs) && wlbm.startsWith("5070201")) {
                newWlmc = "乳液";
            } else if ("北新涂料".equals(bkgs) && wlbm.contains("10114137")) {
                newWlmc = "乳液";
            }
            // 钛白粉
            else if (("北新防水".equals(bkgs) || "北新涂料".equals(bkgs)) && wlmc.contains("钛白粉")) {
                newWlmc = "钛白粉";
            } else if ("北新嘉宝莉".equals(bkgs) && wlbm.startsWith("11PT")) {
                newWlmc = "钛白粉";
            }
            // 重钙
            else if (("北新防水".equals(bkgs) || "北新涂料".equals(bkgs)) && wlmc.contains("重钙")) {
                newWlmc = "重钙";
            } else if ("北新嘉宝莉".equals(bkgs) && wlbm.startsWith("11TD")) {
                newWlmc = "重钙";
            }
            // 包装袋
            else if ("龙牌".equals(bkgs) && jldw.contains("条") && (wlmc.equals("编织袋") || wlmc.equals("阀口袋") || wlmc.equals("两纸一膜")
                    || wlmc.contains("三纸一膜") || wlmc.contains("包装袋") || wlmc.contains("包装"))) {
                newWlmc = "包装袋";
            } else if ("泰山石膏".equals(bkgs) && ( jldw.contains("条") || jldw.contains("根")) && (wlmc.contains("编织袋") || wlmc.contains("纸袋"))) {
                newWlmc = "包装袋";
            } else if ("梦牌".equals(bkgs) && jldw.contains("条") && wlmc.contains("包装袋") && (!wlbm.contains("000000000024499") && !wlbm.contains("102327250000199"))) {
                newWlmc = "包装袋";
            } else if ("北新防水".equals(bkgs) && ( jldw.contains("条") || jldw.contains("个")) && (wlmc.contains("包装袋") || wlmc.contains("阀口袋"))
                    && (!wlbm.contains("60303000157001") && !wlbm.contains("60804000151117") && !wlbm.contains("60303000028798")
                    && !wlbm.contains("60303000028800") && !wlbm.contains("60303000028811") && !wlbm.contains("60804000151102")
                    && !wlbm.contains("50603010005") && !wlbm.contains("50603010006"))
            ) {
                newWlmc = "包装袋";
            } else if ("北新涂料".equals(bkgs) && jldw.contains("只") && wlmc.contains("包装袋")) {
                newWlmc = "包装袋";
            } else if ("北新嘉宝莉".equals(bkgs) && ( jldw.contains("条") || jldw.contains("个")) && (wlmc.contains("阀口袋") || wlmc.contains("腻子粉袋") || wlmc.contains("阀口纸袋")
                    || wlmc.equals("纸袋") || wlmc.equals("编织袋"))) {
                newWlmc = "包装袋";
            }
            // 包装桶
            else if ("龙牌".equals(bkgs) && wlbm.contains("1023411")) {
                newWlmc = "包装桶";
            } else if ("北新防水".equals(bkgs) && wlmc.contains("桶") && jldw.contains("个")) {
                newWlmc = "包装桶";
            } else if ("北新嘉宝莉".equals(bkgs) && wlmc.contains("盖") && !wlmc.contains("桶") && !wlmc.contains("罐") && djhyf < 3.5) {
                newWlmc = "桶盖";
            } else if ("北新嘉宝莉".equals(bkgs) && wlmc.contains("桶身") && jldw.equals("个")) {
                newWlmc = "包装桶";
            } else if ("北新嘉宝莉".equals(bkgs) && wlmc.contains("桶") && !wlmc.contains("桶身") && djhyf>3.5 && jldw.equals("个")) {
                newWlmc = "包装桶";
            } else if ("北新嘉宝莉".equals(bkgs) && wlmc.contains("罐") && !wlmc.contains("箱") && jldw.equals("个")) {
                newWlmc = "包装桶";
            } else {
                newWlmc = wlmc;
            }

        }catch (Exception e){
            LOGGER.info("物料分类报错：{}\n{}",e.getMessage(),e);
            e.printStackTrace();
        }
        return newWlmc;
    }
}
