package com.jzdsh.auto.biz;

import com.jfinal.plugin.activerecord.Db;
import com.jzdsh.auto.model.CarCommercial;
import lombok.extern.log4j.Log4j2;

import java.util.List;

/**
 * @ProjectName: auto
 * @Package: com.jzdsh.auto.biz
 * @ClassName: CarCommercialService
 * @Author: Jzdsh
 * @Description: 商用车信息表
 * @Date: 2020/3/24 11:34
 * @Version: 1.0
 */
@Log4j2
public class CarCommercialService {

    /**
     * 品牌去重
     *
     * @return
     */
    public List< String > getGroupBrand( ) {
        try {
            return Db.query("select distinct(brand) from car_commercial ");
        } catch (Exception e) {
            log.info("", e);
        }
        return null;
    }

    /**
     * 厂家去重
     *
     * @return
     */
    public List< String > getGroupFactory( ) {
        try {
            return Db.query("select distinct(factory) from car_commercial ");
        } catch (Exception e) {
            log.info("", e);
        }
        return null;
    }

    /**
     * 销售版本去重
     *
     * @return
     */
    public List< String > getGroupSaleVersion( ) {
        try {
            return Db.query("select distinct(saleVersion) from car_commercial ");
        } catch (Exception e) {
            log.info("", e);
        }
        return null;
    }


    /**
     * 查询 品牌下的所有厂家
     * @param brand
     * @return
     */
    public List< CarCommercial > getByBrand(String brand) {

        try {
            return CarCommercial.dao.find("select  *  from car_commercial where brand = ? group by factory", brand);
        } catch (Exception e) {
            log.info("", e);
        }
        return null;
    }

    public List< CarCommercial> getByBrandFactory(String brand, String name) {

        try {
            return CarCommercial.dao.find("select  *  from car_commercial where brand = ? and factory = ? group by factory", brand,name);
        } catch (Exception e) {
            log.info("", e);
        }
        return null;
    }

    public List< CarCommercial> getByBrandSaleversion(String brand, String saleVersion) {

        try {
            return CarCommercial.dao.find("select  *  from car_commercial where brand = ? and saleVersion = ? group by saleVersion", brand,saleVersion);
        } catch (Exception e) {
            log.info("", e);
        }
        return null;

    }
}
