Commit aefc68fdc31aede50c137fb89a6b2ab7c1d15f86
1 parent
d8f6e586
数字基建接口--以及配置文件数据库配置修改
Showing
4 changed files
with
147 additions
and
1 deletions
src/main/java/com/bsth/CXFConfig.java
| @@ -14,6 +14,7 @@ import com.bsth.server_rs.bigdata.BigscreenService; | @@ -14,6 +14,7 @@ import com.bsth.server_rs.bigdata.BigscreenService; | ||
| 14 | import com.bsth.server_rs.departure.DepartureRestService; | 14 | import com.bsth.server_rs.departure.DepartureRestService; |
| 15 | import com.bsth.server_rs.destroy.DestroyDetailRestService; | 15 | import com.bsth.server_rs.destroy.DestroyDetailRestService; |
| 16 | import com.bsth.server_rs.directive.DirectiveRestService; | 16 | import com.bsth.server_rs.directive.DirectiveRestService; |
| 17 | +import com.bsth.server_rs.dkl.StationPassengerService; | ||
| 17 | import com.bsth.server_rs.dks.BxRestService; | 18 | import com.bsth.server_rs.dks.BxRestService; |
| 18 | import com.bsth.server_rs.dks.DksRestService; | 19 | import com.bsth.server_rs.dks.DksRestService; |
| 19 | import com.bsth.server_rs.dks.ExternalRestService; | 20 | import com.bsth.server_rs.dks.ExternalRestService; |
| @@ -146,6 +147,8 @@ public class CXFConfig { | @@ -146,6 +147,8 @@ public class CXFConfig { | ||
| 146 | 147 | ||
| 147 | @Autowired | 148 | @Autowired |
| 148 | private ExternalRestService externalRestService; | 149 | private ExternalRestService externalRestService; |
| 150 | + @Autowired | ||
| 151 | + private StationPassengerService stationPassengerService; | ||
| 149 | 152 | ||
| 150 | @Bean | 153 | @Bean |
| 151 | public Server rsServer() { | 154 | public Server rsServer() { |
| @@ -177,7 +180,8 @@ public class CXFConfig { | @@ -177,7 +180,8 @@ public class CXFConfig { | ||
| 177 | xxfbRestService, | 180 | xxfbRestService, |
| 178 | manHoursRestService, | 181 | manHoursRestService, |
| 179 | bxRestService, | 182 | bxRestService, |
| 180 | - externalRestService)); | 183 | + externalRestService, |
| 184 | + stationPassengerService)); | ||
| 181 | endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(), new AesExceptionMapper())); | 185 | endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(), new AesExceptionMapper())); |
| 182 | //endpoint.setFeatures(Arrays.asList(new Swagger2Feature())); | 186 | //endpoint.setFeatures(Arrays.asList(new Swagger2Feature())); |
| 183 | endpoint.getInInterceptors().add(new AuthorizeInterceptor_IN()); | 187 | endpoint.getInInterceptors().add(new AuthorizeInterceptor_IN()); |
src/main/java/com/bsth/server_rs/dkl/StationPassengerService.java
0 → 100644
| 1 | +package com.bsth.server_rs.dkl; | ||
| 2 | + | ||
| 3 | +import com.bsth.common.ResponseCode; | ||
| 4 | +import com.bsth.util.ConfigUtil; | ||
| 5 | +import org.slf4j.Logger; | ||
| 6 | +import org.slf4j.LoggerFactory; | ||
| 7 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 8 | +import org.springframework.jdbc.core.JdbcTemplate; | ||
| 9 | +import org.springframework.jdbc.core.RowMapper; | ||
| 10 | +import org.springframework.stereotype.Component; | ||
| 11 | + | ||
| 12 | +import javax.ws.rs.GET; | ||
| 13 | +import javax.ws.rs.Path; | ||
| 14 | +import javax.ws.rs.PathParam; | ||
| 15 | +import javax.ws.rs.Produces; | ||
| 16 | +import javax.ws.rs.core.MediaType; | ||
| 17 | +import java.io.ByteArrayOutputStream; | ||
| 18 | +import java.io.File; | ||
| 19 | +import java.nio.file.Files; | ||
| 20 | +import java.nio.file.Paths; | ||
| 21 | +import java.sql.ResultSet; | ||
| 22 | +import java.sql.SQLException; | ||
| 23 | +import java.util.*; | ||
| 24 | + | ||
| 25 | +@Component | ||
| 26 | +@Path("/station_passenger") | ||
| 27 | +@Produces({MediaType.APPLICATION_JSON}) | ||
| 28 | +public class StationPassengerService { | ||
| 29 | + | ||
| 30 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
| 31 | + @Autowired | ||
| 32 | + JdbcTemplate jdbcTemplate; | ||
| 33 | + static String url; | ||
| 34 | + static { | ||
| 35 | + url = ConfigUtil.get("http.control.dkl_url"); | ||
| 36 | + } | ||
| 37 | + @GET | ||
| 38 | + @Path("/interactive") | ||
| 39 | + public Map<String, Object> Interactive() { | ||
| 40 | + Map<String, Object> map = new HashMap<>(); | ||
| 41 | + List<String> objList = new ArrayList<>(); | ||
| 42 | + String sql = "SELECT l.name,s.up_down,if(up_down = 0,start_station_name,end_station_name) as station,url FROM `station_video` s LEFT JOIN bsth_c_line l on s.line_code = l.id "; | ||
| 43 | + try { | ||
| 44 | + List<Map<String, Object>> list = jdbcTemplate.query(sql, objList.toArray(), | ||
| 45 | + new RowMapper<Map<String, Object>>() { | ||
| 46 | + @Override | ||
| 47 | + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException { | ||
| 48 | + Map<String, Object> m = new HashMap<String, Object>(); | ||
| 49 | + m.put("name", rs.getString("name")); | ||
| 50 | + m.put("upDown", rs.getString("up_down")); | ||
| 51 | + m.put("station", rs.getString("station")); | ||
| 52 | + m.put("url", rs.getString("url")); | ||
| 53 | + return m; | ||
| 54 | + } | ||
| 55 | + }); | ||
| 56 | + map.put("status", ResponseCode.SUCCESS); | ||
| 57 | + map.put("list",list); | ||
| 58 | + } catch (Exception e) { | ||
| 59 | + map.put("status", ResponseCode.ERROR); | ||
| 60 | + logger.error("站点客流调用失败---", e); | ||
| 61 | + } finally { | ||
| 62 | + return map; | ||
| 63 | + } | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + | ||
| 67 | + | ||
| 68 | + @GET | ||
| 69 | + @Path("/dkl/{date}") | ||
| 70 | + public Map<String, Object> dkl(@PathParam("date") String date) { | ||
| 71 | + Map<String, Object> map = new HashMap<>(); | ||
| 72 | + List<String> objList = new ArrayList<>(); | ||
| 73 | + String sql = "SELECT line_name,up_down,station_name,num,image from dkl_info where create_date like '%"+date+"%' "; | ||
| 74 | + try { | ||
| 75 | + List<Map<String, Object>> list = jdbcTemplate.query(sql, objList.toArray(), | ||
| 76 | + new RowMapper<Map<String, Object>>() { | ||
| 77 | + @Override | ||
| 78 | + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException { | ||
| 79 | + Map<String, Object> m = new HashMap<String, Object>(); | ||
| 80 | + m.put("name", rs.getString("line_name")); | ||
| 81 | + m.put("upDown", rs.getString("up_down")); | ||
| 82 | + m.put("station", rs.getString("station_name")); | ||
| 83 | + m.put("num", rs.getString("num")); | ||
| 84 | + // 将图片路径转换为base64编码 | ||
| 85 | + String imagePath = rs.getString("image"); | ||
| 86 | + String base64Image = convertImageToBase64(url+ imagePath); | ||
| 87 | + m.put("image", base64Image); | ||
| 88 | + return m; | ||
| 89 | + } | ||
| 90 | + }); | ||
| 91 | + map.put("status", ResponseCode.SUCCESS); | ||
| 92 | + map.put("list",list); | ||
| 93 | + } catch (Exception e) { | ||
| 94 | + map.put("status", ResponseCode.ERROR); | ||
| 95 | + logger.error("站点客流调用失败---", e); | ||
| 96 | + } finally { | ||
| 97 | + return map; | ||
| 98 | + } | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + | ||
| 102 | + | ||
| 103 | + /** | ||
| 104 | + * 将图片文件转换为base64编码 | ||
| 105 | + * @param imagePath 图片路径 | ||
| 106 | + * @return base64编码字符串 | ||
| 107 | + */ | ||
| 108 | + private String convertImageToBase64(String imagePath) { | ||
| 109 | + if (imagePath == null || imagePath.isEmpty()) { | ||
| 110 | + return null; | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + try { | ||
| 114 | + // 如果是相对路径,可能需要拼接完整路径 | ||
| 115 | + File imageFile = new File(imagePath); | ||
| 116 | + // 判断是否为URL路径 | ||
| 117 | + // 判断是否为URL路径 | ||
| 118 | + if (imagePath.startsWith("http://") || imagePath.startsWith("https://")) { | ||
| 119 | + // 处理网络图片 | ||
| 120 | + java.net.URL url = new java.net.URL(imagePath); | ||
| 121 | + try (java.io.InputStream in = url.openStream()) { | ||
| 122 | + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); | ||
| 123 | + int nRead; | ||
| 124 | + byte[] data = new byte[1024]; | ||
| 125 | + while ((nRead = in.read(data, 0, data.length)) != -1) { | ||
| 126 | + buffer.write(data, 0, nRead); | ||
| 127 | + } | ||
| 128 | + buffer.flush(); | ||
| 129 | + byte[] imageBytes = buffer.toByteArray(); | ||
| 130 | + return Base64.getEncoder().encodeToString(imageBytes); | ||
| 131 | + } | ||
| 132 | + } | ||
| 133 | + } catch (Exception e) { | ||
| 134 | + logger.error("图片转换为base64失败: " + imagePath, e); | ||
| 135 | + return null; | ||
| 136 | + } | ||
| 137 | + return null; | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | +} |
src/main/resources/application-dev.properties
| @@ -31,6 +31,7 @@ spring.redis.password=bsth_control_001 | @@ -31,6 +31,7 @@ spring.redis.password=bsth_control_001 | ||
| 31 | spring.redis.port=28008 | 31 | spring.redis.port=28008 |
| 32 | 32 | ||
| 33 | http.control.service_data_url= http://127.0.0.1:9088/companyService | 33 | http.control.service_data_url= http://127.0.0.1:9088/companyService |
| 34 | +http.control.dkl_url= http://127.0.0.1:9088 | ||
| 34 | http.control.secret.key= dVPHJkWUt5FhMT7jrM2dLV7QvlHAmZFd42rs1P0usBx8A7HZki | 35 | http.control.secret.key= dVPHJkWUt5FhMT7jrM2dLV7QvlHAmZFd42rs1P0usBx8A7HZki |
| 35 | 36 | ||
| 36 | http.gps.real.url= http://27.115.69.123:8800/transport_server/rtgps/ | 37 | http.gps.real.url= http://27.115.69.123:8800/transport_server/rtgps/ |
src/main/resources/application-prod.properties
| @@ -30,6 +30,7 @@ spring.redis.password=bsth_control_001 | @@ -30,6 +30,7 @@ spring.redis.password=bsth_control_001 | ||
| 30 | spring.redis.port=28008 | 30 | spring.redis.port=28008 |
| 31 | 31 | ||
| 32 | http.control.service_data_url= http://10.10.150.103:9088/companyService | 32 | http.control.service_data_url= http://10.10.150.103:9088/companyService |
| 33 | +http.control.dkl_url= http://10.10.150.103:9088 | ||
| 33 | http.control.secret.key= dVPHJkWUt5FhMT7jrM2dLV7QvlHAmZFd42rs1P0usBx8A7HZki | 34 | http.control.secret.key= dVPHJkWUt5FhMT7jrM2dLV7QvlHAmZFd42rs1P0usBx8A7HZki |
| 34 | 35 | ||
| 35 | http.gps.real.url= http://10.10.150.103:8080/transport_server/rtgps/ | 36 | http.gps.real.url= http://10.10.150.103:8080/transport_server/rtgps/ |
| 36 | \ No newline at end of file | 37 | \ No newline at end of file |