| | |
| | | import java.util.Map;
|
| | | import java.util.Set;
|
| | |
|
| | | import org.apache.commons.collections4.CollectionUtils;
|
| | | import org.apache.commons.collections4.MapUtils;
|
| | | import org.apache.commons.lang3.StringUtils;
|
| | | import org.apache.commons.lang3.time.DateUtils;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | |
| | | Date date = new Date();
|
| | | // 每月一日的数据取上月的数据
|
| | | if (1 == Calendar.getInstance().get(Calendar.DAY_OF_MONTH)) {
|
| | | // 上个月1日00:00:00
|
| | | parameters.put("start", DateUtils.truncate(DateUtils.addMonths(date, -1), Calendar.MONTH));
|
| | | } else {
|
| | | // 这个月1日00:00:00
|
| | | parameters.put("start", DateUtils.truncate(date, Calendar.MONTH));
|
| | | }
|
| | | parameters.put("start", DateUtils.truncate(date, Calendar.MONTH));
|
| | | // 今日00:00:00
|
| | | parameters.put("end", DateUtils.truncate(date, Calendar.DATE));
|
| | |
|
| | | Map<String, Object> average = historyMapper.getMonthAverageBySensor(parameters);
|
| | | Map<String, Object> average = null;
|
| | | average = historyMapper.getMonthAverageBySensor(parameters);
|
| | |
|
| | | if (MapUtils.isNotEmpty(average)) {
|
| | | resultMap.putAll(average);
|
| | | } else {
|
| | | if (ObjectUtils.isEmpty(average)) {
|
| | | // 空值临时处理
|
| | | resultMap.put("average", 90.0384 + Calendar.getInstance().get(Calendar.DAY_OF_MONTH) / 5);
|
| | | //resultMap.put("average", 50.3467 + Calendar.getInstance().get(Calendar.DAY_OF_MONTH) / 5);
|
| | | resultMap.put("average", "N/A");
|
| | | } else {
|
| | | //resultMap.putAll(average);
|
| | | //resultMap.put("average", String.format("%.2f", resultMap.get("average")));
|
| | | resultMap.put("average", String.format("%.2f", average.get("average")));
|
| | | }
|
| | |
|
| | | |
| | | // 3.0 AQI 指数
|
| | | String[] macKeys = { "e1", "e2", "e10", "e11", "e15", "e16" };
|
| | | String[] IAQIValues = ResourceUtil.getArrValue("IAQI");
|
| | | List<Double> IAQIs = new ArrayList<Double>();
|
| | | // 昨日00:00:00
|
| | | parameters.put("start", DateUtils.truncate(DateUtils.addDays(date, -1), Calendar.DATE));
|
| | | for (String macKey : macKeys) {
|
| | | double avg = 0, minMacKey = 0, maxMacKey = 0, minIAQI = 0, maxIAQI = 0;
|
| | | parameters.put("macKey", macKey);
|
| | | average = historyMapper.getMonthAverageBySensor(parameters);
|
| | | if (MapUtils.isNotEmpty(average)) {
|
| | | if (ObjectUtils.isEmpty(average)) {
|
| | | continue;
|
| | | } else {
|
| | | avg = (Double) average.get("average");
|
| | | }
|
| | | String[] macKeyValues = ResourceUtil.getArrValue(macKey);
|
| | |
| | | } else {
|
| | | index = i - 1;
|
| | | }
|
| | | continue;
|
| | | break;
|
| | | }
|
| | | }
|
| | | if (index == -1) {
|
| | |
| | | IAQIs.add(calculateIAQI(maxIAQI, minIAQI, maxMacKey, minMacKey, avg));
|
| | | }
|
| | | }
|
| | | |
| | | if (!resultMap.containsKey("AQI")) {
|
| | | resultMap.put("AQI", Collections.max(IAQIs));
|
| | | if (ObjectUtils.isEmpty(IAQIs)) {
|
| | | resultMap.put("AQI", "N/A");
|
| | | }else {
|
| | | double AQI = Collections.max(IAQIs);
|
| | | // 空值临时处理
|
| | | /*if (AQI == 0.0) {
|
| | | AQI = 60.670;
|
| | | }*/
|
| | | resultMap.put("AQI", String.format("%.0f", AQI));
|
| | | }
|
| | | }
|
| | |
|
| | | |
| | | return resultMap;
|
| | | }
|
| | |
|
| | |
| | | Map<String, Object> result = new LinkedHashMap<String, Object>();
|
| | |
|
| | | setOrgIdsByAccount(parameters);
|
| | |
|
| | | parameters.put("macKey", "all");
|
| | | Date date = new Date();
|
| | | // 当前时间 -10分钟
|
| | | parameters.put("start", DateUtils.addMinutes(date, -10));
|
| | | // 当前时间 -5分钟
|
| | | parameters.put("end", DateUtils.addMinutes(date, -5));
|
| | | List<Map<String, Object>> averageByAll = historyMapper.getAverageByAll(parameters);
|
| | |
|
| | | // 临时方案,空值处理
|
| | | if (CollectionUtils.isEmpty(averageByAll)) {
|
| | | /*if (ObjectUtils.isEmpty(averageByAll)) {
|
| | | String macLog = historyMapper.getMacLogByLast();
|
| | | if (StringUtils.isNotBlank(macLog)) {
|
| | | Map<String, Object> map = JSON.parseObject(macLog);
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }*/
|
| | |
|
| | | for (Map<String, Object> map : averageByAll) {
|
| | | result.put((String) map.get("mac_key"), map.get("avg"));
|
| | |
| | | if (ObjectUtils.isEmpty(account)) {
|
| | | throw new BusinessException(accountId + "该账号不存在!");
|
| | | }
|
| | | String organization = account.getOrganization();
|
| | | String orgId = account.getOrganization();
|
| | | // 不是摩瑞尔账号的需要根据组织来获取数据权限
|
| | | if (!("-1".equals(organization) || ResourceUtil.getValue("orgId").equals(organization))) {
|
| | | Set<String> orgIds = organizationService.getChildOrganizationIds(account.getOrganization());
|
| | | |
| | | if (!("-1".equals(orgId) || ResourceUtil.getValue("orgId").equals(orgId))) {
|
| | | Set<String> orgIds = organizationService.getChildOrganizationIds(orgId);
|
| | | parameters.put("orgIds", orgIds);
|
| | | }
|
| | | }
|
| | |
| | | return (maxIAQI - minIAQI) * (avg - minMacKey) / (maxMacKey - minMacKey) + minIAQI;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public Map<String, Object> getAverageBySensor(Map<String, Object> parameters) {
|
| | | Map<String, Object> result = new LinkedHashMap<String, Object>();
|
| | |
|
| | | setOrgIdsByAccount(parameters);
|
| | | Date date = new Date();
|
| | | // 当前时间 -1小时
|
| | | parameters.put("start", DateUtils.addHours(date, -1));
|
| | | parameters.put("end", date);
|
| | | List<Map<String, Object>> averageByAll = historyMapper.getAverageByAll(parameters);
|
| | |
|
| | | for (Map<String, Object> map : averageByAll) {
|
| | | result.put((String) map.get("name"), map.get("avg"));
|
| | | }
|
| | | return result;
|
| | | }
|
| | |
|
| | | }
|