Commit faa4e6852854cc3f9798e66efa2030505c930dbd
1 parent
cf63be07
1.提供给博协响应式公交数据接口
Showing
6 changed files
with
285 additions
and
0 deletions
src/main/java/com/bsth/common/SystemParamKeys.java
0 → 100644
| 1 | +package com.bsth.common; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * @author Hill | |
| 5 | + */ | |
| 6 | +public class SystemParamKeys { | |
| 7 | + | |
| 8 | + public static final String SPECIAL_ROLES = "special.roles"; | |
| 9 | + | |
| 10 | + public static final String LIMIT_PASSWORDS = "limit.passwords"; | |
| 11 | + | |
| 12 | + public static final String LIMIT_URIS = "limit.uris"; | |
| 13 | + | |
| 14 | + public static final String LIMIT_LINES = "limit.lines"; | |
| 15 | + | |
| 16 | + public static final String LIMIT_DEVICES = "limit.devices"; | |
| 17 | +} | ... | ... |
src/main/java/com/bsth/entity/SystemParam.java
0 → 100644
| 1 | +package com.bsth.entity; | |
| 2 | + | |
| 3 | +import javax.persistence.*; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * @author Hill | |
| 7 | + */ | |
| 8 | +@Entity | |
| 9 | +@Table(name = "bsth_c_sys_param") | |
| 10 | +public class SystemParam { | |
| 11 | + | |
| 12 | + @Id | |
| 13 | + @GeneratedValue(strategy = GenerationType.IDENTITY) | |
| 14 | + private Integer id; | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * 键名(唯一) | |
| 18 | + */ | |
| 19 | + private String key; | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * 值 | |
| 23 | + */ | |
| 24 | + private String value; | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * 备注 | |
| 28 | + */ | |
| 29 | + private String remark; | |
| 30 | + | |
| 31 | + public Integer getId() { | |
| 32 | + return id; | |
| 33 | + } | |
| 34 | + | |
| 35 | + public void setId(Integer id) { | |
| 36 | + this.id = id; | |
| 37 | + } | |
| 38 | + | |
| 39 | + public String getKey() { | |
| 40 | + return key; | |
| 41 | + } | |
| 42 | + | |
| 43 | + public void setKey(String key) { | |
| 44 | + this.key = key; | |
| 45 | + } | |
| 46 | + | |
| 47 | + public String getValue() { | |
| 48 | + return value; | |
| 49 | + } | |
| 50 | + | |
| 51 | + public void setValue(String value) { | |
| 52 | + this.value = value; | |
| 53 | + } | |
| 54 | + | |
| 55 | + public String getRemark() { | |
| 56 | + return remark; | |
| 57 | + } | |
| 58 | + | |
| 59 | + public void setRemark(String remark) { | |
| 60 | + this.remark = remark; | |
| 61 | + } | |
| 62 | +} | ... | ... |
src/main/java/com/bsth/repository/SystemParamRepository.java
0 → 100644
| 1 | +package com.bsth.repository; | |
| 2 | + | |
| 3 | +import com.bsth.entity.SystemParam; | |
| 4 | +import org.springframework.data.repository.PagingAndSortingRepository; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * @author Hill | |
| 8 | + */ | |
| 9 | +public interface SystemParamRepository extends PagingAndSortingRepository<SystemParam, Integer> { | |
| 10 | +} | ... | ... |
src/main/java/com/bsth/server_rs/dks/BxRestService.java
0 → 100644
| 1 | +package com.bsth.server_rs.dks; | |
| 2 | + | |
| 3 | +import com.bsth.common.SystemParamKeys; | |
| 4 | +import com.bsth.entity.ElecInfo; | |
| 5 | +import com.bsth.entity.OilInfo; | |
| 6 | +import com.bsth.entity.SchedulePlanInfo; | |
| 7 | +import com.bsth.entity.ScheduleRealInfo; | |
| 8 | +import com.bsth.redis.ElecRedisService; | |
| 9 | +import com.bsth.redis.OilRedisService; | |
| 10 | +import com.bsth.redis.ScheduleRedisService; | |
| 11 | +import com.bsth.repository.SchedulePlanInfoRepository; | |
| 12 | +import com.bsth.repository.ScheduleRealInfoRepository; | |
| 13 | +import com.bsth.server_rs.AuthorizeInterceptor_IN; | |
| 14 | +import com.bsth.server_rs.base_info.car.Car; | |
| 15 | +import com.bsth.server_rs.base_info.car.buffer.CarBufferData; | |
| 16 | +import com.bsth.server_rs.base_info.line.Line; | |
| 17 | +import com.bsth.server_rs.base_info.line.buffer.LineBufferData; | |
| 18 | +import com.bsth.server_rs.base_info.station.buffer.StationBufferData; | |
| 19 | +import com.bsth.server_rs.base_info.station.entity.StationRotue; | |
| 20 | +import com.bsth.server_rs.gps.buffer.GpsRealDataBuffer; | |
| 21 | +import com.bsth.server_rs.gps.entity.GpsEntity; | |
| 22 | +import com.bsth.server_ws.util.ScheduleCalculator; | |
| 23 | +import com.bsth.service.SystemParamService; | |
| 24 | +import com.bsth.util.Arith; | |
| 25 | +import com.google.common.collect.ArrayListMultimap; | |
| 26 | +import org.joda.time.DateTime; | |
| 27 | +import org.joda.time.format.DateTimeFormat; | |
| 28 | +import org.slf4j.Logger; | |
| 29 | +import org.slf4j.LoggerFactory; | |
| 30 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 31 | +import org.springframework.jdbc.core.BatchPreparedStatementSetter; | |
| 32 | +import org.springframework.jdbc.core.BeanPropertyRowMapper; | |
| 33 | +import org.springframework.jdbc.core.JdbcTemplate; | |
| 34 | +import org.springframework.jdbc.datasource.DataSourceTransactionManager; | |
| 35 | +import org.springframework.scheduling.annotation.EnableScheduling; | |
| 36 | +import org.springframework.scheduling.annotation.Scheduled; | |
| 37 | +import org.springframework.stereotype.Component; | |
| 38 | +import org.springframework.transaction.TransactionDefinition; | |
| 39 | +import org.springframework.transaction.TransactionStatus; | |
| 40 | +import org.springframework.transaction.support.DefaultTransactionDefinition; | |
| 41 | +import org.springframework.util.StringUtils; | |
| 42 | + | |
| 43 | +import javax.ws.rs.GET; | |
| 44 | +import javax.ws.rs.Path; | |
| 45 | +import javax.ws.rs.PathParam; | |
| 46 | +import javax.ws.rs.Produces; | |
| 47 | +import javax.ws.rs.core.MediaType; | |
| 48 | +import java.sql.PreparedStatement; | |
| 49 | +import java.sql.SQLException; | |
| 50 | +import java.util.*; | |
| 51 | + | |
| 52 | +/** | |
| 53 | + * @author Hill | |
| 54 | + * @date 2021-09 | |
| 55 | + */ | |
| 56 | +@Component | |
| 57 | +@Path("/bx") | |
| 58 | +@Produces({MediaType.APPLICATION_JSON}) | |
| 59 | +public class BxRestService { | |
| 60 | + | |
| 61 | + private final static Logger log = LoggerFactory.getLogger(BxRestService.class); | |
| 62 | + | |
| 63 | + @Autowired | |
| 64 | + private AuthorizeInterceptor_IN authorizeInterceptorIn; | |
| 65 | + | |
| 66 | + @Autowired | |
| 67 | + private JdbcTemplate jdbcTemplate; | |
| 68 | + | |
| 69 | + @Autowired | |
| 70 | + private ScheduleRealInfoRepository scheduleRealInfoRepository; | |
| 71 | + | |
| 72 | + @Autowired | |
| 73 | + private SchedulePlanInfoRepository schedulePlanInfoRepository; | |
| 74 | + | |
| 75 | + @Autowired | |
| 76 | + private ScheduleRedisService scheduleRedisService; | |
| 77 | + | |
| 78 | + @Autowired | |
| 79 | + private OilRedisService oilRedisService; | |
| 80 | + | |
| 81 | + @Autowired | |
| 82 | + private ElecRedisService elecRedisService; | |
| 83 | + | |
| 84 | + @Autowired | |
| 85 | + private SystemParamService systemParamService; | |
| 86 | + | |
| 87 | + @GET | |
| 88 | + @Path("/line") | |
| 89 | + public List<Line> findAllLine() { | |
| 90 | + List<Line> result = new ArrayList<>(); | |
| 91 | + String limitLines = systemParamService.getValue(SystemParamKeys.LIMIT_LINES); | |
| 92 | + if (limitLines == null) { | |
| 93 | + return result; | |
| 94 | + } | |
| 95 | + for (Line line : LineBufferData.findAll()) { | |
| 96 | + if (limitLines.indexOf(String.format("%s,", line.getLineCode())) > -1) { | |
| 97 | + result.add(line); | |
| 98 | + } | |
| 99 | + } | |
| 100 | + | |
| 101 | + return result; | |
| 102 | + } | |
| 103 | + | |
| 104 | + @GET | |
| 105 | + @Path("/station") | |
| 106 | + public Map<String, Collection<StationRotue>> findAllStation() { | |
| 107 | + Map<String, Collection<StationRotue>> result = new HashMap<>(); | |
| 108 | + String limitLines = systemParamService.getValue(SystemParamKeys.LIMIT_LINES); | |
| 109 | + if (limitLines == null) { | |
| 110 | + return result; | |
| 111 | + } | |
| 112 | + for (Map.Entry<String, Collection<StationRotue>> entry : StationBufferData.findAllRoute().entrySet()) { | |
| 113 | + String key = entry.getKey(), lineCode = key.split("_")[0]; | |
| 114 | + if (limitLines.indexOf(String.format("%s,", lineCode)) > -1) { | |
| 115 | + result.put(key, entry.getValue()); | |
| 116 | + } | |
| 117 | + } | |
| 118 | + | |
| 119 | + return result; | |
| 120 | + } | |
| 121 | + | |
| 122 | + @GET | |
| 123 | + @Path("/vehicle") | |
| 124 | + public List<Car> findAllVehicle() { | |
| 125 | + List<Car> result = new ArrayList<>(); | |
| 126 | + String limitDevices = systemParamService.getValue(SystemParamKeys.LIMIT_DEVICES); | |
| 127 | + if (limitDevices == null) { | |
| 128 | + return result; | |
| 129 | + } | |
| 130 | + for (Car car : CarBufferData.findAll()) { | |
| 131 | + if (limitDevices.indexOf(String.format("%s,", car.getEquipmentCode())) > -1) { | |
| 132 | + result.add(car); | |
| 133 | + } | |
| 134 | + } | |
| 135 | + | |
| 136 | + return result; | |
| 137 | + } | |
| 138 | + | |
| 139 | + @GET | |
| 140 | + @Path("/gps/all") | |
| 141 | + public List<GpsEntity> findAllGps() { | |
| 142 | + List<GpsEntity> result = new ArrayList<>(); | |
| 143 | + String limitDevices = systemParamService.getValue(SystemParamKeys.LIMIT_DEVICES); | |
| 144 | + if (limitDevices == null) { | |
| 145 | + return result; | |
| 146 | + } | |
| 147 | + for (GpsEntity gps : GpsRealDataBuffer.all()) { | |
| 148 | + if (limitDevices.indexOf(String.format("%s,", gps.getDeviceId())) > -1) { | |
| 149 | + result.add(gps); | |
| 150 | + } | |
| 151 | + } | |
| 152 | + | |
| 153 | + return result; | |
| 154 | + } | |
| 155 | +} | ... | ... |
src/main/java/com/bsth/service/SystemParamService.java
0 → 100644
src/main/java/com/bsth/service/impl/SystemParamServiceImpl.java
0 → 100644
| 1 | +package com.bsth.service.impl; | |
| 2 | + | |
| 3 | +import com.bsth.entity.SystemParam; | |
| 4 | +import com.bsth.repository.SystemParamRepository; | |
| 5 | +import com.bsth.service.SystemParamService; | |
| 6 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 7 | +import org.springframework.scheduling.annotation.EnableScheduling; | |
| 8 | +import org.springframework.scheduling.annotation.Scheduled; | |
| 9 | +import org.springframework.stereotype.Service; | |
| 10 | + | |
| 11 | +import java.util.HashMap; | |
| 12 | +import java.util.Map; | |
| 13 | + | |
| 14 | +@Service | |
| 15 | +@EnableScheduling | |
| 16 | +public class SystemParamServiceImpl implements SystemParamService { | |
| 17 | + | |
| 18 | + @Autowired | |
| 19 | + private SystemParamRepository systemParamRepository; | |
| 20 | + | |
| 21 | + private Map<String, String> pairs = new HashMap<>(); | |
| 22 | + | |
| 23 | + @Scheduled(cron = "0 0/30 * * * ?") | |
| 24 | + public void refresh() { | |
| 25 | + for (SystemParam sp : systemParamRepository.findAll()) { | |
| 26 | + pairs.put(sp.getKey(), sp.getValue()); | |
| 27 | + } | |
| 28 | + } | |
| 29 | + | |
| 30 | + public String getValue(String key) { | |
| 31 | + return pairs.get(key); | |
| 32 | + } | |
| 33 | +} | ... | ... |