소스 검색

Merge remote-tracking branch 'origin/master'

wangyangyang 4 년 전
부모
커밋
1e777c66a9

+ 12 - 17
sms_water/src/main/java/com/huaxu/controller/MonitorDataReportController.java

@@ -33,7 +33,7 @@ public class MonitorDataReportController {
     @Autowired
     private MonitorDataReportService monitorDataReportService;
 
-    @RequestMapping(value = "MonitorDataChartReport",method = RequestMethod.POST)
+    @RequestMapping(value = "MonitorDataChartReport",method = RequestMethod.GET)
     @ApiOperation(value = "二供——图表")
     public AjaxMessage<List<MonitorDataChartReportDeviceDto>> MonitorDataChartReport(
             @ApiParam(value = "场景id", required = true) @RequestParam Long sceneId,
@@ -58,29 +58,24 @@ public class MonitorDataReportController {
         return new AjaxMessage<>(ResultStatus.OK);
     }
 
-    @RequestMapping(value = "MonitorDataChartReportdd",method = RequestMethod.POST)
-    @ApiOperation(value = "二供——图表dd")
-    public AjaxMessage<Integer> MonitorDataChartReportdd(
-            @ApiParam(value = "日期,格式:2020-12-12", required = true) @RequestParam String reportDate,
-            @ApiParam(value = "类型,1年2月3日", required = true) @RequestParam Integer reportType
-    ){
-
-        return new AjaxMessage<>(ResultStatus.OK, monitorDataReportService.MonitorDataChartReportdd());
-    }
-
-    @RequestMapping(value = "MonitorDataCompareReport",method = RequestMethod.POST)
+    @RequestMapping(value = "MonitorDataCompareReport",method = RequestMethod.GET)
     @ApiOperation(value = "二供——对比,按集合顺序取,能耗——水质——报警")
     public AjaxMessage<List<List<MonitorDataChartReportDeviceDto>>> MonitorDataCompareReport(
+            @ApiParam(value = "场景ids", required = true) @RequestParam List<Long> sceneIds,
             @ApiParam(value = "日期,格式:2020-12-12", required = true) @RequestParam String reportDate,
             @ApiParam(value = "类型,1年2月3日", required = true) @RequestParam Integer reportType
     ){
+        LocalDate localDate =LocalDate.now();
+        if(null == reportDate){
+            localDate = LocalDate.parse(reportDate,DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+        }
        List<List<MonitorDataChartReportDeviceDto>> reportList=new ArrayList<>();
-        //能耗(供水量、耗电量)
-        List<MonitorDataChartReportDeviceDto> energy = null;
-        //水质(PH、COD、浊度)
-        List<MonitorDataChartReportDeviceDto> quality = null;
+        //能耗(供水量3、耗电量5
+        List<MonitorDataChartReportDeviceDto> energy = monitorDataReportService.MonitorDataEnergyReport(reportType,sceneIds,localDate.getYear(),localDate.getMonthValue(),localDate.getDayOfMonth());
+        //水质(PH8、余氯11、浊度10
+        List<MonitorDataChartReportDeviceDto> quality = monitorDataReportService.MonitorDataQualityReport(reportType,sceneIds,localDate.getYear(),localDate.getMonthValue(),localDate.getDayOfMonth());
         //报警(报警次数)
-        List<MonitorDataChartReportDeviceDto> alarm = null;
+        List<MonitorDataChartReportDeviceDto> alarm = monitorDataReportService.DeviceAlarmReport(reportType,sceneIds,localDate.getYear(),localDate.getMonthValue(),localDate.getDayOfMonth());
 
         reportList.add(energy);
         reportList.add(quality);

+ 0 - 2
sms_water/src/main/java/com/huaxu/dao/MonitorDataMapper.java

@@ -21,6 +21,4 @@ public interface MonitorDataMapper {
     void batchInsertYearReport(@Param("year") Integer year, @Param("month")Integer month);
     void batchInsertMonthReport(@Param("year") Integer year, @Param("month")Integer month, @Param("day")Integer day);
     void batchInsertDayReport( @Param("dayReportEntities") List<DayReportEntity> dayReportEntities);
-
-    Integer chechDataExist( @Param("deviceId")Integer deviceId,@Param("attributeId")Integer attributeId,@Param("year") Integer year, @Param("month")Integer month, @Param("day")Integer day);
 }

+ 19 - 2
sms_water/src/main/java/com/huaxu/dao/MonitorDataReportMapper.java

@@ -1,9 +1,12 @@
 package com.huaxu.dao;
 
 import com.huaxu.dto.MonitorDataChartReportDeviceDto;
+import com.huaxu.model.ProgramItem;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
+import java.time.LocalDate;
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -25,6 +28,20 @@ public interface MonitorDataReportMapper {
      * @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);
-    Integer updatedd();
+                                                                 @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,
+                                                                  @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,
+                                                                   @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> 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,
+                                                            @Param("programItems")List<ProgramItem> programItems);
 }

+ 2 - 0
sms_water/src/main/java/com/huaxu/dto/MonitorDataChartReportAttributeDto.java

@@ -18,6 +18,8 @@ public class MonitorDataChartReportAttributeDto implements Serializable {
 
     private static final long serialVersionUID = -1296206984259523032L;
 
+    @ApiModelProperty("属性类型:3供水量、5耗电量、8PH、10浊度、11余氯")
+    private String attributeType;
     @ApiModelProperty("属性名称")
     private String attributeName;
     @ApiModelProperty("数据")

+ 1 - 1
sms_water/src/main/java/com/huaxu/dto/MonitorDataChartReportValueDto.java

@@ -16,7 +16,7 @@ import java.util.Date;
  * @data 2020/12/7 10:21
  */
 @Data
-@ApiModel("图表数据内容")
+@ApiModel("数据内容")
 public class MonitorDataChartReportValueDto implements Serializable {
 
     private static final long serialVersionUID = 6248751275101485917L;

+ 6 - 1
sms_water/src/main/java/com/huaxu/service/MonitorDataReportService.java

@@ -19,6 +19,11 @@ public interface MonitorDataReportService {
     List<MonitorDataChartReportDeviceDto> MonitorDataChartReportByYear(Long sceneId,Integer year);
 
 
+    //报警次数
+    List<MonitorDataChartReportDeviceDto> DeviceAlarmReport(Integer type,List<Long>  sceneIds,Integer year,Integer month ,Integer day);
+    //水质对比
+    List<MonitorDataChartReportDeviceDto> MonitorDataQualityReport(Integer type,List<Long>  sceneIds,Integer year,Integer month ,Integer day);
+    //能耗对比
+    List<MonitorDataChartReportDeviceDto> MonitorDataEnergyReport(Integer type,List<Long>  sceneIds,Integer year,Integer month ,Integer day);
 
-    Integer MonitorDataChartReportdd();
 }

+ 69 - 27
sms_water/src/main/java/com/huaxu/service/impl/MonitorDataReportServiceImpl.java

@@ -4,7 +4,9 @@ import com.huaxu.dao.MonitorDataReportMapper;
 import com.huaxu.dto.MonitorDataChartReportAttributeDto;
 import com.huaxu.dto.MonitorDataChartReportDeviceDto;
 import com.huaxu.dto.MonitorDataChartReportValueDto;
+import com.huaxu.model.LoginUser;
 import com.huaxu.service.MonitorDataReportService;
+import com.huaxu.util.UserUtil;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
@@ -26,49 +28,49 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
 
     @Override
     public List<MonitorDataChartReportDeviceDto> MonitorDataChartReportByDay(Long sceneId,Integer year,Integer month ,Integer day) {
-        List<MonitorDataChartReportDeviceDto> monitorDataChartReportDeviceDtos =  monitorDataReportMapper.MonitorDataChartReport(3,year,month,day,sceneId,"sms_day_report");
-        FillLoseData(monitorDataChartReportDeviceDtos,year,month,day);
+        LoginUser loginUser = UserUtil.getCurrentUser();
+        List<MonitorDataChartReportDeviceDto> monitorDataChartReportDeviceDtos =  monitorDataReportMapper.MonitorDataChartReport(3,year,month,day,sceneId,"sms_day_report",
+                loginUser.getTenantId(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
+        FillLoseData(monitorDataChartReportDeviceDtos,3,year,month,day);
         return monitorDataChartReportDeviceDtos;
     }
 
     @Override
     public List<MonitorDataChartReportDeviceDto> MonitorDataChartReportByMonth(Long sceneId,Integer year,Integer month ) {
-        List<MonitorDataChartReportDeviceDto> monitorDataChartReportDeviceDtos = monitorDataReportMapper.MonitorDataChartReport(2,year,month,null,sceneId,"sms_day_report");
-        FillLoseData(monitorDataChartReportDeviceDtos,year,month,null);
+        LoginUser loginUser = UserUtil.getCurrentUser();
+        List<MonitorDataChartReportDeviceDto> monitorDataChartReportDeviceDtos = monitorDataReportMapper.MonitorDataChartReport(2,year,month,null,sceneId,"sms_day_report",
+                loginUser.getTenantId(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
+        FillLoseData(monitorDataChartReportDeviceDtos,2,year,month,1);
         return monitorDataChartReportDeviceDtos;
     }
 
     @Override
     public List<MonitorDataChartReportDeviceDto> MonitorDataChartReportByYear(Long sceneId,Integer year) {
-
-        List<MonitorDataChartReportDeviceDto> monitorDataChartReportDeviceDtos = monitorDataReportMapper.MonitorDataChartReport(1,year,null,null,sceneId,"sms_day_report");
-        FillLoseData(monitorDataChartReportDeviceDtos,year,null,null);
+        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());
+        FillLoseData(monitorDataChartReportDeviceDtos,1,year,1,1);
         return monitorDataChartReportDeviceDtos;
     }
 
-    @Override
-    public Integer MonitorDataChartReportdd() {
-        return monitorDataReportMapper.updatedd();
-    }
-
     /**
      * 补充数据里日期时间缺失的
      */
-    private static void FillLoseData(List<MonitorDataChartReportDeviceDto> monitorDataChartReportDeviceDtos,Integer year,Integer month,Integer day){
+    private static void FillLoseData(List<MonitorDataChartReportDeviceDto> monitorDataChartReportDeviceDtos,Integer type,Integer year,Integer month ,Integer day){
         for(MonitorDataChartReportDeviceDto monitorDataChartReportDeviceDto: monitorDataChartReportDeviceDtos){
             if(monitorDataChartReportDeviceDto != null && monitorDataChartReportDeviceDto.getAttributeData() != null){
                 for(MonitorDataChartReportAttributeDto monitorDataChartReportAttributeDto:monitorDataChartReportDeviceDto.getAttributeData()){
                     if(monitorDataChartReportAttributeDto != null && monitorDataChartReportAttributeDto.getMonitorDataChartReportValue() != null){
                         List<MonitorDataChartReportValueDto> monitorDataChartReportValueDtos = monitorDataChartReportAttributeDto.getMonitorDataChartReportValue();
-                        Integer maxValue =30;
-                        LocalDateTime localDateTime = LocalDateTime.now();
-                        if(day != null){
+                        Integer maxValue =0;
+                        LocalDateTime localDateTime=LocalDateTime.now();
+                        if(type != null && type ==3){
                             maxValue = 24;
                             localDateTime=LocalDateTime.of(year,month,day,0,0,0);
-                        }else if(month != null){
+                        }else if(type != null && type ==2){
                             localDateTime=LocalDateTime.of(year,month,1,0,0,0);
-                            maxValue = LocalDate.of(year,month,1).with(TemporalAdjusters.lastDayOfMonth()).getDayOfMonth();
-                        }else if(year != null){
+                            maxValue = localDateTime.with(TemporalAdjusters.lastDayOfMonth()).getDayOfMonth();
+                        }else if(type != null && type ==1){
                             localDateTime=LocalDateTime.of(year,1,1,0,0,0);
                             maxValue=12;
                         }
@@ -95,14 +97,54 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
             }
         }
     }
-    private static void FillLoseData2(List<Integer> strList ){
-        int size = strList.size();
-        for(int i=0;i<size;i++){
-            Integer tmp = strList.get(i)-1;
-            if(!tmp.equals(i)){
-                strList.add(i,i+1);
-                size++;
-            }
+
+
+    @Override
+    public List<MonitorDataChartReportDeviceDto> DeviceAlarmReport(Integer type,List<Long>  sceneIds,Integer year,Integer month ,Integer day) {
+        LoginUser loginUser = UserUtil.getCurrentUser();
+        LocalDate beginDate;
+        LocalDate endDate;
+        String dateType ;
+        if(type != null && type ==1){
+            beginDate=LocalDate.of(year,1,1);
+            endDate=beginDate.plusYears(1);
+            dateType="month";
+        }else
+        if(type != null && type ==2){
+            beginDate=LocalDate.of(year,month,1);
+            endDate=beginDate.plusMonths(1);
+            dateType="day";
+        }else
+        if(type != null && type ==3){
+            beginDate=LocalDate.of(year,month,day);
+            endDate=beginDate.plusDays(1);
+            dateType="hour";
+        }else{
+            return new ArrayList<>();
         }
+        List<MonitorDataChartReportDeviceDto> monitorDataChartReportDeviceDtos = monitorDataReportMapper.DeviceAlarmReport(dateType,sceneIds,beginDate,endDate,
+                loginUser.getTenantId(),loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
+        FillLoseData(monitorDataChartReportDeviceDtos,type,year,month,day);
+        return monitorDataChartReportDeviceDtos;
+    }
+
+    @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);
+        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);
+        return monitorDataChartReportDeviceDtos;
     }
 }

+ 0 - 15
sms_water/src/main/resources/mapper/MonitorDataMapper.xml

@@ -81,19 +81,4 @@
         where year = #{year} and month =#{month} and day=#{day}
         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, DAY
     </insert>
-
-    <select id="chechDataExist" resultType="java.lang.Integer">
-
-    select count(1)  from sms_day_report
-    where DEVICE_ID = #{deviceId} and ATTRIBUTE_ID = #{attributeId}
-        <if test="year != null">
-            and year = #{year}
-        </if>
-        <if test="month != null">
-            and month = #{month}
-        </if>
-        <if test="day != null">
-            and day = #{day}
-        </if>
-    </select>
 </mapper>

+ 286 - 12
sms_water/src/main/resources/mapper/MonitorDataReportMapper.xml

@@ -9,6 +9,7 @@
     </resultMap>
 
     <resultMap id="AttributeData" type="com.huaxu.dto.MonitorDataChartReportAttributeDto">
+        <result property="attributeType" column="attributeType"/>
         <result property="attributeName" column="attributeName"/>
         <collection property="monitorDataChartReportValue" resultMap="MonitorDataChartReportValue"/>
     </resultMap>
@@ -20,6 +21,11 @@
         <result property="date" column="date"/>
     </resultMap>
 
+    <sql id="MonitorDataReportJoins">
+        left join sms_device_parm dp on dp.DEVICE_ID=r.DEVICE_ID and dp.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
+    </sql>
     <select id="MonitorDataChartReport" resultMap="MonitorDataChartReportMap">
         select
         <if test="type != null and type ==1">
@@ -31,18 +37,16 @@
         <if test="type != null and type ==3">
             r.`HOUR` as "dateLabel",
         </if>
-        cast(ifnull(r.AVG_VALUE,'') as char)+""+ifnull(da.UNIT,'') as "monitorData"
+        cast(ifnull(r.AVG_VALUE,'') as char)+ifnull(da.UNIT,'') as "monitorData"
         ,r.AVG_VALUE as "data"
         ,r.COLLECT_DATE as "date"
 
-        ,r.DEVICE_ID  as "deviceId"
-        ,r.DEVICE_CODE as "devoceCode"
-        ,r.DEVICE_NAME as "deviceName"
+        ,d.DEVICE_CODE as "devoceCode"
+        ,d.DEVICE_NAME as "deviceName"
         ,r.ATTRIBUTE_NAME as "attributeName"
 
         from ${tableName} r
-        left join sms_device_parm dp on dp.DEVICE_ID=r.DEVICE_ID and dp.ATTRIBUTE_ID = r.ATTRIBUTE_ID
-        left join sms_device_attribute da on da.id=r.ATTRIBUTE_ID
+        <include refid="MonitorDataReportJoins"/>
         where dp.IS_CHART = 1 and r.PARENT_SCENE_ID=#{sceneId}
         <if test="year != null">
             and r.year=#{year}
@@ -53,20 +57,290 @@
         <if test="day != null">
             and r.day=#{day}
         </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>
+
+
+        <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
+        </if>
+        <if test="type != null and type ==3">
+            order by d.DEVICE_CODE,r.ATTRIBUTE_NAME,r.`HOUR` asc
+        </if>
+
+    </select>
+
+
+    <select id="MonitorDataEnergyReport" resultMap="MonitorDataChartReportMap">
+        select
+            <if test="type != null and type ==1">
+                r.`MONTH` as "dateLabel",
+            </if>
+            <if test="type != null and type ==2">
+                r.`DAY` as "dateLabel",
+            </if>
+            <if test="type != null and type ==3">
+                r.`HOUR` as "dateLabel",
+            </if>
+            cast(ifnull(r.LATEST_VALUE -r2.LATEST_VALUE,'') as char)+ifnull(da.UNIT,'') as "monitorData"
+            ,ifnull((r.LATEST_VALUE -r2.LATEST_VALUE),0)  as "data"
+            ,r.COLLECT_DATE as "date"
+
+            ,d.DEVICE_CODE as "devoceCode"
+            ,d.DEVICE_NAME as "deviceName"
+            ,da.ATTRIBUTE_TYPE as "attributeType"
+            ,if(da.ATTRIBUTE_TYPE=3,'用水量','耗电量') as  "attributeName"
+        <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
+        </if>
+        <include refid="MonitorDataReportJoins"/>
+
         <if test="type != null and type ==1">
-            order by r.`MONTH` asc
+            left join sms_year_report r2 on r.DEVICE_ID=r2.DEVICE_ID and r.ATTRIBUTE_ID=r2.ATTRIBUTE_ID
+                                    and	r.year=r2.`YEAR`and r.`MONTH`-1=r2.`MONTH`
         </if>
         <if test="type != null and type ==2">
-            order by r.`DAY` asc
+            left join sms_month_report r2 on r.DEVICE_ID=r2.DEVICE_ID and r.ATTRIBUTE_ID=r2.ATTRIBUTE_ID
+                                    and	r.year=r2.`YEAR`and r.`MONTH`=r2.`MONTH`and r.`DAY`-1=r2.`DAY`
         </if>
         <if test="type != null and type ==3">
-            order by r.`HOUR` asc
+            left join sms_day_report r2 on r.DEVICE_ID=r2.DEVICE_ID and r.ATTRIBUTE_ID=r2.ATTRIBUTE_ID
+                                    and	r.year=r2.`YEAR`and r.`MONTH`=r2.`MONTH` and r.`DAY`=r2.`DAY` and r.`HOUR`-1 =r2.`HOUR`
+        </if>
+
+        where (da.ATTRIBUTE_TYPE=3 or da.ATTRIBUTE_TYPE=5)
+        <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>
+        <if test="type != null and type ==1">
+            and r.year=#{year}
+            order by d.DEVICE_CODE,da.ATTRIBUTE_TYPE asc,r.`MONTH` asc
+        </if>
+        <if test="type != null and type ==2">
+            and r.year=#{year}  and r.month=#{month}
+            order by d.DEVICE_CODE,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}
+            order by d.DEVICE_CODE,da.ATTRIBUTE_TYPE asc,r.`hour` asc
+        </if>
     </select>
 
-<select id="updatedd" resultType="java.lang.Integer">
-    select 1
-</select>
+
+    <select id="MonitorDataQualityReport" resultMap="MonitorDataChartReportMap">
+        select
+        <if test="type != null and type ==1">
+            r.`MONTH` as "dateLabel",
+        </if>
+        <if test="type != null and type ==2">
+            r.`DAY` as "dateLabel",
+        </if>
+        <if test="type != null and type ==3">
+            r.`HOUR` as "dateLabel",
+        </if>
+            cast(ifnull(r.AVG_VALUE,'') as char)+ifnull(da.UNIT,'') as "monitorData"
+            ,r.AVG_VALUE as "data"
+            ,r.COLLECT_DATE as "date"
+
+            ,d.DEVICE_CODE as "devoceCode"
+            ,d.DEVICE_NAME as "deviceName"
+            ,da.ATTRIBUTE_TYPE as "attributeType"
+            ,if(da.ATTRIBUTE_TYPE=8,'PH',if(da.ATTRIBUTE_TYPE=11,'余氯','浊度')) as  "attributeName"
+        <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
+        </if>
+        <include refid="MonitorDataReportJoins"/>
+        where (da.ATTRIBUTE_TYPE=8 or da.ATTRIBUTE_TYPE=11  or da.ATTRIBUTE_TYPE=10)
+
+        <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>
+        <if test="type != null and type ==1">
+            and r.year=#{year}
+            order by d.DEVICE_CODE,da.ATTRIBUTE_TYPE asc,r.`MONTH` asc
+        </if>
+        <if test="type != null and type ==2">
+            and r.year=#{year}  and r.month=#{month}
+            order by d.DEVICE_CODE,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}
+            order by d.DEVICE_CODE,da.ATTRIBUTE_TYPE asc,r.`hour` asc
+        </if>
+    </select>
+
+
+
+
+    <select id="DeviceAlarmReport" resultMap="MonitorDataChartReportMap">
+        select
+        a.*,DATE_ADD(#{beginDate},INTERVAL a.dateLabel ${dateType}) as "date"
+        from (
+            select
+        ${dateType}(ad.ALARM_START_TIME) as  "dateLabel"
+            ,count(1) as "monitorData"
+            ,count(1) as "data"
+
+            ,d.DEVICE_CODE as "devoceCode"
+            ,d.DEVICE_NAME as "deviceName"
+            ,'报警次数' as "attributeName"
+            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
+                <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>
+
+            group by d.DEVICE_CODE,d.DEVICE_NAME,${dateType}(ad.ALARM_START_TIME)
+        )a
+        order by devoceCode,deviceName,dateLabel
+    </select>
 
 </mapper>