Compare commits

...

2 Commits

Author SHA1 Message Date
furongxin
61b4528154 feat(rental): 完善租赁订单退款功能并新增相关接口
- 新增租赁订单物品记录相关接口和DTO
- 完善租赁订单状态管理和退款流程- 新增获取租赁订单信息接口
- 优化租赁订单列表展示,增加退款申请信息
2024-11-27 09:26:26 +08:00
furongxin
e26f51b982 feat(rental): 完善租赁订单退款功能并新增相关接口
- 新增租赁订单物品记录相关接口和DTO
- 完善租赁订单状态管理和退款流程- 新增获取租赁订单信息接口
- 优化租赁订单列表展示,增加退款申请信息
2024-11-27 09:23:07 +08:00
26 changed files with 423 additions and 49 deletions

View File

@ -0,0 +1,33 @@
package cn.iocoder.yudao.module.bpm.api.oa;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.bpm.api.oa.vo.BpmOARefundDTO;
import cn.iocoder.yudao.module.bpm.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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
import java.util.Map;
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿fallbackFactory =
@Tag(name = "RPC 服务 - 退款申请")
public interface BpmOARefundApi {
String PREFIX = ApiConstants.PREFIX + "/oa/refund";
@PostMapping(PREFIX + "/get")
@Operation(summary = "获得指定的退款申请列表")
CommonResult<Map<String,BpmOARefundDTO>> getListByOrderNo(@RequestBody List<String> orderNos);
@GetMapping(PREFIX + "/update-status")
@Operation(summary = "修改退款申请的退款状态 为已退款")
@Parameter(name = "orderNo", description = "订单编号", required = true)
@Parameter(name = "status", description = "状态", required = true)
CommonResult<Boolean> updateStatus(@RequestParam("orderNo") String orderNo);
}

View File

@ -0,0 +1,50 @@
package cn.iocoder.yudao.module.bpm.api.oa.vo;
import cn.iocoder.yudao.framework.common.pojo.UploadUserFile;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY;
/**
* @author 符溶馨
*/
@Schema(description = "管理后台 - 退款申请 请求Request VO")
@Data
@ToString(callSuper = true)
public class BpmOARefundDTO {
@Schema(description = "表单主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long id;
@Schema(description = "状态-参见 bpm_process_instance_result 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer result;
@Schema(description = "流程id")
private String processInstanceId;
@Schema(description = "订单编号", requiredMode = Schema.RequiredMode.REQUIRED)
private String orderNo;
@Schema(description = "扣款金额")
private BigDecimal chargebacksAmount;
@Schema(description = "退款金额", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private BigDecimal refundAmount;
@Schema(description = "退款日期", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY)
private LocalDate refundDate;
@Schema(description = "备注", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String notes;
@Schema(description = "上传文件", requiredMode = Schema.RequiredMode.REQUIRED)
private List<UploadUserFile> fileItems;
}

View File

@ -0,0 +1,39 @@
package cn.iocoder.yudao.module.bpm.api.oa;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.bpm.api.oa.vo.BpmOARefundDTO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOARefundDO;
import cn.iocoder.yudao.module.bpm.service.oa.BpmOARefundService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
/**
* Flowable 流程实例 Api 实现类
*/
@RestController
@Validated
public class BpmOARefundApiImpl implements BpmOARefundApi{
@Resource
private BpmOARefundService refundService;
@Override
public CommonResult<Map<String, BpmOARefundDTO>> getListByOrderNo(List<String> orderNos) {
List<BpmOARefundDO> list = refundService.getListByOrderNo(orderNos);
return success(convertMap(BeanUtils.toBean(list, BpmOARefundDTO.class), BpmOARefundDTO::getOrderNo));
}
@Override
public CommonResult<Boolean> updateStatus(String orderNo) {
refundService.updateStatus(orderNo);
return success(true);
}
}

View File

@ -47,6 +47,9 @@ public class BpmOARefundCreateReqVO {
@Schema(description = "备注", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String notes;
@Schema(description = "状态 | 0未退款 1已退款", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer status;
@Schema(description = "流程实例编号")
private String processInstanceId;

View File

@ -46,6 +46,9 @@ public class BpmOARefundRespVO extends BpmOABaseRespVO {
@Schema(description = "备注", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String notes;
@Schema(description = "状态 | 0未退款 1已退款", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer status;
@Schema(description = "上传文件", requiredMode = Schema.RequiredMode.REQUIRED)
private List<UploadUserFile> fileItems;
}

View File

@ -71,6 +71,11 @@ public class BpmOARefundDO extends BaseDO {
*/
private String notes;
/**
* 状态 | 0未退款 1已退款
*/
private Integer status;
/**
* 结果
* 枚举 {@link BpmProcessInstanceResultEnum}

View File

@ -4,8 +4,11 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.evection.BpmOAEvectionCreateReqVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOAEvectionDO;
import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum;
import org.apache.ibatis.annotations.Mapper;
import java.util.Arrays;
/**
* 出差申请 Mapper
*
@ -20,6 +23,7 @@ public interface BpmOAEvectionMapper extends BaseMapperX<BpmOAEvectionDO> {
return selectCount(new LambdaQueryWrapperX<BpmOAEvectionDO>()
.eq(BpmOAEvectionDO::getUserId, userId)
.leIfPresent(BpmOAEvectionDO::getStartTime, createReqVO.getEndTime())
.geIfPresent(BpmOAEvectionDO::getEndTime, createReqVO.getStartTime()));
.geIfPresent(BpmOAEvectionDO::getEndTime, createReqVO.getStartTime())
.in(BpmOAEvectionDO::getResult, Arrays.asList(BpmProcessInstanceResultEnum.PROCESS, BpmProcessInstanceResultEnum.APPROVE)));
}
}

View File

@ -18,6 +18,7 @@ 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.project.ProjectApi;
import cn.iocoder.yudao.module.system.api.rental.RentalDepositRecordApi;
import cn.iocoder.yudao.module.system.api.rental.RentalItemsRecordApi;
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;
@ -32,7 +33,7 @@ import org.springframework.context.annotation.Configuration;
@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,
RentalOrderApi.class, RentalDepositRecordApi.class, ProjectApi.class
RentalOrderApi.class, RentalDepositRecordApi.class, ProjectApi.class, RentalItemsRecordApi.class
})
public class RpcConfiguration {
}

View File

@ -4,11 +4,12 @@ import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.refund.BpmOARefundCrea
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOARefundDO;
import javax.validation.Valid;
import java.util.List;
public interface BpmOARefundService {
/**
* 创建转正申请
* 创建退款申请
*
* @param userId 用户编号
* @param createReqVO 创建信息
@ -17,7 +18,7 @@ public interface BpmOARefundService {
Long createRefund(Long userId, @Valid BpmOARefundCreateReqVO createReqVO);
/**
* 更新转正申请的状态
* 更新退款申请的状态
*
* @param id 编号
* @param result 结果
@ -25,17 +26,30 @@ public interface BpmOARefundService {
void updateRefundResult(String processInstanceId, Long id, Integer result);
/**
* 获得转正申请
* 获得退款申请
*
* @param id 编号
* @return 转正申请
* @return 退款申请
*/
BpmOARefundDO getRefund(Long id);
/**
* 获得指定的转正申请
* 获得指定的退款申请
* @param processInstanceId 流程实例编号
* @return 转正申请
* @return 退款申请
*/
BpmOARefundDO getByProcessInstanceId(String processInstanceId);
/**
* 获得指定的退款申请列表
* @param orderNos 订单编号
* @return 退款申请列表
*/
List<BpmOARefundDO> getListByOrderNo(List<String> orderNos);
/**
* 更新退款申请状态
* @param orderNo 订单编号
*/
void updateStatus(String orderNo);
}

View File

@ -1,18 +1,24 @@
package cn.iocoder.yudao.module.bpm.service.oa;
import cn.iocoder.yudao.framework.common.pojo.UploadUserFile;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi;
import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.refund.BpmOARefundCreateReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.refund.BpmOARefundItems;
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOARefundDO;
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.RentalItemsRecordApi;
import cn.iocoder.yudao.module.system.api.rental.RentalOrderApi;
import cn.iocoder.yudao.module.system.api.rental.dto.RentalItemsRecordDTO;
import cn.iocoder.yudao.module.system.api.rental.dto.RentalOrderDTO;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.flowable.engine.runtime.ProcessInstance;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@ -22,6 +28,7 @@ import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.OA_REFUND_NOT_EXISTS;
@ -57,13 +64,16 @@ public class BpmOARefundServiceImpl extends BpmOABaseService implements BpmOARef
@Resource
private RentalOrderApi rentalOrderApi;
@Resource
private RentalItemsRecordApi rentalItemsRecordApi;
@Resource
private RentalDepositRecordApi depositRecordApi;
@Override
public Long createRefund(Long userId, BpmOARefundCreateReqVO createReqVO) {
// 发起流程前 校验扣款金额+退款金额是否于已收金额
// 发起流程前 校验扣款金额+退款金额是否于已收金额
validateRefundAmount(createReqVO.getOrderNo(), createReqVO.getChargebacksAmount(), createReqVO.getRefundAmount());
//插入OA 退款申请
@ -102,12 +112,16 @@ public class BpmOARefundServiceImpl extends BpmOABaseService implements BpmOARef
}
/**
* 校验扣款金额+退款金额是否于已收金额
* 校验扣款金额+退款金额是否于已收金额
*/
private void validateRefundAmount(String orderNo, BigDecimal chargebacksAmount, BigDecimal refundAmount) {
BigDecimal recordAmount = depositRecordApi.getRecordAmount(orderNo).getCheckedData();
if (recordAmount.compareTo(chargebacksAmount.add(refundAmount)) != 0) {
// 获取订单的已收金额 已退金额
Map<String, BigDecimal> respVO = depositRecordApi.getRecordAmount(orderNo).getCheckedData();
// 获取当前订单 还需退款金额 = 已收金额 - 已退金额
BigDecimal recordAmount = respVO.get("receivedAmount").subtract(respVO.get("refundAmount"));
if (recordAmount.compareTo(chargebacksAmount.add(refundAmount)) < 0) {
throw exception(RENTAL_REFUND_AMOUNT_EXCESS);
}
}
@ -123,11 +137,30 @@ public class BpmOARefundServiceImpl extends BpmOABaseService implements BpmOARef
if (instance.isEnded()) {
// 获取订单的扣款金额
BigDecimal chargebacks = rentalOrderApi.getOrder(refundDO.getOrderNo()).getCheckedData().getChargebacksAmount();
// 审批通过后 更新租赁订单信息
rentalOrderApi.updateOrder(new RentalOrderDTO()
.setOrderNo(refundDO.getOrderNo())
.setChargebacksAmount(refundDO.getChargebacksAmount())
.setChargebacksAmount(refundDO.getChargebacksAmount().add(chargebacks)) // 扣款金额累加
.setStatus(3)); // 状态变更为 等待退款中
List<BpmOARefundItems> items = refundDO.getRefundItems();
//直接从数据库取出来的List<Reimbursement> 实际上是List<LinkedHashMap>类型 所以不能直接遍历
//将list再次转为json串然后由json串再转为list
String json = JsonUtils.toJsonString(items);
items = JsonUtils.parseArray(json, BpmOARefundItems.class);
// 审批通过后 更新租赁物品 归还信息
List<RentalItemsRecordDTO> createReqVO = items.stream()
.map(item -> new RentalItemsRecordDTO()
.setOrderNo(refundDO.getOrderNo())
.setRentalItemsType(item.getRentalItemsType())
.setNumber(item.getRentalNumber())
.setType(2))
.collect(Collectors.toList());
rentalItemsRecordApi.create(createReqVO);
}
}
@ -165,4 +198,19 @@ public class BpmOARefundServiceImpl extends BpmOABaseService implements BpmOARef
return refundMapper.selectOne(BpmOARefundDO::getProcessInstanceId, processInstanceId);
}
@Override
public List<BpmOARefundDO> getListByOrderNo(List<String> orderNos) {
return refundMapper.selectList(new LambdaQueryWrapperX<BpmOARefundDO>()
.inIfPresent(BpmOARefundDO::getOrderNo, orderNos)
.eq(BpmOARefundDO::getStatus, 0));
}
@Override
public void updateStatus(String orderNo) {
refundMapper.update(null, new LambdaUpdateWrapper<BpmOARefundDO>()
.set(BpmOARefundDO::getStatus, 1)
.eq(BpmOARefundDO::getOrderNo, orderNo)
.eq(BpmOARefundDO::getStatus, 0));
}
}

View File

@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import java.math.BigDecimal;
import java.util.Map;
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿fallbackFactory =
@Tag(name = "RPC 服务 - 租赁订单金额记录")
@ -25,5 +26,5 @@ public interface RentalDepositRecordApi {
@GetMapping(PREFIX + "/getRecordAmount")
@Operation(summary = "获取租赁订单已收取的金额")
CommonResult<BigDecimal> getRecordAmount(@RequestParam("orderNo") String orderNo);
CommonResult<Map<String, BigDecimal>> getRecordAmount(@RequestParam("orderNo") String orderNo);
}

View File

@ -0,0 +1,28 @@
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.api.rental.dto.RentalItemsRecordDTO;
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;
import java.util.List;
import java.util.Map;
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿fallbackFactory =
@Tag(name = "RPC 服务 - 租赁订单物品记录")
public interface RentalItemsRecordApi {
String PREFIX = ApiConstants.PREFIX + "/rental-items";
@PutMapping(PREFIX + "/create")
@Operation(summary = "创建租赁订单出入库记录")
CommonResult<Boolean> create(@RequestBody List<RentalItemsRecordDTO> createReqVO);
}

View File

@ -22,4 +22,9 @@ public interface RentalOrderApi {
@PutMapping(PREFIX + "/update")
@Operation(summary = "更新租赁订单信息")
CommonResult<Boolean> updateOrder(@RequestBody RentalOrderDTO updateReqVO);
@GetMapping(PREFIX + "/get")
@Operation(summary = "获取租赁订单信息")
@Parameter(name = "orderNo", description = "订单编号", required = true)
CommonResult<RentalOrderDTO> getOrder(@RequestParam("orderNo") String orderNo);
}

View File

@ -0,0 +1,32 @@
package cn.iocoder.yudao.module.system.api.rental.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - 租赁物品记录新增/修改 Request VO")
@Data
public class RentalItemsRecordDTO {
@Schema(description = "租赁订单表单主键")
private Long id;
@Schema(description = "订单编号", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "订单编号不能为空")
private String orderNo;
@Schema(description = "租赁物品种类 | 字典值参考 system_rental_items_type", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "租赁物品种类不能为空")
private Integer rentalItemsType;
@Schema(description = "租赁数量", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "租赁数量不能为空")
private Integer number;
@Schema(description = "类型 | 1租借 2归还", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "类型不能为空")
private Integer type;
}

View File

@ -3,19 +3,16 @@ 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 java.util.HashMap;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@ -33,8 +30,11 @@ public class RentalDepositRecordApiImpl implements RentalDepositRecordApi {
}
@Override
public CommonResult<BigDecimal> getRecordAmount(String orderNo) {
public CommonResult<Map<String, BigDecimal>> getRecordAmount(String orderNo) {
RentalDepositAmountReqVO reqVO = rentalDepositRecordService.getRentalDepositRecordAmount(orderNo, false);
return success(reqVO.getReceivedAmount());
Map<String, BigDecimal> result = new HashMap<>();
result.put("receivedAmount", reqVO.getReceivedAmount());
result.put("refundAmount", reqVO.getRefundAmount());
return success(result);
}
}

View File

@ -0,0 +1,28 @@
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.RentalItemsRecordDTO;
import cn.iocoder.yudao.module.system.controller.admin.rental.vo.itemsrecord.RentalItemsRecordSaveReqVO;
import cn.iocoder.yudao.module.system.service.rental.RentalItemsRecordService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@RestController // 提供 RESTful API 接口 Feign 调用
@Validated
public class RentalItemsRecordApiImpl implements RentalItemsRecordApi {
@Resource
private RentalItemsRecordService rentalItemsRecordService;
@Override
public CommonResult<Boolean> create(List<RentalItemsRecordDTO> createReqVO) {
rentalItemsRecordService.createRentalItemsRecordBath(BeanUtils.toBean(createReqVO, RentalItemsRecordSaveReqVO.class));
return success(true);
}
}

View File

@ -3,7 +3,7 @@ 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.dal.dataobject.rental.RentalOrderDO;
import cn.iocoder.yudao.module.system.service.rental.RentalOrderService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;
@ -21,7 +21,13 @@ public class RentalOrderApiImpl implements RentalOrderApi {
@Override
public CommonResult<Boolean> updateOrder(RentalOrderDTO updateReqVO) {
rentalOrderService.update(BeanUtils.toBean(updateReqVO, RentalOrderSaveReqVO.class));
rentalOrderService.update(BeanUtils.toBean(updateReqVO, RentalOrderDO.class));
return success(true);
}
@Override
public CommonResult<RentalOrderDTO> getOrder(String orderNo) {
RentalOrderDO rentalOrder = rentalOrderService.getRentalOrder(orderNo);
return success(BeanUtils.toBean(rentalOrder, RentalOrderDTO.class));
}
}

View File

@ -1,11 +1,11 @@
package cn.iocoder.yudao.module.system.controller.admin.rental;
import cn.hutool.core.collection.CollectionUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.bpm.api.oa.BpmOARefundApi;
import cn.iocoder.yudao.module.bpm.api.oa.vo.BpmOARefundDTO;
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;
@ -23,14 +23,14 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
@Tag(name = "管理后台 - 租赁订单")
@ -48,6 +48,9 @@ public class RentalOrderController {
@Resource
private RentalDepositRecordService rentalDepositRecordService;
@Resource
private BpmOARefundApi refundApi;
@PostMapping("/create")
@Operation(summary = "创建租赁订单")
@PreAuthorize("@ss.hasPermission('system:rental-order:create')")
@ -103,6 +106,22 @@ public class RentalOrderController {
@PreAuthorize("@ss.hasPermission('system:rental-order:query')")
public CommonResult<PageResult<RentalOrderRespVO>> getRentalOrderPage(@Valid RentalOrderPageReqVO pageReqVO) {
PageResult<RentalOrderRespVO> pageResult = rentalOrderService.getRentalOrderPage(pageReqVO);
// 获取等待退款的订单号
List<String> orderNos = pageResult.getList().stream()
.filter(item -> Objects.equals(item.getStatus(), RentalOrderDO.WAITING_FOR_REFUND))
.map(RentalOrderRespVO::getOrderNo)
.collect(Collectors.toList());
// 获取订单号对应的退款申请
Map<String, BpmOARefundDTO> refundMap = refundApi.getListByOrderNo(orderNos).getCheckedData();
if (CollectionUtil.isNotEmpty(refundMap)) {
// 设置对应的订单号中的 申请退款和扣款金额
pageResult.getList().forEach(item -> {
item.setApplyRefundAmount(refundMap.get(item.getOrderNo()).getRefundAmount());
item.setApplyChargebacksAmount(refundMap.get(item.getOrderNo()).getChargebacksAmount());
});
}
return success(pageResult);
}
}

View File

@ -43,6 +43,12 @@ public class RentalOrderRespVO {
@Schema(description = "扣款金额")
private BigDecimal chargebacksAmount;
@Schema(description = "申请退款金额")
private BigDecimal applyRefundAmount;
@Schema(description = "申请扣款金额")
private BigDecimal applyChargebacksAmount;
@Schema(description = "备注")
private String notes;

View File

@ -40,6 +40,9 @@ public class RentalDepositRecordSaveReqVO {
@NotNull(message = "收款/退款金额不能为空")
private BigDecimal amount;
@Schema(description = "扣款金额")
private BigDecimal chargebacksAmount;
@Schema(description = "收款/退款日期", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "收款/退款日期不能为空")
private LocalDate paymentDate;

View File

@ -1,13 +1,11 @@
package cn.iocoder.yudao.module.system.dal.dataobject.rental;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
import java.math.BigDecimal;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
/**
* 租赁订单 DO
@ -23,6 +21,23 @@ import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
@AllArgsConstructor
public class RentalOrderDO extends BaseDO {
/**
* 状态 1 租赁中
*/
public static final Integer ON_LEASE = 1;
/**
* 状态 2 退款申请中
*/
public static final Integer REFUND_REQUESTED = 2;
/**
* 状态 3 等待退款中
*/
public static final Integer WAITING_FOR_REFUND = 3;
/**
* 状态 4 已退款
*/
public static final Integer REFUNDED = 4;
/**
* 租赁订单表单主键
*/

View File

@ -1,10 +1,7 @@
package cn.iocoder.yudao.module.system.framework.rpc.config;
import cn.iocoder.yudao.module.bpm.api.model.BpmModelApi;
import cn.iocoder.yudao.module.bpm.api.oa.BpmOAEntryApi;
import cn.iocoder.yudao.module.bpm.api.oa.BpmOAEvectionApi;
import cn.iocoder.yudao.module.bpm.api.oa.BpmOAGoOutApi;
import cn.iocoder.yudao.module.bpm.api.oa.BpmOAReplacementCardApi;
import cn.iocoder.yudao.module.bpm.api.oa.*;
import cn.iocoder.yudao.module.infra.api.config.ConfigApi;
import cn.iocoder.yudao.module.infra.api.file.FileApi;
import cn.iocoder.yudao.module.infra.api.websocket.WebSocketSenderApi;
@ -14,6 +11,6 @@ import org.springframework.context.annotation.Configuration;
@Configuration(proxyBeanMethods = false)
@EnableFeignClients(clients = {FileApi.class, WebSocketSenderApi.class, FactoryInfoApi.class, BpmModelApi.class, BpmOAGoOutApi.class, BpmOAEntryApi.class, ConfigApi.class,
BpmOAEvectionApi.class, BpmOAReplacementCardApi.class})
BpmOAEvectionApi.class, BpmOAReplacementCardApi.class, BpmOARefundApi.class})
public class RpcConfiguration {
}

View File

@ -3,14 +3,17 @@ package cn.iocoder.yudao.module.system.service.rental;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.UploadUserFile;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.bpm.api.oa.BpmOARefundApi;
import cn.iocoder.yudao.module.infra.api.file.FileApi;
import cn.iocoder.yudao.module.system.controller.admin.rental.vo.rentaldepositrecord.RentalDepositAmountReqVO;
import cn.iocoder.yudao.module.system.controller.admin.rental.vo.rentaldepositrecord.RentalDepositRecordPageReqVO;
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.dal.dataobject.rental.RentalOrderDO;
import cn.iocoder.yudao.module.system.dal.mysql.rental.RentalDepositRecordMapper;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
@ -40,7 +43,11 @@ public class RentalDepositRecordServiceImpl implements RentalDepositRecordServic
@Resource
private FileApi fileApi;
@Resource
private BpmOARefundApi refundApi;
@Override
@Transactional(rollbackFor = Exception.class)
public Long createRentalDepositRecord(RentalDepositRecordSaveReqVO createReqVO) {
// 获取当前订单的 剩余押金金额
@ -60,11 +67,25 @@ public class RentalDepositRecordServiceImpl implements RentalDepositRecordServic
}
break;
case 2:
RentalOrderDO updateOrder = new RentalOrderDO();
// 押金退款
// 判断当前退款金额 大于 实际已收的金额时
if (amount.compareTo(createReqVO.getAmount()) < 0) {
// 判断当前退款金额 + 扣款金额 大于 剩余已收金额时
BigDecimal refundAmount = createReqVO.getAmount().add(createReqVO.getChargebacksAmount() == null ? BigDecimal.ZERO : createReqVO.getChargebacksAmount());
if (amount.compareTo(refundAmount) < 0) {
throw exception(RENTAL_REFUND_AMOUNT_EXCESS);
} else if (amount.compareTo(refundAmount) == 0) { // 判断当前退款金额 是否等于 实际已收的金额 - 扣款金额时
// 更新订单状态为 已退款
updateOrder.setOrderNo(createReqVO.getOrderNo());
updateOrder.setStatus(RentalOrderDO.REFUNDED);
}else { // 判断当前退款金额 是否小于 实际已收的金额 - 扣款金额时
// 更新订单状态为 租赁中
updateOrder.setOrderNo(createReqVO.getOrderNo());
updateOrder.setStatus(RentalOrderDO.ON_LEASE);
}
// 同步更新 退款申请流程中的 退款状态
refundApi.updateStatus(createReqVO.getOrderNo());
// 同步更新 租赁订单状态
rentalOrderService.update(updateOrder);
break;
}

View File

@ -35,7 +35,7 @@ public interface RentalOrderService {
* 更新租赁订单
* @param updateReqVO 更新信息
*/
void update(RentalOrderSaveReqVO updateReqVO);
void update(RentalOrderDO updateReqVO);
/**
* 删除租赁订单
@ -52,6 +52,14 @@ public interface RentalOrderService {
*/
RentalOrderDO getRentalOrder(Long id);
/**
* 获得租赁订单
*
* @param orderNo 订单编号
* @return 租赁订单
*/
RentalOrderDO getRentalOrder(String orderNo);
/**
* 获得租赁订单分页
*

View File

@ -10,8 +10,6 @@ import cn.iocoder.yudao.module.system.controller.admin.rental.vo.order.RentalOrd
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;
@ -26,7 +24,6 @@ import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@ -119,15 +116,14 @@ public class RentalOrderServiceImpl implements RentalOrderService {
}
@Override
public void update(RentalOrderSaveReqVO updateReqVO) {
public void update(RentalOrderDO 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>()
rentalOrderMapper.update(updateReqVO, new LambdaQueryWrapperX<RentalOrderDO>()
.eq(RentalOrderDO::getOrderNo, updateReqVO.getOrderNo()));
}
@ -147,9 +143,16 @@ public class RentalOrderServiceImpl implements RentalOrderService {
@Override
public RentalOrderDO getRentalOrder(Long id) {
return rentalOrderMapper.selectById(id);
}
@Override
public RentalOrderDO getRentalOrder(String orderNo) {
return rentalOrderMapper.selectOne(RentalOrderDO::getOrderNo, orderNo);
}
@Override
public PageResult<RentalOrderRespVO> getRentalOrderPage(RentalOrderPageReqVO pageReqVO) {
return rentalOrderMapper.selectPage(pageReqVO);
@ -158,7 +161,7 @@ public class RentalOrderServiceImpl implements RentalOrderService {
@Override
@Cacheable(value = RedisKeyConstants.RENTAL_ORDER_AMOUNT, key = "#orderNo", unless = "#result == null")
public BigDecimal getOrderAmount(String orderNo) {
return rentalOrderMapper.selectOrderAmount(orderNo);
}
}

View File

@ -19,6 +19,8 @@
WHERE
order_no = #{orderNo}
AND deleted = 0
GROUP BY
rental_items_type
<if test="isUpdate">
FOR UPDATE
</if>