feat:财务报表导出

This commit is contained in:
dzc committed 2025-02-21 11:06:16 +08:00
1 parent 211d27f60d
commit 5d04194db9
12 files changed
+257 -226

No files matched your search

@@ -75,8 +75,8 @@ public interface RemoteUserService {
* @param userIds ID
* @return SysUser
*/
@GetMapping("/user/list")
R<List<SysUser>> getUserById(@RequestParam("userIds") List<Long> userIds);
@PostMapping("/user/list")
R<List<SysUser>> getUserById(@RequestBody List<Long> userIds);
@GetMapping("/user/user-dept")
R<List<UserVO>> getUserDeptByIds(@RequestParam("userIds") List<Long> userIds);
@@ -7,6 +7,7 @@ import com.bsd.pjcloud.common.excel.annotation.ExcelLine;
import lombok.Data;
import jakarta.validation.constraints.NotBlank;
import java.io.Serializable;
import java.time.LocalDateTime;
@@ -20,87 +21,87 @@ import java.time.LocalDateTime;
@ColumnWidth(30)
public class UserExcelVO implements Serializable {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
/**
* 导入时候回显行号
*/
@ExcelLine
@ExcelIgnore
private Long lineNum;
/**
* 导入时候回显行号
*/
@ExcelLine
@ExcelIgnore
private Long lineNum;
/**
* 主键ID
*/
@ExcelProperty("用户编号")
private Long userId;
/**
* 主键ID
*/
@ExcelProperty("用户编号")
private Long userId;
/**
* 用户名
*/
@NotBlank(message = "用户名不能为空")
@ExcelProperty("用户名")
private String username;
/**
* 用户名
*/
@NotBlank(message = "用户名不能为空")
@ExcelProperty("用户名")
private String username;
/**
* 手机号
*/
@NotBlank(message = "手机号不能为空")
@ExcelProperty("手机号")
private String phone;
/**
* 手机号
*/
@NotBlank(message = "手机号不能为空")
@ExcelProperty("手机号")
private String phone;
/**
* 手机号
*/
@NotBlank(message = "昵称不能为空")
@ExcelProperty("昵称")
private String nickname;
/**
* 手机号
*/
@NotBlank(message = "昵称不能为空")
@ExcelProperty("昵称")
private String nickname;
/**
* 手机号
*/
@NotBlank(message = "姓名不能为空")
@ExcelProperty("姓名")
private String name;
/**
* 手机号
*/
@NotBlank(message = "姓名不能为空")
@ExcelProperty("姓名")
private String name;
/**
* 手机号
*/
@NotBlank(message = "邮箱不能为空")
@ExcelProperty("邮箱")
private String email;
/**
* 手机号
*/
@NotBlank(message = "邮箱不能为空")
@ExcelProperty("邮箱")
private String email;
/**
* 部门名称
*/
@NotBlank(message = "部门名称不能为空")
@ExcelProperty("部门名称")
private String deptName;
/**
* 部门名称
*/
@NotBlank(message = "部门名称不能为空")
@ExcelProperty("部门名称")
private String deptName;
/**
* 角色列表
*/
@NotBlank(message = "角色不能为空")
@ExcelProperty("角色")
private String roleNameList;
/**
* 角色列表
*/
@NotBlank(message = "角色不能为空")
@ExcelProperty("角色")
private String roleNameList;
/**
* 角色列表
*/
@NotBlank(message = "岗位不能为空")
@ExcelProperty("岗位名称")
private String postNameList;
/**
* 角色列表
*/
@NotBlank(message = "岗位不能为空")
@ExcelProperty("岗位名称")
private String postNameList;
/**
* 锁定标记
*/
@ExcelProperty("锁定标记,0:正常,9:已锁定")
private String lockFlag;
/**
* 锁定标记
*/
@ExcelProperty("锁定标记,0:正常,9:已锁定")
private String lockFlag;
/**
* 创建时间
*/
@ExcelProperty(value = "创建时间")
private LocalDateTime createTime;
/**
* 创建时间
*/
@ExcelProperty(value = "创建时间")
private LocalDateTime createTime;
}
@@ -343,8 +343,8 @@ public class SysUserController {
* @param userIds ID列表
* @return 用户列表
*/
@GetMapping("/list")
public R<List<SysUser>> getUserListByIds(@RequestParam("userIds") List<Long> userIds) {
@PostMapping("/list")
public R<List<SysUser>> getUserListByIds(@RequestBody List<Long> userIds) {
return R.ok(userService.list(Wrappers.<SysUser>lambdaQuery().in(SysUser::getUserId, userIds)));
}
@@ -16,4 +16,14 @@ public class WalletManageDto extends WalletManageEntity {
private LocalDateTime[] createTimeList;
/**
* 是否深度搜索deptId
*/
private Boolean isDeepDept;
/**
* 部门ids
*/
private List<Long> deptIds;
}
@@ -144,9 +144,9 @@ public class WalletManageController {
}
@Operation(summary = "分页查询", description = "分页查询")
@GetMapping("/page-join")
@PostMapping("/page-join")
@PreAuthorize("@pms.hasPermission('wallet_walletManage_view')")
public R getWalletManagePageJoin(@ParameterObject Page page, @ParameterObject WalletManageDto dto) {
public R getWalletManagePageJoin(@ParameterObject Page page, @RequestBody WalletManageDto dto) {
return R.ok(walletManageService.scopePageList(page, dto, DataScope.of()));
}
@@ -180,10 +180,10 @@ public class WalletManageController {
public R removeById(@RequestBody Long[] ids) {
return R.ok(walletManageService.removeBatchByIds(CollUtil.toList(ids)));
}
@GetMapping("/export")
@PostMapping("/export")
@PreAuthorize("@pms.hasPermission('wallet_walletManage_export')")
public void export(HttpServletResponse response, @ParameterObject Page page, @ParameterObject WalletManageDto dto) {
public void export(HttpServletResponse response, @ParameterObject Page page, @RequestBody WalletManageDto dto) {
walletManageService.export(response, page, dto);
}
}
@@ -161,28 +161,29 @@ public class WalletTransactionController {
@Operation(summary = "充值导出", description = "充值导出")
@PostMapping("/export-cz")
@PreAuthorize("@pms.hasPermission('wallet_walletTransaction_export')")
public void exportCz(HttpServletResponse response, @ParameterObject Page page, @RequestBody WalletTransactionDto dto) {
dto.setBizTypes(List.of(WalletBizEnum.RECHARGE.getCode()));
List<WalletTransactionVo> list = walletTransactionService.scopePageList(page, dto, DataScope.of()).getRecords();
public void exportCz(HttpServletResponse response, @RequestBody WalletTransactionDto dto) {
dto.setBizTypes(WalletBizEnum.getTopUpCodes());
dto.setType(WalletTransactionDto.TYPE_INCOME);
List<WalletTransactionVo> list = walletTransactionService.scopeList(dto, DataScope.of());
walletTransactionService.exportByTemplate(response, dto, "file/个人充值明细.xlsx", list);
}
@Operation(summary = "消费导出", description = "消费导出")
@PostMapping("/export-xf")
@PreAuthorize("@pms.hasPermission('wallet_walletTransaction_export')")
public void exportXf(HttpServletResponse response, @ParameterObject Page page, @RequestBody WalletTransactionDto dto) {
public void exportXf(HttpServletResponse response, @RequestBody WalletTransactionDto dto) {
dto.setBizTypes(List.of(WalletBizEnum.PAYMENT.getCode()));
List<WalletTransactionVo> list = walletTransactionService.scopePageList(page, dto, DataScope.of()).getRecords();
List<WalletTransactionVo> list = walletTransactionService.scopeList(dto, DataScope.of());
walletTransactionService.exportByTemplate(response, dto, "file/个人消费明细.xlsx", list);
}
@Operation(summary = "退款导出", description = "退款导出")
@PostMapping("/export-tk")
@PreAuthorize("@pms.hasPermission('wallet_walletTransaction_export')")
public void exportTk(HttpServletResponse response, @ParameterObject Page page, @RequestBody WalletTransactionDto dto) {
public void exportTk(HttpServletResponse response, @RequestBody WalletTransactionDto dto) {
dto.setBizTypes(List.of(WalletBizEnum.REFUND.getCode()));
dto.setIsFindOrder(true);
List<WalletTransactionVo> list = walletTransactionService.scopePageList(page, dto, DataScope.of()).getRecords();
List<WalletTransactionVo> list = walletTransactionService.scopeList(dto, DataScope.of());
walletTransactionService.exportByTemplate(response, dto, "file/个人退款明细.xlsx", list);
}
}
@@ -105,10 +105,12 @@ public interface WalletManageMapper extends PjcloudBaseMapper<WalletManageEntity
default Page<WalletManageVo> scopePageList(Page page, WalletManageDto dto, DataScope dataScope) {
LambdaQueryWrapper<WalletManageEntity> wrapper = new LambdaQueryWrapper<WalletManageEntity>()
.eq(ObjectUtil.isNotEmpty(dto.getUserId()), WalletManageEntity::getUserId, dto.getUserId())
.eq(ObjectUtil.isNotEmpty(dto.getDeptId()), WalletManageEntity::getDeptId, dto.getDeptId())
.eq(ObjectUtil.isNotEmpty(dto.getWalletTypeId()), WalletManageEntity::getWalletTypeId, dto.getWalletTypeId())
.eq(ObjectUtil.isNotEmpty(dto.getIsFreeze()), WalletManageEntity::getIsFreeze, dto.getIsFreeze())
.in(ObjectUtil.isNotEmpty(dto.getWalletIds()), WalletManageEntity::getId, dto.getWalletIds())
.in(ObjectUtil.isNotEmpty(dto.getUserIds()), WalletManageEntity::getUserId, dto.getUserIds())
.in(ObjectUtil.isNotEmpty(dto.getDeptIds()), WalletManageEntity::getDeptId, dto.getDeptIds())
.between(
ObjectUtil.isNotEmpty(dto.getCreateTimeList()),
WalletManageEntity::getCreateTime,
@@ -121,4 +123,24 @@ public interface WalletManageMapper extends PjcloudBaseMapper<WalletManageEntity
return list;
}
default List<WalletManageVo> scopeList(WalletManageDto dto, DataScope dataScope) {
LambdaQueryWrapper<WalletManageEntity> wrapper = new LambdaQueryWrapper<WalletManageEntity>()
.eq(ObjectUtil.isNotEmpty(dto.getUserId()), WalletManageEntity::getUserId, dto.getUserId())
.eq(ObjectUtil.isNotEmpty(dto.getDeptId()), WalletManageEntity::getDeptId, dto.getDeptId())
.eq(ObjectUtil.isNotEmpty(dto.getWalletTypeId()), WalletManageEntity::getWalletTypeId, dto.getWalletTypeId())
.eq(ObjectUtil.isNotEmpty(dto.getIsFreeze()), WalletManageEntity::getIsFreeze, dto.getIsFreeze())
.in(ObjectUtil.isNotEmpty(dto.getWalletIds()), WalletManageEntity::getId, dto.getWalletIds())
.in(ObjectUtil.isNotEmpty(dto.getUserIds()), WalletManageEntity::getUserId, dto.getUserIds())
.in(ObjectUtil.isNotEmpty(dto.getDeptIds()), WalletManageEntity::getDeptId, dto.getDeptIds())
.between(
ObjectUtil.isNotEmpty(dto.getCreateTimeList()),
WalletManageEntity::getCreateTime,
ObjectUtil.isNotEmpty(dto.getCreateTimeList()) ? dto.getCreateTimeList()[0] : null,
ObjectUtil.isNotEmpty(dto.getCreateTimeList()) ? dto.getCreateTimeList()[1] : null
)
.orderByDesc(WalletManageEntity::getCreateTime);
List<WalletManageEntity> list = selectListByScope(wrapper, dataScope);
return BeanUtils.toBean(list, WalletManageVo.class);
}
}
@@ -24,33 +24,11 @@ import java.util.Objects;
@Mapper
public interface WalletTransactionMapper extends PjcloudBaseMapper<WalletTransactionEntity> {
default List<WalletTransactionVo> pageList(WalletTransactionDto dto) {
MPJLambdaWrapper<WalletTransactionEntity> wrapper = new MPJLambdaWrapper<WalletTransactionEntity>()
.selectAll(WalletTransactionEntity.class)
.selectAs(WalletManageEntity::getUserId, WalletTransactionVo::getUserId)
.selectAs(WalletManageEntity::getDeptId, WalletTransactionVo::getDeptId)
.selectAs(WalletTypeEntity::getName, WalletTransactionVo::getWalletTypeName)
.selectAs(WalletTypeEntity::getUniqueCode, WalletTransactionVo::getWalletTypeUniqueCode)
.leftJoin(WalletManageEntity.class, WalletManageEntity::getId, WalletTransactionEntity::getWalletId)
.leftJoin(WalletTypeEntity.class, WalletTypeEntity::getId, WalletManageEntity::getWalletTypeId)
.eqIfExists(WalletTransactionEntity::getWalletId, dto.getWalletId())
.eqIfExists(WalletTransactionEntity::getBizType, dto.getBizType())
.eqIfExists(WalletManageEntity::getWalletTypeId, dto.getWalletTypeId())
.in(ObjectUtil.isNotEmpty(dto.getBizTypes()), WalletTransactionEntity::getBizType, dto.getBizTypes())
.in(ObjectUtil.isNotEmpty(dto.getUserIds()), WalletManageEntity::getUserId, dto.getUserIds())
.orderByDesc(WalletTransactionEntity::getCreateTime);
if (ObjectUtil.equals(dto.getType(), WalletTransactionDto.TYPE_INCOME)) {
wrapper.gt(WalletTransactionEntity::getPrice, 0);
} else if (Objects.equals(dto.getType(), WalletTransactionDto.TYPE_EXPENSE)) {
wrapper.lt(WalletTransactionEntity::getPrice, 0);
}
return selectJoinList(WalletTransactionVo.class, wrapper);
}
default Page<WalletTransactionVo> scopePageList(Page page, WalletTransactionDto dto, DataScope dataScope) {
LambdaQueryWrapper<WalletTransactionEntity> wrapper = new LambdaQueryWrapper<WalletTransactionEntity>()
.eq(ObjectUtil.isNotEmpty(dto.getWalletId()), WalletTransactionEntity::getWalletId, dto.getWalletId())
.eq(ObjectUtil.isNotEmpty(dto.getBizType()), WalletTransactionEntity::getBizType, dto.getBizType())
.eq(ObjectUtil.isNotEmpty(dto.getUserId()), WalletTransactionEntity::getUserId, dto.getUserId())
.eq(ObjectUtil.isNotEmpty(dto.getDeptId()), WalletTransactionEntity::getDeptId, dto.getDeptId())
.in(ObjectUtil.isNotEmpty(dto.getUserIds()), WalletTransactionEntity::getUserId, dto.getUserIds())
.in(ObjectUtil.isNotEmpty(dto.getDeptIds()), WalletTransactionEntity::getDeptId, dto.getDeptIds())
@@ -72,6 +50,32 @@ public interface WalletTransactionMapper extends PjcloudBaseMapper<WalletTransac
return list;
}
default List<WalletTransactionVo> scopeList(WalletTransactionDto dto, DataScope dataScope) {
LambdaQueryWrapper<WalletTransactionEntity> wrapper = new LambdaQueryWrapper<WalletTransactionEntity>()
.eq(ObjectUtil.isNotEmpty(dto.getWalletId()), WalletTransactionEntity::getWalletId, dto.getWalletId())
.eq(ObjectUtil.isNotEmpty(dto.getBizType()), WalletTransactionEntity::getBizType, dto.getBizType())
.eq(ObjectUtil.isNotEmpty(dto.getUserId()), WalletTransactionEntity::getUserId, dto.getUserId())
.eq(ObjectUtil.isNotEmpty(dto.getDeptId()), WalletTransactionEntity::getDeptId, dto.getDeptId())
.in(ObjectUtil.isNotEmpty(dto.getUserIds()), WalletTransactionEntity::getUserId, dto.getUserIds())
.in(ObjectUtil.isNotEmpty(dto.getDeptIds()), WalletTransactionEntity::getDeptId, dto.getDeptIds())
.in(ObjectUtil.isNotEmpty(dto.getBizTypes()), WalletTransactionEntity::getBizType, dto.getBizTypes())
.between(
ObjectUtil.isNotEmpty(dto.getCreateTimeList()),
WalletTransactionEntity::getCreateTime,
ObjectUtil.isNotEmpty(dto.getCreateTimeList()) ? dto.getCreateTimeList()[0] : null,
ObjectUtil.isNotEmpty(dto.getCreateTimeList()) ? dto.getCreateTimeList()[1] : null
)
.orderByDesc(WalletTransactionEntity::getCreateTime);
if (ObjectUtil.equals(dto.getType(), WalletTransactionDto.TYPE_INCOME)) {
wrapper.gt(WalletTransactionEntity::getPrice, 0);
} else if (Objects.equals(dto.getType(), WalletTransactionDto.TYPE_EXPENSE)) {
wrapper.lt(WalletTransactionEntity::getPrice, 0);
}
List<WalletTransactionEntity> list = selectListByScope(wrapper, dataScope);
return BeanUtils.toBean(list, WalletTransactionVo.class);
}
Integer getTransactionPriceCount(@Param("month") String importTimeStr, @Param("walletId") Long walletId, @Param("bizType") String bizType);
List<WalletRechargeApplySelectCompareVo> selectCompare(@Param("bizType") String bizType, @Param("dateTime") String monthTimeStr, @Param("userIdList") List<Long> userIdList);
@@ -2,7 +2,6 @@ package com.bsd.pjcloud.wallet.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
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.dto.WalletManageDto;
@@ -83,7 +82,7 @@ public interface WalletManageService extends IService<WalletManageEntity> {
Page<WalletManageVo> scopePageList(Page page, WalletManageDto dto, DataScope dataScope);
List<WalletManageVo> joinList(WalletManageDto dto);
List<WalletManageVo> scopeList(WalletManageDto dto, DataScope dataScope);
WalletManageVo join(Long user, Long walletId);
@@ -16,7 +16,7 @@ public interface WalletTransactionService extends IService<WalletTransactionEnti
Page<WalletTransactionVo> scopePageList(Page page, WalletTransactionDto dto, DataScope dataScope);
List<WalletTransactionVo> pageList(WalletTransactionDto dto);
List<WalletTransactionVo> scopeList(WalletTransactionDto dto, DataScope dataScope);
/**
* 扣减钱包余额
@@ -39,7 +39,6 @@ import com.bsd.pjcloud.wallet.api.entity.WalletTypeEntity;
import com.bsd.pjcloud.wallet.api.utils.WalletDataUtil;
import com.bsd.pjcloud.wallet.api.vo.WalletManageVo;
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.WalletTypeMapper;
import com.bsd.pjcloud.wallet.service.WalletManageService;
@@ -49,7 +48,6 @@ import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -61,6 +59,7 @@ import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;
/**
* 钱包管理
@@ -219,51 +218,38 @@ public class WalletManageServiceImpl extends ServiceImpl<WalletManageMapper, Wal
}
@Override
public List<WalletManageVo> joinList(WalletManageDto dto) {
List<WalletManageVo> list = baseMapper.joinList(dto);
if (ObjectUtil.isNotEmpty(list)) {
// 用户
List<Long> userIds = list.stream().map(WalletManageVo::getUserId).distinct().toList();
R<List<SysUser>> userList = userService.getUserById(new ArrayList<>(userIds));
if (ObjectUtil.isNotEmpty(userList.getData())) {
DataUtil.convertUserList(list, CollectionUtils.convertMap(userList.getData(), SysUser::getUserId));
}
// 部门
List<Long> deptIds = list.stream().map(WalletManageVo::getDeptId).distinct().toList();
R<Map<Long, SysDept>> deptList = deptService.getDeptByDeptIds(deptIds);
if (ObjectUtil.isNotEmpty(deptList.getData())) {
DataUtil.convertDeptList(list, deptList.getData());
public List<WalletManageVo> scopeList(WalletManageDto dto, DataScope dataScope) {
// 查询部门
if (ObjectUtil.isNotEmpty(dto.getIsDeepDept()) && dto.getIsDeepDept() && ObjectUtil.isNotEmpty(dto.getDeptId())) {
List<SysDept> deptList = deptService.getDescendantList(dto.getDeptId()).getData();
dto.setDeptId(null);
if (ObjectUtil.isNotEmpty(deptList)) {
dto.setDeptIds(deptList.stream().map(SysDept::getDeptId).collect(Collectors.toList()));
}
}
if (ObjectUtil.isNotEmpty(dto.getDeptIds())) {
dto.setDeptId(null);
}
List<WalletManageVo> list = baseMapper.scopeList(dto, dataScope);
disposeList(list, dto);
return list;
}
@Override
public Page<WalletManageVo> scopePageList(Page page, WalletManageDto dto, DataScope dataScope) {
Page<WalletManageVo> list = baseMapper.scopePageList(page, dto, dataScope);
if (ObjectUtil.isNotEmpty(list.getRecords())) {
// 用户
List<Long> userIds = list.getRecords().stream().map(WalletManageVo::getUserId).distinct().toList();
R<List<SysUser>> userList = userService.getUserById(new ArrayList<>(userIds));
if (ObjectUtil.isNotEmpty(userList.getData())) {
DataUtil.convertUserList(list.getRecords(), CollectionUtils.convertMap(userList.getData(), SysUser::getUserId));
}
// 部门
List<Long> deptIds = list.getRecords().stream().map(WalletManageVo::getDeptId).distinct().toList();
R<Map<Long, SysDept>> deptList = deptService.getDeptByDeptIds(deptIds);
if (ObjectUtil.isNotEmpty(deptList.getData())) {
DataUtil.convertDeptList(list.getRecords(), deptList.getData());
}
// 饭卡类型
List<Long> walletTypeId = list.getRecords().stream().map(WalletManageVo::getWalletTypeId).distinct().toList();
if (ObjectUtil.isNotEmpty(walletTypeId)) {
WalletTypeDto walletTypeDto = new WalletTypeDto();
List<WalletTypeEntity> walletTypeList = walletTypeMapper.list(walletTypeDto);
if (ObjectUtil.isNotEmpty(walletTypeList)) {
WalletDataUtil.convertWalletTypeList(list.getRecords(), CollectionUtils.convertMap(walletTypeList, WalletTypeEntity::getId));
}
// 查询部门
if (ObjectUtil.isNotEmpty(dto.getIsDeepDept()) && dto.getIsDeepDept() && ObjectUtil.isNotEmpty(dto.getDeptId())) {
List<SysDept> deptList = deptService.getDescendantList(dto.getDeptId()).getData();
dto.setDeptId(null);
if (ObjectUtil.isNotEmpty(deptList)) {
dto.setDeptIds(deptList.stream().map(SysDept::getDeptId).collect(Collectors.toList()));
}
}
if (ObjectUtil.isNotEmpty(dto.getDeptIds())) {
dto.setDeptId(null);
}
Page<WalletManageVo> list = baseMapper.scopePageList(page, dto, dataScope);
disposeList(list.getRecords(), dto);
return list;
}
@@ -283,7 +269,7 @@ public class WalletManageServiceImpl extends ServiceImpl<WalletManageMapper, Wal
@Override
public void export(HttpServletResponse response, Page page, WalletManageDto dto) {
String fileName = "file/账户余额.xlsx";
List<WalletManageVo> list = scopePageList(page, dto, DataScope.of()).getRecords();
List<WalletManageVo> list = scopeList(dto, DataScope.of());
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();
@@ -323,6 +309,32 @@ public class WalletManageServiceImpl extends ServiceImpl<WalletManageMapper, Wal
}
}
private void disposeList(List<WalletManageVo> list, WalletManageDto dto) {
if (ObjectUtil.isNotEmpty(list)) {
// 用户
List<Long> userIds = list.stream().map(WalletManageVo::getUserId).distinct().toList();
R<List<SysUser>> userList = userService.getUserById(new ArrayList<>(userIds));
if (ObjectUtil.isNotEmpty(userList.getData())) {
DataUtil.convertUserList(list, CollectionUtils.convertMap(userList.getData(), SysUser::getUserId));
}
// 部门
List<Long> deptIds = list.stream().map(WalletManageVo::getDeptId).distinct().toList();
R<Map<Long, SysDept>> deptList = deptService.getDeptByDeptIds(deptIds);
if (ObjectUtil.isNotEmpty(deptList.getData())) {
DataUtil.convertDeptList(list, deptList.getData());
}
// 饭卡类型
List<Long> walletTypeId = list.stream().map(WalletManageVo::getWalletTypeId).distinct().toList();
if (ObjectUtil.isNotEmpty(walletTypeId)) {
WalletTypeDto walletTypeDto = new WalletTypeDto();
List<WalletTypeEntity> walletTypeList = walletTypeMapper.list(walletTypeDto);
if (ObjectUtil.isNotEmpty(walletTypeList)) {
WalletDataUtil.convertWalletTypeList(list, CollectionUtils.convertMap(walletTypeList, WalletTypeEntity::getId));
}
}
}
}
private WalletManageServiceImpl getSelf() {
return SpringUtil.getBean(getClass());
}
@@ -17,7 +17,6 @@ import com.bsd.pjcloud.admin.api.entity.SysUser;
import com.bsd.pjcloud.admin.api.feign.RemoteDeptService;
import com.bsd.pjcloud.admin.api.feign.RemoteUserService;
import com.bsd.pjcloud.admin.api.utils.DataUtil;
import com.bsd.pjcloud.common.core.constant.CacheConstants;
import com.bsd.pjcloud.common.core.util.CollectionUtils;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.data.datascope.DataScope;
@@ -38,7 +37,6 @@ import com.bsd.pjcloud.wallet.service.WalletTransactionService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
@@ -179,54 +177,59 @@ public class WalletTransactionServiceImpl extends ServiceImpl<WalletTransactionM
dto.setDeptId(null);
}
Page<WalletTransactionVo> list = baseMapper.scopePageList(page, dto, dataScope);
if (ObjectUtil.isNotEmpty(list.getRecords())) {
// 用户
List<Long> userIds = list.getRecords().stream().map(WalletTransactionVo::getUserId).distinct().toList();
R<List<SysUser>> userList = userService.getUserById(new ArrayList<>(userIds));
if (ObjectUtil.isNotEmpty(userList.getData())) {
DataUtil.convertUserList(list.getRecords(), CollectionUtils.convertMap(userList.getData(), SysUser::getUserId));
}
// 部门
List<Long> deptIds = list.getRecords().stream().map(WalletTransactionVo::getDeptId).distinct().toList();
R<Map<Long, SysDept>> deptList = deptService.getDeptByDeptIds(deptIds);
if (ObjectUtil.isNotEmpty(deptList.getData())) {
DataUtil.convertDeptList(list.getRecords(), deptList.getData());
}
// 饭卡
List<Long> walletIds = list.getRecords().stream().map(WalletTransactionVo::getWalletId).distinct().toList();
if (ObjectUtil.isNotEmpty(walletIds)) {
WalletManageDto walletManageDto = new WalletManageDto();
walletManageDto.setWalletIds(walletIds);
List<WalletManageEntity> walletList = walletManageMapper.list(walletManageDto);
if (ObjectUtil.isNotEmpty(walletList)) {
WalletDataUtil.convertWalletList(list.getRecords(), CollectionUtils.convertMap(walletList, WalletManageEntity::getId));
}
}
// 饭卡类型
List<Long> walletTypeIds = list.getRecords().stream().map(WalletTransactionVo::getWalletTypeId).distinct().toList();
if (ObjectUtil.isNotEmpty(walletTypeIds)) {
WalletTypeDto walletTypeDto = new WalletTypeDto();
walletTypeDto.setWalletTypeIds(walletTypeIds);
List<WalletTypeEntity> walletTypeList = walletTypeMapper.list(walletTypeDto);
if (ObjectUtil.isNotEmpty(walletTypeList)) {
WalletDataUtil.convertWalletTypeList(list.getRecords(), CollectionUtils.convertMap(walletTypeList, WalletTypeEntity::getId));
}
}
// 订单
if (dto.getIsFindOrder()) {
list.getRecords().forEach(v -> {
if (ObjectUtil.isNotEmpty(v.getBizId())) {
v.setOrderId(Long.valueOf(v.getBizId()));
}
});
}
}
disposeList(list.getRecords(), dto);
return list;
}
@Override
public List<WalletTransactionVo> pageList(WalletTransactionDto dto) {
List<WalletTransactionVo> list = baseMapper.pageList(dto);
public List<WalletTransactionVo> scopeList(WalletTransactionDto dto, DataScope dataScope) {
// 查询部门
if (ObjectUtil.isNotEmpty(dto.getIsDeepDept()) && dto.getIsDeepDept() && ObjectUtil.isNotEmpty(dto.getDeptId())) {
List<SysDept> deptList = deptService.getDescendantList(dto.getDeptId()).getData();
dto.setDeptId(null);
if (ObjectUtil.isNotEmpty(deptList)) {
dto.setDeptIds(deptList.stream().map(SysDept::getDeptId).collect(Collectors.toList()));
}
}
if (ObjectUtil.isNotEmpty(dto.getDeptIds())) {
dto.setDeptId(null);
}
List<WalletTransactionVo> list = baseMapper.scopeList(dto, dataScope);
disposeList(list, dto);
return list;
}
@Override
public void exportByTemplate(HttpServletResponse response, WalletTransactionDto dto, String fileName, List<WalletTransactionVo> list) {
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 priceTotal = BigDecimal.ZERO;
for (WalletTransactionVo v : list) {
if (ObjectUtil.isNotEmpty(v.getPrice())) {
priceTotal = priceTotal.add(BigDecimal.valueOf(v.getPrice()));
v.setPriceStr(BigDecimal.valueOf(v.getPrice()).divide(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP).toString());
}
}
map.put("computeTotalPayPrice", priceTotal.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 void disposeList(List<WalletTransactionVo> list, WalletTransactionDto dto) {
if (ObjectUtil.isNotEmpty(list)) {
// 用户
List<Long> userIds = list.stream().map(WalletTransactionVo::getUserId).distinct().toList();
@@ -260,36 +263,15 @@ public class WalletTransactionServiceImpl extends ServiceImpl<WalletTransactionM
WalletDataUtil.convertWalletTypeList(list, CollectionUtils.convertMap(walletTypeList, WalletTypeEntity::getId));
}
}
// 订单
if (dto.getIsFindOrder()) {
list.forEach(v -> {
if (ObjectUtil.isNotEmpty(v.getBizId())) {
v.setOrderId(Long.valueOf(v.getBizId()));
}
});
}
}
return list;
}
@Override
public void exportByTemplate(HttpServletResponse response, WalletTransactionDto dto, String fileName, List<WalletTransactionVo> list) {
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 priceTotal = BigDecimal.ZERO;
for (WalletTransactionVo v : list) {
if (ObjectUtil.isNotEmpty(v.getPrice())) {
priceTotal = priceTotal.add(BigDecimal.valueOf(v.getPrice()));
v.setPriceStr(BigDecimal.valueOf(v.getPrice()).divide(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP).toString());
}
}
map.put("computeTotalPayPrice", priceTotal.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());
}
}
}