Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
usedCarAuction
/
aus
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 5cba348b
authored
Jan 30, 2026
by
gonglei
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
加入框架代码
1 parent
31816bff
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
15 deletions
aus-api/src/main/java/com/glsx/usedcar/web/api/auction/AuctionController.java
aus-api/src/main/java/com/glsx/usedcar/web/api/auction/AuctionController.java
View file @
5cba348
...
...
@@ -111,20 +111,53 @@ public class AuctionController {
*/
@PostMapping
(
"pageRandomAuctionVehicle"
)
public
Page
<
AuctionVehicle
>
pageRandomAuctionVehicle
(
@RequestBody
Pagination
<
AuctionVehicle
>
pagination
,
@RequestAttribute
(
value
=
LOGIN_ACCOUNT
,
required
=
false
)
Account
account
)
{
pagination
.
addFetch
(
root
->
root
.
fetch
(
AuctionVehicle_
.
vehicle
,
JoinType
.
LEFT
));
pagination
.
addFetch
(
root
->
root
.
fetch
(
AuctionVehicle_
.
auction
,
JoinType
.
LEFT
));
String
cityCode
=
(
String
)
pagination
.
getDataValue
(
"cities"
);
pagination
.
addCondition
((
root
,
query
,
builder
)
->
{
Expression
<
Double
>
randomExp
=
builder
.
function
(
"RAND"
,
Double
.
class
);
// MySQL 用 RAND()
if
(
StringUtils
.
hasText
(
cityCode
))
{
CriteriaBuilder
.
Case
<
Number
>
caseExpr
=
builder
.
selectCase
();
caseExpr
.
when
(
builder
.
like
(
root
.
get
(
AuctionVehicle_
.
auction
).
get
(
Auction_
.
cities
),
"%"
+
cityCode
+
"%"
),
1
).
otherwise
(
0
);
query
.
orderBy
(
builder
.
desc
(
caseExpr
),
builder
.
asc
(
randomExp
));
// 按随机值升序(或降序,效果相同)
}
else
{
query
.
orderBy
(
builder
.
asc
(
randomExp
));
// 按随机值升序(或降序,效果相同)
}
return
null
;
// 无过滤条件,返回所有数据并随机排序
});
return
pageAuctionVehicle
(
pagination
,
account
);
// 已审核的拍卖场次
pagination
.
addFilter
(
List
.
of
(
Auction
.
AuctionState
.
PREVIEW
,
Auction
.
AuctionState
.
AUCTIONING
),
Operator
.
in
,
AuctionVehicle_
.
auctionState
);
// 查询用户所有的标签
List
<
AccountTag
>
accountTags
=
null
;
if
(
Objects
.
nonNull
(
account
))
{
accountTags
=
accountService
.
getAccountTagsByAccount
(
account
);
}
if
(
CollectionUtils
.
isEmpty
(
accountTags
))
{
pagination
.
addFilter
(
Auction
.
AccessScope
.
GLOBAL
,
AuctionVehicle_
.
auction
,
Auction_
.
accessScope
);
pagination
.
addCondition
((
root
,
query
,
builder
)
->
{
Expression
<
Double
>
randomExp
=
builder
.
function
(
"RAND"
,
Double
.
class
);
// MySQL 用 RAND()
if
(
StringUtils
.
hasText
(
cityCode
))
{
CriteriaBuilder
.
Case
<
Number
>
caseExpr
=
builder
.
selectCase
();
caseExpr
.
when
(
builder
.
like
(
root
.
get
(
AuctionVehicle_
.
auction
).
get
(
Auction_
.
cities
),
"%"
+
cityCode
+
"%"
),
1
).
otherwise
(
0
);
query
.
orderBy
(
builder
.
desc
(
caseExpr
),
builder
.
asc
(
randomExp
));
// 按随机值升序(或降序,效果相同)
}
else
{
query
.
orderBy
(
builder
.
asc
(
randomExp
));
// 按随机值升序(或降序,效果相同)
}
return
null
;
// 无过滤条件,返回所有数据并随机排序
});
}
else
{
List
<
AccountTag
>
finalAccountTags
=
accountTags
;
pagination
.
addCondition
((
root
,
query
,
builder
)
->
{
// 关联AccountTag(左连接,确保有角色关联的用户被筛选)
Join
auctionJoin
=
root
.
join
(
AuctionVehicle_
.
auction
,
JoinType
.
LEFT
);
Join
<
Auction
,
AccountTag
>
tagsJoin
=
auctionJoin
.
join
(
Auction_
.
accountTags
,
JoinType
.
LEFT
);
Predicate
tagsIn
=
tagsJoin
.
in
(
finalAccountTags
);
query
.
distinct
(
true
);
// 去重
Expression
<
Double
>
randomExp
=
builder
.
function
(
"RAND"
,
Double
.
class
);
// MySQL 用 RAND()
if
(
StringUtils
.
hasText
(
cityCode
))
{
CriteriaBuilder
.
Case
<
Number
>
caseExpr
=
builder
.
selectCase
();
caseExpr
.
when
(
builder
.
like
(
auctionJoin
.
get
(
Auction_
.
cities
),
"%"
+
cityCode
+
"%"
),
1
).
otherwise
(
0
);
query
.
orderBy
(
builder
.
desc
(
caseExpr
),
builder
.
asc
(
randomExp
));
// 按随机值升序(或降序,效果相同)
}
else
{
query
.
orderBy
(
builder
.
asc
(
randomExp
));
// 按随机值升序(或降序,效果相同)
}
return
builder
.
or
(
builder
.
equal
(
auctionJoin
.
get
(
Auction_
.
accessScope
),
Auction
.
AccessScope
.
GLOBAL
),
tagsIn
);
});
}
return
auctionService
.
pageAuctionVehicle
(
pagination
);
}
/**
...
...
@@ -156,9 +189,10 @@ public class AuctionController {
List
<
AccountTag
>
finalAccountTags
=
accountTags
;
pagination
.
addCondition
((
root
,
query
,
builder
)
->
{
// 关联AccountTag(左连接,确保有角色关联的用户被筛选)
Join
<
Auction
,
AccountTag
>
tagsJoin
=
root
.
join
(
AuctionVehicle_
.
auction
,
JoinType
.
LEFT
).
join
(
Auction_
.
accountTags
,
JoinType
.
LEFT
);
Join
auctionJoin
=
root
.
join
(
AuctionVehicle_
.
auction
,
JoinType
.
LEFT
);
Join
<
Auction
,
AccountTag
>
tagsJoin
=
auctionJoin
.
join
(
Auction_
.
accountTags
,
JoinType
.
LEFT
);
Predicate
tagsIn
=
tagsJoin
.
in
(
finalAccountTags
);
//
query.distinct(true); // 去重
query
.
distinct
(
true
);
// 去重
return
builder
.
or
(
builder
.
equal
(
root
.
get
(
AuctionVehicle_
.
auction
).
get
(
Auction_
.
accessScope
),
Auction
.
AccessScope
.
GLOBAL
),
tagsIn
);
});
}
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment