v1.0.79 #91
+3
-1
@@ -8,6 +8,7 @@ import com.imyeyu.api.modules.gao.entity.GaoCustomer;
|
||||
import com.imyeyu.api.modules.gao.mapper.GaoRecycleAccountMapper;
|
||||
import com.imyeyu.api.modules.gao.service.GaoCustomerService;
|
||||
import com.imyeyu.api.modules.gao.service.GaoRecycleAccountService;
|
||||
import com.imyeyu.api.modules.gao.service.GaoRecycleLedgerService;
|
||||
import com.imyeyu.api.modules.gao.service.GaoStoreScopeService;
|
||||
import com.imyeyu.api.modules.gao.vo.GaoRecycleAccountAdjustRequest;
|
||||
import com.imyeyu.java.bean.timi.TimiException;
|
||||
@@ -26,6 +27,7 @@ import com.imyeyu.utils.Time;
|
||||
public class GaoRecycleAccountController {
|
||||
private final GaoRecycleAccountMapper mapper;
|
||||
private final GaoRecycleAccountService service;
|
||||
private final GaoRecycleLedgerService ledgerService;
|
||||
private final GaoStoreScopeService scope;
|
||||
private final GaoCustomerService customerService;
|
||||
private final AttachmentService attachmentService;
|
||||
@@ -117,7 +119,7 @@ public class GaoRecycleAccountController {
|
||||
@PostMapping("/ledger")
|
||||
public List<Map<String, Object>> ledger(@RequestParam String storeId, @RequestParam String customerId) {
|
||||
checkCustomer(storeId, customerId);
|
||||
return mapper.listLedger(storeId, customerId);
|
||||
return ledgerService.listLedger(storeId, customerId);
|
||||
}
|
||||
|
||||
@RequireGaoPermission(GaoPermissionCode.RECYCLE_ACCOUNT_ADJUST)
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.imyeyu.api.modules.gao.entity;
|
||||
|
||||
import com.imyeyu.spring.annotation.table.AutoUUID;
|
||||
import com.imyeyu.spring.annotation.table.Id;
|
||||
import com.imyeyu.spring.entity.Creatable;
|
||||
import com.imyeyu.spring.entity.IDEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/// 回收物额度流水
|
||||
@Data
|
||||
public class GaoRecycleLedger implements IDEntity<String>, Creatable {
|
||||
@Id
|
||||
@AutoUUID
|
||||
private String id;
|
||||
private String accountId;
|
||||
private String storeId;
|
||||
private String customerId;
|
||||
private String recycleItemId;
|
||||
private String bizType;
|
||||
private String bizId;
|
||||
private String requestNo;
|
||||
private BigDecimal balanceDelta;
|
||||
private BigDecimal reservedDelta;
|
||||
private BigDecimal balanceAfter;
|
||||
private BigDecimal reservedAfter;
|
||||
private String operatorUserId;
|
||||
private String reason;
|
||||
private Long createdAt;
|
||||
}
|
||||
@@ -44,11 +44,6 @@ public interface GaoRecycleAccountMapper {
|
||||
@Select("SELECT id, name, unit_name AS unitName, status FROM gao_recycle_item WHERE store_id=#{store} ORDER BY name, id")
|
||||
List<Map<String, Object>> accountItems(@Param("store") String store);
|
||||
|
||||
@Select("SELECT id, account_id AS accountId, store_id AS storeId, customer_id AS customerId, recycle_item_id AS recycleItemId, " +
|
||||
"biz_type AS bizType, biz_id AS bizId, request_no AS requestNo, balance_delta AS balanceDelta, reserved_delta AS reservedDelta, " +
|
||||
"balance_after AS balanceAfter, reserved_after AS reservedAfter, operator_user_id AS operatorUserId, reason, created_at AS createdAt " +
|
||||
"FROM gao_recycle_ledger WHERE store_id=#{store} AND customer_id=#{customer} ORDER BY created_at DESC LIMIT 100")
|
||||
List<Map<String, Object>> listLedger(@Param("store") String store, @Param("customer") String customer);
|
||||
@Select("SELECT recycle_item_id,quantity_per_base FROM gao_recycle_product_yield WHERE store_id=#{store} AND sku_id=#{sku} AND deleted_at IS NULL ORDER BY recycle_item_id")
|
||||
List<Map<String, Object>> yields(@Param("store") String store, @Param("sku") String sku);
|
||||
|
||||
@@ -69,20 +64,14 @@ public interface GaoRecycleAccountMapper {
|
||||
"ORDER BY s.sort, s.name, y.recycle_item_id")
|
||||
List<Map<String, Object>> yieldListByProduct(@Param("store") String store, @Param("product") String product);
|
||||
|
||||
@Select("SELECT recycle_item_id,balance_delta FROM gao_recycle_ledger WHERE biz_type='FULFILLMENT_YIELD' AND biz_id=#{biz} ORDER BY recycle_item_id")
|
||||
List<Map<String, Object>> yieldsByFulfillment(@Param("biz") String biz);
|
||||
@Insert("INSERT IGNORE INTO gao_recycle_account (id,store_id,customer_id,recycle_item_id,balance,reserved,created_at) VALUES (#{id},#{store},#{customer},#{item},0,0,#{now})")
|
||||
void ensure(@Param("id") String id, @Param("store") String store, @Param("customer") String customer, @Param("item") String item, @Param("now") long now);
|
||||
|
||||
@Select("SELECT id,balance,reserved FROM gao_recycle_account WHERE store_id=#{store} AND customer_id=#{customer} AND recycle_item_id=#{item} FOR UPDATE")
|
||||
Map<String, Object> lock(@Param("store") String store, @Param("customer") String customer, @Param("item") String item);
|
||||
|
||||
@Select("SELECT customer_id,recycle_item_id,biz_type,biz_id,balance_delta,reserved_delta,reason FROM gao_recycle_ledger WHERE store_id=#{store} AND request_no=#{request} FOR UPDATE")
|
||||
Map<String, Object> findRequest(@Param("store") String store, @Param("request") String request);
|
||||
|
||||
@Update("UPDATE gao_recycle_account SET balance=balance+#{balance},reserved=reserved+#{reserved},updated_at=#{now} WHERE id=#{id} AND balance+#{balance} >= 0 AND reserved+#{reserved} >= 0 AND reserved+#{reserved} <= balance+#{balance}")
|
||||
int change(@Param("id") String id, @Param("balance") BigDecimal balance, @Param("reserved") BigDecimal reserved, @Param("now") long now);
|
||||
|
||||
@Insert("INSERT INTO gao_recycle_ledger (id,account_id,store_id,customer_id,recycle_item_id,biz_type,biz_id,request_no,balance_delta,reserved_delta,balance_after,reserved_after,operator_user_id,reason,created_at) SELECT #{id},id,store_id,customer_id,recycle_item_id,#{type},#{biz},#{request},#{balance},#{reserved},balance,reserved,#{operator},#{reason},#{now} FROM gao_recycle_account WHERE id=#{account}")
|
||||
void ledger(@Param("id") String id, @Param("account") String account, @Param("type") String type, @Param("biz") String biz, @Param("request") String request, @Param("balance") BigDecimal balance, @Param("reserved") BigDecimal reserved, @Param("operator") String operator, @Param("reason") String reason, @Param("now") long now);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.imyeyu.api.modules.gao.mapper;
|
||||
|
||||
import com.imyeyu.api.modules.gao.entity.GaoRecycleLedger;
|
||||
import com.imyeyu.spring.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/// 回收物额度流水 Mapper
|
||||
public interface GaoRecycleLedgerMapper extends BaseMapper<GaoRecycleLedger, String> {
|
||||
@Select("SELECT id, account_id AS accountId, store_id AS storeId, customer_id AS customerId, recycle_item_id AS recycleItemId, " +
|
||||
"biz_type AS bizType, biz_id AS bizId, request_no AS requestNo, balance_delta AS balanceDelta, reserved_delta AS reservedDelta, " +
|
||||
"balance_after AS balanceAfter, reserved_after AS reservedAfter, operator_user_id AS operatorUserId, reason, created_at AS createdAt " +
|
||||
"FROM gao_recycle_ledger WHERE store_id=#{store} AND customer_id=#{customer} ORDER BY created_at DESC LIMIT 100")
|
||||
List<Map<String, Object>> listLedger(@Param("store") String store, @Param("customer") String customer);
|
||||
|
||||
@Select("SELECT recycle_item_id,balance_delta FROM gao_recycle_ledger WHERE biz_type='FULFILLMENT_YIELD' AND biz_id=#{biz} ORDER BY recycle_item_id")
|
||||
List<Map<String, Object>> yieldsByFulfillment(@Param("biz") String biz);
|
||||
|
||||
@Select("SELECT customer_id,recycle_item_id,biz_type,biz_id,balance_delta,reserved_delta,reason FROM gao_recycle_ledger WHERE store_id=#{store} AND request_no=#{request} FOR UPDATE")
|
||||
Map<String, Object> findRequest(@Param("store") String store, @Param("request") String request);
|
||||
|
||||
@Insert("INSERT INTO gao_recycle_ledger (id,account_id,store_id,customer_id,recycle_item_id,biz_type,biz_id,request_no,balance_delta,reserved_delta,balance_after,reserved_after,operator_user_id,reason,created_at) SELECT #{id},id,store_id,customer_id,recycle_item_id,#{type},#{biz},#{request},#{balance},#{reserved},balance,reserved,#{operator},#{reason},#{now} FROM gao_recycle_account WHERE id=#{account}")
|
||||
void ledger(@Param("id") String id, @Param("account") String account, @Param("type") String type, @Param("biz") String biz, @Param("request") String request, @Param("balance") BigDecimal balance, @Param("reserved") BigDecimal reserved, @Param("operator") String operator, @Param("reason") String reason, @Param("now") long now);
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import com.imyeyu.api.modules.gao.entity.GaoOrderFulfillmentItem;
|
||||
@RequiredArgsConstructor
|
||||
public class GaoRecycleAccountService {
|
||||
private final GaoRecycleAccountMapper mapper;
|
||||
private final GaoRecycleLedgerService ledgerService;
|
||||
private final UserLoginService login;
|
||||
|
||||
/// 按实际履约产生客户额度,规则结果写入流水快照
|
||||
@@ -46,7 +47,7 @@ public class GaoRecycleAccountService {
|
||||
|
||||
/// 撤回原履约产生的额度,不追溯历史履约
|
||||
public void revokeFulfillment(String store, String customer, String sourceId, String reverseId) {
|
||||
for (Map<String, Object> row : mapper.yieldsByFulfillment(sourceId)) {
|
||||
for (Map<String, Object> row : ledgerService.yieldsByFulfillment(sourceId)) {
|
||||
String item = (String) row.get("recycle_item_id");
|
||||
BigDecimal value = (BigDecimal) row.get("balance_delta");
|
||||
change(store, customer, item, value.negate(), BigDecimal.ZERO, "FULFILLMENT_REVOKE", reverseId, "yield-revoke:" + reverseId + ":" + item, null);
|
||||
@@ -80,7 +81,7 @@ public class GaoRecycleAccountService {
|
||||
mapper.ensure(UUID.randomUUID().toString(), storeId, customerId, recycleItemId, now);
|
||||
Map<String, Object> account = mapper.lock(storeId, customerId, recycleItemId);
|
||||
TimiException.required(account, "额度账户不存在");
|
||||
Map<String, Object> existing = mapper.findRequest(storeId, requestNo);
|
||||
Map<String, Object> existing = ledgerService.findRequest(storeId, requestNo);
|
||||
if (existing != null) {
|
||||
TimiException.requiredTrue(Objects.equals(customerId, existing.get("customer_id")) && Objects.equals(recycleItemId, existing.get("recycle_item_id"))
|
||||
&& Objects.equals(bizType, existing.get("biz_type")) && Objects.equals(bizId, existing.get("biz_id"))
|
||||
@@ -91,6 +92,6 @@ public class GaoRecycleAccountService {
|
||||
}
|
||||
String id = (String) account.get("id");
|
||||
TimiException.requiredTrue(mapper.change(id, balanceDelta, reservedDelta, now) == 1, "可用回收物额度不足");
|
||||
mapper.ledger(UUID.randomUUID().toString(), id, bizType, bizId, requestNo, balanceDelta, reservedDelta, login.getRequireLoginUserId(), reason, now);
|
||||
ledgerService.ledger(UUID.randomUUID().toString(), id, bizType, bizId, requestNo, balanceDelta, reservedDelta, login.getRequireLoginUserId(), reason, now);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.imyeyu.api.modules.gao.service;
|
||||
|
||||
import com.imyeyu.api.modules.gao.mapper.GaoRecycleLedgerMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
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;
|
||||
|
||||
public List<Map<String, Object>> listLedger(String store, String customer) {
|
||||
return mapper.listLedger(store, customer);
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> yieldsByFulfillment(String biz) {
|
||||
return mapper.yieldsByFulfillment(biz);
|
||||
}
|
||||
|
||||
public Map<String, Object> findRequest(String store, String request) {
|
||||
return mapper.findRequest(store, request);
|
||||
}
|
||||
|
||||
public void ledger(String id, String account, String type, String biz, String request, BigDecimal balance,
|
||||
BigDecimal reserved, String operator, String reason, long now) {
|
||||
mapper.ledger(id, account, type, biz, request, balance, reserved, operator, reason, now);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user