CityService.java
1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.viontech.service.impl;
import com.viontech.model.City;
import com.viontech.model.Mall;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author zhaibolin
*/
@Service
public class CityService {
@Autowired
private JdbcTemplate jdbcTemplate;
@Autowired
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
private String SQL_SELECT_MALL = "select name,status,province_id,city_id from b_mall";
private String SQL_SELECT_CITY = "select area_name as cityName,province_id,weather_code,city_id from b_city where city_id in (:cityIds)";
private String SQL_SELECT_WEATHER = "select city_id from d_weather where data_date=?";
public List<Mall> selectMallList() {
List<Mall> mallList = jdbcTemplate.query(SQL_SELECT_MALL, new BeanPropertyRowMapper<>(Mall.class));
return mallList;
}
public List<City> selectCityList(List<Mall> mallList) {
if (mallList.isEmpty()) {
System.out.println("获取不到商场列表");
return Collections.emptyList();
}
List<Integer> cityIdList = mallList.stream().filter(x -> x.getCity_id() != null).map(Mall::getCity_id).collect(Collectors.toList());
Map<String, Object> paramMap = new HashMap<>(1);
paramMap.put("cityIds", cityIdList);
return namedParameterJdbcTemplate.query(SQL_SELECT_CITY, paramMap, new BeanPropertyRowMapper<>(City.class));
}
public List<Integer> selectTodayWeather(Date date) {
List<Integer> cityIdList = jdbcTemplate.queryForList(SQL_SELECT_WEATHER, new Object[]{date}, Integer.class);
return cityIdList;
}
}