diff --git a/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/vo/order/excel/HardMchOrderExcelVo.java b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/vo/order/excel/HardMchOrderExcelVo.java new file mode 100644 index 000000000..edac50125 --- /dev/null +++ b/pjcloud-hardware/pjcloud-hardware-api/src/main/java/com/bsd/pjcloud/hard/api/vo/order/excel/HardMchOrderExcelVo.java @@ -0,0 +1,50 @@ +package com.bsd.pjcloud.hard.api.vo.order.excel; + +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.write.style.ColumnWidth; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * 商户流水导出 + */ +@Data +@ColumnWidth(30) +public class HardMchOrderExcelVo { + + @ExcelProperty("商户") + private String merchantName; + + @ExcelProperty("姓名") + private String username; + + @ExcelProperty("手机号") + private String userMobile; + + @ExcelProperty("支付方式") + private String payType; + + @ExcelProperty("商品总价") + private Double totalPrice; + + @ExcelProperty("额外支付") + private Double extraPrice; + + @ExcelProperty("实际支付") + private Double payPrice; + + @ExcelProperty("退款金额") + private Double refundPrice; + + @ExcelProperty("订单支付时间") + private LocalDateTime payTime; + + /** + * 导出相关 + */ + @Schema(description = "列号") + private Long lineNumber; + +} diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/order/HardOrderTotalController.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/order/HardOrderTotalController.java index e1a02c57e..0a5a3a4f2 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/order/HardOrderTotalController.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/controller/order/HardOrderTotalController.java @@ -12,7 +12,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.bsd.pjcloud.admin.api.dto.UserInfo; import com.bsd.pjcloud.admin.api.feign.RemoteUserService; import com.bsd.pjcloud.common.core.constant.enums.MerchantTypeEnum; +import com.bsd.pjcloud.common.core.util.BeanUtils; import com.bsd.pjcloud.common.core.util.R; +import com.bsd.pjcloud.common.data.datascope.DataScope; import com.bsd.pjcloud.common.log.annotation.SysLog; import com.bsd.pjcloud.common.security.service.PjcloudUser; import com.bsd.pjcloud.common.security.util.SecurityUtils; @@ -21,11 +23,11 @@ import com.bsd.pjcloud.hard.api.constant.order.HardOrderStatusEnum; import com.bsd.pjcloud.hard.api.constant.order.HardPayTypeEnum; import com.bsd.pjcloud.hard.api.dto.order.HardDeptTotalDto; import com.bsd.pjcloud.hard.api.dto.order.HardOrderDto; -import com.bsd.pjcloud.hard.api.vo.order.HardDeptTotalVo; -import com.bsd.pjcloud.hard.api.vo.order.HardOrderCsVo; -import com.bsd.pjcloud.hard.api.vo.order.HardOrderPayTypeVo; -import com.bsd.pjcloud.hard.api.vo.order.HardOrderSbVo; +import com.bsd.pjcloud.hard.api.vo.order.*; +import com.bsd.pjcloud.hard.api.vo.order.excel.HardMchOrderExcelVo; +import com.bsd.pjcloud.hard.mapper.order.HardOrderMapper; import com.bsd.pjcloud.hard.service.HardManagerService; +import com.bsd.pjcloud.hard.service.HardOrderService; import com.bsd.pjcloud.hard.service.HardOrderTotalService; import com.bsd.pjcloud.wallet.api.feign.RemoteMchService; import com.bsd.pjcloud.wallet.api.vo.MchManageVo; @@ -54,9 +56,12 @@ import java.util.Map; @SecurityRequirement(name = HttpHeaders.AUTHORIZATION) public class HardOrderTotalController { + private final HardOrderService hardOrderService; private final HardOrderTotalService hardOrderTotalService; private final HardManagerService hardManagerService; + private final HardOrderMapper hardOrderMapper; + private final RemoteMchService mchService; private final RemoteUserService userService; @@ -222,6 +227,83 @@ public class HardOrderTotalController { } } + @Operation(summary = "单个商户交易流水导出", description = "单个商户交易流水导出") + @PostMapping("/export-mch-cs") + @SysLog("单个商户交易流水导出") + public void exportMchCs(HttpServletResponse response, @RequestBody HardOrderDto dto) throws IOException { + dto.setOrderStatusCodes(HardOrderStatusEnum.getPayPrice()); + // 查询商户和下面的子商户 + List mchDtoIds = new ArrayList<>(); + if (ObjectUtil.isNotEmpty(dto.getMerchantId())) { + List mchList = mchService.getByParentId(dto.getMerchantId()).getData(); + if (ObjectUtil.isNotEmpty(mchList)) { + List mchIds = mchList.stream().map(MchManageVo::getId).toList(); + mchDtoIds.add(dto.getMerchantId()); + mchDtoIds.addAll(mchIds); + dto.setMerchantId(null); + dto.setMchIds(mchDtoIds); + } + } + // 查询商户 + MchManageVo mch = mchService.getById(dto.getMerchantId()).getData(); + if (ObjectUtil.isEmpty(mch)) throw new RuntimeException("商户不存在"); + + Long count = hardOrderMapper.count(dto, DataScope.of()); + if (count > 5000) throw new RuntimeException("导出数据超出5000条,请缩小查询范围"); + List list = hardOrderService.scopeList(dto, DataScope.of()); + List excelList = BeanUtils.toBean(list, HardMchOrderExcelVo.class); + + 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 map = new HashMap(); + if (ObjectUtil.isNotEmpty(dto.getPayTimeList())) { + map.put("timeSpan", " 到 "); + map.put("startTime", LocalDateTimeUtil.format(dto.getPayTimeList()[0], DatePattern.NORM_DATETIME_PATTERN)); + map.put("endTime", LocalDateTimeUtil.format(dto.getPayTimeList()[1], DatePattern.NORM_DATETIME_PATTERN)); + } + map.put("merchantName", mch.getName()); + if (ObjectUtil.isNotEmpty(excelList)) { + BigDecimal totalPriceSum = BigDecimal.ZERO; + BigDecimal extraPriceSum = BigDecimal.ZERO; + BigDecimal payPriceSum = BigDecimal.ZERO; + BigDecimal refundPriceSum = BigDecimal.ZERO; + Long lineNumber = 1L; + for (HardMchOrderExcelVo v : excelList) { + v.setLineNumber(lineNumber); + lineNumber++; + if (ObjectUtil.isNotEmpty(v.getTotalPrice())) { + totalPriceSum = totalPriceSum.add(BigDecimal.valueOf(v.getTotalPrice())); + v.setTotalPrice(BigDecimal.valueOf(v.getTotalPrice()).divide(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP).doubleValue()); + } + if (ObjectUtil.isNotEmpty(v.getExtraPrice())) { + extraPriceSum = extraPriceSum.add(BigDecimal.valueOf(v.getExtraPrice())); + v.setExtraPrice(BigDecimal.valueOf(v.getExtraPrice()).divide(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP).doubleValue()); + } + if (ObjectUtil.isNotEmpty(v.getPayPrice())) { + payPriceSum = payPriceSum.add(BigDecimal.valueOf(v.getPayPrice())); + v.setPayPrice(BigDecimal.valueOf(v.getPayPrice()).divide(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP).doubleValue()); + } + if (ObjectUtil.isNotEmpty(v.getRefundPrice())) { + refundPriceSum = refundPriceSum.add(BigDecimal.valueOf(v.getRefundPrice())); + v.setRefundPrice(BigDecimal.valueOf(v.getRefundPrice()).divide(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP).doubleValue()); + } + if (ObjectUtil.isNotEmpty(v.getPayType())) { + HardPayTypeEnum hardPayTypeEnum = HardPayTypeEnum.valueOfByType(v.getPayType()); + if (ObjectUtil.isNotEmpty(hardPayTypeEnum)) { + v.setPayType(hardPayTypeEnum.getDescription()); + } + } + } + map.put("totalPriceSum", totalPriceSum.divide(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP).toString()); + map.put("extraPriceSum", extraPriceSum.divide(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP).toString()); + map.put("payPriceSum", payPriceSum.divide(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP).toString()); + map.put("refundPriceSum", refundPriceSum.divide(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP).toString()); + } + excelWriter.fill(map, writeSheet); + excelWriter.fill(excelList, fillConfig, writeSheet); + } + } @Operation(summary = "商户交易记录导出", description = "商户交易记录导出") @PostMapping("/export-cs") diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/mapper/order/HardOrderMapper.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/mapper/order/HardOrderMapper.java index 7f5ea38d6..1c4472a2f 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/mapper/order/HardOrderMapper.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/mapper/order/HardOrderMapper.java @@ -112,6 +112,8 @@ public interface HardOrderMapper extends PjcloudBaseMapper { List scopeList(@Param("dto") HardOrderDto dto, DataScope dataScope); + Long count(HardOrderDto dto, DataScope dataScope); + List listSb(@Param("dto") HardOrderDto dto, DataScope dataScope); List listRefundSb(@Param("dto") HardOrderDto refundDto, @Param("refundDataScope") DataScope refundDataScope); diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardCarServiceImpl.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardCarServiceImpl.java index 4d42cf77c..530c531c5 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardCarServiceImpl.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardCarServiceImpl.java @@ -36,6 +36,7 @@ import com.bsd.pjcloud.supermarket.entity.ShopSkuEntity; import com.bsd.pjcloud.supermarket.vo.app.ShopSpuDetailAppVo; import com.bsd.pjcloud.supermarket.vo.erp.SmErpUnitWithSpuVo; import com.bsd.pjcloud.supermarket.vo.mall.MallProductDetailAppVo; +import com.bsd.pjcloud.supermarket.vo.mall.MallProductSkuAppVo; import com.bsd.pjcloud.thirdparty.dto.pay.PayDto; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -422,11 +423,15 @@ public class HardCarServiceImpl extends ServiceImpl carObjectList = new ArrayList<>(); - List spuList = remoteMallProductService.getDetailByIds(productIds).getData(); + List spuList = remoteMallProductService.getSkusWithSpuBySkuIds(productIds).getData(); for (HardCreateCarDto v : productList) { HardCarEntity item = HardCarEntity.builder().parentCarId(parentCarId).build(); spuList.stream().filter(i -> ObjectUtil.equals(i.getId(), v.getProductId())).findFirst().ifPresent(spu -> { - Integer price = getSupermarket(spu); + if (ObjectUtil.isEmpty(spu.getSkuList())) { + throw new RuntimeException("共富商城商品无SKU信息商品名字:" + spu.getTitle() + "商品ID:" + spu.getId() + "请联系管理员"); + } + MallProductSkuAppVo skuDetail = spu.getSkuList().get(0); + Integer price = skuDetail.getPrice(); int totalPrice = 0; if (ObjectUtil.isNotEmpty(v.getProductCount()) && !ObjectUtil.equals(v.getProductCount(), 0)) { // 按数量 @@ -435,7 +440,7 @@ public class HardCarServiceImpl extends ServiceImpl itemList = carList.stream().map(v -> { MallProductStockChangeDTO.Item item = new MallProductStockChangeDTO.Item(); item.setId(v.getProductId()); - item.setProductType(1); if (ObjectUtil.isNotEmpty(v.getProductCount()) && !ObjectUtil.equals(v.getProductCount(), 0)) { // 按数量 int prouctCount = v.getProductCount(); diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardOrderTotalServiceImpl.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardOrderTotalServiceImpl.java index b1aad55ef..7359511f0 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardOrderTotalServiceImpl.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardOrderTotalServiceImpl.java @@ -359,7 +359,7 @@ public class HardOrderTotalServiceImpl implements HardOrderTotalService { } List deptList = remoteDeptService.getInnerAllDept(deptDto).getData(); if (ObjectUtil.isEmpty(deptList)) return null; - List deptIds = deptList.stream().map(SysDept::getDeptId).filter(ObjectUtil::isNotEmpty).distinct().toList(); + // List deptIds = deptList.stream().map(SysDept::getDeptId).filter(ObjectUtil::isNotEmpty).distinct().toList(); List resultList = deptList.stream().map(v -> { HardDeptTotalVo item = new HardDeptTotalVo(); item.setDeptId(v.getDeptId()); @@ -369,7 +369,8 @@ public class HardOrderTotalServiceImpl implements HardOrderTotalService { // 查询钱包批量充值流水 CompletableFuture> walletBatchFuture = CompletableFuture.supplyAsync(() -> { WalletTransactionSumAndCountDto walletDto = new WalletTransactionSumAndCountDto(); - walletDto.setDeptIds(deptIds); + walletDto.setDeptIds(dto.getDeptIds()); + walletDto.setIsInclude(dto.getIsInclude()); walletDto.setBizTypes(List.of(WalletBizEnum.BATCH.getCode())); walletDto.setType(WalletTransactionSumAndCountDto.TYPE_INCOME); if (ObjectUtil.isNotEmpty(dto.getCreateTimeList())) { @@ -383,7 +384,8 @@ public class HardOrderTotalServiceImpl implements HardOrderTotalService { // 查询钱包批量扣减流水 CompletableFuture> walletReduceFuture = CompletableFuture.supplyAsync(() -> { WalletTransactionSumAndCountDto walletDto = new WalletTransactionSumAndCountDto(); - walletDto.setDeptIds(deptIds); + walletDto.setDeptIds(dto.getDeptIds()); + walletDto.setIsInclude(dto.getIsInclude()); walletDto.setBizTypes(List.of(WalletBizEnum.BATCH.getCode())); walletDto.setType(WalletTransactionSumAndCountDto.TYPE_EXPENSE); if (ObjectUtil.isNotEmpty(dto.getCreateTimeList())) { @@ -397,7 +399,8 @@ public class HardOrderTotalServiceImpl implements HardOrderTotalService { // 查询钱包退还各自食堂 CompletableFuture> walletRetrunCanteenFuture = CompletableFuture.supplyAsync(() -> { WalletTransactionSumAndCountDto walletDto = new WalletTransactionSumAndCountDto(); - walletDto.setDeptIds(deptIds); + walletDto.setDeptIds(dto.getDeptIds()); + walletDto.setIsInclude(dto.getIsInclude()); walletDto.setBizTypes(List.of(WalletBizEnum.RETURN_CANTEEN.getCode())); // walletDto.setType(WalletTransactionSumAndCountDto.TYPE_EXPENSE); if (ObjectUtil.isNotEmpty(dto.getCreateTimeList())) { @@ -411,7 +414,8 @@ public class HardOrderTotalServiceImpl implements HardOrderTotalService { // 查询钱包单次充值流水 CompletableFuture> walletOnceBatchFuture = CompletableFuture.supplyAsync(() -> { WalletTransactionSumAndCountDto walletDto = new WalletTransactionSumAndCountDto(); - walletDto.setDeptIds(deptIds); + walletDto.setDeptIds(dto.getDeptIds()); + walletDto.setIsInclude(dto.getIsInclude()); walletDto.setBizTypes(List.of(WalletBizEnum.UPDATE.getCode())); walletDto.setType(WalletTransactionSumAndCountDto.TYPE_INCOME); if (ObjectUtil.isNotEmpty(dto.getCreateTimeList())) { @@ -425,7 +429,8 @@ public class HardOrderTotalServiceImpl implements HardOrderTotalService { // 查询钱包单次扣减流水 CompletableFuture> walletOnceReduceFuture = CompletableFuture.supplyAsync(() -> { WalletTransactionSumAndCountDto walletDto = new WalletTransactionSumAndCountDto(); - walletDto.setDeptIds(deptIds); + walletDto.setDeptIds(dto.getDeptIds()); + walletDto.setIsInclude(dto.getIsInclude()); walletDto.setBizTypes(List.of(WalletBizEnum.UPDATE.getCode())); walletDto.setType(WalletTransactionSumAndCountDto.TYPE_EXPENSE); if (ObjectUtil.isNotEmpty(dto.getCreateTimeList())) { @@ -439,7 +444,8 @@ public class HardOrderTotalServiceImpl implements HardOrderTotalService { // 查询订单支付流水 CompletableFuture> payFuture = CompletableFuture.supplyAsync(() -> { HardOrderSumAndCountDto payDto = new HardOrderSumAndCountDto(); - payDto.setUserDeptIds(deptIds); + payDto.setUserDeptIds(dto.getDeptIds()); + payDto.setIsInclude(dto.getIsInclude()); payDto.setOrderStatusCodes(HardOrderStatusEnum.getPayPrice()); if (ObjectUtil.isNotEmpty(dto.getCreateTimeList())) { payDto.setCreateTimeList(dto.getCreateTimeList()); @@ -452,7 +458,8 @@ public class HardOrderTotalServiceImpl implements HardOrderTotalService { // 查询订单退款流水 CompletableFuture> refundFuture = CompletableFuture.supplyAsync(() -> { HardOrderSumAndCountDto refundDto = new HardOrderSumAndCountDto(); - refundDto.setUserDeptIds(deptIds); + refundDto.setUserDeptIds(dto.getDeptIds()); + refundDto.setIsInclude(dto.getIsInclude()); refundDto.setOrderStatusCodes(HardOrderStatusEnum.getPayErrorCodes()); refundDto.setRefundStatusCodes(List.of(HardSaleStatusEnum.COMPLETE.getStatus())); if (ObjectUtil.isNotEmpty(dto.getCreateTimeList())) { diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/file/商户交易流水导出.xlsx b/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/file/商户交易流水导出.xlsx new file mode 100644 index 000000000..943218ced Binary files /dev/null and b/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/file/商户交易流水导出.xlsx differ diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardCarMapper.xml b/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardCarMapper.xml index 5c8f9e4c7..e835b8002 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardCarMapper.xml +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardCarMapper.xml @@ -77,13 +77,13 @@ - and o.dept_id IN + and o.user_dept_id IN - and o.dept_id NOT IN + and o.user_dept_id NOT IN - and o.dept_id IN + and o.user_dept_id IN diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardOrderMapper.xml b/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardOrderMapper.xml index fb9d5dc12..13147c267 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardOrderMapper.xml +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/resources/mapper/order/HardOrderMapper.xml @@ -231,6 +231,28 @@ + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pjcloud-wallet/pjcloud-wallet-biz/src/main/resources/mapper/WalletTransactionMapper.xml b/pjcloud-wallet/pjcloud-wallet-biz/src/main/resources/mapper/WalletTransactionMapper.xml index 0317eebb6..dd6ab9665 100644 --- a/pjcloud-wallet/pjcloud-wallet-biz/src/main/resources/mapper/WalletTransactionMapper.xml +++ b/pjcloud-wallet/pjcloud-wallet-biz/src/main/resources/mapper/WalletTransactionMapper.xml @@ -137,8 +137,9 @@ sum(a.price) as sum, count(0) as count from wallet_transaction a + left join wallet_manage m on m.id = a.wallet_id - a.del_flag = 0 and a.dept_id is not null + a.del_flag = 0 and m.dept_id is not null a.wallet_id = ${dto.walletId} @@ -159,7 +160,17 @@ - and a.dept_id in + + + and m.dept_id IN + + + and m.dept_id NOT IN + + + and m.dept_id IN + + #{v}