package com.mq.zhongzhuanxiezai.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 XieZaiDao extends BaseDao<XieZaiEntity> {

    private XieZaiDao() {
    }

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

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

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

    public List<XieZaiEntity> 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, XieZaiEntity.class);
    }

    public List<XieZaiEntity> 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, XieZaiEntity.class);
    }
}
