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

代码优化

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