feat:退还各自食堂

This commit is contained in:
dzc committed 2025-06-18 11:14:38 +08:00
1 parent 7aba505038
commit 1529301deb
7 files changed
+31 -20

No files matched your search

@@ -17,6 +17,7 @@ public enum WalletBizEnum {
REFUND("5", "退款"),
TRANSFER_ACCOUNTS("6", "转账"),
TRANSFER_ACCOUNTS_REFUND("7", "转账退款"),
RETURN_CANTEEN("8", "退还各自食堂"),
;
private final String code;
@@ -5,17 +5,24 @@ import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
import java.util.List;
@Getter
@AllArgsConstructor
public enum WalletBizRechargeEnum {
ADD("1", "添加"),
REDUCTION("2", "减少"),
REDUCTION("2", "记账扣款"),
RETURN_CANTEEN("3", "退还各自食堂"),
;
private final String code;
private final String desc;
public static List<String> reductionCodes() {
return Arrays.asList(REDUCTION.getCode(), RETURN_CANTEEN.getCode());
}
public static WalletBizRechargeEnum valueOfByType(String code) {
return Arrays.stream(WalletBizRechargeEnum.values())
.filter(v -> ObjectUtil.equal(v.getCode(), code))
@@ -89,6 +89,12 @@ public class WalletRechargeApplyEntity extends Model<WalletRechargeApplyEntity>
@Schema(description = "申请时间")
private LocalDateTime applyTime;
/**
* 是否授权(退还各自食堂)
*/
@Schema(description = "是否授权")
private String isAuthorization;
/**
* 备注
*/
@@ -3,7 +3,6 @@ package com.bsd.pjcloud.wallet.controller.recharge;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.excel.EasyExcel;
@@ -17,13 +16,11 @@ import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.data.datascope.DataScope;
import com.bsd.pjcloud.common.idempotent.annotation.Idempotent;
import com.bsd.pjcloud.common.log.annotation.SysLog;
import com.bsd.pjcloud.hard.api.constant.HardTypeEnum;
import com.bsd.pjcloud.wallet.api.constant.WalletBizRechargeEnum;
import com.bsd.pjcloud.wallet.api.constant.WalletTypeEnum;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeImportDto;
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargeImportEntity;
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeImportVo;
import com.bsd.pjcloud.wallet.api.vo.transaction.WalletTransactionVo;
import com.bsd.pjcloud.wallet.service.WalletRechargeImportService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
@@ -42,7 +39,6 @@ import java.math.RoundingMode;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* 充值导入表
@@ -134,7 +130,7 @@ public class WalletRechargeImportController {
v.setLineNumber(lineNumber);
lineNumber++;
if (ObjectUtil.isNotEmpty(v.getPrice())) {
if (ObjectUtil.equals(v.getBizType(), WalletBizRechargeEnum.REDUCTION.getCode()) && v.getPrice() > 0) {
if (WalletBizRechargeEnum.reductionCodes().contains(v.getBizType()) && v.getPrice() > 0) {
v.setPrice(v.getPrice() * -1);
}
priceStrSum = priceStrSum.add(BigDecimal.valueOf(v.getPrice()));
@@ -32,23 +32,16 @@ public interface WalletRechargeApplyService extends IService<WalletRechargeApply
/**
* 提交申请
*
* @param id
*/
void apply(Long id);
/**
* 取消申请
*
* @param dto
*/
void cancelApply(WalletRechargeApplyDto dto);
/**
* 读取excel内容
*
* @param excelVOList
* @param bindingResult
*/
R readExcel(List<WalletRechargeExcelDto> excelVOList, BindingResult bindingResult);
@@ -125,7 +125,7 @@ public class WalletTransactionServiceImpl extends ServiceImpl<WalletTransactionM
walletManageMapper.updateWhenRecharge(wallet.getId(), price);
break;
}
case REFUND, TRANSFER_ACCOUNTS_REFUND: {
case REFUND, TRANSFER_ACCOUNTS_REFUND, RETURN_CANTEEN: {
walletManageMapper.updateWhenConsumptionRefund(wallet.getId(), price);
break;
}
@@ -17,6 +17,7 @@ import com.bsd.pjcloud.admin.api.feign.RemoteDeptService;
import com.bsd.pjcloud.admin.api.feign.RemoteUserService;
import com.bsd.pjcloud.admin.api.utils.DataUtil;
import com.bsd.pjcloud.admin.api.vo.UserVO;
import com.bsd.pjcloud.common.core.constant.enums.YesNoEnum;
import com.bsd.pjcloud.common.core.util.BeanUtils;
import com.bsd.pjcloud.common.core.util.CollectionUtils;
import com.bsd.pjcloud.common.core.util.R;
@@ -114,6 +115,9 @@ public class WalletRechargeApplyServiceImpl extends ServiceImpl<WalletRechargeAp
if (ObjectUtil.isEmpty(detail)) {
throw new RuntimeException("申请不存在");
}
if (ObjectUtil.equals(dto.getIsAuthorization(), YesNoEnum.NO.getCode())) {
throw new RuntimeException("请同意授权协议");
}
WalletRechargeApplyEntity updateObj = BeanUtils.toBean(dto, WalletRechargeApplyEntity.class);
baseMapper.updateById(updateObj);
getSelf().updateBeforePrice(baseMapper.selectById(dto.getId()));
@@ -348,7 +352,7 @@ public class WalletRechargeApplyServiceImpl extends ServiceImpl<WalletRechargeAp
return;
}
getSelf().updateBeforePrice(detail);
if (ObjectUtil.equals(detail.getBizType(), WalletBizRechargeEnum.REDUCTION.getCode())) {
if (WalletBizRechargeEnum.reductionCodes().contains(detail.getBizType())) {
importList.forEach(v -> v.setPrice(-1 * Math.abs(v.getPrice())));
}
for (WalletRechargeImportEntity v : importList) {
@@ -357,7 +361,9 @@ public class WalletRechargeApplyServiceImpl extends ServiceImpl<WalletRechargeAp
if (ObjectUtil.isEmpty(wallet)) {
continue;
}
walletTransactionService.addWalletBalance(wallet.getId(), v.getPrice(), String.valueOf(v.getId()), WalletBizEnum.BATCH);
// 判断是`退还各自食堂`还是`批量更新余额`
WalletBizEnum walletBiz = ObjectUtil.equal(WalletBizRechargeEnum.RETURN_CANTEEN.getCode(), detail.getBizType()) ? WalletBizEnum.RETURN_CANTEEN : WalletBizEnum.BATCH;
walletTransactionService.addWalletBalance(wallet.getId(), v.getPrice(), String.valueOf(v.getId()), walletBiz);
}
// 同步到正元钱包状态
List<Long> userIds = importList.stream().map(WalletRechargeImportEntity::getUserId).distinct().toList();
@@ -488,7 +494,7 @@ public class WalletRechargeApplyServiceImpl extends ServiceImpl<WalletRechargeAp
* 判断申请下如果类型为记账扣款,余额是否够扣款
*/
private void validateWalletBalance(WalletRechargeApplyEntity applyDto) {
if (ObjectUtil.notEqual(applyDto.getBizType(), WalletBizRechargeEnum.REDUCTION.getCode())) return;
if (!WalletBizRechargeEnum.reductionCodes().contains(applyDto.getBizType())) return;
List<WalletRechargeImportEntity> importList = rechargeImportService.list(new LambdaQueryWrapper<WalletRechargeImportEntity>()
.eq(WalletRechargeImportEntity::getApplyId, applyDto.getId())
);
@@ -528,7 +534,8 @@ public class WalletRechargeApplyServiceImpl extends ServiceImpl<WalletRechargeAp
}
private void validateWalletBalanceByType(WalletRechargeApplyEntity applyDto) {
if (ObjectUtil.notEqual(applyDto.getBizType(), WalletBizRechargeEnum.REDUCTION.getCode())) return;
if (!WalletBizRechargeEnum.reductionCodes().contains(applyDto.getBizType())) return;
WalletBizRechargeEnum bizTypeEnum = WalletBizRechargeEnum.valueOfByType(applyDto.getBizType());
List<WalletRechargeImportEntity> importList = rechargeImportService.list(new LambdaQueryWrapper<WalletRechargeImportEntity>()
.eq(WalletRechargeImportEntity::getApplyId, applyDto.getId())
);
@@ -553,7 +560,8 @@ public class WalletRechargeApplyServiceImpl extends ServiceImpl<WalletRechargeAp
} else {
errorMsg.append("用户名<").append(userTarget.getName()).append(">");
}
errorMsg.append("记账扣款失败,");
errorMsg.append(bizTypeEnum.getDesc());
errorMsg.append("失败,");
errorMsg.append("操作前的金额<").append(wallet.getBalance() / 100).append(">,");
errorMsg.append("记账扣款的金额<").append(i.getPrice() / 100).append(">,");
errorMsg.append("记账扣款后的金额<").append(discountPrice / 100).append(">\n");
@@ -565,7 +573,7 @@ public class WalletRechargeApplyServiceImpl extends ServiceImpl<WalletRechargeAp
}
public void updateAllWalletBalance(WalletRechargeApplyEntity applyDto, List<WalletRechargeImportEntity> importList) {
if (ObjectUtil.notEqual(applyDto.getBizType(), WalletBizRechargeEnum.REDUCTION.getCode())) return;
if (!WalletBizRechargeEnum.reductionCodes().contains(applyDto.getBizType())) return;
List<Long> importUserIds = importList.stream().map(WalletRechargeImportEntity::getUserId).distinct().toList();
// 查询用户钱包
WalletManageDto userWalletDto = new WalletManageDto();