发货门槛设置新增校验
This commit is contained in:
parent
ca06d12209
commit
13fc2e5f69
@ -4,8 +4,10 @@ import com.red.circle.common.business.dto.cmd.AppExtCommand;
|
|||||||
import com.red.circle.common.business.dto.cmd.app.AppAccountCmd;
|
import com.red.circle.common.business.dto.cmd.app.AppAccountCmd;
|
||||||
import com.red.circle.common.business.dto.cmd.app.AppFlowCmd;
|
import com.red.circle.common.business.dto.cmd.app.AppFlowCmd;
|
||||||
import com.red.circle.common.business.dto.cmd.app.AppUserIdCmd;
|
import com.red.circle.common.business.dto.cmd.app.AppUserIdCmd;
|
||||||
|
import com.red.circle.component.redis.service.RedisService;
|
||||||
import com.red.circle.framework.core.asserts.ResponseAssert;
|
import com.red.circle.framework.core.asserts.ResponseAssert;
|
||||||
import com.red.circle.framework.web.controller.BaseController;
|
import com.red.circle.framework.web.controller.BaseController;
|
||||||
|
import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils;
|
||||||
import com.red.circle.wallet.app.dto.clientobject.FreightAccountCO;
|
import com.red.circle.wallet.app.dto.clientobject.FreightAccountCO;
|
||||||
import com.red.circle.wallet.app.dto.clientobject.FreightDealerUserSearchResultCO;
|
import com.red.circle.wallet.app.dto.clientobject.FreightDealerUserSearchResultCO;
|
||||||
import com.red.circle.wallet.app.dto.clientobject.FreightRunningWaterCO;
|
import com.red.circle.wallet.app.dto.clientobject.FreightRunningWaterCO;
|
||||||
@ -14,6 +16,9 @@ import com.red.circle.wallet.app.dto.clientobject.FreightSellerCO;
|
|||||||
import com.red.circle.wallet.app.dto.cmd.*;
|
import com.red.circle.wallet.app.dto.cmd.*;
|
||||||
import com.red.circle.wallet.app.service.UserFreightService;
|
import com.red.circle.wallet.app.service.UserFreightService;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.red.circle.wallet.infra.database.rds.entity.freight.FreightBalance;
|
import com.red.circle.wallet.infra.database.rds.entity.freight.FreightBalance;
|
||||||
@ -21,6 +26,7 @@ import com.red.circle.wallet.infra.database.rds.service.freight.FreightBalanceSe
|
|||||||
import com.red.circle.wallet.inner.error.FreightErrorCode;
|
import com.red.circle.wallet.inner.error.FreightErrorCode;
|
||||||
import com.red.circle.wallet.inner.error.WalletErrorCode;
|
import com.red.circle.wallet.inner.error.WalletErrorCode;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@ -41,6 +47,7 @@ public class FreightRestController extends BaseController {
|
|||||||
|
|
||||||
private final UserFreightService userFreightService;
|
private final UserFreightService userFreightService;
|
||||||
private final FreightBalanceService freightBalanceService;
|
private final FreightBalanceService freightBalanceService;
|
||||||
|
private final RedisTemplate<String, String> redisTemplate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 货运账户余额.
|
* 货运账户余额.
|
||||||
@ -123,7 +130,26 @@ public class FreightRestController extends BaseController {
|
|||||||
|
|
||||||
@PutMapping("/threshold")
|
@PutMapping("/threshold")
|
||||||
public Boolean updateFreightBalance(@RequestBody @Validated FreightBalanceUpdateCmd cmd) {
|
public Boolean updateFreightBalance(@RequestBody @Validated FreightBalanceUpdateCmd cmd) {
|
||||||
FreightBalance freightBalance = freightBalanceService.getById(cmd.getReqUserId());
|
// 校验日期是否为每月一号
|
||||||
|
LocalDate today = LocalDate.now();
|
||||||
|
if (today.getDayOfMonth() != 1 && today.getMonthValue() != 12) {
|
||||||
|
throw new RuntimeException("This operation is only allowed on the 1st of each month");
|
||||||
|
}
|
||||||
|
|
||||||
|
String monthKey = "freight:threshold:" + today.format(DateTimeFormatter.ofPattern("yyyy-MM"));
|
||||||
|
|
||||||
|
// 使用 Redis SETNX 实现“当月仅执行一次”
|
||||||
|
Boolean firstDo = redisTemplate.opsForValue().setIfAbsent(
|
||||||
|
monthKey,
|
||||||
|
"done",
|
||||||
|
Duration.ofDays(today.lengthOfMonth())
|
||||||
|
);
|
||||||
|
|
||||||
|
if (Boolean.FALSE.equals(firstDo)) {
|
||||||
|
throw new RuntimeException("This operation has been performed this month and cannot be repeated");
|
||||||
|
}
|
||||||
|
|
||||||
|
FreightBalance freightBalance = freightBalanceService.getFreightBalance(cmd.getReqUserId());
|
||||||
ResponseAssert.notNull(FreightErrorCode.NOT_FREIGHT, freightBalance);
|
ResponseAssert.notNull(FreightErrorCode.NOT_FREIGHT, freightBalance);
|
||||||
freightBalance.setDeliveryThreshold(cmd.getDeliveryThreshold());
|
freightBalance.setDeliveryThreshold(cmd.getDeliveryThreshold());
|
||||||
return freightBalanceService.updateSelectiveById(freightBalance);
|
return freightBalanceService.updateSelectiveById(freightBalance);
|
||||||
@ -136,7 +162,7 @@ public class FreightRestController extends BaseController {
|
|||||||
*/
|
*/
|
||||||
@GetMapping("/threshold")
|
@GetMapping("/threshold")
|
||||||
public FreightBalance getFreightThreshold(AppAccountCmd cmd) {
|
public FreightBalance getFreightThreshold(AppAccountCmd cmd) {
|
||||||
return freightBalanceService.getById(cmd.getReqUserId());
|
return freightBalanceService.getFreightBalance(cmd.getReqUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -102,7 +102,7 @@ public class SendFreightShipCmdExe {
|
|||||||
ResponseAssert.isTrue(WalletErrorCode.INSUFFICIENT_BALANCE,
|
ResponseAssert.isTrue(WalletErrorCode.INSUFFICIENT_BALANCE,
|
||||||
ArithmeticUtils.gte(cmd.getQuantity(), BigDecimal.ZERO));
|
ArithmeticUtils.gte(cmd.getQuantity(), BigDecimal.ZERO));
|
||||||
|
|
||||||
FreightBalance freightBalance = freightBalanceService.getById(cmd.getReqUserId());
|
FreightBalance freightBalance = freightBalanceService.getFreightBalance(cmd.getReqUserId());
|
||||||
ResponseAssert.notNull(FreightErrorCode.NOT_FREIGHT, freightBalance);
|
ResponseAssert.notNull(FreightErrorCode.NOT_FREIGHT, freightBalance);
|
||||||
|
|
||||||
long result = cmd.getQuantity().divide(new BigDecimal(10000), RoundingMode.DOWN).setScale(0, RoundingMode.DOWN).longValue();
|
long result = cmd.getQuantity().divide(new BigDecimal(10000), RoundingMode.DOWN).setScale(0, RoundingMode.DOWN).longValue();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user