From a4861816c0b9cb27c655a7066f627b90afb23f54 Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Mon, 13 Oct 2025 16:56:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=8A=E6=9C=88=E7=BB=93=E7=AE=97=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../other/adapter/app/TestRestController.java | 2 +- .../query/TeamHistoryWorkCountQryExe.java | 2 + .../strategy/GiftAnchorCountStrategy.java | 9 +-- .../other/app/scheduler/TeamBillTask.java | 24 +++++--- .../infra/common/team/TeamTargetCommon.java | 14 +++-- .../service/team/TeamBillCycleUtils.java | 30 ++++++++++ .../team/impl/TeamBillCycleServiceImpl.java | 58 +++++++++++++++---- 7 files changed, 104 insertions(+), 35 deletions(-) diff --git a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/TestRestController.java b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/TestRestController.java index dfe26097..56083ea8 100644 --- a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/TestRestController.java +++ b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/TestRestController.java @@ -134,7 +134,7 @@ public class TestRestController extends BaseController { @PostMapping("/processTeamMonthBill") public void processTeamMonthBill() { - teamBillTask.processTeamMonthBill(); + teamBillTask.processTeamHalfMonthBill(); } @PostMapping("/activity/send/game") diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamHistoryWorkCountQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamHistoryWorkCountQryExe.java index 24bf83ae..785a0ea4 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamHistoryWorkCountQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamHistoryWorkCountQryExe.java @@ -20,6 +20,8 @@ import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; +import static com.red.circle.other.infra.database.mongo.service.team.TeamBillCycleUtils.getCalcBillBelong; + /** * 历史app内主播中心 数据统计. * diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/strategy/GiftAnchorCountStrategy.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/strategy/GiftAnchorCountStrategy.java index 880d54a0..a889e84d 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/strategy/GiftAnchorCountStrategy.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/gift/strategy/GiftAnchorCountStrategy.java @@ -175,7 +175,7 @@ public class GiftAnchorCountStrategy implements GiftStrategy { CompletableFuture.runAsync(() -> { log.warn("异步同步钻石情况{}", teamIds); - initProfilesDiamond(teamIds, giftAcceptUsers); +// initProfilesDiamond(teamIds, giftAcceptUsers); }); } @@ -387,13 +387,6 @@ public class GiftAnchorCountStrategy implements GiftStrategy { } private void countTarget(GiftGiveRunningWater runningWater, GiftAcceptUser acceptAnchorUser) { - // 2023/12/20 印度特色房间, 礼物不进目标 - List ignoreRooms = Arrays.asList("1655084280806866945", - "1738118365374660610"); - if (ignoreRooms.contains(runningWater.getOriginId())) { - return; - } - // 累计目标 TeamTargetBillRes teamTargetBillRes = teamTargetCommon.incrementGiftValue( acceptAnchorUser.getAcceptUserId(), diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/TeamBillTask.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/TeamBillTask.java index bf4ce261..ce0ed696 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/TeamBillTask.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/TeamBillTask.java @@ -10,7 +10,11 @@ import com.red.circle.other.infra.database.mongo.service.team.team.TeamProfileSe import com.red.circle.other.infra.utils.ZonedDateTimeUtils; import com.red.circle.other.inner.model.cmd.team.TeamBillCmd; import com.red.circle.tool.core.date.TimestampUtils; + +import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.ZoneId; + import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Scheduled; @@ -32,17 +36,21 @@ public class TeamBillTask { private final GiftGiveRunningWaterService giftGiveRunningWaterService; /** - * 每月1号 0点执行. + * 每月1号和16号 0点执行半月结算 */ - // 每月最后一天 0点执行 - // @Scheduled(cron = "0 0 0 L * ?", zone = "Asia/Riyadh") - @Scheduled(cron = "0 0 0 1 * ?", zone = "Asia/Riyadh") - @TaskCacheLock(key = "PROCESS_TEAM_BILL", expireSecond = 86400) - public void processTeamMonthBill() { + @Scheduled(cron = "0 0 0 1,16 * ?", zone = "Asia/Riyadh") + @TaskCacheLock(key = "PROCESS_TEAM_BILL_HALF_MONTH", expireSecond = 86400) + public void processTeamHalfMonthBill() { long startTime = System.currentTimeMillis(); - log.info("exec process_team_bill start"); + log.info("exec process_team_half_month_bill start"); + + // 判断是上半月还是下半月 + LocalDate now = LocalDate.now(ZoneId.of("Asia/Riyadh")); + String billPeriod = now.getDayOfMonth() == 1 ? "first_half" : "second_half"; + processTeamBill(); - log.info("exec process_team_bill end with {}",System.currentTimeMillis()-startTime); + log.info("exec process_team_half_month_bill end with {}", + System.currentTimeMillis() - startTime); } public void processTeamMonthBillTest() { diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/common/team/TeamTargetCommon.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/common/team/TeamTargetCommon.java index 8f53509a..cd9b1d28 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/common/team/TeamTargetCommon.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/common/team/TeamTargetCommon.java @@ -23,6 +23,8 @@ import java.util.Objects; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; +import static com.red.circle.other.infra.database.mongo.service.team.TeamBillCycleUtils.getCalcBillBelong; + /** * 房间主播管理. * @@ -120,7 +122,7 @@ public class TeamTargetCommon { TeamMember teamMember = teamMemberService.getByMemberId(userId); if (Objects.isNull(teamMember)) { - return TeamTargetBillRes.of((long) ZonedDateTimeAsiaRiyadhUtils.nowYearMonthToInt(), + return TeamTargetBillRes.of((long) getCalcBillBelong(), Boolean.FALSE); } @@ -138,13 +140,13 @@ public class TeamTargetCommon { } // 锁定期间进来的数据一律当做不是主播处理 - return TeamTargetBillRes.of((long) ZonedDateTimeAsiaRiyadhUtils.nowYearMonthToInt(), + return TeamTargetBillRes.of((long) getCalcBillBelong(), Boolean.FALSE); } // 创建成员每日目标单据 teamMemberTargetService - .createDailyWorkTarget(userId, ZonedDateTimeAsiaRiyadhUtils.nowYearMonthToInt()); + .createDailyWorkTarget(userId, getCalcBillBelong()); return consumer.apply(); } @@ -155,8 +157,8 @@ public class TeamTargetCommon { .setTimeId(IdWorkerUtils.getId()) .setSysOrigin(teamMember.getSysOrigin()) .setTeamId(teamMember.getTeamId()) - .setBillBelong(ZonedDateTimeAsiaRiyadhUtils.nowYearMonthToInt()) - .setBillTitle(ZonedDateTimeAsiaRiyadhUtils.nowFormat(DateFormatConstant.MM_SLASH_YYYY)) + .setBillBelong(getCalcBillBelong()) + .setBillTitle(getCalcBillBelong().toString()) .setUserId(teamMember.getMemberId()) .setStatus(Boolean.TRUE.equals(getOpenDailyAutoSalary(teamMember)) ? TeamMemberTargetStatus.AUTO : TeamMemberTargetStatus.NOT_RECORDED) @@ -178,7 +180,7 @@ public class TeamTargetCommon { private Boolean existsBillTarget(Long userId) { return teamMemberTargetService - .existsBillTarget(userId, ZonedDateTimeAsiaRiyadhUtils.nowYearMonthToInt()); + .existsBillTarget(userId, getCalcBillBelong()); } private Boolean getOpenDailyAutoSalary(TeamMember teamMember) { diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/team/TeamBillCycleUtils.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/team/TeamBillCycleUtils.java index dc653021..a47327f3 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/team/TeamBillCycleUtils.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/team/TeamBillCycleUtils.java @@ -12,11 +12,14 @@ import com.red.circle.other.inner.enums.team.TeamMemberTargetIndex; import com.red.circle.tool.core.collection.CollectionUtils; import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils; import com.red.circle.tool.core.num.NumUtils; +import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.math.BigDecimal; import java.math.RoundingMode; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import java.util.Comparator; import java.util.List; import java.util.Objects; @@ -472,4 +475,31 @@ public final class TeamBillCycleUtils { }).filter(Objects::nonNull).collect(Collectors.toList()); } + + public static Integer getCalcBillBelong() { + LocalDate now = ZonedDateTimeAsiaRiyadhUtils.now().toLocalDate(); + return calculateCurrentBillBelong(now); + } + + /** + * 计算当前账期的 billBelong + * 规则: + * - 1-15号:当前账期是本月1号(20251001) + * - 16-月末:当前账期是本月16号(20251016) + */ + private static Integer calculateCurrentBillBelong(LocalDate now) { + int day = now.getDayOfMonth(); + LocalDate billDate; + + if (day < 16) { + // 当前是上半月,账期开始日期是本月1号 + billDate = now.withDayOfMonth(1); + } else { + // 当前是下半月,账期开始日期是本月16号 + billDate = now.withDayOfMonth(16); + } + + return Integer.parseInt(billDate.format(DateTimeFormatter.ofPattern("yyyyMMdd"))); + } + } diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/team/team/impl/TeamBillCycleServiceImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/team/team/impl/TeamBillCycleServiceImpl.java index eb55d43f..72b78971 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/team/team/impl/TeamBillCycleServiceImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/team/team/impl/TeamBillCycleServiceImpl.java @@ -18,6 +18,7 @@ import com.red.circle.tool.core.date.TimestampUtils; import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils; import com.red.circle.tool.core.sequence.IdWorkerUtils; import com.red.circle.tool.core.text.StringUtils; + import java.time.format.DateTimeFormatter; import java.util.List; import java.util.Map; @@ -33,6 +34,8 @@ import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Update; import org.springframework.stereotype.Service; +import static com.red.circle.other.infra.database.mongo.service.team.TeamBillCycleUtils.getCalcBillBelong; + /** * 账单服务. * @@ -83,15 +86,29 @@ public class TeamBillCycleServiceImpl implements TeamBillCycleService { @Override public Map mapLastMonthByTeamIds(Set teamIds) { - if (CollectionUtils.isEmpty(teamIds)) { return Maps.newHashMap(); } + int lastMonthYYYYMM = Integer.parseInt( + ZonedDateTimeAsiaRiyadhUtils.now().minusMonths(1) + .format(DateTimeFormatter.ofPattern(DateFormatConstant.yyyyMM))); + + // 计算8位格式的范围:yyyyMM01 到 yyyyMM31 + int rangeStart = lastMonthYYYYMM * 100; // 例如:202509 * 100 = 20250900 + int rangeEnd = lastMonthYYYYMM * 100 + 99; // 例如:202509 * 100 + 99 = 20250999 + + // 匹配条件: + // 1. billBelong = 202509 (6位旧格式) + // 2. billBelong 在 20250901 到 20250999 之间 (8位新格式) + Criteria criteria = new Criteria().orOperator( + Criteria.where("billBelong").is(lastMonthYYYYMM), + Criteria.where("billBelong").gte(rangeStart).lte(rangeEnd) + ); + List teamBillCycles = mongoTemplate.find( - Query.query(Criteria.where("teamId").in(teamIds) - .and("billBelong").is(Integer.parseInt(ZonedDateTimeAsiaRiyadhUtils.now().minusMonths(1) - .format(DateTimeFormatter.ofPattern(DateFormatConstant.yyyyMM)))) + Query.query(criteria + .and("teamId").in(teamIds) .and("status").is(TeamBillCycleStatus.SETTLED)), TeamBillCycle.class); @@ -99,7 +116,8 @@ public class TeamBillCycleServiceImpl implements TeamBillCycleService { return Maps.newHashMap(); } - return teamBillCycles.stream().collect(Collectors.toMap(TeamBillCycle::getTeamId, v -> v)); + return teamBillCycles.stream() + .collect(Collectors.toMap(TeamBillCycle::getTeamId, v -> v)); } @@ -116,8 +134,8 @@ public class TeamBillCycleServiceImpl implements TeamBillCycleService { .setRegion(param.getRegion()) .setInternalRemarks(Lists.newArrayList()) .setSettleResult(null) - .setBillBelong(ZonedDateTimeAsiaRiyadhUtils.nowYearMonthToInt()) - .setBillTitle(ZonedDateTimeAsiaRiyadhUtils.nowFormat(DateFormatConstant.MM_SLASH_YYYY)) + .setBillBelong(getCalcBillBelong()) + .setBillTitle(getCalcBillBelong().toString()) .setCreateTime(param.getOperationTime()) .setUpdateTime(TimestampUtils.now()) .setCreateUser(param.getOperationBackUser()) @@ -127,10 +145,23 @@ public class TeamBillCycleServiceImpl implements TeamBillCycleService { @Override public List listLastMonthByTeamIds(Set teamIds) { + int currentYearMonth = ZonedDateTimeAsiaRiyadhUtils.nowYearMonthToInt(); + + // 计算8位格式的范围:yyyyMM01 到 yyyyMM99 + int rangeStart = currentYearMonth * 100; // 例如:202510 * 100 = 20251000 + int rangeEnd = currentYearMonth * 100 + 99; // 例如:202510 * 100 + 99 = 20251099 + + // 匹配条件: + // 1. billBelong = 202510 (6位旧格式) + // 2. billBelong 在 20251001 到 20251099 之间 (8位新格式) + Criteria criteria = new Criteria().orOperator( + Criteria.where("billBelong").is(currentYearMonth), + Criteria.where("billBelong").gte(rangeStart).lte(rangeEnd) + ); return mongoTemplate.find( - Query.query(Criteria.where("teamId").in(teamIds) - .and("billBelong").is(ZonedDateTimeAsiaRiyadhUtils.nowYearMonthToInt()) + Query.query(criteria + .and("teamId").in(teamIds) .and("status").is(TeamBillCycleStatus.SETTLED)), TeamBillCycle.class); } @@ -183,7 +214,7 @@ public class TeamBillCycleServiceImpl implements TeamBillCycleService { return mongoPrimaryService.exists("team_bill_cycle", Filters.and( Filters.eq("teamId", teamId), - Filters.eq("billBelong", ZonedDateTimeAsiaRiyadhUtils.nowYearMonthToInt()) + Filters.eq("billBelong", getCalcBillBelong()) ) ); } @@ -340,10 +371,13 @@ public class TeamBillCycleServiceImpl implements TeamBillCycleService { @Override public void billStatusPayOut() { - // 进行中 -> 出单 + // 计算当前账期的 billBelong + Integer currentBillBelong = getCalcBillBelong(); + + // 将小于当前账期的 UNPAID 状态改为 PAY_OUT mongoTemplate.updateMulti( Query.query( - Criteria.where("billBelong").lt(ZonedDateTimeAsiaRiyadhUtils.nowYearMonthToInt()) + Criteria.where("billBelong").lt(currentBillBelong) .and("status").is(TeamBillCycleStatus.UNPAID)), new Update() .set("updateTime", TimestampUtils.now())