| 
					
				 | 
			
			
				@ -11,6 +11,7 @@ import com.yihu.jw.patient.dao.BasePatientDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.restmodel.web.PageEnvelop; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.rm.base.BaseRequestMapping; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.utils.StringUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import io.swagger.models.auth.In; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.commons.lang.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.slf4j.Logger; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.slf4j.LoggerFactory; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -21,6 +22,7 @@ import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.text.DecimalFormat; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.ArrayList; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.HashMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.stream.Collectors; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -60,7 +62,7 @@ public class DetectionPlatformService  { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql +=" limit "+page*pageSize+","+pageSize; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<Map<String,Object>> list = jdbcTemplate.queryForList(sql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return PageEnvelop.getSuccessListWithPage("查询成功",list,page,pageSize,count); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else if (type == 2){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String sql = " select  '22' as 'OrderType',ord.id,ord.patient,p.name,ord.serve_desc,DATE_FORMAT(ord.create_time,'%Y-%m-%d %H:%i:%S') create_time,ord.`status`,ord.doctor,ord.doctor_name \n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "from base_security_monitoring_order ord INNER JOIN base_patient p on ord.patient = p.id order by create_time desc "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String countSql = "select count(id) from ("+sql+")A "; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -68,6 +70,16 @@ public class DetectionPlatformService  { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql +=" limit "+page*pageSize+","+pageSize; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<Map<String,Object>> list = jdbcTemplate.queryForList(sql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return PageEnvelop.getSuccessListWithPage("查询成功",list,page,pageSize,count); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String sql = " SELECT pd.id,pd.device_sn deviceSn,pd.`user`,p.`name`,d.contact_status_time contactStatusTime,CASE pd.category_code WHEN '1' THEN '血糖仪离线' WHEN '2' THEN '血压计离线' WHEN '13' THEN '睡眠带离线'\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "WHEN '17' THEN '随身WiFi离线' WHEN '7' THEN '居家安全报警器离线' WHEN '12' THEN '监控器离线' WHEN '14' THEN '气感报警器离线' WHEN '15' THEN '烟感报警器离线' WHEN '16' THEN '智能拐杖离线' WHEN '4' THEN '智能手表离线' \n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "ELSE '未知' END categoryCode FROM wlyy_devices d,wlyy_patient_device pd,base_patient p\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "WHERE d.contact_status = 0 AND pd.del = 0 AND pd.device_sn = d.device_code AND pd.`user` = p.id ORDER BY d.contact_status_time DESC "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String countSql = "select count(id) from ("+sql+")A "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            long count = jdbcTemplate.queryForObject(countSql,long.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql +=" limit "+page*pageSize+","+pageSize; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<Map<String,Object>> list = jdbcTemplate.queryForList(sql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return PageEnvelop.getSuccessListWithPage("查询成功",list,page,pageSize,count); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -323,4 +335,71 @@ public class DetectionPlatformService  { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return nightRecordList;  //起夜记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject getDistributionOfWarningTypes(){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject object = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        /****预警类型分布****/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = "SELECT hsd.dict_value,aa.count FROM wlyy_hospital_sys_dict hsd LEFT JOIN (SELECT serve_desc,COUNT(1) count FROM base_security_monitoring_order GROUP BY serve_desc)aa ON hsd.dict_value = aa.serve_desc WHERE hsd.dict_name = 'security_server_dict'"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String , Object>> list = jdbcTemplate.queryForList(sql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        /****工单总量****/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sqlAll = "SELECT COUNT(1) count FROM base_security_monitoring_order"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Integer countAll = jdbcTemplate.queryForObject(sqlAll,Integer.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        /****误报警数量****/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql1 = "SELECT COUNT(1) count FROM base_security_monitoring_order WHERE emergency_cancel IS NOT NULL OR emergency_cancel != ''"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Integer falseAlarmCount = jdbcTemplate.queryForObject(sql1,Integer.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        /****响应数量****/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String responseCountSql = "SELECT COUNT(1) count FROM base_security_monitoring_order WHERE (emergency_cancel IS NOT NULL OR emergency_cancel != '') OR `status` = 0 GROUP BY id"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String,Object>> responseList = jdbcTemplate.queryForList(responseCountSql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Integer responseCount = responseList.size(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        object.put("distributionOfWarning",list); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        object.put("countAll",countAll); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        object.put("falseAlarmCount",falseAlarmCount); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        object.put("responseCount",responseCount); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        /****误报警率****/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        object.put("falseAlarmLaw",getRange(falseAlarmCount,countAll)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        /****响应率****/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        object.put("responseLaw",getRange(responseCount,countAll)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return object; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject getServiceSituation(){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject object = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        /*****设备分类****/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // SELECT hsd.`value` dict_value,aa.count FROM base_system_dict_entry hsd LEFT JOIN (SELECT serve_desc,COUNT(1) count FROM base_security_monitoring_order GROUP BY serve_desc)aa ON hsd.`value` = aa.serve_desc WHERE hsd.remark = 'security' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String passportTypeSql = "SELECT sde.`value`,COUNT(d.id) count,GROUP_CONCAT(DISTINCT d.category_code SEPARATOR ',') AS category_code,GROUP_CONCAT(DISTINCT d.model SEPARATOR ',') AS model FROM base_system_dict_entry sde LEFT JOIN dm_device d ON FIND_IN_SET(sde.`code`,d.service_topic) WHERE sde.remark = 'security' GROUP BY sde.`value` "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String , Object>> passportType = jdbcTemplate.queryForList(passportTypeSql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String useSql = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String allSql = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String model = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Integer use = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Integer putOnFile = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (passportType.size() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (int i=0;i<passportType.size();i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                System.out.println(passportType.get(i).get("value") +"      " + passportType.get(i).get("count") +"      " + passportType.get(i).get("category_code")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Long count = (Long) passportType.get(i).get("count"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                model = (String) passportType.get(i).get("model"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                model = model.replace(",","','"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if ( count.intValue() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    useSql = "SELECT COUNT(1) FROM wlyy_patient_device WHERE category_code IN ("+ passportType.get(i).get("category_code") +") AND del = 0"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    use = jdbcTemplate.queryForObject(useSql,Integer.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    passportType.get(i).put("use",use);//使用 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    allSql = "SELECT COUNT(1) FROM wlyy_devices WHERE device_model IN ('"+ model +"')"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    putOnFile = jdbcTemplate.queryForObject(allSql,Integer.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    passportType.get(i).put("putOnFile",putOnFile); //备案 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    passportType.get(i).put("stock",putOnFile - use); //库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    passportType.get(i).put("putOnFile",0); //备案 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    passportType.get(i).put("stock",0); //库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    passportType.get(i).put("use",0); //使用 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        object.put("passportType",passportType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return object; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |