fix: use bill policy for salary catch-up
This commit is contained in:
parent
e8975dca9d
commit
17e4cd69bb
@ -16,10 +16,11 @@ import com.red.circle.framework.core.asserts.ResponseAssert;
|
||||
import com.red.circle.framework.dto.ResultResponse;
|
||||
import com.red.circle.mq.business.model.event.team.TeamSalaryPaymentEvent;
|
||||
import com.red.circle.mq.rocket.business.streams.TeamSalaryPaymentSink;
|
||||
import com.red.circle.other.infra.common.props.PropsSendCommon;
|
||||
import com.red.circle.other.infra.database.mongo.dto.team.TeamBillMemberTarget;
|
||||
import com.red.circle.other.infra.database.mongo.dto.team.TeamPolicy;
|
||||
import com.red.circle.other.infra.database.mongo.dto.team.TeamSalaryPaymentDetails;
|
||||
import com.red.circle.other.infra.common.props.PropsSendCommon;
|
||||
import com.red.circle.other.infra.database.mongo.dto.team.TeamBillMemberTarget;
|
||||
import com.red.circle.other.infra.database.mongo.dto.team.TeamBillSettleResult;
|
||||
import com.red.circle.other.infra.database.mongo.dto.team.TeamPolicy;
|
||||
import com.red.circle.other.infra.database.mongo.dto.team.TeamSalaryPaymentDetails;
|
||||
import com.red.circle.other.infra.database.mongo.entity.team.team.TeamBillCycle;
|
||||
import com.red.circle.other.infra.database.mongo.entity.team.team.TeamMember;
|
||||
import com.red.circle.other.infra.database.mongo.entity.team.team.TeamMemberTarget;
|
||||
@ -150,11 +151,11 @@ public class TeamSalaryPaymentListener implements MessageListener {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, TeamPolicyManager> regionPolicyMap = teamPolicyManagerService.mapRegionReleaseWithCountry(Set.of(teamProfile.getRegion()));
|
||||
if (MapUtil.isEmpty(regionPolicyMap)) {
|
||||
// [满足政策的团队工资实时发送]该团队没有区域政策
|
||||
return;
|
||||
}
|
||||
Map<String, TeamPolicyManager> regionPolicyMap = getPaymentPolicyMap(teamProfile, billCycle, event);
|
||||
if (MapUtil.isEmpty(regionPolicyMap)) {
|
||||
// [满足政策的团队工资实时发送]该团队没有区域政策或账单政策
|
||||
return;
|
||||
}
|
||||
|
||||
List<TeamMemberTarget> teamMemberTargets = getTeamMemberTargets(billCycle);
|
||||
if (CollectionUtils.isEmpty(teamMemberTargets)) {
|
||||
@ -226,13 +227,13 @@ public class TeamSalaryPaymentListener implements MessageListener {
|
||||
|
||||
if (Objects.isNull(policyManager.getPolicyType()) || Objects.equals(TeamPolicyTypeEnum.MONEY.name(), policyManager.getPolicyType())) {
|
||||
log.warn("发送团队成员美元工资:{}\n{}\n{}\n{}\n{}\n{}", teamProfile, memberTarget, region, policy, payment, billCycle);
|
||||
// 发送团队成员工资
|
||||
memberBankBalancePayment(teamProfile, memberTarget.getId(), tmpBillMemberTarget,
|
||||
region.getMetadata(), policy, payment);
|
||||
|
||||
// 发送团队拥有者(代理)工资
|
||||
teamBankBalancePayment(teamProfile, memberTarget.getId(), tmpBillMemberTarget,
|
||||
region.getMetadata(), policy, payment);
|
||||
// 发送团队成员工资
|
||||
memberBankBalancePayment(teamProfile, memberTarget.getId(), tmpBillMemberTarget,
|
||||
region.getMetadata(), policy, payment, billCycle.getId());
|
||||
|
||||
// 发送团队拥有者(代理)工资
|
||||
teamBankBalancePayment(teamProfile, memberTarget.getId(), tmpBillMemberTarget,
|
||||
region.getMetadata(), policy, payment, billCycle.getId());
|
||||
} else {
|
||||
// 辅助:组装钻石工资辅助模型
|
||||
tmpBillMemberTarget = buildDiamondTmpBillMemberTarget(policy, billTarget);
|
||||
@ -483,22 +484,41 @@ public class TeamSalaryPaymentListener implements MessageListener {
|
||||
/**
|
||||
* 获得团队政策.
|
||||
*/
|
||||
private TeamBillCycle getTeamBillCycle(TeamProfile teamProfile, TeamSalaryPaymentEvent event) {
|
||||
|
||||
if (Boolean.TRUE.equals(event.getThisMonthFirstDay())) {
|
||||
// 如果为1号则自动结算一次上个月工资
|
||||
return teamBillCycleService.getTeamBill(teamProfile.getId(), event.getLastMonth());
|
||||
}
|
||||
// 结算本月工资
|
||||
return teamBillCycleService.getLatestByTeamId(teamProfile.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送团队拥有者工资到银行账户
|
||||
*/
|
||||
private void teamBankBalancePayment(TeamProfile teamProfile, String memberTargetId,
|
||||
TeamBillMemberTarget target, Map<String, String> metadata, TeamPolicy policy,
|
||||
TeamSalaryPayment payment) {
|
||||
private TeamBillCycle getTeamBillCycle(TeamProfile teamProfile, TeamSalaryPaymentEvent event) {
|
||||
|
||||
if (Boolean.TRUE.equals(event.getThisMonthFirstDay())) {
|
||||
// 如果为1号则自动结算一次上个月工资
|
||||
TeamBillCycle legacyMonthBill = teamBillCycleService.getTeamBill(teamProfile.getId(), event.getLastMonth());
|
||||
if (Objects.nonNull(legacyMonthBill)) {
|
||||
return legacyMonthBill;
|
||||
}
|
||||
return teamBillCycleService.getLatestTeamBillByMonth(teamProfile.getId(), event.getLastMonth());
|
||||
}
|
||||
// 结算本月工资
|
||||
return teamBillCycleService.getLatestByTeamId(teamProfile.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得本次发放使用的政策.
|
||||
*/
|
||||
private Map<String, TeamPolicyManager> getPaymentPolicyMap(TeamProfile teamProfile,
|
||||
TeamBillCycle billCycle, TeamSalaryPaymentEvent event) {
|
||||
|
||||
if (Boolean.TRUE.equals(event.getThisMonthFirstDay())) {
|
||||
return Optional.ofNullable(billCycle.getSettleResult())
|
||||
.map(TeamBillSettleResult::getPolicy)
|
||||
.orElseGet(CollectionUtils::newHashMap);
|
||||
}
|
||||
|
||||
return teamPolicyManagerService.mapRegionReleaseWithCountry(Set.of(teamProfile.getRegion()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送团队拥有者工资到银行账户
|
||||
*/
|
||||
private void teamBankBalancePayment(TeamProfile teamProfile, String memberTargetId,
|
||||
TeamBillMemberTarget target, Map<String, String> metadata, TeamPolicy policy,
|
||||
TeamSalaryPayment payment, Long teamBillId) {
|
||||
|
||||
// 是否已经发送过代理部份工资
|
||||
if (Boolean.FALSE.equals(
|
||||
@ -526,7 +546,7 @@ public class TeamSalaryPaymentListener implements MessageListener {
|
||||
.setTeamId(teamProfile.getId())
|
||||
.setTeamOwnId(teamProfile.getOwnUserId())
|
||||
.setTeamMemberId(target.getUserId())
|
||||
.setTeamBillId(getBillIdByTeamId(teamProfile))
|
||||
.setTeamBillId(teamBillId)
|
||||
.setTeamRegionId(teamProfile.getRegion())
|
||||
.setRemarks(Lists.newArrayList(new TeamSalaryPaymentRemark()
|
||||
.setRemark("将代理工资放入代理钱包")
|
||||
@ -575,7 +595,7 @@ public class TeamSalaryPaymentListener implements MessageListener {
|
||||
.setMemberTargetId(memberTargetId)
|
||||
.setTeamOwnId(teamProfile.getOwnUserId())
|
||||
.setTeamMemberId(target.getUserId())
|
||||
.setTeamBillId(getBillIdByTeamId(teamProfile))
|
||||
.setTeamBillId(teamBillId)
|
||||
.setTeamRegionId(teamProfile.getRegion())
|
||||
.setRemarks(Lists.newArrayList(new TeamSalaryPaymentRemark()
|
||||
.setRemark("本次主播工资已转入代理钱包")
|
||||
@ -601,9 +621,9 @@ public class TeamSalaryPaymentListener implements MessageListener {
|
||||
/**
|
||||
* 发送团队成员工资到银行账户
|
||||
*/
|
||||
private void memberBankBalancePayment(TeamProfile teamProfile, String memberTargetId,
|
||||
TeamBillMemberTarget target, Map<String, String> metadata, TeamPolicy policy,
|
||||
TeamSalaryPayment payment) {
|
||||
private void memberBankBalancePayment(TeamProfile teamProfile, String memberTargetId,
|
||||
TeamBillMemberTarget target, Map<String, String> metadata, TeamPolicy policy,
|
||||
TeamSalaryPayment payment, Long teamBillId) {
|
||||
|
||||
// 是否已经发送过该成员工资
|
||||
if (Boolean.TRUE.equals(
|
||||
@ -635,7 +655,7 @@ public class TeamSalaryPaymentListener implements MessageListener {
|
||||
.setMemberTargetId(memberTargetId)
|
||||
.setTeamOwnId(teamProfile.getOwnUserId())
|
||||
.setTeamMemberId(target.getUserId())
|
||||
.setTeamBillId(getBillIdByTeamId(teamProfile))
|
||||
.setTeamBillId(teamBillId)
|
||||
.setTeamRegionId(teamProfile.getRegion())
|
||||
.setRemarks(Lists.newArrayList(new TeamSalaryPaymentRemark()
|
||||
.setRemark("将主播工资发放至主播钱包")
|
||||
@ -726,13 +746,6 @@ public class TeamSalaryPaymentListener implements MessageListener {
|
||||
// policy.getLevel(), isPayMember);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得账单ID.
|
||||
*/
|
||||
private Long getBillIdByTeamId(TeamProfile teamProfile) {
|
||||
return teamBillCycleService.getLatestBillIdByTeamId(teamProfile.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 基于当前等级获得上一个等级政策.
|
||||
*
|
||||
|
||||
@ -82,14 +82,19 @@ public interface TeamBillCycleService {
|
||||
*/
|
||||
TeamBillCycle getByBillId(Long billId);
|
||||
|
||||
/**
|
||||
* 获取团队指定账单信息.
|
||||
*/
|
||||
TeamBillCycle getTeamBill(Long teamId, Integer billBelong);
|
||||
|
||||
/**
|
||||
* 查询账单.
|
||||
*/
|
||||
/**
|
||||
* 获取团队指定账单信息.
|
||||
*/
|
||||
TeamBillCycle getTeamBill(Long teamId, Integer billBelong);
|
||||
|
||||
/**
|
||||
* 获取团队指定月份最新账单,兼容 yyyyMM 与 yyyyMM01/yyyyMM16 账期.
|
||||
*/
|
||||
TeamBillCycle getLatestTeamBillByMonth(Long teamId, Integer yearMonth);
|
||||
|
||||
/**
|
||||
* 查询账单.
|
||||
*/
|
||||
List<TeamBillCycle> list(TeamBillCycleBackQryCmd query);
|
||||
|
||||
List<TeamBillCycle> listAll();
|
||||
|
||||
@ -420,15 +420,29 @@ public class TeamBillCycleServiceImpl implements TeamBillCycleService {
|
||||
TeamBillCycle.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TeamBillCycle getTeamBill(Long teamId, Integer billBelong) {
|
||||
return mongoTemplate.findOne(Query.query(Criteria.where("teamId").is(teamId)
|
||||
.and("billBelong").is(billBelong)),
|
||||
TeamBillCycle.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TeamBillCycle> list(TeamBillCycleBackQryCmd query) {
|
||||
@Override
|
||||
public TeamBillCycle getTeamBill(Long teamId, Integer billBelong) {
|
||||
return mongoTemplate.findOne(Query.query(Criteria.where("teamId").is(teamId)
|
||||
.and("billBelong").is(billBelong)),
|
||||
TeamBillCycle.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TeamBillCycle getLatestTeamBillByMonth(Long teamId, Integer yearMonth) {
|
||||
if (Objects.isNull(teamId) || Objects.isNull(yearMonth)) {
|
||||
return null;
|
||||
}
|
||||
Integer normalizedYearMonth = yearMonth > 999999
|
||||
? Integer.valueOf(yearMonth.toString().substring(0, 6))
|
||||
: yearMonth;
|
||||
return mongoTemplate.findOne(
|
||||
Query.query(getBillBelongCriteria(normalizedYearMonth).and("teamId").is(teamId))
|
||||
.with(Sort.by(Sort.Order.desc("billBelong"), Sort.Order.desc("id"))),
|
||||
TeamBillCycle.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TeamBillCycle> list(TeamBillCycleBackQryCmd query) {
|
||||
Criteria criteria = new Criteria();
|
||||
|
||||
if (Objects.nonNull(query.getId())) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user