| 
					
				 | 
			
			
				@ -3,12 +3,16 @@ package com.yihu.jw.care.service.statistics; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.util.ConstantUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.es.util.ElasticsearchUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.util.date.DateUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.commons.lang.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.slf4j.Logger; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.slf4j.LoggerFactory; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.jdbc.core.JdbcTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.Calendar; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * Created by yeshijie on 2021/4/7. 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -27,26 +31,111 @@ public class StatisticsService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 统计首页头部数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param area 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param startTime 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param endTime 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param startDate 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param endDate 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject indexTopNum(String area,String startTime,String endTime,String level){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject indexTopNum(String area,String startDate,String endDate,Integer level){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject re = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String signSql = "select count(s.id) from base_service_package_sign_record s"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String capacitySql = "select count(c.id) from base_capacity_assessment_record c"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String signSql = " SELECT COUNT(sr.id) " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " FROM " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  base_service_package_sign_record sr, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  base_service_package_record r, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  base_service_package_item i, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "   base_org o " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " WHERE " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  sr.id = r.sign_id " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " AND sr. STATUS = 1 " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " AND r.service_package_id = i.service_package_id " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " AND i.del = 1 and i.org_code = o.code"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String capacitySql = "select count(sr.id) from base_capacity_assessment_record sr, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "   base_org o " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " WHERE " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " sr.org_code = o.code" ; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String filters = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(ConstantUtil.cityLevel.equals(level)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            filters = " and o.city_code = '"+area+"'"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else if(ConstantUtil.townLevel.equals(level)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            filters = " and o.town_code = '"+area+"'"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else if(ConstantUtil.orgLevel.equals(level)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            filters = " and o.code = '"+area+"'"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(StringUtils.isNotBlank(startDate)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            filters += " and sr.create_time >='"+startDate+"'"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(StringUtils.isNotBlank(endDate)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            filters += " and sr.create_time <='"+endDate+"'"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //签约数 能力评估 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(ConstantUtil.CITY.equals(area)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            signSql += " where s.status = 1"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Integer signNum = jdbcTemplate.queryForObject(signSql+filters,Integer.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Integer capacityNum = jdbcTemplate.queryForObject(capacitySql+filters,Integer.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        re.put("signNum",signNum); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        re.put("capacityNum",capacityNum); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return re; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 首页 养护服务 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param area 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param startDate 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param endDate 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param level 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param type 类型:1本周,2本月 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject indexMaintenanceServices(String area,String startDate,String endDate,Integer level,int type){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject re = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = "select count(sr.id) from base_life_care_order sr, " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "   base_org o " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " WHERE " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " sr.hospital = o.code" ; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(ConstantUtil.cityLevel.equals(level)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql += " and o.city_code = '"+area+"'"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else if(ConstantUtil.townLevel.equals(level)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql += " and o.town_code = '"+area+"'"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else if(ConstantUtil.orgLevel.equals(level)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql += " and o.code = '"+area+"'"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String filters = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String timefilters = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(StringUtils.isNotBlank(startDate)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            filters += " and sr.create_time >='"+startDate+"'"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(StringUtils.isNotBlank(endDate)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            filters += " and sr.create_time <='"+endDate+"'"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String start = calStart(endDate,type); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        timefilters += " and sr.create_time >='"+start+"'"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        timefilters += " and sr.create_time <='"+endDate+"'"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Integer signNum = jdbcTemplate.queryForObject(signSql,Integer.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Integer capacityNum = jdbcTemplate.queryForObject(capacitySql,Integer.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        re.put("signNum",signNum); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        re.put("capacityNum",capacityNum); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //生活照料 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Integer lifeCareNum = jdbcTemplate.queryForObject(sql+filters,Integer.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Integer lifeCareNumAdd = jdbcTemplate.queryForObject(sql+timefilters,Integer.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        re.put("lifeCareNum",lifeCareNum); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        re.put("lifeCareNumAdd",lifeCareNumAdd); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return re; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 计算开始时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param endDate 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param type 1周,2月 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public String calStart(String endDate,int type){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(StringUtils.isEmpty(endDate)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return endDate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Calendar cal = Calendar.getInstance(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        cal.setTime(DateUtil.strToDate(endDate)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(1==type){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                cal.add(Calendar.DAY_OF_WEEK,-1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            cal.set(Calendar.DAY_OF_WEEK,Calendar.MONDAY); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            cal.set(Calendar.DAY_OF_MONTH,1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return DateUtil.dateToStrShort(cal.getTime()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |