Commit f9ac02337b453c4434360c34586bd49e675868c8
1 parent
54300941
停车场信息 First Commit
Showing
5 changed files
with
196 additions
and
0 deletions
src/main/java/com/bsth/CXFConfig.java
| @@ -2,6 +2,7 @@ package com.bsth; | @@ -2,6 +2,7 @@ package com.bsth; | ||
| 2 | 2 | ||
| 3 | import com.bsth.server_rs.AuthorizeInterceptor_IN; | 3 | import com.bsth.server_rs.AuthorizeInterceptor_IN; |
| 4 | import com.bsth.server_rs.base_info.car.CarRestService; | 4 | import com.bsth.server_rs.base_info.car.CarRestService; |
| 5 | +import com.bsth.server_rs.base_info.carpark.CarParkRestService; | ||
| 5 | import com.bsth.server_rs.base_info.line.LineRestService; | 6 | import com.bsth.server_rs.base_info.line.LineRestService; |
| 6 | import com.bsth.server_rs.base_info.person.PersonRestService; | 7 | import com.bsth.server_rs.base_info.person.PersonRestService; |
| 7 | import com.bsth.server_rs.base_info.section.LD_RoadSpeedRestService; | 8 | import com.bsth.server_rs.base_info.section.LD_RoadSpeedRestService; |
| @@ -117,6 +118,7 @@ public class CXFConfig { | @@ -117,6 +118,7 @@ public class CXFConfig { | ||
| 117 | new LineRestService(), | 118 | new LineRestService(), |
| 118 | new CarRestService(), | 119 | new CarRestService(), |
| 119 | new PersonRestService(), | 120 | new PersonRestService(), |
| 121 | + new CarParkRestService(), | ||
| 120 | gpsRestService, | 122 | gpsRestService, |
| 121 | scheduleRealService, | 123 | scheduleRealService, |
| 122 | stationRestService, | 124 | stationRestService, |
src/main/java/com/bsth/server_rs/base_info/carpark/CarPark.java
0 → 100644
| 1 | +package com.bsth.server_rs.base_info.carpark; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * 停车场信息 | ||
| 5 | + * Created by panzhao on 2017/8/31. | ||
| 6 | + */ | ||
| 7 | +public class CarPark { | ||
| 8 | + /** | ||
| 9 | + * 公司代码 | ||
| 10 | + */ | ||
| 11 | + private String company; | ||
| 12 | + | ||
| 13 | + /** | ||
| 14 | + * 停车场名称 | ||
| 15 | + */ | ||
| 16 | + private String parkName; | ||
| 17 | + | ||
| 18 | + /** | ||
| 19 | + * GPS空间坐标点 | ||
| 20 | + */ | ||
| 21 | + private String gparkVector; | ||
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * 停车场地址 | ||
| 25 | + */ | ||
| 26 | + private String parkAddress; | ||
| 27 | + | ||
| 28 | + | ||
| 29 | + public String getCompany() { | ||
| 30 | + return company; | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + public void setCompany(String company) { | ||
| 34 | + this.company = company; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + public String getParkName() { | ||
| 38 | + return parkName; | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + public void setParkName(String parkName) { | ||
| 42 | + this.parkName = parkName; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + public String getGparkVector() { | ||
| 46 | + return gparkVector; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + public void setGparkVector(String gparkVector) { | ||
| 50 | + this.gparkVector = gparkVector; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + public String getParkAddress() { | ||
| 54 | + return parkAddress; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + public void setParkAddress(String parkAddress) { | ||
| 58 | + this.parkAddress = parkAddress; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + | ||
| 62 | + public CarPark() { | ||
| 63 | + super(); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + public CarPark(String company, String parkName, String gparkVector, String parkAddress) { | ||
| 67 | + super(); | ||
| 68 | + this.company = company; | ||
| 69 | + this.parkName = parkName; | ||
| 70 | + this.gparkVector = gparkVector; | ||
| 71 | + this.parkAddress = parkAddress; | ||
| 72 | + } | ||
| 73 | +} |
src/main/java/com/bsth/server_rs/base_info/carpark/CarParkRestService.java
0 → 100644
| 1 | +package com.bsth.server_rs.base_info.carpark; | ||
| 2 | + | ||
| 3 | +import com.bsth.server_rs.base_info.carpark.buffer.CarParkBufferData; | ||
| 4 | +import org.springframework.stereotype.Component; | ||
| 5 | + | ||
| 6 | +import javax.ws.rs.GET; | ||
| 7 | +import javax.ws.rs.Path; | ||
| 8 | +import javax.ws.rs.PathParam; | ||
| 9 | +import javax.ws.rs.Produces; | ||
| 10 | +import javax.ws.rs.core.MediaType; | ||
| 11 | +import java.util.List; | ||
| 12 | + | ||
| 13 | +@Component | ||
| 14 | +@Path("/carpark") | ||
| 15 | +@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) | ||
| 16 | +public class CarParkRestService { | ||
| 17 | + @GET | ||
| 18 | + @Path("/all") | ||
| 19 | + public List<CarPark> findAll() { | ||
| 20 | + return CarParkBufferData.findAll(); | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + @GET | ||
| 24 | + @Path("/{company}") | ||
| 25 | + public List<CarPark> findByCompany(@PathParam("company") String company) { | ||
| 26 | + List<CarPark> list = CarParkBufferData.findByCompany(company); | ||
| 27 | + System.out.println(list.get(0).getCompany()); | ||
| 28 | + System.out.println(list.get(0).getParkName()); | ||
| 29 | + return CarParkBufferData.findByCompany(company); | ||
| 30 | + } | ||
| 31 | +} |
src/main/java/com/bsth/server_rs/base_info/carpark/buffer/CarParkBufferData.java
0 → 100644
| 1 | +package com.bsth.server_rs.base_info.carpark.buffer; | ||
| 2 | + | ||
| 3 | +import com.bsth.Application; | ||
| 4 | +import com.bsth.server_rs.base_info.carpark.CarPark; | ||
| 5 | +import com.google.common.collect.ArrayListMultimap; | ||
| 6 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 7 | +import org.springframework.boot.CommandLineRunner; | ||
| 8 | +import org.springframework.core.annotation.Order; | ||
| 9 | +import org.springframework.stereotype.Component; | ||
| 10 | +import java.util.*; | ||
| 11 | +import java.util.concurrent.TimeUnit; | ||
| 12 | + | ||
| 13 | +/** | ||
| 14 | + * 停车场数据缓存(自更新) | ||
| 15 | + * Created by panzhao on 2017/3/27. | ||
| 16 | + */ | ||
| 17 | +@Component | ||
| 18 | +@Order(6) | ||
| 19 | +public class CarParkBufferData implements CommandLineRunner { | ||
| 20 | + | ||
| 21 | + @Autowired | ||
| 22 | + CarparkRefreshThread carparkRefreshThread; | ||
| 23 | + | ||
| 24 | + private static List<CarPark> data; | ||
| 25 | + | ||
| 26 | + private static ArrayListMultimap<String, CarPark> companyListMap; | ||
| 27 | + | ||
| 28 | + | ||
| 29 | + public static List<CarPark> findAll(){ | ||
| 30 | + return data; | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + public static List<CarPark> findByCompany(String company){ | ||
| 34 | + return companyListMap.get(company); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + public static void replaceAll(List<CarPark> newData){ | ||
| 38 | + data = newData; | ||
| 39 | + ArrayListMultimap<String, CarPark> listMap = ArrayListMultimap.create(); | ||
| 40 | + | ||
| 41 | + for(CarPark carpark : data){ | ||
| 42 | + listMap.put(carpark.getCompany(), carpark); | ||
| 43 | + } | ||
| 44 | + companyListMap = listMap; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + @Override | ||
| 48 | + public void run(String... strings) throws Exception { | ||
| 49 | + Application.mainServices.scheduleWithFixedDelay(carparkRefreshThread, 10, 60 * 60, TimeUnit.SECONDS); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | +} |
src/main/java/com/bsth/server_rs/base_info/carpark/buffer/CarparkRefreshThread.java
0 → 100644
| 1 | +package com.bsth.server_rs.base_info.carpark.buffer; | ||
| 2 | + | ||
| 3 | +import com.bsth.server_rs.base_info.carpark.CarPark; | ||
| 4 | +import org.slf4j.Logger; | ||
| 5 | +import org.slf4j.LoggerFactory; | ||
| 6 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 7 | +import org.springframework.jdbc.core.BeanPropertyRowMapper; | ||
| 8 | +import org.springframework.jdbc.core.JdbcTemplate; | ||
| 9 | +import org.springframework.stereotype.Component; | ||
| 10 | + | ||
| 11 | +import java.util.List; | ||
| 12 | + | ||
| 13 | +/** | ||
| 14 | + * Created by panzhao on 2017/3/27. | ||
| 15 | + */ | ||
| 16 | +@Component | ||
| 17 | +public class CarparkRefreshThread extends Thread{ | ||
| 18 | + | ||
| 19 | + @Autowired | ||
| 20 | + JdbcTemplate jdbcTemplate; | ||
| 21 | + | ||
| 22 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
| 23 | + | ||
| 24 | + @Override | ||
| 25 | + public void run() { | ||
| 26 | + try { | ||
| 27 | + //停车场信息 | ||
| 28 | + List<CarPark> carParkList = jdbcTemplate.query("select company,park_name AS parkName,ST_AsText(g_park_point) AS gparkVector,park_point from bsth_c_car_park where destroy=0", | ||
| 29 | + BeanPropertyRowMapper.newInstance(CarPark.class)); | ||
| 30 | + | ||
| 31 | + if(carParkList == null || carParkList.size() == 0) | ||
| 32 | + return; | ||
| 33 | + CarParkBufferData.replaceAll(carParkList); | ||
| 34 | + }catch (Exception e){ | ||
| 35 | + logger.error("", e); | ||
| 36 | + } | ||
| 37 | + } | ||
| 38 | +} |