package com.palmnest.dao.repair.impl;

import com.palmnest.dao.hibernate.GenericDaoHibernate;
import com.palmnest.dao.repair.RepairOperateRecordDao;
import com.palmnest.model.repair.RepairOperateRecord;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("repairOperateRecordDao")
public class RepairOperateRecordDaoImpl extends GenericDaoHibernate<RepairOperateRecord, Long> implements RepairOperateRecordDao {

	public RepairOperateRecordDaoImpl() {
		super(RepairOperateRecord.class);
	}

	@Override
	public RepairOperateRecord findBy(Long billId, Integer operateType) {
		String                    strHql = "from RepairOperateRecord where repairBillId = ? and operateType = ? order by createTime desc ";
		List<RepairOperateRecord> list   = getSession().createQuery(strHql).setLong(0, billId).setInteger(1, operateType).list();
		if (list.size() > 0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<RepairOperateRecord> findBy(Long billId) {
		String                    strHql = "from RepairOperateRecord where repairBillId = ?  order by createTime desc ";
		List<RepairOperateRecord> list   = getSession().createQuery(strHql).setLong(0, billId).list();
		return list;
	}

}
