@Override public List<FmsCountEfficiency> getReportForms(final String sql) { SQLQuery query = (SQLQuery) this.getSession().createSQLQuery(sql); query.setResultTransformer(Transformers.aliasToBean(FmsCountEfficiency.class)); query.addScalar("feName",Hibernate.STRING); query.addScalar("feCenterName",Hibernate.STRING); query.addScalar("feDeptName",Hibernate.STRING); query.addScalar("feDisitNum",Hibernate.INTEGER); query.addScalar("feFaultNum",Hibernate.INTEGER); query.addScalar("feOnTime",Hibernate.INTEGER); query.addScalar("feOverTime",Hibernate.INTEGER); query.addScalar("feBreakDown",Hibernate.INTEGER); query.addScalar("feNoReply",Hibernate.INTEGER); query.addScalar("feAvgNum",Hibernate.DOUBLE); List list=query.list(); return list; } String sql="SELECT FF_RESPONSIBLE_PERSON_NAME as feName,"+ " (SELECT sd.SD_PARENT_DEPT_NAME FROM SYS_DEPT sd WHERE SD.SD_DEPT_NAME=FF_RESPONSIBLE_PERSON_Deptname) as feCenterName,FF_RESPONSIBLE_PERSON_Deptname as feDeptName,"+ "(SELECT count(FV.FV_ID) FROM FMS_VISIT fv WHERE FV.FV_VISITOR_NAME= FF_RESPONSIBLE_PERSON_NAME AND FV.FV_STATE='20') as feDisitNum,"+ "count(FF_ID) as feFaultNum,"+ "(SELECT count(FF.FF_ID) FROM FMS_FAULT ff WHERE FF.FF_RESPONSIBLE_PERSON_NAME=FF_RESPONSIBLE_PERSON_NAME AND FF.FF_STATUS='550' AND FF.FF_STATUS not in('110','210','310','610')) as feOnTime, (SELECT count(FF.FF_ID) FROM FMS_FAULT ff WHERE FF.FF_RESPONSIBLE_PERSON_NAME=FF_RESPONSIBLE_PERSON_NAME AND FF.FF_STATUS='550' AND FF.FF_STATUS in('110','210','310','610')) as feOverTime,"+ "(SELECT count(FF.FF_ID) FROM FMS_FAULT ff WHERE FF.FF_STATUS='240') as feBreakDown,"+ "(SELECT count(FF.FF_ID) FROM FMS_FAULT ff WHERE (to_number(to_date(to_char(FF.FF_FINISH_TIME,'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss') - to_Date(to_char(FF.SYS_CREATE_DATE,'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss'))*24)>4) as feNoReply ,"+ "(SELECT sum(to_number(to_date(to_char(FF.FF_FINISH_TIME,'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss') - to_Date(to_char(FF.SYS_CREATE_DATE,'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss'))*24)/count(FF.FF_ID) FROM fms_fault ff WHERE FF.FF_STATUS='550') as feAvgNum "+ "from FMS_FAULT GROUP BY FF_RESPONSIBLE_PERSON_NAME,FF_RESPONSIBLE_PERSON_Deptname";
其中FmsCountEfficiency是咱們須要填充的實體類,不須要與數據庫映射。 query.addScalar("feName",Hibernate.STRING);中feName是FmsCountEfficiency的一個屬性,也必須跟咱們從數據庫中查出的字段名一致,這樣三點一線就能夠填充咱們的實體類。提升咱們的工做效率。java