|  | @ -352,7 +352,7 @@ public class ElasticsearchUtil {
 | 
	
		
			
				|  |  | //        sql.append(" quotaCode='" + index + "'  ");
 | 
	
		
			
				|  |  |         sql.append(" quotaCode in(" + index + ")  ");
 | 
	
		
			
				|  |  |         sql.append(" and timeLevel='" + timeLevel + "'  ");
 | 
	
		
			
				|  |  |         sql.append(" and areaLevel='6'");
 | 
	
		
			
				|  |  | //        sql.append(" and areaLevel='6'");
 | 
	
		
			
				|  |  |         if (StringUtils.isNotEmpty(startDate)) {
 | 
	
		
			
				|  |  |             sql.append(" and quotaDate>='" + startDate + "'");
 | 
	
		
			
				|  |  |         }
 | 
	
	
		
			
				|  | @ -803,7 +803,7 @@ public class ElasticsearchUtil {
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         sql.append(" quotaCode in(" + index + ")  ");
 | 
	
		
			
				|  |  |         sql.append(" and timeLevel='" + timeLevel + "'  ");
 | 
	
		
			
				|  |  |         sql.append(" and areaLevel='6'");
 | 
	
		
			
				|  |  | //        sql.append(" and areaLevel='6'");
 | 
	
		
			
				|  |  |         if (StringUtils.isNotEmpty(startDate)) {
 | 
	
		
			
				|  |  |             sql.append(" and quotaDate>='" + startDate + "'");
 | 
	
		
			
				|  |  |         }
 | 
	
	
		
			
				|  | @ -842,6 +842,7 @@ public class ElasticsearchUtil {
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         sql.append(groupBy);
 | 
	
		
			
				|  |  |         logger.info("sql :" + sql.toString());
 | 
	
		
			
				|  |  |         return excute(sql.toString(), SaveModel.class, "", "");
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -1757,7 +1758,22 @@ public class ElasticsearchUtil {
 | 
	
		
			
				|  |  |         return returnModels;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public List findDateQuotaWithoutLevel(String startDate, String endDate, String index, String slaveKey) throws Exception {
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 将slaveKey1作为筛选条件而不进行group by
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param startDate 开始时间
 | 
	
		
			
				|  |  |      * @param endDate   结束时间
 | 
	
		
			
				|  |  |      * @param area      区域code
 | 
	
		
			
				|  |  |      * @param level     等级
 | 
	
		
			
				|  |  |      * @param index     指标
 | 
	
		
			
				|  |  |      * @param timeLevel 1增量 2到达量
 | 
	
		
			
				|  |  |      * @param interval  1日 2周 3月
 | 
	
		
			
				|  |  |      * @param lowLevel  下一级区域等级
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      * @throws Exception
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public List findDateQuotaLevel0BySlaveKey1(String startDate, String endDate, String area, int level, String index, String timeLevel, String interval, String lowLevel, String slaveKey1) throws Exception {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //时间格式转换  yyyy-MM-dd转成 2017-07-17T00:00:00+0800
 | 
	
		
			
				|  |  |         if (StringUtils.isNotEmpty(startDate)) {
 | 
	
		
			
				|  |  |             if (startDate.length() > 10) {
 | 
	
	
		
			
				|  | @ -1773,17 +1789,76 @@ public class ElasticsearchUtil {
 | 
	
		
			
				|  |  |                 endDate = changeDate(endDate);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         StringBuffer sql = new StringBuffer();
 | 
	
		
			
				|  |  |         StringBuffer groupBy = new StringBuffer();
 | 
	
		
			
				|  |  |         String low_level = level + "";
 | 
	
		
			
				|  |  |         if (StringUtils.isNotEmpty(lowLevel)) {
 | 
	
		
			
				|  |  |             low_level = lowLevel;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         StringBuffer sb = new StringBuffer();
 | 
	
		
			
				|  |  |         sb.append("select sum(result1) as result1,sum(result2) as result2 from ").append(esIndex)
 | 
	
		
			
				|  |  |                 .append(" where city='350200' and quotaCode in(").append(index)
 | 
	
		
			
				|  |  |                 .append(") and timeLevel='1' and areaLevel='6' and quotaDate>='").append(startDate).append("' ");
 | 
	
		
			
				|  |  |         sb.append("and quotaDate<='").append(endDate).append("'");
 | 
	
		
			
				|  |  |         if (StringUtils.isNotEmpty(slaveKey)) {
 | 
	
		
			
				|  |  |             sb.append(" and slaveKey1='").append(slaveKey).append("'");
 | 
	
		
			
				|  |  |         if (SaveModel.deptLevel.equals(low_level)) {
 | 
	
		
			
				|  |  |             sql.append("select dept,deptName,sum(result1) result1, sum(result2) result2 from " + esIndex + " where ");
 | 
	
		
			
				|  |  |             groupBy.append("  group by dept,deptName");
 | 
	
		
			
				|  |  |         } else if (SaveModel.OrgLevel.equals(low_level)) {
 | 
	
		
			
				|  |  |             sql.append("select hospital,hospitalName,sum(result1) result1,sum(result2) result2 from " + esIndex + " where ");
 | 
	
		
			
				|  |  |             groupBy.append("  group by hospital,hospitalName");
 | 
	
		
			
				|  |  |         } else if (SaveModel.townLevel.equals(low_level)) {
 | 
	
		
			
				|  |  |             sql.append("select town,townName,sum(result1) result1,sum(result2) result2 from " + esIndex + " where ");
 | 
	
		
			
				|  |  |             groupBy.append("  group by town,townName");
 | 
	
		
			
				|  |  |         } else if (SaveModel.cityLevel.equals(low_level)) {
 | 
	
		
			
				|  |  |             sql.append("select city,cityName,sum(result1) result1,sum(result2) result2 from " + esIndex + " where ");
 | 
	
		
			
				|  |  |             groupBy.append("  group by city,cityName");
 | 
	
		
			
				|  |  |         }else if (SaveModel.doctorLevel.equals(low_level)) {
 | 
	
		
			
				|  |  |             sql.append("select doctor,doctorName,sum(result1) result1,sum(result2) result2 from " + esIndex + " where ");
 | 
	
		
			
				|  |  |             groupBy.append("  group by doctor,doctorName ");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         sb.append(" group by town,townName,hospital,hospitalName order by town,townName, hospital,hospitalName");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return excute(sb.toString(), SaveModel.class, "", "");
 | 
	
		
			
				|  |  |         if (StringUtils.isNotEmpty(area)) {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             if (SaveModel.deptLevel.equals(level + "")) {
 | 
	
		
			
				|  |  |                 sql.append(" dept='" + area + "'");
 | 
	
		
			
				|  |  |             } else if (SaveModel.OrgLevel.equals(level + "")) {
 | 
	
		
			
				|  |  |                 sql.append(" hospital='" + area + "'");
 | 
	
		
			
				|  |  |             } else if (SaveModel.townLevel.equals(level + "")) {
 | 
	
		
			
				|  |  |                 sql.append(" town='" + area + "'");
 | 
	
		
			
				|  |  |             } else if (SaveModel.cityLevel.equals(level + "")) {
 | 
	
		
			
				|  |  |                 sql.append(" city='" + area + "'");
 | 
	
		
			
				|  |  |             }else if (SaveModel.doctorLevel.equals(level + "")) {
 | 
	
		
			
				|  |  |                 sql.append(" doctor='" + area + "'");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             sql.append(" and ");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | //        sql.append(" quotaCode='" + index + "'  ");
 | 
	
		
			
				|  |  |         sql.append(" quotaCode in(" + index + ")  ");
 | 
	
		
			
				|  |  |         sql.append(" and timeLevel='" + timeLevel + "'  ");
 | 
	
		
			
				|  |  | //        sql.append(" and areaLevel='5'");
 | 
	
		
			
				|  |  |         if (StringUtils.isNotEmpty(startDate)) {
 | 
	
		
			
				|  |  |             sql.append(" and quotaDate>='" + startDate + "'");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (StringUtils.isNotEmpty(endDate)) {
 | 
	
		
			
				|  |  |             sql.append(" and quotaDate<='" + endDate + "'");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (StringUtils.isNotEmpty(slaveKey1) && !commonParams.equals(slaveKey1)) {
 | 
	
		
			
				|  |  |             String[] temp = slaveKey1.split(",");
 | 
	
		
			
				|  |  |             String slaveKey1Temp = "";
 | 
	
		
			
				|  |  |             for(String one : temp){
 | 
	
		
			
				|  |  |                 slaveKey1Temp += ",'"+one+"'";
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             sql.append(" and slaveKey1 in ("+slaveKey1Temp.substring(1)+")");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //根据时间维度分组
 | 
	
		
			
				|  |  |         if (StringUtils.isNotEmpty(interval)) {
 | 
	
		
			
				|  |  |             if (SaveModel.interval_month.equals(interval)) {
 | 
	
		
			
				|  |  |                 groupBy.append(" ,date_histogram(field='quotaDate','interval'='month','time_zone'='+08:00','alias'='quotaDate') ");
 | 
	
		
			
				|  |  |             } else if (SaveModel.interval_week.equals(interval)) {
 | 
	
		
			
				|  |  |                 groupBy.append(" ,date_histogram(field='quotaDate','interval'='week','time_zone'='+08:00','alias'='quotaDate') ");
 | 
	
		
			
				|  |  |             } else if (SaveModel.interval_day.equals(interval)) {
 | 
	
		
			
				|  |  |                 groupBy.append(" ,date_histogram(field='quotaDate','interval'='1d','time_zone'='+08:00','alias'='quotaDate') ");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         sql.append(groupBy);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return excute(sql.toString(), SaveModel.class, "", "");
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | }
 |