ifishSocket/src/main/java/com/ifish/daoImpl/DevicePowerMonthDaoImpl.java

68 lines
1.8 KiB
Java

package com.ifish.daoImpl;
import com.ifish.dao.DevicePowerMonthDao;
import com.ifish.entity.DevicePowerMonth;
import com.ifish.enums.BooleanEnum;
import com.ifish.hibernate.HibernateBaseDao;
import org.hibernate.criterion.Restrictions;
import org.hibernate.transform.Transformers;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @ClassName: DeviceDaoImpl
* @Description: TODO
* @author ggw
*
*/
@Repository
public class DevicePowerMonthDaoImpl extends HibernateBaseDao<DevicePowerMonth, Integer> implements DevicePowerMonthDao {
@Override
protected Class<DevicePowerMonth> getEntityClass() {
return DevicePowerMonth.class;
}
@Override
public DevicePowerMonth findById(Integer id) {
return this.get(id);
}
@Override
public DevicePowerMonth getUniqueByProperty(String property, Object value) {
return this.findUniqueByProperty(Restrictions.eq(property, value));
}
@Override
public DevicePowerMonth save(DevicePowerMonth device) {
this.getSession().save(device);
return device;
}
@Override
public DevicePowerMonth update(DevicePowerMonth device) {
this.getSession().update(device);
return device;
}
@Override
public List<DevicePowerMonth> getByProperty(String property, Object value) {
return this.findByProperty(Restrictions.eq(property, value));
}
@Override
public DevicePowerMonth findByDate(String macAddress, String year, String month) {
String sql = "select id,mac_address macAddress,year_s yearS,month_s monthS,power from tbl_device_power_month where mac_address = ? and year_s = ? and month_s = ? ";
List<DevicePowerMonth> list = this.getSession().createSQLQuery(sql)
.setParameter(0, macAddress)
.setParameter(1, year)
.setParameter(2, month)
.setResultTransformer(Transformers.aliasToBean(DevicePowerMonth.class)).list();
return list.get(0);
}
}