用户列表导出接口1

This commit is contained in:
gong
2026-01-28 13:57:30 +08:00
parent 9e2cf024eb
commit c984867e4e
2 changed files with 10 additions and 11 deletions

View File

@@ -97,6 +97,12 @@ public class ShopUserController {
return CzgResult.success(shopUserService.getPage(key, isVip, amount));
}
/**
* 导出用户列表
*
* @param key 昵称或手机号
* @param isVip 0 非vip 1 vip
*/
@GetMapping("/export")
public void exportUserList(String key, Integer isVip, HttpServletResponse response) {
shopUserService.exportUserList(key, isVip, response);

View File

@@ -3,8 +3,8 @@ package com.czg.service.account.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONObject;
import com.czg.account.dto.shopuser.*;
import com.czg.account.entity.ShopInfo;
import com.czg.account.entity.ShopUser;
import com.czg.account.entity.UserInfo;
import com.czg.account.service.AShopUserService;
@@ -37,7 +37,6 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@@ -131,19 +130,13 @@ public class AShopUserServiceImpl implements AShopUserService {
@Override
public void exportUserList(String key, Integer isVip, HttpServletResponse response) {
Long mainIdByShopId = shopInfoService.getMainIdByShopId(StpKit.USER.getShopId());
ShopInfo shopInfo = shopInfoService.getById(StpKit.USER.getShopId());
PageHelper.startPage(PageUtil.buildPageHelp());
List<ShopUserDTO> dtoList = shopUserMapper.selectPageByKeyAndIsVip(mainIdByShopId, isVip, key, null);
// 将 dtoList 转换为 ShopUserExportDTO 列表
List<ShopUserExportDTO> exportList = new ArrayList<>();
for (ShopUserDTO shopUserDTO : dtoList) {
ShopUserExportDTO exportDTO = BeanUtil.copyProperties(shopUserDTO, ShopUserExportDTO.class);
exportDTO.setVipRemark((isVip != null && isVip.equals(1)) ? "" : "");
exportList.add(exportDTO);
}
log.info(JSONObject.toJSONString(exportList));
ExcelExportUtil.exportToResponse(exportList, ShopUserExportDTO.class, "店铺用户列表.xlsx", response);
List<ShopUserExportDTO> exportList = BeanUtil.copyToList(dtoList, ShopUserExportDTO.class);
ExcelExportUtil.exportToResponse(exportList, ShopUserExportDTO.class, shopInfo == null ? "店铺用户列表" : shopInfo.getShopName() + "_用户列表", response);
}