package com.sifang.modules.customer.utils;

import com.jfinal.plugin.activerecord.Db;
import com.sifang.modules.sys.util.SqlBuilder;

import java.math.BigDecimal;


public class DeliverOrderUtils {


    public static Long findOrderCount(String traderId){
        SqlBuilder sql = new SqlBuilder();
        sql.line("SELECT COUNT(*) FROM crm_supply_material_deliver_order WHERE trader_id = ? AND type IN ('1','2','4') AND status NOT IN ('0','8','10') AND order_examine_status in ('1','3') ",traderId);
        Long queryLong = Db.queryLong(sql.build(), sql.params());
        if (queryLong == 0L){
            SqlBuilder sql2 = new SqlBuilder();
            sql2.line("SELECT yk_deliver_total_capacity FROM crm_trader_account WHERE trader_id = ? ",traderId);
            long longValue = Db.queryBigDecimal(sql2.build(), sql2.params()).longValue();
            return longValue;
        }
        return queryLong;
    }

    public static BigDecimal findCustomerEntrydesign(String entryIds){
        SqlBuilder sql = new SqlBuilder();
        sql.inst("select sum(design_capacity) design_capacity from crm_customer_entry WHERE id in ",entryIds.split(","));

        return Db.queryBigDecimal(sql.build(),sql.params());
    }

    /**
     * 获取代理商已发货总量
    */
    public static BigDecimal findTraderAmount(String traderId){
        SqlBuilder sql = new SqlBuilder();
        sql.line("select sum(d.sales_price*d.out_amount) as fhAmount from crm_supply_material_deliver_order_detail d")
                .line("left join crm_supply_material_deliver_order o on o.id=d.main_id")
                .line("where d.`status`='0'  and o.status in('6','7')")
                .line(" and o.trader_id=?",traderId);

        return Db.queryBigDecimal(sql.build(),sql.params());
    }

    /**
     * 获取已安装量 ----已安装验收电站容量（MW）*1.5*1000000/10000
    */


    /**
     * 获取已并网量  ---已并网验收电站容量（MW）*1.5*1000000/10000
    */




}
