工业级运维app手机api
沈斌
2017-10-27 d0a7ad5e3a1c147a70a0e792c3eafa3b7613fff7
Merge remote-tracking branch 'origin/master'
4 files modified
42 ■■■■ changed files
src/main/java/com/moral/monitor/dao/HistoryEntityMapper.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/monitor/service/impl/ScreenServiceImpl.java 34 ●●●● patch | view | raw | blame | history
src/main/resources/mapper/HistoryEntityMapper.xml 3 ●●●●● patch | view | raw | blame | history
src/main/resources/sysConfig.properties 3 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/monitor/dao/HistoryEntityMapper.java
@@ -13,4 +13,6 @@
    List<Map<String, Object>> getAverageByAll(Map<String, Object> parameters);
    List<Map<String, Object>> getEquipmentStates(Map<String, Object> parameters); 
    String getMacLogByLast();
}
src/main/java/com/moral/monitor/service/impl/ScreenServiceImpl.java
@@ -10,12 +10,14 @@
import java.util.Map;
import java.util.Set;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON;
import com.moral.monitor.dao.AccountEntityMapper;
import com.moral.monitor.dao.HistoryEntityMapper;
import com.moral.monitor.entity.AccountEntity;
@@ -81,6 +83,7 @@
        //AQI 指数
        String[] macKeys = { "e1", "e2", "e10", "e11", "e15", "e16" };
        String[] IAQIValues = ResourceUtil.getArrValue("IAQI");
        List<Double> IAQIs = new ArrayList<Double>();
        for (String macKey : macKeys) {
            double avg = 0, maxMacKey = 0, minMacKey = 0;
@@ -93,26 +96,21 @@
            String[] macKeyValues = ResourceUtil.getArrValue(macKey);
            int index = -1;
            for (int i = 0; i < macKeyValues.length; i++) {
                Double macKeyValue = Double.valueOf(macKeyValues[i]);
                if (avg <= macKeyValue) {
                if (avg <= Double.valueOf(macKeyValues[i])) {
                    if (i == 0) {
                        index = 0;
                        minMacKey = macKeyValue;
                        maxMacKey = Double.valueOf(macKeyValues[i + 1]);
                        index = i;
                    } else {
                        index = i - 1;
                        minMacKey = Double.valueOf(macKeyValues[i - 1]);
                        maxMacKey = macKeyValue;
                    }
                    minMacKey = Double.valueOf(macKeyValues[index]);
                    maxMacKey = Double.valueOf(macKeyValues[index + 1]);
                    continue;
                }
            }
            if (index == -1) {
                resultMap.put("AQI", ">500");
                break;
            }
            String[] IAQIValues = ResourceUtil.getArrValue("IAQI");
            double minIAQI = Double.valueOf(IAQIValues[index]);
            double maxIAQI = Double.valueOf(IAQIValues[index + 1]);
            IAQIs.add(calculateIAQI(maxIAQI, minIAQI, maxMacKey, minMacKey, avg));
@@ -150,6 +148,19 @@
        parameters.put("start", DateUtils.addMinutes(date, -10));
        parameters.put("end", DateUtils.addMinutes(date, -5));
        List<Map<String, Object>> averageByAll = historyMapper.getAverageByAll(parameters);
        //临时方案,空值处理
        if (CollectionUtils.isEmpty(averageByAll)) {
            String macLog = historyMapper.getMacLogByLast();
            if(StringUtils.isNotBlank(macLog)){
                Map<String, Object> map = JSON.parseObject(macLog);
                for (String key : map.keySet()) {
                    if (key.startsWith("e")) {
                        result.put(key, map.get(key));
                    }
                }
            }
        }
        for (Map<String, Object> map : averageByAll) {
            result.put((String) map.get("mac_key"), map.get("avg"));
        }
@@ -185,9 +196,12 @@
    public void setOrgIdsByAccount(Map<String, Object> parameters) {
        AccountEntity account = accountMapper.selectByPrimaryKey((Integer.valueOf((String) parameters.get("accountId"))));
        if (null == account) {
            return;
        }
        String organization = account.getOrganization();
        //不是摩瑞尔账号的需要根据组织来获取数据权限
        if (!("-1".equals(organization) || "5212b9dfb55448e699889e01fa0fa6a2".equals(organization))) {
        if (!("-1".equals(organization) || ResourceUtil.getValue("orgId").equals(organization))) {
            Set<String> orgIds = organizationService.getChildOrganizationIds(account.getOrganization());
            parameters.put("orgIds", orgIds);
        }
src/main/resources/mapper/HistoryEntityMapper.xml
@@ -306,4 +306,7 @@
            state
    </select>
    <select id="getMacLogByLast" resultType="string">
        SELECT mac_log FROM logger ORDER BY time DESC LIMIT 1
    </select>
</mapper>
src/main/resources/sysConfig.properties
@@ -25,4 +25,5 @@
e16-standard=40
e17-standard=
e18-standard=
e19-standard=
e19-standard=
orgId=5212b9dfb55448e699889e01fa0fa6a2