Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
T
travel-cloud
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
cloud
travel-cloud
Commits
967c03fa
提交
967c03fa
authored
11月 27, 2024
作者:
hzh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
代码优化
上级
4e2216c1
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
25 行增加
和
46 行删除
+25
-46
TrainController.java
.../org/dromara/server/controller/train/TrainController.java
+25
-46
没有找到文件。
ruoyi-modules/ruoyi-server/src/main/java/org/dromara/server/controller/train/TrainController.java
浏览文件 @
967c03fa
...
...
@@ -39,10 +39,6 @@ import org.springframework.web.bind.annotation.*;
import
java.time.Duration
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.concurrent.Callable
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.Future
;
import
java.util.stream.Collectors
;
/**
...
...
@@ -118,11 +114,6 @@ public class TrainController extends BaseController {
return
stationList
;
}
/**
* 线程数
*/
private
static
final
int
NUM_THREADS
=
100
;
/**
* 火车票查询列表
*
...
...
@@ -132,7 +123,6 @@ public class TrainController extends BaseController {
* @param fromCity 出发城市
* @param toCity 到达城市
* @return 查询列表
* @throws InterruptedException
*/
@GlobalTransactional
(
timeoutMills
=
600000
)
@GetMapping
(
"/list"
)
...
...
@@ -142,56 +132,45 @@ public class TrainController extends BaseController {
@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
>
fromStationCodes
=
getStationCodeList
(
fromStationCodeList
,
fromCity
);
String
fromStationCode
=
getStationCodeList
(
fromStationCodeList
,
fromCity
);
//获取目的站点
List
<
String
>
toStationCodes
=
getStationCodeList
(
toStationCodeList
,
toCity
);
String
toStationCode
=
getStationCodeList
(
toStationCodeList
,
toCity
);
String
userId
=
getUserId
();
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
)
.
setToStationCode
(
toCode
)
.
setTripType
(
TripType
.
PUBLIC
.
getCode
());
return
trainService
.
queryModel
(
userId
,
query
);
})).
collect
(
Collectors
.
toList
());
// 创建一个线程池
ExecutorService
executorService
=
Executors
.
newFixedThreadPool
(
NUM_THREADS
);
// 提交任务并等待完成
List
<
Future
<
List
<
org
.
dromara
.
common
.
ys
.
model
.
res
.
train
.
QueryModel
>>>
futures
=
executorService
.
invokeAll
(
taskList
);
// 关闭线程池
executorService
.
shutdown
();
// 检查任务是否完成
List
<
org
.
dromara
.
common
.
ys
.
model
.
res
.
train
.
QueryModel
>
list
=
futures
.
stream
().
flatMap
(
f
->
{
try
{
return
f
.
get
().
stream
();
}
catch
(
Exception
e
)
{
return
new
ArrayList
<
org
.
dromara
.
common
.
ys
.
model
.
res
.
train
.
QueryModel
>().
stream
();
}
}).
collect
(
Collectors
.
groupingBy
(
org
.
dromara
.
common
.
ys
.
model
.
res
.
train
.
QueryModel
::
getTrainCode
))
.
entrySet
().
stream
().
map
(
entry
->
entry
.
getValue
().
get
(
0
)).
collect
(
Collectors
.
toList
());
QueryModel
query
=
new
QueryModel
()
.
setFromDate
(
fromDate
)
.
setFromStationCode
(
fromStationCode
)
.
setToStationCode
(
toStationCode
)
.
setTripType
(
TripType
.
PUBLIC
.
getCode
());
List
<
org
.
dromara
.
common
.
ys
.
model
.
res
.
train
.
QueryModel
>
list
=
trainService
.
queryModel
(
userId
,
query
);
System
.
out
.
println
(
"list:"
+
list
.
size
());
return
R
.
ok
(
list
);
}
private
List
<
String
>
getStationCodeList
(
List
<
String
>
codeList
,
String
city
)
{
private
String
getStationCodeList
(
List
<
String
>
codeList
,
String
city
)
{
List
<
String
>
stationCodeList
=
new
ArrayList
<>();
if
(
CollectionUtil
.
isNotEmpty
(
codeList
))
{
stationCodeList
.
addAll
(
codeList
);
}
else
{
stationCodeList
=
getStationList
().
stream
().
filter
(
item
->
StringUtils
.
equals
(
item
.
getCityName
(),
city
)).
map
(
AllStationModel:
:
getZddm
)
stationCodeList
=
getStationList
().
stream
().
filter
(
item
->
StringUtils
.
equals
(
item
.
getCityName
(),
city
))
.
sorted
((
o1
,
o2
)
->
{
double
v
=
StrUtil
.
similar
(
o1
.
getZdmc
(),
city
)
-
StrUtil
.
similar
(
o2
.
getZdmc
(),
city
);
if
(
v
>
0
)
{
return
-
1
;
}
else
if
(
v
==
0
)
{
return
0
;
}
else
{
return
1
;
}
})
.
map
(
AllStationModel:
:
getZddm
)
.
collect
(
Collectors
.
toList
());
}
return
stationCodeList
;
return
stationCodeList
.
get
(
0
)
;
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论