package com.mq.zhuangchefaka.db;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.mq.mylibrary.db.BaseDao;
import com.mq.mylibrary.tool.HappySQL;
import com.mq.mylibrary.tool.StringTool;

import java.util.List;


/**
 * 创建人 mQ
 * 创建时间 2019/8/19 0019 10:40
 * 文件名称 ZhuangCheDao
 * 说明:
 **/
public class ZhuangCheDao extends BaseDao<ZhuangCheEntity> {

    private ZhuangCheDao() {
    }


    private static class SingleHelper {
        private static final ZhuangCheDao INSTANCE = new ZhuangCheDao();
    }

    public static ZhuangCheDao get() {
        return SingleHelper.INSTANCE;
    }

    @Override
    public String getTableName() {
        return "zhuang_che_fa_ka";
    }


    public List<ZhuangCheEntity> getListByCar(SQLiteDatabase db, String car) {
        Cursor cursor;
        if (StringTool.isEmpty(car)) {
            cursor = db.rawQuery("select * from " + getTableName() +
                    " order by load_time desc", null);
        } else {
            cursor = db.rawQuery("select * from " + getTableName() +
                    " where car = '" + car + "' order by load_time desc", null);
        }
        return HappySQL.cursor2VOList(cursor, ZhuangCheEntity.class);
    }

    public List<ZhuangCheEntity> getCarList(SQLiteDatabase db) {
        String sql = "SELECT  * FROM " + getTableName() + " group by car order by load_time desc";
        Cursor cursor = db.rawQuery(sql, null);
        return HappySQL.cursor2VOList(cursor, ZhuangCheEntity.class);
    }

}
