Commit f6d110c7c318825d9ed1eee1fd2bb83db122df7f
1 parent
bd229979
1.百度地图key替换
2.区间子线路+线路文件、报站文件生成的完善,以及线调的处理变化 3.js打包兼容es6
Showing
1 changed file
with
78 additions
and
60 deletions
src/main/java/com/bsth/service/impl/StationRouteServiceImpl.java
| ... | ... | @@ -12,7 +12,6 @@ import com.bsth.util.db.DBUtils_MS; |
| 12 | 12 | import com.google.common.base.Splitter; |
| 13 | 13 | import org.apache.commons.lang3.StringUtils; |
| 14 | 14 | import org.geolatte.geom.Polygon; |
| 15 | -import org.springframework.beans.BeanUtils; | |
| 16 | 15 | import org.springframework.beans.factory.annotation.Autowired; |
| 17 | 16 | import org.springframework.beans.factory.annotation.Value; |
| 18 | 17 | import org.springframework.data.domain.Sort; |
| ... | ... | @@ -1037,47 +1036,56 @@ public class StationRouteServiceImpl extends BaseServiceImpl<StationRoute, Integ |
| 1037 | 1036 | } |
| 1038 | 1037 | } |
| 1039 | 1038 | |
| 1039 | + /** | |
| 1040 | + * 组装子线路文件内容 | |
| 1041 | + * @param lineRegion | |
| 1042 | + * @return | |
| 1043 | + */ | |
| 1040 | 1044 | private String subLine2Ftp(LineRegion lineRegion) { |
| 1041 | 1045 | StringBuilder builder = new StringBuilder(); |
| 1042 | 1046 | int len = lineRegion.getStationRoutes().size(); |
| 1043 | - if (len < 2) throw new RuntimeException("无效的区间线路"); | |
| 1044 | 1047 | int idx = 1; |
| 1045 | - List<LsStationRoute> stationRoutes = new ArrayList<>(); | |
| 1046 | - stationRoutes.add(lineRegion.getStationRoutes().get(len - 1)); | |
| 1047 | - stationRoutes.add(lineRegion.getStationRoutes().get(0)); | |
| 1048 | 1048 | if (lineRegion.getDirection() == 1) { |
| 1049 | - idx = mergeSubLine(stationRoutes, builder, idx); | |
| 1049 | + LsStationRoute first = lineRegion.getStationRoutes().get(0), last = lineRegion.getStationRoutes().get(len - 1); | |
| 1050 | + spliceRoute(builder, first, idx, false); idx++; | |
| 1051 | + spliceRoute(builder, last, idx, true); idx++; | |
| 1052 | + } | |
| 1053 | + for (int i = 0;i < len;i++) { | |
| 1054 | + LsStationRoute route = lineRegion.getStationRoutes().get(i); | |
| 1055 | + spliceRoute(builder, route, idx, i == len - 1); | |
| 1056 | + | |
| 1057 | + idx++; | |
| 1050 | 1058 | } |
| 1051 | - idx = mergeSubLine(lineRegion.getStationRoutes(), builder, idx); | |
| 1052 | 1059 | if (lineRegion.getDirection() == 0) { |
| 1053 | - mergeSubLine(stationRoutes, builder, idx); | |
| 1060 | + LsStationRoute first = lineRegion.getStationRoutes().get(0), last = lineRegion.getStationRoutes().get(len - 1); | |
| 1061 | + spliceRoute(builder, first, idx, false); idx++; | |
| 1062 | + spliceRoute(builder, last, idx, true); | |
| 1054 | 1063 | } |
| 1055 | 1064 | |
| 1056 | 1065 | return builder.toString(); |
| 1057 | 1066 | } |
| 1058 | 1067 | |
| 1059 | - private int mergeSubLine(List<LsStationRoute> stationRoutes, StringBuilder builder, int idx) { | |
| 1060 | - int len = stationRoutes.size(); | |
| 1061 | - for (int i = 0;i < len;i++) { | |
| 1062 | - LsStationRoute route = stationRoutes.get(i); | |
| 1063 | - builder.append(route.getCenterPointWgs().getPosition().getCoordinate(0)) | |
| 1064 | - .append("\t").append(route.getCenterPointWgs().getPosition().getCoordinate(1)) | |
| 1065 | - .append("\t").append(i == len - 1 ? 2 : 1) | |
| 1066 | - .append("\t").append(idx).append("\t"); | |
| 1067 | - for (int j = 0;j < 8 - route.getStationCode().length();j++) { | |
| 1068 | - builder.append("0"); | |
| 1069 | - } | |
| 1070 | - builder.append(route.getStationCode()) | |
| 1071 | - .append("\t").append((int) route.getDistances().doubleValue() * 1000) | |
| 1072 | - .append("\t0") | |
| 1073 | - .append("\t").append(route.getStationName()) | |
| 1074 | - .append("\t").append(route.getStationNameEn()) | |
| 1075 | - .append("\r\n"); | |
| 1076 | - | |
| 1077 | - idx++; | |
| 1068 | + /** | |
| 1069 | + * 按站点路由进行组装 | |
| 1070 | + * @param builder | |
| 1071 | + * @param route | |
| 1072 | + * @param idx | |
| 1073 | + * @param isEnd | |
| 1074 | + */ | |
| 1075 | + private void spliceRoute(StringBuilder builder, LsStationRoute route, int idx, boolean isEnd){ | |
| 1076 | + builder.append(route.getCenterPointWgs().getPosition().getCoordinate(0)) | |
| 1077 | + .append("\t").append(route.getCenterPointWgs().getPosition().getCoordinate(1)) | |
| 1078 | + .append("\t").append(isEnd ? 2 : 1) | |
| 1079 | + .append("\t").append(idx).append("\t"); | |
| 1080 | + for (int j = 0;j < 8 - route.getStationCode().length();j++) { | |
| 1081 | + builder.append("0"); | |
| 1078 | 1082 | } |
| 1079 | - | |
| 1080 | - return idx; | |
| 1083 | + builder.append(route.getStationCode()) | |
| 1084 | + .append("\t").append((int) route.getDistances().doubleValue() * 1000) | |
| 1085 | + .append("\t0") | |
| 1086 | + .append("\t").append(route.getStationName()) | |
| 1087 | + .append("\t").append(route.getStationNameEn()) | |
| 1088 | + .append("\r\n"); | |
| 1081 | 1089 | } |
| 1082 | 1090 | |
| 1083 | 1091 | /** |
| ... | ... | @@ -1115,8 +1123,8 @@ public class StationRouteServiceImpl extends BaseServiceImpl<StationRoute, Integ |
| 1115 | 1123 | downs++; |
| 1116 | 1124 | } |
| 1117 | 1125 | } |
| 1118 | - cnBuilder.delete(cnBuilder.length() - 7, cnBuilder.length()); | |
| 1119 | - enBuilder.delete(enBuilder.length() - 7, enBuilder.length()); | |
| 1126 | + cnBuilder.delete(cnBuilder.length() - 8, cnBuilder.length() - 1); | |
| 1127 | + enBuilder.delete(enBuilder.length() - 8, enBuilder.length() - 1); | |
| 1120 | 1128 | |
| 1121 | 1129 | // 文本转语音并进行分割 |
| 1122 | 1130 | // 音频存放及压缩文件路径 |
| ... | ... | @@ -1146,15 +1154,15 @@ public class StationRouteServiceImpl extends BaseServiceImpl<StationRoute, Integ |
| 1146 | 1154 | seq = merge(lineId, "0", seq, seqs, languages); |
| 1147 | 1155 | if (line.getLinePlayType() != 1) { |
| 1148 | 1156 | seqs.clear(); |
| 1149 | - for (int i = seq;i < ups + downs;i++) { | |
| 1150 | - seqs.add(new SeqStationLevel(i, i + 1, 1)); | |
| 1157 | + for (int i = seq;i <= ups + downs;i++) { | |
| 1158 | + seqs.add(new SeqStationLevel(i, i, 1)); | |
| 1151 | 1159 | } |
| 1152 | 1160 | merge(lineId, "0", seq, seqs, languages); |
| 1153 | 1161 | } |
| 1154 | - zipAudio(String.format("%s%s/", linePath, "0"), voicePath, lineId); | |
| 1162 | + zipAudio(String.format("%s%s/", linePath, "0"), voicePath); | |
| 1155 | 1163 | |
| 1156 | 1164 | // 线路区间 |
| 1157 | - Map<String, List<SeqStationLevel>> region2map = new HashMap<>(); | |
| 1165 | + Map<LineRegion, List<SeqStationLevel>> region2map = new HashMap<>(); | |
| 1158 | 1166 | for (LineRegion lineRegion : lineRegions) { |
| 1159 | 1167 | for (int i = 0;i < objects.size();i++) { |
| 1160 | 1168 | Object[] objArr = objects.get(i); |
| ... | ... | @@ -1164,10 +1172,10 @@ public class StationRouteServiceImpl extends BaseServiceImpl<StationRoute, Integ |
| 1164 | 1172 | for (int j = 0;j < lineRegion.getStationRoutes().size();j++) { |
| 1165 | 1173 | LsStationRoute stationRoute = lineRegion.getStationRoutes().get(j); |
| 1166 | 1174 | if (stationCode.equals(stationRoute.getStationCode())) { |
| 1167 | - List<SeqStationLevel> map = region2map.get(lineRegion.getSeq().toString()); | |
| 1175 | + List<SeqStationLevel> map = region2map.get(lineRegion); | |
| 1168 | 1176 | if (map == null) { |
| 1169 | 1177 | map = new ArrayList<>(); |
| 1170 | - region2map.put(lineRegion.getSeq().toString(), map); | |
| 1178 | + region2map.put(lineRegion, map); | |
| 1171 | 1179 | } |
| 1172 | 1180 | map.add(new SeqStationLevel(j + 1, i + 1, direction)); |
| 1173 | 1181 | break; |
| ... | ... | @@ -1176,12 +1184,26 @@ public class StationRouteServiceImpl extends BaseServiceImpl<StationRoute, Integ |
| 1176 | 1184 | } |
| 1177 | 1185 | } |
| 1178 | 1186 | } |
| 1179 | - for (Map.Entry<String, List<SeqStationLevel>> entry : region2map.entrySet()) { | |
| 1180 | - String subLineId = entry.getKey(); | |
| 1187 | + for (Map.Entry<LineRegion, List<SeqStationLevel>> entry : region2map.entrySet()) { | |
| 1188 | + LineRegion lineRegion = entry.getKey(); | |
| 1189 | + String subLineId = lineRegion.getSeq().toString(); | |
| 1181 | 1190 | List<SeqStationLevel> map = entry.getValue(); |
| 1182 | 1191 | seq = 1; |
| 1183 | - merge(lineId, subLineId, seq, map, languages); | |
| 1184 | - zipAudio(String.format("%s%s/", linePath, subLineId), String.format("%s%s-%s.zip", linePath, lineId, subLineId), String.format("%s-%s", lineId, subLineId)); | |
| 1192 | + if (lineRegion.getDirection() == 1) { | |
| 1193 | + List<SeqStationLevel> map1 = new ArrayList<>(); | |
| 1194 | + map1.add(new SeqStationLevel(1, 1, 0)); | |
| 1195 | + map1.add(new SeqStationLevel(2, 2, 0)); | |
| 1196 | + seq = merge(lineId, subLineId, seq, map1, languages); | |
| 1197 | + } | |
| 1198 | + seq = merge(lineId, subLineId, seq, map, languages); | |
| 1199 | + if (lineRegion.getDirection() == 0) { | |
| 1200 | + List<SeqStationLevel> map1 = new ArrayList<>(); | |
| 1201 | + map1.add(new SeqStationLevel(map.size() + 1, 1, 1)); | |
| 1202 | + map1.add(new SeqStationLevel(map.size() + 2, 2, 1)); | |
| 1203 | + merge(lineId, subLineId, seq, map1, languages); | |
| 1204 | + } | |
| 1205 | + | |
| 1206 | + zipAudio(String.format("%s%s/", linePath, subLineId), String.format("%s%s-%s.zip", linePath, lineId, subLineId)); | |
| 1185 | 1207 | } |
| 1186 | 1208 | } |
| 1187 | 1209 | |
| ... | ... | @@ -1203,28 +1225,28 @@ public class StationRouteServiceImpl extends BaseServiceImpl<StationRoute, Integ |
| 1203 | 1225 | * @param subLinePath 子线路文件夹 |
| 1204 | 1226 | * @param voicePath 语音报站文件压缩包路径 |
| 1205 | 1227 | */ |
| 1206 | - private void zipAudio(String subLinePath, String voicePath, String zipFolder) throws Exception { | |
| 1228 | + private void zipAudio(String subLinePath, String voicePath) throws Exception { | |
| 1207 | 1229 | File file = new File(subLinePath); |
| 1208 | 1230 | ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(voicePath)); |
| 1209 | 1231 | for (File f : file.listFiles()) { |
| 1210 | 1232 | if (f.isFile() && f.getName().endsWith(".mp3")) { |
| 1211 | - addFileToZip(zos, f, zipFolder); | |
| 1233 | + addFileToZip(zos, f); | |
| 1212 | 1234 | } |
| 1213 | 1235 | } |
| 1214 | 1236 | // Key打头音频 |
| 1215 | 1237 | file = new File(commonPath); |
| 1216 | 1238 | for (File f : file.listFiles()) { |
| 1217 | 1239 | if (f.isFile() && f.getName().startsWith("Key-")) { |
| 1218 | - addFileToZip(zos, f, zipFolder); | |
| 1240 | + addFileToZip(zos, f); | |
| 1219 | 1241 | } |
| 1220 | 1242 | } |
| 1221 | 1243 | zos.flush(); |
| 1222 | 1244 | zos.close(); |
| 1223 | 1245 | } |
| 1224 | 1246 | |
| 1225 | - private static void addFileToZip(ZipOutputStream zos, File file, String zipFolder) throws IOException { | |
| 1247 | + private static void addFileToZip(ZipOutputStream zos, File file) throws IOException { | |
| 1226 | 1248 | FileInputStream fis = new FileInputStream(file); |
| 1227 | - ZipEntry zipEntry = new ZipEntry(String.format("%s/%s", zipFolder, file.getName())); | |
| 1249 | + ZipEntry zipEntry = new ZipEntry(file.getName()); | |
| 1228 | 1250 | zos.putNextEntry(zipEntry); |
| 1229 | 1251 | |
| 1230 | 1252 | byte[] bytes = new byte[4096]; |
| ... | ... | @@ -1253,16 +1275,16 @@ public class StationRouteServiceImpl extends BaseServiceImpl<StationRoute, Integ |
| 1253 | 1275 | if (current.getStationLevel() > startSeq.getStationLevel()) { |
| 1254 | 1276 | if (i == 1) { |
| 1255 | 1277 | // 生成首站 |
| 1256 | - mergeOriginStart(lineId, subLineId, seq, current, terminal, languages); | |
| 1257 | - mergeNormalArrive(lineId, subLineId, seq, current, terminal, languages); | |
| 1278 | + mergeOriginStart(lineId, subLineId, seq, current, current.getDirection(), terminal, languages); | |
| 1279 | + mergeNormalArrive(lineId, subLineId, seq, current, current.getDirection(), terminal, languages); | |
| 1258 | 1280 | } else if (current.getStationLevel() == terminal.getStationLevel()) { |
| 1259 | 1281 | // 生成终点站 |
| 1260 | - mergeNormalStart(lineId, subLineId, seq, current, terminal, languages); | |
| 1261 | - mergeTerminalArrive(lineId, subLineId, seq, current, terminal, languages); | |
| 1282 | + mergeNormalStart(lineId, subLineId, seq, current, current.getDirection(), terminal, languages); | |
| 1283 | + mergeTerminalArrive(lineId, subLineId, seq, current, current.getDirection(), terminal, languages); | |
| 1262 | 1284 | } else { |
| 1263 | 1285 | // 生成中途站 |
| 1264 | - mergeNormalStart(lineId, subLineId, seq, current, terminal, languages); | |
| 1265 | - mergeNormalArrive(lineId, subLineId, seq, current, terminal, languages); | |
| 1286 | + mergeNormalStart(lineId, subLineId, seq, current, current.getDirection(), terminal, languages); | |
| 1287 | + mergeNormalArrive(lineId, subLineId, seq, current, current.getDirection(), terminal, languages); | |
| 1266 | 1288 | } |
| 1267 | 1289 | seq++; |
| 1268 | 1290 | } |
| ... | ... | @@ -1271,11 +1293,10 @@ public class StationRouteServiceImpl extends BaseServiceImpl<StationRoute, Integ |
| 1271 | 1293 | return seq; |
| 1272 | 1294 | } |
| 1273 | 1295 | |
| 1274 | - private void mergeOriginStart(String lineId, String subLineId, int seq, SeqStationLevel current, SeqStationLevel terminal, Set<String> languages) throws Exception { | |
| 1296 | + private void mergeOriginStart(String lineId, String subLineId, int seq, SeqStationLevel current, int direction, SeqStationLevel terminal, Set<String> languages) throws Exception { | |
| 1275 | 1297 | // 子线路路径 |
| 1276 | 1298 | String linePath = String.format(linePathPattern, lineId); |
| 1277 | 1299 | String subLinePath = String.format("%s%s/", linePath, subLineId); |
| 1278 | - int direction = current.getDirection(); | |
| 1279 | 1300 | List<String> arr = Arrays.asList(commonPath + "cn_origin_1.mp3", linePath + String.format("cn/%03d.mp3", 0), commonPath + "cn_origin_2.mp3", linePath + String.format("cn/%03d.mp3", terminal.getStationLevel()), commonPath + "sh_origin_1.mp3", linePath + String.format("sh/%03d.mp3", 0), commonPath + "sh_origin_2.mp3", linePath + String.format("cn/%03d.mp3", terminal.getStationLevel()), commonPath + "cn_start_1.mp3", linePath + String.format("cn/%03d.mp3", current.getStationLevel()), commonPath + "cn_start_2.mp3", commonPath + "sh_start_1.mp3", linePath + String.format("sh/%03d.mp3", current.getStationLevel()), commonPath + "sh_start_2.mp3", commonPath + "en_1.mp3", linePath + String.format("en/%03d.mp3", current.getStationLevel()), commonPath + "cn_start_3.mp3", commonPath + "sh_start_3.mp3"); |
| 1280 | 1301 | List<String> inputPaths = new ArrayList<>(); |
| 1281 | 1302 | for (String path : arr) { |
| ... | ... | @@ -1289,10 +1310,9 @@ public class StationRouteServiceImpl extends BaseServiceImpl<StationRoute, Integ |
| 1289 | 1310 | AudioOperationUtils.merge(inputPaths, String.format("%s%03da%s-%03d-%s-Start.mp3", subLinePath, seq, direction == 0 ? "u" : "d", direction == 0 ? current.getSeq() : terminal.getSeq() - current.getSeq() + 1, direction == 0 ? "Up" : "Dn")); |
| 1290 | 1311 | } |
| 1291 | 1312 | |
| 1292 | - private void mergeNormalStart(String lineId, String subLineId, int seq, SeqStationLevel current, SeqStationLevel terminal, Set<String> languages) throws Exception { | |
| 1313 | + private void mergeNormalStart(String lineId, String subLineId, int seq, SeqStationLevel current, int direction, SeqStationLevel terminal, Set<String> languages) throws Exception { | |
| 1293 | 1314 | String linePath = String.format(linePathPattern, lineId); |
| 1294 | 1315 | String subLinePath = String.format("%s%s/", linePath, subLineId); |
| 1295 | - int direction = current.getDirection(); | |
| 1296 | 1316 | List<String> arr = Arrays.asList(commonPath + "cn_start.mp3", linePath + String.format("cn/%03d.mp3", current.getStationLevel()), commonPath + "cn_start_2.mp3", commonPath + "sh_start_1.mp3", linePath + String.format("sh/%03d.mp3", current.getStationLevel()), commonPath + "sh_start_2.mp3", commonPath + "en_1.mp3", linePath + String.format("en/%03d.mp3", current.getStationLevel()), commonPath + "cn_start_3.mp3", commonPath + "sh_start_3.mp3"); |
| 1297 | 1317 | List<String> inputPaths = new ArrayList<>(); |
| 1298 | 1318 | for (String path : arr) { |
| ... | ... | @@ -1306,10 +1326,9 @@ public class StationRouteServiceImpl extends BaseServiceImpl<StationRoute, Integ |
| 1306 | 1326 | AudioOperationUtils.merge(inputPaths, String.format("%s%03da%s-%03d-%s-Start.mp3", subLinePath, seq, direction == 0 ? "u" : "d", direction == 0 ? current.getSeq() : terminal.getSeq() - current.getSeq() + 1, direction == 0 ? "Up" : "Dn")); |
| 1307 | 1327 | } |
| 1308 | 1328 | |
| 1309 | - private void mergeNormalArrive(String lineId, String subLineId, int seq, SeqStationLevel current, SeqStationLevel terminal, Set<String> languages) throws Exception { | |
| 1329 | + private void mergeNormalArrive(String lineId, String subLineId, int seq, SeqStationLevel current, int direction, SeqStationLevel terminal, Set<String> languages) throws Exception { | |
| 1310 | 1330 | String linePath = String.format(linePathPattern, lineId); |
| 1311 | 1331 | String subLinePath = String.format("%s%s/", linePath, subLineId); |
| 1312 | - int direction = current.getDirection(); | |
| 1313 | 1332 | List<String> arr = new ArrayList<>(Arrays.asList(commonPath + "cn_arrive.mp3", linePath + String.format("cn/%03d.mp3", current.getStationLevel()), commonPath + "cn_arrive_1.mp3", linePath + String.format("sh/%03d.mp3", current.getStationLevel()), commonPath + "sh_arrive_1.mp3", commonPath + "en_2.mp3", linePath + String.format("en/%03d.mp3", current.getStationLevel()))); |
| 1314 | 1333 | List<String> inputPaths = new ArrayList<>(); |
| 1315 | 1334 | if (languages.contains("sh")) { |
| ... | ... | @@ -1337,10 +1356,9 @@ public class StationRouteServiceImpl extends BaseServiceImpl<StationRoute, Integ |
| 1337 | 1356 | AudioOperationUtils.merge(inputPaths, String.format("%s%03db%s-%03d-%s-Arrive.mp3", subLinePath, seq, direction == 0 ? "u" : "d", direction == 0 ? current.getSeq() : terminal.getSeq() - current.getSeq() + 1, direction == 0 ? "Up" : "Dn")); |
| 1338 | 1357 | } |
| 1339 | 1358 | |
| 1340 | - private void mergeTerminalArrive(String lineId, String subLineId, int seq, SeqStationLevel current, SeqStationLevel terminal, Set<String> languages) throws Exception { | |
| 1359 | + private void mergeTerminalArrive(String lineId, String subLineId, int seq, SeqStationLevel current, int direction, SeqStationLevel terminal, Set<String> languages) throws Exception { | |
| 1341 | 1360 | String linePath = String.format(linePathPattern, lineId); |
| 1342 | 1361 | String subLinePath = String.format("%s%s/", linePath, subLineId); |
| 1343 | - int direction = current.getDirection(); | |
| 1344 | 1362 | List<String> arr = Arrays.asList(commonPath + "cn_terminal.mp3", linePath + String.format("cn/%03d.mp3", current.getStationLevel()), commonPath + "cn_arrive_1.mp3", commonPath + "sh_terminal.mp3", linePath + String.format("sh/%03d.mp3", current.getStationLevel()), commonPath + "sh_arrive_1.mp3", commonPath + "en_3.mp3", linePath + String.format("en/%03d.mp3", current.getStationLevel()), commonPath + "terminal_music.mp3"); |
| 1345 | 1363 | List<String> inputPaths = new ArrayList<>(); |
| 1346 | 1364 | for (String path : arr) { | ... | ... |