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 implements DevicePowerMonthDao { @Override protected Class 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 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 list = this.getSession().createSQLQuery(sql) .setParameter(0, macAddress) .setParameter(1, year) .setParameter(2, month) .setResultTransformer(Transformers.aliasToBean(DevicePowerMonth.class)).list(); return list.get(0); } }