| 
					
				 | 
			
			
				@@ -4,14 +4,15 @@ import com.baomidou.mybatisplus.core.metadata.IPage; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.huaxu.client.UserCenterClient; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.huaxu.common.FileUploadUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.huaxu.common.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.huaxu.dto.DeviceDto; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.huaxu.entity.DeviceParmEntity; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.huaxu.entity.DeviceSceneEntity; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.huaxu.entity.SceneTypeEntity; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.huaxu.entity.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.huaxu.model.AjaxMessage; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.huaxu.model.LoginUser; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.huaxu.model.Pagination; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.huaxu.model.ResultStatus; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.huaxu.service.AlarmSettingService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.huaxu.service.ParmSettingService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.huaxu.util.UserUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import io.swagger.annotations.Api; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import io.swagger.annotations.ApiOperation; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -26,12 +27,9 @@ import java.io.IOException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.text.ParseException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.text.SimpleDateFormat; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.time.LocalDate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.Calendar; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.Date; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.web.bind.annotation.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.huaxu.entity.SceneEntity; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.huaxu.service.SceneService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.web.multipart.MultipartFile; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -50,6 +48,8 @@ public class SceneController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private String baseDir; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     UserCenterClient userCenterClient; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private ParmSettingService parmSettingService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @ApiOperation(value = "分页查询场景") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @RequestMapping(value = "/selectPage", method = RequestMethod.GET) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -220,7 +220,7 @@ public class SceneController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @RequestMapping(value = "/selectAlarmSceneAndDevice", method = RequestMethod.GET) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @ResponseBody 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @ApiOperation(value = "场景及设备故障率") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public  AjaxMessage<List<Map<String,Object>>> selectAlarmSceneAndDevice( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public  AjaxMessage<Object> selectAlarmSceneAndDevice( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             @ApiParam(value = "统计类型:0-按月统计,1-按年统计,2-自定义统计", required = true) @RequestParam(required = true) int type, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             @ApiParam(value = "统计时间:月格式(yyyy-MM),年格式(yyyy),自定义统计时间开始日期", required = true) @RequestParam(required = true) String startDate, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             @ApiParam(value = "统计时间:年月统计不用传入此参数,自定义统计截至日期", required = false) @RequestParam(required = false) String endDate) throws ParseException { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -249,6 +249,27 @@ public class SceneController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 days = differentDaysByMillisecond(startDate,endDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ParmSettingEntity parmSettingEntity = new ParmSettingEntity(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        parmSettingEntity.setCompanyOrgId(Long.valueOf(loginUser.getCompanyId().toString())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        parmSettingEntity.setParmType(3); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<ParmSettingEntity> paramSettingList = parmSettingService.findList(parmSettingEntity); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(paramSettingList.size()==0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return new AjaxMessage<>(ResultStatus.ERROR,"没有配置故障率参数"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ParmSettingEntity parmSetting = paramSettingList.get(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String paramValue = parmSetting.getParmValue(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String[] params =  paramValue.split(";"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(params.length!=3 ){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+           return new AjaxMessage<>(ResultStatus.ERROR,"参数设置格式错误!请参照正确格式设置:0.5;0.5~0.2;0.2"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String[] mParam = params[1].split("~"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(mParam.length!=2){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+           return new AjaxMessage<>(ResultStatus.ERROR,"参数设置格式错误!请参照正确格式设置:0.5;0.5~0.2;0.2"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(validateNumber(params[0])==false || validateNumber(params[2])==false 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                || validateNumber(mParam[0])==false || validateNumber(mParam[1])==false){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return new AjaxMessage<>(ResultStatus.ERROR,"参数设置格式错误!请参照正确格式设置:0.5;0.5~0.2;0.2"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         List<Map<String,Object>> list = sceneService.selectAlarmSceneAndDevice(sceneEntity, startDate, endDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         for(int i=0;i<list.size();i++){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             Map<String,Object> map = list.get(i); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -256,13 +277,13 @@ public class SceneController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             double rate =amount / days; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             map.put("rate",rate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if(rate>=0.5){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if(rate>=Double.parseDouble(params[0])){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 map.put("level","高"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            else if(rate>=0.2 && rate<0.5){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            else if(rate>=Double.parseDouble(params[1]) && rate<Double.parseDouble(params[0])){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 map.put("level","中"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            else if(rate<0.2){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            else if(rate<Double.parseDouble(params[2])){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 map.put("level","低"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -270,6 +291,84 @@ public class SceneController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @RequestMapping(value = "/alarmTimesStatistics", method = RequestMethod.GET) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @ResponseBody 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @ApiOperation(value = "报警次数统计") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public  AjaxMessage<List<Map<String,Object>>> alarmTimesStatistics( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            @ApiParam(value = "设备或场景ID", required = true) @RequestParam(required = true) int id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            @ApiParam(value = "设备或场景标识(1:设备;2:场景)", required = true) @RequestParam(required = true) int sort, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            @ApiParam(value = "统计类型:0-按月统计,1-按年统计,2-自定义统计", required = true) @RequestParam(required = true) int type, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            @ApiParam(value = "统计时间:月格式(yyyy-MM),年格式(yyyy),自定义统计时间开始日期", required = true) @RequestParam(required = true) String startDate, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            @ApiParam(value = "统计时间:年月统计不用传入此参数,自定义统计截至日期", required = false) @RequestParam(required = false) String endDate) throws ParseException { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        LoginUser loginUser = UserUtil.getCurrentUser(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        SceneEntity sceneEntity = new SceneEntity(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        sceneEntity.setId(Long.parseLong(String.valueOf(id))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        switch (type) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            case 0: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                startDate = String.format("%s-01", startDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                endDate = subMonth(startDate, 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            case 1: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                startDate = String.format("%s-01-01", startDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                endDate = subYear(startDate, 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            case 2: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                startDate = String.format("%s-01", startDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                endDate = String.format("%s-01", endDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<Map<String,Object>> list = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(type == 0 || type== 2){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            list = sceneService.selectMonthAlarmTimes(sceneEntity, startDate, endDate,sort); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        else if(type == 1){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            list = sceneService.selectYearAlarmTimes(sceneEntity, startDate, endDate,sort); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return new AjaxMessage<>(ResultStatus.OK, list); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @RequestMapping(value = "/selectAlarmDeviceIdBySenceId", method = RequestMethod.GET) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @ResponseBody 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @ApiOperation(value = "根据场景ID获取报警设备的ID") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public AjaxMessage<List<Map<String,Object>>> selectAlarmDeviceIdBySenceId( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            @ApiParam(value = "设备或场景ID", required = true) @RequestParam(required = true) int id){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<Map<String,Object>> list = sceneService.selectAlarmDeviceIdBySenceId(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return new AjaxMessage<>(ResultStatus.OK,list); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @RequestMapping(value = "/selectAlarmLable", method = RequestMethod.GET) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @ResponseBody 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @ApiOperation(value = "报警标签") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public AjaxMessage<List<Map<String,Object>>> selectAlarmLable( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            @ApiParam(value = "设备或场景ID", required = true) @RequestParam(required = true) int id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            @ApiParam(value = "设备或场景标识(1:设备;2:场景)", required = true) @RequestParam(required = true) int sort, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            @ApiParam(value = "统计类型:0-按月统计,1-按年统计,2-自定义统计", required = true) @RequestParam(required = true) int type, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            @ApiParam(value = "统计时间:月格式(yyyy-MM),年格式(yyyy),自定义统计时间开始日期", required = true) @RequestParam(required = true) String startDate, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            @ApiParam(value = "统计时间:年月统计不用传入此参数,自定义统计截至日期", required = false) @RequestParam(required = false) String endDate) throws ParseException { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        SceneEntity sceneEntity = new SceneEntity(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        sceneEntity.setId(Long.parseLong(String.valueOf(id))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        switch (type) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            case 0: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                startDate = String.format("%s-01", startDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                endDate = subMonth(startDate, 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            case 1: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                startDate = String.format("%s-01-01", startDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                endDate = subYear(startDate, 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            case 2: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                startDate = String.format("%s-01", startDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                endDate = String.format("%s-01", endDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<Map<String,Object>> list = sceneService.selectAlarmLable(sceneEntity,startDate,endDate,sort); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return new AjaxMessage<>(ResultStatus.OK,list); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -320,4 +419,15 @@ public class SceneController { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return reStr; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 判断是否是整数或者是小数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param str 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @return true:是,false不是 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private boolean validateNumber(String str) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(StringUtils.isBlank(str)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return str.matches("[+-]?[0-9]+(\\\\.[0-9]+)?"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |