v1.0.79 #91
+14
-1
@@ -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<GaoRecycleLedger> 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)
|
||||
|
||||
@@ -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<GaoRecyclePayment> list(@RequestParam String orderId) { return service.list(orderId); }
|
||||
|
||||
@@ -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<String>, 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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -12,6 +12,8 @@ import java.util.List;
|
||||
/// 回收物额度流水 Mapper
|
||||
public interface GaoRecycleLedgerMapper extends BaseMapper<GaoRecycleLedger, String> {
|
||||
|
||||
GaoRecycleLedger detail(@Param("id") String id);
|
||||
|
||||
long countByQuery(GaoRecycleLedgerPage page);
|
||||
|
||||
List<GaoRecycleLedger> selectByQuery(GaoRecycleLedgerPage page);
|
||||
|
||||
@@ -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<GaoRecycleLedger> pageByQuery(GaoRecycleLedgerPage page) {
|
||||
PageResult<GaoRecycleLedger> result = new PageResult<>();
|
||||
result.setTotal(mapper.countByQuery(page));
|
||||
result.setList(mapper.selectByQuery(page));
|
||||
List<GaoRecycleLedger> records = mapper.selectByQuery(page);
|
||||
List<String> customerIds = records.stream().map(GaoRecycleLedger::getCustomerId)
|
||||
.filter(id -> id != null && !id.isBlank()).distinct().toList();
|
||||
if (!customerIds.isEmpty()) {
|
||||
Map<String, GaoCustomer> customers = customerService.mapByIdList(customerIds);
|
||||
Map<String, List<Attachment>> 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<GaoRecyclePayment> list(String orderId) {
|
||||
GaoSalesOrder order = orders.get(orderId);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -2,15 +2,43 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.imyeyu.api.modules.gao.mapper.GaoRecycleLedgerMapper">
|
||||
<sql id="ledgerQueryWhere">
|
||||
store_id=#{storeId} AND customer_id=#{customerId}
|
||||
l.store_id=#{storeId}
|
||||
<if test="customerId != null and customerId != ''">AND l.customer_id=#{customerId}</if>
|
||||
<if test="recycleItemId != null and recycleItemId != ''">AND l.recycle_item_id=#{recycleItemId}</if>
|
||||
<if test="bizType != null and bizType != ''">
|
||||
<choose>
|
||||
<when test="bizType == 'MANUAL'">AND l.biz_type IN ('MANUAL', 'ADJUST')</when>
|
||||
<otherwise>AND l.biz_type=#{bizType}</otherwise>
|
||||
</choose>
|
||||
</if>
|
||||
<if test="beginAt != null">AND l.created_at >= #{beginAt}</if>
|
||||
<if test="endAt != null">AND l.created_at <= #{endAt}</if>
|
||||
<if test="keyword != null and keyword != ''">
|
||||
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}, '%'))
|
||||
</if>
|
||||
</sql>
|
||||
<select id="countByQuery" resultType="long">
|
||||
SELECT COUNT(1) FROM gao_recycle_ledger WHERE <include refid="ledgerQueryWhere"/>
|
||||
SELECT COUNT(1) FROM gao_recycle_ledger l
|
||||
LEFT JOIN gao_customer c ON c.id=l.customer_id AND c.store_id=l.store_id
|
||||
WHERE <include refid="ledgerQueryWhere"/>
|
||||
</select>
|
||||
<select id="selectByQuery" resultType="com.imyeyu.api.modules.gao.entity.GaoRecycleLedger">
|
||||
SELECT * FROM gao_recycle_ledger WHERE <include refid="ledgerQueryWhere"/>
|
||||
ORDER BY created_at DESC, id DESC
|
||||
SELECT l.*, c.name AS customerName, c.code AS customerCode, i.name AS recycleName, i.unit_name AS recycleUnit
|
||||
FROM gao_recycle_ledger l
|
||||
LEFT JOIN gao_customer c ON c.id=l.customer_id AND c.store_id=l.store_id
|
||||
LEFT JOIN gao_recycle_item i ON i.id=l.recycle_item_id AND i.store_id=l.store_id
|
||||
WHERE <include refid="ledgerQueryWhere"/>
|
||||
ORDER BY l.created_at DESC, l.id DESC
|
||||
LIMIT #{offset}, #{limit}
|
||||
</select>
|
||||
<select id="detail" resultType="com.imyeyu.api.modules.gao.entity.GaoRecycleLedger">
|
||||
SELECT l.*, c.name AS customerName, c.code AS customerCode, i.name AS recycleName, i.unit_name AS recycleUnit
|
||||
FROM gao_recycle_ledger l
|
||||
LEFT JOIN gao_customer c ON c.id=l.customer_id AND c.store_id=l.store_id
|
||||
LEFT JOIN gao_recycle_item i ON i.id=l.recycle_item_id AND i.store_id=l.store_id
|
||||
WHERE l.id=#{id}
|
||||
</select>
|
||||
<select id="yieldsByFulfillment" resultType="com.imyeyu.api.modules.gao.entity.GaoRecycleLedger">
|
||||
SELECT recycle_item_id,balance_delta
|
||||
|
||||
@@ -12,9 +12,12 @@
|
||||
WHERE order_id=#{orderId} AND status='VERIFIED' AND source_payment_id IS NULL
|
||||
</select>
|
||||
<select id="search" resultType="com.imyeyu.api.modules.gao.entity.GaoRecyclePayment">
|
||||
SELECT p.*, e.id AS recycleExchangeId, e.recycle_name_snapshot AS recycleName, e.recycle_unit_snapshot AS recycleUnit
|
||||
SELECT p.*, e.id AS recycleExchangeId, e.recycle_name_snapshot AS recycleName, e.recycle_unit_snapshot AS recycleUnit,
|
||||
o.sale_amount AS salesOrderAmount,
|
||||
(o.sale_amount - COALESCE(o.paid_amount, 0)) AS salesOrderUnpaidAmount
|
||||
FROM gao_recycle_payment p
|
||||
LEFT JOIN gao_recycle_exchange e ON e.sales_order_id = p.order_id
|
||||
LEFT JOIN gao_sales_order o ON o.id = p.order_id AND o.store_id = p.store_id
|
||||
WHERE 1=1
|
||||
<if test='storeId != null'>
|
||||
AND p.store_id = #{storeId}
|
||||
|
||||
Reference in New Issue
Block a user