|
|
@@ -1,19 +1,22 @@
|
|
|
-package com.citu.module.menduner.reward.service.record;
|
|
|
+package com.citu.module.menduner.system.service.record;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
+import com.citu.framework.common.exception.util.ServiceExceptionUtil;
|
|
|
import com.citu.framework.common.pojo.PageParam;
|
|
|
import com.citu.framework.common.pojo.PageResult;
|
|
|
-import com.citu.module.menduner.reward.controller.base.record.EnterpriseAccountRecordPageReqVO;
|
|
|
-import com.citu.module.menduner.reward.dal.dataobject.record.EnterpriseAccountRecordDO;
|
|
|
-import com.citu.module.menduner.reward.dal.mysql.record.EnterpriseAccountRecordMapper;
|
|
|
-import com.citu.module.menduner.reward.enums.MathOperationEnum;
|
|
|
-import com.citu.module.menduner.reward.enums.record.AccountRecordTypeEnum;
|
|
|
-import com.citu.module.menduner.reward.enums.record.BalanceBizTypeEnum;
|
|
|
-import com.citu.module.menduner.reward.enums.record.PointBizTypeEnum;
|
|
|
import com.citu.module.menduner.system.api.account.AccountRespDTO;
|
|
|
import com.citu.module.menduner.system.api.account.EnterpriseAccountApi;
|
|
|
+import com.citu.module.menduner.system.controller.base.account.record.EnterpriseAccountRecordPageReqVO;
|
|
|
+import com.citu.module.menduner.system.dal.dataobject.enterprise.EnterpriseAccountDO;
|
|
|
+import com.citu.module.menduner.system.dal.dataobject.record.EnterpriseAccountRecordDO;
|
|
|
+import com.citu.module.menduner.system.dal.mysql.record.EnterpriseAccountRecordMapper;
|
|
|
+import com.citu.module.menduner.system.enums.MathOperationEnum;
|
|
|
+import com.citu.module.menduner.system.enums.account.AccountRecordTypeEnum;
|
|
|
+import com.citu.module.menduner.system.enums.account.BalanceBizTypeEnum;
|
|
|
+import com.citu.module.menduner.system.enums.account.PointBizTypeEnum;
|
|
|
+import com.citu.module.menduner.system.service.enterprise.account.EnterpriseAccountService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
@@ -23,9 +26,8 @@ import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.List;
|
|
|
|
|
|
-import static com.citu.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
-import static com.citu.module.menduner.reward.enums.ErrorCodeConstants.USER_BALANCE_NOT_ENOUGH;
|
|
|
-import static com.citu.module.menduner.reward.enums.ErrorCodeConstants.USER_POINT_NOT_ENOUGH;
|
|
|
+import static com.citu.module.menduner.system.enums.ErrorCodeConstants.USER_BALANCE_NOT_ENOUGH;
|
|
|
+import static com.citu.module.menduner.system.enums.ErrorCodeConstants.USER_POINT_NOT_ENOUGH;
|
|
|
|
|
|
/**
|
|
|
* 企业账户变动 Service 实现类
|
|
|
@@ -41,7 +43,7 @@ public class EnterpriseAccountRecordServiceImpl implements EnterpriseAccountReco
|
|
|
private EnterpriseAccountRecordMapper mapper;
|
|
|
|
|
|
@Resource
|
|
|
- private EnterpriseAccountApi enterpriseAccountApi;
|
|
|
+ private EnterpriseAccountService enterpriseAccountService;
|
|
|
|
|
|
@Override
|
|
|
public PageResult<EnterpriseAccountRecordDO> page(EnterpriseAccountRecordPageReqVO pageReqVO) {
|
|
|
@@ -61,17 +63,17 @@ public class EnterpriseAccountRecordServiceImpl implements EnterpriseAccountReco
|
|
|
return;
|
|
|
}
|
|
|
// 1. 校验用户积分余额
|
|
|
- AccountRespDTO userAccountResp = enterpriseAccountApi
|
|
|
- .createEnterpriseAccountIfAbsent(enterpriseId, userId).getCheckedData();
|
|
|
- Integer userPoint = ObjectUtil.defaultIfNull(userAccountResp.getPoint(), 0);
|
|
|
+ EnterpriseAccountDO enterpriseAccount = enterpriseAccountService
|
|
|
+ .createEnterpriseAccountIfAbsent(enterpriseId, userId);
|
|
|
+ Integer userPoint = ObjectUtil.defaultIfNull(enterpriseAccount.getPoint(), 0);
|
|
|
int totalPoint = userPoint + point; // 用户变动后的积分
|
|
|
if (totalPoint < 0) {
|
|
|
- throw exception(USER_POINT_NOT_ENOUGH);
|
|
|
+ throw ServiceExceptionUtil.exception(USER_POINT_NOT_ENOUGH);
|
|
|
}
|
|
|
|
|
|
if (MathOperationEnum.SUBTRACT.equals(operation)) {
|
|
|
if (userPoint - point < 0) {
|
|
|
- throw exception(USER_POINT_NOT_ENOUGH);
|
|
|
+ throw ServiceExceptionUtil.exception(USER_POINT_NOT_ENOUGH);
|
|
|
}
|
|
|
totalPoint = userPoint - point;
|
|
|
// 减法
|
|
|
@@ -80,9 +82,9 @@ public class EnterpriseAccountRecordServiceImpl implements EnterpriseAccountReco
|
|
|
}
|
|
|
|
|
|
// 2. 更新用户积分
|
|
|
- boolean success = enterpriseAccountApi.updatePoint(enterpriseId, userId, point).getCheckedData();
|
|
|
+ boolean success = enterpriseAccountService.updatePoint(enterpriseId, userId, point);
|
|
|
if (!success) {
|
|
|
- throw exception(USER_POINT_NOT_ENOUGH);
|
|
|
+ throw ServiceExceptionUtil.exception(USER_POINT_NOT_ENOUGH);
|
|
|
}
|
|
|
|
|
|
// 3. 增加用户账户变动
|
|
|
@@ -121,19 +123,19 @@ public class EnterpriseAccountRecordServiceImpl implements EnterpriseAccountReco
|
|
|
}
|
|
|
|
|
|
// 1. 校验用户余额
|
|
|
- AccountRespDTO userAccountResp = enterpriseAccountApi.
|
|
|
- createEnterpriseAccountIfAbsent(enterpriseId, userId).getCheckedData();
|
|
|
+ EnterpriseAccountDO enterpriseAccount = enterpriseAccountService.
|
|
|
+ createEnterpriseAccountIfAbsent(enterpriseId, userId);
|
|
|
|
|
|
- BigDecimal userBalance = ObjectUtil.defaultIfNull(userAccountResp.getBalance(), BigDecimal.ZERO);
|
|
|
+ BigDecimal userBalance = ObjectUtil.defaultIfNull(enterpriseAccount.getBalance(), BigDecimal.ZERO);
|
|
|
BigDecimal totalBalance = userBalance.add(balance);
|
|
|
|
|
|
if (totalBalance.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
- throw exception(USER_BALANCE_NOT_ENOUGH);
|
|
|
+ throw ServiceExceptionUtil.exception(USER_BALANCE_NOT_ENOUGH);
|
|
|
}
|
|
|
|
|
|
if (MathOperationEnum.SUBTRACT.equals(operation)) {
|
|
|
if (userBalance.subtract(balance).compareTo(BigDecimal.ZERO) < 0) {
|
|
|
- throw exception(USER_BALANCE_NOT_ENOUGH);
|
|
|
+ throw ServiceExceptionUtil.exception(USER_BALANCE_NOT_ENOUGH);
|
|
|
}
|
|
|
totalBalance = userBalance.subtract(balance);
|
|
|
balance = balance.negate();
|
|
|
@@ -142,9 +144,9 @@ public class EnterpriseAccountRecordServiceImpl implements EnterpriseAccountReco
|
|
|
}
|
|
|
|
|
|
// 2. 更新用户余额
|
|
|
- boolean success = enterpriseAccountApi.updateBalance(enterpriseId, userId, balance).getCheckedData();
|
|
|
+ boolean success = enterpriseAccountService.updateBalance(enterpriseId, userId, balance);
|
|
|
if (!success) {
|
|
|
- throw exception(USER_BALANCE_NOT_ENOUGH);
|
|
|
+ throw ServiceExceptionUtil.exception(USER_BALANCE_NOT_ENOUGH);
|
|
|
}
|
|
|
|
|
|
// 3. 增加用户账户变动
|