提交 4c3ed04b authored 作者: hzh's avatar hzh

代码优化

上级 2ec8923a
package org.dromara.server.controller.train;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import io.seata.spring.annotation.GlobalTransactional;
......@@ -116,25 +117,33 @@ public class TrainController extends BaseController {
/**
* 火车票查询列表
*
* @param fromDate 出发日期
* @param fromStationCodeList 出发站点代码列表 (与出发城市二选一填写)
* @param toStationCodeList 到达站点代码列表 (与到达城市二选一填写)
* @param fromCity 出发城市
* @param toCity 到达城市
* @return 查询列表
* @throws InterruptedException
*/
@GlobalTransactional(timeoutMills = 600000)
@GetMapping("/list")
public R<List<org.dromara.common.ys.model.res.train.QueryModel>> list(
@RequestParam(value = "fromDate") String fromDate,
@RequestParam(value = "fromStationCode", required = false) String fromStationCode,
@RequestParam(value = "toStationCode", required = false) String toStationCode,
@RequestParam(value = "fromStationCodeList", required = false) List<String> fromStationCodeList,
@RequestParam(value = "toStationCodeList", required = false) List<String> toStationCodeList,
@RequestParam(value = "fromCity", required = false) String fromCity,
@RequestParam(value = "toCity", required = false) String toCity
) throws InterruptedException {
//获取出发站点
List<String> fromStationCodeList = getStationCodeList(fromStationCode, fromCity);
List<String> fromStationCodes = getStationCodeList(fromStationCodeList, fromCity);
//获取目的站点
List<String> toStationCodeList = getStationCodeList(toStationCode, toCity);
List<String> toStationCodes = getStationCodeList(toStationCodeList, toCity);
String userId = getUserId();
List<Callable<List<org.dromara.common.ys.model.res.train.QueryModel>>> taskList = fromStationCodeList.stream().flatMap(fromCode ->
toStationCodeList.stream().map(toCode -> (Callable<List<org.dromara.common.ys.model.res.train.QueryModel>>) () -> {
List<Callable<List<org.dromara.common.ys.model.res.train.QueryModel>>> taskList = fromStationCodes.stream().flatMap(fromCode ->
toStationCodes.stream().map(toCode -> (Callable<List<org.dromara.common.ys.model.res.train.QueryModel>>) () -> {
QueryModel query = new QueryModel()
.setFromDate(fromDate)
.setFromStationCode(fromCode)
......@@ -166,10 +175,10 @@ public class TrainController extends BaseController {
return R.ok(list);
}
private List<String> getStationCodeList(String stationCode, String city) {
private List<String> getStationCodeList(List<String> codeList, String city) {
List<String> stationCodeList = new ArrayList<>();
if (StringUtils.isNotEmpty(stationCode)) {
stationCodeList.add(stationCode);
if (CollectionUtil.isNotEmpty(codeList)) {
stationCodeList.addAll(codeList);
} else {
stationCodeList = getStationList().stream().filter(item -> StringUtils.equals(item.getCityName(), city)).map(AllStationModel::getZddm)
.collect(Collectors.toList());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论