| 
					
				 | 
			
			
				@ -2,12 +2,14 @@ package com.yihu.jw.care.service.statistics; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.restmodel.web.PageEnvelop; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import io.swagger.models.auth.In; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				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.text.DecimalFormat; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -50,21 +52,66 @@ public class DetectionPlatformService  { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject getDeviceComapny(){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject object = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String deviceTypeSum = "SELECT COUNT(1) deviceTypeSum FROM dm_device where del = 1 GROUP BY brands"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String deviceTypeSum = "SELECT * FROM wlyy_devices WHERE device_name IS NOT NULL AND device_name != '' GROUP BY device_name"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String , Object>> deviceList = jdbcTemplate.queryForList(deviceTypeSum); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (deviceList.size() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            object.put("deviceTypeCount",deviceList.size()); //设备品牌数量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            object.put("deviceTypeCount",0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String manufacturerSql = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String manufacturerSql = "SELECT * FROM wlyy_devices WHERE manufacturer IS NOT NULL AND manufacturer != '' GROUP BY manufacturer ;"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String , Object>> manufacturerList = jdbcTemplate.queryForList(manufacturerSql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (manufacturerList.size() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            object.put("manufacturerCount",manufacturerList.size()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            object.put("manufacturerCount",manufacturerList.size()); //入驻厂商数量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            object.put("manufacturerCount",0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String securitySql = "SELECT allCount,isUse,(allCount - isUse) inventory FROM \n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "(SELECT COUNT(1) allCount FROM wlyy_devices WHERE device_type = 1) allCount,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "(SELECT COUNT(1) isUse FROM wlyy_devices WHERE device_type = 1 AND is_binding = 1) isUse"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String , Object>> securityList = jdbcTemplate.queryForList(securitySql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (securityList.size() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            object.put("securityAllCount",securityList.get(0).get("allCount")); //安防设备总量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            object.put("securityIsUseCount",securityList.get(0).get("isUse"));//安防设备使用中数量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            object.put("securityInventoryCount",securityList.get(0).get("inventory"));//安防设备库存量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            object.put("securityAllCount",0); //安防设备总量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            object.put("securityIsUseCount",0);//安防设备使用中数量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            object.put("securityInventoryCount",0);//安防设备库存量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String healthSql = "SELECT allCount,isUse,(allCount - isUse) inventory FROM \n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "(SELECT COUNT(1) allCount FROM wlyy_devices WHERE device_type = 0) allCount,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "(SELECT COUNT(1) isUse FROM wlyy_devices WHERE device_type = 0 AND is_binding = 1) isUse"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String , Object>> healthList = jdbcTemplate.queryForList(healthSql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (healthList.size() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            object.put("healthAllCount",securityList.get(0).get("allCount"));//健康设备总量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            object.put("healthIsUseCount",securityList.get(0).get("isUse"));//健康设备使用中数量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            object.put("healthInventoryCount",securityList.get(0).get("inventory"));//健康设备库存量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            object.put("healthAllCount",0);//健康设备总量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            object.put("healthIsUseCount",0);//健康设备使用中数量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            object.put("healthInventoryCount",0);//健康设备库存量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //物联率 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        object.put("lawOfIOT",getRange( ((Integer)securityList.get(0).get("isUse") + (Integer) healthList.get(0).get("isUser")),( (Integer) securityList.get(0).get("allCount") + (Integer) healthList.get(0).get("allCount") ) )); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        object.put("isUseAllIot",((Integer)securityList.get(0).get("isUse") + (Integer) healthList.get(0).get("isUser")));//已发放设备 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        object.put("allIot",(Integer) securityList.get(0).get("allCount") + (Integer) healthList.get(0).get("allCount"));//总设备 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return object; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public String getRange(int first, int second) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (second == 0 && first > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //如果分母为0 分子不为0 返回100% 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return "100%"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } else if (second == 0 && first == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //如果分母为0 分子为0 返回0% 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return "0%"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        float size = (float) (first * 100) / second; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        DecimalFormat df = new DecimalFormat("0.00");//格式化小数,不足的补0 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String filesize = df.format(size); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return filesize + "%"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |