| | |
| | | if (ObjectUtils.isEmpty(mac) || ObjectUtils.isEmpty(time) || ObjectUtils.isEmpty(type)) {
|
| | | result.put("msg", "参数不能为空!");
|
| | | } else {
|
| | | String[][] exportColumn = new String[][] { |
| | | new String[] { "时间", "20", "time" },
|
| | | new String[] { "Pm2.5", "10", "e1" }, |
| | | new String[] { "Pm10", "20", "e2" },
|
| | | new String[] { "0.1升0.3um量", "30", "e3" }, |
| | | new String[] { "0.1升2.5um量", "10", "e4" },
|
| | | new String[] { "甲醛", "10", "e5" },
|
| | | new String[] { "湿度", "10", "e6" },
|
| | | new String[] { "温度", "10", "e7" },
|
| | | new String[] { "氧气(O2)", "10", "e8" },
|
| | | new String[] { "氯气(CL2)", "10", "e9" },
|
| | | new String[] { "一氧化碳(CO)", "10", "e10" },
|
| | | new String[] { "二氧化硫(SO2)", "10", "e11" },
|
| | | new String[] { "光照", "10", "e12" },
|
| | | new String[] { "噪音", "10", "e13" },
|
| | | new String[] { "氨气(NH3)", "10", "e14" },
|
| | | new String[] { "臭氧(O3)", "10", "e15" },
|
| | | new String[] { "二氧化氮(NO2)", "10", "e16" },
|
| | | new String[] { "挥发性有机气体", "10", "e17" },
|
| | | new String[] { "风速", "10", "e18" },
|
| | | new String[] { "二氧化碳(CO2)", "10", "e19" }
|
| | | };
|
| | | List<Map<String, Object>> sensorsAverage = reportService.getSensorsAverageByEquipment(parameters);
|
| | | if (ObjectUtils.isEmpty(sensorsAverage)) {
|
| | | result.put("msg", "无有效数据");
|
| | | } else {
|
| | | String[][] exportColumn = new String[][] { |
| | | new String[] { "时间", "20", "time" },
|
| | | new String[] { "Pm2.5", "10", "e1" }, |
| | | new String[] { "Pm10", "20", "e2" },
|
| | | new String[] { "0.1升0.3um量", "30", "e3" }, |
| | | new String[] { "0.1升2.5um量", "10", "e4" },
|
| | | new String[] { "甲醛", "10", "e5" },
|
| | | new String[] { "湿度", "10", "e6" },
|
| | | new String[] { "温度", "10", "e7" },
|
| | | new String[] { "氧气(O2)", "10", "e8" },
|
| | | new String[] { "氯气(CL2)", "10", "e9" },
|
| | | new String[] { "一氧化碳(CO)", "10", "e10" },
|
| | | new String[] { "二氧化硫(SO2)", "10", "e11" },
|
| | | new String[] { "光照", "10", "e12" },
|
| | | new String[] { "噪音", "10", "e13" },
|
| | | new String[] { "氨气(NH3)", "10", "e14" },
|
| | | new String[] { "臭氧(O3)", "10", "e15" },
|
| | | new String[] { "二氧化氮(NO2)", "10", "e16" },
|
| | | new String[] { "挥发性有机气体", "10", "e17" },
|
| | | new String[] { "风速", "10", "e18" },
|
| | | new String[] { "二氧化碳(CO2)", "10", "e19" }
|
| | | };
|
| | | OutputStream outputStream = ExportExcelUtils.exportData(response, time + "日" + "设备:" + mac + type + "数据", sensorsAverage, exportColumn);
|
| | | outputStream.flush();
|
| | | outputStream.close();
|
| | | result.put("msg", "成功下载");
|
| | | }
|
| | | }
|
| | | } catch (BusinessException be) {
|
| | |
| | |
|
| | | List<Map<String, Object>> getEquipmentStates(Map<String, Object> parameters);
|
| | |
|
| | | String getMacLogByLast(); |
| | |
|
| | | List<Map<String, Object>> getSensorsAverageByEquipment(Map<String, Object> parameters);
|
| | | } |
| | |
| | |
|
| | | List<AccountEntity> getAccountLists(String account, String password);
|
| | |
|
| | | Map<String, Object> getMonthDataByEquipment(Map<String, Object> parameters);
|
| | | Map<String, Object> getMonthDataByEquipment(Map<String, Object> parameters) throws Exception;
|
| | |
|
| | | Map<String, Object> getAverageByAll(Map<String, Object> parameters);
|
| | |
|
| | |
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.Set;
|
| | | import java.util.concurrent.Callable;
|
| | | import java.util.concurrent.CompletionService;
|
| | | import java.util.concurrent.ExecutorCompletionService;
|
| | | import java.util.concurrent.ExecutorService;
|
| | | import java.util.concurrent.Executors;
|
| | |
|
| | | import org.apache.commons.lang3.StringUtils;
|
| | | import org.apache.commons.lang3.time.DateUtils;
|
| | |
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.util.ObjectUtils;
|
| | |
|
| | | import com.alibaba.fastjson.JSON;
|
| | | import com.moral.monitor.dao.AccountEntityMapper;
|
| | | import com.moral.monitor.dao.HistoryEntityMapper;
|
| | | import com.moral.monitor.entity.AccountEntity;
|
| | |
| | | import com.moral.monitor.util.ResourceUtil;
|
| | |
|
| | | @Service
|
| | | @SuppressWarnings("unused")
|
| | | public class ScreenServiceImpl implements ScreenService {
|
| | |
|
| | | @Autowired
|
| | |
| | | return accountMapper.selectByExample(example);
|
| | | }
|
| | |
|
| | | public Map<String, Object> getMonthDataByEquipment(Map<String, Object> parameters) {
|
| | | public Map<String, Object> getMonthDataByEquipment(final Map<String, Object> parameters) throws Exception {
|
| | | Map<String, Object> resultMap = new HashMap<String, Object>();
|
| | |
|
| | | // 1.0 实际标准值
|
| | | resultMap.put("standard", ResourceUtil.getValue(parameters.get("macKey") + "-standard"));
|
| | |
|
| | | // 2.0 本月平均值
|
| | | // 2.0 AQI 指数
|
| | | Date date = new Date();
|
| | | // 昨日00:00:00
|
| | | parameters.put("start", DateUtils.truncate(DateUtils.addDays(date, -1), Calendar.DATE));
|
| | | // 今日00:00:00
|
| | | parameters.put("end", DateUtils.truncate(date, Calendar.DATE));
|
| | | String[] macKeys = { "e1", "e2", "e10", "e11", "e15", "e16" };
|
| | | final String[] IAQIValues = ResourceUtil.getArrValue("IAQI");
|
| | | ExecutorService threadPool = Executors.newCachedThreadPool();
|
| | | CompletionService<Double> cs = new ExecutorCompletionService<Double>(threadPool);
|
| | | for (final String macKey : macKeys) {
|
| | | cs.submit(new Callable<Double>() {
|
| | | @Override
|
| | | public Double call() throws Exception {
|
| | | Double result = null;
|
| | | double avg = 0, minMacKey = 0, maxMacKey = 0, minIAQI = 0, maxIAQI = 0;
|
| | | Map<String, Object> map = new HashMap<String, Object>(parameters);
|
| | | map.put("macKey", macKey);
|
| | | Map<String, Object> average = historyMapper.getMonthAverageBySensor(map);
|
| | | if (!ObjectUtils.isEmpty(average)) {
|
| | | avg = (Double) average.get("average");
|
| | | String[] macKeyValues = ResourceUtil.getArrValue(macKey);
|
| | | 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) {
|
| | | result = 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]);
|
| | | result = calculateIAQI(maxIAQI, minIAQI, maxMacKey, minMacKey, avg);
|
| | | }
|
| | | }
|
| | | return result;
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | // 3.0 本月平均值
|
| | | Map<String, Object> average = null;
|
| | | Map<String, Object> map = new HashMap<String, Object>(parameters);
|
| | | // 每月一日的数据取上月的数据
|
| | | if (1 == Calendar.getInstance().get(Calendar.DAY_OF_MONTH)) {
|
| | | // 上个月1日00:00:00
|
| | | parameters.put("start", DateUtils.truncate(DateUtils.addMonths(date, -1), Calendar.MONTH));
|
| | | map.put("start", DateUtils.truncate(DateUtils.addMonths(date, -1), Calendar.MONTH));
|
| | | } else {
|
| | | // 这个月1日00:00:00
|
| | | parameters.put("start", DateUtils.truncate(date, Calendar.MONTH));
|
| | | map.put("start", DateUtils.truncate(date, Calendar.MONTH));
|
| | | }
|
| | | // 今日00:00:00
|
| | | parameters.put("end", DateUtils.truncate(date, Calendar.DATE));
|
| | |
|
| | | Map<String, Object> average = null;
|
| | | average = historyMapper.getMonthAverageBySensor(parameters);
|
| | |
|
| | | average = historyMapper.getMonthAverageBySensor(map);
|
| | | if (ObjectUtils.isEmpty(average)) {
|
| | | // 空值临时处理
|
| | | //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 (ObjectUtils.isEmpty(average)) {
|
| | | continue;
|
| | | } else {
|
| | | avg = (Double) average.get("average");
|
| | | }
|
| | | String[] macKeyValues = ResourceUtil.getArrValue(macKey);
|
| | | 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) {
|
| | | 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));
|
| | | }
|
| | | IAQIs.add(cs.take().get());
|
| | | }
|
| | |
|
| | | if (!resultMap.containsKey("AQI")) {
|
| | | if (ObjectUtils.isEmpty(IAQIs)) {
|
| | | resultMap.put("AQI", "N/A");
|
| | | }else {
|
| | | double AQI = Collections.max(IAQIs);
|
| | | // 空值临时处理
|
| | | /*if (AQI == 0.0) {
|
| | | AQI = 60.670;
|
| | | }*/
|
| | | if (ObjectUtils.isEmpty(IAQIs)) {
|
| | | resultMap.put("AQI", "N/A");
|
| | | } 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;
|
| | | }
|
| | |
|
| | |
| | | // 当前时间 -5分钟
|
| | | parameters.put("end", DateUtils.addMinutes(date, -5));
|
| | | List<Map<String, Object>> averageByAll = historyMapper.getAverageByAll(parameters);
|
| | |
|
| | | // 临时方案,空值处理
|
| | | /*if (ObjectUtils.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"));
|
| | |
| | | FROM
|
| | | history
|
| | | WHERE
|
| | | mac = #{mac}
|
| | | AND mac_key = #{macKey}
|
| | | AND time > #{start}
|
| | | AND time < #{end}
|
| | | mac = #{mac,jdbcType=VARCHAR}
|
| | | AND mac_key = #{macKey,jdbcType=VARCHAR}
|
| | | AND time > #{start,jdbcType=TIMESTAMP}
|
| | | AND time < #{end,jdbcType=TIMESTAMP}
|
| | | </select>
|
| | |
|
| | | <select id="getAverageByAll" resultType="map">
|
| | |
| | | </foreach>
|
| | | </if>
|
| | | GROUP BY state
|
| | | </select>
|
| | |
|
| | | <select id="getMacLogByLast" resultType="string">
|
| | | SELECT mac_log FROM logger ORDER BY time DESC LIMIT 1
|
| | | </select>
|
| | |
|
| | | <select id="getSensorsAverageByEquipment" resultType="map">
|