package org.well.well.manager;

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

import java.util.Date;
import java.util.List;

@Service
public class DeptManager extends HibernateEntityDao<SysDept> {


    public Criteria getCriteria() {
        return getSession().createCriteria(SysDept.class);
    }


    public void clearOffline(String devCode) {//查找设备状态（1：在线，0：离线）

        Criteria criteria = getSession().createCriteria(Device.class);
        criteria.add(Restrictions.eq("devCode", devCode));
        criteria.add(Restrictions.eq("valid", true));
        criteria.add(Restrictions.eq("onlineState", "0"));
        List<Device> devices = criteria.list();
        for (Device device : devices) {
            device.setOnlineState("1");
            device.setLogtime(new Date());
            save(device);
        }
    }
}