package org.eimhe.dao; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.eimhe.HibernateSessionFactory; import org.hibernate.HibernateException; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.Transaction; public class DayMachineInfoDao extends AbstractDao { private Session session; private Transaction tx; public List findByYearAndMonthAndDayAndPowerPlantIdAndMachineNo(String year,String month,String day,long powerPlantId,long machineNo){ List objects=null; try{ startOperation(); Query query=session.createQuery("from DayMachineInfo d where d.id.year="+year+" and d.id.month="+month+" and d.id.day="+day+ " and d.id.powerPlantId="+powerPlantId+" and d.id.machineNo="+machineNo); objects=query.list(); tx.commit(); }catch(HibernateException e){ handleException(e); }finally{ session.close(); } return objects; } public List findReturnPeriodIdAndTotalContractAndAdjustAndRealTotalContract(String year,String month,String day,long powerPlantId,long machineNo){ List objects=null; try{ startOperation(); Query query=session.createQuery("select d.id.periodId,d.dayMachineContractQuantity,d.dayMachineRealtimeAdjustCapacity,"+ " d.dayMachineContractQuantity+d.dayMachineRealtimeAdjustCapacity as realTotalContract" + " from DayMachineInfo d where d.id.year=:year and d.id.month=:month and d.id.day=:day"+ " and d.id.powerPlantId=:powerPlantId and d.id.machineNo=:machineNo"); query.setString("year", year); query.setString("month", month); query.setString("day", day); query.setString("powerPlantId", String.valueOf(powerPlantId)); query.setString("machineNo", String.valueOf(machineNo)); objects=query.list(); tx.commit(); }catch(HibernateException e){ handleException(e); }finally{ session.close(); } return objects; } public List findReturnDayAndMonthContract(String year,String month,long powerPlantId,long machineNo){ List objects=null; try{ startOperation(); Query query=session.createQuery("select d.id.day,sum(d.dayMachineDecomposeMonthBidQuantity) as monthContract"+ " from DayMachineInfo d where d.id.year=:year and d.id.month=:month"+ " and d.id.powerPlantId=:powerPlantId and d.id.machineNo=:machineNo"+ " group by d.id.day"); query.setString("year", year); query.setString("month", month); query.setString("powerPlantId", String.valueOf(powerPlantId)); query.setString("machineNo", String.valueOf(machineNo)); objects=query.list(); tx.commit(); }catch(HibernateException e){ handleException(e); }finally{ session.close(); } return objects; } public List findReturnDayAndYearContractAndAdjustAndRealContract(String year,String month,long powerPlantId,long machineNo){ List objects=null; try{ startOperation(); Query query=session.createQuery("select d.id.day,sum(d.dayMachineDecomposeYearContractQuantity) as yearContract,"+ " sum(d.dayMachineRealtimeAdjustCapacity) as adjust,"+ " sum(d.dayMachineDecomposeYearContractQuantity)+sum(d.dayMachineRealtimeAdjustCapacity) as realContract"+ " from DayMachineInfo d where d.id.year=:year and d.id.month=:month"+ " and d.id.powerPlantId=:powerPlantId and d.id.machineNo=:machineNo"+ " group by d.id.day"); query.setString("year", year); query.setString("month", month); query.setString("powerPlantId", String.valueOf(powerPlantId)); query.setString("machineNo", String.valueOf(machineNo)); objects=query.list(); tx.commit(); }catch(HibernateException e){ handleException(e); }finally{ session.close(); } return objects; } public List findDayMachineInfoAndYearMachineInfoReturnMonthAndDayAndYearContractAndAdjustAndRealContract(String year,String month,long powerPlantId,long machineNo){ List objects=null; try{ startOperation(); Query query=session.createQuery("select d.id.month,d.id.day,sum(d.dayMachineDecomposeYearContractQuantity) as yearContract,"+ " sum(d.dayMachineRealtimeAdjustCapacity) as adjust,"+ " sum(d.dayMachineDecomposeYearContractQuantity)+sum(d.dayMachineRealtimeAdjustCapacity) as realContract"+ " from DayMachineInfo d where d.id.year=:year and d.id.month<=:month"+ " and d.id.powerPlantId=:powerPlantId and d.id.machineNo=:machineNo"+ " group by d.id.month,d.id.day"); query.setString("year", year); query.setString("month", month); query.setString("powerPlantId", String.valueOf(powerPlantId)); query.setString("machineNo", String.valueOf(machineNo)); objects=query.list(); // tx.commit(); query=session.createQuery("select '9999', '-1000',-10L,-10L,y.yearMachineBaseContractQuantity "+ " from YearMachineInfo y "+ " where y.id.year=:year and y.id.powerPlantId=:powerPlantId and y.id.machineNo=:machineNo"); query.setString("year", year); query.setString("powerPlantId", String.valueOf(powerPlantId)); query.setString("machineNo", String.valueOf(machineNo)); objects.add(query.list().iterator().next()); tx.commit(); }catch(HibernateException e){ handleException(e); }finally{ session.close(); } return objects; } public List findYearMachineInfoByYearAndPowerPlantIdAndMachineNo(String year,long powerPlantId,long machineNo){ List objects=new ArrayList(); try{ startOperation(); Query query=session.createQuery("select '9999', '-1000',-10L,-10L,y.yearMachineBaseContractQuantity "+ " from YearMachineInfo y "+ " where y.id.year=:year and y.id.powerPlantId=:powerPlantId and y.id.machineNo=:machineNo"); query.setString("year", year); query.setString("powerPlantId", String.valueOf(powerPlantId)); query.setString("machineNo", String.valueOf(machineNo)); objects.add(query.list().iterator().next()); tx.commit(); }catch(HibernateException e){ handleException(e); }finally{ session.close(); } return objects; } protected void startOperation() throws HibernateException{ session=HibernateSessionFactory.getSession(); tx=session.beginTransaction(); } }
|