|  | @ -13,10 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | import org.springframework.jdbc.core.JdbcTemplate;
 | 
	
		
			
				|  |  | import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import java.util.HashMap;
 | 
	
		
			
				|  |  | import java.util.Iterator;
 | 
	
		
			
				|  |  | import java.util.List;
 | 
	
		
			
				|  |  | import java.util.Map;
 | 
	
		
			
				|  |  | import java.util.*;
 | 
	
		
			
				|  |  | import java.util.stream.Collectors;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /**
 | 
	
	
		
			
				|  | @ -805,6 +802,75 @@ public class WlyygcStatisticsService {
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 社区计数
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public List<Map<String,Object>> getOlderTeamListWithPage(Integer page,Integer size) throws Exception {
 | 
	
		
			
				|  |  |         List<Map<String,Object>> teamList  = new ArrayList<>();
 | 
	
		
			
				|  |  |         page = page>0?page-1:0;
 | 
	
		
			
				|  |  |         String sql = " select count(distinct org.code) from " +
 | 
	
		
			
				|  |  |                 " base_service_package pack INNER JOIN base_org org on pack.org_code = org.code " +
 | 
	
		
			
				|  |  |                 "INNER JOIN base_team te on te.org_code = org.`code` " +
 | 
	
		
			
				|  |  |                 " where  org.del=1 and org.type=3 and te.del=1 and org.code not in " +
 | 
	
		
			
				|  |  |                 " (select dict_code from wlyy_hospital_sys_dict where dict_name='jkzl_org') ";
 | 
	
		
			
				|  |  |         Long totalNum = jdbcTemplate.queryForObject(sql,Long.class);
 | 
	
		
			
				|  |  |         sql = " select distinct org.code as orgCode,org.name as orgName,te.id as teamId,te.name as teamName from " +
 | 
	
		
			
				|  |  |                 " base_service_package pack INNER JOIN base_org org on pack.org_code = org.code " +
 | 
	
		
			
				|  |  |                 "INNER JOIN base_team te on te.org_code = org.`code` " +
 | 
	
		
			
				|  |  |                 " where  org.del=1 and org.type=3 and te.del=1 and org.code not in " +
 | 
	
		
			
				|  |  |                 " (select dict_code from wlyy_hospital_sys_dict where dict_name='jkzl_org') order by org.code asc " +
 | 
	
		
			
				|  |  |                 "limit "+(page*size)+","+size ;
 | 
	
		
			
				|  |  |         teamList = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |         for (Map<String,Object> map:teamList){
 | 
	
		
			
				|  |  |             Integer count = 0;
 | 
	
		
			
				|  |  |             //1 获取社工人数(该团队人数) 2.预警数(紧急呼叫+安防监护 已取消的不算)
 | 
	
		
			
				|  |  |             //3助老服务(该社区所有老人的生活照料总数 已取消的不算) 4物联设备(健康设备绑定量+安防设备绑定量)
 | 
	
		
			
				|  |  |             String teamName = map.get("teamName").toString();
 | 
	
		
			
				|  |  |             String teamId = map.get("teamId").toString();
 | 
	
		
			
				|  |  |             teamName = teamName.replace("团队","社区");
 | 
	
		
			
				|  |  |             teamName = teamName.replace("服务","");
 | 
	
		
			
				|  |  |             if(!teamName.contains("社区")){
 | 
	
		
			
				|  |  |                 teamName = teamName+"社区";
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             map.put("teamName",teamName);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             sql = " SELECT count(o.bussiness_id) " +
 | 
	
		
			
				|  |  |                     "FROM ( SELECT o.id AS bussiness_id,o.team_code as dept,o.`status`,o.update_time " +
 | 
	
		
			
				|  |  |                     "FROM base_security_monitoring_order o UNION ALL  " +
 | 
	
		
			
				|  |  |                     "SELECT o.id AS bussiness_id,o.team_code as dept,o.`status`,o.update_time " +
 | 
	
		
			
				|  |  |                     "FROM base_emergency_assistance_order o " +
 | 
	
		
			
				|  |  |                     ") o WHERE 1=1  and dept='"+teamId+"' and `status` = 1 ";
 | 
	
		
			
				|  |  |             Long emeAssistanceCount = jdbcTemplate.queryForObject(sql,Long.class);
 | 
	
		
			
				|  |  |             map.put("emeAssistanceCount",emeAssistanceCount);//救助服务
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             sql = "  select count(distinct pd.device_sn) from wlyy_patient_device pd INNER JOIN wlyy_devices dev on pd.device_sn = dev.device_code  " +
 | 
	
		
			
				|  |  |                     " INNER JOIN base_patient p on pd.user = p.id and pd.del=0 and p.del=1  " +
 | 
	
		
			
				|  |  |                     " where 1=1 and EXISTS ( " +
 | 
	
		
			
				|  |  |                     " select 1 from base_service_package_sign_record sr,base_service_package_record r, base_service_package_item i," +
 | 
	
		
			
				|  |  |                     " base_service_package pack " +
 | 
	
		
			
				|  |  |                     " where sr.id = r.sign_id and sr.status=1 and r.service_package_id = i.service_package_id and r.service_package_id = pack.id " +
 | 
	
		
			
				|  |  |                     "  and i.del = 1  and sr.`status`=1 and CONVERT(sr.patient USING utf8)  = p.id " +
 | 
	
		
			
				|  |  |                     " and CONVERT(sr.patient USING utf8) not in (SELECT dict_code FROM `base`.`wlyy_hospital_sys_dict` " +
 | 
	
		
			
				|  |  |                     " WHERE `dict_name` = 'jkzl_older' or dict_name='jkzl_child') and r.team_code='"+teamId+"' ) ";
 | 
	
		
			
				|  |  |             count = jdbcTemplate.queryForObject(sql,Integer.class);
 | 
	
		
			
				|  |  |             map.put("bindingDeviceCount",count);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             String sqltmp = "SELECT GROUP_CONCAT(dict_code) orgCodes from wlyy_hospital_sys_dict WHERE dict_name = 'jkzl_older' ";
 | 
	
		
			
				|  |  |             List<Map<String,Object>> listtmp =  jdbcTemplate.queryForList(sqltmp);
 | 
	
		
			
				|  |  |             String filter ="";
 | 
	
		
			
				|  |  |             if(listtmp.size()>0){
 | 
	
		
			
				|  |  |                 String orgCodes = String.valueOf(listtmp.get(0).get("orgCodes"));
 | 
	
		
			
				|  |  |                 orgCodes = orgCodes.replaceAll(",","','");
 | 
	
		
			
				|  |  |                 filter = " and a.id not in ('"+orgCodes+"')";
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             sql = "SELECT count(a.id) from base_patient a  WHERE a.archive_type = 1 and a.del = '1' ";
 | 
	
		
			
				|  |  |             sql += " and EXISTS ( select 1 from " +
 | 
	
		
			
				|  |  |                     "base_service_package_sign_record sr,base_service_package_record r, base_service_package_item i,base_service_package pack " +
 | 
	
		
			
				|  |  |                     " where sr.id = r.sign_id and sr.status=1 and r.service_package_id = i.service_package_id and r.service_package_id = pack.id " +
 | 
	
		
			
				|  |  |                     " and i.del = 1  and sr.`status`=1 and CONVERT(sr.patient USING utf8)  = a.id and r.team_code='"+teamId+"' ) "+filter;
 | 
	
		
			
				|  |  |             count =  jdbcTemplate.queryForObject(sql,Integer.class);
 | 
	
		
			
				|  |  |             map.put("oldTotal",count);//照护老人数量
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return  teamList;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 |