Merge remote-tracking branch 'origin/master'

This commit is contained in:
zjf committed 2025-10-24 17:25:32 +08:00
commit 2cf9867971
13 files changed
+319 -116

No files matched your search

@@ -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;
}
@@ -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<Long> mchDtoIds = new ArrayList<>();
if (ObjectUtil.isNotEmpty(dto.getMerchantId())) {
List<MchManageVo> mchList = mchService.getByParentId(dto.getMerchantId()).getData();
if (ObjectUtil.isNotEmpty(mchList)) {
List<Long> 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<HardOrderVo> list = hardOrderService.scopeList(dto, DataScope.of());
List<HardMchOrderExcelVo> 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<String, Object> map = new HashMap<String, Object>();
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")
@@ -112,6 +112,8 @@ public interface HardOrderMapper extends PjcloudBaseMapper<HardOrderEntity> {
List<HardOrderVo> scopeList(@Param("dto") HardOrderDto dto, DataScope dataScope);
Long count(HardOrderDto dto, DataScope dataScope);
List<HardOrderSbVo> listSb(@Param("dto") HardOrderDto dto, DataScope dataScope);
List<HardOrderSbVo> listRefundSb(@Param("dto") HardOrderDto refundDto, @Param("refundDataScope") DataScope refundDataScope);
@@ -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<HardCarMapper, HardCarEntity
// 共富商城
if (ObjectUtil.equals(sysType, HardTypeEnum.FARMER)) {
List<HardCarEntity> carObjectList = new ArrayList<>();
List<MallProductDetailAppVo> spuList = remoteMallProductService.getDetailByIds(productIds).getData();
List<MallProductDetailAppVo> 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<HardCarMapper, HardCarEntity
// 按重量
totalPrice = v.getProductWeight().multiply(BigDecimal.valueOf(price)).setScale(0, RoundingMode.CEILING).intValue();
}
item.setProductId(spu.getId());
item.setProductId(skuDetail.getId());
item.setProductName(spu.getTitle());
item.setProductPrice(price);
item.setProductPic(spu.getCoverImage());
@@ -1317,7 +1317,6 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
List<MallProductStockChangeDTO.Item> 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();
@@ -359,7 +359,7 @@ public class HardOrderTotalServiceImpl implements HardOrderTotalService {
}
List<SysDept> deptList = remoteDeptService.getInnerAllDept(deptDto).getData();
if (ObjectUtil.isEmpty(deptList)) return null;
List<Long> deptIds = deptList.stream().map(SysDept::getDeptId).filter(ObjectUtil::isNotEmpty).distinct().toList();
// List<Long> deptIds = deptList.stream().map(SysDept::getDeptId).filter(ObjectUtil::isNotEmpty).distinct().toList();
List<HardDeptTotalVo> resultList = deptList.stream().map(v -> {
HardDeptTotalVo item = new HardDeptTotalVo();
item.setDeptId(v.getDeptId());
@@ -369,7 +369,8 @@ public class HardOrderTotalServiceImpl implements HardOrderTotalService {
// 查询钱包批量充值流水
CompletableFuture<List<WalletTransactionSumAndCountVo>> 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<List<WalletTransactionSumAndCountVo>> 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<List<WalletTransactionSumAndCountVo>> 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<List<WalletTransactionSumAndCountVo>> 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<List<WalletTransactionSumAndCountVo>> 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<List<HardOrderSumAndCountVo>> 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<List<HardOrderSumAndCountVo>> 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())) {
@@ -77,13 +77,13 @@
<if test="dto.deptIds != null and dto.deptIds.size() != 0">
<choose>
<when test="dto.isInclude != null and dto.isInclude == true">
and o.dept_id IN
and o.user_dept_id IN
</when>
<when test="dto.isInclude != null and dto.isInclude == false">
and o.dept_id NOT IN
and o.user_dept_id NOT IN
</when>
<otherwise>
and o.dept_id IN
and o.user_dept_id IN
</otherwise>
</choose>
<foreach collection="dto.deptIds" item="v" open="(" close=")" separator=",">
@@ -231,6 +231,28 @@
<include refid="pageList"/>
</select>
<select id="count" resultType="java.lang.Long">
select count(0)
from hard_order a
left join hard_manager m on m.id = a.hard_id
left join hard_after_sale s on s.order_id = a.id
<where>
<include refid="whereA"/>
<if test="dto.hardTypeCode != null and dto.hardTypeCode != '' ">
and m.type = #{dto.hardTypeCode}
</if>
<if test="dto.hardTypeCodes != null and dto.hardTypeCodes.size() != 0">
and m.type in
<foreach collection="dto.hardTypeCodes" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="dto.afterSaleNo != null and dto.afterSaleNo != ''">
and s.no = #{dto.afterSaleNo}
</if>
</where>
</select>
<select id="listSb" resultType="com.bsd.pjcloud.hard.api.vo.order.HardOrderSbVo">
select
a.hard_id,
@@ -422,7 +444,17 @@
</foreach>
</if>
<if test="dto.getUserDeptIds != null and dto.getUserDeptIds.size() != 0">
and a.user_dept_id in
<choose>
<when test="dto.isInclude != null and dto.isInclude == true">
and a.user_dept_id IN
</when>
<when test="dto.isInclude != null and dto.isInclude == false">
and a.user_dept_id NOT IN
</when>
<otherwise>
and a.user_dept_id IN
</otherwise>
</choose>
<foreach collection="dto.getUserDeptIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
@@ -453,7 +485,17 @@
</foreach>
</if>
<if test="dto.getUserDeptIds != null and dto.getUserDeptIds.size() != 0">
and o.user_dept_id in
<choose>
<when test="dto.isInclude != null and dto.isInclude == true">
and o.user_dept_id IN
</when>
<when test="dto.isInclude != null and dto.isInclude == false">
and o.user_dept_id NOT IN
</when>
<otherwise>
and o.user_dept_id IN
</otherwise>
</choose>
<foreach collection="dto.getUserDeptIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
@@ -35,9 +35,9 @@ public class MallProductServiceTest {
productCreateDTO.setBrand("测试品牌");
productCreateDTO.setCoverImage("https://example.com/cover.jpg");
productCreateDTO.setCarouselImages("https://example.com/img1.jpg,https://example.com/img2.jpg");
productCreateDTO.setPriceType(1); // 多SKU模式
// productCreateDTO.setPriceType(1); // 多SKU模式
productCreateDTO.setOriginalPrice(1);
productCreateDTO.setUnit("台");
// productCreateDTO.setUnit("台");
productCreateDTO.setStatus("0");
productCreateDTO.setSaleStartTime(LocalDateTime.now());
productCreateDTO.setSaleEndTime(LocalDateTime.now().plusYears(1));
@@ -84,10 +84,10 @@ public class MallProductServiceTest {
productCreateDTO.setBrand("测试品牌");
productCreateDTO.setCoverImage("https://example.com/cover.jpg");
productCreateDTO.setCarouselImages("https://example.com/img1.jpg");
productCreateDTO.setPriceType(2); // 单价SPU模式
productCreateDTO.setSpuPrice(1);
productCreateDTO.setOriginalPrice(1);
productCreateDTO.setUnit("台");
// productCreateDTO.setPriceType(2); // 单价SPU模式
// productCreateDTO.setSpuPrice(1);
// productCreateDTO.setOriginalPrice(1);
// productCreateDTO.setUnit("台");
productCreateDTO.setStatus("1");
productCreateDTO.setSaleStartTime(LocalDateTime.now());
productCreateDTO.setSaleEndTime(LocalDateTime.now().plusYears(1));
@@ -1,5 +1,6 @@
package com.bsd.pjcloud.wallet.api.dto;
import com.bsd.pjcloud.admin.api.vo.base.BaseIsIncludeTreeInterface;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@@ -7,7 +8,7 @@ import java.time.LocalDateTime;
import java.util.List;
@Data
public class WalletTransactionSumAndCountDto {
public class WalletTransactionSumAndCountDto implements BaseIsIncludeTreeInterface {
/**
* 类型 - 收入
*/
@@ -31,4 +32,9 @@ public class WalletTransactionSumAndCountDto {
private Long walletId;
/**
* 是否包含deptIds
*/
private Boolean isInclude = false;
}
@@ -194,50 +194,20 @@
</select>
<select id="selectTotalBalance" resultType="java.lang.Long">
SELECT
SUM(a.balance)
SELECT SUM(latest_balance.balance)
FROM (
SELECT DISTINCT a.user_id,
m.wallet_type_id,
FIRST_VALUE(a.balance) OVER (
PARTITION BY a.user_id, m.wallet_type_id
ORDER BY a.create_time DESC
) as balance
FROM wallet_transaction a
LEFT JOIN wallet_manage m on a.wallet_id = m.id
INNER JOIN wallet_manage m
ON a.wallet_id = m.id
<where>
a.del_flag = 0
<if test="dto.walletRecordMonth != null">
AND a.create_time = (
SELECT MAX(sub.create_time)
FROM wallet_transaction sub
LEFT JOIN wallet_manage wallet on wallet.id = sub.wallet_id
WHERE sub.user_id = a.user_id
AND DATE_FORMAT(sub.create_time, '%Y-%m') &lt;= #{dto.walletRecordMonth}
<if test="dto.userId != null">
AND sub.user_id = #{dto.userId}
</if>
<if test="dto.userIds != null and dto.userIds.size() != 0">
and sub.user_id in
<foreach collection="dto.userIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="dto.deptIds != null and dto.deptIds.size() != 0">
<choose>
<when test="dto.isInclude != null and dto.isInclude == true">
and wallet.dept_id IN
</when>
<when test="dto.isInclude != null and dto.isInclude == false">
and wallet.dept_id NOT IN
</when>
<otherwise>
and wallet.dept_id IN
</otherwise>
</choose>
<foreach collection="dto.deptIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="dto.walletTypeId != null">
AND wallet.wallet_type_id = #{dto.walletTypeId}
</if>
limit 1
)
</if>
a.del_flag = '0'
AND DATE_FORMAT(a.create_time, '%Y-%m') &lt;= #{dto.walletRecordMonth}
<if test="dto.userId != null">
AND a.user_id = #{dto.userId}
</if>
@@ -267,50 +237,79 @@
</foreach>
</if>
</where>
) latest_balance
</select>
<!-- SELECT SUM(latest_balance.balance)-->
<!-- FROM (-->
<!-- SELECT DISTINCT a.user_id,-->
<!-- m.wallet_type_id,-->
<!-- FIRST_VALUE(a.balance) OVER (-->
<!-- PARTITION BY a.user_id, m.wallet_type_id-->
<!-- ORDER BY a.create_time DESC-->
<!-- ) as balance-->
<!-- FROM wallet_transaction a-->
<!-- INNER JOIN wallet_manage m-->
<!-- ON a.wallet_id = m.id-->
<!-- <where>-->
<!-- a.del_flag = '0'-->
<!-- AND DATE_FORMAT(a.create_time, '%Y-%m') &lt;= #{dto.walletRecordMonth}-->
<!-- <if test="dto.userId != null">-->
<!-- AND a.user_id = #{dto.userId}-->
<!-- </if>-->
<!-- <if test="dto.walletTypeId != null">-->
<!-- AND m.wallet_type_id = #{dto.walletTypeId}-->
<!-- </if>-->
<!-- <if test="dto.userIds != null and dto.userIds.size() != 0">-->
<!-- and a.user_id in-->
<!-- <foreach collection="dto.userIds" item="v" open="(" close=")" separator=",">-->
<!-- #{v}-->
<!-- </foreach>-->
<!-- </if>-->
<!-- <if test="dto.deptIds != null and dto.deptIds.size() != 0">-->
<!-- <choose>-->
<!-- <when test="dto.isInclude != null and dto.isInclude == true">-->
<!-- and m.dept_id IN-->
<!-- </when>-->
<!-- <when test="dto.isInclude != null and dto.isInclude == false">-->
<!-- and m.dept_id NOT IN-->
<!-- </when>-->
<!-- <otherwise>-->
<!-- and m.dept_id IN-->
<!-- </otherwise>-->
<!-- </choose>-->
<!-- <foreach collection="dto.deptIds" item="v" open="(" close=")" separator=",">-->
<!-- #{v}-->
<!-- </foreach>-->
<!-- </if>-->
<!-- </where>-->
<!-- ) latest_balance-->
<!-- SELECT-->
<!-- SUM(a.balance)-->
<!-- FROM wallet_transaction a-->
<!-- LEFT JOIN wallet_manage m on a.wallet_id = m.id-->
<!-- <where>-->
<!-- a.del_flag = 0-->
<!-- <if test="dto.walletRecordMonth != null">-->
<!-- AND a.create_time = (-->
<!-- SELECT MAX(sub.create_time)-->
<!-- FROM wallet_transaction sub-->
<!-- LEFT JOIN wallet_manage wallet on wallet.id = sub.wallet_id-->
<!-- WHERE sub.user_id = a.user_id-->
<!-- AND DATE_FORMAT(sub.create_time, '%Y-%m') &lt;= #{dto.walletRecordMonth}-->
<!-- <if test="dto.userId != null">-->
<!-- AND sub.user_id = #{dto.userId}-->
<!-- </if>-->
<!-- <if test="dto.userIds != null and dto.userIds.size() != 0">-->
<!-- and sub.user_id in-->
<!-- <foreach collection="dto.userIds" item="v" open="(" close=")" separator=",">-->
<!-- #{v}-->
<!-- </foreach>-->
<!-- </if>-->
<!-- <if test="dto.deptIds != null and dto.deptIds.size() != 0">-->
<!-- <choose>-->
<!-- <when test="dto.isInclude != null and dto.isInclude == true">-->
<!-- and wallet.dept_id IN-->
<!-- </when>-->
<!-- <when test="dto.isInclude != null and dto.isInclude == false">-->
<!-- and wallet.dept_id NOT IN-->
<!-- </when>-->
<!-- <otherwise>-->
<!-- and wallet.dept_id IN-->
<!-- </otherwise>-->
<!-- </choose>-->
<!-- <foreach collection="dto.deptIds" item="v" open="(" close=")" separator=",">-->
<!-- #{v}-->
<!-- </foreach>-->
<!-- </if>-->
<!-- <if test="dto.walletTypeId != null">-->
<!-- AND wallet.wallet_type_id = #{dto.walletTypeId}-->
<!-- </if>-->
<!-- )-->
<!-- </if>-->
<!-- <if test="dto.userId != null">-->
<!-- AND a.user_id = #{dto.userId}-->
<!-- </if>-->
<!-- <if test="dto.walletTypeId != null">-->
<!-- AND m.wallet_type_id = #{dto.walletTypeId}-->
<!-- </if>-->
<!-- <if test="dto.userIds != null and dto.userIds.size() != 0">-->
<!-- and a.user_id in-->
<!-- <foreach collection="dto.userIds" item="v" open="(" close=")" separator=",">-->
<!-- #{v}-->
<!-- </foreach>-->
<!-- </if>-->
<!-- <if test="dto.deptIds != null and dto.deptIds.size() != 0">-->
<!-- <choose>-->
<!-- <when test="dto.isInclude != null and dto.isInclude == true">-->
<!-- and m.dept_id IN-->
<!-- </when>-->
<!-- <when test="dto.isInclude != null and dto.isInclude == false">-->
<!-- and m.dept_id NOT IN-->
<!-- </when>-->
<!-- <otherwise>-->
<!-- and m.dept_id IN-->
<!-- </otherwise>-->
<!-- </choose>-->
<!-- <foreach collection="dto.deptIds" item="v" open="(" close=")" separator=",">-->
<!-- #{v}-->
<!-- </foreach>-->
<!-- </if>-->
<!-- </where>-->
</mapper>
@@ -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
<where>
a.del_flag = 0 and a.dept_id is not null
a.del_flag = 0 and m.dept_id is not null
<if test="dto.walletId != null">
a.wallet_id = ${dto.walletId}
</if>
@@ -159,7 +160,17 @@
</foreach>
</if>
<if test="dto.deptIds != null and dto.deptIds.size() != 0">
and a.dept_id in
<choose>
<when test="dto.isInclude != null and dto.isInclude == true">
and m.dept_id IN
</when>
<when test="dto.isInclude != null and dto.isInclude == false">
and m.dept_id NOT IN
</when>
<otherwise>
and m.dept_id IN
</otherwise>
</choose>
<foreach collection="dto.deptIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>