From 15c042a9971766d2fc5f0cc8bc6da2c04df0ed0f Mon Sep 17 00:00:00 2001
From: fengxiang <110431245@qq.com>
Date: Fri, 02 Feb 2018 09:18:12 +0800
Subject: [PATCH] 安全跨域设置
---
src/main/java/com/moral/service/impl/HistoryServiceImpl.java | 124 +++++------------------------------------
1 files changed, 16 insertions(+), 108 deletions(-)
diff --git a/src/main/java/com/moral/service/impl/HistoryServiceImpl.java b/src/main/java/com/moral/service/impl/HistoryServiceImpl.java
index e20f449..2bef76d 100644
--- a/src/main/java/com/moral/service/impl/HistoryServiceImpl.java
+++ b/src/main/java/com/moral/service/impl/HistoryServiceImpl.java
@@ -1,24 +1,18 @@
package com.moral.service.impl;
import static com.moral.common.bean.Constants.NULL_VALUE;
-import static org.apache.commons.lang3.time.DateUtils.addDays;
import static org.apache.commons.lang3.time.DateUtils.addHours;
import static org.apache.commons.lang3.time.DateUtils.addMinutes;
import static org.apache.commons.lang3.time.DateUtils.addMonths;
-import static org.apache.commons.lang3.time.DateUtils.parseDate;
import static org.apache.commons.lang3.time.DateUtils.truncate;
import static org.springframework.util.ObjectUtils.isEmpty;
-import java.text.ParseException;
import java.util.Calendar;
-import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import javax.annotation.Resource;
@@ -29,9 +23,7 @@
import org.springframework.stereotype.Service;
import com.mongodb.BasicDBObject;
-import com.moral.common.exception.BusinessException;
-import com.moral.common.util.CalculateUtils;
-import com.moral.common.util.ResourceUtil;
+import com.moral.common.util.ValidateUtil;
import com.moral.mapper.HistoryMapper;
import com.moral.service.AccountService;
import com.moral.service.HistoryService;
@@ -46,10 +38,13 @@
private HistoryMapper historyMapper;
@Resource
- private MongoTemplate mongoTemplate;
+ private MongoTemplate mongoTemplate;
+
@Override
public Map<String, Object> getAllSensorAverageByDevice(Map<String, Object> parameters) {
+ ValidateUtil.notNull(parameters.get("areaCode"), "param.is.null");
+ ValidateUtil.notNull(parameters.get("accountId"), "param.is.null");
accountService.setOrgIdsByAccount(parameters);
Date date = new Date();
// ������������ -10������
@@ -73,14 +68,17 @@
@Override
public Map<String, Object> getDeviceRankingBySensorAverage(Map<String, Object> parameters) {
- Map<String, Object> result = new LinkedHashMap<String, Object>();
+ ValidateUtil.notNull(parameters.get("areaCode"), "param.is.null");
+ ValidateUtil.notNull(parameters.get("accountId"), "param.is.null");
+ ValidateUtil.notNull(parameters.get("macKey"), "param.is.null");
+ Map<String, Object> result = new LinkedHashMap<String, Object>();
accountService.setOrgIdsByAccount(parameters);
Date date = new Date();
// ������������ -1������
parameters.put("start", addHours(date, -1));
parameters.put("end", date);
- parameters.put("macKey", "'$."+ parameters.get("macKey")+"'");
+ parameters.put("macKey", "'$." + parameters.get("macKey") + "'");
List<Map<String, Object>> list = historyMapper.getAreaAllDataByAccount(parameters);
for (Map<String, Object> map : list) {
@@ -90,66 +88,9 @@
}
@Override
- public Map<String, Object> getDayAQIByDevice(Map<String, Object> parameters) {
- Map<String, Object> resultMap = new HashMap<String, Object>();
- Date date = new Date();
- // ������00:00:00
- parameters.put("start", truncate(addDays(date, -1), Calendar.DATE));
- // ������00:00:00
- parameters.put("end", truncate(date, Calendar.DATE));
- String[] IAQIValues = ResourceUtil.getArrValue("IAQI");
- Map<String, Double> average = historyMapper.getDayAQIByDevice(parameters);
- if (isEmpty(average)) {
- resultMap.put("AQI", NULL_VALUE);
- } else {
- Set<Double> IAQIs = new HashSet<Double>();
- for (Map.Entry<String, Double> entry : average.entrySet()) {
- double minMacKey = 0, maxMacKey = 0, minIAQI = 0, maxIAQI = 0;
- String[] macKeyValues = ResourceUtil.getArrValue(entry.getKey());
- Double avg = entry.getValue();
- if (isEmpty(avg)) {
- IAQIs.add(null);
- } else {
- int index = -1;
- for (int i = 0; i < macKeyValues.length; i++) {
- if (avg <= Double.valueOf(macKeyValues[i])) {
- if (i == 0) {
- index = i;
- } else {
- index = i - 1;
- }
- break;
- }
- }
- if (index == -1) {
- IAQIs.add(Double.MAX_VALUE);
- } else {
- minMacKey = Double.valueOf(macKeyValues[index]);
- maxMacKey = Double.valueOf(macKeyValues[index + 1]);
- minIAQI = Double.valueOf(IAQIValues[index]);
- maxIAQI = Double.valueOf(IAQIValues[index + 1]);
- Double result = CalculateUtils.calculateIAQI(maxIAQI, minIAQI, maxMacKey, minMacKey, avg);
- IAQIs.add(result);
- }
- }
- }
- IAQIs.remove(null);
- if (isEmpty(IAQIs)) {
- resultMap.put("AQI", NULL_VALUE);
- } else {
- Double AQI = Collections.max(IAQIs);
- if (AQI == Double.MAX_VALUE) {
- resultMap.put("AQI", IAQIValues[IAQIValues.length - 1]);
- } else {
- resultMap.put("AQI", String.format("%.0f", AQI));
- }
- }
- }
- return resultMap;
- }
-
- @Override
public Map<String, Object> getMonthAverageBySensor(Map<String, Object> parameters) {
+ ValidateUtil.notNull(parameters.get("mac"), "param.is.null");
+ ValidateUtil.notNull(parameters.get("macKey"), "param.is.null");
Map<String, Object> result = new HashMap<String, Object>();
Date date = new Date();
Long end = truncate(date, Calendar.DATE).getTime(), start;
@@ -159,14 +100,12 @@
start = truncate(addMonths(date, -1), Calendar.MONTH).getTime();
} else {
// ���������1���00:00:00
- start = truncate(date, Calendar.MONTH).getTime();
+ start = truncate(date, Calendar.MONTH).getTime();
}
Aggregation aggregation = Aggregation.newAggregation(
Aggregation.match(Criteria.where("mac").is(parameters.get("mac"))),
- Aggregation.match(Criteria.where("time").gte(start)),
- Aggregation.match(Criteria.where("time").lt(end)),
- Aggregation.group("mac").avg((String) parameters.get("macKey")).as("average")
- );
+ Aggregation.match(Criteria.where("time").gte(start)), Aggregation.match(Criteria.where("time").lt(end)),
+ Aggregation.group("mac").avg((String) parameters.get("macKey")).as("average"));
AggregationResults<BasicDBObject> results = mongoTemplate.aggregate(aggregation, "data", BasicDBObject.class);
List<BasicDBObject> list = results.getMappedResults();
if (isEmpty(list)) {
@@ -178,37 +117,6 @@
return result;
}
- @Override
- public List<Map<String, Object>> getSensorsAverageByDevice4Report(Map<String, Object> parameters,List<Map<String, Object>> sensors) {
- Object type = parameters.get("type");
- if ("hour".equals(type)) {
- parameters.put("type", "%Y-%m-%d %H:00");
- } else if ("minute".equals(type)) {
- parameters.put("type", "%Y-%m-%d %H:%i:00");
- } else {
- throw new BusinessException("type���������������������");
- }
-
- try {
- Date start = parseDate((String)parameters.get("time"), "yyyy-MM-dd");
- parameters.put("start", start);
- parameters.put("end", addDays(start, 1));
- } catch (ParseException e) {
- e.printStackTrace();
- throw new BusinessException("time���������������������");
- }
- String queryColumns = "";
- for (int i = 0; i < sensors.size(); i++) {
- String sensorKey = (String) sensors.get(i).get("key");
- if (i == sensors.size() - 1) {
- queryColumns += "AVG(value -> '$." + sensorKey + "') " + sensorKey;
- } else {
- queryColumns += "AVG(value -> '$." + sensorKey + "') " + sensorKey +",";
- }
- }
- parameters.put("queryColumns", queryColumns);
-
- return historyMapper.getSensorsAverageByDevice4Report(parameters);
- }
+
}
--
Gitblit v1.8.0