Procházet zdrojové kódy

图表报表修改

wangli před 4 roky
rodič
revize
39b6f2309a

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

@@ -35,7 +35,7 @@ public class MonitorDataReportController {
     @ApiOperation(value = "二供——图表")
     public AjaxMessage<List<MonitorDataChartReportDeviceDto>> MonitorDataChartReport(
             @ApiParam(value = "场景id", required = true) @RequestParam Long sceneId,
-            @ApiParam(value = "日期,格式:2020-12-12", required = true) @RequestParam String reportDate,
+            @ApiParam(value = "时间", required = true) @RequestParam String reportDate,
             @ApiParam(value = "类型,1年2月3日", required = true) @RequestParam Integer reportType
     ){
         LocalDate localDate =LocalDate.now();

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

@@ -22,6 +22,8 @@ public class MonitorDataChartReportAttributeDto implements Serializable {
     private String attributeType;
     @ApiModelProperty("属性名称")
     private String attributeName;
+    @ApiModelProperty("属性单位")
+    private String unit;
     @ApiModelProperty("数据")
     private List<MonitorDataChartReportValueDto> monitorDataChartReportValue;
 }

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

@@ -20,8 +20,10 @@ import java.util.Date;
 public class MonitorDataChartReportValueDto implements Serializable {
 
     private static final long serialVersionUID = 6248751275101485917L;
-    @ApiModelProperty("X轴时间数字")
+    @ApiModelProperty("X轴数字")
     private Integer dateLabel;
+    @ApiModelProperty("X轴时间")
+    private String dateStringLabel;
     @ApiModelProperty("数据带单位")
     private String monitorData;
     @ApiModelProperty("数据值")

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

@@ -102,33 +102,7 @@ public class ReceiveData {
             }
             List<MonitorDataEntity> list = new ArrayList<>();
             //暂时测试共用一个设备数据
-            MonitorDataEntity monitorDataEntity0 =  monitorDataService.getDeviceMonitorInfoByDeviceCode(devcieCode);
-            MonitorDataEntity monitorDataEntity1 =  monitorDataService.getDeviceMonitorInfoByDeviceCode("SDD5456");
-            MonitorDataEntity monitorDataEntity2 =  monitorDataService.getDeviceMonitorInfoByDeviceCode("AJH1210");
-            MonitorDataEntity monitorDataEntity3 =  monitorDataService.getDeviceMonitorInfoByDeviceCode("WL20201215A");
-            MonitorDataEntity monitorDataEntity4 =  monitorDataService.getDeviceMonitorInfoByDeviceCode("WL20201215B");
-            MonitorDataEntity monitorDataEntity5 =  monitorDataService.getDeviceMonitorInfoByDeviceCode("WL20201215C");
-            MonitorDataEntity monitorDataEntity6 =  monitorDataService.getDeviceMonitorInfoByDeviceCode("SDH54GDS45");
-            MonitorDataEntity monitorDataEntity7 =  monitorDataService.getDeviceMonitorInfoByDeviceCode("QWA65D");
-            MonitorDataEntity monitorDataEntity8 =  monitorDataService.getDeviceMonitorInfoByDeviceCode("DFG454963");
-            MonitorDataEntity monitorDataEntity9 =  monitorDataService.getDeviceMonitorInfoByDeviceCode("DFD1234");
-            MonitorDataEntity monitorDataEntity10 =  monitorDataService.getDeviceMonitorInfoByDeviceCode("DSF24564 ");
-            MonitorDataEntity monitorDataEntity11 =  monitorDataService.getDeviceMonitorInfoByDeviceCode("ASH641 ");
-            MonitorDataEntity monitorDataEntity12 =  monitorDataService.getDeviceMonitorInfoByDeviceCode("HJH562");
-            list.add(monitorDataEntity0);
-            list.add(monitorDataEntity1);
-            list.add(monitorDataEntity2);
-            list.add(monitorDataEntity3);
-            list.add(monitorDataEntity4);
-            list.add(monitorDataEntity5);
-            list.add(monitorDataEntity6 );
-            list.add(monitorDataEntity7 );
-            list.add(monitorDataEntity8 );
-            list.add(monitorDataEntity9 );
-            list.add(monitorDataEntity10);
-            list.add(monitorDataEntity11);
-            list.add(monitorDataEntity12);
-            for(MonitorDataEntity monitorDataEntity:list){
+            MonitorDataEntity monitorDataEntity =  monitorDataService.getDeviceMonitorInfoByDeviceCode(devcieCode);
             //
             //查询不到设备或者设备属性为空
             if(monitorDataEntity == null
@@ -222,7 +196,7 @@ public class ReceiveData {
                 alarmDetailMapper.batchInsert(insert);
                }
            }
-            }
+
         }
 
     }

+ 36 - 6
sms_water/src/main/java/com/huaxu/service/impl/MonitorDataReportServiceImpl.java

@@ -81,13 +81,28 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
                                 MonitorDataChartReportValueDto monitorDataChartReportValueDto = new MonitorDataChartReportValueDto();
                                 monitorDataChartReportValueDto.setData(0.0);
                                 if(type != null && type ==3){
-                                    monitorDataChartReportValueDto.setDate(localDateTime.plusHours(i));
+                                    LocalDateTime dateTime= localDateTime.plusHours(i);
+                                    monitorDataChartReportValueDto.setDate(dateTime);
+                                    monitorDataChartReportValueDto.setDateStringLabel(
+                                                        dateTime.getYear()+"-"+
+                                                        dateTime.getMonthValue()+"-"+
+                                                        dateTime.getDayOfMonth()+" "+
+                                                        dateTime.getHour()+":00");
                                 }
                                 if(type != null && type ==2){
-                                    monitorDataChartReportValueDto.setDate(localDateTime.plusDays(i));
+                                    LocalDateTime dateTime= localDateTime.plusDays(i);
+                                    monitorDataChartReportValueDto.setDate(dateTime);
+                                    monitorDataChartReportValueDto.setDateStringLabel(
+                                                    dateTime.getYear()+"-"+
+                                                    dateTime.getMonthValue()+"-"+
+                                                    dateTime.getDayOfMonth());
                                 }
                                 if(type != null && type ==1){
-                                    monitorDataChartReportValueDto.setDate(localDateTime.plusMonths(i));
+                                    LocalDateTime dateTime= localDateTime.plusMonths(i);
+                                    monitorDataChartReportValueDto.setDate(dateTime);
+                                    monitorDataChartReportValueDto.setDateStringLabel(
+                                            dateTime.getYear()+"-"+
+                                                    dateTime.getMonthValue());
                                 }
                                 monitorDataChartReportValueDto.setDateLabel(i+growingBase);
                                 monitorDataChartReportValueDto.setMonitorData("");
@@ -97,13 +112,28 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
                                 MonitorDataChartReportValueDto monitorDataChartReportValueDto = new MonitorDataChartReportValueDto();
                                 monitorDataChartReportValueDto.setData(0.0);
                                 if(type != null && type ==3){
-                                    monitorDataChartReportValueDto.setDate(localDateTime.plusHours(i));
+                                    LocalDateTime dateTime= localDateTime.plusHours(i);
+                                    monitorDataChartReportValueDto.setDate(dateTime);
+                                    monitorDataChartReportValueDto.setDateStringLabel(
+                                            dateTime.getYear()+"-"+
+                                                    dateTime.getMonthValue()+"-"+
+                                                    dateTime.getDayOfMonth()+" "+
+                                                    dateTime.getHour()+":00");
                                 }
                                 if(type != null && type ==2){
-                                    monitorDataChartReportValueDto.setDate(localDateTime.plusDays(i));
+                                    LocalDateTime dateTime= localDateTime.plusDays(i);
+                                    monitorDataChartReportValueDto.setDate(dateTime);
+                                    monitorDataChartReportValueDto.setDateStringLabel(
+                                            dateTime.getYear()+"-"+
+                                                    dateTime.getMonthValue()+"-"+
+                                                    dateTime.getDayOfMonth());
                                 }
                                 if(type != null && type ==1){
-                                    monitorDataChartReportValueDto.setDate(localDateTime.plusMonths(i));
+                                    LocalDateTime dateTime= localDateTime.plusMonths(i);
+                                    monitorDataChartReportValueDto.setDate(dateTime);
+                                    monitorDataChartReportValueDto.setDateStringLabel(
+                                            dateTime.getYear()+"-"+
+                                                    dateTime.getMonthValue());
                                 }
                                 monitorDataChartReportValueDto.setDateLabel(i+growingBase);
                                 monitorDataChartReportValueDto.setMonitorData("");

+ 36 - 11
sms_water/src/main/resources/mapper/MonitorDataReportMapper.xml

@@ -11,11 +11,13 @@
     <resultMap id="AttributeData" type="com.huaxu.dto.MonitorDataChartReportAttributeDto">
         <result property="attributeType" column="attributeType"/>
         <result property="attributeName" column="attributeName"/>
+        <result property="unit" column="unit"/>
         <collection property="monitorDataChartReportValue" resultMap="MonitorDataChartReportValue"/>
     </resultMap>
 
     <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"/>
@@ -30,12 +32,15 @@
         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>
         cast(ifnull(r.AVG_VALUE,'') as char)+ifnull(da.UNIT,'') as "monitorData"
         ,r.AVG_VALUE as "data"
@@ -43,6 +48,7 @@
 
         ,d.DEVICE_CODE as "devoceCode"
         ,d.DEVICE_NAME as "deviceName"
+        ,da.unit as "unit"
         ,r.ATTRIBUTE_NAME as "attributeName"
 
         from ${tableName} r
@@ -104,23 +110,28 @@
 
     <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.SUM_VALUE,0) as char)+ifnull(da.UNIT,'') as "monitorData"
+        <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>
+        cast(ifnull(r.SUM_VALUE,0) as char)+ifnull(da.UNIT,'') as "monitorData"
             ,ifnull(r.SUM_VALUE ,0)  as "data"
             ,r.COLLECT_DATE as "date"
 
             ,d.DEVICE_CODE as "devoceCode"
             ,d.DEVICE_NAME as "deviceName"
             ,da.ATTRIBUTE_TYPE as "attributeType"
+            ,da.unit as "unit"
             ,if(da.ATTRIBUTE_TYPE=3,'用水量','耗电量') as  "attributeName"
+
         <if test="type != null and type ==1">
             from sms_year_report r
         </if>
@@ -188,12 +199,15 @@
         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>
             cast(ifnull(r.AVG_VALUE,'') as char)+ifnull(da.UNIT,'') as "monitorData"
             ,r.AVG_VALUE as "data"
@@ -202,6 +216,7 @@
             ,d.DEVICE_CODE as "devoceCode"
             ,d.DEVICE_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"
         <if test="type != null and type ==1">
             from sms_year_report r
@@ -271,10 +286,20 @@
 
     <select id="DeviceAlarmReport" resultMap="MonitorDataChartReportMap">
         select
-        a.*,DATE_ADD(#{beginDate},INTERVAL a.dateLabel ${dateType}) as "date"
+        a.*,DATE_ADD(#{beginDate},INTERVAL a.dateLabel-1 ${dateType}) as "date"
         from (
             select
         ${dateType}(ad.ALARM_START_TIME) as  "dateLabel"
+
+        <if test="dateType != null and dateType == 'month'">
+            ,DATE_FORMAT(max(ad.ALARM_START_TIME),'%Y-%m') as "dateStringLabel"
+        </if>
+        <if test="dateType != null and dateType == 'day'">
+            ,DATE_FORMAT(max(ad.ALARM_START_TIME),'%Y-%m-%d') as "dateStringLabel"
+        </if>
+        <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"