|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public Map<String, Object> getMonthDataByEquipment(Map<String, Object> parameters) { | 
|---|
|  |  |  | Map<String, Object> resultMap = new HashMap<String, Object>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 1.0 实际标准值 | 
|---|
|  |  |  | resultMap.put("standard", ResourceUtil.getValue(parameters.get("macKey") + "-standard")); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 2.0 本月平均值 | 
|---|
|  |  |  | Date date = new Date(); | 
|---|
|  |  |  | //每月一日的数据取上月的数据 | 
|---|
|  |  |  | // 每月一日的数据取上月的数据 | 
|---|
|  |  |  | if (1 == Calendar.getInstance().get(Calendar.DAY_OF_MONTH)) { | 
|---|
|  |  |  | parameters.put("start", DateUtils.truncate(DateUtils.addMonths(date, -1), Calendar.MONTH)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | parameters.put("start", DateUtils.truncate(date, Calendar.MONTH)); | 
|---|
|  |  |  | parameters.put("end", DateUtils.truncate(date, Calendar.DATE)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // | 
|---|
|  |  |  | parameters.put("mac", "898602b8191630065884"); | 
|---|
|  |  |  | parameters.put("macKey", "e1"); | 
|---|
|  |  |  | Map<String, Object> average = historyMapper.getMonthAverageBySensor(parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 本月平均值 | 
|---|
|  |  |  | if (MapUtils.isNotEmpty(average)) { | 
|---|
|  |  |  | resultMap.putAll(average); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | // 空值临时处理 | 
|---|
|  |  |  | resultMap.put("average", 90.0384 + Calendar.getInstance().get(Calendar.DAY_OF_MONTH) / 5); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //AQI 指数 | 
|---|
|  |  |  | // 3.0 AQI 指数 | 
|---|
|  |  |  | String[] macKeys = { "e1", "e2", "e10", "e11", "e15", "e16" }; | 
|---|
|  |  |  | String[] IAQIValues = ResourceUtil.getArrValue("IAQI"); | 
|---|
|  |  |  | List<Double> IAQIs = new ArrayList<Double>(); | 
|---|
|  |  |  | parameters.put("start", DateUtils.truncate(DateUtils.addDays(date, -1), Calendar.DATE)); | 
|---|
|  |  |  | for (String macKey : macKeys) { | 
|---|
|  |  |  | double avg = 0, maxMacKey = 0, minMacKey = 0; | 
|---|
|  |  |  | double avg = 0, minMacKey = 0, maxMacKey = 0, minIAQI = 0, maxIAQI = 0; | 
|---|
|  |  |  | parameters.put("macKey", macKey); | 
|---|
|  |  |  | parameters.put("start", DateUtils.truncate(DateUtils.addDays(date, -1), Calendar.DATE)); | 
|---|
|  |  |  | average = historyMapper.getMonthAverageBySensor(parameters); | 
|---|
|  |  |  | if (MapUtils.isNotEmpty(average)) { | 
|---|
|  |  |  | avg = (Double) average.get("average"); | 
|---|
|  |  |  | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | index = i - 1; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | minMacKey = Double.valueOf(macKeyValues[index]); | 
|---|
|  |  |  | maxMacKey = Double.valueOf(macKeyValues[index + 1]); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (index == -1) { | 
|---|
|  |  |  | resultMap.put("AQI", ">500"); | 
|---|
|  |  |  | resultMap.put("AQI", IAQIValues[IAQIValues.length - 1]); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | minMacKey = Double.valueOf(macKeyValues[index]); | 
|---|
|  |  |  | maxMacKey = Double.valueOf(macKeyValues[index + 1]); | 
|---|
|  |  |  | minIAQI = Double.valueOf(IAQIValues[index]); | 
|---|
|  |  |  | maxIAQI = Double.valueOf(IAQIValues[index + 1]); | 
|---|
|  |  |  | IAQIs.add(calculateIAQI(maxIAQI, minIAQI, maxMacKey, minMacKey, avg)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | double minIAQI = Double.valueOf(IAQIValues[index]); | 
|---|
|  |  |  | double maxIAQI = Double.valueOf(IAQIValues[index + 1]); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | IAQIs.add(calculateIAQI(maxIAQI, minIAQI, maxMacKey, minMacKey, avg)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!resultMap.containsKey("AQI")) { | 
|---|
|  |  |  | resultMap.put("AQI", Collections.max(IAQIs)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //实际标准值 | 
|---|
|  |  |  | resultMap.put("standard", ResourceUtil.getValue(parameters.get("macKey")+"-standard")); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | 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)){ | 
|---|
|  |  |  | if (StringUtils.isNotBlank(macLog)) { | 
|---|
|  |  |  | Map<String, Object> map = JSON.parseObject(macLog); | 
|---|
|  |  |  | for (String key : map.keySet()) { | 
|---|
|  |  |  | if (key.startsWith("e")) { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (Map<String, Object> map : averageByAll) { | 
|---|
|  |  |  | result.put((String) map.get("mac_key"), map.get("avg")); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void setOrgIdsByAccount(Map<String, Object> parameters) { | 
|---|
|  |  |  | String accountId = (String) parameters.get("accountId"); | 
|---|
|  |  |  | if (!StringUtils.isNumeric((String)parameters.get("accountId")) ) { | 
|---|
|  |  |  | if (!StringUtils.isNumeric((String) parameters.get("accountId"))) { | 
|---|
|  |  |  | throw new BusinessException("accountId 参数不合法!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AccountEntity account = accountMapper.selectByPrimaryKey((Integer.valueOf(accountId))); | 
|---|
|  |  |  | if (ObjectUtils.isEmpty(account)) { | 
|---|
|  |  |  | throw new BusinessException(accountId +"该账号不存在!"); | 
|---|
|  |  |  | throw new BusinessException(accountId + "该账号不存在!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String organization = account.getOrganization(); | 
|---|
|  |  |  | //不是摩瑞尔账号的需要根据组织来获取数据权限 | 
|---|
|  |  |  | // 不是摩瑞尔账号的需要根据组织来获取数据权限 | 
|---|
|  |  |  | if (!("-1".equals(organization) || ResourceUtil.getValue("orgId").equals(organization))) { | 
|---|
|  |  |  | Set<String> orgIds = organizationService.getChildOrganizationIds(account.getOrganization()); | 
|---|
|  |  |  | parameters.put("orgIds", orgIds); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private double calculateIAQI(double maxIAQI, double minIAQI, double maxMacKey, double minMacKey,double avg) { | 
|---|
|  |  |  | private double calculateIAQI(double maxIAQI, double minIAQI, double maxMacKey, double minMacKey, double avg) { | 
|---|
|  |  |  | return (maxIAQI - minIAQI) * (avg - minMacKey) / (maxMacKey - minMacKey) + minIAQI; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|