diff --git a/src/main/java/com/imyeyu/api/modules/gao/controller/GaoRecycleLedgerController.java b/src/main/java/com/imyeyu/api/modules/gao/controller/GaoRecycleLedgerController.java index d7b3f49..5d99eeb 100644 --- a/src/main/java/com/imyeyu/api/modules/gao/controller/GaoRecycleLedgerController.java +++ b/src/main/java/com/imyeyu/api/modules/gao/controller/GaoRecycleLedgerController.java @@ -30,11 +30,24 @@ public class GaoRecycleLedgerController { private final GaoStoreScopeService scope; private final GaoCustomerService customerService; + @RequireGaoPermission(GaoPermissionCode.RECYCLE_ACCOUNT_READ) + @PostMapping("/detail") + public GaoRecycleLedger detail(@RequestParam String id) { + GaoRecycleLedger ledger = service.detail(id); + TimiException.required(ledger, "回收物流水不存在"); + scope.checkStoreId(ledger.getStoreId()); + return ledger; + } + @RequireGaoPermission(GaoPermissionCode.RECYCLE_ACCOUNT_READ) @PostMapping("/list") public PageResult list(@RequestBody GaoRecycleLedgerPage page) { TimiException.required(page, "请求不能为空"); - checkCustomer(page.getStoreId(), page.getCustomerId()); + scope.checkStoreId(page.getStoreId()); + if (page.getCustomerId() != null && !page.getCustomerId().isBlank()) { + checkCustomer(page.getStoreId(), page.getCustomerId()); + } + TimiException.requiredTrue(page.getIndex() >= 0 && page.getSize() > 0 && page.getSize() <= 100, "分页参数无效"); return service.pageByQuery(page); } @RequireGaoPermission(GaoPermissionCode.RECYCLE_ACCOUNT_ADJUST) diff --git a/src/main/java/com/imyeyu/api/modules/gao/controller/GaoRecyclePaymentController.java b/src/main/java/com/imyeyu/api/modules/gao/controller/GaoRecyclePaymentController.java index ba1f8b5..52907be 100644 --- a/src/main/java/com/imyeyu/api/modules/gao/controller/GaoRecyclePaymentController.java +++ b/src/main/java/com/imyeyu/api/modules/gao/controller/GaoRecyclePaymentController.java @@ -33,6 +33,10 @@ public class GaoRecyclePaymentController { @PostMapping("/create-and-verify") public GaoRecyclePayment createAndVerify(@RequestBody GaoRecyclePaymentRequest request) { return service.createAndVerify(request); } + @RequireGaoPermission(GaoPermissionCode.FUND_RECORD_READ) + @PostMapping("/detail") + public GaoRecyclePayment detail(@RequestParam String id) { return service.detail(id); } + @RequireGaoPermission(GaoPermissionCode.FUND_RECORD_READ) @PostMapping("/list") public List list(@RequestParam String orderId) { return service.list(orderId); } diff --git a/src/main/java/com/imyeyu/api/modules/gao/entity/GaoRecycleLedger.java b/src/main/java/com/imyeyu/api/modules/gao/entity/GaoRecycleLedger.java index 9a890ef..9204e59 100644 --- a/src/main/java/com/imyeyu/api/modules/gao/entity/GaoRecycleLedger.java +++ b/src/main/java/com/imyeyu/api/modules/gao/entity/GaoRecycleLedger.java @@ -1,7 +1,9 @@ package com.imyeyu.api.modules.gao.entity; +import com.imyeyu.api.modules.user.entity.User; import com.imyeyu.spring.annotation.table.AutoUUID; import com.imyeyu.spring.annotation.table.Id; +import com.imyeyu.spring.annotation.table.Transient; import com.imyeyu.spring.entity.Creatable; import com.imyeyu.spring.entity.IDEntity; import lombok.Data; @@ -47,6 +49,18 @@ public class GaoRecycleLedger implements IDEntity, Creatable { private BigDecimal balanceAfter; private BigDecimal reservedAfter; private String operatorUserId; + @Transient + private User operator; private String reason; private Long createdAt; + @Transient + private GaoCustomer customer; + @Transient + private String customerName; + @Transient + private String customerCode; + @Transient + private String recycleName; + @Transient + private String recycleUnit; } diff --git a/src/main/java/com/imyeyu/api/modules/gao/entity/GaoRecyclePayment.java b/src/main/java/com/imyeyu/api/modules/gao/entity/GaoRecyclePayment.java index c82409e..686e0a5 100644 --- a/src/main/java/com/imyeyu/api/modules/gao/entity/GaoRecyclePayment.java +++ b/src/main/java/com/imyeyu/api/modules/gao/entity/GaoRecyclePayment.java @@ -51,6 +51,12 @@ public class GaoRecyclePayment extends UUIDEntity { private String recycleName; @Transient private String recycleUnit; + /// 关联订单当前成交金额,单位分 + @Transient + private Long salesOrderAmount; + /// 关联订单当前剩余待收金额,单位分 + @Transient + private Long salesOrderUnpaidAmount; @Transient private GaoCustomer customer; @Transient diff --git a/src/main/java/com/imyeyu/api/modules/gao/mapper/GaoRecycleLedgerMapper.java b/src/main/java/com/imyeyu/api/modules/gao/mapper/GaoRecycleLedgerMapper.java index f3f628b..7ef3e32 100644 --- a/src/main/java/com/imyeyu/api/modules/gao/mapper/GaoRecycleLedgerMapper.java +++ b/src/main/java/com/imyeyu/api/modules/gao/mapper/GaoRecycleLedgerMapper.java @@ -12,6 +12,8 @@ import java.util.List; /// 回收物额度流水 Mapper public interface GaoRecycleLedgerMapper extends BaseMapper { + GaoRecycleLedger detail(@Param("id") String id); + long countByQuery(GaoRecycleLedgerPage page); List selectByQuery(GaoRecycleLedgerPage page); diff --git a/src/main/java/com/imyeyu/api/modules/gao/service/GaoRecycleLedgerService.java b/src/main/java/com/imyeyu/api/modules/gao/service/GaoRecycleLedgerService.java index c5d7875..45d936d 100644 --- a/src/main/java/com/imyeyu/api/modules/gao/service/GaoRecycleLedgerService.java +++ b/src/main/java/com/imyeyu/api/modules/gao/service/GaoRecycleLedgerService.java @@ -1,6 +1,11 @@ package com.imyeyu.api.modules.gao.service; import com.imyeyu.api.modules.gao.mapper.GaoRecycleLedgerMapper; +import com.imyeyu.api.modules.user.entity.User; +import com.imyeyu.api.modules.user.service.UserService; +import com.imyeyu.api.modules.gao.entity.GaoCustomer; +import com.imyeyu.api.modules.common.entity.Attachment; +import com.imyeyu.api.modules.common.service.AttachmentService; import com.imyeyu.api.modules.gao.entity.GaoRecycleLedger; import com.imyeyu.api.modules.gao.vo.recycle.GaoRecycleLedgerPage; import com.imyeyu.spring.bean.PageResult; @@ -10,17 +15,51 @@ import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.util.List; +import java.util.Map; /// 回收物额度流水服务 @Service @RequiredArgsConstructor public class GaoRecycleLedgerService { private final GaoRecycleLedgerMapper mapper; + private final GaoCustomerService customerService; + private final AttachmentService attachmentService; + private final UserService userService; + + public GaoRecycleLedger detail(String id) { + GaoRecycleLedger ledger = mapper.detail(id); + if (ledger != null && ledger.getOperatorUserId() != null && !ledger.getOperatorUserId().isBlank()) { + User source = userService.get(ledger.getOperatorUserId()); + if (source != null) { + User operator = new User(); + operator.setId(source.getId()); + operator.setName(source.getName()); + operator.setNick(source.getNick()); + ledger.setOperator(operator); + } + } + return ledger; + } public PageResult pageByQuery(GaoRecycleLedgerPage page) { PageResult result = new PageResult<>(); result.setTotal(mapper.countByQuery(page)); - result.setList(mapper.selectByQuery(page)); + List records = mapper.selectByQuery(page); + List customerIds = records.stream().map(GaoRecycleLedger::getCustomerId) + .filter(id -> id != null && !id.isBlank()).distinct().toList(); + if (!customerIds.isEmpty()) { + Map customers = customerService.mapByIdList(customerIds); + Map> photos = attachmentService.mapByBizIdList( + Attachment.BizType.GAO_CUSTOMER, customerIds, GaoCustomer.AttachType.PHOTO.name()); + records.forEach(record -> { + GaoCustomer customer = customers.get(record.getCustomerId()); + if (customer != null) { + customer.setAttachmentList(photos.getOrDefault(customer.getId(), List.of())); + record.setCustomer(customer); + } + }); + } + result.setList(records); return result; } diff --git a/src/main/java/com/imyeyu/api/modules/gao/service/GaoRecyclePaymentService.java b/src/main/java/com/imyeyu/api/modules/gao/service/GaoRecyclePaymentService.java index 84d7bac..3c6aff3 100644 --- a/src/main/java/com/imyeyu/api/modules/gao/service/GaoRecyclePaymentService.java +++ b/src/main/java/com/imyeyu/api/modules/gao/service/GaoRecyclePaymentService.java @@ -49,6 +49,14 @@ public class GaoRecyclePaymentService { return order.getRecycleRequiredQuantity() != null && 0 <= mapper.paid(order.getId()).compareTo(order.getRecycleRequiredQuantity()); } + /// 查询单笔回收物支付记录 + public GaoRecyclePayment detail(String id) { + GaoRecyclePayment payment = mapper.byId(id); + TimiException.required(payment, "支付记录不存在"); + scope.checkStoreId(payment.getStoreId()); + return payment; + } + /// 查询订单的回收物支付记录 public List list(String orderId) { GaoSalesOrder order = orders.get(orderId); diff --git a/src/main/java/com/imyeyu/api/modules/gao/vo/recycle/GaoRecycleLedgerPage.java b/src/main/java/com/imyeyu/api/modules/gao/vo/recycle/GaoRecycleLedgerPage.java index 03636b1..6c87d9c 100644 --- a/src/main/java/com/imyeyu/api/modules/gao/vo/recycle/GaoRecycleLedgerPage.java +++ b/src/main/java/com/imyeyu/api/modules/gao/vo/recycle/GaoRecycleLedgerPage.java @@ -10,4 +10,9 @@ import lombok.EqualsAndHashCode; public class GaoRecycleLedgerPage extends BasePage { private String storeId; private String customerId; + private String recycleItemId; + private String keyword; + private String bizType; + private Long beginAt; + private Long endAt; } diff --git a/src/main/resources/mapper/timi-server/gao/GaoRecycleLedgerMapper.xml b/src/main/resources/mapper/timi-server/gao/GaoRecycleLedgerMapper.xml index 0d6dade..dd756b1 100644 --- a/src/main/resources/mapper/timi-server/gao/GaoRecycleLedgerMapper.xml +++ b/src/main/resources/mapper/timi-server/gao/GaoRecycleLedgerMapper.xml @@ -2,15 +2,43 @@ - store_id=#{storeId} AND customer_id=#{customerId} + l.store_id=#{storeId} + AND l.customer_id=#{customerId} + AND l.recycle_item_id=#{recycleItemId} + + + AND l.biz_type IN ('MANUAL', 'ADJUST') + AND l.biz_type=#{bizType} + + + AND l.created_at >= #{beginAt} + AND l.created_at <= #{endAt} + + AND (c.name LIKE CONCAT('%', #{keyword}, '%') OR c.code LIKE CONCAT('%', #{keyword}, '%') + OR c.name_pinyin_full LIKE CONCAT('%', #{keyword}, '%') OR c.name_pinyin_initial LIKE CONCAT('%', #{keyword}, '%') + OR c.name_pinyin_mixed LIKE CONCAT('%', #{keyword}, '%')) + +