package com.mq.zhongzhuanzhuangche.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/14 0014 16:51
 * 文件名称 ZhiCangDao
 * 说明:
 **/
public class ZhongZhuanZhuangCheDao extends BaseDao<ZhongZhuanZhuangCheEntity> {

    private ZhongZhuanZhuangCheDao() {
    }

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

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

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

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

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