|
|
@@ -41,7 +41,6 @@ import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.Duration;
|
|
|
-import java.time.Instant;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
@@ -457,14 +456,40 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
// 按子账号 id/phone/status 过滤:批量查 store_user,只保留对应子账号满足条件的 role
|
|
|
List<Integer> distinctUserIds = userRoles.stream().map(StorePlatformUserRole::getUserId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
|
|
List<StoreUser> subAccountList = distinctUserIds.isEmpty() ? Collections.emptyList() : storeUserMapper.selectBatchIds(distinctUserIds);
|
|
|
- Map<Integer, StoreUser> subAccountMap = subAccountList == null ? new HashMap<>() : subAccountList.stream().filter(u -> u.getDeleteFlag() != null && u.getDeleteFlag() == 0).collect(Collectors.toMap(StoreUser::getId, u -> u, (a, b) -> a));
|
|
|
+ // 根据 status 参数决定子账号池:选「注销中/已注销」时只保留对应状态;否则排除注销中、已注销
|
|
|
+ Map<Integer, StoreUser> subAccountMap;
|
|
|
+ if (status != null && (status == -1 || status == 2)) {
|
|
|
+ final int filterStatus = status;
|
|
|
+ subAccountMap = subAccountList == null ? new HashMap<>() : subAccountList.stream()
|
|
|
+ .filter(u -> u.getDeleteFlag() != null && u.getDeleteFlag() == 0)
|
|
|
+ .filter(u -> {
|
|
|
+ if (filterStatus == -1) return u.getStatus() != null && u.getStatus() == -1;
|
|
|
+ return (u.getStatus() != null && u.getStatus() == 2) || (u.getLogoutFlag() != null && u.getLogoutFlag() == 1);
|
|
|
+ })
|
|
|
+ .collect(Collectors.toMap(StoreUser::getId, u -> u, (a, b) -> a));
|
|
|
+ } else {
|
|
|
+ subAccountMap = subAccountList == null ? new HashMap<>() : subAccountList.stream()
|
|
|
+ .filter(u -> u.getDeleteFlag() != null && u.getDeleteFlag() == 0
|
|
|
+ && (u.getLogoutFlag() == null || u.getLogoutFlag() == 0)
|
|
|
+ && (u.getStatus() == null || (u.getStatus() != -1 && u.getStatus() != 2)))
|
|
|
+ .collect(Collectors.toMap(StoreUser::getId, u -> u, (a, b) -> a));
|
|
|
+ }
|
|
|
List<StorePlatformUserRole> filteredRoles = new ArrayList<>();
|
|
|
for (StorePlatformUserRole role : userRoles) {
|
|
|
StoreUser subAccount = subAccountMap.get(role.getUserId());
|
|
|
if (subAccount == null) continue;
|
|
|
if (StringUtils.isNotEmpty(id) && (subAccount.getId() == null || !String.valueOf(subAccount.getId()).contains(id))) continue;
|
|
|
if (StringUtils.isNotEmpty(phone) && (subAccount.getPhone() == null || !subAccount.getPhone().contains(phone))) continue;
|
|
|
- if (status != null && !status.equals(subAccount.getStatus())) continue;
|
|
|
+ // 状态筛选:选「注销中/已注销」时以 store_user 为准(已由 subAccountMap 限定);否则以 role.status 为准
|
|
|
+ int rowStatus;
|
|
|
+ if (status != null && (status == -1 || status == 2)) {
|
|
|
+ rowStatus = (subAccount.getStatus() != null && subAccount.getStatus() == -1) ? -1
|
|
|
+ : ((subAccount.getStatus() != null && subAccount.getStatus() == 2) || (subAccount.getLogoutFlag() != null && subAccount.getLogoutFlag() == 1)) ? 2
|
|
|
+ : (subAccount.getStatus() != null ? subAccount.getStatus() : 0);
|
|
|
+ } else {
|
|
|
+ rowStatus = role.getStatus() != null ? role.getStatus() : (subAccount.getStatus() != null ? subAccount.getStatus() : 0);
|
|
|
+ }
|
|
|
+ if (status != null && !status.equals(rowStatus)) continue;
|
|
|
filteredRoles.add(role);
|
|
|
}
|
|
|
filteredRoles.sort(Comparator.comparing(StorePlatformUserRole::getId, Comparator.nullsLast(Comparator.naturalOrder())));
|
|
|
@@ -513,13 +538,15 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
return R.data(storeUserVoIPage);
|
|
|
}
|
|
|
|
|
|
- // 主账号分支:直接查库返回最新 status,主账号页面展示子账号数量(按 store_platform_user_role 统计)
|
|
|
+ // 主账号分支:直接查库返回最新 status,主账号页面展示子账号数量(按 store_platform_user_role 统计);排除注销中、已注销
|
|
|
LambdaQueryWrapper<StoreUser> storeUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
storeUserLambdaQueryWrapper.eq(StoreUser::getDeleteFlag, 0)
|
|
|
.like(StringUtils.isNotEmpty(id), StoreUser::getId, id)
|
|
|
.like(StringUtils.isNotEmpty(phone), StoreUser::getPhone, phone)
|
|
|
.eq(status != null, StoreUser::getStatus, status)
|
|
|
.eq(StoreUser::getAccountType, 1)
|
|
|
+ .and(w -> w.isNull(StoreUser::getLogoutFlag).or().eq(StoreUser::getLogoutFlag, 0))
|
|
|
+ .and(w -> w.isNull(StoreUser::getStatus).or().in(StoreUser::getStatus, 0, 1))
|
|
|
.orderByDesc(StoreUser::getCreatedTime);
|
|
|
|
|
|
IPage<StoreUser> storeUsers = storeUserMapper.selectPage(page, storeUserLambdaQueryWrapper);
|
|
|
@@ -648,7 +675,7 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
@Override
|
|
|
public String exportExcel(String id, String phone, String status, Integer accountType) throws IOException {
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
- // 主账号导出:与 getStoreUserList 主账号分支一致,子账号数量按 store_platform_user_role 统计
|
|
|
+ // 主账号导出:与 getStoreUserList 主账号分支一致,子账号数量按 store_platform_user_role 统计;排除注销中、已注销
|
|
|
if (accountType == 1) {
|
|
|
LambdaQueryWrapper<StoreUser> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.eq(StoreUser::getDeleteFlag, 0)
|
|
|
@@ -656,6 +683,8 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
.like(StringUtils.isNotEmpty(phone), StoreUser::getPhone, phone)
|
|
|
.eq(StringUtils.isNotEmpty(status), StoreUser::getStatus, status)
|
|
|
.eq(StoreUser::getAccountType, 1)
|
|
|
+ .and(w -> w.isNull(StoreUser::getLogoutFlag).or().eq(StoreUser::getLogoutFlag, 0))
|
|
|
+ .and(w -> w.isNull(StoreUser::getStatus).or().in(StoreUser::getStatus, 0, 1))
|
|
|
.orderByDesc(StoreUser::getCreatedTime);
|
|
|
List<StoreUser> storeUsers = storeUserMapper.selectList(wrapper);
|
|
|
List<StoreUserExcelVo> storeUserExcelVoList = new ArrayList<>();
|
|
|
@@ -684,14 +713,43 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
}
|
|
|
List<Integer> distinctUserIds = userRoles.stream().map(StorePlatformUserRole::getUserId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
|
|
List<StoreUser> subAccountList = distinctUserIds.isEmpty() ? Collections.emptyList() : storeUserMapper.selectBatchIds(distinctUserIds);
|
|
|
- Map<Integer, StoreUser> subAccountMap = subAccountList == null ? new HashMap<>() : subAccountList.stream().filter(u -> u.getDeleteFlag() != null && u.getDeleteFlag() == 0).collect(Collectors.toMap(StoreUser::getId, u -> u, (a, b) -> a));
|
|
|
+ Integer statusInt = null;
|
|
|
+ if (StringUtils.isNotEmpty(status)) {
|
|
|
+ try { statusInt = Integer.parseInt(status.trim()); } catch (NumberFormatException ignored) { }
|
|
|
+ }
|
|
|
+ // 与 getStoreUserList 一致:选「注销中/已注销」时只保留对应状态;否则排除注销中、已注销
|
|
|
+ Map<Integer, StoreUser> subAccountMap;
|
|
|
+ if (statusInt != null && (statusInt == -1 || statusInt == 2)) {
|
|
|
+ final int filterStatus = statusInt;
|
|
|
+ subAccountMap = subAccountList == null ? new HashMap<>() : subAccountList.stream()
|
|
|
+ .filter(u -> u.getDeleteFlag() != null && u.getDeleteFlag() == 0)
|
|
|
+ .filter(u -> {
|
|
|
+ if (filterStatus == -1) return u.getStatus() != null && u.getStatus() == -1;
|
|
|
+ return (u.getStatus() != null && u.getStatus() == 2) || (u.getLogoutFlag() != null && u.getLogoutFlag() == 1);
|
|
|
+ })
|
|
|
+ .collect(Collectors.toMap(StoreUser::getId, u -> u, (a, b) -> a));
|
|
|
+ } else {
|
|
|
+ subAccountMap = subAccountList == null ? new HashMap<>() : subAccountList.stream()
|
|
|
+ .filter(u -> u.getDeleteFlag() != null && u.getDeleteFlag() == 0
|
|
|
+ && (u.getLogoutFlag() == null || u.getLogoutFlag() == 0)
|
|
|
+ && (u.getStatus() == null || (u.getStatus() != -1 && u.getStatus() != 2)))
|
|
|
+ .collect(Collectors.toMap(StoreUser::getId, u -> u, (a, b) -> a));
|
|
|
+ }
|
|
|
List<StorePlatformUserRole> filteredRoles = new ArrayList<>();
|
|
|
for (StorePlatformUserRole role : userRoles) {
|
|
|
StoreUser subAccount = subAccountMap.get(role.getUserId());
|
|
|
if (subAccount == null) continue;
|
|
|
if (StringUtils.isNotEmpty(id) && (subAccount.getId() == null || !String.valueOf(subAccount.getId()).contains(id))) continue;
|
|
|
if (StringUtils.isNotEmpty(phone) && (subAccount.getPhone() == null || !subAccount.getPhone().contains(phone))) continue;
|
|
|
- if (status != null && !status.equals(subAccount.getStatus())) continue;
|
|
|
+ int rowStatus;
|
|
|
+ if (statusInt != null && (statusInt == -1 || statusInt == 2)) {
|
|
|
+ rowStatus = (subAccount.getStatus() != null && subAccount.getStatus() == -1) ? -1
|
|
|
+ : ((subAccount.getStatus() != null && subAccount.getStatus() == 2) || (subAccount.getLogoutFlag() != null && subAccount.getLogoutFlag() == 1)) ? 2
|
|
|
+ : (subAccount.getStatus() != null ? subAccount.getStatus() : 0);
|
|
|
+ } else {
|
|
|
+ rowStatus = role.getStatus() != null ? role.getStatus() : (subAccount.getStatus() != null ? subAccount.getStatus() : 0);
|
|
|
+ }
|
|
|
+ if (statusInt != null && !statusInt.equals(rowStatus)) continue;
|
|
|
filteredRoles.add(role);
|
|
|
}
|
|
|
filteredRoles.sort(Comparator.comparing(StorePlatformUserRole::getId, Comparator.nullsLast(Comparator.naturalOrder())));
|
|
|
@@ -713,7 +771,10 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
vo.setId(subAccount.getId());
|
|
|
vo.setPhone(subAccount.getPhone());
|
|
|
vo.setCreatedTime(subAccount.getCreatedTime() != null ? subAccount.getCreatedTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime().format(formatter) : null);
|
|
|
- vo.setStatus(subAccount.getStatus() == null ? "" : (subAccount.getStatus() == 0 ? "启用" : "禁用"));
|
|
|
+ int rowStatus = (subAccount.getStatus() != null && subAccount.getStatus() == -1) ? -1
|
|
|
+ : ((subAccount.getStatus() != null && subAccount.getStatus() == 2) || (subAccount.getLogoutFlag() != null && subAccount.getLogoutFlag() == 1)) ? 2
|
|
|
+ : (role.getStatus() != null ? role.getStatus() : (subAccount.getStatus() != null ? subAccount.getStatus() : 0));
|
|
|
+ vo.setStatus(rowStatus == -1 ? "注销中" : rowStatus == 2 ? "已注销" : (rowStatus == 0 ? "启用" : "禁用"));
|
|
|
StoreUser mainAccount = role.getStoreId() == null ? null : mainAccountMap.get(role.getStoreId());
|
|
|
if (mainAccount != null) {
|
|
|
vo.setParentAccountPhone(mainAccount.getPhone());
|