package org.well.well.manager;


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

import javax.annotation.Resource;
import java.util.List;

@Service
public class DeviceConfigManager extends HibernateEntityDao<DeviceConfig> {


    @Resource
    DeviceManager deviceManager;

    public void updateStatus(String devCode) {
        Device device=deviceManager.getDeviceByDevCode(devCode);
        if(null==device)return;
        Criteria criteria = getSession().createCriteria(DeviceConfig.class);
        criteria.add(Restrictions.eq("deviceId", device.getId()));
        List<DeviceConfig> deviceConfigList = criteria.list();
        for (DeviceConfig deviceConfig : deviceConfigList) {
            deviceConfig.setStatus(true);
            this.save(deviceConfig);
        }
    }



}
