| | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * 字符串转日期的转换器 |
| | | * @author byshome |
| | | * @version $Id: StringToDateConverter.java, v 0.1 2015年9月24日 下午7:19:41 byshome Exp $ |
| | | * |
| | | * 字符串转日期的转换器: |
| | | * @author: fengxiang |
| | | * @date: 2018/7/30 14:40 |
| | | */ |
| | | public class StringToDateConverter implements Converter<String, Date> { |
| | | private static Logger log = Logger.getLogger(StringToDateConverter.class); |
| | | private static final String dateFormat = "yyyy-MM-dd HH:mm:ss"; |
| | | // private static final String shortDateFormat = "yyyy-MM-dd"; |
| | | private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat); |
| | | private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat); |
| | | /** |
| | | * @see org.springframework.core.convert.converter.Converter#convert(java.lang.Object) |
| | | */ |
| | |
| | | try { |
| | | if(StringUtils.isNullOrEmpty(source)){ |
| | | throw new BusinessException(String.format("parser %s to Date fail", source)); |
| | | } |
| | | if("null".equals(source)){ |
| | | return null; |
| | | } |
| | | if(StringUtils.isNumericZidai(source)) { |
| | | source = source.length() == 10 ? source+"000" : source; |
| | |
| | | package com.moral.common.util; |
| | | |
| | | import com.mysql.jdbc.TimeUtil; |
| | | |
| | | import javax.validation.constraints.NotNull; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * |
| | | * 功能描述: string 工具类 |
| | | * @author: fengxiang |
| | | * @date: 2018/7/30 10:53 |
| | | */ |
| | | public class StringUtils { |
| | | public static final char UNDERLINE = '_'; |
| | | public static final String NULL = "null"; |
| | | |
| | | /** |
| | | * 驼峰格式字符串转换为下划线格式字符串 |
| | |
| | | return sb.toString(); |
| | | } |
| | | public static boolean isNullOrEmpty(String toTest) { |
| | | return toTest == null || toTest.length() == 0; |
| | | return toTest == null || toTest.length() == 0 || NULL.equals(toTest); |
| | | } |
| | | public static Object stringToObject4Type(Class<?> type,String value) throws Exception{ |
| | | Object result = value; |
| | |
| | | import com.moral.mapper.AlarmDailyMapper;
|
| | | import com.moral.mapper.DemoMapper;
|
| | |
|
| | |
|
| | | @RestController
|
| | | @RequestMapping("demo")
|
| | | public class DemoConreoller {
|
| | |
| | | return thisMonth;
|
| | | }
|
| | |
|
| | | /**
|
| | | *
|
| | | * 功能描述: |
| | | *
|
| | | * @param: startTime 开始时间
|
| | | * @param: endTime 结束时间
|
| | | * @return:
|
| | | * @author: fengxiang
|
| | | * @date: 2018/7/30 11:27
|
| | | */
|
| | | @GetMapping("get-dayaqis")
|
| | | public List<Map<String, Object>> getDayAqis(Date startTime,Date endTime) {
|
| | | return demoMapper.selectByTimeZones(startTime,endTime);
|
| | | }
|
| | | }
|
| | |
| | | package com.moral.mapper; |
| | | |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | public interface DemoMapper { |
| | | List<Map<String, Object>> getDatas(Map<String, Object> parameters); |
| | | List<Map<String, Object>> selectByTimeZones(@Param("startTime") Date startTime,@Param("endTime") Date endTime); |
| | | } |
| | |
| | | LIMIT #{size} |
| | | </if> |
| | | </select> |
| | | <select id="selectByTimeZones" resultType="map"> |
| | | select * from hangzhou_aqi where time in ( |
| | | SELECT max(time) from ( |
| | | select time,cast(aqi_json->"$.AQI" as SIGNED INTEGER) as aqi from hangzhou_aqi |
| | | ) hz where EXISTS ( select * from ( |
| | | select max(cast(aqi_json->"$.AQI" as SIGNED INTEGER)) as max_aqi, |
| | | DATE_FORMAT(time,'%Y-%m-%d') as day_time |
| | | from hangzhou_aqi |
| | | where time >= #{startTime} and time <![CDATA[<=]]> #{endTime} |
| | | GROUP BY day_time |
| | | ) as max_result where day_time = DATE_FORMAT(hz.time,'%Y-%m-%d') and max_aqi = hz.aqi |
| | | ) GROUP BY DATE_FORMAT(time,'%Y-%m-%d') ORDER BY time ASC |
| | | ) |
| | | </select> |
| | | </mapper> |