补贴管理 =

This commit is contained in:
gaowdong 2025-04-10 13:13:16 +08:00
parent 4fe71a435b
commit 240c49a5b7
12 changed files with 218 additions and 123 deletions

View File

@ -27,39 +27,39 @@ public class AccSubsidyController extends BaseController {
private AccSubService accSubService; private AccSubService accSubService;
@ApiOperation("单人补贴") @ApiOperation("单人补贴")
@PostMapping("/add") @PostMapping("/add")
public AjaxResult individualAccSubsidyAdd(@RequestBody @Valid AccSubsidyParam param) { public AjaxResult individualAccSubsidyAdd(@RequestBody @Valid AccSubsidyAddParam param) {
this.accSubService.individualAccSubsidyAdd(param); this.accSubService.individualAccSubsidyAdd(param);
return AjaxResult.success(); return AjaxResult.success();
} }
@ApiOperation("补贴清空") @ApiOperation("补贴清空")
@PostMapping({"/clear"}) @PostMapping({"/clear"})
public AjaxResult individualAccSubsidyClear(@RequestBody @Valid AccSubsidyParam param) { public AjaxResult individualAccSubsidyClear(@RequestBody @Valid AccSubsidyClearParam param) {
this.accSubService.individualAccSubsidyClear(param); this.accSubService.individualAccSubsidyClear(param);
return AjaxResult.success(); return AjaxResult.success();
} }
@ApiOperation("批量补贴") @ApiOperation("批量补贴")
@PostMapping("/batch/add") @PostMapping("/batch/add")
public AjaxResult batchAccSubsidyAdd(@RequestBody @Valid AccSubsidyParam param) { public AjaxResult batchAccSubsidyAdd(@RequestBody @Valid AccSubsidyBatchAddParam param) {
this.accSubService.batchAccSubsidyAdd(param); this.accSubService.batchAccSubsidyAdd(param);
return AjaxResult.success(); return AjaxResult.success();
} }
@ApiOperation("批量补贴校验") @ApiOperation("批量补贴校验")
@PostMapping("/batch/add/check") @PostMapping("/batch/add/check")
public AjaxResult batchAccSubsidyAddCheck(@RequestBody @Valid AccSubsidyParam param) { public AjaxResult batchAccSubsidyAddCheck(@RequestBody @Valid AccSubsidyBatchAddParam param) {
return AjaxResult.success(accSubService.batchOperationWalletAddCheck(param)); return AjaxResult.success(accSubService.batchOperationWalletAddCheck(param));
} }
@ApiOperation("批量补贴清空") @ApiOperation("批量补贴清空")
@PostMapping({"/batch/clear"}) @PostMapping({"/batch/clear"})
public AjaxResult batchAccSubsidyClear(@RequestBody @Valid AccSubsidyParam param) { public AjaxResult batchAccSubsidyClear(@RequestBody @Valid AccSubsidyBatchClearParam param) {
this.accSubService.batchAccSubsidyClear(param); this.accSubService.batchAccSubsidyClear(param);
return AjaxResult.success(); return AjaxResult.success();
} }
@ApiOperation("批量补贴清空校验") @ApiOperation("批量补贴清空校验")
@PostMapping({"/batch/clear/check"}) @PostMapping({"/batch/clear/check"})
public AjaxResult batchAccSubsidyClearCheck(@RequestBody @Valid AccSubsidyParam param) { public AjaxResult batchAccSubsidyClearCheck(@RequestBody @Valid AccSubsidyBatchClearParam param) {
return AjaxResult.success(accSubService.batchOperationWalletClearCheck(param)); return AjaxResult.success(accSubService.batchOperationWalletClearCheck(param));
} }

View File

@ -0,0 +1,34 @@
package com.bonus.canteen.core.account.domain.param;
import com.bonus.common.core.web.domain.BaseEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
@Data
public class AccSubsidyAddParam extends BaseEntity {
@ApiModelProperty(value = "用户编号")
private @NotNull(
message = "用户编号不能为空"
) Long userId;
@ApiModelProperty(
value = "充值金额/分"
)
private @NotNull(
message = "金额不能为空"
) @Max(
value = 10000000L,
message = "超过最大金额限制"
) @Min(
value = 1L,
message = "小于最小充值金额"
) BigDecimal amount;
@ApiModelProperty("操作类型 补贴-1 清空补贴-2")
@JsonIgnore
private Integer operationType;
}

View File

@ -10,18 +10,11 @@ import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List; import java.util.List;
@Data @Data
public class AccSubsidyParam extends BaseEntity { public class AccSubsidyBatchAddParam extends BaseEntity {
@ApiModelProperty( @ApiModelProperty(
value = "用户编号", value = "用户编号"
required = true
)
private @NotNull(
message = "用户编号不能为空"
) Long userId;
@ApiModelProperty(
value = "用户编号",
required = true
) )
private @NotNull( private @NotNull(
message = "用户编号不能为空" message = "用户编号不能为空"
@ -39,8 +32,6 @@ public class AccSubsidyParam extends BaseEntity {
value = 1L, value = 1L,
message = "小于最小充值金额" message = "小于最小充值金额"
) BigDecimal amount; ) BigDecimal amount;
@ApiModelProperty("清空类型 清空-1 清空至-2")
private Integer clearType = 1;
@ApiModelProperty("操作类型 补贴-1 清空补贴-2") @ApiModelProperty("操作类型 补贴-1 清空补贴-2")
@JsonIgnore @JsonIgnore
private Integer operationType; private Integer operationType;

View File

@ -0,0 +1,27 @@
package com.bonus.canteen.core.account.domain.param;
import com.bonus.common.core.web.domain.BaseEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;
@Data
public class AccSubsidyBatchClearParam extends BaseEntity {
@ApiModelProperty(
value = "用户编号"
)
private @NotNull(
message = "用户编号不能为空"
) List<Long> userIds;
@ApiModelProperty("清空类型 清空-1 清空至-2")
private Integer clearType = 1;
@ApiModelProperty("操作类型 补贴-1 清空补贴-2")
@JsonIgnore
private Integer operationType;
}

View File

@ -0,0 +1,25 @@
package com.bonus.canteen.core.account.domain.param;
import com.bonus.common.core.web.domain.BaseEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
@Data
public class AccSubsidyClearParam extends BaseEntity {
@ApiModelProperty(value = "用户编号")
private @NotNull(
message = "用户编号不能为空"
) Long userId;
@ApiModelProperty("清空类型 清空-1 清空至-2")
private Integer clearType = 1;
@ApiModelProperty("操作类型 补贴-1 清空补贴-2")
@JsonIgnore
private Integer operationType;
}

View File

@ -2,6 +2,7 @@ package com.bonus.canteen.core.account.mapper;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import com.bonus.canteen.core.account.domain.AccWalletInfo; import com.bonus.canteen.core.account.domain.AccWalletInfo;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
@ -21,7 +22,7 @@ public interface AccWalletInfoMapper {
* @return 钱包详情信息 * @return 钱包详情信息
*/ */
public List<AccWalletInfo> selectAccWalletInfoByUserId(Long userId); public List<AccWalletInfo> selectAccWalletInfoByUserId(Long userId);
public AccWalletInfo selectAccWalletInfoByUserIdAndWalletId(Long userId, Integer walletId); public AccWalletInfo selectAccWalletInfoByUserIdAndWalletId(@Param("userId") Long userId, @Param("walletId") Integer walletId);
List<AccWalletInfoVO> selectAccWalletInfoByUserIds(@Param("userIds") List<Long> userIds); List<AccWalletInfoVO> selectAccWalletInfoByUserIds(@Param("userIds") List<Long> userIds);
@ -71,18 +72,24 @@ public interface AccWalletInfoMapper {
@Param("walletId") Integer walletId, @Param("walletId") Integer walletId,
@Param("userIds") List<Long> userIds, @Param("userIds") List<Long> userIds,
@Param("updateBy") String updateBy, @Param("updateBy") String updateBy,
@Param("updateTime") LocalDate updateTime); @Param("updateTime") LocalDateTime updateTime);
void addAccWalletInfo(@Param("amount") BigDecimal amount, void addAccWalletInfo(@Param("amount") BigDecimal amount,
@Param("userId") Long userId, @Param("userId") Long userId,
@Param("walletId") Integer walletId @Param("walletId") Integer walletId,
@Param("updateBy") String updateBy,
@Param("updateTime") LocalDateTime updateTime
); );
void reduceAccWalletInfo(@Param("amount") BigDecimal amount, void reduceAccWalletInfo(@Param("amount") BigDecimal amount,
@Param("userId") Long userId, @Param("userId") Long userId,
@Param("walletId") Integer walletId @Param("walletId") Integer walletId,
@Param("updateBy") String updateBy,
@Param("updateTime") LocalDateTime updateTime
); );
void clearAccWalletInfo(@Param("userId") Long userId, void clearAccWalletInfo(@Param("userId") Long userId,
@Param("walletId") Integer walletId @Param("walletId") Integer walletId,
@Param("updateBy") String updateBy,
@Param("updateTime") LocalDateTime updateTime
); );
} }

View File

@ -1,7 +1,6 @@
package com.bonus.canteen.core.account.service; package com.bonus.canteen.core.account.service;
import com.bonus.canteen.core.account.domain.param.AccSubOperationQueryParam; import com.bonus.canteen.core.account.domain.param.*;
import com.bonus.canteen.core.account.domain.param.AccSubsidyParam;
import com.bonus.canteen.core.account.domain.vo.AccBatchOperationWalletPreCheckVO; import com.bonus.canteen.core.account.domain.vo.AccBatchOperationWalletPreCheckVO;
import com.bonus.canteen.core.account.domain.vo.AccSubOperationListVO; import com.bonus.canteen.core.account.domain.vo.AccSubOperationListVO;
@ -9,17 +8,17 @@ import java.math.BigDecimal;
import java.util.List; import java.util.List;
public interface AccSubService { public interface AccSubService {
void individualAccSubsidyAdd(AccSubsidyParam param); void individualAccSubsidyAdd(AccSubsidyAddParam param);
void individualAccSubsidyClear(AccSubsidyParam param); void individualAccSubsidyClear(AccSubsidyClearParam param);
void batchAccSubsidyAdd(AccSubsidyParam param); void batchAccSubsidyAdd(AccSubsidyBatchAddParam param);
void batchAccSubsidyClear(AccSubsidyParam param); void batchAccSubsidyClear(AccSubsidyBatchClearParam param);
AccBatchOperationWalletPreCheckVO batchOperationWalletAddCheck(AccSubsidyParam param); AccBatchOperationWalletPreCheckVO batchOperationWalletAddCheck(AccSubsidyBatchAddParam param);
AccBatchOperationWalletPreCheckVO batchOperationWalletClearCheck(AccSubsidyParam param); AccBatchOperationWalletPreCheckVO batchOperationWalletClearCheck(AccSubsidyBatchClearParam param);
public void addAccWalletBalance(BigDecimal amount, Long userId, Integer walletId); public void addAccWalletBalance(BigDecimal amount, Long userId, Integer walletId);

View File

@ -1,5 +1,7 @@
package com.bonus.canteen.core.account.service.impl; package com.bonus.canteen.core.account.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bonus.canteen.core.account.domain.bo.AccOperationHistory; import com.bonus.canteen.core.account.domain.bo.AccOperationHistory;
import com.bonus.canteen.core.account.domain.param.AccOperationQueryParam; import com.bonus.canteen.core.account.domain.param.AccOperationQueryParam;
@ -31,7 +33,7 @@ public class AccOperationHistoryServiceImpl extends ServiceImpl<AccOperationHist
public void addAccOperationHistory(Long userId, Integer type) { public void addAccOperationHistory(Long userId, Integer type) {
AjaxResult userResult = remoteUserService.getInfo(userId , SecurityConstants.INNER); AjaxResult userResult = remoteUserService.getInfo(userId , SecurityConstants.INNER);
if(Objects.nonNull(userResult)) { if(Objects.nonNull(userResult)) {
SysUser sysUser = userResult.getDataAs(SysUser.class); SysUser sysUser = JSONObject.parseObject(JSON.toJSONString(userResult.get(AjaxResult.DATA_TAG)), SysUser.class);
AccOperationHistory accOperationRecord = new AccOperationHistory(); AccOperationHistory accOperationRecord = new AccOperationHistory();
accOperationRecord.setType(type); accOperationRecord.setType(type);
accOperationRecord.setUserId(userId); accOperationRecord.setUserId(userId);

View File

@ -7,8 +7,7 @@ import com.bonus.canteen.core.account.constants.AccWalletIdEnum;
import com.bonus.canteen.core.account.constants.WalletBalanceOperationEnum; import com.bonus.canteen.core.account.constants.WalletBalanceOperationEnum;
import com.bonus.canteen.core.account.domain.AccWalletInfo; import com.bonus.canteen.core.account.domain.AccWalletInfo;
import com.bonus.canteen.core.account.domain.bo.WalletBalanceOperation; import com.bonus.canteen.core.account.domain.bo.WalletBalanceOperation;
import com.bonus.canteen.core.account.domain.param.AccSubOperationQueryParam; import com.bonus.canteen.core.account.domain.param.*;
import com.bonus.canteen.core.account.domain.param.AccSubsidyParam;
import com.bonus.canteen.core.account.domain.vo.AccBatchOperationWallerErrorVO; import com.bonus.canteen.core.account.domain.vo.AccBatchOperationWallerErrorVO;
import com.bonus.canteen.core.account.domain.vo.AccBatchOperationWalletPreCheckVO; import com.bonus.canteen.core.account.domain.vo.AccBatchOperationWalletPreCheckVO;
import com.bonus.canteen.core.account.domain.vo.AccInfoDetailsVO; import com.bonus.canteen.core.account.domain.vo.AccInfoDetailsVO;
@ -57,7 +56,7 @@ public class AccSubServiceImpl implements AccSubService {
@Transactional( @Transactional(
rollbackFor = {Exception.class} rollbackFor = {Exception.class}
) )
public void individualAccSubsidyAdd(AccSubsidyParam param) { public void individualAccSubsidyAdd(AccSubsidyAddParam param) {
AccInfoDetailsVO accInfoVO = this.accInfoService.queryAccInfoByUserId(param.getUserId()); AccInfoDetailsVO accInfoVO = this.accInfoService.queryAccInfoByUserId(param.getUserId());
if(Objects.isNull(accInfoVO)) { if(Objects.isNull(accInfoVO)) {
throw new ServiceException("账户不存在"); throw new ServiceException("账户不存在");
@ -68,7 +67,7 @@ public class AccSubServiceImpl implements AccSubService {
@Transactional( @Transactional(
rollbackFor = {Exception.class} rollbackFor = {Exception.class}
) )
public void individualAccSubsidyClear(AccSubsidyParam param) { public void individualAccSubsidyClear(AccSubsidyClearParam param) {
AccInfoDetailsVO accInfoVO = this.accInfoService.queryAccInfoByUserId(param.getUserId()); AccInfoDetailsVO accInfoVO = this.accInfoService.queryAccInfoByUserId(param.getUserId());
if(Objects.isNull(accInfoVO)) { if(Objects.isNull(accInfoVO)) {
throw new ServiceException("账户不存在"); throw new ServiceException("账户不存在");
@ -77,25 +76,25 @@ public class AccSubServiceImpl implements AccSubService {
clearAllAccSubsidyHandler(accInfoVO, param); clearAllAccSubsidyHandler(accInfoVO, param);
} }
private void clearAccSubsidyHandler(AccInfoDetailsVO accInfoVO, AccSubsidyParam param) { // private void clearAccSubsidyHandler(AccInfoDetailsVO accInfoVO, AccSubsidyClearParam param) {
AccWalletInfo walletInfo = accWalletInfoService.selectAccWalletInfoByUserIdAndWalletId(accInfoVO.getUserId(), AccWalletIdEnum.SUBSIDY.getKey()); // AccWalletInfo walletInfo = accWalletInfoService.selectAccWalletInfoByUserIdAndWalletId(accInfoVO.getUserId(), AccWalletIdEnum.SUBSIDY.getKey());
if(Objects.isNull(walletInfo)) { // if(Objects.isNull(walletInfo)) {
throw new ServiceException("补贴钱包不存在"); // throw new ServiceException("补贴钱包不存在");
} // }
BigDecimal walletBal = walletInfo.getWalletBal(); // BigDecimal walletBal = walletInfo.getWalletBal();
if (walletBal.compareTo(BigDecimal.ZERO) <= 0) { // if (walletBal.compareTo(BigDecimal.ZERO) <= 0) {
throw new ServiceException("补贴钱包余额必须大于0元"); // throw new ServiceException("补贴钱包余额必须大于0元");
} else { // } else {
BigDecimal clearAmount = this.calculateClearAmount(walletBal, param.getClearType(), param.getAmount()); // BigDecimal clearAmount = this.calculateClearAmount(walletBal, param.getClearType(), param.getAmount());
if (clearAmount.compareTo(BigDecimal.ZERO) <= 0) { // if (clearAmount.compareTo(BigDecimal.ZERO) <= 0) {
throw new ServiceException("清空金额必须大于0元"); // throw new ServiceException("清空金额必须大于0元");
} else { // } else {
reduceAccWalletBalance(clearAmount, param.getUserId(), AccWalletIdEnum.SUBSIDY.getKey()); // reduceAccWalletBalance(clearAmount, param.getUserId(), AccWalletIdEnum.SUBSIDY.getKey());
} // }
} // }
} // }
private void clearAllAccSubsidyHandler(AccInfoDetailsVO accInfoVO, AccSubsidyParam param) { private void clearAllAccSubsidyHandler(AccInfoDetailsVO accInfoVO, AccSubsidyClearParam param) {
AccWalletInfo walletInfo = accWalletInfoService.selectAccWalletInfoByUserIdAndWalletId(accInfoVO.getUserId(), AccWalletIdEnum.SUBSIDY.getKey()); AccWalletInfo walletInfo = accWalletInfoService.selectAccWalletInfoByUserIdAndWalletId(accInfoVO.getUserId(), AccWalletIdEnum.SUBSIDY.getKey());
if(Objects.isNull(walletInfo)) { if(Objects.isNull(walletInfo)) {
throw new ServiceException("补贴钱包不存在"); throw new ServiceException("补贴钱包不存在");
@ -103,17 +102,17 @@ public class AccSubServiceImpl implements AccSubService {
clearAccWalletBalance(walletInfo.getWalletBal(), param.getUserId(), AccWalletIdEnum.SUBSIDY.getKey()); clearAccWalletBalance(walletInfo.getWalletBal(), param.getUserId(), AccWalletIdEnum.SUBSIDY.getKey());
} }
private BigDecimal calculateClearAmount(BigDecimal walletBal, Integer clearType, BigDecimal amount) { // private BigDecimal calculateClearAmount(BigDecimal walletBal, Integer clearType, BigDecimal amount) {
BigDecimal clearAmount; // BigDecimal clearAmount;
if (AccWalletClearTypeEnum.CLEAR_BY.getKey().equals(clearType)) { // if (AccWalletClearTypeEnum.CLEAR_BY.getKey().equals(clearType)) {
clearAmount = amount.compareTo(walletBal) >= 0 ? BigDecimal.ZERO : walletBal.subtract(amount); // clearAmount = amount.compareTo(walletBal) >= 0 ? BigDecimal.ZERO : walletBal.subtract(amount);
} else { // } else {
clearAmount = amount.compareTo(walletBal) >= 0 ? walletBal : amount; // clearAmount = amount.compareTo(walletBal) >= 0 ? walletBal : amount;
} // }
return clearAmount.compareTo(BigDecimal.ZERO) <= 0 ? BigDecimal.ZERO : clearAmount; // return clearAmount.compareTo(BigDecimal.ZERO) <= 0 ? BigDecimal.ZERO : clearAmount;
} // }
public void batchAccSubsidyClear(AccSubsidyParam param) { public void batchAccSubsidyClear(AccSubsidyBatchClearParam param) {
log.info("批量清空补贴用户数量:{}", param.getUserIds().size()); log.info("批量清空补贴用户数量:{}", param.getUserIds().size());
if(CollUtil.isEmpty(param.getUserIds())) { if(CollUtil.isEmpty(param.getUserIds())) {
throw new ServiceException("批量清空补贴用户为空"); throw new ServiceException("批量清空补贴用户为空");
@ -124,12 +123,12 @@ public class AccSubServiceImpl implements AccSubService {
throw new ServiceException("批量清空补贴查询到的用户为空"); throw new ServiceException("批量清空补贴查询到的用户为空");
} else { } else {
this.asyncTaskExecutor.execute(() -> { this.asyncTaskExecutor.execute(() -> {
this.batchAccSubsidyClearHandler(accInfoVOList, param.getAmount(), param.getClearType()); this.batchAccSubsidyClearHandler(accInfoVOList, param.getClearType());
}); });
} }
} }
public void batchAccSubsidyAdd(AccSubsidyParam param) { public void batchAccSubsidyAdd(AccSubsidyBatchAddParam param) {
log.info("批量补贴用户数量:{}", param.getUserIds().size()); log.info("批量补贴用户数量:{}", param.getUserIds().size());
if(CollUtil.isEmpty(param.getUserIds())) { if(CollUtil.isEmpty(param.getUserIds())) {
throw new ServiceException("批量补贴用户为空"); throw new ServiceException("批量补贴用户为空");
@ -171,7 +170,7 @@ public class AccSubServiceImpl implements AccSubService {
log.info("批量补贴结束"); log.info("批量补贴结束");
} }
private void batchAccSubsidyClearHandler(List<AccInfoDetailsVO> accInfoDetails, BigDecimal amount, Integer clearType) { private void batchAccSubsidyClearHandler(List<AccInfoDetailsVO> accInfoDetails, Integer clearType) {
log.info("批量清空补贴开始:{}", accInfoDetails.size()); log.info("批量清空补贴开始:{}", accInfoDetails.size());
AccRedisUtils.lockBatchUpdateAccWallet(); AccRedisUtils.lockBatchUpdateAccWallet();
try { try {
@ -182,11 +181,10 @@ public class AccSubServiceImpl implements AccSubService {
throw new ServiceException(accInfo.getNickName() + "的账户不存在"); throw new ServiceException(accInfo.getNickName() + "的账户不存在");
} }
accInfoService.checkAccStatus(accInfoVO); accInfoService.checkAccStatus(accInfoVO);
AccSubsidyParam param = new AccSubsidyParam(); AccSubsidyClearParam param = new AccSubsidyClearParam();
param.setAmount(amount);
param.setUserId(accInfo.getUserId()); param.setUserId(accInfo.getUserId());
param.setClearType(clearType); param.setClearType(clearType);
clearAccSubsidyHandler(accInfoVO, param); clearAllAccSubsidyHandler(accInfoVO, param);
} catch (Exception var10) { } catch (Exception var10) {
log.error("批量清空补贴充值异常", var10); log.error("批量清空补贴充值异常", var10);
} }
@ -225,24 +223,24 @@ public class AccSubServiceImpl implements AccSubService {
} }
} }
public void reduceAccWalletBalance(BigDecimal amount, Long userId, Integer walletId) { // public void reduceAccWalletBalance(BigDecimal amount, Long userId, Integer walletId) {
log.info("清空补贴入参: amount{} userId{}walletId{}", amount, userId, walletId); // log.info("清空补贴入参: amount{} userId{}walletId{}", amount, userId, walletId);
AccRedisUtils.lockUpdateAccWalletBalance(userId); // AccRedisUtils.lockUpdateAccWalletBalance(userId);
try { // try {
WalletBalanceOperation operation = new WalletBalanceOperation(); // WalletBalanceOperation operation = new WalletBalanceOperation();
operation.setAmount(amount); // operation.setAmount(amount);
operation.setUserId(userId); // operation.setUserId(userId);
operation.setWalletId(walletId); // operation.setWalletId(walletId);
operation.setOperationType(WalletBalanceOperationEnum.REDUCE_BAL.getKey()); // operation.setOperationType(WalletBalanceOperationEnum.REDUCE_BAL.getKey());
operation.setTradeType(AccTradeTypeEnum.CLEAR.getKey()); // operation.setTradeType(AccTradeTypeEnum.CLEAR.getKey());
operation.setPayChannel(PayChannelEnum.GW_SYSTEM.getKey()); // operation.setPayChannel(PayChannelEnum.GW_SYSTEM.getKey());
operation.setPayType(PayTypeEnum.SUB_GRANT.getKey()); // operation.setPayType(PayTypeEnum.SUB_GRANT.getKey());
accWalletInfoService.acWalletBalanceOperation(operation); // accWalletInfoService.acWalletBalanceOperation(operation);
log.info("清空补贴结束"); // log.info("清空补贴结束");
} finally { // } finally {
AccRedisUtils.unlockUpdateAccWalletBalance(userId); // AccRedisUtils.unlockUpdateAccWalletBalance(userId);
} // }
} // }
public void clearAccWalletBalance(BigDecimal amount, Long userId, Integer walletId) { public void clearAccWalletBalance(BigDecimal amount, Long userId, Integer walletId) {
log.info("清空补贴入参: userId{}walletId{}", userId, walletId); log.info("清空补贴入参: userId{}walletId{}", userId, walletId);
@ -263,7 +261,7 @@ public class AccSubServiceImpl implements AccSubService {
} }
} }
public AccBatchOperationWalletPreCheckVO batchOperationWalletClearCheck(AccSubsidyParam param) { public AccBatchOperationWalletPreCheckVO batchOperationWalletClearCheck(AccSubsidyBatchClearParam param) {
log.info("批量清空校验操作人数:{}", param.getUserIds().size()); log.info("批量清空校验操作人数:{}", param.getUserIds().size());
List<AccInfoDetailsVO> accInfoVOList = accInfoService.queryAccInfoByUserIds(param.getUserIds()); List<AccInfoDetailsVO> accInfoVOList = accInfoService.queryAccInfoByUserIds(param.getUserIds());
if (CollUtil.isEmpty(accInfoVOList)) { if (CollUtil.isEmpty(accInfoVOList)) {
@ -272,7 +270,7 @@ public class AccSubServiceImpl implements AccSubService {
List<AccBatchOperationWallerErrorVO> errVOList = new ArrayList<>(); List<AccBatchOperationWallerErrorVO> errVOList = new ArrayList<>();
List<Long> validUserList = new ArrayList<>(); List<Long> validUserList = new ArrayList<>();
List<BigDecimal> amountList = new ArrayList<>(); List<BigDecimal> amountList = new ArrayList<>();
BigDecimal walletBal = null;
for (AccInfoDetailsVO accInfo : accInfoVOList) { for (AccInfoDetailsVO accInfo : accInfoVOList) {
try { try {
checkAccount(accInfo); checkAccount(accInfo);
@ -280,7 +278,7 @@ public class AccSubServiceImpl implements AccSubService {
if(Objects.isNull(walletInfo)) { if(Objects.isNull(walletInfo)) {
throw new ServiceException("补贴钱包不存在"); throw new ServiceException("补贴钱包不存在");
} }
BigDecimal walletBal = walletInfo.getWalletBal(); walletBal = walletInfo.getWalletBal();
// if (walletBal.compareTo(BigDecimal.ZERO) <= 0) { // if (walletBal.compareTo(BigDecimal.ZERO) <= 0) {
// throw new ServiceException("补贴钱包余额必须大于0元"); // throw new ServiceException("补贴钱包余额必须大于0元");
// } else { // } else {
@ -294,14 +292,22 @@ public class AccSubServiceImpl implements AccSubService {
amountList.add(walletBal); amountList.add(walletBal);
validUserList.add(walletInfo.getUserId()); validUserList.add(walletInfo.getUserId());
} catch (Exception ex) { } catch (Exception ex) {
errVOList.add(createErrorVO(accInfo, param.getAmount(), ex.getMessage())); errVOList.add(createErrorVO(accInfo, walletBal, ex.getMessage()));
} }
} }
BigDecimal validTotalAmount = amountList.stream().reduce(BigDecimal.ZERO, BigDecimal::add); BigDecimal validTotalAmount = amountList.stream().reduce(BigDecimal.ZERO, BigDecimal::add);
return buildResult(param, validUserList, errVOList, validTotalAmount); AccBatchOperationWalletPreCheckVO result = new AccBatchOperationWalletPreCheckVO();
result.setTotalUserSum(param.getUserIds().size());
result.setValidCount(validUserList.size());
result.setValidTotalAmount(validTotalAmount);
result.setValidUserIdList(validUserList);
result.setInvalidCount(errVOList.size());
result.setErrVOList(errVOList);
result.setRemark(param.getRemark());
return result;
} }
public AccBatchOperationWalletPreCheckVO batchOperationWalletAddCheck(AccSubsidyParam param) { public AccBatchOperationWalletPreCheckVO batchOperationWalletAddCheck(AccSubsidyBatchAddParam param) {
log.info("批量校验操作人数:{}", param.getUserIds().size()); log.info("批量校验操作人数:{}", param.getUserIds().size());
List<AccInfoDetailsVO> accInfoVOList = accInfoService.queryAccInfoByUserIds(param.getUserIds()); List<AccInfoDetailsVO> accInfoVOList = accInfoService.queryAccInfoByUserIds(param.getUserIds());
if (CollUtil.isEmpty(accInfoVOList)) { if (CollUtil.isEmpty(accInfoVOList)) {
@ -319,7 +325,16 @@ public class AccSubServiceImpl implements AccSubService {
} }
} }
BigDecimal validTotalAmount = param.getAmount().multiply(new BigDecimal(sucVoList.size())); BigDecimal validTotalAmount = param.getAmount().multiply(new BigDecimal(sucVoList.size()));
return buildResult(param, sucVoList, errVOList, validTotalAmount); AccBatchOperationWalletPreCheckVO result = new AccBatchOperationWalletPreCheckVO();
result.setTotalUserSum(param.getUserIds().size());
result.setValidCount(sucVoList.size());
result.setValidTotalAmount(validTotalAmount);
result.setValidUserIdList(sucVoList);
result.setInvalidCount(errVOList.size());
result.setErrVOList(errVOList);
result.setAmount(param.getAmount());
result.setRemark(param.getRemark());
return result;
} }
private void checkAccount(AccInfoDetailsVO accInfo) { private void checkAccount(AccInfoDetailsVO accInfo) {
@ -336,23 +351,6 @@ public class AccSubServiceImpl implements AccSubService {
errVO.setErrorMessage(errMsg); errVO.setErrorMessage(errMsg);
return errVO; return errVO;
} }
private AccBatchOperationWalletPreCheckVO buildResult(AccSubsidyParam param,
List<Long> sucVoList,
List<AccBatchOperationWallerErrorVO> errVOList,
BigDecimal validTotalAmount) {
AccBatchOperationWalletPreCheckVO result = new AccBatchOperationWalletPreCheckVO();
result.setTotalUserSum(param.getUserIds().size());
result.setValidCount(sucVoList.size());
result.setValidTotalAmount(validTotalAmount);
result.setValidUserIdList(sucVoList);
result.setInvalidCount(errVOList.size());
result.setErrVOList(errVOList);
result.setAmount(param.getAmount());
result.setRemark(param.getRemark());
return result;
}
@Override @Override
public List<AccSubOperationListVO> queryAccSubOperationList(AccSubOperationQueryParam param) { public List<AccSubOperationListVO> queryAccSubOperationList(AccSubOperationQueryParam param) {
return accTradeService.queryAccSubOperationList(param); return accTradeService.queryAccSubOperationList(param);

View File

@ -9,6 +9,8 @@ import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bonus.canteen.core.account.constants.AccTradeStateEnum; import com.bonus.canteen.core.account.constants.AccTradeStateEnum;
import com.bonus.canteen.core.account.constants.AccTradeTypeEnum; import com.bonus.canteen.core.account.constants.AccTradeTypeEnum;
import com.bonus.canteen.core.account.constants.WalletBalanceOperationEnum; import com.bonus.canteen.core.account.constants.WalletBalanceOperationEnum;
@ -170,7 +172,7 @@ public class AccWalletInfoServiceImpl implements IAccWalletInfoService {
try { try {
accWalletInfoMapper.updateMinBalanceByUserId(minBalance, walletId, userIds, accWalletInfoMapper.updateMinBalanceByUserId(minBalance, walletId, userIds,
SecurityUtils.getUserId().toString(), DateUtils.toLocalDate(new Date())); SecurityUtils.getUserId().toString(), DateUtils.toLocalDateTime(new Date()));
} catch (Exception e) { } catch (Exception e) {
log.error("修改钱包最低余额限制失败", e); log.error("修改钱包最低余额限制失败", e);
throw new ServiceException("修改钱包最低余额限制失败"); throw new ServiceException("修改钱包最低余额限制失败");
@ -178,15 +180,18 @@ public class AccWalletInfoServiceImpl implements IAccWalletInfoService {
} }
private void addAccWalletInfo(WalletBalanceOperation operation) { private void addAccWalletInfo(WalletBalanceOperation operation) {
accWalletInfoMapper.addAccWalletInfo(operation.getAmount(), operation.getUserId(), operation.getWalletId()); accWalletInfoMapper.addAccWalletInfo(operation.getAmount(), operation.getUserId(), operation.getWalletId(),
SecurityUtils.getUserId().toString(), DateUtils.toLocalDateTime(new Date()));
} }
private void reduceAccWalletInfo(WalletBalanceOperation operation) { private void reduceAccWalletInfo(WalletBalanceOperation operation) {
accWalletInfoMapper.reduceAccWalletInfo(operation.getAmount(), operation.getUserId(), operation.getWalletId()); accWalletInfoMapper.reduceAccWalletInfo(operation.getAmount(), operation.getUserId(), operation.getWalletId(),
SecurityUtils.getUserId().toString(), DateUtils.toLocalDateTime(new Date()));
} }
// private void clearAccWalletInfo(WalletBalanceOperation operation) { // private void clearAccWalletInfo(WalletBalanceOperation operation) {
// accWalletInfoMapper.clearAccWalletInfo(operation.getUserId(), operation.getWalletId()); // accWalletInfoMapper.clearAccWalletInfo(operation.getUserId(), operation.getWalletId(),
// SecurityUtils.getUserId().toString(), DateUtils.toLocalDateTime(new Date()));
// } // }
public void acWalletBalanceOperation(WalletBalanceOperation operation) { public void acWalletBalanceOperation(WalletBalanceOperation operation) {
@ -206,7 +211,7 @@ public class AccWalletInfoServiceImpl implements IAccWalletInfoService {
AjaxResult userResult = remoteUserService.getInfo(operation.getUserId() , SecurityConstants.INNER); AjaxResult userResult = remoteUserService.getInfo(operation.getUserId() , SecurityConstants.INNER);
SysUser sysUser = null; SysUser sysUser = null;
if(Objects.nonNull(userResult)) { if(Objects.nonNull(userResult)) {
sysUser = userResult.getDataAs(SysUser.class); sysUser = JSONObject.parseObject(JSON.toJSONString(userResult.get(AjaxResult.DATA_TAG)), SysUser.class);
} }
long tradeId = Id.next(); long tradeId = Id.next();
LocalDateTime tradeTime = LocalDateTime.now(); LocalDateTime tradeTime = LocalDateTime.now();

View File

@ -1,11 +1,12 @@
package com.bonus.canteen.core.utils; package com.bonus.canteen.core.utils;
import com.bonus.common.houqin.i18n.I18nConfiguration; import com.bonus.common.houqin.i18n.I18nConfiguration;
import com.bonus.common.houqin.utils.SpringContextHolder;
import com.bonus.common.houqin.utils.id.IdWorkConfiguration; import com.bonus.common.houqin.utils.id.IdWorkConfiguration;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
@Configuration @Configuration
@Import({IdWorkConfiguration.class, I18nConfiguration.class}) @Import({IdWorkConfiguration.class, I18nConfiguration.class, SpringContextHolder.class})
public class CommonConfiguration { public class CommonConfiguration {
} }

View File

@ -157,22 +157,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<update id="addAccWalletInfo"> <update id="addAccWalletInfo">
UPDATE acc_wallet_info UPDATE acc_wallet_info
SET wallet_bal = wallet_bal + #{amount} SET wallet_bal = wallet_bal + #{amount},
update_by = #{updateBy},
update_time = #{updateTime}
WHERE user_id = #{userId} WHERE user_id = #{userId}
AND wallet_id = #{walletId} AND wallet_id = #{walletId}
</update> </update>
<update id="reduceAccWalletInfo"> <update id="reduceAccWalletInfo">
UPDATE acc_wallet_info UPDATE acc_wallet_info
SET wallet_bal = wallet_bal - #{amount} SET wallet_bal = wallet_bal - #{amount},
WHERE user_id = #{custId} update_by = #{updateBy},
update_time = #{updateTime}
WHERE user_id = #{userId}
AND wallet_id = #{walletId} AND wallet_id = #{walletId}
</update> </update>
<update id="clearAccWalletInfo"> <update id="clearAccWalletInfo">
UPDATE acc_wallet_info UPDATE acc_wallet_info
SET wallet_bal = 0 SET wallet_bal = 0,
WHERE user_id = #{custId} update_by = #{updateBy},
update_time = #{updateTime}
WHERE user_id = #{userId}
AND wallet_id = #{walletId} AND wallet_id = #{walletId}
</update> </update>
</mapper> </mapper>