public interface SWMWConvForecastDao{
public List findSWMWConvForecastBytimeRange (String timeRange, String elements);
}
@Component
public class SWMWConvForecastDaoImpl implements SWMWConvForecastDao {
@Autowired
@PersistenceContext
private EntityManager entityManager;
public List<SWMWConvForecast> findSWMWConvForecastBytimeRange (String timeRange, String elements){
String[] times = timeRange.split("," );
String start="" ;
String end="" ;
if (times.length > 1 ) {
start = DateUtils.getTimeString(times[0 ], DateUtils.SECOND_FORMAT1);
end = DateUtils.getTimeString(times[1 ], DateUtils.SECOND_FORMAT1);
} else {
start = DateUtils.getTimeString(timeRange, DateUtils.SECOND_FORMAT1);
end = DateUtils.getTimeString(timeRange, DateUtils.SECOND_FORMAT1);
}
String sel = "id,content,publictime,inserttime,warning,citycode,stationcode,ip" ;
if (elements!=null ) {
sel=elements;;
}
String sql = "select " +sel+" from SWMW_ConvForecast where publictime between '" +start+"' and '" +end+"'" ;
Query query = entityManager.createNativeQuery(sql);
List<SWMWConvForecast> list = query.unwrap(SQLQuery.class)
.setResultTransformer(Transformers.aliasToBean(SWMWConvForecast.class))
.list();
return list;
}
@JsonInclude (Include.NON_NULL)
public class SWMWConvForecast {
private int id;
private String content;
private String producttype;
@JsonFormat (pattern = "yyyyMMddHHmmss" , timezone = "GMT+8" )
private Date publictime;
@JsonFormat (pattern = "yyyyMMddHHmmss" , timezone = "GMT+8" )
private Date inserttime;
private Boolean warning;
private String citycode;
private String stationcode;
private String ip;
.....
public String getWarning () {
if (warning == null ) {
return "0" ;
}
if (warning) {
return "1" ;
} else {
return "0" ;
}
}