|
|
@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.netease.yidun.sdk.anticheat.v3.AnticheatCheckRequest;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.tuple.Triple;
|
|
|
@@ -21,6 +22,7 @@ import shop.alien.entity.result.R;
|
|
|
import shop.alien.entity.store.*;
|
|
|
import shop.alien.entity.store.excelVo.StoreUserExcelVo;
|
|
|
import shop.alien.entity.store.excelVo.util.ExcelGenerator;
|
|
|
+import shop.alien.entity.store.vo.StoreSubExcelVo;
|
|
|
import shop.alien.entity.store.vo.StoreUserVo;
|
|
|
import shop.alien.entity.store.vo.WebSocketVo;
|
|
|
import shop.alien.mapper.*;
|
|
|
@@ -44,6 +46,7 @@ import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 二期-门店用户 服务实现类
|
|
|
@@ -397,21 +400,86 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public R<IPage<StoreUserVo>> getStoreUserList(int pageNum, int pageSize, String id, String phone, Integer status) {
|
|
|
+ public R<IPage<StoreUserVo>> getStoreUserList(int pageNum, int pageSize, String id, String phone, Integer status,Integer accountType) {
|
|
|
+
|
|
|
IPage<StoreUser> page = new Page<>(pageNum, pageSize);
|
|
|
+ IPage<StoreUserVo> storeUserVoIPage = new Page<>();
|
|
|
+
|
|
|
+ // 查询子账号(accountType == 2)
|
|
|
+ if (accountType == 2) {
|
|
|
+ // 构建子账号查询条件
|
|
|
+ LambdaQueryWrapper<StoreUser> subAccountWrapper = new LambdaQueryWrapper<>();
|
|
|
+ subAccountWrapper.eq(StoreUser::getAccountType, 2) // 子账号类型
|
|
|
+ .like(!StringUtils.isEmpty(id), StoreUser::getId, id)
|
|
|
+ .and(StringUtils.isNotEmpty(phone), qw -> qw
|
|
|
+ .like(StoreUser::getPhone, phone) // 子账号手机号模糊匹配
|
|
|
+ .or()
|
|
|
+ .exists("SELECT 1 FROM store_user su WHERE su.id = " +
|
|
|
+ "store_user.sub_account_id AND su.phone LIKE CONCAT('%', '" + phone + "', '%')") // 主账号手机号模糊匹配
|
|
|
+ )
|
|
|
+ .eq(status != null, StoreUser::getStatus, status)
|
|
|
+ .orderByDesc(StoreUser::getCreatedTime);
|
|
|
+
|
|
|
+ IPage<StoreUser> subAccountsPage = storeUserMapper.selectPage(page, subAccountWrapper);
|
|
|
+ BeanUtils.copyProperties(subAccountsPage, storeUserVoIPage);
|
|
|
+
|
|
|
+ List<StoreUserVo> resultRecords = new ArrayList<>();
|
|
|
+ for (StoreUser subAccount : subAccountsPage.getRecords()) {
|
|
|
+ StoreUserVo storeUserVo = new StoreUserVo();
|
|
|
+ BeanUtils.copyProperties(subAccount, storeUserVo);
|
|
|
+
|
|
|
+ // 查询主账号信息(通过 subAccountId 关联)
|
|
|
+ if (subAccount.getSubAccountId() != null) {
|
|
|
+ StoreUser mainAccount = storeUserMapper.selectById(subAccount.getSubAccountId());
|
|
|
+ if (mainAccount != null) {
|
|
|
+ // 设置主账号联系电话
|
|
|
+ storeUserVo.setParentAccountPhone(mainAccount.getPhone());
|
|
|
+ storeUserVo.setParentAccountId(mainAccount.getId());
|
|
|
+ storeUserVo.setParentAccountName(mainAccount.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 不返回密码
|
|
|
+ storeUserVo.setPassword(null);
|
|
|
+ storeUserVo.setPayPassword(null);
|
|
|
+
|
|
|
+ resultRecords.add(storeUserVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ storeUserVoIPage.setRecords(resultRecords);
|
|
|
+ return R.data(storeUserVoIPage);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询主账号(accountType == 1)
|
|
|
LambdaQueryWrapper<StoreUser> storeUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
- storeUserLambdaQueryWrapper.like(!StringUtils.isEmpty(id), StoreUser::getId, id);
|
|
|
- storeUserLambdaQueryWrapper.like(!StringUtils.isEmpty(phone), StoreUser::getPhone, phone);
|
|
|
- storeUserLambdaQueryWrapper.eq(status != null, StoreUser::getStatus, status);
|
|
|
- storeUserLambdaQueryWrapper.orderByDesc(StoreUser::getCreatedTime);
|
|
|
+ storeUserLambdaQueryWrapper.like(!StringUtils.isEmpty(id), StoreUser::getId, id)
|
|
|
+ .like(!StringUtils.isEmpty(phone), StoreUser::getPhone, phone)
|
|
|
+ .eq(status != null, StoreUser::getStatus, status)
|
|
|
+ .eq(StoreUser::getAccountType, accountType)
|
|
|
+ .orderByDesc(StoreUser::getCreatedTime);
|
|
|
+
|
|
|
IPage<StoreUser> storeUsers = storeUserMapper.selectPage(page, storeUserLambdaQueryWrapper);
|
|
|
- IPage<StoreUserVo> storeUserVoIPage = new Page<>();
|
|
|
BeanUtils.copyProperties(storeUsers, storeUserVoIPage);
|
|
|
+
|
|
|
for (StoreUser storeUser : storeUserVoIPage.getRecords()) {
|
|
|
- //不返回密码
|
|
|
+ // 不返回密码
|
|
|
storeUser.setPassword(null);
|
|
|
storeUser.setPayPassword(null);
|
|
|
+
|
|
|
+ // 如果是主账号,统计子账号数量
|
|
|
+ if (accountType == 1) {
|
|
|
+ List<StoreUser> childAccounts = getChildAccountsByParentId(String.valueOf(storeUser.getId()));
|
|
|
+ Integer childCount = childAccounts != null ? childAccounts.size() : 0;
|
|
|
+ storeUser.setChildAccountCount(childCount);
|
|
|
+ if (childAccounts != null && !childAccounts.isEmpty()) {
|
|
|
+ List<String> childPhoneNumbers = childAccounts.stream()
|
|
|
+ .map(StoreUser::getPhone)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ storeUser.setChildPhoneNumbers(childPhoneNumbers);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
return R.data(storeUserVoIPage);
|
|
|
}
|
|
|
|
|
|
@@ -481,21 +549,26 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String exportExcel(String id, String phone, String status) throws IOException {
|
|
|
+ public String exportExcel(String id, String phone, String status, Integer accountType) throws IOException {
|
|
|
// 定义格式化模式
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
- // 先将 Date 转换为 Instant
|
|
|
+ if (accountType==1){
|
|
|
List<StoreUser> storeUsers = storeUserMapper.selectList(
|
|
|
new LambdaQueryWrapper<StoreUser>()
|
|
|
.like(StringUtils.isNotEmpty(id), StoreUser::getId, id)
|
|
|
.like(StringUtils.isNotEmpty(phone), StoreUser::getPhone, phone)
|
|
|
.eq(StringUtils.isNotEmpty(status), StoreUser::getStatus, status)
|
|
|
+ .eq(StoreUser::getAccountType, 1)
|
|
|
+ .orderByDesc(StoreUser::getCreatedTime)
|
|
|
);
|
|
|
+
|
|
|
List<StoreUserExcelVo> storeUserExcelVoList = new ArrayList<>();
|
|
|
int serialNumber = 0;
|
|
|
for (StoreUser storeUser : storeUsers) {
|
|
|
StoreUserExcelVo storeUserExcelVo = new StoreUserExcelVo();
|
|
|
storeUserExcelVo.setSerialNumber(++serialNumber);
|
|
|
+
|
|
|
+ Integer currentUserId = storeUser.getId();
|
|
|
BeanUtils.copyProperties(storeUser, storeUserExcelVo);
|
|
|
Instant instant = storeUser.getCreatedTime().toInstant();
|
|
|
// 格式化时间
|
|
|
@@ -503,13 +576,51 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
storeUserExcelVo.setCreatedTime(formattedTime);
|
|
|
//格式化状态
|
|
|
storeUserExcelVo.setStatus(storeUser.getStatus() == 0 ? "启用" : "禁用");
|
|
|
+ List<StoreUser> childAccounts = getChildAccountsByParentId(String.valueOf(currentUserId));
|
|
|
+ Integer childCount = childAccounts != null ? childAccounts.size() : 0;
|
|
|
+ storeUserExcelVo.setChildAccountCount(childCount);
|
|
|
storeUserExcelVoList.add(storeUserExcelVo);
|
|
|
}
|
|
|
String fileName = UUID.randomUUID().toString().replace("-", "");
|
|
|
String filePath = ExcelGenerator.generateExcel(excelPath + excelGeneratePath + fileName + ".xlsx", storeUserExcelVoList, StoreUserExcelVo.class);
|
|
|
return aliOSSUtil.uploadFile(new File(filePath), "excel/" + fileName + ".xlsx");
|
|
|
+ }
|
|
|
+ List<StoreUser> storeUsers = storeUserMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<StoreUser>()
|
|
|
+ .like(StringUtils.isNotEmpty(id), StoreUser::getId, id)
|
|
|
+ .like(StringUtils.isNotEmpty(phone), StoreUser::getPhone, phone)
|
|
|
+ .eq(StringUtils.isNotEmpty(status), StoreUser::getStatus, status)
|
|
|
+ .eq(StoreUser::getAccountType, 2)
|
|
|
+ .orderByDesc(StoreUser::getCreatedTime)
|
|
|
+ );
|
|
|
+ List<StoreSubExcelVo> storeUserExcelVoList = new ArrayList<>();
|
|
|
+ int serialNumber = 0;
|
|
|
+ for (StoreUser subAccount : storeUsers) {
|
|
|
+ StoreSubExcelVo storeUserExcelVo = new StoreSubExcelVo();
|
|
|
+ storeUserExcelVo.setSerialNumber(++serialNumber);
|
|
|
+ BeanUtils.copyProperties(subAccount, storeUserExcelVo);
|
|
|
+ if (subAccount.getSubAccountId() != null){
|
|
|
+ StoreUser mainAccount = storeUserMapper.selectById(subAccount.getSubAccountId());
|
|
|
+ if (mainAccount != null){
|
|
|
+ storeUserExcelVo.setId(mainAccount.getId());
|
|
|
+ storeUserExcelVo.setParentAccountPhone(mainAccount.getPhone());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Instant instant = subAccount.getCreatedTime().toInstant();
|
|
|
+ // 格式化时间
|
|
|
+ String formattedTime = instant.atZone(ZoneId.systemDefault()).toLocalDateTime().format(formatter);
|
|
|
+ storeUserExcelVo.setCreatedTime(formattedTime);
|
|
|
+ //格式化状态
|
|
|
+ storeUserExcelVo.setStatus(subAccount.getStatus() == 0 ? "启用" : "禁用");
|
|
|
+ storeUserExcelVoList.add(storeUserExcelVo);
|
|
|
+ }
|
|
|
+ String fileName = UUID.randomUUID().toString().replace("-", "");
|
|
|
+ String filePath = ExcelGenerator.generateExcel(excelPath + excelGeneratePath + fileName + ".xlsx", storeUserExcelVoList, StoreSubExcelVo.class);
|
|
|
+ return aliOSSUtil.uploadFile(new File(filePath), "excel/" + fileName + ".xlsx");
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 注册校验
|
|
|
*
|
|
|
@@ -794,4 +905,50 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
return R.data(returnMap);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<StoreUser> getSubAccountsByMainAccountId(Integer mainAccountId) {
|
|
|
+ LambdaQueryWrapper<StoreUser> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(StoreUser::getAccountType, 2) // 子账号类型
|
|
|
+ .eq(StoreUser::getSubAccountId, mainAccountId) // 关联主账号ID
|
|
|
+ .eq(StoreUser::getDeleteFlag, 0) // 未删除的账号
|
|
|
+ .orderByDesc(StoreUser::getCreatedTime); // 按创建时间倒序
|
|
|
+
|
|
|
+ return storeUserMapper.selectList(queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<StoreUser> getChildAccountsByParentId(String Id) {
|
|
|
+ Integer parentId = safeParseInt(Id);
|
|
|
+ if (parentId == null) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ LambdaQueryWrapper<StoreUser> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(StoreUser::getSubAccountId, Id)
|
|
|
+ .eq(StoreUser::getAccountType, 2) // 子账号
|
|
|
+ .eq(StoreUser::getDeleteFlag, 0)
|
|
|
+ .orderByAsc(StoreUser::getCreatedTime);
|
|
|
+
|
|
|
+ List<StoreUser> result = this.list(wrapper);
|
|
|
+
|
|
|
+ // 确保返回非空集合
|
|
|
+ return result != null ? result : Collections.emptyList();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 安全解析字符串为整数
|
|
|
+ */
|
|
|
+ private Integer safeParseInt(String str) {
|
|
|
+ if (str == null || str.trim().isEmpty()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ return Integer.valueOf(str.trim());
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ log.warn("无法解析字符串为整数: {}", str);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|