From 995a527d6e7d2d0cb141f6853b2b7a2a67b8a1c2 Mon Sep 17 00:00:00 2001 From: kaiyu <404897439@qq.com> Date: Fri, 20 Nov 2020 18:00:22 +0800 Subject: [PATCH] Merge branch 'master' of http://blit.7drlb.com:8888/r/screen_job --- src/main/java/com/moral/service/DeviceService.java | 4 src/main/resources/mapper/WeatherMapper.xml | 56 ++++- src/main/java/com/moral/util/RedisUtils.java | 195 +++++++++++++++++++ src/main/resources/mapper/AQIMapper.xml | 6 src/main/java/com/moral/task/DeviceAdjustValueTimingTask.java | 26 ++ src/main/java/com/moral/service/impl/DeviceServiceImpl.java | 7 src/main/java/com/moral/service/impl/WeatherServiceImpl.java | 260 +++++++++++-------------- 7 files changed, 392 insertions(+), 162 deletions(-) diff --git a/src/main/java/com/moral/service/DeviceService.java b/src/main/java/com/moral/service/DeviceService.java index 786bbb1..7c76d7f 100644 --- a/src/main/java/com/moral/service/DeviceService.java +++ b/src/main/java/com/moral/service/DeviceService.java @@ -1,5 +1,7 @@ package com.moral.service; +import com.moral.entity.Device; + import java.util.List; import java.util.Map; @@ -20,4 +22,6 @@ List<Map<String, Object>> macAndOrganizationIdMap(List<String> macs); List<Map<String, Object>> getAllByMacList(List<String> macList); + + Device getDeviceByID(int id); } diff --git a/src/main/java/com/moral/service/impl/DeviceServiceImpl.java b/src/main/java/com/moral/service/impl/DeviceServiceImpl.java index 2d97264..e3dfd63 100644 --- a/src/main/java/com/moral/service/impl/DeviceServiceImpl.java +++ b/src/main/java/com/moral/service/impl/DeviceServiceImpl.java @@ -3,6 +3,7 @@ import java.util.List; import java.util.Map; +import com.moral.entity.Device; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -61,4 +62,10 @@ public List<Map<String, Object>> getAllByMacList(List<String> macList) { return deviceMapper.getAllByMacList(macList); } + + @Override + public Device getDeviceByID(int id) { + Device result = deviceMapper.selectByPrimaryKey(id); + return result; + } } diff --git a/src/main/java/com/moral/service/impl/WeatherServiceImpl.java b/src/main/java/com/moral/service/impl/WeatherServiceImpl.java index 6ebfd4b..c505346 100644 --- a/src/main/java/com/moral/service/impl/WeatherServiceImpl.java +++ b/src/main/java/com/moral/service/impl/WeatherServiceImpl.java @@ -18,13 +18,10 @@ import com.alibaba.fastjson.JSONObject; import com.moral.mapper.AQIMapper; -import com.moral.mapper.AreaMapper; -import com.moral.mapper.CityMapper; import com.moral.mapper.DeviceMapper; import com.moral.mapper.WeatherMapper; import com.moral.mapper.HistoryHourlyMapper; import com.moral.mapper.MonitorPointMapper; -import com.moral.mapper.ProvinceMapper; import com.moral.service.WeatherService; @Service @@ -45,6 +42,7 @@ @Resource private HistoryHourlyMapper historyHourlyMapper; + //O3,PM2.5,PM10������������������forecast_weather��� @Override public int insertForecastWeatherNew() throws ParseException { Calendar c = Calendar.getInstance(); @@ -70,6 +68,7 @@ cityList.add(ks); int count = 0; for (Map<String, Object> map : cityList) { + String cityCode = map.get("cityCode").toString(); String id = map.get("cityId").toString(); Map<String, Object> dataMap = restTemplate.getForObject("https://api.heweather.net/v7/weather/72h?key=da05c6c4852d4f7aa3364a9236ee9e26&gzip=n&location={1}", Map.class, id); if (dataMap == null) { @@ -82,51 +81,18 @@ List<Map<String, Object>> hourlyList = (List<Map<String, Object>>) JSONObject.parse(string); for (Map<String, Object> hourlyMap : hourlyList) { //��������������������� - String fxTime = hourlyMap.get("fxTime").toString().split("\\+")[0].replace("T", " ") + ":00"; - hourlyMap.remove("fxTime"); + String fxTime = hourlyMap.remove("fxTime").toString().split("\\+")[0].replace("T", " ") + ":00"; //icon������������������ hourlyMap.remove("icon"); hourlyMap.put("time", fxTime); //������ String text = hourlyMap.get("text").toString(); //������km/h->m/s - Double windSpeed = Double.valueOf(hourlyMap.get("windSpeed").toString()); + double windSpeed = Double.parseDouble(hourlyMap.get("windSpeed").toString()); windSpeed = windSpeed * 1000 / 3600; hourlyMap.put("windSpeed", df.format(windSpeed)); - String condition = ""; - if ("���".equals(text)) { - condition = "100"; - } else if ("���".equals(text)) { - condition = "90"; - } else if ("������".equals(text)) { - condition = "80"; - } else if ("���".equals(text)) { - condition = "70"; - } else if ("���".equals(text) || "������".equals(text) || "������".equals(text) || "".equals(text)) { - condition = "60"; - } else if ("������".equals(text)) { - condition = "45"; - } else if ("���������".equals(text)) { - condition = "40"; - } else if ("������������������".equals(text) || "���������������".equals(text)) { - condition = "30"; - } else if ("������".equals(text)) { - condition = "20"; - } else if ("���".equals(text)) { - condition = "10"; - } else if ("������������������".equals(text)) { - condition = "5"; - } else if ("������������������".equals(text)) { - condition = "4"; - } else if ("������".equals(text) || "������".equals(text) || "������".equals(text) - || "������".equals(text) || "������".equals(text) || "������".equals(text) - || "���������".equals(text) || "���������������������������".equals(text) || "������".equals(text) - ) { - condition = "0"; - } else { - condition = "50"; - } - hourlyMap.put("condition", condition); + hourlyMap.put("windScale", String.valueOf(getWindScale(windSpeed))); + hourlyMap.put("condition", getWeatherCondition(text)); String hour = fxTime.split(" ")[0]; String hour1 = fxTime.split(":")[0]; if (hour.equals(nextDay)) { @@ -138,39 +104,42 @@ } nextDayList.remove(0); map.put("data", nextDayList); - } + //������ + c.setTime(sdf.parse(today)); + c.add(Calendar.YEAR, -3); + Date start = c.getTime(); + Date end = sdf.parse(today); + int timeUnits1 = c.get(Calendar.YEAR); + int timeUnits2 = timeUnits1 + 1; + int timeUnits3 = timeUnits1 + 2; + int timeUnits4 = timeUnits1 + 3; + //���������15��� 70%,���������45���15%,������ 15% + c.setTime(end); + c.add(Calendar.DAY_OF_MONTH, -15); + //���15��������������� + Date slicedTime1 = c.getTime(); + //���45��������������� + c.add(Calendar.DAY_OF_MONTH, -30); + Date slicedTime2 = c.getTime(); - //today:������ - c.setTime(sdf.parse(today)); - c.add(Calendar.YEAR, -3); - Date start = c.getTime(); - Date end = sdf.parse(today); - int timeUnits1 = c.get(Calendar.YEAR); - int timeUnits2 = timeUnits1 + 1; - int timeUnits3 = timeUnits1 + 2; - int timeUnits4 = timeUnits1 + 3; - //���������15��� 70%,���������45���15%,������ 15% - c.setTime(end); - c.add(Calendar.DAY_OF_MONTH, -15); - //���15��������������� - Date slicedTime1 = c.getTime(); - //���45��������������� - c.add(Calendar.DAY_OF_MONTH, -30); - Date slicedTime2 = c.getTime(); - for (Map<String, Object> map : cityList) { - String cityCode = map.get("cityCode").toString(); - ArrayList<Map<String, Object>> dataList = (ArrayList<Map<String, Object>>) map.get("data"); - for (Map<String, Object> dataMap : dataList) { + //������������������������list + List<Map<String, Object>> resultList = new ArrayList<>(); + for (Map<String, Object> nextDayMap : nextDayList) { Map<String, Object> hashMap = new HashMap<>(); List<String> hours = new ArrayList<>(); hashMap.put("cityCode", cityCode); hashMap.put("start", start); hashMap.put("end", end); hashMap.put("typeFormat", "%Y-%m-%d %H:%i:%s"); - Integer condition = Integer.valueOf(dataMap.get("condition").toString()); - Double temp = Double.valueOf(dataMap.get("temp").toString()); - Integer pressure = Integer.valueOf(dataMap.get("pressure").toString()); - String time = dataMap.get("time").toString(); + int condition = Integer.parseInt(nextDayMap.get("condition").toString()); + double temp = Double.parseDouble(nextDayMap.get("temp").toString()); + int pressure = Integer.parseInt(nextDayMap.get("pressure").toString()); + String time = nextDayMap.remove("time").toString(); + //������,pm2.5,pm10������������������ + String month = time.substring(5, 7); + //��������������������� + String windDir = nextDayMap.get("windDir").toString(); + double windSpeed = Double.parseDouble(nextDayMap.get("windSpeed").toString()); //������������ hours.add(time.substring(11, 13)); c.setTime(sdf1.parse(time)); @@ -222,23 +191,18 @@ Double avg2 = getAvgO3(params, times2); Double avg3 = getAvgO3(params, times3); Double resultO3 = avg1 * 0.7 + avg2 * 0.15 + avg3 * 0.15; - dataMap.put("O3C", String.valueOf(Math.round(resultO3))); - } - - List<Map<String, Object>> resultList = new ArrayList<>(); - for (Map<String, Object> dataMap : dataList) { - Map<String, Object> resultMap = new HashMap<>(); - String time = dataMap.remove("time").toString(); - Map<String, Object> params = new HashMap<>(); - params.put("cityCode", cityCode); - params.put("time", sdf1.parse(time)); + nextDayMap.put("O3C", String.valueOf(Math.round(resultO3))); + //pm2.5,pm10������ + params.put("time", time); String beam = weatherMapper.getBeam(params); if (beam != null) { - dataMap.put("beam", beam.replace("\"", "")); + nextDayMap.put("beam", beam.replace("\"", "")); } + //������������������map + Map<String, Object> resultMap = new HashMap<>(); resultMap.put("cityCode", cityCode); resultMap.put("time", time); - resultMap.put("json", JSONObject.toJSONString(dataMap)); + resultMap.put("json", JSONObject.toJSONString(nextDayMap)); resultList.add(resultMap); } Map<String, Object> parameters = new HashMap<>(); @@ -387,41 +351,9 @@ Double windSpeed = Double.valueOf(nextDayMap.get("windSpeed").toString()); windSpeed = windSpeed * 1000 / 3600; nextDayMap.put("windSpeed", df.format(windSpeed)); + nextDayMap.put("windScale", String.valueOf(getWindScale(windSpeed))); String text = nextDayMap.get("text").toString(); - String condition = ""; - if ("���".equals(text)) { - condition = "100"; - } else if ("���".equals(text)) { - condition = "90"; - } else if ("������".equals(text)) { - condition = "80"; - } else if ("���".equals(text)) { - condition = "70"; - } else if ("���".equals(text) || "������".equals(text) || "������".equals(text) || "".equals(text)) { - condition = "60"; - } else if ("������".equals(text)) { - condition = "45"; - } else if ("���������".equals(text)) { - condition = "40"; - } else if ("������������������".equals(text) || "���������������".equals(text)) { - condition = "30"; - } else if ("������".equals(text)) { - condition = "20"; - } else if ("���".equals(text)) { - condition = "10"; - } else if ("������������������".equals(text)) { - condition = "5"; - } else if ("������������������".equals(text)) { - condition = "4"; - } else if ("������".equals(text) || "������".equals(text) || "������".equals(text) - || "������".equals(text) || "������".equals(text) || "������".equals(text) - || "���������".equals(text) || "���������������������������".equals(text) || "������".equals(text) - ) { - condition = "0"; - } else { - condition = "50"; - } - nextDayMap.put("condition", condition); + nextDayMap.put("condition", getWeatherCondition(text)); } map.put("data", nextDayList); } @@ -649,44 +581,80 @@ jsonMap.remove("obsTime"); jsonMap.remove("icon"); String text = jsonMap.get("text").toString(); - String condition; - if ("���".equals(text)) { - condition = "100"; - } else if ("���".equals(text)) { - condition = "90"; - } else if ("������".equals(text)) { - condition = "80"; - } else if ("���".equals(text)) { - condition = "70"; - } else if ("���".equals(text) || "������".equals(text) || "������".equals(text) || "".equals(text)) { - condition = "60"; - } else if ("������".equals(text)) { - condition = "45"; - } else if ("���������".equals(text)) { - condition = "40"; - } else if ("������������������".equals(text) || "���������������".equals(text)) { - condition = "30"; - } else if ("������".equals(text)) { - condition = "20"; - } else if ("���".equals(text)) { - condition = "10"; - } else if ("������������������".equals(text)) { - condition = "5"; - } else if ("������������������".equals(text)) { - condition = "4"; - } else if ("������".equals(text) || "������".equals(text) || "������".equals(text) - || "������".equals(text) || "������".equals(text) || "������".equals(text) - || "���������".equals(text) || "���������������������������".equals(text) || "������".equals(text) - ) { - condition = "0"; - } else { - condition = "50"; - } - jsonMap.put("condition", condition); + jsonMap.put("condition", getWeatherCondition(text)); resultMap.put("json", JSONObject.toJSONString(jsonMap)); resultList.add(resultMap); } weatherMapper.deleteRealWeather(sdf1.format(now)); return weatherMapper.insertRealWeather(resultList); } + + private int getWindScale(Double windSpeed) { + int windScale = 0; + if (windSpeed <= 1.5) { + windScale = 1; + } else if (windSpeed <= 3.3) { + windScale = 2; + } else if (windSpeed <= 5.4) { + windScale = 3; + } else if (windSpeed <= 7.9) { + windScale = 4; + } else if (windSpeed <= 10.7) { + windScale = 5; + } else if (windSpeed <= 13.8) { + windScale = 6; + } else if (windSpeed <= 17.1) { + windScale = 7; + } else if (windSpeed <= 20.7) { + windScale = 8; + } else if (windSpeed <= 24.4) { + windScale = 9; + } else if (windSpeed <= 28.4) { + windScale = 10; + } else if (windSpeed <= 32.6) { + windScale = 11; + }else if (windSpeed <= 36.9) { + windScale = 12; + } + return windScale; + } + + private String getWeatherCondition(String text) { + String condition; + if ("���".equals(text)) { + condition = "100"; + } else if ("���".equals(text)) { + condition = "90"; + } else if ("������".equals(text)) { + condition = "80"; + } else if ("���".equals(text)) { + condition = "70"; + } else if ("���".equals(text) || "������".equals(text) || "������".equals(text) || "".equals(text)) { + condition = "60"; + } else if ("������".equals(text)) { + condition = "45"; + } else if ("���������".equals(text)) { + condition = "40"; + } else if ("������������������".equals(text) || "���������������".equals(text)) { + condition = "30"; + } else if ("������".equals(text)) { + condition = "20"; + } else if ("���".equals(text)) { + condition = "10"; + } else if ("������������������".equals(text)) { + condition = "5"; + } else if ("������������������".equals(text)) { + condition = "4"; + } else if ("������".equals(text) || "������".equals(text) || "������".equals(text) + || "������".equals(text) || "������".equals(text) || "������".equals(text) + || "���������".equals(text) || "���������������������������".equals(text) || "������".equals(text) + ) { + condition = "0"; + } else { + condition = "50"; + } + return condition; + } } + + diff --git a/src/main/java/com/moral/task/DeviceAdjustValueTimingTask.java b/src/main/java/com/moral/task/DeviceAdjustValueTimingTask.java index f8ea0d4..0d47fa1 100644 --- a/src/main/java/com/moral/task/DeviceAdjustValueTimingTask.java +++ b/src/main/java/com/moral/task/DeviceAdjustValueTimingTask.java @@ -1,9 +1,13 @@ package com.moral.task; +import com.alibaba.fastjson.JSON; +import com.moral.entity.Device; import com.moral.service.DeviceAdjustValueService; import com.moral.service.DeviceAdjustValueTimingService; +import com.moral.service.DeviceService; import com.moral.util.AlarmUtils_2; import com.moral.util.LengthOfTimeUtils; +import com.moral.util.RedisUtils; import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.handler.annotation.XxlJob; import com.xxl.job.core.log.XxlJobLogger; @@ -27,6 +31,12 @@ @Resource private DeviceAdjustValueService deviceAdjustValueService; + + @Resource + private DeviceService deviceService; + + @Resource + RedisUtils redisUtils; @XxlJob("DeviceAdjustValueTiming") public ReturnT DeviceAdjustValueTiming(String params) { @@ -70,6 +80,22 @@ }else { deviceAdjustValueService.updateValueByDeviceID(device_id,value); } + try { + // ���������redis + //Map<String,String> adjustMap = new HashMap<>(); + if(value!=null&&!value.isEmpty()){ + Map<String, Object> valueMap = JSON.parseObject(value); + System.out.println("valueMap:"+valueMap); + if(!valueMap.isEmpty()){ + Device device = deviceService.getDeviceByID(device_id); + String key = RedisUtils.getAdjustKey(device.getMac()); + redisUtils.set(key,valueMap); + } + } + }catch (Exception e){ + ReturnT returnT = new ReturnT(500, "������redis���������������"); + return returnT; + } ReturnT returnT = new ReturnT(200, "������������������������"); return returnT; } diff --git a/src/main/java/com/moral/util/RedisUtils.java b/src/main/java/com/moral/util/RedisUtils.java new file mode 100644 index 0000000..43122d4 --- /dev/null +++ b/src/main/java/com/moral/util/RedisUtils.java @@ -0,0 +1,195 @@ +package com.moral.util; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.TypeReference; +import com.moral.common.BooleanValueFilter; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.ValueOperations; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +@Component +public class RedisUtils { + private static final String AlarmPrefix = "alarm_"; + public static String getAlarmKey(int organizationId){ + return AlarmPrefix+organizationId; + } + private static final String Adjust = "adjust_"; + public static String getAdjustKey(String mac){ + return Adjust + mac; + } + @Resource + private RedisTemplate redisTemplate; + @Resource + private BooleanValueFilter javaTypePatchValueFilter; + /** + * ���������������������value + * + * @param keys + */ + public void remove(final String... keys) { + for (String key : keys) { + remove(key); + } + } + + /** + * ������������key + * + * @param pattern + */ + public void removePattern(final String pattern) { + Set<Serializable> keys = redisTemplate.keys(pattern); + if (keys.size() > 0) + redisTemplate.delete(keys); + } + + /** + * ���������������value + * + * @param key + */ + public void remove(final String key) { + if (exists(key)) { + redisTemplate.delete(key); + } + } + + /** + * ���������������������������������value + * + * @param key + * @return + */ + public boolean exists(final String key) { + return redisTemplate.hasKey(key); + } + + /** + * ������������ + * + * @param key + * @return + */ + public Object get(final String key) { + Object result = null; + ValueOperations<Serializable, Object> operations = redisTemplate.opsForValue(); + result = operations.get(key); + return result; + } + /** + * ������������,������������������ + * + * @param key + * @return + */ + public <T>T get(String key,Class<T> clazz) { + Object obj = get(key); + String json = obj!=null?obj.toString():null; + if(json!=null) { + return (T) parseObject(json,clazz); + } + return null; + } + /** + * ������������,������������������ + * + * @param key + * @return + */ + public <T>T get(String key,TypeReference typeReference) { + Object obj = get(key); + String json = obj!=null?obj.toString():null; + if(json!=null) { + return (T) parseObject(json,typeReference); + } + return null; + } + private static <T>T parseObject(String key,Class<T> clazz) { + return (T) JSON.parseObject(key,clazz); + } + private static <T>T parseObject(String key,TypeReference typeReference) { + return (T) JSON.parseObject(key,typeReference); + } + public <T> List<T> getList(String pattern,TypeReference typeReference){ + List<String> jsonList = getList(pattern); + List<T> list = new ArrayList<T>(); + for(String json:jsonList) { + list.add((T)parseObject(json,typeReference)); + } + return list; + } + public <T> List<T> getList(String pattern,Class<T> clazz){ + List<String> jsonList = getList(pattern); + List<T> list = new ArrayList<>(); + for(String json:jsonList) { + list.add(parseObject(json,clazz)); + } + return list; + } + public List<String> getList(String pattern){ + Set<String> keys = keys(pattern); + List<String> list = new ArrayList<String>(); + for(String key:keys) { + Object obj = get(key); + String json = obj!=null?obj.toString():null; + if(json!=null) { + list.add(json); + } + } + return list; + } + public Set<String> keys(String pattern) { + return redisTemplate.keys(pattern); + } + /** + * ������������ + * + * @param key + * @param value + * @return + */ + public boolean set(final String key, Object value) { + boolean result = false; + try { + if(value!=null&&!(value instanceof String)) { + value = JSON.toJSONString(value,new BooleanValueFilter()); + } + ValueOperations<Serializable, Object> operations = redisTemplate.opsForValue(); + operations.set(key, value); + result = true; + } catch (Exception e) { + e.printStackTrace(); + } + return result; + } + + /** + * ������������ + * + * @param key + * @param value + * @return + */ + public boolean set(final String key, Object value, Long expireTime) { + boolean result = false; + try { + if(value!=null&&!(value instanceof String)) { + value = JSON.toJSONString(value, javaTypePatchValueFilter); + } + ValueOperations<Serializable, Object> operations = redisTemplate.opsForValue(); + operations.set(key, value); + redisTemplate.expire(key, expireTime, TimeUnit.SECONDS); + result = true; + } catch (Exception e) { + e.printStackTrace(); + } + return result; + } +} diff --git a/src/main/resources/mapper/AQIMapper.xml b/src/main/resources/mapper/AQIMapper.xml index ffddfca..cb01946 100644 --- a/src/main/resources/mapper/AQIMapper.xml +++ b/src/main/resources/mapper/AQIMapper.xml @@ -1,6 +1,8 @@ <?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.mapper.AQIMapper"> + <cache/> + <select id="getCityAqiConfig" resultType="java.util.LinkedHashMap"> select * from city_aqi_config; </select> @@ -24,7 +26,7 @@ </foreach> </select> - <select id="getO3ByTime" resultType="java.lang.String"> + <select id="getO3ByTime" resultType="java.lang.String" useCache="true"> select ifnull(aqi_json->'$.O3C',aqi_json->'$.O3') as 'O3' from hangzhou_aqi where city_code=#{cityCode} @@ -39,7 +41,7 @@ and DATE_FORMAT(time, '%Y%H')=#{yearAndHour} </select> - <select id="getO3FromHistory" resultType="java.lang.String"> + <select id="getO3FromHistory" resultType="java.lang.String" useCache="true"> select value ->'$.O3C' as 'O3' from history_aqi_${timeUnits} where city_code=#{cityCode} diff --git a/src/main/resources/mapper/WeatherMapper.xml b/src/main/resources/mapper/WeatherMapper.xml index 11c492c..06ce0a4 100644 --- a/src/main/resources/mapper/WeatherMapper.xml +++ b/src/main/resources/mapper/WeatherMapper.xml @@ -1,6 +1,8 @@ <?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.mapper.WeatherMapper"> + <cache/> + <select id="getCityWeatherConfig" resultType="java.util.Map"> select city_code AS cityCode, city_id AS cityId @@ -114,7 +116,7 @@ ) </select> - <select id="getSampleFromHistoryWeather" resultType="java.lang.String"> + <select id="getSampleFromHistoryWeather" resultType="java.lang.String" useCache="true"> select DATE_FORMAT(time, #{typeFormat}) as time from history_weather_${timeUnits} <where> @@ -143,20 +145,34 @@ and cast(value->'$.pressure' as UNSIGNED integer) <![CDATA[<=]]> #{endPressure} </if> - and time >= #{start} - and time <![CDATA[<]]> #{end} - and DATE_FORMAT(time, '%H') in - <foreach collection="hours" open="(" separator="," close=")" item="hour"> - #{hour} - </foreach> + <if test="start != null"> + and time >= #{start} + </if> + + <if test="end != null"> + and time <![CDATA[<]]> #{end} + </if> + + <if test="hours != null"> + and DATE_FORMAT(time, '%H') in + <foreach collection="hours" open="(" separator="," close=")" item="hour"> + #{hour} + </foreach> + </if> + </where> </select> - <select id="getSampleFromRealWeather" resultType="java.lang.String"> + <select id="getSampleFromRealWeather" resultType="java.lang.String" useCache="true"> select DATE_FORMAT(time, #{typeFormat}) as time from real_weather <where> city_code=#{cityCode} + + <if test="windDir != null"> + and json->'$.windDir' = #{windDir} + </if> + <if test="condition == 0"> and cast(json->'$.condition' as UNSIGNED integer) > #{score} </if> @@ -181,12 +197,24 @@ and cast(json->'$.pressure' as UNSIGNED integer) <![CDATA[<=]]> #{endPressure} </if> - and time >= #{start} - and time <![CDATA[<]]> #{end} - and DATE_FORMAT(time, '%H') in - <foreach collection="hours" open="(" separator="," close=")" item="hour"> - #{hour} - </foreach> + <if test="start != null"> + and time >= #{start} + </if> + + <if test="end != null"> + and time <![CDATA[<]]> #{end} + </if> + + <if test="hours != null"> + and DATE_FORMAT(time, '%H') in + <foreach collection="hours" open="(" separator="," close=")" item="hour"> + #{hour} + </foreach> + </if> + + <if test="month != null"> + and DATE_FORMAT(time, '%m')=#{month} + </if> </where> </select> </mapper> \ No newline at end of file -- Gitblit v1.8.0