feat(bpm): 整合租赁订单退款流程

- 新增 RentalOrderApi 和 RentalDepositRecordApi接口
- 实现租赁订单状态更新和退款金额校验功能
- 添加租赁订单相关数据结构和接口实现
- 修改租赁订单状态枚举,增加等待退款中状态
This commit is contained in:
furongxin 2024-11-25 10:00:07 +08:00
parent 58929c5224
commit ce26b95c08
14 changed files with 283 additions and 9 deletions

View File

@ -16,6 +16,8 @@ import cn.iocoder.yudao.module.system.api.holiday.HolidayApi;
import cn.iocoder.yudao.module.system.api.notify.NotifyMessageSendApi;
import cn.iocoder.yudao.module.system.api.permission.RoleApi;
import cn.iocoder.yudao.module.system.api.position.PositionApi;
import cn.iocoder.yudao.module.system.api.rental.RentalDepositRecordApi;
import cn.iocoder.yudao.module.system.api.rental.RentalOrderApi;
import cn.iocoder.yudao.module.system.api.sms.SmsSendApi;
import cn.iocoder.yudao.module.system.api.social.SocialClientApi;
import cn.iocoder.yudao.module.system.api.subscribe.SubscribeMessageSendApi;
@ -28,7 +30,8 @@ import org.springframework.context.annotation.Configuration;
@Configuration(proxyBeanMethods = false)
@EnableFeignClients(clients = {FileApi.class, RoleApi.class, DeptApi.class, PostApi.class, AdminUserApi.class, SmsSendApi.class, DictDataApi.class, NotifyMessageSendApi.class,
SubscribeMessageSendApi.class, SocialClientApi.class, UsersExtApi.class, AttendanceApi.class, BankApi.class, ConfigApi.class, PositionApi.class, SupplierApi.class, AssetsApi.class,
AssetsTypeApi.class, AssetReceiveApi.class, AttendanceApi.class, AttendanceGroupApi.class, WorkOvertimeApi.class, HolidayApi.class
AssetsTypeApi.class, AssetReceiveApi.class, AttendanceApi.class, AttendanceGroupApi.class, WorkOvertimeApi.class, HolidayApi.class,
RentalOrderApi.class, RentalDepositRecordApi.class
})
public class RpcConfiguration {
}

View File

@ -10,17 +10,22 @@ import cn.iocoder.yudao.module.bpm.dal.mysql.oa.BpmOARefundMapper;
import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum;
import cn.iocoder.yudao.module.bpm.service.task.BpmHistoryProcessInstanceService;
import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService;
import cn.iocoder.yudao.module.system.api.rental.RentalDepositRecordApi;
import cn.iocoder.yudao.module.system.api.rental.RentalOrderApi;
import cn.iocoder.yudao.module.system.api.rental.dto.RentalOrderDTO;
import org.flowable.engine.runtime.ProcessInstance;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.OA_REFUND_NOT_EXISTS;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.RENTAL_REFUND_AMOUNT_EXCESS;
/**
* OA 退款申请 Service 实现类
@ -49,9 +54,18 @@ public class BpmOARefundServiceImpl extends BpmOABaseService implements BpmOARef
@Resource
private BpmProcessInstanceService bpmProcessInstanceService;
@Resource
private RentalOrderApi rentalOrderApi;
@Resource
private RentalDepositRecordApi depositRecordApi;
@Override
public Long createRefund(Long userId, BpmOARefundCreateReqVO createReqVO) {
// 发起流程前 校验扣款金额+退款金额是否等于已收金额
validateRefundAmount(createReqVO.getOrderNo(), createReqVO.getChargebacksAmount(), createReqVO.getRefundAmount());
//插入OA 退款申请
BpmOARefundDO refund = BeanUtils.toBean(createReqVO, BpmOARefundDO.class)
.setUserId(userId)
@ -64,7 +78,7 @@ public class BpmOARefundServiceImpl extends BpmOABaseService implements BpmOARef
new BpmProcessInstanceCreateReqDTO().setProcessDefinitionKey(PROCESS_KEY)
.setVariables(processInstanceVariables).setBusinessKey(String.valueOf(refund.getId()))).getCheckedData();
// 将工作流的编号更新到 OA 转正单中
// 将工作流的编号更新到 OA 退款申请单中
refundMapper.updateById(new BpmOARefundDO().setId(refund.getId()).setProcessInstanceId(processInstanceId));
// 判断是否为重新发起的流程
@ -78,13 +92,30 @@ public class BpmOARefundServiceImpl extends BpmOABaseService implements BpmOARef
if (fileItems != null && !fileItems.isEmpty()) {
uploadBpmFileProcessInstanceId(processInstanceId,fileItems) ;
}
// 退款申请发起后变更租赁订单状态为 退款中
rentalOrderApi.updateOrder(new RentalOrderDTO()
.setOrderNo(refund.getOrderNo())
.setStatus(2));
return refund.getId();
}
/**
* 校验扣款金额+退款金额是否等于已收金额
*/
private void validateRefundAmount(String orderNo, BigDecimal chargebacksAmount, BigDecimal refundAmount) {
BigDecimal recordAmount = depositRecordApi.getRecordAmount(orderNo).getCheckedData();
if (recordAmount.compareTo(chargebacksAmount.add(refundAmount)) != 0) {
throw exception(RENTAL_REFUND_AMOUNT_EXCESS);
}
}
@Override
public void updateRefundResult(String processInstanceId, Long id, Integer result) {
validateLeaveExists(id);
BpmOARefundDO refundDO = validateLeaveExists(id);
//审核通过 最后节点
if (BpmProcessInstanceResultEnum.APPROVE.getResult().equals(result)) {
@ -92,16 +123,23 @@ public class BpmOARefundServiceImpl extends BpmOABaseService implements BpmOARef
if (instance.isEnded()) {
// 审批通过后 更新租赁订单信息
rentalOrderApi.updateOrder(new RentalOrderDTO()
.setOrderNo(refundDO.getOrderNo())
.setChargebacksAmount(refundDO.getChargebacksAmount())
.setStatus(3)); // 状态变更为 等待退款中
}
}
refundMapper.updateById(new BpmOARefundDO().setId(id).setResult(result));
}
private void validateLeaveExists(Long id) {
if (refundMapper.selectById(id) == null) {
private BpmOARefundDO validateLeaveExists(Long id) {
BpmOARefundDO refundDO = refundMapper.selectById(id);
if (refundDO == null) {
throw exception(OA_REFUND_NOT_EXISTS);
}
return refundDO;
}
@Override

View File

@ -0,0 +1,29 @@
package cn.iocoder.yudao.module.system.api.rental;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.api.rental.dto.RentalDepositRecordDTO;
import cn.iocoder.yudao.module.system.enums.ApiConstants;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import java.math.BigDecimal;
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿fallbackFactory =
@Tag(name = "RPC 服务 - 租赁订单金额记录")
public interface RentalDepositRecordApi {
String PREFIX = ApiConstants.PREFIX + "/rental-deposit";
@PutMapping(PREFIX + "/create")
@Operation(summary = "创建租赁订单出入张记录")
CommonResult<Long> create(@RequestBody RentalDepositRecordDTO createReqVO);
@GetMapping(PREFIX + "/getRecordAmount")
@Operation(summary = "获取租赁订单已收取的金额")
CommonResult<BigDecimal> getRecordAmount(@RequestParam("orderNo") String orderNo);
}

View File

@ -0,0 +1,25 @@
package cn.iocoder.yudao.module.system.api.rental;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.api.position.dto.PositionDTO;
import cn.iocoder.yudao.module.system.api.rental.dto.RentalOrderDTO;
import cn.iocoder.yudao.module.system.enums.ApiConstants;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿fallbackFactory =
@Tag(name = "RPC 服务 - 租赁订单")
public interface RentalOrderApi {
String PREFIX = ApiConstants.PREFIX + "/rental-order";
@PutMapping(PREFIX + "/update")
@Operation(summary = "更新租赁订单信息")
CommonResult<Boolean> updateOrder(@RequestBody RentalOrderDTO updateReqVO);
}

View File

@ -0,0 +1,53 @@
package cn.iocoder.yudao.module.system.api.rental.dto;
import cn.iocoder.yudao.framework.common.pojo.UploadUserFile;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;
@Schema(description = "管理后台 - 租赁订单押金记录新增/修改 Request VO")
@Data
public class RentalDepositRecordDTO {
@Schema(description = "租赁订单押金记录表单主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Long id;
@Schema(description = "订单编号", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "订单编号不能为空")
private String orderNo;
@Schema(description = "支付方式 | 1支付宝 2微信 3银行卡", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "支付方式不能为空")
private Integer paymentMethod;
@Schema(description = "交易订单号", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "交易订单号不能为空")
private String transactionOrderNumber;
@Schema(description = "银行卡号")
private String bankNo;
@Schema(description = "客户银行卡号", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "客户银行卡号不能为空")
private String customerBankNo;
@Schema(description = "收款/退款金额", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "收款/退款金额不能为空")
private BigDecimal amount;
@Schema(description = "收款/退款日期", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "收款/退款日期不能为空")
private LocalDate paymentDate;
@Schema(description = "类型 | 1收款 2退款", example = "1")
private Integer type;
@Schema(description = "附件信息")
private List<UploadUserFile> fileItems;
}

View File

@ -0,0 +1,37 @@
package cn.iocoder.yudao.module.system.api.rental.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
@Schema(description = "管理后台 - 租赁订单新增/修改 Request VO")
@Data
public class RentalOrderDTO {
@Schema(description = "租赁订单表单主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Long id;
@Schema(description = "订单编号")
private String orderNo;
@Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED)
private Long customerId;
@Schema(description = "收款人")
private String recipient;
@Schema(description = "押金金额", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "押金金额不能为空")
private BigDecimal depositAmount;
@Schema(description = "扣款金额")
private BigDecimal chargebacksAmount;
@Schema(description = "备注")
private String notes;
@Schema(description = "状态 | 1租赁中 2退款中 3已退")
private Integer status;
}

View File

@ -0,0 +1,40 @@
package cn.iocoder.yudao.module.system.api.rental;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.api.rental.dto.RentalDepositRecordDTO;
import cn.iocoder.yudao.module.system.api.rental.dto.RentalOrderDTO;
import cn.iocoder.yudao.module.system.controller.admin.rental.vo.order.RentalOrderSaveReqVO;
import cn.iocoder.yudao.module.system.controller.admin.rental.vo.rentaldepositrecord.RentalDepositAmountReqVO;
import cn.iocoder.yudao.module.system.controller.admin.rental.vo.rentaldepositrecord.RentalDepositRecordSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.rental.RentalDepositRecordDO;
import cn.iocoder.yudao.module.system.service.rental.RentalDepositRecordService;
import cn.iocoder.yudao.module.system.service.rental.RentalOrderService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.math.BigDecimal;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@RestController // 提供 RESTful API 接口 Feign 调用
@Validated
public class RentalDepositRecordApiImpl implements RentalDepositRecordApi {
@Resource
private RentalDepositRecordService rentalDepositRecordService;
@Override
public CommonResult<Long> create(RentalDepositRecordDTO createReqVO) {
RentalDepositRecordSaveReqVO depositRecord = BeanUtils.toBean(createReqVO, RentalDepositRecordSaveReqVO.class);
return success(rentalDepositRecordService.createRentalDepositRecord(depositRecord));
}
@Override
public CommonResult<BigDecimal> getRecordAmount(String orderNo) {
RentalDepositAmountReqVO reqVO = rentalDepositRecordService.getRentalDepositRecordAmount(orderNo, false);
return success(reqVO.getReceivedAmount());
}
}

View File

@ -0,0 +1,27 @@
package cn.iocoder.yudao.module.system.api.rental;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.api.rental.dto.RentalOrderDTO;
import cn.iocoder.yudao.module.system.controller.admin.rental.vo.order.RentalOrderSaveReqVO;
import cn.iocoder.yudao.module.system.service.rental.RentalOrderService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@RestController // 提供 RESTful API 接口 Feign 调用
@Validated
public class RentalOrderApiImpl implements RentalOrderApi {
@Resource
private RentalOrderService rentalOrderService;
@Override
public CommonResult<Boolean> updateOrder(RentalOrderDTO updateReqVO) {
rentalOrderService.update(BeanUtils.toBean(updateReqVO, RentalOrderSaveReqVO.class));
return success(true);
}
}

View File

@ -29,7 +29,7 @@ public class RentalOrderPageReqVO extends PageParam {
@Schema(description = "押金金额")
private Integer depositAmount;
@Schema(description = "状态 | 1租赁中 2退款中 3已退")
@Schema(description = "状态 | 1租赁中 2退款申请中 3等待退款中 4已退")
private Integer status;
@Schema(description = "创建时间")

View File

@ -46,7 +46,7 @@ public class RentalOrderRespVO {
@Schema(description = "备注")
private String notes;
@Schema(description = "状态 | 1租赁中 2退款中 3已退")
@Schema(description = "状态 | 1租赁中 2退款申请中 3等待退款中 4已退")
private Integer status;
@Schema(description = "创建时间")

View File

@ -37,7 +37,7 @@ public class RentalOrderSaveReqVO {
@Schema(description = "备注")
private String notes;
@Schema(description = "状态 | 1租赁中 2退款中 3已退")
@Schema(description = "状态 | 1租赁中 2退款申请中 3等待退款中 4已退")
private Integer status;
@Schema(description = "租赁物品记录")

View File

@ -53,7 +53,7 @@ public class RentalOrderDO extends BaseDO {
*/
private String notes;
/**
* 状态 | 1租赁中 2退款 3已退
* 状态 | 1租赁中 2退款申请 3等待退款中 4已退
*/
private Integer status;

View File

@ -31,6 +31,12 @@ public interface RentalOrderService {
*/
BigDecimal updateRentalOrder(@Valid RentalOrderSaveReqVO updateReqVO);
/**
* 更新租赁订单
* @param updateReqVO 更新信息
*/
void update(RentalOrderSaveReqVO updateReqVO);
/**
* 删除租赁订单
*

View File

@ -3,12 +3,15 @@ package cn.iocoder.yudao.module.system.service.rental;
import cn.hutool.core.collection.CollectionUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.controller.admin.rental.vo.order.RentalOrderPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.rental.vo.order.RentalOrderRespVO;
import cn.iocoder.yudao.module.system.controller.admin.rental.vo.order.RentalOrderSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.rental.RentalOrderDO;
import cn.iocoder.yudao.module.system.dal.mysql.rental.RentalOrderMapper;
import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
@ -115,6 +118,19 @@ public class RentalOrderServiceImpl implements RentalOrderService {
return updateObj.getDepositAmount().subtract(updateObj.getChargebacksAmount() == null ? BigDecimal.ZERO : updateObj.getChargebacksAmount());
}
@Override
public void update(RentalOrderSaveReqVO updateReqVO) {
Long count = rentalOrderMapper.selectCount(RentalOrderDO::getOrderNo, updateReqVO.getOrderNo());
if (count <= 0L) {
throw exception(RENTAL_ORDER_NOT_EXISTS);
}
// 更新
RentalOrderDO updateObj = BeanUtils.toBean(updateReqVO, RentalOrderDO.class);
rentalOrderMapper.update(updateObj, new LambdaQueryWrapperX<RentalOrderDO>()
.eq(RentalOrderDO::getOrderNo, updateReqVO.getOrderNo()));
}
@Override
public void deleteRentalOrder(Long id) {
// 校验存在