Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
haoban-manage3.0
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
haoban3.0
haoban-manage3.0
Commits
4c094e14
Commit
4c094e14
authored
May 24, 2021
by
fudahua
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
批量处理关联关系
parent
baa8291d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
11 deletions
+72
-11
TabHaobanStoreRelationMapper.java
...nage/service/dao/mapper/TabHaobanStoreRelationMapper.java
+9
-0
StoreRangeServiceImpl.java
...an/manage/service/service/impl/StoreRangeServiceImpl.java
+50
-11
TabHaobanStoreRelationMapper.xml
...rc/main/resources/mapper/TabHaobanStoreRelationMapper.xml
+13
-0
No files found.
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/dao/mapper/TabHaobanStoreRelationMapper.java
View file @
4c094e14
...
@@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.Mapper;
...
@@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.Mapper;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Set
;
@Mapper
@Mapper
public
interface
TabHaobanStoreRelationMapper
{
public
interface
TabHaobanStoreRelationMapper
{
...
@@ -64,6 +65,14 @@ public interface TabHaobanStoreRelationMapper {
...
@@ -64,6 +65,14 @@ public interface TabHaobanStoreRelationMapper {
public
int
deleteAllStoreRalation
(
@Param
(
"enterpriseId"
)
String
enterpriseId
);
public
int
deleteAllStoreRalation
(
@Param
(
"enterpriseId"
)
String
enterpriseId
);
/**
/**
* 删除门店
*
* @param enterpriseId
* @return
*/
public
int
deleteStoreRalationByStoreIds
(
@Param
(
"enterpriseId"
)
String
enterpriseId
,
Set
<
String
>
storeIds
);
/**
* 所有门店id
* 所有门店id
*
*
* @param wxEnterpriseId
* @param wxEnterpriseId
...
...
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/service/impl/StoreRangeServiceImpl.java
View file @
4c094e14
...
@@ -113,15 +113,25 @@ public class StoreRangeServiceImpl implements StoreRangeService {
...
@@ -113,15 +113,25 @@ public class StoreRangeServiceImpl implements StoreRangeService {
return
true
;
return
true
;
}
}
String
enterpriseId
=
list
.
get
(
0
).
getEnterpriseId
();
String
enterpriseId
=
list
.
get
(
0
).
getEnterpriseId
();
//导购绑定列表 容错处理
List
<
StaffClerkRelationDTO
>
staffClerkRelationDTOS
=
staffClerkRelationService
.
listBindStoreIdByEnterpriseId
(
enterpriseId
);
Map
<
String
,
Set
<
String
>>
oldStaffStoreIdByWxEidMap
=
staffClerkRelationDTOS
.
stream
().
collect
(
Collectors
.
groupingBy
(
StaffClerkRelationDTO:
:
getWxEnterpriseId
,
Collectors
.
mapping
(
dto
->
dto
.
getStoreId
(),
Collectors
.
toSet
())));
//根据wxEnterpriseId 分组
//根据wxEnterpriseId 分组
Map
<
String
,
Set
<
String
>>
newStoreIdBywxEnterpriseMap
=
list
.
stream
().
collect
(
Collectors
.
groupingBy
(
TabStoreRelation:
:
getWxEnterpriseId
,
Collectors
.
mapping
(
dto
->
dto
.
getStoreId
(),
Collectors
.
toSet
())));
Map
<
String
,
Set
<
String
>>
newStoreIdBywxEnterpriseMap
=
list
.
stream
().
collect
(
Collectors
.
groupingBy
(
TabStoreRelation:
:
getWxEnterpriseId
,
Collectors
.
mapping
(
dto
->
dto
.
getStoreId
(),
Collectors
.
toSet
())));
//所有就的门店old绑定列表
//所有就的门店old绑定列表
Map
<
String
,
Set
<
String
>>
oldStoreIdBywxEnterpriseMap
=
getOldStoreIdsByWxEnterpriseId
(
enterpriseId
);
Map
<
String
,
Set
<
String
>>
oldStoreIdBywxEnterpriseMap
=
getOldStoreIdsByWxEnterpriseId
(
enterpriseId
,
oldStaffStoreIdByWxEidMap
);
//需要解绑门店
Set
<
String
>
needUnBindStoreIds
=
new
HashSet
<>();
Set
<
String
>
needUnBindStoreIds
=
new
HashSet
<>();
//需要新增权限门店
Set
<
String
>
needAddStoreIds
=
new
HashSet
<>();
oldStoreIdBywxEnterpriseMap
.
forEach
((
wxEid
,
oldStoreIds
)
->
{
oldStoreIdBywxEnterpriseMap
.
forEach
((
wxEid
,
oldStoreIds
)
->
{
Set
<
String
>
newStoreIds
=
newStoreIdBywxEnterpriseMap
.
get
(
wxEid
);
Set
<
String
>
newStoreIds
=
newStoreIdBywxEnterpriseMap
.
get
(
wxEid
);
if
(
CollectionUtils
.
isEmpty
(
newStoreIds
))
{
if
(
CollectionUtils
.
isEmpty
(
newStoreIds
))
{
//没有新的 老的都需要删除
needUnBindStoreIds
.
addAll
(
oldStoreIds
);
return
;
return
;
}
}
Sets
.
SetView
<
String
>
needDelStoreIds
=
Sets
.
difference
(
oldStoreIds
,
newStoreIds
);
Sets
.
SetView
<
String
>
needDelStoreIds
=
Sets
.
difference
(
oldStoreIds
,
newStoreIds
);
...
@@ -129,18 +139,47 @@ public class StoreRangeServiceImpl implements StoreRangeService {
...
@@ -129,18 +139,47 @@ public class StoreRangeServiceImpl implements StoreRangeService {
logger
.
info
(
"wxEnterpriseId:{},{}"
,
wxEid
,
JSONObject
.
toJSONString
(
needDelStoreIds
));
logger
.
info
(
"wxEnterpriseId:{},{}"
,
wxEid
,
JSONObject
.
toJSONString
(
needDelStoreIds
));
Set
<
String
>
mid
=
needDelStoreIds
.
stream
().
collect
(
Collectors
.
toSet
());
Set
<
String
>
mid
=
needDelStoreIds
.
stream
().
collect
(
Collectors
.
toSet
());
needUnBindStoreIds
.
addAll
(
mid
);
needUnBindStoreIds
.
addAll
(
mid
);
//需要新增
Set
<
String
>
old
=
oldStaffStoreIdByWxEidMap
.
get
(
wxEid
);
if
(
CollectionUtils
.
isEmpty
(
old
))
{
needAddStoreIds
.
addAll
(
newStoreIds
);
return
;
}
Sets
.
SetView
<
String
>
needAdd
=
Sets
.
difference
(
newStoreIds
,
old
);
needAddStoreIds
.
addAll
(
needAdd
);
});
});
//这些门店解除绑定
//这些门店解除绑定
staffClerkRelationService
.
delBindByStoreIds
(
null
,
needUnBindStoreIds
,
optStaffId
,
channelCode
);
staffClerkRelationService
.
delBindByStoreIds
(
null
,
needUnBindStoreIds
,
optStaffId
,
channelCode
);
//先删除 后新增
// //先删除 后新增
tabHaobanStoreRelationMapper
.
deleteAllStoreRalation
(
enterpriseId
);
// tabHaobanStoreRelationMapper.deleteAllStoreRalation(enterpriseId);
//批量插入
// //批量插入
insertStoreRelationBatch
(
list
);
// insertStoreRelationBatch(list);
//批量处理关联关系
dealStoreRelation
(
list
,
enterpriseId
,
needUnBindStoreIds
,
needAddStoreIds
);
return
true
;
return
true
;
}
}
private
void
dealStoreRelation
(
List
<
TabStoreRelation
>
storeRelations
,
String
enterpriseId
)
{
/**
//todo 动态删除
* 批量处理关联关系
*
* @param storeRelations
* @param enterpriseId
* @param delStoreIds
* @param addStoreIds
*/
private
void
dealStoreRelation
(
List
<
TabStoreRelation
>
storeRelations
,
String
enterpriseId
,
Set
<
String
>
delStoreIds
,
Set
<
String
>
addStoreIds
)
{
//先删除 后新增
if
(
CollectionUtils
.
isNotEmpty
(
delStoreIds
))
{
tabHaobanStoreRelationMapper
.
deleteStoreRalationByStoreIds
(
enterpriseId
,
delStoreIds
);
}
if
(
CollectionUtils
.
isNotEmpty
(
addStoreIds
))
{
insertStoreRelationBatch
(
storeRelations
);
}
else
{
List
<
TabStoreRelation
>
adds
=
storeRelations
.
stream
().
filter
(
dto
->
addStoreIds
.
contains
(
dto
.
getStoreId
())).
collect
(
Collectors
.
toList
());
//批量插入
insertStoreRelationBatch
(
adds
);
}
}
}
/**
/**
...
@@ -167,7 +206,7 @@ public class StoreRangeServiceImpl implements StoreRangeService {
...
@@ -167,7 +206,7 @@ public class StoreRangeServiceImpl implements StoreRangeService {
* @param enterpriseId
* @param enterpriseId
* @return
* @return
*/
*/
private
Map
<
String
,
Set
<
String
>>
getOldStoreIdsByWxEnterpriseId
(
String
enterpriseId
)
{
private
Map
<
String
,
Set
<
String
>>
getOldStoreIdsByWxEnterpriseId
(
String
enterpriseId
,
Map
<
String
,
Set
<
String
>>
oldStaffStoreIdByWxEidMap
)
{
Map
<
String
,
Set
<
String
>>
ret
=
new
HashMap
<>();
Map
<
String
,
Set
<
String
>>
ret
=
new
HashMap
<>();
Set
<
String
>
wxEnterpriseIds
=
new
HashSet
<>();
Set
<
String
>
wxEnterpriseIds
=
new
HashSet
<>();
...
@@ -179,9 +218,9 @@ public class StoreRangeServiceImpl implements StoreRangeService {
...
@@ -179,9 +218,9 @@ public class StoreRangeServiceImpl implements StoreRangeService {
}
}
//导购绑定列表
//导购绑定列表
List
<
StaffClerkRelationDTO
>
staffClerkRelationDTOS
=
staffClerkRelationService
.
listBindStoreIdByEnterpriseId
(
enterpriseId
);
//
List<StaffClerkRelationDTO> staffClerkRelationDTOS = staffClerkRelationService.listBindStoreIdByEnterpriseId(enterpriseId);
Map
<
String
,
Set
<
String
>>
oldStaffStoreIdByWxEidMap
=
staffClerkRelationDTOS
.
stream
().
collect
(
Collectors
.
groupingBy
(
StaffClerkRelationDTO:
:
getWxEnterpriseId
,
Collectors
.
mapping
(
dto
->
dto
.
getStoreId
(),
Collectors
.
toSet
())));
//
Map<String, Set<String>> oldStaffStoreIdByWxEidMap = staffClerkRelationDTOS.stream().collect(Collectors.groupingBy(StaffClerkRelationDTO::getWxEnterpriseId, Collectors.mapping(dto -> dto.getStoreId(), Collectors.toSet())));
if
(
CollectionUtils
.
isNotEmpty
(
staffClerkRelationDTOS
)
)
{
if
(
oldStaffStoreIdByWxEidMap
!=
null
&&
oldStaffStoreIdByWxEidMap
.
size
()
>
0
)
{
wxEnterpriseIds
.
addAll
(
oldStaffStoreIdByWxEidMap
.
keySet
());
wxEnterpriseIds
.
addAll
(
oldStaffStoreIdByWxEidMap
.
keySet
());
}
}
...
...
haoban-manage3-service/src/main/resources/mapper/TabHaobanStoreRelationMapper.xml
View file @
4c094e14
...
@@ -195,4 +195,16 @@
...
@@ -195,4 +195,16 @@
where enterprise_id=#{enterpriseId}
where enterprise_id=#{enterpriseId}
and status_flag=1
and status_flag=1
</update>
</update>
<update
id=
"deleteStoreRalationByStoreIds"
>
update tab_haoban_store_relation
set
status_flag = 0,
update_time = now()
where enterprise_id=#{enterpriseId}
<foreach
collection=
"storeIds"
open=
"("
close=
")"
separator=
","
item=
"item"
>
#{item}
</foreach>
and status_flag=1
</update>
</mapper>
</mapper>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment