package org.well.well.manager;


import org.well.well.core.hibernate.HibernateEntityDao;
import org.well.well.domain.Device;
import org.well.well.domain.DeviceWell;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DeviceWellManager extends HibernateEntityDao<DeviceWell> {

    public  DeviceWell getDeviceWellByDevice(Device device){
        try {
            Criteria criteria = getSession().createCriteria(DeviceWell.class);
            criteria.add(Restrictions.eq("deviceId", device.getId()));
            criteria.add(Restrictions.eq("valid", true));
            List<DeviceWell> deviceWellList = criteria.list();
            if (deviceWellList != null && deviceWellList.size() > 0)
                return deviceWellList.get(0);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
