feat:钱包导出

This commit is contained in:
dzc committed 2025-01-23 10:03:52 +08:00
1 parent a5bfdd6ced
commit ec5e245fb0
8 files changed
+117 -38

No files matched your search

@@ -20,6 +20,7 @@
package com.bsd.pjcloud.admin.controller; package com.bsd.pjcloud.admin.controller;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsd.pjcloud.admin.api.dto.UserDTO; import com.bsd.pjcloud.admin.api.dto.UserDTO;
@@ -3,6 +3,8 @@ package com.bsd.pjcloud.wallet.api.dto;
import com.bsd.pjcloud.wallet.api.entity.WalletManageEntity; import com.bsd.pjcloud.wallet.api.entity.WalletManageEntity;
import lombok.Data; import lombok.Data;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
@Data @Data
@@ -12,4 +14,6 @@ public class WalletManageDto extends WalletManageEntity {
private List<Long> walletIds; private List<Long> walletIds;
private LocalDateTime[] createTimeList;
} }
@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsd.pjcloud.common.core.util.R; import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.data.datascope.DataScope;
import com.bsd.pjcloud.common.data.datascope.DataScopeFuncEnum;
import com.bsd.pjcloud.common.log.annotation.SysLog; import com.bsd.pjcloud.common.log.annotation.SysLog;
import com.bsd.pjcloud.common.security.annotation.Inner; import com.bsd.pjcloud.common.security.annotation.Inner;
import com.bsd.pjcloud.common.security.service.PjcloudUser; import com.bsd.pjcloud.common.security.service.PjcloudUser;
@@ -18,6 +20,7 @@ import com.bsd.pjcloud.wallet.api.vo.WalletManageVo;
import com.bsd.pjcloud.wallet.mapper.WalletManageMapper; import com.bsd.pjcloud.wallet.mapper.WalletManageMapper;
import com.bsd.pjcloud.wallet.service.WalletCodeUseService; import com.bsd.pjcloud.wallet.service.WalletCodeUseService;
import com.bsd.pjcloud.wallet.service.WalletManageService; import com.bsd.pjcloud.wallet.service.WalletManageService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import com.bsd.pjcloud.common.excel.annotation.ResponseExcel; import com.bsd.pjcloud.common.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.security.SecurityRequirement;
@@ -112,7 +115,9 @@ public class WalletManageController {
PjcloudUser user = SecurityUtils.getUser(); PjcloudUser user = SecurityUtils.getUser();
WalletManageDto dto = new WalletManageDto(); WalletManageDto dto = new WalletManageDto();
dto.setUserId(user.getId()); dto.setUserId(user.getId());
return R.ok(walletManageService.pageJoin(page, dto)); DataScope dataScope = new DataScope();
dataScope.func(DataScopeFuncEnum.ALL);
return R.ok(walletManageService.scopePageList(page, dto, dataScope));
} }
@Operation(summary = "分页查询", description = "分页查询") @Operation(summary = "分页查询", description = "分页查询")
@@ -142,7 +147,7 @@ public class WalletManageController {
@GetMapping("/page-join") @GetMapping("/page-join")
@PreAuthorize("@pms.hasPermission('wallet_walletManage_view')") @PreAuthorize("@pms.hasPermission('wallet_walletManage_view')")
public R getWalletManagePageJoin(@ParameterObject Page page, @ParameterObject WalletManageDto dto) { public R getWalletManagePageJoin(@ParameterObject Page page, @ParameterObject WalletManageDto dto) {
return R.ok(walletManageService.scopePageList(page, dto)); return R.ok(walletManageService.scopePageList(page, dto, DataScope.of()));
} }
@Operation(summary = "通过id查询", description = "通过id查询") @Operation(summary = "通过id查询", description = "通过id查询")
@@ -175,11 +180,10 @@ public class WalletManageController {
public R removeById(@RequestBody Long[] ids) { public R removeById(@RequestBody Long[] ids) {
return R.ok(walletManageService.removeBatchByIds(CollUtil.toList(ids))); return R.ok(walletManageService.removeBatchByIds(CollUtil.toList(ids)));
} }
@ResponseExcel
@GetMapping("/export") @GetMapping("/export")
@PreAuthorize("@pms.hasPermission('wallet_walletManage_export')") @PreAuthorize("@pms.hasPermission('wallet_walletManage_export')")
public List<WalletManageEntity> export(WalletManageEntity walletManage, Long[] ids) { public void export(HttpServletResponse response, @ParameterObject Page page, @ParameterObject WalletManageDto dto) {
return walletManageService.list(Wrappers.lambdaQuery(walletManage).in(ArrayUtil.isNotEmpty(ids), WalletManageEntity::getId, ids)); walletManageService.export(response, page, dto);
} }
} }
@@ -149,28 +149,28 @@ public class WalletTransactionController {
@Operation(summary = "充值导出", description = "充值导出") @Operation(summary = "充值导出", description = "充值导出")
@GetMapping("/export-cz") @GetMapping("/export-cz")
@PreAuthorize("@pms.hasPermission('wallet_walletTransaction_export')") @PreAuthorize("@pms.hasPermission('wallet_walletTransaction_export')")
public void exportCz(HttpServletResponse response, WalletTransactionDto dto) { public void exportCz(HttpServletResponse response, @ParameterObject Page page, WalletTransactionDto dto) {
dto.setBizTypes(List.of(WalletBizEnum.RECHARGE.getCode())); dto.setBizTypes(List.of(WalletBizEnum.RECHARGE.getCode()));
List<WalletTransactionVo> list = walletTransactionService.pageList(dto); List<WalletTransactionVo> list = walletTransactionService.scopePageList(page, dto, DataScope.of()).getRecords();
walletTransactionService.exportByTemplate(response, dto, "file/个人充值明细.xlsx", list); walletTransactionService.exportByTemplate(response, dto, "file/个人充值明细.xlsx", list);
} }
@Operation(summary = "消费导出", description = "消费导出") @Operation(summary = "消费导出", description = "消费导出")
@GetMapping("/export-xf") @GetMapping("/export-xf")
@PreAuthorize("@pms.hasPermission('wallet_walletTransaction_export')") @PreAuthorize("@pms.hasPermission('wallet_walletTransaction_export')")
public void exportXf(HttpServletResponse response, WalletTransactionDto dto) { public void exportXf(HttpServletResponse response, @ParameterObject Page page, WalletTransactionDto dto) {
dto.setBizTypes(List.of(WalletBizEnum.PAYMENT.getCode())); dto.setBizTypes(List.of(WalletBizEnum.PAYMENT.getCode()));
List<WalletTransactionVo> list = walletTransactionService.pageList(dto); List<WalletTransactionVo> list = walletTransactionService.scopePageList(page, dto, DataScope.of()).getRecords();
walletTransactionService.exportByTemplate(response, dto, "file/个人消费明细.xlsx", list); walletTransactionService.exportByTemplate(response, dto, "file/个人消费明细.xlsx", list);
} }
@Operation(summary = "退款导出", description = "退款导出") @Operation(summary = "退款导出", description = "退款导出")
@GetMapping("/export-tk") @GetMapping("/export-tk")
@PreAuthorize("@pms.hasPermission('wallet_walletTransaction_export')") @PreAuthorize("@pms.hasPermission('wallet_walletTransaction_export')")
public void exportTk(HttpServletResponse response, WalletTransactionDto dto) { public void exportTk(HttpServletResponse response, @ParameterObject Page page, WalletTransactionDto dto) {
dto.setBizTypes(List.of(WalletBizEnum.REFUND.getCode())); dto.setBizTypes(List.of(WalletBizEnum.REFUND.getCode()));
dto.setIsFindOrder(true); dto.setIsFindOrder(true);
List<WalletTransactionVo> list = walletTransactionService.pageList(dto); List<WalletTransactionVo> list = walletTransactionService.scopePageList(page, dto, DataScope.of()).getRecords();
walletTransactionService.exportByTemplate(response, dto, "file/个人退款明细.xlsx", list); walletTransactionService.exportByTemplate(response, dto, "file/个人退款明细.xlsx", list);
} }
} }
@@ -13,7 +13,6 @@ import com.bsd.pjcloud.wallet.api.entity.WalletTypeEntity;
import com.bsd.pjcloud.wallet.api.vo.WalletManageVo; import com.bsd.pjcloud.wallet.api.vo.WalletManageVo;
import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
@@ -59,7 +58,7 @@ public interface WalletManageMapper extends PjcloudBaseMapper<WalletManageEntity
return update(null, lambdaUpdateWrapper); return update(null, lambdaUpdateWrapper);
} }
default Page<WalletManageVo> pageJoin(Page<WalletManageVo> page, @Param("pa") WalletManageDto dto) { default List<WalletManageVo> joinList(WalletManageDto dto) {
MPJLambdaWrapper<WalletManageEntity> wrapper = new MPJLambdaWrapper<WalletManageEntity>() MPJLambdaWrapper<WalletManageEntity> wrapper = new MPJLambdaWrapper<WalletManageEntity>()
.selectAll(WalletManageEntity.class) .selectAll(WalletManageEntity.class)
.selectAs(WalletTypeEntity::getName, WalletManageVo::getWalletTypeName) .selectAs(WalletTypeEntity::getName, WalletManageVo::getWalletTypeName)
@@ -70,8 +69,14 @@ public interface WalletManageMapper extends PjcloudBaseMapper<WalletManageEntity
.eqIfExists(WalletManageEntity::getWalletTypeId, dto.getWalletTypeId()) .eqIfExists(WalletManageEntity::getWalletTypeId, dto.getWalletTypeId())
.eqIfExists(WalletManageEntity::getIsFreeze, dto.getIsFreeze()) .eqIfExists(WalletManageEntity::getIsFreeze, dto.getIsFreeze())
.likeIfExists(WalletManageEntity::getCardNumber, dto.getCardNumber()) .likeIfExists(WalletManageEntity::getCardNumber, dto.getCardNumber())
.in(ObjectUtil.isNotEmpty(dto.getUserIds()), WalletManageEntity::getUserId, dto.getUserIds()); .in(ObjectUtil.isNotEmpty(dto.getUserIds()), WalletManageEntity::getUserId, dto.getUserIds())
return selectJoinPage(page, WalletManageVo.class, wrapper); .between(
ObjectUtil.isNotEmpty(dto.getCreateTimeList()),
WalletManageEntity::getCreateTime,
ObjectUtil.isNotEmpty(dto.getCreateTimeList()) ? dto.getCreateTimeList()[0] : null,
ObjectUtil.isNotEmpty(dto.getCreateTimeList()) ? dto.getCreateTimeList()[1] : null
);
return selectJoinList(WalletManageVo.class, wrapper);
} }
default List<WalletManageEntity> list(WalletManageDto dto) { default List<WalletManageEntity> list(WalletManageDto dto) {
@@ -95,14 +100,20 @@ public interface WalletManageMapper extends PjcloudBaseMapper<WalletManageEntity
return selectJoinOne(WalletManageVo.class, wrapper); return selectJoinOne(WalletManageVo.class, wrapper);
} }
default Page<WalletManageVo> scopePageList(Page page, WalletManageDto dto) { default Page<WalletManageVo> scopePageList(Page page, WalletManageDto dto, DataScope dataScope) {
LambdaQueryWrapper<WalletManageEntity> wrapper = new LambdaQueryWrapper<WalletManageEntity>() LambdaQueryWrapper<WalletManageEntity> wrapper = new LambdaQueryWrapper<WalletManageEntity>()
.eq(ObjectUtil.isNotEmpty(dto.getUserId()), WalletManageEntity::getUserId, dto.getUserId()) .eq(ObjectUtil.isNotEmpty(dto.getUserId()), WalletManageEntity::getUserId, dto.getUserId())
.eq(ObjectUtil.isNotEmpty(dto.getWalletTypeId()), WalletManageEntity::getWalletTypeId, dto.getWalletTypeId()) .eq(ObjectUtil.isNotEmpty(dto.getWalletTypeId()), WalletManageEntity::getWalletTypeId, dto.getWalletTypeId())
.eq(ObjectUtil.isNotEmpty(dto.getIsFreeze()), WalletManageEntity::getIsFreeze, dto.getIsFreeze()) .eq(ObjectUtil.isNotEmpty(dto.getIsFreeze()), WalletManageEntity::getIsFreeze, dto.getIsFreeze())
.in(ObjectUtil.isNotEmpty(dto.getWalletIds()), WalletManageEntity::getId, dto.getWalletIds()) .in(ObjectUtil.isNotEmpty(dto.getWalletIds()), WalletManageEntity::getId, dto.getWalletIds())
.in(ObjectUtil.isNotEmpty(dto.getUserIds()), WalletManageEntity::getUserId, dto.getUserIds()); .in(ObjectUtil.isNotEmpty(dto.getUserIds()), WalletManageEntity::getUserId, dto.getUserIds())
Page list = selectPageByScope(page, wrapper, DataScope.of()); .between(
ObjectUtil.isNotEmpty(dto.getCreateTimeList()),
WalletManageEntity::getCreateTime,
ObjectUtil.isNotEmpty(dto.getCreateTimeList()) ? dto.getCreateTimeList()[0] : null,
ObjectUtil.isNotEmpty(dto.getCreateTimeList()) ? dto.getCreateTimeList()[1] : null
);
Page list = selectPageByScope(page, wrapper, dataScope);
list.setRecords(BeanUtils.toBean(list.getRecords(), WalletManageVo.class)); list.setRecords(BeanUtils.toBean(list.getRecords(), WalletManageVo.class));
return list; return list;
} }
@@ -3,10 +3,12 @@ package com.bsd.pjcloud.wallet.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.bsd.pjcloud.common.core.util.R; import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.data.datascope.DataScope;
import com.bsd.pjcloud.wallet.api.constant.WalletTypeEnum; import com.bsd.pjcloud.wallet.api.constant.WalletTypeEnum;
import com.bsd.pjcloud.wallet.api.dto.WalletManageDto; import com.bsd.pjcloud.wallet.api.dto.WalletManageDto;
import com.bsd.pjcloud.wallet.api.entity.WalletManageEntity; import com.bsd.pjcloud.wallet.api.entity.WalletManageEntity;
import com.bsd.pjcloud.wallet.api.vo.WalletManageVo; import com.bsd.pjcloud.wallet.api.vo.WalletManageVo;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import java.util.List; import java.util.List;
@@ -47,6 +49,7 @@ public interface WalletManageService extends IService<WalletManageEntity> {
/** /**
* 获取钱包(没有缓存) * 获取钱包(没有缓存)
*
* @param cardNumber * @param cardNumber
* @return * @return
*/ */
@@ -70,7 +73,6 @@ public interface WalletManageService extends IService<WalletManageEntity> {
*/ */
WalletManageEntity getWallet(@NotNull Long walletId); WalletManageEntity getWallet(@NotNull Long walletId);
/** /**
* 根据用户id删除用户钱包 * 根据用户id删除用户钱包
* *
@@ -79,16 +81,9 @@ public interface WalletManageService extends IService<WalletManageEntity> {
*/ */
Boolean delWalletByUserIds(List<@NotNull Long> userIds); Boolean delWalletByUserIds(List<@NotNull Long> userIds);
/** Page<WalletManageVo> scopePageList(Page page, WalletManageDto dto, DataScope dataScope);
* 分页连表查询
*
* @param page
* @param dto
* @return
*/
Page<WalletManageVo> pageJoin(Page page, WalletManageDto dto);
Page<WalletManageVo> scopePageList(Page page, WalletManageDto dto); List<WalletManageVo> joinList(WalletManageDto dto);
WalletManageVo join(Long user, Long walletId); WalletManageVo join(Long user, Long walletId);
@@ -98,4 +93,12 @@ public interface WalletManageService extends IService<WalletManageEntity> {
* @param walletId 钱包id * @param walletId 钱包id
*/ */
String getQrCode(Long walletId); String getQrCode(Long walletId);
/**
* 导出
*
* @param response
* @param dto
*/
void export(HttpServletResponse response, Page page, WalletManageDto dto);
} }
@@ -1,8 +1,15 @@
package com.bsd.pjcloud.wallet.service.impl; package com.bsd.pjcloud.wallet.service.impl;
import cn.hutool.core.codec.Base64; import cn.hutool.core.codec.Base64;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.spring.SpringUtil; import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.fill.FillConfig;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -18,6 +25,7 @@ import com.bsd.pjcloud.common.core.constant.enums.YesNoEnum;
import com.bsd.pjcloud.common.core.util.BeanUtils; import com.bsd.pjcloud.common.core.util.BeanUtils;
import com.bsd.pjcloud.common.core.util.CollectionUtils; import com.bsd.pjcloud.common.core.util.CollectionUtils;
import com.bsd.pjcloud.common.core.util.R; import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.data.datascope.DataScope;
import com.bsd.pjcloud.common.data.resolver.ParamResolver; import com.bsd.pjcloud.common.data.resolver.ParamResolver;
import com.bsd.pjcloud.hard.api.constant.order.HardOrderTypeEnum; import com.bsd.pjcloud.hard.api.constant.order.HardOrderTypeEnum;
import com.bsd.pjcloud.hard.api.constant.order.HardPayTypeEnum; import com.bsd.pjcloud.hard.api.constant.order.HardPayTypeEnum;
@@ -31,11 +39,13 @@ import com.bsd.pjcloud.wallet.api.entity.WalletTypeEntity;
import com.bsd.pjcloud.wallet.api.utils.WalletDataUtil; import com.bsd.pjcloud.wallet.api.utils.WalletDataUtil;
import com.bsd.pjcloud.wallet.api.vo.WalletManageVo; import com.bsd.pjcloud.wallet.api.vo.WalletManageVo;
import com.bsd.pjcloud.wallet.api.vo.WalletSettingVo; import com.bsd.pjcloud.wallet.api.vo.WalletSettingVo;
import com.bsd.pjcloud.wallet.api.vo.transaction.WalletTransactionVo;
import com.bsd.pjcloud.wallet.mapper.WalletManageMapper; import com.bsd.pjcloud.wallet.mapper.WalletManageMapper;
import com.bsd.pjcloud.wallet.mapper.WalletTypeMapper; import com.bsd.pjcloud.wallet.mapper.WalletTypeMapper;
import com.bsd.pjcloud.wallet.service.WalletManageService; import com.bsd.pjcloud.wallet.service.WalletManageService;
import com.bsd.pjcloud.wallet.service.WalletSettingService; import com.bsd.pjcloud.wallet.service.WalletSettingService;
import com.bsd.pjcloud.wallet.service.WalletTypeService; import com.bsd.pjcloud.wallet.service.WalletTypeService;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -45,6 +55,9 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.util.*; import java.util.*;
@@ -206,28 +219,28 @@ public class WalletManageServiceImpl extends ServiceImpl<WalletManageMapper, Wal
} }
@Override @Override
public Page<WalletManageVo> pageJoin(Page page, WalletManageDto dto) { public List<WalletManageVo> joinList(WalletManageDto dto) {
Page<WalletManageVo> list = baseMapper.pageJoin(page, dto); List<WalletManageVo> list = baseMapper.joinList(dto);
if (ObjectUtil.isNotEmpty(list.getRecords())) { if (ObjectUtil.isNotEmpty(list)) {
// 用户 // 用户
List<Long> userIds = list.getRecords().stream().map(WalletManageVo::getUserId).distinct().toList(); List<Long> userIds = list.stream().map(WalletManageVo::getUserId).distinct().toList();
R<List<SysUser>> userList = userService.getUserById(new ArrayList<>(userIds)); R<List<SysUser>> userList = userService.getUserById(new ArrayList<>(userIds));
if (ObjectUtil.isNotEmpty(userList.getData())) { if (ObjectUtil.isNotEmpty(userList.getData())) {
DataUtil.convertUserList(list.getRecords(), CollectionUtils.convertMap(userList.getData(), SysUser::getUserId)); DataUtil.convertUserList(list, CollectionUtils.convertMap(userList.getData(), SysUser::getUserId));
} }
// 部门 // 部门
List<Long> deptIds = list.getRecords().stream().map(WalletManageVo::getDeptId).distinct().toList(); List<Long> deptIds = list.stream().map(WalletManageVo::getDeptId).distinct().toList();
R<Map<Long, SysDept>> deptList = deptService.getDeptByDeptIds(deptIds); R<Map<Long, SysDept>> deptList = deptService.getDeptByDeptIds(deptIds);
if (ObjectUtil.isNotEmpty(deptList.getData())) { if (ObjectUtil.isNotEmpty(deptList.getData())) {
DataUtil.convertDeptList(list.getRecords(), deptList.getData()); DataUtil.convertDeptList(list, deptList.getData());
} }
} }
return list; return list;
} }
@Override @Override
public Page<WalletManageVo> scopePageList(Page page, WalletManageDto dto) { public Page<WalletManageVo> scopePageList(Page page, WalletManageDto dto, DataScope dataScope) {
Page<WalletManageVo> list = baseMapper.scopePageList(page, dto); Page<WalletManageVo> list = baseMapper.scopePageList(page, dto, dataScope);
if (ObjectUtil.isNotEmpty(list.getRecords())) { if (ObjectUtil.isNotEmpty(list.getRecords())) {
// 用户 // 用户
List<Long> userIds = list.getRecords().stream().map(WalletManageVo::getUserId).distinct().toList(); List<Long> userIds = list.getRecords().stream().map(WalletManageVo::getUserId).distinct().toList();
@@ -267,6 +280,49 @@ public class WalletManageServiceImpl extends ServiceImpl<WalletManageMapper, Wal
return detail; return detail;
} }
@Override
public void export(HttpServletResponse response, Page page, WalletManageDto dto) {
String fileName = "file/账户余额.xlsx";
List<WalletManageVo> list = scopePageList(page, dto, DataScope.of()).getRecords();
try (ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).withTemplate(ResourceUtil.getStream(fileName)).build()) {
WriteSheet writeSheet = EasyExcel.writerSheet().build();
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
Map<String, Object> map = new HashMap<String, Object>();
if (ObjectUtil.isNotEmpty(dto.getCreateTimeList())) {
map.put("timeSpan", " 到 ");
map.put("startTime", LocalDateTimeUtil.format(dto.getCreateTimeList()[0], DatePattern.NORM_DATETIME_PATTERN));
map.put("endTime", LocalDateTimeUtil.format(dto.getCreateTimeList()[0], DatePattern.NORM_DATETIME_PATTERN));
}
if (ObjectUtil.isNotEmpty(list)) {
BigDecimal balanceSum = BigDecimal.ZERO;
BigDecimal totalExpenseSum = BigDecimal.ZERO;
BigDecimal totalRechargeSum = BigDecimal.ZERO;
for (WalletManageVo v : list) {
if (ObjectUtil.isNotEmpty(v.getBalance())) {
balanceSum = balanceSum.add(BigDecimal.valueOf(v.getBalance()));
v.setBalance(BigDecimal.valueOf(v.getBalance()).divide(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP).intValue());
}
if (ObjectUtil.isNotEmpty(v.getTotalExpense())) {
totalExpenseSum = totalExpenseSum.add(BigDecimal.valueOf(v.getTotalExpense()));
v.setTotalExpense(BigDecimal.valueOf(v.getTotalExpense()).divide(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP).intValue());
}
if (ObjectUtil.isNotEmpty(v.getTotalRecharge())) {
totalRechargeSum = totalRechargeSum.add(BigDecimal.valueOf(v.getTotalRecharge()));
v.setTotalRecharge(BigDecimal.valueOf(v.getTotalRecharge()).divide(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP).intValue());
}
}
map.put("balanceSum", balanceSum.divide(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP).toString());
map.put("totalExpenseSum", totalExpenseSum.divide(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP).toString());
map.put("totalRechargeSum", totalRechargeSum.divide(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP).toString());
}
excelWriter.fill(map, writeSheet);
excelWriter.fill(list, fillConfig, writeSheet);
} catch (IOException e) {
e.printStackTrace();
log.error("|{}|导入错误,dto:|{}|,fileName:|{}|,error:|{}|", TAG, JSON.toJSONString(dto), fileName, e.getMessage());
}
}
private WalletManageServiceImpl getSelf() { private WalletManageServiceImpl getSelf() {
return SpringUtil.getBean(getClass()); return SpringUtil.getBean(getClass());
} }