package com.jzdsh.auto.biz;

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

import java.util.List;

/**
 * @ProjectName: auto
 * @Package: com.jzdsh.auto.biz
 * @ClassName: CarSendanService
 * @Author: Jzdsh
 * @Description: 小型车数据信息表
 * @Date: 2020/3/24 15:20
 * @Version: 1.0
 */
@Log4j2
public class CarSendanService {

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

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

    /**
     * 系列去重
     *
     * @return
     */
    public List< String > getGroupSeries( ) {
        try {
            return Db.query("select distinct(series) from car_sedan");
        } catch (Exception e) {
            log.info("", e);
        }
        return null;
    }

    /**
     * 根据品牌查厂家
     *
     * @param brand
     * @return
     */
    public List< CarSedan > getByBrand(String brand) {
        try {
            return CarSedan.dao.find("select * from car_sedan where brand = ? group by factory", brand);
        } catch (Exception e) {
            log.info("", e);
        }
        return null;
    }

    public List< CarSedan > getByBrandFactory(String brand, String factory) {
        try {
            return CarSedan.dao.find("select * from car_sedan where brand = ? and factory = ? group by factory", brand, factory);
        } catch (Exception e) {
            log.info("", e);
        }
        return null;
    }

    public List< CarSedan > getByBrandSeries(String brand, String series) {
        try {
            return CarSedan.dao.find("select * from car_sedan where brand = ? and series = ? group by series", brand, series);
        } catch (Exception e) {
            log.info("", e);
        }
        return null;
    }
}
