diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/BdLeaderSalarySettlementServiceImpl.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/BdLeaderSalarySettlementServiceImpl.java index 584edaea..e446e124 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/BdLeaderSalarySettlementServiceImpl.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/BdLeaderSalarySettlementServiceImpl.java @@ -22,6 +22,8 @@ import com.red.circle.tool.core.date.TimestampUtils; import com.red.circle.tool.core.sequence.IdWorkerUtils; import com.red.circle.wallet.inner.endpoint.bank.UserBankBalanceClient; import com.red.circle.wallet.inner.endpoint.bank.UserBankRunningWaterClient; +import com.red.circle.wallet.inner.endpoint.salary.UserSalaryAccountClient; +import com.red.circle.wallet.inner.model.cmd.SalaryIssueInnerCmd; import com.red.circle.wallet.inner.model.cmd.UserBankBalanceIncrCmd; import com.red.circle.wallet.inner.model.dto.UserBankRunningWaterDTO; import com.red.circle.wallet.inner.model.enums.UserBankWaterEvent; @@ -52,7 +54,7 @@ public class BdLeaderSalarySettlementServiceImpl implements BdLeaderSalarySettle private final BdLeaderSalaryPolicyService bdLeaderSalaryPolicyService; private final BdLeaderSalarySettlementRecordService bdLeaderSalarySettlementRecordService; private final UserBankBalanceClient userBankBalanceClient; - private final UserBankRunningWaterClient userBankRunningWaterClient; + private final UserSalaryAccountClient userSalaryAccountClient; private final UserProfileGateway userProfileGateway; @Override @@ -261,35 +263,16 @@ public class BdLeaderSalarySettlementServiceImpl implements BdLeaderSalarySettle * 发放工资到美元账户. */ private void issueSalary(Long bdLeaderUserId, BdLeaderSalarySettlementRecord record) { - // 1. 增加美元余额 - userBankBalanceClient.incr(new UserBankBalanceIncrCmd() - .setUserId(bdLeaderUserId) - .setSysOrigin(record.getSysOrigin()) - .setAmount(com.red.circle.tool.core.tuple.PennyAmount.ofDollar(record.getSettlementSalary())) - ); - - // 2. 插入流水记录 - String remark = String.format("结算周期:%s,等级:%d,基础工资:%s USD", - record.getBillTitle(), record.getHitLevel(), record.getBasicSalary()); - if (record.getRewardEligible()) { - remark += String.format(",奖励:%s USD", record.getRewardAmount()); - } - - userBankRunningWaterClient.add(new UserBankRunningWaterDTO() - .setId(IdWorkerUtils.getId()) - .setUserId(bdLeaderUserId) - .setSysOrigin(record.getSysOrigin()) - .setType(ReceiptType.INCOME.getType()) - .setAmount(record.getSettlementSalary()) - .setEvent(UserBankWaterEvent.BD_LEADER_SALARY_SETTLEMENT.name()) - .setEventDescribe("BD Leader工资结算") - .setTrackId(record.getId()) - .setRemark(remark) - .setBalance(userBankBalanceClient.getBalance(bdLeaderUserId).getBody().getAccurateBalance()) - .setCreateTime(TimestampUtils.now()) - .setCreateUser(0L) - .setCreateUserOrigin(0) - ); + SalaryIssueInnerCmd innerCmd = new SalaryIssueInnerCmd(); + innerCmd.setBillBelong(record.getBillBelong()); + innerCmd.setUserId(bdLeaderUserId); + innerCmd.setSysOrigin(record.getSysOrigin()); + innerCmd.setSalaryType("BD_LEADER_SALARY"); + innerCmd.setEventDesc("SALARY_BD_LEADER"); + innerCmd.setAmount(record.getSettlementSalary()); + innerCmd.setTrackId(record.getId()); + innerCmd.setBdId(bdLeaderUserId); + userSalaryAccountClient.issueSalary(innerCmd); } /** diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/BdSalarySettlementServiceImpl.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/BdSalarySettlementServiceImpl.java index b856f73b..a9f2bd92 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/BdSalarySettlementServiceImpl.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/BdSalarySettlementServiceImpl.java @@ -28,6 +28,8 @@ import com.red.circle.order.inner.endpoint.api.InAppPurchaseDetailsClientApi; import com.red.circle.order.inner.model.dto.inapp.BatchUserRechargeStatisticsDTO; import com.red.circle.wallet.inner.endpoint.bank.UserBankBalanceClient; import com.red.circle.wallet.inner.endpoint.bank.UserBankRunningWaterClient; +import com.red.circle.wallet.inner.endpoint.salary.UserSalaryAccountClient; +import com.red.circle.wallet.inner.model.cmd.SalaryIssueInnerCmd; import com.red.circle.wallet.inner.model.cmd.UserBankBalanceIncrCmd; import com.red.circle.wallet.inner.model.dto.UserBankRunningWaterDTO; import com.red.circle.wallet.inner.model.enums.UserBankWaterEvent; @@ -57,10 +59,9 @@ public class BdSalarySettlementServiceImpl implements BdSalarySettlementService private final TeamMemberTargetService teamMemberTargetService; private final BdSalaryPolicyService bdSalaryPolicyService; private final BdSalarySettlementRecordService bdSalarySettlementRecordService; - private final UserBankBalanceClient userBankBalanceClient; - private final UserBankRunningWaterClient userBankRunningWaterClient; private final InAppPurchaseDetailsClientApi inAppPurchaseDetailsClientApi; private final UserProfileGateway userProfileGateway; + private final UserSalaryAccountClient userSalaryAccountClient; @Override @@ -437,30 +438,16 @@ public class BdSalarySettlementServiceImpl implements BdSalarySettlementService * 发放工资到美元账户. */ private void issueSalary(Long bdUserId, BdSalarySettlementRecord record) { - // 1. 增加美元余额 - userBankBalanceClient.incr(new UserBankBalanceIncrCmd() - .setUserId(bdUserId) - .setSysOrigin(record.getSysOrigin()) - .setAmount(com.red.circle.tool.core.tuple.PennyAmount.ofDollar(record.getSettlementSalary())) - ); - - // 2. 插入流水记录 - userBankRunningWaterClient.add(new UserBankRunningWaterDTO() - .setId(IdWorkerUtils.getId()) - .setUserId(bdUserId) - .setSysOrigin(record.getSysOrigin()) - .setType(ReceiptType.INCOME.getType()) - .setAmount(record.getSettlementSalary()) - .setEvent(UserBankWaterEvent.BD_SALARY_SETTLEMENT.name()) - .setEventDescribe("BD工资结算") - .setTrackId(record.getId()) - .setRemark(String.format("结算周期:%s,等级:%d,提成比例:%s%%", - record.getBillTitle(), record.getHitLevel(), record.getCommissionRate())) - .setBalance(userBankBalanceClient.getBalance(bdUserId).getBody().getAccurateBalance()) - .setCreateTime(TimestampUtils.now()) - .setCreateUser(0L) - .setCreateUserOrigin(0) - ); + SalaryIssueInnerCmd innerCmd = new SalaryIssueInnerCmd(); + innerCmd.setBillBelong(record.getBillBelong()); + innerCmd.setUserId(bdUserId); + innerCmd.setSysOrigin(record.getSysOrigin()); + innerCmd.setSalaryType("BD_SALARY"); + innerCmd.setEventDesc("SALARY_BD"); + innerCmd.setAmount(record.getSettlementSalary()); + innerCmd.setTrackId(record.getId()); + innerCmd.setBdId(bdUserId); + userSalaryAccountClient.issueSalary(innerCmd); } /** diff --git a/rc-service/rc-service-other/other-start/src/test/java/BdSettlementTest.java b/rc-service/rc-service-other/other-start/src/test/java/BdSettlementTest.java index 19516edc..85bbf218 100644 --- a/rc-service/rc-service-other/other-start/src/test/java/BdSettlementTest.java +++ b/rc-service/rc-service-other/other-start/src/test/java/BdSettlementTest.java @@ -2,10 +2,15 @@ import com.red.circle.OtherServiceApplication; import com.red.circle.other.app.scheduler.BdLeaderSalarySettlementTask; import com.red.circle.other.app.scheduler.BdSalarySettlementTask; import com.red.circle.other.app.scheduler.TeamBillTask; +import com.red.circle.other.infra.database.mongo.entity.bd.BdLeaderSalarySettlementRecord; import com.red.circle.other.infra.database.mongo.entity.bd.BdSalaryPolicy; +import com.red.circle.other.infra.database.mongo.entity.bd.BdSalarySettlementRecord; import com.red.circle.other.infra.database.mongo.service.bd.BdSalaryPolicyService; import com.red.circle.other.infra.database.mongo.service.team.TeamBillCycleUtils; import com.red.circle.other.infra.enums.BdPolicyType; +import com.red.circle.tool.core.sequence.IdWorkerUtils; +import com.red.circle.wallet.inner.endpoint.salary.UserSalaryAccountClient; +import com.red.circle.wallet.inner.model.cmd.SalaryIssueInnerCmd; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -16,6 +21,7 @@ import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; import org.springframework.test.context.junit4.SpringRunner; +import java.math.BigDecimal; import java.util.List; @SpringBootTest(classes = OtherServiceApplication.class) @@ -30,6 +36,8 @@ public class BdSettlementTest { private BdSalaryPolicyService bdSalaryPolicyService; @Autowired private MongoTemplate mongoTemplate; + @Autowired + private UserSalaryAccountClient userSalaryAccountClient; /** @@ -54,5 +62,57 @@ public class BdSettlementTest { } + @Test + public void testIssueSalary() { +// Long bdUserId = 1963790037740466178L; +// BdSalarySettlementRecord bdSalarySettlementRecord = new BdSalarySettlementRecord(); +// bdSalarySettlementRecord.setBillBelong(20251116); +// bdSalarySettlementRecord.setSysOrigin("LIKEI"); +// bdSalarySettlementRecord.setSettlementSalary(new BigDecimal(111)); +// bdSalarySettlementRecord.setId(IdWorkerUtils.getIdStr()); +// issueSalary(bdUserId, bdSalarySettlementRecord); + + + Long bdLeaderUserId = 1963790037740466178L; + BdLeaderSalarySettlementRecord bdLeaderSalarySettlementRecord = new BdLeaderSalarySettlementRecord(); + bdLeaderSalarySettlementRecord.setBillBelong(20251116); + bdLeaderSalarySettlementRecord.setSysOrigin("LIKEI"); + bdLeaderSalarySettlementRecord.setSettlementSalary(new BigDecimal(2)); + bdLeaderSalarySettlementRecord.setId(IdWorkerUtils.getIdStr()); + issueSalary(bdLeaderUserId, bdLeaderSalarySettlementRecord); + } + + /** + * 发放BD工资 + */ + private void issueSalary(Long bdUserId, BdSalarySettlementRecord record) { + SalaryIssueInnerCmd innerCmd = new SalaryIssueInnerCmd(); + innerCmd.setBillBelong(record.getBillBelong()); + innerCmd.setUserId(bdUserId); + innerCmd.setSysOrigin(record.getSysOrigin()); + innerCmd.setSalaryType("BD_SALARY"); + innerCmd.setEventDesc("SALARY_BD"); + innerCmd.setAmount(record.getSettlementSalary()); + innerCmd.setTrackId(record.getId()); + innerCmd.setBdId(bdUserId); + userSalaryAccountClient.issueSalary(innerCmd); + } + + /** + * 发放BDLEADER工资 + */ + private void issueSalary(Long bdLeaderUserId, BdLeaderSalarySettlementRecord record) { + SalaryIssueInnerCmd innerCmd = new SalaryIssueInnerCmd(); + innerCmd.setBillBelong(record.getBillBelong()); + innerCmd.setUserId(bdLeaderUserId); + innerCmd.setSysOrigin(record.getSysOrigin()); + innerCmd.setSalaryType("BD_LEADER_SALARY"); + innerCmd.setEventDesc("SALARY_BD_LEADER"); + innerCmd.setAmount(record.getSettlementSalary()); + innerCmd.setTrackId(record.getId()); + innerCmd.setBdId(bdLeaderUserId); + userSalaryAccountClient.issueSalary(innerCmd); + } + } diff --git a/rc-service/rc-service-wallet/wallet-inner-endpoint/src/main/java/com/red/circle/wallet/inner/convertor/SalaryAccountInnerConvertor.java b/rc-service/rc-service-wallet/wallet-inner-endpoint/src/main/java/com/red/circle/wallet/inner/convertor/SalaryAccountInnerConvertor.java index 32a47b6b..51ce9779 100644 --- a/rc-service/rc-service-wallet/wallet-inner-endpoint/src/main/java/com/red/circle/wallet/inner/convertor/SalaryAccountInnerConvertor.java +++ b/rc-service/rc-service-wallet/wallet-inner-endpoint/src/main/java/com/red/circle/wallet/inner/convertor/SalaryAccountInnerConvertor.java @@ -35,6 +35,7 @@ public class SalaryAccountInnerConvertor { cmd.setTeamId(innerCmd.getTeamId()); cmd.setBdId(innerCmd.getBdId()); cmd.setAgentId(innerCmd.getAgentId()); + cmd.setSalaryEvent(innerCmd.getEventDesc()); cmd.setEventDesc(innerCmd.getEventDesc()); cmd.setRemark(innerCmd.getRemark());