ZhuDongming
2020-05-19 e51e2d053b498e236097bcb4012c8446d672be86
设备版本添加大屏界面控制
7 files modified
269 ■■■■ changed files
src/main/java/com/moral/controller/OrganizationLayoutController.java 21 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/impl/HistoryServiceImpl.java 14 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/impl/OrganizationLayoutServiceImpl.java 23 ●●●●● patch | view | raw | blame | history
src/main/resources/mapper/DeviceVersionMapper.xml 4 ●●●● patch | view | raw | blame | history
src/main/resources/mapper/HistoryHourlyMapper.xml 32 ●●●● patch | view | raw | blame | history
src/main/resources/mapper/HistoryMapper.xml 32 ●●●● patch | view | raw | blame | history
src/main/resources/mapper/HistoryMinutelyMapper.xml 143 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/controller/OrganizationLayoutController.java
@@ -1,22 +1,27 @@
package com.moral.controller;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import com.moral.common.bean.ResultBean;
import com.moral.entity.DeviceVersion;
import com.moral.entity.Sensor;
import com.moral.entity.layout.RealTimeDeviceLayout;
import com.moral.entity.layout.RtdLayoutUpload;
import com.moral.entity.layout.SensorComb;
import com.moral.service.DeviceVersionService;
import com.moral.service.OrganizationLayoutService;
import com.moral.service.SensorService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("org-layout")
src/main/java/com/moral/service/impl/HistoryServiceImpl.java
@@ -23,10 +23,6 @@
import javax.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.googlecode.aviator.AviatorEvaluator;
@@ -46,6 +42,10 @@
import com.moral.service.HistoryService;
import com.moral.service.ProfessionService;
import com.moral.util.AQICalculation;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
@Service
public class HistoryServiceImpl implements HistoryService {
@@ -485,6 +485,8 @@
        String startTime = parameters.get("startTime").toString();
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime startTimeLocalDateTime = LocalDateTime.parse(startTime, dateTimeFormatter);
        LocalDateTime today = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS);
        LocalDateTime startTimeDay = startTimeLocalDateTime.truncatedTo(ChronoUnit.DAYS);
        int year = startTimeLocalDateTime.getYear();
        int month = startTimeLocalDateTime.getMonthValue();
        String monthStr = month < 10 ? ("0" + month) : month + "";
@@ -496,7 +498,9 @@
        }
        parameters.put("sensorKeys", sensorKeys);
        List<Map<String, Object>> listMap = null;
        listMap = historyMapper.listGetSensorData(parameters);
        if (today.compareTo(startTimeDay) == 0) {
            listMap = historyMapper.listGetSensorData(parameters);
        }
        if (CollectionUtils.isEmpty(listMap)) {
            listMap = historyMapper.getCarSensorData(parameters);
            if (CollectionUtils.isEmpty(listMap)) {
src/main/java/com/moral/service/impl/OrganizationLayoutServiceImpl.java
@@ -1,8 +1,19 @@
package com.moral.service.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.moral.entity.*;
import com.moral.entity.DictionaryData;
import com.moral.entity.OrganizationLayout;
import com.moral.entity.OrganizationSensorUnit;
import com.moral.entity.Sensor;
import com.moral.entity.SensorUnit;
import com.moral.entity.layout.RealTimeDeviceLayout;
import com.moral.entity.layout.RtdLayoutUpload;
import com.moral.entity.layout.SensorComb;
@@ -11,15 +22,10 @@
import com.moral.mapper.OrganizationSensorUnitMapper;
import com.moral.mapper.SensorMapper;
import com.moral.service.OrganizationLayoutService;
import org.springframework.data.annotation.Transient;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@Service
public class OrganizationLayoutServiceImpl implements OrganizationLayoutService{
@@ -215,7 +221,8 @@
    public  RealTimeDeviceLayout queryRtdLayoutWithUnit(Integer orgId, Integer versionNo) {
        String pageType = getPageType(versionNo);
        if(queryPageConfigCountByOrgId(orgId,pageType) == 0 ){
            orgId = dataMapper.selectSupperOrgId();
            // orgId = dataMapper.selectSupperOrgId();
            orgId = 0;
        }
        RealTimeDeviceLayout rtdLayout = queryRealTimeDeviceLayout(orgId,versionNo);
        loadUnitToComb(orgId,rtdLayout);
src/main/resources/mapper/DeviceVersionMapper.xml
@@ -24,10 +24,6 @@
                (
                   SELECT id FROM monitor_point mpt
                   WHERE mpt.organization_id = #{orgId,jdbcType=INTEGER}
                        or EXISTS (
                        SELECT * from dictionary_data where dict_data_key = 'auth_config_super_org' and dict_data_value = #{orgId,jdbcType=INTEGER}
                        )
                )
              )
          order by dvn.create_time desc
src/main/resources/mapper/HistoryHourlyMapper.xml
@@ -10,10 +10,10 @@
        history_hourly
        <where>
            <if test="mac!=null">
                AND mac=#{mac}
                AND mac = #{mac}
            </if>
            <if test="time!=null">
                AND time= DATE_SUB(#{time}, INTERVAL 1 HOUR)
                AND time = DATE_SUB(#{time}, INTERVAL 1 HOUR)
            </if>
        </where>
    </select>
@@ -26,30 +26,30 @@
        </foreach>
        FROM
        <if test="mac!=null and time!=null">
        (select mac,value,time,version from history
        where mac=#{mac} and time BETWEEN DATE_SUB(#{time}, INTERVAL 1 HOUR) and #{time}) h
            (select mac,value,time,version from history
            where mac = #{mac} and time BETWEEN DATE_SUB(#{time}, INTERVAL 1 HOUR) and #{time}) h
        </if>
        GROUP BY
        DATE_FORMAT(time,'%Y-%m-%d %H')
        <if test="time!=null">
        having time=DATE_FORMAT(DATE_SUB(#{time}, INTERVAL 1 HOUR),'%Y-%m-%d %H')
            having time = DATE_FORMAT(DATE_SUB(#{time}, INTERVAL 1 HOUR),'%Y-%m-%d %H')
        </if>
    </select>
    <select id="getPollutionSourceDataAll" resultType="java.util.Map">
    SELECT
    DATE_FORMAT(time,'%Y-%m-%d %H') time,
    <foreach collection="sensorKeys" separator="," item="sensorKey">
        AVG(h.value ->'$.${sensorKey}') AS '${sensorKey}'
    </foreach>
    FROM
        SELECT
        DATE_FORMAT(time,'%Y-%m-%d %H') time,
        <foreach collection="sensorKeys" separator="," item="sensorKey">
            AVG(h.value ->'$.${sensorKey}') AS '${sensorKey}'
        </foreach>
        FROM
        <if test="mac!=null">
            (select mac,value,time,version from history
            where mac=#{mac} and time BETWEEN DATE_SUB(#{time}, INTERVAL 1 DAY) and #{time}) h
            where mac = #{mac} and time BETWEEN DATE_SUB(#{time}, INTERVAL 1 DAY) and #{time}) h
        </if>
    GROUP BY
    DATE_FORMAT(time,'%Y-%m-%d %H')
    order by time desc
    limit 0,1
        GROUP BY
        DATE_FORMAT(time,'%Y-%m-%d %H')
        order by time desc
        limit 0,1
    </select>
</mapper>
src/main/resources/mapper/HistoryMapper.xml
@@ -183,7 +183,7 @@
        history h
        <where>
            <if test="mac!=null">
                and h.mac=#{mac}
                and h.mac = #{mac}
            </if>
            and h.time >= #{startTime}
            and h.time <![CDATA[<=]]> #{endTime}
@@ -193,21 +193,21 @@
        ORDER BY
        time
    </select>
    <select id="getAVGSensorRankByMonitorPointIdList" resultType="java.util.Map">
        SELECT mp.name, AVG(JSON_EXTRACT(h.value,'$.${sensor}[0]')) sensor
        FROM device d, history h, monitor_point mp
        WHERE d.mac=h.mac
        And mp.id=d.monitor_point_id
        AND d.monitor_point_id IN
            <foreach collection="monitorPointIdList" index="index" item="monitorPointId" open="(" separator="," close=")">
                #{monitorPointId}
            </foreach>
        AND h.time BETWEEN #{before5Time} AND #{endTime}
        GROUP BY d.monitor_point_id
        ORDER BY AVG(JSON_EXTRACT(h.value,'$.${sensor}[0]')) DESC
        SELECT mp.name, AVG(JSON_EXTRACT(h.value,'$.${sensor}[0]')) sensor
        FROM device d, history h, monitor_point mp
        WHERE d.mac=h.mac
        And mp.id=d.monitor_point_id
        AND d.monitor_point_id IN
        <foreach collection="monitorPointIdList" index="index" item="monitorPointId" open="(" separator="," close=")">
            #{monitorPointId}
        </foreach>
        AND h.time BETWEEN #{before5Time} AND #{endTime}
        GROUP BY d.monitor_point_id
        ORDER BY AVG(JSON_EXTRACT(h.value,'$.${sensor}[0]')) DESC
    </select>
    <select id="getMonitorPointAVGValueByMonitorPointIdAndTimeslot" resultType="java.util.Map">
        SELECT AVG(JSON_EXTRACT(value,'$.e1[0]')) e1,AVG(JSON_EXTRACT(value,'$.e2[0]')) e2,AVG(JSON_EXTRACT(value,'$.e10[0]')) e10,AVG(JSON_EXTRACT(value,'$.e11[0]')) e11,AVG(JSON_EXTRACT(value,'$.e16[0]')) e16,AVG(JSON_EXTRACT(value,'$.e15[0]')) e15
        FROM device d,history h
@@ -227,7 +227,7 @@
        history_special as h
        <where>
            <if test="mac!=null">
                and h.mac=#{mac}
                and h.mac = #{mac}
            </if>
            and h.time >= #{startTime}
            and h.time <![CDATA[<]]> #{endTime}
@@ -246,7 +246,7 @@
        history as h
        <where>
            <if test="mac!=null">
                and h.mac=#{mac}
                and h.mac = #{mac}
            </if>
            and h.time >= #{startTime}
            and h.time <![CDATA[<]]> #{endTime}
src/main/resources/mapper/HistoryMinutelyMapper.xml
@@ -8,8 +8,8 @@
    <select id="getSersionAvgByDevice" resultType="java.util.Map">
        SELECT
        <foreach collection="sensorKeys" separator="," item="sensorKey">
      AVG(json->'$.${sensorKey}[0]') AS '${sensorKey}'
    </foreach>
            AVG(json->'$.${sensorKey}[0]') AS '${sensorKey}'
        </foreach>
        FROM
        history_minutely_${yearAndMonth}
        WHERE
@@ -21,11 +21,11 @@
        WHERE
        d.is_delete = 0
        <if test="monitorPointId != null">
      AND d.monitor_point_id = #{monitorPointId}
    </if>
            AND d.monitor_point_id = #{monitorPointId}
        </if>
        <if test="mac != null">
      AND d.mac = #{mac}
    </if>
            AND d.mac = #{mac}
        </if>
        )
        AND time >= #{start}
        AND time &lt; #{end}
@@ -34,8 +34,8 @@
    <select id="getAvgByDevice" resultType="java.util.Map">
        SELECT
        <foreach collection="sensorKeys" separator="," item="sensorKey">
      AVG(json->'$.${sensorKey}[0]') AS '${sensorKey}'
    </foreach>
            AVG(json->'$.${sensorKey}[0]') AS '${sensorKey}'
        </foreach>
        FROM
        history_daily
        WHERE
@@ -47,11 +47,11 @@
        WHERE
        d.is_delete = 0
        <if test="monitorPointId != null">
      AND d.monitor_point_id = #{monitorPointId}
    </if>
            AND d.monitor_point_id = #{monitorPointId}
        </if>
        <if test="mac != null">
      AND d.mac = #{mac}
    </if>
            AND d.mac = #{mac}
        </if>
        )
        AND time >= #{start}
        AND time &lt; #{end}
@@ -61,16 +61,16 @@
        SELECT
        DATE_FORMAT(time, #{typeFormat}) time
        <foreach collection="sensorKeys" open="," separator="," item="sensorKey">
      AVG(json->'$.${sensorKey}[0]') AS '${sensorKey}'
    </foreach>
            AVG(json->'$.${sensorKey}[0]') AS '${sensorKey}'
        </foreach>
        FROM
        history_${timeUnits} h
        WHERE
        h.time >= #{start}
        AND h.time <![CDATA[<]]> #{end}
        <if test="mac != null">
      AND h.mac = #{mac}
    </if>
            AND h.mac = #{mac}
        </if>
        <if test="mac == null">
            AND h.mac IN
            (SELECT
@@ -81,20 +81,20 @@
            WHERE
            d.monitor_point_id = mp.id
            <if test="provinceCode != null">
        AND mp.province_code = #{provinceCode}
      </if>
                AND mp.province_code = #{provinceCode}
            </if>
            <if test="cityCode != null">
        AND mp.city_code = #{cityCode}
      </if>
                AND mp.city_code = #{cityCode}
            </if>
            <if test="areaCode != null">
        AND mp.area_code = #{areaCode}
      </if>
                AND mp.area_code = #{areaCode}
            </if>
            <if test="monitorPointId != null">
        AND mp.id = #{monitorPointId}
      </if>
                AND mp.id = #{monitorPointId}
            </if>
            <if test="professionId != null">
        AND d.profession_id = #{professionId}
      </if>
                AND d.profession_id = #{professionId}
            </if>
            )
        </if>
@@ -110,14 +110,14 @@
            <when test="'MINUTE'==dataCondition.timeUnits.toString() and 'DEVICE'==dataCondition.areaRange.toString()">
                <foreach collection="sensorKeys"
                         item="sensorKey" separator="," close=",">
          json->'$.${sensorKey}[0]' as '${sensorKey}'
        </foreach>
                    json->'$.${sensorKey}[0]' as '${sensorKey}'
                </foreach>
            </when>
            <otherwise>
                <foreach collection="sensorKeys"
                         item="sensorKey" separator="," close=",">
          AVG(json->'$.${sensorKey}[0]') as '${sensorKey}'
        </foreach>
                    AVG(json->'$.${sensorKey}[0]') as '${sensorKey}'
                </foreach>
            </otherwise>
        </choose>
        DATE_FORMAT(time,'${@com.moral.common.util.ReportTimeFormat@toMySqlTimeFormat(timePeriod.timeUnits)}') as
@@ -128,38 +128,38 @@
            and hmi.time >= #{timePeriod.startTime}
            and hmi.time <![CDATA[<=]]> #{timePeriod.endTime}
            <if test="dataCondition.actualTime != null">
        and DATE_FORMAT(time,
        '${@com.moral.common.util.ReportTimeFormat@toMySqlActualTimeFormat(dataCondition.timeUnits)}') =
        #{dataCondition.actualTime}
      </if>
                and DATE_FORMAT(time,
                '${@com.moral.common.util.ReportTimeFormat@toMySqlActualTimeFormat(dataCondition.timeUnits)}') =
                #{dataCondition.actualTime}
            </if>
            and hmi.mac in (
            select mac from device dev
            join monitor_point mpt on dev.monitor_point_id = mpt.id
            <where>
                <if test='"DEVICE"==dataCondition.areaRange.toString()'>
          and dev.id = #{dataCondition.areaRangeId}
        </if>
                    and dev.id = #{dataCondition.areaRangeId}
                </if>
                <if test='"PROFESSION"==dataCondition.deviceDimension.toString()'>
          and dev.profession_id = #{dataCondition.dimensionValue}
        </if>
                    and dev.profession_id = #{dataCondition.dimensionValue}
                </if>
                <if test='"MONITORPOINT"==dataCondition.areaRange.toString()'>
          and mpt.id = #{dataCondition.areaRangeId}
        </if>
                    and mpt.id = #{dataCondition.areaRangeId}
                </if>
                <if test='"PROVINCE"==dataCondition.areaRange.toString()'>
          and mpt.province_code = #{dataCondition.areaRangeId}
        </if>
                    and mpt.province_code = #{dataCondition.areaRangeId}
                </if>
                <if test='"CITY"==dataCondition.areaRange.toString()'>
          and mpt.city_code = #{dataCondition.areaRangeId}
        </if>
                    and mpt.city_code = #{dataCondition.areaRangeId}
                </if>
                <if test='"AREA"==dataCondition.areaRange.toString()'>
          and mpt.area_code = #{dataCondition.areaRangeId}
        </if>
                    and mpt.area_code = #{dataCondition.areaRangeId}
                </if>
            </where>
            )
        </where>
        <if test="'MINUTE'!=dataCondition.timeUnits.toString() or 'DEVICE'!=dataCondition.areaRange.toString()">
      GROUP BY format_time
    </if>
            GROUP BY format_time
        </if>
        ORDER BY format_time asc
    </select>
@@ -168,16 +168,16 @@
        SELECT
        DATE_FORMAT(hm.time,'%Y-%m-%d %H:%i:%s') time,
        <foreach collection="sensorKeys" item="sensorKey" separator=",">
      hm.json->'$.${sensorKey}[0]' as '${sensorKey}',
      hm.json->'$.${sensorKey}[1]' as 'min${sensorKey}',
      hm.json->'$.${sensorKey}[2]' as 'max${sensorKey}'
    </foreach>
            hm.json->'$.${sensorKey}[0]' as '${sensorKey}',
            hm.json->'$.${sensorKey}[1]' as 'min${sensorKey}',
            hm.json->'$.${sensorKey}[2]' as 'max${sensorKey}'
        </foreach>
        FROM
        history_minutely as hm
        <where>
            <if test="mac!=null">
        and hm.mac=#{mac}
      </if>
                and hm.mac = #{mac}
            </if>
            and hm.time >= #{startTime}
            and hm.time <![CDATA[<]]> #{endTime}
        </where>
@@ -189,16 +189,16 @@
        SELECT
        DATE_FORMAT(hm.time,'%Y-%m-%d %H:%i:%s') time,
        <foreach collection="sensorKeys" item="sensorKey" separator=",">
      hm.json->'$.${sensorKey}[0]' as '${sensorKey}',
      hm.json->'$.${sensorKey}[1]' as 'min${sensorKey}',
      hm.json->'$.${sensorKey}[2]' as 'max${sensorKey}'
    </foreach>
            hm.json->'$.${sensorKey}[0]' as '${sensorKey}',
            hm.json->'$.${sensorKey}[1]' as 'min${sensorKey}',
            hm.json->'$.${sensorKey}[2]' as 'max${sensorKey}'
        </foreach>
        FROM
        history_minutely_${yearAndMonth} as hm
        <where>
            <if test="mac!=null">
        and hm.mac=#{mac}
      </if>
                and hm.mac = #{mac}
            </if>
            and hm.time >= #{startTime}
            and hm.time <![CDATA[<]]> #{endTime}
        </where>
@@ -210,28 +210,27 @@
        select
        rs.monitorPointName,rs.name,
        <foreach collection="timeList" separator="," item="time">
      max(case time when #{time} then rs.${sensorKey} else "" end) as #{time}
    </foreach>
            max(case time when #{time} then rs.${sensorKey} else "" end) as #{time}
        </foreach>
        from
        (SELECT
        m.name as monitorPointName,d.name,DATE_FORMAT(time, #{typeFormat}) time,
        <foreach collection="sensorKeys" separator="," item="sensorKey">
      AVG(json->'$.${sensorKey}[0]') AS '${sensorKey}'
    </foreach>
            AVG(json->'$.${sensorKey}[0]') AS '${sensorKey}'
        </foreach>
        FROM
        history_${timeUnits} h,
        device d,
        monitor_point m
        WHERE
        h.mac=d.mac
        AND d.monitor_point_id=m.id
        h.mac = d.mac
        AND d.monitor_point_id = m.id
        AND h.time >= #{start}
        AND h.time <![CDATA[<=]]> #{end}
        AND h.mac in
        <foreach collection="macs" open="(" separator="," close=")"
                 item="mac">
      #{mac}
    </foreach>
        <foreach collection="macs" open="(" separator="," close=")" item="mac">
            #{mac}
        </foreach>
        GROUP BY
        h.mac,m.name,d.name,DATE_FORMAT(time, #{typeFormat})
        ORDER BY
@@ -254,8 +253,8 @@
        device d,
        monitor_point m
        WHERE
        h.mac=d.mac
        AND d.monitor_point_id=m.id
        h.mac = d.mac
        AND d.monitor_point_id = m.id
        AND h.time >= #{start}
        AND h.time <![CDATA[<=]]> #{end}
        AND h.mac in