v1.0.69
CI / build-deploy (pull_request) Successful in 33s
CI / notify-on-failure (pull_request) Skipped

This commit is contained in:
Timi
2026-11-08 20:04:59 +08:00
parent 74dd150469
commit bc901e2f0b
3 changed files with 13 additions and 3 deletions
+1 -1
View File
@@ -11,7 +11,7 @@
<groupId>com.imyeyu.timiserverapi</groupId> <groupId>com.imyeyu.timiserverapi</groupId>
<artifactId>TimiServerAPI</artifactId> <artifactId>TimiServerAPI</artifactId>
<version>1.0.68</version> <version>1.0.69</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>TimiServerAPI</name> <name>TimiServerAPI</name>
<description>imyeyu.com API</description> <description>imyeyu.com API</description>
@@ -23,6 +23,10 @@ public interface GaoRecycleExchangeWriteMapper extends BaseMapper<GaoRecycleExch
@Select("SELECT * FROM gao_recycle_exchange WHERE store_id=#{storeId} AND id=#{id} FOR UPDATE") @Select("SELECT * FROM gao_recycle_exchange WHERE store_id=#{storeId} AND id=#{id} FOR UPDATE")
GaoRecycleExchange lockExchange(@Param("storeId") String storeId, @Param("id") String id); GaoRecycleExchange lockExchange(@Param("storeId") String storeId, @Param("id") String id);
/// 不加锁按 ID 取单,只用于动作请求未带门店时反查归属门店;一致性仍由后续 lockExchange 保证
@Select("SELECT * FROM gao_recycle_exchange WHERE id=#{id}")
GaoRecycleExchange byId(@Param("id") String id);
@Select("SELECT * FROM gao_recycle_exchange_action WHERE store_id=#{storeId} AND request_no=#{requestNo}") @Select("SELECT * FROM gao_recycle_exchange_action WHERE store_id=#{storeId} AND request_no=#{requestNo}")
GaoRecycleExchangeAction actionByRequest(@Param("storeId") String storeId, @Param("requestNo") String requestNo); GaoRecycleExchangeAction actionByRequest(@Param("storeId") String storeId, @Param("requestNo") String requestNo);
@@ -84,6 +84,8 @@ public class GaoRecycleExchangeWriteService {
TimiException.requiredTrue(fingerprint.equals(existing.getRequestFingerprint()), "请求号对应的内容不一致"); TimiException.requiredTrue(fingerprint.equals(existing.getRequestFingerprint()), "请求号对应的内容不一致");
return existing; return existing;
} }
// 凭证是核销依据,新建必须上传;幂等重放走上面的分支,不受此约束影响
TimiException.requiredTrue(request.getAttachmentList() != null && !request.getAttachmentList().isEmpty(), "请上传兑换凭证");
GaoCustomer customer = customerService.get(request.getCustomerId()); GaoCustomer customer = customerService.get(request.getCustomerId());
TimiException.required(customer, "客户不存在"); TimiException.required(customer, "客户不存在");
TimiException.requiredTrue(store.equals(customer.getStoreId()), "客户不属于当前门店"); TimiException.requiredTrue(store.equals(customer.getStoreId()), "客户不属于当前门店");
@@ -174,11 +176,15 @@ public class GaoRecycleExchangeWriteService {
@OperationAudit(AuditOperation.GAO_RECYCLE_EXCHANGE_ACTION) @OperationAudit(AuditOperation.GAO_RECYCLE_EXCHANGE_ACTION)
public GaoRecycleExchange apply(GaoRecycleExchangeActionRequest request, GaoRecycleExchangeAction.ActionType type) { public GaoRecycleExchange apply(GaoRecycleExchangeActionRequest request, GaoRecycleExchangeAction.ActionType type) {
TimiException.required(request, "请求不能为空"); TimiException.required(request, "请求不能为空");
String store = scope.resolveStoreId(request.getStoreId());
TimiException.required(store, "门店不能为空");
TimiException.required(request.getExchangeId(), "兑换单不能为空"); TimiException.required(request.getExchangeId(), "兑换单不能为空");
TimiException.required(request.getRequestNo(), "请求号不能为空"); TimiException.required(request.getRequestNo(), "请求号不能为空");
TimiException.requiredTrue(!request.getRequestNo().isBlank() && !(128 < request.getRequestNo().length()), "请求号无效"); TimiException.requiredTrue(!request.getRequestNo().isBlank() && !(128 < request.getRequestNo().length()), "请求号无效");
// 门店是兑换单自身的属性,调用方不必重复传:按 ID 取单快照确定门店,
// 再用单据门店加锁串行化,越权访问由 checkStoreId 拦住
GaoRecycleExchange snapshot = mapper.byId(request.getExchangeId());
TimiException.required(snapshot, "兑换单不存在");
scope.checkStoreId(snapshot.getStoreId());
String store = snapshot.getStoreId();
String fingerprint = fingerprint(request.getExchangeId(), type, request.getOccurredAt(), request.getReason(), request.getRemark(), request.getRecycleReturned(), request.getStockReturned(), attachments(request.getAttachmentList())); String fingerprint = fingerprint(request.getExchangeId(), type, request.getOccurredAt(), request.getReason(), request.getRemark(), request.getRecycleReturned(), request.getStockReturned(), attachments(request.getAttachmentList()));
// 门店锁串行化同门店请求,确保幂等检查和写入之间不发生竞争 // 门店锁串行化同门店请求,确保幂等检查和写入之间不发生竞争
TimiException.required(mapper.lockStore(store), "门店不存在"); TimiException.required(mapper.lockStore(store), "门店不存在");