Browse Source

图表和对比修改

wangli 4 years ago
parent
commit
634e5f2e16

+ 40 - 17
sms_water/src/main/java/com/huaxu/dao/MonitorDataReportMapper.java

@@ -17,29 +17,52 @@ import java.util.List;
 @Mapper
 public interface MonitorDataReportMapper {
 
-    /**
-     *
-     * @param type 查询类型 1年2月3日
-     * @param year
-     * @param month
-     * @param day
-     * @param sceneId 场景id
-     * @param tableName 表明 年 sms_year_report 月日
-     * @return
-     */
-    List<MonitorDataChartReportDeviceDto> MonitorDataChartReport(@Param("type") Integer type, @Param("year")Integer year, @Param("month")Integer month,
-                                                                 @Param("day")Integer day, @Param("sceneId")Long sceneId , @Param("tableName")String tableName,
-                                                                 @Param("tenantId")String tenantId,@Param("userType")String userType,@Param("permissonType")Integer permissonType,
-                                                                 @Param("programItems")List<ProgramItem> programItems);
-
-    List<MonitorDataChartReportDeviceDto> MonitorDataEnergyReport(@Param("type") Integer type, @Param("sceneIds")List<Long> sceneIds,
+
+    List<MonitorDataChartReportDeviceDto> MonitorDataChartReportByDay( @Param("year")Integer year, @Param("month")Integer month, @Param("day")Integer day,
+                                                                       @Param("sceneId")Long sceneId ,@Param("tenantId")String tenantId,
+                                                                       @Param("userType")String userType,@Param("permissonType")Integer permissonType,
+                                                                       @Param("programItems")List<ProgramItem> programItems);
+    List<MonitorDataChartReportDeviceDto> MonitorDataChartReportByMonth( @Param("year")Integer year, @Param("month")Integer month,
+                                                                         @Param("sceneId")Long sceneId ,@Param("tenantId")String tenantId,
+                                                                         @Param("userType")String userType,@Param("permissonType")Integer permissonType,
+                                                                         @Param("programItems")List<ProgramItem> programItems);
+    List<MonitorDataChartReportDeviceDto> MonitorDataChartReportByYear( @Param("year")Integer year,
+                                                                        @Param("sceneId")Long sceneId ,@Param("tenantId")String tenantId,
+                                                                        @Param("userType")String userType,@Param("permissonType")Integer permissonType,
+                                                                        @Param("programItems")List<ProgramItem> programItems);
+
+
+
+    List<MonitorDataChartReportDeviceDto> MonitorDataEnergyReportByDay(@Param("sceneIds")List<Long> sceneIds,
                                                                   @Param("year")Integer year, @Param("month")Integer month, @Param("day")Integer day,
                                                                   @Param("tenantId")String tenantId,@Param("userType")String userType,@Param("permissonType")Integer permissonType,
                                                                   @Param("programItems")List<ProgramItem> programItems);
-    List<MonitorDataChartReportDeviceDto> MonitorDataQualityReport(@Param("type") Integer type, @Param("sceneIds")List<Long> sceneIds,
+    List<MonitorDataChartReportDeviceDto> MonitorDataEnergyReportByMonth( @Param("sceneIds")List<Long> sceneIds,
+                                                                  @Param("year")Integer year, @Param("month")Integer month,
+                                                                  @Param("tenantId")String tenantId,@Param("userType")String userType,@Param("permissonType")Integer permissonType,
+                                                                  @Param("programItems")List<ProgramItem> programItems);
+    List<MonitorDataChartReportDeviceDto> MonitorDataEnergyReportByYear( @Param("sceneIds")List<Long> sceneIds,
+                                                                  @Param("year")Integer year,
+                                                                  @Param("tenantId")String tenantId,@Param("userType")String userType,@Param("permissonType")Integer permissonType,
+                                                                  @Param("programItems")List<ProgramItem> programItems);
+
+
+
+    List<MonitorDataChartReportDeviceDto> MonitorDataQualityReportByDay(@Param("sceneIds")List<Long> sceneIds,
                                                                    @Param("year")Integer year, @Param("month")Integer month, @Param("day")Integer day,
                                                                    @Param("tenantId")String tenantId,@Param("userType")String userType,@Param("permissonType")Integer permissonType,
                                                                    @Param("programItems")List<ProgramItem> programItems);
+    List<MonitorDataChartReportDeviceDto> MonitorDataQualityReportByMonth( @Param("sceneIds")List<Long> sceneIds,
+                                                                   @Param("year")Integer year, @Param("month")Integer month,
+                                                                   @Param("tenantId")String tenantId,@Param("userType")String userType,@Param("permissonType")Integer permissonType,
+                                                                   @Param("programItems")List<ProgramItem> programItems);
+    List<MonitorDataChartReportDeviceDto> MonitorDataQualityReportByYear( @Param("sceneIds")List<Long> sceneIds,
+                                                                   @Param("year")Integer year,
+                                                                   @Param("tenantId")String tenantId,@Param("userType")String userType,@Param("permissonType")Integer permissonType,
+                                                                   @Param("programItems")List<ProgramItem> programItems);
+
+
+
     List<MonitorDataChartReportDeviceDto> DeviceAlarmReport(@Param("dateType") String dateType, @Param("sceneIds")List<Long> sceneIds,
                                                             @Param("beginDate") LocalDate beginDate, @Param("endDate")LocalDate endDate,
                                                             @Param("tenantId")String tenantId, @Param("userType")String userType, @Param("permissonType")Integer permissonType,

+ 14 - 7
sms_water/src/main/java/com/huaxu/dto/DeviceCheckAlarmDto.java

@@ -1,6 +1,7 @@
 package com.huaxu.dto;
 
 import com.huaxu.common.CalcUtil;
+import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
@@ -18,13 +19,19 @@ import java.util.Date;
 public class DeviceCheckAlarmDto {
 
     private String tenantId;
-    private Integer deviceId;
-    private String deviceName;
-    private Integer companyOrgId;
-    private Integer deptOrgId;
-    private String alarmType;
-    private Integer attributeId;//
-    private Date lastUpdateTime;//
+
+    private Integer parentSceneId;  //一级场景id
+    private String parentSceneName;//一级场景名称
+    private Integer sceneId;//所属场景id
+    private String sceneName;//所属场景名称
+
+    private Integer deviceId;//设备id
+    private String deviceName;//设备名称
+    private Integer companyOrgId;//公司id
+    private Integer deptOrgId;//部门id
+    private String alarmType;//报警类型
+    private Integer attributeId;//设备属性
+    private Date lastUpdateTime;//上次上报时间
 
     private Integer alarmSettingId;//报警设置id
     private Double duration;//离线时间

+ 9 - 0
sms_water/src/main/java/com/huaxu/entity/AlarmDetailsEntity.java

@@ -25,6 +25,15 @@ public class AlarmDetailsEntity implements Serializable {
     @ApiModelProperty(value = "租户标识")
     private String tenantId;
 
+    @ApiModelProperty("一级场景信息")
+    private Integer parentSceneId;
+    @ApiModelProperty("一级场景名称")
+    private String parentSceneName;
+    @ApiModelProperty("场景信息")
+    private Integer sceneId;
+    @ApiModelProperty("场景名称")
+    private String sceneName;
+
     @ApiModelProperty(value = "设备信息")
     private Integer deviceId;
     @ApiModelProperty(value = "所属公司")

+ 0 - 8
sms_water/src/main/java/com/huaxu/entity/MonitorDataEntity.java

@@ -32,14 +32,6 @@ public class MonitorDataEntity implements Serializable {
     private Integer hour;
     @ApiModelProperty("租户标识")
     private String tenantId;
-    @ApiModelProperty("一级场景信息")
-    private Integer parentSceneId;
-    @ApiModelProperty("一级场景名称")
-    private String parentSceneName;
-    @ApiModelProperty("场景信息")
-    private Integer sceneId;
-    @ApiModelProperty("场景名称")
-    private String sceneName;
     @ApiModelProperty("设备信息")
     private Integer deviceId;
     @ApiModelProperty("设备名称")

+ 6 - 6
sms_water/src/main/java/com/huaxu/rabbitmq/ReceiveData.java

@@ -95,13 +95,10 @@ public class ReceiveData {
 
             String devcieCode =jsonObject .getString("unitIdentifier");
             JSONObject receiveData =JSONObject.parseObject(jsonObject .getString("parsedData"));
-
-            //保存报警数据
             if(StringUtils.isBlank(devcieCode)){
                 return ;
             }
-            List<MonitorDataEntity> list = new ArrayList<>();
-            //暂时测试共用一个设备数据
+
             MonitorDataEntity monitorDataEntity =  monitorDataService.getDeviceMonitorInfoByDeviceCode(devcieCode);
             //
             //查询不到设备或者设备属性为空
@@ -138,8 +135,6 @@ public class ReceiveData {
                Map<Integer,AlarmDetailsDto> alarmDetailsDtoMap = alarmDetailsDtos.stream().collect(Collectors.toMap(AlarmDetailsDto::getAlarmSettingId, a -> a,(k1, k2)->k1));
 
                List<AlarmDetailsEntity> insert =new ArrayList<>();
-               List<AlarmDetailsDto> update =new ArrayList<>();
-               List<AlarmDetailsDto> delete =new ArrayList<>();
 
                //校验各参数异常情况
                for(DeviceCheckAlarmDto deviceCheckAlarmDto:deviceCheckAlarmDtos){
@@ -162,6 +157,11 @@ public class ReceiveData {
                        }else{
                            AlarmDetailsEntity alarmDetailsEntity = new AlarmDetailsDto();
                            alarmDetailsEntity.setTenantId(deviceCheckAlarmDto.getTenantId());
+                           alarmDetailsEntity.setParentSceneId(deviceCheckAlarmDto.getParentSceneId());
+                           alarmDetailsEntity.setParentSceneName(deviceCheckAlarmDto.getParentSceneName());
+                           alarmDetailsEntity.setSceneId(deviceCheckAlarmDto.getSceneId());
+                           alarmDetailsEntity.setSceneName(deviceCheckAlarmDto.getSceneName());
+
                            alarmDetailsEntity.setDeviceId(deviceCheckAlarmDto.getDeviceId());
                            alarmDetailsEntity.setCompanyOrgId(deviceCheckAlarmDto.getCompanyOrgId());
                            alarmDetailsEntity.setDeptOrgId(deviceCheckAlarmDto.getDeptOrgId());

+ 4 - 0
sms_water/src/main/java/com/huaxu/service/impl/AlarmDetailsServiceImpl.java

@@ -165,6 +165,10 @@ public class AlarmDetailsServiceImpl implements AlarmDetailsService {
                     alarmDetailsEntity.setStatus(1);
                     alarmDetailsEntity.setOpState(1);
                     alarmDetailsEntity.setState(1);
+                    alarmDetailsEntity.setParentSceneId(d.getParentSceneId());
+                    alarmDetailsEntity.setParentSceneName(d.getParentSceneName());
+                    alarmDetailsEntity.setSceneId(d.getSceneId());
+                    alarmDetailsEntity.setSceneName(d.getSceneName());
                     alarmDetailsEntity.setAlarmStartTime(new Date());
                     alarmDetailsEntity.setAlarmContent(d.getDeviceName()+"离线时间"+d.getAlarmCondition() +d.getAlarmValue()+"分钟");
                     alarmDetailsEntity.setAlarmValue(d.getDuration());

+ 61 - 45
sms_water/src/main/java/com/huaxu/service/impl/MonitorDataReportServiceImpl.java

@@ -7,6 +7,7 @@ import com.huaxu.dto.MonitorDataChartReportValueDto;
 import com.huaxu.model.LoginUser;
 import com.huaxu.service.MonitorDataReportService;
 import com.huaxu.util.UserUtil;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
@@ -29,7 +30,7 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
     @Override
     public List<MonitorDataChartReportDeviceDto> MonitorDataChartReportByDay(Long sceneId,Integer year,Integer month ,Integer day) {
         LoginUser loginUser = UserUtil.getCurrentUser();
-        List<MonitorDataChartReportDeviceDto> monitorDataChartReportDeviceDtos =  monitorDataReportMapper.MonitorDataChartReport(3,year,month,day,sceneId,"sms_day_report",
+        List<MonitorDataChartReportDeviceDto> monitorDataChartReportDeviceDtos =  monitorDataReportMapper.MonitorDataChartReportByDay(year,month,day,sceneId,
                 loginUser.getTenantId(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
         FillLoseData(monitorDataChartReportDeviceDtos,3,year,month,day);
         return monitorDataChartReportDeviceDtos;
@@ -38,7 +39,7 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
     @Override
     public List<MonitorDataChartReportDeviceDto> MonitorDataChartReportByMonth(Long sceneId,Integer year,Integer month ) {
         LoginUser loginUser = UserUtil.getCurrentUser();
-        List<MonitorDataChartReportDeviceDto> monitorDataChartReportDeviceDtos = monitorDataReportMapper.MonitorDataChartReport(2,year,month,null,sceneId,"sms_month_report",
+        List<MonitorDataChartReportDeviceDto> monitorDataChartReportDeviceDtos = monitorDataReportMapper.MonitorDataChartReportByMonth(year,month,sceneId,
                 loginUser.getTenantId(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
         FillLoseData(monitorDataChartReportDeviceDtos,2,year,month,1);
         return monitorDataChartReportDeviceDtos;
@@ -47,7 +48,7 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
     @Override
     public List<MonitorDataChartReportDeviceDto> MonitorDataChartReportByYear(Long sceneId,Integer year) {
         LoginUser loginUser = UserUtil.getCurrentUser();
-        List<MonitorDataChartReportDeviceDto> monitorDataChartReportDeviceDtos = monitorDataReportMapper.MonitorDataChartReport(1,year,null,null,sceneId,"sms_year_report",
+        List<MonitorDataChartReportDeviceDto> monitorDataChartReportDeviceDtos = monitorDataReportMapper.MonitorDataChartReportByYear(year,sceneId,
                 loginUser.getTenantId(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
         FillLoseData(monitorDataChartReportDeviceDtos,1,year,1,1);
         return monitorDataChartReportDeviceDtos;
@@ -61,6 +62,8 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
             if(monitorDataChartReportDeviceDto != null && monitorDataChartReportDeviceDto.getAttributeData() != null){
                 for(MonitorDataChartReportAttributeDto monitorDataChartReportAttributeDto:monitorDataChartReportDeviceDto.getAttributeData()){
                     if(monitorDataChartReportAttributeDto != null && monitorDataChartReportAttributeDto.getMonitorDataChartReportValue() != null){
+                        String unit = monitorDataChartReportAttributeDto.getUnit();
+                        unit= StringUtils.isNotBlank(unit)?unit:"";
                         List<MonitorDataChartReportValueDto> monitorDataChartReportValueDtos = monitorDataChartReportAttributeDto.getMonitorDataChartReportValue();
                         Integer maxValue =0;
                         LocalDateTime localDateTime=LocalDateTime.now();
@@ -77,67 +80,58 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
                             maxValue=12;
                         }
                         for(int i=0;i<maxValue;i++){
-                            if(i == monitorDataChartReportValueDtos.size()){
+                            if(i == monitorDataChartReportValueDtos.size() || !monitorDataChartReportValueDtos.get(i).getDateLabel().equals(i+growingBase)){
                                 MonitorDataChartReportValueDto monitorDataChartReportValueDto = new MonitorDataChartReportValueDto();
                                 monitorDataChartReportValueDto.setData(0.0);
+                                LocalDateTime dateTime=localDateTime.now();
                                 if(type != null && type ==3){
-                                    LocalDateTime dateTime= localDateTime.plusHours(i);
-                                    monitorDataChartReportValueDto.setDate(dateTime);
+                                    dateTime= localDateTime.plusHours(i);
                                     monitorDataChartReportValueDto.setDateStringLabel(
-                                                        dateTime.getYear()+"-"+
-                                                        dateTime.getMonthValue()+"-"+
-                                                        dateTime.getDayOfMonth()+" "+
-                                                        dateTime.getHour()+":00");
+                                            dateTime.getYear()+"-"+
+                                                    String.format("%02d",dateTime.getMonthValue())+"-"+
+                                                    String.format("%02d",dateTime.getDayOfMonth())+" "+
+                                                    String.format("%02d",dateTime.getHour())+":00");
                                 }
                                 if(type != null && type ==2){
-                                    LocalDateTime dateTime= localDateTime.plusDays(i);
-                                    monitorDataChartReportValueDto.setDate(dateTime);
+                                    dateTime= localDateTime.plusDays(i);
                                     monitorDataChartReportValueDto.setDateStringLabel(
-                                                    dateTime.getYear()+"-"+
-                                                    dateTime.getMonthValue()+"-"+
-                                                    dateTime.getDayOfMonth());
+                                            dateTime.getYear()+"-"+
+                                                    String.format("%02d",dateTime.getMonthValue())+"-"+
+                                                    String.format("%02d",dateTime.getDayOfMonth()));
                                 }
                                 if(type != null && type ==1){
-                                    LocalDateTime dateTime= localDateTime.plusMonths(i);
-                                    monitorDataChartReportValueDto.setDate(dateTime);
+                                    dateTime= localDateTime.plusMonths(i);
                                     monitorDataChartReportValueDto.setDateStringLabel(
                                             dateTime.getYear()+"-"+
-                                                    dateTime.getMonthValue());
+                                                    String.format("%02d",dateTime.getMonthValue()));
                                 }
+                                monitorDataChartReportValueDto.setDate(dateTime);
+
                                 monitorDataChartReportValueDto.setDateLabel(i+growingBase);
                                 monitorDataChartReportValueDto.setMonitorData("");
                                 monitorDataChartReportValueDtos.add(i,monitorDataChartReportValueDto);
-                            }else
-                            if(!monitorDataChartReportValueDtos.get(i).getDateLabel().equals(i+growingBase)){
-                                MonitorDataChartReportValueDto monitorDataChartReportValueDto = new MonitorDataChartReportValueDto();
-                                monitorDataChartReportValueDto.setData(0.0);
+                            }else{
+                                MonitorDataChartReportValueDto monitorDataChartReportValueDto =monitorDataChartReportValueDtos.get(i);
+                                monitorDataChartReportValueDto.setMonitorData(monitorDataChartReportValueDto.getData()+""+unit);
+                                LocalDateTime dateTime = monitorDataChartReportValueDto.getDate();
                                 if(type != null && type ==3){
-                                    LocalDateTime dateTime= localDateTime.plusHours(i);
-                                    monitorDataChartReportValueDto.setDate(dateTime);
                                     monitorDataChartReportValueDto.setDateStringLabel(
                                             dateTime.getYear()+"-"+
-                                                    dateTime.getMonthValue()+"-"+
-                                                    dateTime.getDayOfMonth()+" "+
-                                                    dateTime.getHour()+":00");
+                                                    String.format("%02d",dateTime.getMonthValue())+"-"+
+                                                    String.format("%02d",dateTime.getDayOfMonth())+" "+
+                                                    String.format("%02d",dateTime.getHour())+":00");
                                 }
                                 if(type != null && type ==2){
-                                    LocalDateTime dateTime= localDateTime.plusDays(i);
-                                    monitorDataChartReportValueDto.setDate(dateTime);
                                     monitorDataChartReportValueDto.setDateStringLabel(
                                             dateTime.getYear()+"-"+
-                                                    dateTime.getMonthValue()+"-"+
-                                                    dateTime.getDayOfMonth());
+                                                    String.format("%02d",dateTime.getMonthValue())+"-"+
+                                                    String.format("%02d",dateTime.getDayOfMonth()));
                                 }
                                 if(type != null && type ==1){
-                                    LocalDateTime dateTime= localDateTime.plusMonths(i);
-                                    monitorDataChartReportValueDto.setDate(dateTime);
                                     monitorDataChartReportValueDto.setDateStringLabel(
                                             dateTime.getYear()+"-"+
-                                                    dateTime.getMonthValue());
+                                                    String.format("%02d",dateTime.getMonthValue()));
                                 }
-                                monitorDataChartReportValueDto.setDateLabel(i+growingBase);
-                                monitorDataChartReportValueDto.setMonitorData("");
-                                monitorDataChartReportValueDtos.add(i,monitorDataChartReportValueDto);
                             }
                         }
                     }
@@ -179,20 +173,42 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
     @Override
     public List<MonitorDataChartReportDeviceDto> MonitorDataQualityReport(Integer type,List<Long>  sceneIds,Integer year,Integer month ,Integer day) {
         LoginUser loginUser = UserUtil.getCurrentUser();
-//        List<MonitorDataChartReportDeviceDto> monitorDataChartReportDeviceDtos = monitorDataReportMapper.MonitorDataChartReport(1,year,null,null,sceneId,"sms_day_report",
-//                loginUser.getTenantId(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
-        List<MonitorDataChartReportDeviceDto> monitorDataChartReportDeviceDtos = monitorDataReportMapper.MonitorDataQualityReport(type,sceneIds,year,month,day,
-                loginUser.getTenantId(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
-        FillLoseData(monitorDataChartReportDeviceDtos,type,year,month,day);
+
+        List<MonitorDataChartReportDeviceDto> monitorDataChartReportDeviceDtos = null;
+        if(type != null && type == 3){
+            monitorDataChartReportDeviceDtos = monitorDataReportMapper.MonitorDataQualityReportByDay(sceneIds,year,month,day,
+                    loginUser.getTenantId(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
+        } else if(type != null && type == 2){
+            monitorDataChartReportDeviceDtos = monitorDataReportMapper.MonitorDataQualityReportByMonth(sceneIds,year,month,
+                    loginUser.getTenantId(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
+        } else if(type != null && type == 1){
+            monitorDataChartReportDeviceDtos = monitorDataReportMapper.MonitorDataQualityReportByYear(sceneIds,year,
+                    loginUser.getTenantId(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
+        }
+        if(monitorDataChartReportDeviceDtos != null){
+            FillLoseData(monitorDataChartReportDeviceDtos,type,year,month,day);
+        }
+
         return monitorDataChartReportDeviceDtos;
     }
 
     @Override
     public List<MonitorDataChartReportDeviceDto> MonitorDataEnergyReport(Integer type,List<Long> sceneIds,Integer year,Integer month ,Integer day) {
         LoginUser loginUser = UserUtil.getCurrentUser();
-        List<MonitorDataChartReportDeviceDto> monitorDataChartReportDeviceDtos = monitorDataReportMapper.MonitorDataEnergyReport(type,sceneIds,year,month,day,
-                loginUser.getTenantId(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
-        FillLoseData(monitorDataChartReportDeviceDtos,type,year,month,day);
+        List<MonitorDataChartReportDeviceDto> monitorDataChartReportDeviceDtos = null;
+        if(type != null && type == 3){
+            monitorDataChartReportDeviceDtos = monitorDataReportMapper.MonitorDataEnergyReportByDay(sceneIds,year,month,day,
+                   loginUser.getTenantId(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
+       } else if(type != null && type == 2){
+            monitorDataChartReportDeviceDtos = monitorDataReportMapper.MonitorDataEnergyReportByMonth(sceneIds,year,month,
+                   loginUser.getTenantId(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
+       } else if(type != null && type == 1){
+           monitorDataChartReportDeviceDtos = monitorDataReportMapper.MonitorDataEnergyReportByYear(sceneIds,year,
+                   loginUser.getTenantId(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
+       }
+        if(monitorDataChartReportDeviceDtos != null){
+            FillLoseData(monitorDataChartReportDeviceDtos,type,year,month,day);
+        }
         return monitorDataChartReportDeviceDtos;
     }
 }

+ 132 - 15
sms_water/src/main/java/com/huaxu/service/impl/MonitorDataServiceImpl.java

@@ -1,11 +1,8 @@
 package com.huaxu.service.impl;
 
 import com.huaxu.dao.MonitorDataMapper;
-import com.huaxu.dto.AlarmDetailsDto;
 import com.huaxu.entity.DayReportEntity;
 import com.huaxu.entity.MonitorDataEntity;
-import com.huaxu.entity.MonthReportEntity;
-import com.huaxu.entity.YearReportEntity;
 import com.huaxu.quartz.entity.QuartzEntity;
 import com.huaxu.quartz.job.MonitorDataReportByDayJob;
 import com.huaxu.quartz.job.MonitorDataReportByMonthJob;
@@ -14,7 +11,9 @@ import com.huaxu.quartz.service.JobAndTriggerService;
 import com.huaxu.service.MonitorDataService;
 import com.huaxu.util.ByteArrayUtils;
 import com.huaxu.util.RedisUtil;
+import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.InitializingBean;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Sort;
@@ -29,6 +28,7 @@ import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
+import java.time.Duration;
 import java.time.LocalDateTime;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -105,7 +105,6 @@ public class MonitorDataServiceImpl implements MonitorDataService , Initializing
         Query query = new Query(Criteria.where("id").is(monitorDataEntity.getId()));
 
         Update update = new Update();
-        update.set("sceneName", monitorDataEntity.getSceneName());
         update.set("deviceName", monitorDataEntity.getDeviceName());
 
 
@@ -135,8 +134,7 @@ public class MonitorDataServiceImpl implements MonitorDataService , Initializing
                 Aggregation.match(criteria),    //查询条件
                 Aggregation.unwind("dataValues"),//将文档中的某一个数组类型字段拆分成多条,每条包含数组中的一个值
                 Aggregation.sort(Sort.Direction.DESC, "collectDate"),//在聚合之前对数据进行排序
-                Aggregation.group("tenantId","year","month","day","hour","parentSceneId","parentSceneName","sceneId",
-                        "sceneName","deviceId","deviceName","deviceCode","dataValues.attributeId","dataValues.attributeName" )
+                Aggregation.group("year","month","day","hour","tenantId","deviceId","deviceName","deviceCode","dataValues.attributeId","dataValues.attributeName" )
                         .min("$dataValues.dataValue").as("minValue")
                         .max("$dataValues.dataValue").as("maxValue")
                         .avg("$dataValues.dataValue").as("avgValue")
@@ -157,23 +155,51 @@ public class MonitorDataServiceImpl implements MonitorDataService , Initializing
         //取前一个小时的时间
         LocalDateTime dateTime = LocalDateTime.now().plusHours(-1);
 
-        List<DayReportEntity> HourData = getMonitorDataGroupByHour(dateTime);
-        List<DayReportEntity> lastHourData = getMonitorDataGroupByHour(dateTime.plusHours(-1));
-
-        Map<String,DayReportEntity> lastHourDataMap = lastHourData.stream().collect(Collectors.toMap(DayReportEntity::getMapkey, a -> a,(k1, k2)->k1));
+        List<DayReportEntity> hourDatas = getMonitorDataGroupByHour(dateTime);
+        List<DayReportEntity> lastHourDatas = getMonitorDataGroupByHour(dateTime.plusHours(-1));
 
+        Map<String,DayReportEntity> lastHourDataMap = lastHourDatas.stream().collect(Collectors.toMap(DayReportEntity::getMapkey, a -> a,(k1, k2)->k1));
         //保存日报表数据
-        if(HourData.size()>0){
+        if(hourDatas.size()>0){
             //计算累计值
-            for(DayReportEntity dayReportEntity : HourData){
+            for(DayReportEntity dayReportEntity : hourDatas){
                 if(dayReportEntity.getLatestValue()!=null && lastHourDataMap.containsKey(dayReportEntity.getMapkey())
-                 && lastHourDataMap.get(dayReportEntity.getMapkey()).getLatestValue() != null){
+                        && lastHourDataMap.get(dayReportEntity.getMapkey()).getLatestValue() != null){
                     dayReportEntity.setSumValue(new BigDecimal(dayReportEntity.getLatestValue().toString()).subtract(new BigDecimal(lastHourDataMap.get(dayReportEntity.getMapkey()).getLatestValue().toString())).doubleValue());
                 }
             }
-            monitorDataMapper.batchInsertDayReport(HourData);
+            monitorDataMapper.batchInsertDayReport(hourDatas);
         }
-        return HourData;
+        return hourDatas;
+
+//        Map<String,DayReportEntity> hourDataMap = hourDatas.stream().collect(Collectors.toMap(DayReportEntity::getMapkey, a -> a,(k1, k2)->k1));
+//        //需要统计的属性值(租户——场景——设备——属性)
+//        List<DayReportEntity> dayReportEntities = monitorDataMapper.getReportBaseInfo();
+//        //保存日报表数据
+//        if(hourDatas.size()>0 && dayReportEntities.size()>0){
+//           //填充数据
+//
+//            dayReportEntities =  dayReportEntities.stream()
+//                            .filter(d ->StringUtils.isNotBlank(d.getMapkey()) && hourDataMap.containsKey(d.getMapkey()))
+//                            .map(dayReportEntity ->{
+//                                DayReportEntity hourData = hourDataMap.get(dayReportEntity.getMapkey());
+//                                dayReportEntity.setYear(hourData.getYear());
+//                                dayReportEntity.setMonth(hourData.getMonth());
+//                                dayReportEntity.setDay(hourData.getDay());
+//                                dayReportEntity.setHour(hourData.getHour());
+//                                dayReportEntity.setMinValue(hourData.getMinValue());
+//                                dayReportEntity.setMaxValue(hourData.getMaxValue());
+//                                dayReportEntity.setAvgValue(hourData.getAvgValue());
+//                                dayReportEntity.setCollectDate(hourData.getCollectDate());
+//                                dayReportEntity.setLatestValue(hourData.getLatestValue());
+//                                if(lastHourDataMap.containsKey(dayReportEntity.getMapkey()) && lastHourDataMap.get(dayReportEntity.getMapkey()).getLatestValue() != null){
+//                                    dayReportEntity.setSumValue(new BigDecimal(hourDataMap.get(dayReportEntity.getMapkey()).getLatestValue().toString()).subtract(new BigDecimal(lastHourDataMap.get(dayReportEntity.getMapkey()).getLatestValue().toString())).doubleValue());
+//                                }
+//                                return dayReportEntity;
+//                            }).collect(Collectors.toList());
+//            monitorDataMapper.batchInsertDayReport(dayReportEntities);
+//        }
+//        return dayReportEntities;
     }
 
     @Override
@@ -191,4 +217,95 @@ public class MonitorDataServiceImpl implements MonitorDataService , Initializing
         //保存日报表数据
         monitorDataMapper.batchInsertYearReport(dateTime.getYear(),dateTime.getMonthValue());
     }
+
+
+    public static void main(String[] args) {
+        List<tt> l1 =new ArrayList<>(10000);
+       for(Integer i=0 ;i<10000; i++){
+           if(i % 10 ==0){
+               l1.add(null);
+           }else{
+                l1.add(new tt(i.toString(),"a"+i.toString(),""));
+           }
+
+       }
+
+        List<tt> l2 =new ArrayList<>(10000);
+
+        for(Integer i=0 ;i<10000; i++){
+            l2.add(new tt(i.toString(),"","c"+i.toString()));
+        }
+
+        LocalDateTime dateTime =LocalDateTime.now();
+
+//        l1.removeAll(Collections.singleton(null));
+//System.out.println(l1.size());
+//        l1.removeIf(Objects::isNull);
+//
+
+        Map<String ,tt> map =l2.stream().collect(Collectors.toMap(tt::getA, a -> a,(k1, k2)->k1));
+
+        l1 = l1.stream().filter(Objects::nonNull)
+                .map(t -> {
+                    if(map.containsKey(t.getA())&&map.get(t.getA()).getC() != null){
+                        t.setC(map.get(t.getA()).getC());
+                    }
+                    return t;
+                })
+                .collect(Collectors.toList());
+//        for(tt t:l1){
+//            if(map.containsKey(t.getA())&&map.get(t.getA()).getC() != null){
+//                t.setC(map.get(t.getA()).getC());
+//            }
+//        }
+//        List<tt> l=l1.stream().map(la ->
+//                     l2.stream()
+//                            .filter( lb ->  la.getA().equals(lb.getA()))
+//                            .map(lb -> {
+//                                 la.setC(lb.getC());
+//                                 return la;
+//                            }).collect(Collectors.toList())
+//        ).flatMap(List::stream).collect(Collectors.toList());
+
+//        List<tt> l = l1.stream()
+//                .map(map -> l2.stream()
+//                        .filter(m -> Objects.equals(m.getA(), map.getA()))
+//                        .findFirst().map(m -> {
+//                            map.setC(m.getC());
+//                            return map;
+//                        }).orElse(null))
+//                .filter(Objects::nonNull).collect(Collectors.toList());
+
+        LocalDateTime dateTime2 =LocalDateTime.now();
+        Duration duration =Duration.between(dateTime,dateTime2);
+        System.out.println(duration.toMillis());
+        System.out.println(l1.size());
+        System.out.println(l1.get(l1.size()-1).toString());
+
+
+
+
+
+    }
+
 }
+@Data
+class tt{
+    private String a;
+    private String b;
+    private String c;
+    public tt(String a,String b,String c){
+        this.a=a;
+        this.b=b;
+        this.c=c;
+    }
+
+    @Override
+    public String toString() {
+        return "tt{" +
+                "a='" + a + '\'' +
+                ", b='" + b + '\'' +
+                ", c='" + c + '\'' +
+                '}';
+    }
+}

+ 1 - 17
sms_water/src/main/java/com/huaxu/service/impl/TestDataServiceImpl.java

@@ -147,21 +147,5 @@ public class TestDataServiceImpl implements TestDataService {
             }
         }
     }
-
-    public static void main(String[] args) {
-        int max=8,min=7;
-        int ran2 = (int) (Math.random()*(max-min+1)+min);
-        int a=(int) (Math.random()*10);
-        int b=(int)(Math.random()*10);
-        System.out.println(a+"..."+b+"......."+ran2);
-
-//        Long timestamp = LocalDateTime.now().toEpochSecond(ZoneOffset.ofHours(8));
-//        Long timestamp2 = LocalDateTime.now().toInstant(ZoneOffset.ofHours(8)).toEpochMilli();
-//        LocalDate localDate = Instant.ofEpochSecond(timestamp).atZone(ZoneOffset.ofHours(8)).toLocalDate();
-//        LocalDateTime localDateTime = Instant.ofEpochSecond(timestamp).atZone(ZoneOffset.ofHours(8)).toLocalDateTime();
-//        System.out.println(timestamp);
-//        System.out.println(timestamp2);
-//        System.out.println(localDate.toString());
-//        System.out.println(localDateTime.toString());
-    }
+    
 }

+ 13 - 6
sms_water/src/main/resources/mapper/AlarmDetailMapper.xml

@@ -27,7 +27,7 @@
             ,timestampdiff(MINUTE,ifnull(a.ALARM_END_TIME,now()),a.ALARM_START_TIME) as "duration"
             /*,(case when ALARM_END_TIME is not null then timestampdiff(MINUTE,a.ALARM_END_TIME,a.ALARM_START_TIME) else null end ) as "duration"*/
             ,att.`NAME` as "attributeName"
-            ,s.SCENE_NAME as "sceneName"
+            ,a.SCENE_NAME as "sceneName"
             ,d.DEVICE_NAME as "deviceName"
             ,t.DEVICE_TYPE as "deviceType"
             ,d.ADDRESS as "address"
@@ -43,7 +43,7 @@
             a.ID as "id"
             ,a.STATE as "state"
             ,a.OP_STATE as "opState"
-            ,s.SCENE_NAME as "sceneName"
+            ,a.SCENE_NAME as "sceneName"
             ,d.DEVICE_NAME as "deviceName"
             ,t.DEVICE_TYPE as "deviceType"
             ,a.ALARM_TYPE as "alarmType"
@@ -52,8 +52,6 @@
             ,d.ADDRESS as "address"
             ,d.POINT_X as "pointX"
             ,d.POINT_Y as "pointY"
-
-            ,ast.id as "alarmSettingId"
             ,concat(a.ALARM_VALUE,ifnull(att.unit,'')) as "alarmValue"
             ,a.ALARM_CONTENT as "alarmContent"
 
@@ -63,7 +61,7 @@
             a.ID as "id"
             ,a.STATE as "state"
             ,a.OP_STATE as "opState"
-            ,s.SCENE_NAME as "sceneName"
+            ,a.SCENE_NAME as "sceneName"
             ,d.DEVICE_NAME as "deviceName"
             ,t.DEVICE_TYPE as "deviceType"
             ,a.ALARM_TYPE as "alarmType"
@@ -88,7 +86,6 @@
 
     <sql id="alarmDetailJoins">
         left join sms_device d on a.DEVICE_ID =d.id and d.`STATUS` = 1
-        left join sms_scene s on d.SCENE_ID =s.id and s.`STATUS` =1
         left join sms_device_type t on d.DEVICE_TYPE_ID =t.ID
         left join sms_alarm_setting ast on ast.id= a.alarm_setting_id
         left join sms_device_attribute att on att.id=a.ATTRIBUTE_ID
@@ -606,6 +603,12 @@
             ,d.DEVICE_NAME as "deviceName"
             ,d.COMPANY_ORG_ID as "companyOrgId"
             ,d.DEPT_ORG_ID as "deptOrgId"
+
+            ,a.PARENT_SCENE_ID as "parentSceneId"
+            ,a.PARENT_SCENE_NAME as "parentSceneName"
+            ,a.SCENE_ID as "sceneId"
+            ,a.SCENE_NAME as "sceneName"
+
             ,a.ALARM_TYPE as "alarmType"
             ,a.ATTRIBUTE_ID as "attributeId"
             ,d.LAST_UPDATE_TIME as "lastUpdateTime"
@@ -634,6 +637,10 @@
     <select id="selectStateAlarm" resultType="com.huaxu.dto.AlarmDetailsDto">
         select
             id as "id"
+            ,PARENT_SCENE_ID as "parentSceneId"
+            ,PARENT_SCENE_NAME as "parentSceneName"
+            ,SCENE_ID as "sceneId"
+            ,SCENE_NAME as "sceneName"
             ,DEVICE_ID as "deviceId"
             ,ATTRIBUTE_ID as "attributeId"
             ,ALARM_VALUE as "alarmValue"

+ 9 - 19
sms_water/src/main/resources/mapper/MonitorDataMapper.xml

@@ -4,10 +4,6 @@
 
     <resultMap id="DeviceMonitorInfo" type="com.huaxu.entity.MonitorDataEntity">
         <result property="tenantId" column="tenantId" jdbcType="INTEGER"/>
-        <result property="parentSceneId" column="parentSceneId" jdbcType="INTEGER"/>
-        <result property="parentSceneName" column="parentSceneName" jdbcType="INTEGER"/>
-        <result property="sceneId" column="sceneId" jdbcType="INTEGER"/>
-        <result property="sceneName" column="sceneName" jdbcType="INTEGER"/>
         <result property="deviceId" column="deviceId" jdbcType="INTEGER"/>
         <result property="deviceName" column="deviceName" jdbcType="INTEGER"/>
         <result property="deviceCode" column="deviceCode" jdbcType="INTEGER"/>
@@ -22,10 +18,6 @@
 
         select
             d.TENANT_ID as "tenantId"
-            ,ps.id as "parentSceneId"
-            ,ps.SCENE_NAME as "parentSceneName"
-            ,s.id as "sceneId"
-            ,s.SCENE_NAME as "sceneName"
             ,d.id as "deviceId"
             ,d.DEVICE_NAME as "deviceName"
             ,d.DEVICE_CODE as "deviceCode"
@@ -34,8 +26,6 @@
             ,da.IDENTIFIER as "identifier"
             ,da.UNIT as "unit"
         from sms_device d
-        left join sms_scene s on s.id = d.SCENE_ID and s.STATUS = 1
-        left join sms_scene ps on s.PARENT_SCENE_IDS LIKE concat('%,', ps.id ,',%') and ps.PARENT_SCENE_ID ='0' and ps.STATUS = 1
         left join sms_device_type dt on dt.id=d.DEVICE_TYPE_ID and dt.STATUS = 1
         left join sms_device_attribute da on dt.id=da.DEVICE_TYPE_ID and da.STATUS = 1
         where d.STATUS =1 and d.DEVICE_CODE=#{deviceCode}
@@ -44,38 +34,38 @@
 
     <insert id="batchInsertDayReport">
         INSERT INTO sms_day_report(
-        TENANT_ID, YEAR, MONTH, DAY, HOUR, PARENT_SCENE_ID, PARENT_SCENE_NAME, SCENE_ID, SCENE_NAME, DEVICE_ID, DEVICE_NAME, DEVICE_CODE, ATTRIBUTE_ID,
+        TENANT_ID, YEAR, MONTH, DAY, HOUR, DEVICE_ID, DEVICE_NAME, DEVICE_CODE, ATTRIBUTE_ID,
         ATTRIBUTE_NAME, MIN_VALUE, MAX_VALUE, AVG_VALUE, SUM_VALUE, LATEST_VALUE, COLLECT_DATE)
         VALUES
         <foreach collection="dayReportEntities" item="item" index="index" separator=",">
-            (#{item.tenantId},#{item.year},#{item.month},#{item.day},#{item.hour},#{item.parentSceneId},#{item.parentSceneName},#{item.sceneId},#{item.sceneName},#{item.deviceId},#{item.deviceName},#{item.deviceCode},#{item.attributeId},
+            (#{item.tenantId},#{item.year},#{item.month},#{item.day},#{item.hour},#{item.deviceId},#{item.deviceName},#{item.deviceCode},#{item.attributeId},
             #{item.attributeName},#{item.minValue},#{item.maxValue},#{item.avgValue},#{item.sumValue},#{item.latestValue},#{item.collectDate})
         </foreach>
     </insert>
 
     <insert id="batchInsertYearReport">
-        INSERT INTO sms_year_report( TENANT_ID, PARENT_SCENE_ID, PARENT_SCENE_NAME, SCENE_ID, SCENE_NAME, DEVICE_ID, DEVICE_NAME, DEVICE_CODE, ATTRIBUTE_ID, ATTRIBUTE_NAME, YEAR, MONTH, MIN_VALUE, MAX_VALUE, AVG_VALUE, SUM_VALUE, LATEST_VALUE, COLLECT_DATE)
-        select TENANT_ID, PARENT_SCENE_ID, PARENT_SCENE_NAME, SCENE_ID, SCENE_NAME, DEVICE_ID, DEVICE_NAME, DEVICE_CODE, ATTRIBUTE_ID, ATTRIBUTE_NAME,  YEAR, MONTH
+        INSERT INTO sms_year_report( TENANT_ID, DEVICE_ID, DEVICE_NAME, DEVICE_CODE, ATTRIBUTE_ID, ATTRIBUTE_NAME, YEAR, MONTH, MIN_VALUE, MAX_VALUE, AVG_VALUE, SUM_VALUE, LATEST_VALUE, COLLECT_DATE)
+        select TENANT_ID, DEVICE_ID, DEVICE_NAME, DEVICE_CODE, ATTRIBUTE_ID, ATTRIBUTE_NAME,  YEAR, MONTH
             ,min(MIN_VALUE) MIN_VALUE
             ,max(MAX_VALUE) MAX_VALUE
             ,avg(AVG_VALUE) AVG_VALUE
             ,sum(SUM_VALUE) SUM_VALUE
-            ,(select LATEST_VALUE from sms_day_report where DEVICE_ID =a.DEVICE_ID and ATTRIBUTE_ID = a.ATTRIBUTE_ID and COLLECT_DATE = max(a.COLLECT_DATE)) LATEST_VALUE
+            ,(select LATEST_VALUE from sms_month_report where id = max(a.id)) LATEST_VALUE
             ,max(COLLECT_DATE) COLLECT_DATE
         from sms_month_report a
         where year =#{year} and month =#{month}
-        group by TENANT_ID, PARENT_SCENE_ID, PARENT_SCENE_NAME, SCENE_ID, SCENE_NAME, DEVICE_ID, DEVICE_NAME, DEVICE_CODE, ATTRIBUTE_ID, ATTRIBUTE_NAME,  YEAR, MONTH
+        group by TENANT_ID, DEVICE_ID, DEVICE_NAME, DEVICE_CODE, ATTRIBUTE_ID, ATTRIBUTE_NAME,  YEAR, MONTH
     </insert>
 
     <insert id="batchInsertMonthReport">
-        INSERT INTO sms_month_report( TENANT_ID, PARENT_SCENE_ID, PARENT_SCENE_NAME, SCENE_ID, SCENE_NAME, DEVICE_ID, DEVICE_NAME, DEVICE_CODE, ATTRIBUTE_ID, ATTRIBUTE_NAME, YEAR, MONTH, DAY, MIN_VALUE, MAX_VALUE, AVG_VALUE, SUM_VALUE, LATEST_VALUE, COLLECT_DATE)
+        INSERT INTO sms_month_report( TENANT_ID, DEVICE_ID, DEVICE_NAME, DEVICE_CODE, ATTRIBUTE_ID, ATTRIBUTE_NAME, YEAR, MONTH, DAY, MIN_VALUE, MAX_VALUE, AVG_VALUE, SUM_VALUE, LATEST_VALUE, COLLECT_DATE)
 
-        select TENANT_ID, PARENT_SCENE_ID, PARENT_SCENE_NAME, SCENE_ID, SCENE_NAME, DEVICE_ID, DEVICE_NAME, DEVICE_CODE, ATTRIBUTE_ID, ATTRIBUTE_NAME,  YEAR, MONTH, DAY
+        select TENANT_ID, DEVICE_ID, DEVICE_NAME, DEVICE_CODE, ATTRIBUTE_ID, ATTRIBUTE_NAME,  YEAR, MONTH, DAY
             ,min(MIN_VALUE) MIN_VALUE
             ,max(MAX_VALUE) MAX_VALUE
             ,avg(AVG_VALUE) AVG_VALUE
             ,sum(SUM_VALUE) SUM_VALUE
-            ,(select LATEST_VALUE from sms_day_report where DEVICE_ID =a.DEVICE_ID and ATTRIBUTE_ID = a.ATTRIBUTE_ID and COLLECT_DATE = max(a.COLLECT_DATE)) LATEST_VALUE
+            ,(select LATEST_VALUE from sms_day_report where id = max(a.id)) LATEST_VALUE
             ,max(COLLECT_DATE) COLLECT_DATE
         from sms_day_report a
         where year = #{year} and month =#{month} and day=#{day}

+ 365 - 132
sms_water/src/main/resources/mapper/MonitorDataReportMapper.xml

@@ -17,8 +17,6 @@
 
     <resultMap id="MonitorDataChartReportValue" type="com.huaxu.dto.MonitorDataChartReportValueDto">
         <result property="dateLabel" column="dateLabel" />
-        <result property="dateStringLabel" column="dateStringLabel" />
-        <result property="monitorData" column="monitorData" />
         <result property="data" column="data"/>
         <result property="date" column="date"/>
     </resultMap>
@@ -28,41 +26,25 @@
         left join sms_device_attribute da on da.id=r.ATTRIBUTE_ID
         left join sms_device d on d.id=r.DEVICE_ID
     </sql>
-    <select id="MonitorDataChartReport" resultMap="MonitorDataChartReportMap">
-        select
-        <if test="type != null and type ==1">
-            r.`MONTH` as "dateLabel",
-            CONCAT(r.`YEAR`,'-',if(r.`MONTH`&lt;10,CONCAT(0,r.`MONTH`),r.`MONTH`)) as "dateStringLabel",
-        </if>
-        <if test="type != null and type ==2">
-            r.`DAY` as "dateLabel",
-            CONCAT(r.`YEAR`,'-',if(r.`MONTH`&lt;10,CONCAT(0,r.`MONTH`),r.`MONTH`),'-',if(r.`DAY`&lt;10,CONCAT(0,r.`DAY`),r.`DAY`)) as "dateStringLabel",
-        </if>
-        <if test="type != null and type ==3">
-            r.`HOUR` as "dateLabel",
-            CONCAT(r.`YEAR`,'-',if(r.`MONTH`&lt;10,CONCAT(0,r.`MONTH`),r.`MONTH`),'-',if(r.`DAY`&lt;10,CONCAT(0,r.`DAY`),r.`DAY`),' ',if(r.`HOUR`&lt;10,CONCAT(0,r.`HOUR`),r.`HOUR`),':00') as "dateStringLabel",
-        </if>
-        CONCAT(cast(ifnull(ROUND(r.AVG_VALUE,2),'') as char),ifnull(da.unit,'')) as "monitorData"
-        ,ROUND(r.AVG_VALUE,2) as "data"
-        ,r.COLLECT_DATE as "date"
+    <select id="MonitorDataChartReportByDay" resultMap="MonitorDataChartReportMap">
+        SELECT
+            r.`HOUR` AS "dateLabel",
+            CONCAT( r.PARENT_SCENE_NAME, r.DEVICE_NAME ) AS "deviceName",
+            r.DEVICE_CODE AS "devoceCode",
+            r.ATTRIBUTE_NAME AS "attributeName",
+            da.unit AS "unit",
 
-        ,d.DEVICE_CODE as "devoceCode"
-        ,CONCAT(r.PARENT_SCENE_NAME,d.DEVICE_NAME) as "deviceName"
-        ,da.unit as "unit"
-        ,r.ATTRIBUTE_NAME as "attributeName"
-
-        from ${tableName} r
-        <include refid="MonitorDataReportJoins"/>
-        where dp.IS_CHART = 1 and r.PARENT_SCENE_ID=#{sceneId}
-        <if test="year != null">
+            ROUND( sum(r.AVG_VALUE), 2 ) AS "data",
+            max(r.COLLECT_DATE) AS "date"
+        FROM sms_device_parm p
+        LEFT JOIN sms_day_report r ON p.DEVICE_ID = r.DEVICE_ID AND p.ATTRIBUTE_ID = r.ATTRIBUTE_ID
+        LEFT JOIN sms_device_attribute da ON da.id = r.ATTRIBUTE_ID
+        LEFT JOIN sms_device d ON d.id = r.DEVICE_ID
+        where p.IS_CHART = 1 and p.`STATUS`= 1
+            and p.PARENT_SCENE_ID=#{sceneId}
             and r.year=#{year}
-        </if>
-        <if test="month != null">
             and r.month=#{month}
-        </if>
-        <if test="day != null">
             and r.day=#{day}
-        </if>
         <if test="tenantId != null and tenantId != '' ">
             and d.tenant_id = #{tenantId}
         </if>
@@ -93,56 +75,186 @@
                 and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
             </if>
         </if>
+        group by r.hour ,r.PARENT_SCENE_NAME,r.DEVICE_NAME,r.DEVICE_CODE,r.ATTRIBUTE_NAME,da.unit
+        ORDER BY r.`HOUR` ASC
 
+    </select>
+    <select id="MonitorDataChartReportByMonth" resultMap="MonitorDataChartReportMap">
+        SELECT
+            r.`day` AS "dateLabel",
+            CONCAT( r.PARENT_SCENE_NAME, r.DEVICE_NAME ) AS "deviceName",
+            r.DEVICE_CODE AS "devoceCode",
+            r.ATTRIBUTE_NAME AS "attributeName",
+            da.unit AS "unit",
 
-        <if test="type != null and type ==1">
-            order by d.DEVICE_CODE,r.ATTRIBUTE_NAME,r.`MONTH` asc
-        </if>
-        <if test="type != null and type ==2">
-            order by d.DEVICE_CODE,r.ATTRIBUTE_NAME,r.`DAY` asc
+            ROUND( sum(r.AVG_VALUE), 2 ) AS "data",
+            max(r.COLLECT_DATE) AS "date"
+        FROM sms_device_parm p
+        LEFT JOIN sms_month_report r ON p.DEVICE_ID = r.DEVICE_ID AND p.ATTRIBUTE_ID = r.ATTRIBUTE_ID
+        LEFT JOIN sms_device_attribute da ON da.id = r.ATTRIBUTE_ID
+        LEFT JOIN sms_device d ON d.id = r.DEVICE_ID
+        where p.IS_CHART = 1 and p.`STATUS`= 1
+        and p.PARENT_SCENE_ID=#{sceneId}
+        and r.year=#{year}
+        and r.month=#{month}
+        <if test="tenantId != null and tenantId != '' ">
+            and d.tenant_id = #{tenantId}
         </if>
-        <if test="type != null and type ==3">
-            order by d.DEVICE_CODE,r.ATTRIBUTE_NAME,r.`HOUR` asc
+        <if test="userType!=null and userType!=-999 and userType!=-9999 and  programItems != null and programItems.size() > 0">
+            <if test="permissonType == 5 or permissonType == 2">
+                and ( d.DEPT_ORG_ID in
+                <foreach collection="programItems" item="item" open="(" close=")" separator=",">
+                    #{item.orgId}
+                </foreach>
+                or
+                d.COMPANY_ORG_ID in
+                <foreach collection="programItems" item="item" open="(" close=")" separator=",">
+                    #{item.orgId}
+                </foreach>
+                )
+            </if>
+            <if test="permissonType == 4 or permissonType == 3">
+                and d.DEPT_ORG_ID in
+                <foreach collection="programItems" item="item" open="(" close=")" separator=",">
+                    #{item.orgId}
+                </foreach>
+            </if>
+            <if test="permissonType == 1">
+                and d.COMPANY_ORG_ID in
+                <foreach collection="programItems" item="item" open="(" close=")" separator=",">
+                    #{item.orgId}
+                </foreach>
+                and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
+            </if>
         </if>
-
+        group by r.day ,r.PARENT_SCENE_NAME,r.DEVICE_NAME,r.DEVICE_CODE,r.ATTRIBUTE_NAME,da.unit
+        ORDER BY r.`day` ASC
     </select>
+    <select id="MonitorDataChartReportByYear" resultMap="MonitorDataChartReportMap">
+        SELECT
+            r.`month` AS "dateLabel",
+            CONCAT( r.PARENT_SCENE_NAME, r.DEVICE_NAME ) AS "deviceName",
+            r.DEVICE_CODE AS "devoceCode",
+            r.ATTRIBUTE_NAME AS "attributeName",
+            da.unit AS "unit",
 
-
-    <select id="MonitorDataEnergyReport" resultMap="MonitorDataChartReportMap">
-        select
-        <if test="type != null and type ==1">
-            r.`MONTH` as "dateLabel",
-            CONCAT(r.`YEAR`,'-',if(r.`MONTH`&lt;10,CONCAT(0,r.`MONTH`),r.`MONTH`)) as "dateStringLabel",
-        </if>
-        <if test="type != null and type ==2">
-            r.`DAY` as "dateLabel",
-            CONCAT(r.`YEAR`,'-',if(r.`MONTH`&lt;10,CONCAT(0,r.`MONTH`),r.`MONTH`),'-',if(r.`DAY`&lt;10,CONCAT(0,r.`DAY`),r.`DAY`)) as "dateStringLabel",
+            ROUND( sum(r.AVG_VALUE), 2 ) AS "data",
+            max(r.COLLECT_DATE) AS "date"
+        FROM sms_device_parm p
+        LEFT JOIN sms_year_report r ON p.DEVICE_ID = r.DEVICE_ID AND p.ATTRIBUTE_ID = r.ATTRIBUTE_ID
+        LEFT JOIN sms_device_attribute da ON da.id = r.ATTRIBUTE_ID
+        LEFT JOIN sms_device d ON d.id = r.DEVICE_ID
+        where p.IS_CHART = 1 and p.`STATUS`= 1
+        and p.PARENT_SCENE_ID=#{sceneId}
+        and r.year=#{year}
+        <if test="tenantId != null and tenantId != '' ">
+            and d.tenant_id = #{tenantId}
         </if>
-        <if test="type != null and type ==3">
-            r.`HOUR` as "dateLabel",
-            CONCAT(r.`YEAR`,'-',if(r.`MONTH`&lt;10,CONCAT(0,r.`MONTH`),r.`MONTH`),'-',if(r.`DAY`&lt;10,CONCAT(0,r.`DAY`),r.`DAY`),' ',if(r.`HOUR`&lt;10,CONCAT(0,r.`HOUR`),r.`HOUR`),':00') as "dateStringLabel",
+        <if test="userType!=null and userType!=-999 and userType!=-9999 and  programItems != null and programItems.size() > 0">
+            <if test="permissonType == 5 or permissonType == 2">
+                and ( d.DEPT_ORG_ID in
+                <foreach collection="programItems" item="item" open="(" close=")" separator=",">
+                    #{item.orgId}
+                </foreach>
+                or
+                d.COMPANY_ORG_ID in
+                <foreach collection="programItems" item="item" open="(" close=")" separator=",">
+                    #{item.orgId}
+                </foreach>
+                )
+            </if>
+            <if test="permissonType == 4 or permissonType == 3">
+                and d.DEPT_ORG_ID in
+                <foreach collection="programItems" item="item" open="(" close=")" separator=",">
+                    #{item.orgId}
+                </foreach>
+            </if>
+            <if test="permissonType == 1">
+                and d.COMPANY_ORG_ID in
+                <foreach collection="programItems" item="item" open="(" close=")" separator=",">
+                    #{item.orgId}
+                </foreach>
+                and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
+            </if>
         </if>
+        group by r.month ,r.PARENT_SCENE_NAME,r.DEVICE_NAME,r.DEVICE_CODE,r.ATTRIBUTE_NAME,da.unit
+        ORDER BY r.`month` ASC
+    </select>
 
-        r.PARENT_SCENE_NAME as "deviceName"
-        ,da.ATTRIBUTE_TYPE as "attributeType"
-        ,da.unit as "unit"
-        ,if(da.ATTRIBUTE_TYPE=3,'用水量','耗电量') as  "attributeName"
 
-        ,CONCAT(cast(ifnull(ROUND(sum(r.SUM_VALUE),2),0) as char),ifnull(da.unit,'')) as "monitorData"
-        ,ifnull(ROUND(sum(r.SUM_VALUE),2) ,0)  as "data"
-        ,max(r.COLLECT_DATE) as "date"
+    <select id="MonitorDataEnergyReportByDay" resultMap="MonitorDataChartReportMap">
+        SELECT
+            r.`HOUR` AS "dateLabel",
+            IF( p.parm_type = 3, '用水量', '耗电量' ) AS "attributeName",
+            s.SCENE_NAME AS "deviceName",
+            p.parm_type AS "attributeType",
+            da.unit AS "unit",
 
-        <if test="type != null and type ==1">
-            from sms_year_report r
-        </if>
-        <if test="type != null and type ==2">
-            from sms_month_report r
-        </if>
-        <if test="type != null and type ==3">
-            from sms_day_report r
+            ifnull( ROUND( sum( r.SUM_VALUE ), 2 ), 0 ) AS "data",
+            max( r.COLLECT_DATE ) AS "date"
+        FROM sms_device_parm p
+        LEFT JOIN sms_day_report r ON p.DEVICE_ID = r.DEVICE_ID AND p.ATTRIBUTE_ID = r.ATTRIBUTE_ID
+        left join sms_scene s on s.id=p.parent_scene_id
+        left join sms_device_attribute  da ON da.id = p.ATTRIBUTE_ID
+        LEFT JOIN sms_device d ON d.id = r.DEVICE_ID
+        WHERE p.`STATUS`= 1 and p.parm_type in (3,5)
+            AND r.YEAR = #{year}  and r.month=#{month}  and r.day=#{day}
+            <if test="sceneIds != null and sceneIds.size()>0">
+                and r.PARENT_SCENE_ID in
+                <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
+                    #{item}
+                </foreach>
+            </if>
+            <if test="tenantId != null and tenantId != '' ">
+                and d.tenant_id = #{tenantId}
+            </if>
+            <if test="userType!=null and userType!=-999 and userType!=-9999 and  programItems != null and programItems.size() > 0">
+            <if test="permissonType == 5 or permissonType == 2">
+                and ( d.DEPT_ORG_ID in
+                <foreach collection="programItems" item="item" open="(" close=")" separator=",">
+                    #{item.orgId}
+                </foreach>
+                or
+                d.COMPANY_ORG_ID in
+                <foreach collection="programItems" item="item" open="(" close=")" separator=",">
+                    #{item.orgId}
+                </foreach>
+                )
+            </if>
+            <if test="permissonType == 4 or permissonType == 3">
+                and d.DEPT_ORG_ID in
+                <foreach collection="programItems" item="item" open="(" close=")" separator=",">
+                    #{item.orgId}
+                </foreach>
+            </if>
+            <if test="permissonType == 1">
+                and d.COMPANY_ORG_ID in
+                <foreach collection="programItems" item="item" open="(" close=")" separator=",">
+                    #{item.orgId}
+                </foreach>
+                and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
+            </if>
         </if>
-        <include refid="MonitorDataReportJoins"/>
-        where (da.ATTRIBUTE_TYPE=3 or da.ATTRIBUTE_TYPE=5)
+        GROUP BY s.SCENE_NAME,p.parm_type,da.unit,r.HOUR
+        order by r.`hour` asc
+    </select>
+    <select id="MonitorDataEnergyReportByMonth" resultMap="MonitorDataChartReportMap">
+        SELECT
+            r.`day` AS "dateLabel",
+            IF( p.parm_type = 3, '用水量', '耗电量' ) AS "attributeName",
+            s.SCENE_NAME AS "deviceName",
+            p.parm_type AS "attributeType",
+            da.unit AS "unit",
+
+            ifnull( ROUND( sum( r.SUM_VALUE ), 2 ), 0 ) AS "data",
+            max( r.COLLECT_DATE ) AS "date"
+        FROM sms_device_parm p
+        LEFT JOIN sms_month_report r ON p.DEVICE_ID = r.DEVICE_ID AND p.ATTRIBUTE_ID = r.ATTRIBUTE_ID
+        left join sms_scene s on s.id=p.parent_scene_id
+        left join sms_device_attribute  da ON da.id = p.ATTRIBUTE_ID
+        LEFT JOIN sms_device d ON d.id = r.DEVICE_ID
+        WHERE p.`STATUS`= 1 and p.parm_type in (3,5)
+        AND r.YEAR = #{year}  and r.month=#{month}
         <if test="sceneIds != null and sceneIds.size()>0">
             and r.PARENT_SCENE_ID in
             <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
@@ -179,60 +291,140 @@
                 and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
             </if>
         </if>
-        <if test="type != null and type ==1">
-            and r.year=#{year}
-            group by r.PARENT_SCENE_NAME,da.ATTRIBUTE_TYPE,da.unit,r.year,r.month
-            order by r.PARENT_SCENE_NAME,da.ATTRIBUTE_TYPE asc,r.`MONTH` asc
-        </if>
-        <if test="type != null and type ==2">
-            and r.year=#{year}  and r.month=#{month}
-            group by r.PARENT_SCENE_NAME,da.ATTRIBUTE_TYPE,da.unit,r.year,r.month,r.day
-            order by r.PARENT_SCENE_NAME,da.ATTRIBUTE_TYPE asc,r.`day` asc
-        </if>
-        <if test="type != null and type ==3">
-            and r.year=#{year}  and r.month=#{month} and r.day=#{day}
-            group by r.PARENT_SCENE_NAME,da.ATTRIBUTE_TYPE,da.unit,r.year,r.month,r.day,r.hour
-            order by r.PARENT_SCENE_NAME,da.ATTRIBUTE_TYPE asc,r.`hour` asc
-        </if>
+        GROUP BY s.SCENE_NAME,p.parm_type,da.unit,r.day
+        order by r.`day` asc
     </select>
+    <select id="MonitorDataEnergyReportByYear" resultMap="MonitorDataChartReportMap">
+        SELECT
+            r.`month` AS "dateLabel",
+            IF( p.parm_type = 3, '用水量', '耗电量' ) AS "attributeName",
+            s.SCENE_NAME AS "deviceName",
+            p.parm_type AS "attributeType",
+            da.unit AS "unit",
 
-
-    <select id="MonitorDataQualityReport" resultMap="MonitorDataChartReportMap">
-        select
-        <if test="type != null and type ==1">
-            r.`MONTH` as "dateLabel",
-            CONCAT(r.`YEAR`,'-',if(r.`MONTH`&lt;10,CONCAT(0,r.`MONTH`),r.`MONTH`)) as "dateStringLabel",
+            ifnull( ROUND( sum( r.SUM_VALUE ), 2 ), 0 ) AS "data",
+            max( r.COLLECT_DATE ) AS "date"
+        FROM sms_device_parm p
+        LEFT JOIN sms_year_report r ON p.DEVICE_ID = r.DEVICE_ID AND p.ATTRIBUTE_ID = r.ATTRIBUTE_ID
+        left join sms_scene s on s.id=p.parent_scene_id
+        left join sms_device_attribute  da ON da.id = p.ATTRIBUTE_ID
+        LEFT JOIN sms_device d ON d.id = r.DEVICE_ID
+        WHERE p.`STATUS`= 1 and p.parm_type in (3,5)
+        AND r.YEAR = #{year}  and r.month=#{month}
+        <if test="sceneIds != null and sceneIds.size()>0">
+            and r.PARENT_SCENE_ID in
+            <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
+                #{item}
+            </foreach>
         </if>
-        <if test="type != null and type ==2">
-            r.`DAY` as "dateLabel",
-            CONCAT(r.`YEAR`,'-',if(r.`MONTH`&lt;10,CONCAT(0,r.`MONTH`),r.`MONTH`),'-',if(r.`DAY`&lt;10,CONCAT(0,r.`DAY`),r.`DAY`)) as "dateStringLabel",
+        <if test="tenantId != null and tenantId != '' ">
+            and d.tenant_id = #{tenantId}
         </if>
-        <if test="type != null and type ==3">
-            r.`HOUR` as "dateLabel",
-            CONCAT(r.`YEAR`,'-',if(r.`MONTH`&lt;10,CONCAT(0,r.`MONTH`),r.`MONTH`),'-',if(r.`DAY`&lt;10,CONCAT(0,r.`DAY`),r.`DAY`),' ',if(r.`HOUR`&lt;10,CONCAT(0,r.`HOUR`),r.`HOUR`),':00') as "dateStringLabel",
+        <if test="userType!=null and userType!=-999 and userType!=-9999 and  programItems != null and programItems.size() > 0">
+            <if test="permissonType == 5 or permissonType == 2">
+                and ( d.DEPT_ORG_ID in
+                <foreach collection="programItems" item="item" open="(" close=")" separator=",">
+                    #{item.orgId}
+                </foreach>
+                or
+                d.COMPANY_ORG_ID in
+                <foreach collection="programItems" item="item" open="(" close=")" separator=",">
+                    #{item.orgId}
+                </foreach>
+                )
+            </if>
+            <if test="permissonType == 4 or permissonType == 3">
+                and d.DEPT_ORG_ID in
+                <foreach collection="programItems" item="item" open="(" close=")" separator=",">
+                    #{item.orgId}
+                </foreach>
+            </if>
+            <if test="permissonType == 1">
+                and d.COMPANY_ORG_ID in
+                <foreach collection="programItems" item="item" open="(" close=")" separator=",">
+                    #{item.orgId}
+                </foreach>
+                and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
+            </if>
         </if>
+        GROUP BY s.SCENE_NAME,p.parm_type,da.unit,r.month
+        order by r.`month` asc
+    </select>
 
-        r.PARENT_SCENE_NAME as "deviceName"
-        ,da.ATTRIBUTE_TYPE as "attributeType"
-        ,da.unit as "unit"
-        ,if(da.ATTRIBUTE_TYPE=8,'PH',if(da.ATTRIBUTE_TYPE=11,'余氯','浊度')) as  "attributeName"
 
-        ,CONCAT(cast(ifnull(ROUND(avg(r.SUM_VALUE),2),0) as char),ifnull(da.UNIT,'')) as "monitorData"
-        ,ifnull(ROUND(avg(r.SUM_VALUE),2) ,0)  as "data"
-        ,max(r.COLLECT_DATE) as "date"
+    <select id="MonitorDataQualityReportByDay" resultMap="MonitorDataChartReportMap">
+        SELECT
+        r.`HOUR` AS "dateLabel",
+        if(p.parm_type=8,'PH',if(p.parm_type=11,'余氯','浊度')) as  "attributeName",
+        s.SCENE_NAME AS "deviceName",
+        p.parm_type AS "attributeType",
+        da.unit AS "unit",
 
-        <if test="type != null and type ==1">
-            from sms_year_report r
+        ifnull( ROUND( sum( r.SUM_VALUE ), 2 ), 0 ) AS "data",
+        max( r.COLLECT_DATE ) AS "date"
+        FROM sms_device_parm p
+        LEFT JOIN sms_day_report r ON p.DEVICE_ID = r.DEVICE_ID AND p.ATTRIBUTE_ID = r.ATTRIBUTE_ID
+        left join sms_scene s on s.id=p.parent_scene_id
+        left join sms_device_attribute  da ON da.id = p.ATTRIBUTE_ID
+        LEFT JOIN sms_device d ON d.id = r.DEVICE_ID
+        WHERE p.`STATUS`= 1 and p.parm_type in (8,11,10)
+        AND r.YEAR = #{year}  and r.month=#{month}  and r.day=#{day}
+        <if test="sceneIds != null and sceneIds.size()>0">
+            and r.PARENT_SCENE_ID in
+            <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
+                #{item}
+            </foreach>
         </if>
-        <if test="type != null and type ==2">
-            from sms_month_report r
+        <if test="tenantId != null and tenantId != '' ">
+            and d.tenant_id = #{tenantId}
         </if>
-        <if test="type != null and type ==3">
-            from sms_day_report r
+        <if test="userType!=null and userType!=-999 and userType!=-9999 and  programItems != null and programItems.size() > 0">
+            <if test="permissonType == 5 or permissonType == 2">
+                and ( d.DEPT_ORG_ID in
+                <foreach collection="programItems" item="item" open="(" close=")" separator=",">
+                    #{item.orgId}
+                </foreach>
+                or
+                d.COMPANY_ORG_ID in
+                <foreach collection="programItems" item="item" open="(" close=")" separator=",">
+                    #{item.orgId}
+                </foreach>
+                )
+            </if>
+            <if test="permissonType == 4 or permissonType == 3">
+                and d.DEPT_ORG_ID in
+                <foreach collection="programItems" item="item" open="(" close=")" separator=",">
+                    #{item.orgId}
+                </foreach>
+            </if>
+            <if test="permissonType == 1">
+                and d.COMPANY_ORG_ID in
+                <foreach collection="programItems" item="item" open="(" close=")" separator=",">
+                    #{item.orgId}
+                </foreach>
+                and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
+            </if>
         </if>
-        <include refid="MonitorDataReportJoins"/>
-        where (da.ATTRIBUTE_TYPE=8 or da.ATTRIBUTE_TYPE=11  or da.ATTRIBUTE_TYPE=10)
+        GROUP BY s.SCENE_NAME,p.parm_type,da.unit,r.HOUR
+        order by r.`hour` asc
+    </select>
+    <select id="MonitorDataQualityReportByMonth" resultMap="MonitorDataChartReportMap">
+        SELECT
+        r.`day` AS "dateLabel",
+        if(p.parm_type=8,'PH',if(p.parm_type=11,'余氯','浊度')) as  "attributeName",
+        s.SCENE_NAME AS "deviceName",
+        p.parm_type AS "attributeType",
+        da.unit AS "unit",
 
+        ifnull( ROUND( sum( r.SUM_VALUE ), 2 ), 0 ) AS "data",
+        max( r.COLLECT_DATE ) AS "date"
+        FROM sms_device_parm p
+        LEFT JOIN sms_month_report r ON p.DEVICE_ID = r.DEVICE_ID AND p.ATTRIBUTE_ID = r.ATTRIBUTE_ID
+        left join sms_scene s on s.id=p.parent_scene_id
+        left join sms_device_attribute  da ON da.id = p.ATTRIBUTE_ID
+        LEFT JOIN sms_device d ON d.id = r.DEVICE_ID
+        WHERE p.`STATUS`= 1 and p.parm_type in (8,11,10)
+        AND r.YEAR = #{year}  and r.month=#{month}  and r.day=#{day}
         <if test="sceneIds != null and sceneIds.size()>0">
             and r.PARENT_SCENE_ID in
             <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
@@ -269,21 +461,64 @@
                 and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
             </if>
         </if>
-        <if test="type != null and type ==1">
-            and r.year=#{year}
-            group by r.PARENT_SCENE_NAME,da.ATTRIBUTE_TYPE,da.unit,r.year,r.month
-            order by r.PARENT_SCENE_NAME,da.ATTRIBUTE_TYPE asc,r.`MONTH` asc
+        GROUP BY s.SCENE_NAME,p.parm_type,da.unit,r.day
+        order by r.`day` asc
+    </select>
+    <select id="MonitorDataQualityReportByYear" resultMap="MonitorDataChartReportMap">
+        SELECT
+        r.`month` AS "dateLabel",
+        if(p.parm_type=8,'PH',if(p.parm_type=11,'余氯','浊度')) as  "attributeName",
+        s.SCENE_NAME AS "deviceName",
+        p.parm_type AS "attributeType",
+        da.unit AS "unit",
+
+        ifnull( ROUND( sum( r.SUM_VALUE ), 2 ), 0 ) AS "data",
+        max( r.COLLECT_DATE ) AS "date"
+        FROM sms_device_parm p
+        LEFT JOIN sms_year_report r ON p.DEVICE_ID = r.DEVICE_ID AND p.ATTRIBUTE_ID = r.ATTRIBUTE_ID
+        left join sms_scene s on s.id=p.parent_scene_id
+        left join sms_device_attribute  da ON da.id = p.ATTRIBUTE_ID
+        LEFT JOIN sms_device d ON d.id = r.DEVICE_ID
+        WHERE p.`STATUS`= 1 and p.parm_type in (8,11,10)
+        AND r.YEAR = #{year}  and r.month=#{month}  and r.day=#{day}
+        <if test="sceneIds != null and sceneIds.size()>0">
+            and r.PARENT_SCENE_ID in
+            <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
+                #{item}
+            </foreach>
         </if>
-        <if test="type != null and type ==2">
-            and r.year=#{year}  and r.month=#{month}
-            group by r.PARENT_SCENE_NAME,da.ATTRIBUTE_TYPE,da.unit,r.year,r.month,r.day
-            order by r.PARENT_SCENE_NAME,da.ATTRIBUTE_TYPE asc,r.`day` asc
+        <if test="tenantId != null and tenantId != '' ">
+            and d.tenant_id = #{tenantId}
         </if>
-        <if test="type != null and type ==3">
-            and r.year=#{year}  and r.month=#{month} and r.day=#{day}
-            group by r.PARENT_SCENE_NAME,da.ATTRIBUTE_TYPE,da.unit,r.year,r.month,r.day,r.hour
-            order by r.PARENT_SCENE_NAME,da.ATTRIBUTE_TYPE asc,r.`hour` asc
+        <if test="userType!=null and userType!=-999 and userType!=-9999 and  programItems != null and programItems.size() > 0">
+            <if test="permissonType == 5 or permissonType == 2">
+                and ( d.DEPT_ORG_ID in
+                <foreach collection="programItems" item="item" open="(" close=")" separator=",">
+                    #{item.orgId}
+                </foreach>
+                or
+                d.COMPANY_ORG_ID in
+                <foreach collection="programItems" item="item" open="(" close=")" separator=",">
+                    #{item.orgId}
+                </foreach>
+                )
+            </if>
+            <if test="permissonType == 4 or permissonType == 3">
+                and d.DEPT_ORG_ID in
+                <foreach collection="programItems" item="item" open="(" close=")" separator=",">
+                    #{item.orgId}
+                </foreach>
+            </if>
+            <if test="permissonType == 1">
+                and d.COMPANY_ORG_ID in
+                <foreach collection="programItems" item="item" open="(" close=")" separator=",">
+                    #{item.orgId}
+                </foreach>
+                and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
+            </if>
         </if>
+        GROUP BY s.SCENE_NAME,p.parm_type,da.unit,r.month
+        order by r.`month` asc
     </select>
 
 
@@ -305,19 +540,17 @@
         <if test="dateType != null and dateType == 'hour'">
             ,DATE_FORMAT(max(ad.ALARM_START_TIME),'%Y-%m-%d %H:00') as "dateStringLabel"
         </if>
-            ,count(1) as "monitorData"
-            ,count(1) as "data"
 
-            ,ps.SCENE_NAME as "deviceName"
+            ,ad.PARENT_SCENE_NAME as "deviceName"
             ,'报警次数' as "attributeName"
+            ,count(1) as "monitorData"
+            ,count(1) as "data"
             from sms_alarm_details ad
             left join sms_device d on ad.DEVICE_ID=d.ID
-            left join sms_scene s on s.id = d.SCENE_ID and s.`STATUS` = 1
-            left join sms_scene ps on s.PARENT_SCENE_IDS LIKE concat('%,', ps.id ,',%') and ps.PARENT_SCENE_ID ='0' and ps.`STATUS` = 1
 
             where ad.ALARM_START_TIME &lt; #{endDate} and ad.ALARM_START_TIME >= #{beginDate}
             <if test="sceneIds != null and sceneIds.size()>0">
-                and ps.id  in
+                and ad.parent_scene_id  in
                 <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
                     #{item}
                 </foreach>
@@ -353,7 +586,7 @@
             </if>
         </if>
 
-            group by ps.SCENE_NAME,${dateType}(ad.ALARM_START_TIME)
+            group by ad.PARENT_SCENE_NAME,${dateType}(ad.ALARM_START_TIME)
         )a
         order by deviceName,dateLabel
     </select>

+ 2 - 2
sms_water/src/main/resources/mapper/TestDataMapper.xml

@@ -29,7 +29,7 @@
             ,max(MAX_VALUE) MAX_VALUE
             ,avg(AVG_VALUE) AVG_VALUE
             ,sum(SUM_VALUE) SUM_VALUE
-            ,(select LATEST_VALUE from sms_day_report where DEVICE_ID =a.DEVICE_ID and ATTRIBUTE_ID = a.ATTRIBUTE_ID and COLLECT_DATE = max(a.COLLECT_DATE)) LATEST_VALUE
+            ,(select LATEST_VALUE from sms_month_report where id = max(a.id)) LATEST_VALUE
             ,max(COLLECT_DATE) COLLECT_DATE
         from sms_month_report a
         where year =#{year} and DEVICE_ID=#{id}
@@ -44,7 +44,7 @@
             ,max(MAX_VALUE) MAX_VALUE
             ,avg(AVG_VALUE) AVG_VALUE
             ,sum(SUM_VALUE) SUM_VALUE
-            ,(select LATEST_VALUE from sms_day_report where DEVICE_ID =a.DEVICE_ID and ATTRIBUTE_ID = a.ATTRIBUTE_ID and COLLECT_DATE = max(a.COLLECT_DATE)) LATEST_VALUE
+            ,(select LATEST_VALUE from sms_day_report where id = max(a.id)) LATEST_VALUE
             ,max(COLLECT_DATE) COLLECT_DATE
         from sms_day_report a
         where year = #{year} and month =#{month} and DEVICE_ID=#{id}