Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
dj
/
rop-dj-pe-analysis
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 c6379025
authored
Mar 10, 2026
by
zhouhaibao
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]新增兜底预警门店以及生态预警门店否的条件过滤
1 parent
1305aa98
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
104 additions
and
20 deletions
src/main/java/cn/com/glsx/dj/service/LoginService.java
src/main/java/cn/com/glsx/dj/service/LoginService.java
View file @
c637902
...
...
@@ -925,21 +925,61 @@ public class LoginService {
if
(
CommonUtil
.
isNoPermissionAndNoEmpty
(
merchantIdList
))
{
return
NO_PERMISSION_LIST
;
}
if
(
Objects
.
isNull
(
request
.
getDdyjMerchantFlag
())
)
{
return
merchantIdList
;
// 1. 调用远程接口获取兜底门店列表
RpcResponse
<
List
<
Integer
>>
backUpStoresResp
=
businessSceneAnalysisRemote
.
findBackUpStores
(
request
);
// 2. 异常处理:如果远程调用失败
if
(
backUpStoresResp
.
isFailed
())
{
log
.
error
(
"获取兜底门店失败, errorMsg: {}, response: {}"
,
backUpStoresResp
.
getMessage
(),
backUpStoresResp
);
throw
new
RpcServiceException
(
"获取兜底门店列表失败: "
+
backUpStoresResp
.
getMessage
());
}
RpcResponse
<
List
<
Integer
>>
backUpStores
=
businessSceneAnalysisRemote
.
findBackUpStores
(
request
);
if
(
backUpStores
.
isFailed
())
{
log
.
error
(
"获取兜底门店失败, backUpStores:{}"
,
backUpStores
);
throw
new
RuntimeException
(
backUpStores
.
getMessage
());
// 3. 获取结果列表
List
<
Integer
>
backupStoreIdList
=
backUpStoresResp
.
getResult
();
// 4. 边界处理:如果兜底列表为空
// 逻辑判断:
// - 如果兜底列表为空,且用户选的是"是"(1):结果为空列表。
// - 如果兜底列表为空,且用户选的是"否"(0):结果为原列表(因为没有要排除的)。
// 为了代码简洁,这里先统一判空返回 NO_PERMISSION_LIST (如果您业务上 flag=0 且列表为空时应返回全量,请移除此块或调整逻辑)
if
(
CollectionUtils
.
isEmpty
(
backupStoreIdList
))
{
// 如果业务含义是:没有兜底门店时,无论选什么都是无权限/空列表,则保持此处逻辑
// 如果业务含义是:选"否"时,没兜底门店就返回全部,请将此 if 块移到 flag==1 的判断内部
if
(
request
.
getDdyjMerchantFlag
()
!=
null
&&
request
.
getDdyjMerchantFlag
()
==
1
)
{
return
NO_PERMISSION_LIST
;
}
// 如果 flag=0 且列表为空,说明没有要排除的,直接返回原列表 (视具体业务需求而定,此处暂按返回原列表处理,防止误杀)
// 如果您的原逻辑是只要查不到兜底列表就直接返回 NO_PERMISSION_LIST,请保留原样:
// return NO_PERMISSION_LIST;
// 下面按更通用的逻辑:列表为空时,如果是"否",返回全部;如果是"是",返回空。
return
(
request
.
getDdyjMerchantFlag
()
!=
null
&&
request
.
getDdyjMerchantFlag
()
==
1
)
?
NO_PERMISSION_LIST
:
merchantIdList
;
}
List
<
Integer
>
backupMerchantIdList
=
backUpStores
.
getResult
();
if
(
CollectionUtils
.
isEmpty
(
backupMerchantIdList
))
{
return
NO_PERMISSION_LIST
;
// 5. 性能优化:转换为 HashSet,将查找复杂度从 O(N) 降为 O(1)
Set
<
Integer
>
backupStoreSet
=
new
HashSet
<>(
backupStoreIdList
);
// 6. 核心过滤逻辑
Byte
flag
=
request
.
getDdyjMerchantFlag
();
if
(
flag
!=
null
&&
flag
==
1
)
{
// 场景:1.是 (兜底预警门店)
// 逻辑:保留 【在】 兜底列表中的门店 (交集)
log
.
info
(
"执行兜底预警过滤模式,保留兜底门店。原始数量: {}, 兜底库数量: {}"
,
merchantIdList
.
size
(),
backupStoreSet
.
size
());
return
merchantIdList
.
stream
()
.
filter
(
backupStoreSet:
:
contains
)
.
collect
(
Collectors
.
toList
());
}
else
{
// 场景:0.否 (非兜底预警门店) 或 默认情况
// 逻辑:保留 【不在】 兜底列表中的门店 (差集) -> 您要求的逻辑
log
.
info
(
"执行非兜底预警过滤模式,剔除兜底门店。原始数量: {}, 兜底库数量: {}"
,
merchantIdList
.
size
(),
backupStoreSet
.
size
());
return
merchantIdList
.
stream
()
.
filter
(
storeId
->
!
backupStoreSet
.
contains
(
storeId
))
.
collect
(
Collectors
.
toList
());
}
Set
<
Integer
>
backupStoreSet
=
new
HashSet
<>(
backupMerchantIdList
);
// 转换为 HashSet,查找复杂度 O(1)
return
merchantIdList
.
stream
().
filter
(
backupStoreSet:
:
contains
).
collect
(
Collectors
.
toList
());
}
...
...
@@ -951,17 +991,61 @@ public class LoginService {
return
merchantIdList
;
}
RpcResponse
<
List
<
Integer
>>
delayWarningStore
=
businessSceneAnalysisRemote
.
getDelayWarningStore
(
req
);
if
(
delayWarningStore
.
isFailed
())
{
log
.
error
(
"获取生态预警门店失败, backUpStores:{}"
,
delayWarningStore
);
throw
new
RuntimeException
(
delayWarningStore
.
getMessage
());
// 1. 调用远程接口获取生态预警门店列表
// 注意:请确认 req 中是否有对应的 flag 字段,这里假设为 getIsDelayWarningFlag()
RpcResponse
<
List
<
Integer
>>
delayWarningResp
=
businessSceneAnalysisRemote
.
getDelayWarningStore
(
req
);
// 2. 异常处理
if
(
delayWarningResp
.
isFailed
())
{
log
.
error
(
"获取生态预警门店失败, response: {}"
,
delayWarningResp
);
throw
new
RuntimeException
(
"获取生态预警门店列表失败: "
+
delayWarningResp
.
getMessage
());
}
List
<
Integer
>
result
=
delayWarningStore
.
getResult
();
if
(
CollectionUtils
.
isEmpty
(
result
))
{
return
NO_PERMISSION_LIST
;
// 3. 获取结果
List
<
Integer
>
warningStoreList
=
delayWarningResp
.
getResult
();
// 4. 获取筛选标志位 (请根据实际 DTO 字段名修改,例如: getIsDelayWarning(), getFlag() 等)
// 假设 1 代表"是",0 或 null 代表"否"
Byte
flag
=
req
.
getStyjMerchantFlag
();
// 5. 处理空列表情况
if
(
CollectionUtils
.
isEmpty
(
warningStoreList
))
{
// 如果预警列表为空:
// - 选"是":结果为空 (因为没有命中的) -> 返回 NO_PERMISSION_LIST
// - 选"否":结果为全部 (因为没有要排除的) -> 返回 merchantIdList
if
(
flag
!=
null
&&
flag
==
1
)
{
return
NO_PERMISSION_LIST
;
}
else
{
// 选"否"且无预警名单,直接返回原列表,无需过滤
return
merchantIdList
;
}
}
Set
<
Integer
>
backupStoreSet
=
new
HashSet
<>(
result
);
// 转换为 HashSet,查找复杂度 O(1)
return
merchantIdList
.
stream
().
filter
(
backupStoreSet:
:
contains
).
collect
(
Collectors
.
toList
());
// 6. 转换为 HashSet 提升性能 O(1)
Set
<
Integer
>
warningStoreSet
=
new
HashSet
<>(
warningStoreList
);
// 7. 核心过滤逻辑
if
(
flag
!=
null
&&
flag
==
1
)
{
// 场景:1.是 (只看生态预警门店)
// 逻辑:保留【在】预警列表中的门店
log
.
info
(
"执行生态预警过滤[是],原始数量: {}, 预警库数量: {}, 结果数量: {}"
,
merchantIdList
.
size
(),
warningStoreSet
.
size
(),
merchantIdList
.
stream
().
filter
(
warningStoreSet:
:
contains
).
count
());
return
merchantIdList
.
stream
()
.
filter
(
warningStoreSet:
:
contains
)
.
collect
(
Collectors
.
toList
());
}
else
{
// 场景:0.否 (不看生态预警门店 / 排除预警门店)
// 逻辑:保留【不在】预警列表中的门店 (取反)
log
.
info
(
"执行生态预警过滤[否],原始数量: {}, 预警库数量: {}, 结果数量: {}"
,
merchantIdList
.
size
(),
warningStoreSet
.
size
(),
merchantIdList
.
stream
().
filter
(
id
->
!
warningStoreSet
.
contains
(
id
)).
count
());
return
merchantIdList
.
stream
()
.
filter
(
storeId
->
!
warningStoreSet
.
contains
(
storeId
))
.
collect
(
Collectors
.
toList
());
}
}
}
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