设置过状态处理
This commit is contained in:
parent
70742b3362
commit
5a6d1dfb64
@ -18,7 +18,9 @@ import com.red.circle.wallet.app.service.UserFreightService;
|
|||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.time.temporal.TemporalAdjusters;
|
||||||
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;
|
||||||
@ -136,13 +138,19 @@ public class FreightRestController extends BaseController {
|
|||||||
throw new RuntimeException("This operation is only allowed on the 1st of each month");
|
throw new RuntimeException("This operation is only allowed on the 1st of each month");
|
||||||
}
|
}
|
||||||
|
|
||||||
String monthKey = "freight:threshold:" + today.format(DateTimeFormatter.ofPattern("yyyy-MM"));
|
String monthKey = "freight:threshold:" + cmd.getReqUserId() + ":" + today.format(DateTimeFormatter.ofPattern("yyyy-MM"));
|
||||||
|
LocalDate lastDay = today.with(TemporalAdjusters.lastDayOfMonth());
|
||||||
|
LocalDateTime endOfMonth = lastDay.atTime(23, 59, 59);
|
||||||
|
long ttl = Duration.between(LocalDateTime.now(), endOfMonth).getSeconds();
|
||||||
|
if (ttl < 1) {
|
||||||
|
ttl = 1;
|
||||||
|
}
|
||||||
|
|
||||||
// 使用 Redis SETNX 实现“当月仅执行一次”
|
// 使用 Redis SETNX 实现“当月仅执行一次”
|
||||||
Boolean firstDo = redisTemplate.opsForValue().setIfAbsent(
|
Boolean firstDo = redisTemplate.opsForValue().setIfAbsent(
|
||||||
monthKey,
|
monthKey,
|
||||||
"done",
|
"done",
|
||||||
Duration.ofDays(today.lengthOfMonth())
|
Duration.ofSeconds(ttl)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (Boolean.FALSE.equals(firstDo)) {
|
if (Boolean.FALSE.equals(firstDo)) {
|
||||||
@ -162,7 +170,12 @@ public class FreightRestController extends BaseController {
|
|||||||
*/
|
*/
|
||||||
@GetMapping("/threshold")
|
@GetMapping("/threshold")
|
||||||
public FreightBalance getFreightThreshold(AppAccountCmd cmd) {
|
public FreightBalance getFreightThreshold(AppAccountCmd cmd) {
|
||||||
return freightBalanceService.getFreightBalance(cmd.getReqUserId());
|
FreightBalance freightBalance = freightBalanceService.getFreightBalance(cmd.getReqUserId());
|
||||||
|
if (freightBalance != null) {
|
||||||
|
String monthKey = "freight:threshold:" + cmd.getReqUserId() + ":" + LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM"));
|
||||||
|
freightBalance.setSettinged(redisTemplate.opsForValue().get(monthKey) != null);
|
||||||
|
}
|
||||||
|
return freightBalance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -112,4 +112,10 @@ public class FreightBalance extends TimestampBaseEntity {
|
|||||||
@TableField("delivery_threshold")
|
@TableField("delivery_threshold")
|
||||||
private Integer deliveryThreshold;
|
private Integer deliveryThreshold;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否设置过
|
||||||
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
|
private Boolean settinged;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user