From 8a1e35934f5ad3e3febe6168e8eb990a0cd9cadb Mon Sep 17 00:00:00 2001
From: kaiyu <404897439@qq.com>
Date: Thu, 15 Jul 2021 11:55:04 +0800
Subject: [PATCH] Merge branch 'dev' of http://blit.7drlb.com:8888/r/moral into dev
---
screen-common/src/main/java/com/moral/util/DateUtils.java | 18 +
screen-job/src/main/java/com/moral/api/service/impl/HistoryFiveMinutelyServiceImpl.java | 7
screen-api/src/main/java/com/moral/api/controller/WebController.java | 66 ++++++
screen-api/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java | 50 ++++
screen-api/src/main/java/com/moral/api/entity/HistoryHourly.java | 50 ++++
screen-common/src/main/java/com/moral/util/AQIUtils.java | 193 +++++++++++++++++
screen-api/src/main/java/com/moral/api/service/HistoryDailyService.java | 20 +
screen-api/src/main/java/com/moral/api/entity/HistoryDaily.java | 45 ++++
screen-api/src/main/java/com/moral/api/service/impl/HistoryDailyServiceImpl.java | 44 ++++
screen-api/src/main/java/com/moral/api/mapper/HistoryHourlyMapper.java | 16 +
screen-api/src/main/resources/mapper/HistoryDailyMapper.xml | 21 +
screen-api/src/main/java/com/moral/api/mapper/HistoryDailyMapper.java | 20 +
screen-api/src/main/java/com/moral/api/service/HistoryHourlyService.java | 20 +
screen-common/src/main/java/com/moral/constant/Constants.java | 24 ++
screen-api/src/main/resources/mapper/HistoryHourlyMapper.xml | 13 +
screen-common/src/main/java/com/moral/constant/RedisConstants.java | 5
16 files changed, 610 insertions(+), 2 deletions(-)
diff --git a/screen-api/src/main/java/com/moral/api/controller/WebController.java b/screen-api/src/main/java/com/moral/api/controller/WebController.java
new file mode 100644
index 0000000..ae6bf47
--- /dev/null
+++ b/screen-api/src/main/java/com/moral/api/controller/WebController.java
@@ -0,0 +1,66 @@
+package com.moral.api.controller;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import com.moral.api.service.HistoryDailyService;
+import com.moral.api.service.HistoryHourlyService;
+import com.moral.constant.ResponseCodeEnum;
+import com.moral.constant.ResultMessage;
+import com.moral.util.WebUtils;
+
+@Slf4j
+@Api(tags = {"web���������"})
+@RestController
+@RequestMapping("/web")
+public class WebController {
+
+ @Autowired
+ private HistoryHourlyService historyHourlyService;
+
+ @Autowired
+ private HistoryDailyService historyDailyService;
+
+ @GetMapping("getHourlyAqi")
+ @ApiOperation(value = "���������������AQI", notes = "���������������AQI")
+ @ApiImplicitParams(value = {
+ @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
+ @ApiImplicitParam(name = "mac", value = "������mac", required = true, paramType = "query", dataType = "String")
+ })
+ public ResultMessage getHourlyAqi(HttpServletRequest request) {
+ Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
+ if (!params.containsKey("mac")) {
+ return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
+ }
+ Map<String, Object> result = historyHourlyService.getHourlyAqiByMac(params.get("mac").toString());
+ return ResultMessage.ok(result);
+ }
+
+ @GetMapping("getMonthAvg")
+ @ApiOperation(value = "������������������������������������", notes = "������������������������������������")
+ @ApiImplicitParams(value = {
+ @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"),
+ @ApiImplicitParam(name = "mac", value = "������mac", required = true, paramType = "query", dataType = "String"),
+ @ApiImplicitParam(name = "sensorCode", value = "������code", required = true, paramType = "query", dataType = "String")
+ })
+ public ResultMessage getMonthAvg(HttpServletRequest request) {
+ Map<String, Object> params = WebUtils.getParametersStartingWith(request, null);
+ if (!params.containsKey("mac") || !params.containsKey("sensorCode")) {
+ return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
+ }
+ Map<String, Object> result = historyDailyService.getMonthAvg(params);
+ return ResultMessage.ok(result);
+ }
+
+}
diff --git a/screen-api/src/main/java/com/moral/api/entity/HistoryDaily.java b/screen-api/src/main/java/com/moral/api/entity/HistoryDaily.java
new file mode 100644
index 0000000..c6b463b
--- /dev/null
+++ b/screen-api/src/main/java/com/moral/api/entity/HistoryDaily.java
@@ -0,0 +1,45 @@
+package com.moral.api.entity;
+
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import java.io.Serializable;
+import java.util.Date;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * <p>
+ * ���������
+ * </p>
+ *
+ * @author moral
+ * @since 2021-07-14
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class HistoryDaily extends Model<HistoryDaily> {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * ������mac
+ */
+ private String mac;
+
+ /**
+ * ������
+ */
+ private Date time;
+
+ /**
+ * ������
+ */
+ private String value;
+
+
+ @Override
+ protected Serializable pkVal() {
+ return null;
+ }
+
+}
diff --git a/screen-api/src/main/java/com/moral/api/entity/HistoryHourly.java b/screen-api/src/main/java/com/moral/api/entity/HistoryHourly.java
new file mode 100644
index 0000000..efa413c
--- /dev/null
+++ b/screen-api/src/main/java/com/moral/api/entity/HistoryHourly.java
@@ -0,0 +1,50 @@
+package com.moral.api.entity;
+
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import java.io.Serializable;
+import java.util.Date;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * <p>
+ * ������������������
+ * </p>
+ *
+ * @author moral
+ * @since 2021-07-14
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class HistoryHourly extends Model<HistoryHourly> {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * ������mac
+ */
+ private String mac;
+
+ /**
+ * ������������
+ */
+ private Date time;
+
+ /**
+ * ������
+ */
+ private String value;
+
+ /**
+ * ������
+ */
+ private Integer version;
+
+
+ @Override
+ protected Serializable pkVal() {
+ return null;
+ }
+
+}
diff --git a/screen-api/src/main/java/com/moral/api/mapper/HistoryDailyMapper.java b/screen-api/src/main/java/com/moral/api/mapper/HistoryDailyMapper.java
new file mode 100644
index 0000000..35614f0
--- /dev/null
+++ b/screen-api/src/main/java/com/moral/api/mapper/HistoryDailyMapper.java
@@ -0,0 +1,20 @@
+package com.moral.api.mapper;
+
+import java.util.Map;
+
+import com.moral.api.entity.HistoryDaily;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ * ��������� Mapper ������
+ * </p>
+ *
+ * @author moral
+ * @since 2021-07-14
+ */
+public interface HistoryDailyMapper extends BaseMapper<HistoryDaily> {
+
+ Map<String, Object> getAvgByMac(Map<String, Object> params);
+
+}
diff --git a/screen-api/src/main/java/com/moral/api/mapper/HistoryHourlyMapper.java b/screen-api/src/main/java/com/moral/api/mapper/HistoryHourlyMapper.java
new file mode 100644
index 0000000..ec74607
--- /dev/null
+++ b/screen-api/src/main/java/com/moral/api/mapper/HistoryHourlyMapper.java
@@ -0,0 +1,16 @@
+package com.moral.api.mapper;
+
+import com.moral.api.entity.HistoryHourly;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ * ������������������ Mapper ������
+ * </p>
+ *
+ * @author moral
+ * @since 2021-07-14
+ */
+public interface HistoryHourlyMapper extends BaseMapper<HistoryHourly> {
+
+}
diff --git a/screen-api/src/main/java/com/moral/api/service/HistoryDailyService.java b/screen-api/src/main/java/com/moral/api/service/HistoryDailyService.java
new file mode 100644
index 0000000..15d62eb
--- /dev/null
+++ b/screen-api/src/main/java/com/moral/api/service/HistoryDailyService.java
@@ -0,0 +1,20 @@
+package com.moral.api.service;
+
+import java.util.Map;
+
+import com.moral.api.entity.HistoryDaily;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * <p>
+ * ��������� ���������
+ * </p>
+ *
+ * @author moral
+ * @since 2021-07-14
+ */
+public interface HistoryDailyService extends IService<HistoryDaily> {
+
+ Map<String, Object> getMonthAvg(Map<String, Object> params);
+
+}
diff --git a/screen-api/src/main/java/com/moral/api/service/HistoryHourlyService.java b/screen-api/src/main/java/com/moral/api/service/HistoryHourlyService.java
new file mode 100644
index 0000000..241a855
--- /dev/null
+++ b/screen-api/src/main/java/com/moral/api/service/HistoryHourlyService.java
@@ -0,0 +1,20 @@
+package com.moral.api.service;
+
+import java.util.Map;
+
+import com.moral.api.entity.HistoryHourly;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * <p>
+ * ������������������ ���������
+ * </p>
+ *
+ * @author moral
+ * @since 2021-07-14
+ */
+public interface HistoryHourlyService extends IService<HistoryHourly> {
+
+ Map<String,Object> getHourlyAqiByMac(String mac);
+
+}
diff --git a/screen-api/src/main/java/com/moral/api/service/impl/HistoryDailyServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/HistoryDailyServiceImpl.java
new file mode 100644
index 0000000..5c1316e
--- /dev/null
+++ b/screen-api/src/main/java/com/moral/api/service/impl/HistoryDailyServiceImpl.java
@@ -0,0 +1,44 @@
+package com.moral.api.service.impl;
+
+import com.moral.api.entity.HistoryDaily;
+import com.moral.api.mapper.HistoryDailyMapper;
+import com.moral.api.service.HistoryDailyService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.moral.constant.Constants;
+import com.moral.util.DateUtils;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.ObjectUtils;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * <p>
+ * ��������� ���������������
+ * </p>
+ *
+ * @author moral
+ * @since 2021-07-14
+ */
+@Service
+public class HistoryDailyServiceImpl extends ServiceImpl<HistoryDailyMapper, HistoryDaily> implements HistoryDailyService {
+
+ @Autowired
+ private HistoryDailyMapper historyDailyMapper;
+
+ @Override
+ public Map<String, Object> getMonthAvg(Map<String, Object> params) {
+ params.put("start", DateUtils.getFirstDayOfCurrMonth());
+ params.put("end", DateUtils.getLastDayOfCurrMonth());
+ Map<String, Object> data = historyDailyMapper.getAvgByMac(params);
+ Map<String, Object> result = new HashMap<>();
+ if (ObjectUtils.isEmpty(data)) {
+ result.put("avg", Constants.NULL_VALUE);
+ return result;
+ }
+ result.put("avg", data.get(params.get("sensorCode")));
+ return result;
+ }
+}
diff --git a/screen-api/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java
new file mode 100644
index 0000000..b64554c
--- /dev/null
+++ b/screen-api/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java
@@ -0,0 +1,50 @@
+package com.moral.api.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.moral.api.entity.HistoryHourly;
+import com.moral.api.mapper.HistoryHourlyMapper;
+import com.moral.api.service.HistoryHourlyService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.moral.constant.Constants;
+import com.moral.util.AQIUtils;
+import com.moral.util.DateUtils;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * <p>
+ * ������������������ ���������������
+ * </p>
+ *
+ * @author moral
+ * @since 2021-07-14
+ */
+@Service
+public class HistoryHourlyServiceImpl extends ServiceImpl<HistoryHourlyMapper, HistoryHourly> implements HistoryHourlyService {
+
+ @Autowired
+ private HistoryHourlyMapper historyHourlyMapper;
+
+ @Override
+ public Map<String, Object> getHourlyAqiByMac(String mac) {
+ QueryWrapper<HistoryHourly> queryWrapper = new QueryWrapper<>();
+ String time = DateUtils.dateToDateString(new Date(), DateUtils.yyyy_MM_dd_HH_EN) + ":00:00";
+ queryWrapper.eq("mac", mac).eq("time", time);
+ //������������������
+ HistoryHourly historyHourly = historyHourlyMapper.selectOne(queryWrapper);
+ Map<String, Object> result = new HashMap<>();
+ if (historyHourly == null) {
+ result.put("AQI", Constants.NULL_VALUE);
+ return result;
+ }
+ Map<String, Object> data = JSONObject.parseObject(historyHourly.getValue(), Map.class);
+ result.put("AQI", AQIUtils.hourlyAqi(data));
+ return result;
+ }
+}
diff --git a/screen-api/src/main/resources/mapper/HistoryDailyMapper.xml b/screen-api/src/main/resources/mapper/HistoryDailyMapper.xml
new file mode 100644
index 0000000..a54c78b
--- /dev/null
+++ b/screen-api/src/main/resources/mapper/HistoryDailyMapper.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.moral.api.mapper.HistoryDailyMapper">
+
+ <!-- ������������������������ -->
+ <resultMap id="BaseResultMap" type="com.moral.api.entity.HistoryDaily">
+ <result column="mac" property="mac"/>
+ <result column="time" property="time"/>
+ <result column="value" property="value"/>
+ </resultMap>
+
+ <select id="getAvgByMac" resultType="java.util.Map">
+ SELECT
+ AVG(`value` ->'$.${sensorCode}') AS '${sensorCode}'
+ FROM history_daily
+ WHERE mac = #{mac}
+ AND time <![CDATA[>=]]> #{start}
+ AND time <![CDATA[<=]]> #{end}
+ </select>
+
+</mapper>
\ No newline at end of file
diff --git a/screen-api/src/main/resources/mapper/HistoryHourlyMapper.xml b/screen-api/src/main/resources/mapper/HistoryHourlyMapper.xml
new file mode 100644
index 0000000..90af3f8
--- /dev/null
+++ b/screen-api/src/main/resources/mapper/HistoryHourlyMapper.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.moral.api.mapper.HistoryHourlyMapper">
+
+ <!-- ������������������������ -->
+ <resultMap id="BaseResultMap" type="com.moral.api.entity.HistoryHourly">
+ <result column="mac" property="mac"/>
+ <result column="time" property="time"/>
+ <result column="value" property="value"/>
+ <result column="version" property="version"/>
+ </resultMap>
+
+</mapper>
\ No newline at end of file
diff --git a/screen-common/src/main/java/com/moral/constant/Constants.java b/screen-common/src/main/java/com/moral/constant/Constants.java
index 6351a17..246e402 100644
--- a/screen-common/src/main/java/com/moral/constant/Constants.java
+++ b/screen-common/src/main/java/com/moral/constant/Constants.java
@@ -153,4 +153,28 @@
* ������������code
* */
public static final String SENSOR_CODE_CO= "a21005";
+
+ /*
+ * PM2.5 code
+ * */
+ public static final String SENSOR_CODE_PM25= "a34004";
+
+ /*
+ * PM10 code
+ * */
+ public static final String SENSOR_CODE_PM10= "a34002";
+
+ /*
+ * SO2 code
+ * */
+ public static final String SENSOR_CODE_SO2= "a21026";
+
+ /*
+ * NO2 code
+ * */
+ public static final String SENSOR_CODE_NO2= "a21004";
+
+ /** The Constant NULL_VALUE. */
+ public static final String NULL_VALUE = "N/V";
+
}
diff --git a/screen-common/src/main/java/com/moral/constant/RedisConstants.java b/screen-common/src/main/java/com/moral/constant/RedisConstants.java
index 40ad154..25c36a2 100644
--- a/screen-common/src/main/java/com/moral/constant/RedisConstants.java
+++ b/screen-common/src/main/java/com/moral/constant/RedisConstants.java
@@ -64,5 +64,10 @@
* */
public static final String UNIT_CONVERSION = "unit_conversion";
+ /*
+ * redis���5������������key
+ * */
+ public static final String DATA_FIVE_MINUTES = "data_five_minutes";
+
}
diff --git a/screen-common/src/main/java/com/moral/util/AQIUtils.java b/screen-common/src/main/java/com/moral/util/AQIUtils.java
new file mode 100644
index 0000000..70cddb2
--- /dev/null
+++ b/screen-common/src/main/java/com/moral/util/AQIUtils.java
@@ -0,0 +1,193 @@
+package com.moral.util;
+
+import org.springframework.util.ObjectUtils;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import com.moral.constant.Constants;
+
+public class AQIUtils {
+ public static int hourlyAqi(Map<String, Object> map) {
+ List<Integer> AQIList = new ArrayList<>();
+ for (Map.Entry<String, Object> entry : map.entrySet()) {
+ String key = entry.getKey();
+ if (entry.getValue().toString().equals("")) {
+ continue;
+ }
+ int PM2_5AQI;
+ int PM10AQI;
+ int SO2AQI;
+ int NO2AQI;
+ int COAQI;
+ int O3AQI;
+ switch (key) {
+ case Constants.SENSOR_CODE_PM25:
+ PM2_5AQI = PM2_5AQI(Double.valueOf(entry.getValue().toString()));
+ AQIList.add(PM2_5AQI);
+ break;
+ case Constants.SENSOR_CODE_PM10:
+ PM10AQI = PM10AQI(Double.valueOf(entry.getValue().toString()));
+ AQIList.add(PM10AQI);
+ break;
+ case Constants.SENSOR_CODE_SO2:
+ SO2AQI = SO2AQI(Double.valueOf(entry.getValue().toString()));
+ AQIList.add(SO2AQI);
+ break;
+ case Constants.SENSOR_CODE_NO2:
+ NO2AQI = NO2AQI(Double.valueOf(entry.getValue().toString()));
+ AQIList.add(NO2AQI);
+ break;
+ case Constants.SENSOR_CODE_CO:
+ COAQI = COAQI(Double.valueOf(entry.getValue().toString()));
+ AQIList.add(COAQI);
+ break;
+ case Constants.SENSOR_CODE_O3:
+ O3AQI = O3AQI(Double.valueOf(entry.getValue().toString()));
+ AQIList.add(O3AQI);
+ break;
+ default:
+ break;
+ }
+ }
+ int AQIMAX = 0;
+ if (!ObjectUtils.isEmpty(AQIList)) {
+ AQIMAX = Collections.max(AQIList);
+ }
+ return AQIMAX;
+ }
+
+ //PM2.5 IAQI
+ public static int PM2_5AQI(Double value) {
+ double result;
+ if (value <= 0) {
+ result = 0;
+ } else if (value <= 35) {
+ result = 50d / 35d * (value - 0) + 0;
+ } else if (value <= 75) {
+ result = 50d / 40d * (value - 35) + 50;
+ } else if (value <= 115) {
+ result = 50d / 40d * (value - 75) + 100;
+ } else if (value <= 150) {
+ result = 50d / 35d * (value - 115) + 150;
+ } else if (value <= 250) {
+ result = 100d / 100d * (value - 150) + 200;
+ } else if (value <= 350) {
+ result = 100d / 100d * (value - 250) + 300;
+ } else {
+ result = 100d / 150d * (value - 350) + 400;
+ }
+ return (int) Math.ceil(result);
+ }
+
+ //PM10 IAQI
+ public static int PM10AQI(Double value) {
+ double result;
+ if (value <= 0) {
+ result = 0;
+ } else if (value <= 50) {
+ result = 50d / 50d * (value - 0) + 0;
+ } else if (value <= 150) {
+ result = 50d / 100d * (value - 50) + 50;
+ } else if (value <= 250) {
+ result = 50d / 100d * (value - 150) + 100;
+ } else if (value <= 350) {
+ result = 50d / 100d * (value - 250) + 150;
+ } else if (value <= 420) {
+ result = 100d / 70d * (value - 350) + 200;
+ } else if (value <= 500) {
+ result = 100d / 80d * (value - 420) + 300;
+ } else {
+ result = 100d / 100d * (value - 500) + 400;
+ }
+ return (int) Math.ceil(result);
+ }
+
+ //SO2 IAQI
+ public static int SO2AQI(Double value) {
+ double result;
+ if (value <= 0) {
+ result = 0;
+ } else if (value <= 150) {
+ result = 50d / 150d * (value - 0) + 0;
+ } else if (value <= 500) {
+ result = 50d / 350d * (value - 150) + 50;
+ } else if (value <= 650) {
+ result = 50d / 150d * (value - 500) + 100;
+ } else {
+ result = 50d / 150d * (value - 650) + 150;
+ }
+ return (int) Math.ceil(result);
+ }
+
+ //NO2 IAQI
+ public static int NO2AQI(Double value) {
+ double result;
+ if (value <= 0) {
+ result = 0;
+ } else if (value <= 100) {
+ result = 50d / 100d * (value - 0) + 0;
+ } else if (value <= 200) {
+ result = 50d / 100d * (value - 100) + 50;
+ } else if (value <= 700) {
+ result = 50d / 500d * (value - 200) + 100;
+ } else if (value <= 1200) {
+ result = 50d / 500d * (value - 700) + 150;
+ } else if (value <= 2340) {
+ result = 100d / 1140d * (value - 1200) + 200;
+ } else if (value <= 3090) {
+ result = 100d / 750d * (value - 2340) + 300;
+ } else {
+ result = 100d / 750d * (value - 3090) + 400;
+ }
+ return (int) Math.ceil(result);
+ }
+
+ //CO IAQI
+ public static int COAQI(Double value) {
+ double result;
+ if (value <= 0) {
+ result = 0;
+ } else if (value <= 5) {
+ result = 50d / 5d * (value - 0) + 0;
+ } else if (value <= 10) {
+ result = 50d / 5d * (value - 5) + 50;
+ } else if (value <= 35) {
+ result = 50d / 25d * (value - 10) + 100;
+ } else if (value <= 60) {
+ result = 50d / 25d * (value - 35) + 150;
+ } else if (value <= 90) {
+ result = 100d / 30d * (value - 60) + 200;
+ } else if (value <= 120) {
+ result = 100d / 30d * (value - 90) + 300;
+ } else {
+ result = 100d / 30d * (value - 120) + 400;
+ }
+ return (int) Math.ceil(result);
+ }
+
+ //O3 IAQI
+ public static int O3AQI(Double value) {
+ double result;
+ if (value <= 0) {
+ result = 0;
+ } else if (value <= 100) {
+ result = 50d / 100d * (value - 0) + 0;
+ } else if (value <= 160) {
+ result = 50d / 60d * (value - 100) + 50;
+ } else if (value <= 215) {
+ result = 50d / 55d * (value - 160) + 100;
+ } else if (value <= 265) {
+ result = 50d / 150d * (value - 215) + 150;
+ } else if (value <= 800) {
+ result = 100d / 535d * (value - 265) + 200;
+ } else if (value <= 2100) {
+ result = 100d / 12d * (value - 800) + 300;
+ } else {
+ result = 100d / 12d * (value - 48) + 400;
+ }
+ return (int) Math.ceil(result);
+ }
+}
diff --git a/screen-common/src/main/java/com/moral/util/DateUtils.java b/screen-common/src/main/java/com/moral/util/DateUtils.java
index 5fde952..1d777ef 100644
--- a/screen-common/src/main/java/com/moral/util/DateUtils.java
+++ b/screen-common/src/main/java/com/moral/util/DateUtils.java
@@ -761,6 +761,17 @@
}
/**
+ * ������������������������
+ *
+ * @return
+ */
+ public static Date getFirstDayOfCurrMonth() {
+ Calendar cal = Calendar.getInstance();
+ cal.set(Calendar.DAY_OF_MONTH, 1);
+ return getDate(dateToDateString(cal.getTime(), yyyy_MM_dd_EN));
+ }
+
+ /**
* ������������������������������
*
* @return
@@ -769,8 +780,7 @@
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MONTH, 1);
cal.set(Calendar.DAY_OF_MONTH, 0);
-
- return cal.getTime();
+ return getDate(dateToDateString(cal.getTime(), yyyy_MM_dd_EN));
}
/**
@@ -1326,4 +1336,8 @@
calendar.set(Calendar.DAY_OF_MONTH, 1);
return getDate(dateToDateString(calendar.getTime(), yyyy_MM_dd_EN));
}
+
+ public static void main(String[] args) {
+ System.out.println(getFirstDayOfCurrMonth());
+ }
}
diff --git a/screen-job/src/main/java/com/moral/api/service/impl/HistoryFiveMinutelyServiceImpl.java b/screen-job/src/main/java/com/moral/api/service/impl/HistoryFiveMinutelyServiceImpl.java
index 4fc7ac3..368cfb5 100644
--- a/screen-job/src/main/java/com/moral/api/service/impl/HistoryFiveMinutelyServiceImpl.java
+++ b/screen-job/src/main/java/com/moral/api/service/impl/HistoryFiveMinutelyServiceImpl.java
@@ -1,6 +1,7 @@
package com.moral.api.service.impl;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
@@ -22,6 +23,7 @@
import com.moral.api.service.HistoryMinutelyService;
import com.moral.api.service.SensorService;
import com.moral.constant.Constants;
+import com.moral.constant.RedisConstants;
import com.moral.util.AmendUtils;
import com.moral.util.DateUtils;
@@ -41,6 +43,9 @@
public void createTable(String timeUnits) {
historyFiveMinutelyMapper.createTable(timeUnits);
}
+
+ @Autowired
+ private RedisTemplate redisTemplate;
@Override
@Transactional
@@ -111,6 +116,8 @@
}
});
dataMap.put("value", JSONObject.toJSONString(jsonMap));
+ //������redis
+ redisTemplate.opsForHash().put(RedisConstants.DATA_FIVE_MINUTES, key, jsonMap);
insertData.add(dataMap);
});
--
Gitblit v1.8.0