hibernate group by

			DetachedCriteria dc = DetachedCriteria.forClass(EnterpriseSummaryMonth.class);
			if (isNotEmpty(c.getEnterpriseId())) {
				dc.add(Restrictions.eq("enterpriseId", c.getEnterpriseId()));
			}else{
				if (isNotEmpty(c.getCityId())) {
					dc.add(Restrictions.eq("cityId", c.getCityId()));
				}else{
					if (isNotEmpty(c.getProvinceId())) {
						dc.add(Restrictions.eq("provinceId", c.getProvinceId()));
					}
				}
			}
			
			if (isNotEmpty(c.getYearMonth())) {
				dc.add(Restrictions.eq("yearMonth", c.getYearMonth()));
			}
			dc.setProjection(Projections.projectionList()
					.add(Projections.max("enterpriseName"),"enterpriseName")
					.add(Projections.min("startTime"),"startTime")
					.add(Projections.sum("outworkerNum"),"outworkerNum")
					.add(Projections.max("smsExpressionNum"),"smsExpressionNum")
					.add(Projections.sum("smsNum"),"smsNum")
					.add(Projections.sum("noticeNum"),"noticeNum")
					.add(Projections.max("customerNum"),"customerNum")
					.add(Projections.sum("customerVisitLogNum"),"customerVisitLogNum")
					.add(Projections.sum("taskNum"),"taskNum")
					.add(Projections.sum("phoneTaskNum"),"phoneTaskNum")
					.add(Projections.sum("templateNum"),"templateNum")
					.add(Projections.sum("travelLogNum"),"travelLogNum")
					.add(Projections.sum("attendanceNum"),"attendanceNum")
					.add(Projections.sum("attendPhoneNum"),"attendPhoneNum")
					.add(Projections.sum("travelPosNum"),"travelPosNum")
					.add(Projections.sum("locNum"),"locNum")
					.add(Projections.sum("alarmNum"),"alarmNum")
					.add(Projections.max("summaryTime"),"summaryTime")
					.add( Projections.groupProperty("enterpriseId"))
				);
			dc.setResultTransformer(Transformers.aliasToBean(EnterpriseSummaryMonth.class));
			return dao.findByPage(dc, pv);

你可能感兴趣的:(hibernate group by)