feat:充值/扣款申请导出

This commit is contained in:
dzc committed 2026-01-16 10:30:01 +08:00
1 parent 7cec1477cd
commit 71acd46cb7
6 files changed
+141 -29

No files matched your search

@@ -23,13 +23,13 @@ public enum TaskCheckStatusEnum {
public static TaskCheckStatusEnum descOf(String description) {
return Arrays.stream(TaskCheckStatusEnum.values())
.filter(v -> ObjectUtil.equal(v.getDesc(), description))
.findFirst().get();
.findFirst().orElse(null);
}
public static TaskCheckStatusEnum codeOf(String code) {
return Arrays.stream(TaskCheckStatusEnum.values())
.filter(v -> ObjectUtil.equal(v.getCode(), code))
.findFirst().get();
.findFirst().orElse(null);
}
}
@@ -26,7 +26,7 @@ public enum WalletBizRechargeEnum {
public static WalletBizRechargeEnum valueOfByType(String code) {
return Arrays.stream(WalletBizRechargeEnum.values())
.filter(v -> ObjectUtil.equal(v.getCode(), code))
.findFirst().get();
.findFirst().orElse(null);
}
public static WalletBizRechargeEnum descOf(String description) {
@@ -12,6 +12,7 @@ import com.bsd.pjcloud.common.idempotent.annotation.Idempotent;
import com.bsd.pjcloud.common.log.annotation.SysLog;
import com.bsd.pjcloud.common.security.annotation.Inner;
import com.bsd.pjcloud.flow.task.dto.ProcessNodeRecordAssignUserParamDto;
import com.bsd.pjcloud.hard.api.dto.order.HardOrderDto;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeApplyDto;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeImportDto;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeSaveTopupDto;
@@ -22,6 +23,7 @@ import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeImportVo;
import com.bsd.pjcloud.wallet.api.vo.recharge.excel.WalletRechargeByApplyExcelVo;
import com.bsd.pjcloud.wallet.service.WalletRechargeApplyService;
import com.bsd.pjcloud.wallet.service.WalletRechargeApplyComposeService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import com.bsd.pjcloud.common.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
@@ -153,11 +155,14 @@ public class WalletRechargeApplyController {
return walletRechargeApplyService.exportExcel(dto);
}
/**
* 导出充值/扣款申请
*/
@ResponseExcel
@GetMapping("/export")
@PostMapping("/export")
@PreAuthorize("@pms.hasPermission('wallet_walletRechargeApply_export')")
public List<WalletRechargeApplyEntity> export(WalletRechargeApplyEntity walletRechargeApply, Long[] ids) {
return walletRechargeApplyService.list(Wrappers.lambdaQuery(walletRechargeApply).in(ArrayUtil.isNotEmpty(ids), WalletRechargeApplyEntity::getId, ids));
public void export(HttpServletResponse response, @RequestBody WalletRechargeApplyDto dto) {
walletRechargeApplyService.export(response, dto);
}
@PostMapping("/read-excel")
@@ -5,6 +5,7 @@ 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.flow.task.dto.ProcessNodeRecordAssignUserParamDto;
import com.bsd.pjcloud.hard.api.dto.order.HardOrderDto;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeApplyDto;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeImportDto;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeSaveTopupDto;
@@ -12,6 +13,7 @@ import com.bsd.pjcloud.wallet.api.dto.recharge.excel.WalletRechargeExcelDto;
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargeApplyEntity;
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeApplyVo;
import com.bsd.pjcloud.wallet.api.vo.recharge.excel.WalletRechargeByApplyExcelVo;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.validation.BindingResult;
import java.util.ArrayList;
@@ -65,4 +67,9 @@ public interface WalletRechargeApplyService extends IService<WalletRechargeApply
void updateBeforePrice(WalletRechargeApplyEntity detail);
List<WalletRechargeByApplyExcelVo> exportExcel(WalletRechargeImportDto dto);
/**
* 导出充值/扣款申请
*/
void export(HttpServletResponse response, WalletRechargeApplyDto dto);
}
@@ -2,10 +2,15 @@ package com.bsd.pjcloud.wallet.service.impl.recharge;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.lang.Validator;
import cn.hutool.core.util.ObjectUtil;
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.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -32,6 +37,7 @@ import com.bsd.pjcloud.flow.task.constant.TaskCheckStatusEnum;
import com.bsd.pjcloud.flow.task.dto.ProcessNodeRecordAssignUserParamDto;
import com.bsd.pjcloud.flow.task.dto.TaskDto;
import com.bsd.pjcloud.flow.task.dto.TaskParamDto;
import com.bsd.pjcloud.hard.api.dto.order.HardOrderDto;
import com.bsd.pjcloud.wallet.api.constant.WalletBizEnum;
import com.bsd.pjcloud.wallet.api.constant.WalletBizRechargeEnum;
import com.bsd.pjcloud.wallet.api.constant.WalletRechargeInvoiceStatusEnum;
@@ -61,6 +67,7 @@ import com.bsd.pjcloud.wallet.service.*;
import com.bsd.pjcloud.wallet.utils.flow.FlowUtil;
import com.bsd.pjcloud.wallet.utils.flow.dto.WalletRechargeApplyFlowDto;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -70,11 +77,14 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.CompletableFuture;
/**
* 充值/扣款申请
@@ -544,39 +554,128 @@ public class WalletRechargeApplyServiceImpl extends ServiceImpl<WalletRechargeAp
return result;
}
/**
* 导出充值/扣款申请
*/
@Override
public void export(HttpServletResponse response, WalletRechargeApplyDto dto) {
try (ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).withTemplate(ResourceUtil.getStream("file/充值或扣款申请.xlsx")).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()[1], DatePattern.NORM_DATETIME_PATTERN));
}
// 统计
double sumTotalPrice = 0;
int lineNumber = 1;
long currentPage = 1;
long pageSize = 1000;
while (true) {
Page<WalletRechargeApplyVo> page = scopePageList(new Page(currentPage, pageSize), dto, DataScope.of());
List<WalletRechargeApplyVo> records = page.getRecords();
if (ObjectUtil.isEmpty(records)) break;
// 处理excel start
List<Map<String, Object>> excelList = new LinkedList<>();
for (WalletRechargeApplyVo v : records) {
Map<String, Object> excelMap = new HashMap<>();
excelMap.put("lineNumber", lineNumber);
excelMap.put("username", v.getUsername());
excelMap.put("bizTypeStr", "");
if (ObjectUtil.isNotEmpty(v.getBizType())) {
WalletBizRechargeEnum bizTypeEnum = WalletBizRechargeEnum.valueOfByType(v.getBizType());
if (ObjectUtil.isNotEmpty(bizTypeEnum)) excelMap.put("bizTypeStr", bizTypeEnum.getDesc());
}
excelMap.put("invoiceCode", v.getInvoiceCode());
excelMap.put("walletTypeName", v.getWalletTypeName());
excelMap.put("deptName", v.getDeptName());
excelMap.put("totalPrice", 0);
if (ObjectUtil.isNotEmpty(v.getTotalPrice())) {
double totalPrice = new BigDecimal(v.getTotalPrice()).divide(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP).doubleValue();
if (ObjectUtil.isNotEmpty(totalPrice)) {
excelMap.put("totalPrice", totalPrice);
// 累加
sumTotalPrice += totalPrice;
}
}
excelMap.put("importTime", LocalDateTimeUtil.format(v.getImportTime(), DatePattern.NORM_MONTH_PATTERN));
excelMap.put("processStatus", "");
if (ObjectUtil.isNotEmpty(v.getProcessStatus())) {
TaskCheckStatusEnum processStatusEnum = TaskCheckStatusEnum.codeOf(v.getProcessStatus());
if (ObjectUtil.isNotEmpty(processStatusEnum)) {
excelMap.put("processStatus", processStatusEnum.getCode());
}
}
excelMap.put("remark", v.getRemark());
excelMap.put("applyTime", LocalDateTimeUtil.format(v.getApplyTime(), DatePattern.NORM_DATETIME_PATTERN));
excelMap.put("processTime", LocalDateTimeUtil.format(v.getProcessTime(), DatePattern.NORM_DATETIME_PATTERN));
excelList.add(excelMap);
lineNumber++;
}
excelWriter.fill(excelList, fillConfig, writeSheet);
// 处理excel end
if (page.getTotal() < pageSize) break;
currentPage++;
}
map.put("totalPrice", sumTotalPrice);
excelWriter.fill(map, writeSheet);
} catch (Exception e) {
e.printStackTrace();
log.error("|{}|导出充值/扣款申请异常,dto:|{}|error:|{}|", TAG, JSON.toJSONString(dto), e.getMessage());
}
}
private void disposeList(List<WalletRechargeApplyVo> list, WalletRechargeApplyDto dto) {
if (ObjectUtil.isEmpty(list)) return;
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
PjcloudUser user = SecurityUtils.getUser();
// 用户
List<Long> userIds = list.stream().map(WalletRechargeApplyVo::getUserId).distinct().toList();
if (ObjectUtil.isNotEmpty(userIds)) {
List<SysUser> userList = userService.getUserById(new ArrayList<>(userIds)).getData();
if (ObjectUtil.isNotEmpty(userList)) {
DataUtil.convertUserList(list, CollectionUtils.convertMap(userList, SysUser::getUserId));
CompletableFuture<Void> userFuture = CompletableFuture.runAsync(() -> {
RequestContextHolder.setRequestAttributes(requestAttributes);
List<Long> userIds = list.stream().map(WalletRechargeApplyVo::getUserId).distinct().toList();
if (ObjectUtil.isNotEmpty(userIds)) {
List<SysUser> userList = userService.getUserById(new ArrayList<>(userIds)).getData();
if (ObjectUtil.isNotEmpty(userList)) {
DataUtil.convertUserList(list, CollectionUtils.convertMap(userList, SysUser::getUserId));
}
}
}
});
// 部门
List<Long> deptIds = list.stream().map(WalletRechargeApplyVo::getDeptId).distinct().toList();
if (ObjectUtil.isNotEmpty(deptIds)) {
Map<Long, SysDept> deptList = deptService.getDeptByDeptIds(deptIds).getData();
if (ObjectUtil.isNotEmpty(deptList)) {
DataUtil.convertDeptList(list, deptList);
CompletableFuture<Void> deptFuture = CompletableFuture.runAsync(() -> {
RequestContextHolder.setRequestAttributes(requestAttributes);
List<Long> deptIds = list.stream().map(WalletRechargeApplyVo::getDeptId).distinct().toList();
if (ObjectUtil.isNotEmpty(deptIds)) {
Map<Long, SysDept> deptList = deptService.getDeptByDeptIds(deptIds).getData();
if (ObjectUtil.isNotEmpty(deptList)) {
DataUtil.convertDeptList(list, deptList);
}
}
}
});
// 饭卡类型
List<Long> walletTypeIds = list.stream().map(WalletRechargeApplyVo::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, CollectionUtils.convertMap(walletTypeList, WalletTypeEntity::getId));
CompletableFuture<Void> walletTypeFuture = CompletableFuture.runAsync(() -> {
RequestContextHolder.setRequestAttributes(requestAttributes);
List<Long> walletTypeIds = list.stream().map(WalletRechargeApplyVo::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, CollectionUtils.convertMap(walletTypeList, WalletTypeEntity::getId));
}
}
}
});
// 审批流程
if (dto.getIsFindCheckUser()) {
CompletableFuture<Void> flowFuture = CompletableFuture.runAsync(() -> {
RequestContextHolder.setRequestAttributes(requestAttributes);
if (!dto.getIsFindCheckUser()) return;
List<String> processInstanceIds = list.stream().map(WalletRechargeApplyVo::getProcessId).filter(ObjectUtil::isNotEmpty).distinct().toList();
if (ObjectUtil.isNotEmpty(processInstanceIds)) {
List<TaskDto> taskList = flowUtil.queryProcessInstanceList(SecurityUtils.getUser().getId().toString(), processInstanceIds);
List<TaskDto> taskList = flowUtil.queryProcessInstanceList(String.valueOf(user.getId()), processInstanceIds);
if (ObjectUtil.isNotEmpty(taskList)) {
Map<String, TaskDto> taskMap = CollectionUtils.convertMap(taskList, TaskDto::getProcessInstanceId);
CollectionUtils.convertList(list, v -> {
@@ -588,7 +687,8 @@ public class WalletRechargeApplyServiceImpl extends ServiceImpl<WalletRechargeAp
});
}
}
}
});
CompletableFuture.allOf(userFuture, deptFuture, walletTypeFuture, flowFuture).join();
}
private boolean isCheckData(Long walletId) {