半月结算处理
This commit is contained in:
parent
5e2d38c93e
commit
a4861816c0
@ -134,7 +134,7 @@ public class TestRestController extends BaseController {
|
||||
|
||||
@PostMapping("/processTeamMonthBill")
|
||||
public void processTeamMonthBill() {
|
||||
teamBillTask.processTeamMonthBill();
|
||||
teamBillTask.processTeamHalfMonthBill();
|
||||
}
|
||||
|
||||
@PostMapping("/activity/send/game")
|
||||
|
||||
@ -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内主播中心 数据统计.
|
||||
*
|
||||
|
||||
@ -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<String> ignoreRooms = Arrays.asList("1655084280806866945",
|
||||
"1738118365374660610");
|
||||
if (ignoreRooms.contains(runningWater.getOriginId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 累计目标
|
||||
TeamTargetBillRes teamTargetBillRes = teamTargetCommon.incrementGiftValue(
|
||||
acceptAnchorUser.getAcceptUserId(),
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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")));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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<Long, TeamBillCycle> mapLastMonthByTeamIds(Set<Long> 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<TeamBillCycle> 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<TeamBillCycle> listLastMonthByTeamIds(Set<Long> 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())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user