feat(bpm): 添加 OA 退款申请功能
- 新增退款申请相关的数据结构和接口 - 实现退款申请的创建、查询和结果更新功能 - 添加退款申请的监听器,用于处理流程实例结果事件 - 定义退款申请相关的错误码
This commit is contained in:
parent
4e22e93913
commit
b8da3af92d
@ -57,6 +57,8 @@ public interface ErrorCodeConstants {
|
||||
ErrorCode OA_EVECTION_IS_EXISTS = new ErrorCode(1_009_001_120, "该时间段您正在出差!请重新选择正确出差时间。");
|
||||
ErrorCode OA_INVOICE_NOT_EXISTS = new ErrorCode(1_009_001_121, "开票申请不存在");
|
||||
ErrorCode OA_REPLACEMENT_CARD_NOT_EXISTS = new ErrorCode(1_009_001_122, "补卡申请不存在");
|
||||
ErrorCode OA_REFUND_CARD_NOT_EXISTS = new ErrorCode(1_009_001_123, "退款申请不存在");
|
||||
|
||||
|
||||
// ========== 流程模型 1-009-002-000 ==========
|
||||
ErrorCode MODEL_KEY_EXISTS = new ErrorCode(1_009_002_000, "已经存在流程标识为【{}】的流程");
|
||||
|
@ -0,0 +1,62 @@
|
||||
package cn.iocoder.yudao.module.bpm.controller.admin.oa;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.refund.BpmOARefundCreateReqVO;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.refund.BpmOARefundRespVO;
|
||||
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOARefundDO;
|
||||
import cn.iocoder.yudao.module.bpm.service.oa.BpmOARefundService;
|
||||
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.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
|
||||
/**
|
||||
* OA 退款申请 Controller
|
||||
*
|
||||
* @author 符溶馨
|
||||
|
||||
*/
|
||||
@Tag(name = "管理后台 - OA 退款申请")
|
||||
@RestController
|
||||
@RequestMapping("/bpm/oa/refund")
|
||||
@Validated
|
||||
public class BpmOARefundController {
|
||||
|
||||
@Resource
|
||||
private BpmOARefundService refundService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建请求申请")
|
||||
public CommonResult<Long> createRefund(@Valid @RequestBody BpmOARefundCreateReqVO createReqVO) {
|
||||
|
||||
return success(refundService.createRefund(getLoginUserId(), createReqVO));
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得退款申请")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
public CommonResult<BpmOARefundRespVO> getRefund(@RequestParam("id") Long id) {
|
||||
|
||||
BpmOARefundDO refund = refundService.getRefund(id);
|
||||
|
||||
return success(BeanUtils.toBean(refund, BpmOARefundRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/getByProcessInstanceId")
|
||||
@Operation(summary = "获得退款申请")
|
||||
@Parameter(name = "processInstanceId", description = "流程实例编号", required = true, example = "1024")
|
||||
public CommonResult<BpmOARefundRespVO> getByProcessInstanceId(@RequestParam("processInstanceId") String processInstanceId) {
|
||||
|
||||
BpmOARefundDO refund = refundService.getByProcessInstanceId(processInstanceId);
|
||||
|
||||
return success(BeanUtils.toBean(refund, BpmOARefundRespVO.class));
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.refund;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.UploadUserFile;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 退款申请 创建 Request VO
|
||||
*
|
||||
* @author 符溶馨
|
||||
*/
|
||||
@Schema(description = "管理后台 - 退款申请创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode()
|
||||
@ToString(callSuper = true)
|
||||
public class BpmOARefundCreateReqVO {
|
||||
|
||||
@Schema(description = "订单编号", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "订单编号不能为空")
|
||||
private String orderNo;
|
||||
|
||||
@Schema(description = "归还物品明细", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
|
||||
@NotNull(message = "归还物品明细不能为空")
|
||||
private List<BpmOARefundItems> refundItems;
|
||||
|
||||
@Schema(description = "扣款金额")
|
||||
private BigDecimal chargebacksAmount;
|
||||
|
||||
@Schema(description = "退款金额", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
|
||||
@NotNull(message = "退款金额不能为空")
|
||||
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 = "流程实例编号")
|
||||
private String processInstanceId;
|
||||
|
||||
@Schema(description = "状态-参见 bpm_process_instance_result 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Integer result;
|
||||
|
||||
@Schema(description = "上传文件", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private List<UploadUserFile> fileItems;
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.refund;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Schema(description = "管理后台 - 退款申请 归还物品明细 Request VO")
|
||||
@Data
|
||||
public class BpmOARefundItems {
|
||||
|
||||
@Schema(description = "租赁物品类型")
|
||||
private Integer rentalItemsType;
|
||||
|
||||
@Schema(description = "归还数量")
|
||||
private Integer number;
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.refund;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.UploadUserFile;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.BpmOABaseRespVO;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
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
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class BpmOARefundRespVO extends BpmOABaseRespVO {
|
||||
|
||||
@Schema(description = "订单编号", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "订单编号不能为空")
|
||||
private String orderNo;
|
||||
|
||||
@Schema(description = "归还物品明细", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
|
||||
@NotNull(message = "归还物品明细不能为空")
|
||||
private List<BpmOARefundItems> refundItems;
|
||||
|
||||
@Schema(description = "扣款金额")
|
||||
private BigDecimal chargebacksAmount;
|
||||
|
||||
@Schema(description = "退款金额", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
|
||||
@NotNull(message = "退款金额不能为空")
|
||||
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;
|
||||
}
|
@ -1,10 +1,19 @@
|
||||
package cn.iocoder.yudao.module.bpm.dal.dataobject.oa;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.UploadUserFile;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.refund.BpmOARefundItems;
|
||||
import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||
import lombok.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* OA 转正申请 DO
|
||||
*
|
||||
@ -33,6 +42,53 @@ public class BpmOARefundDO extends BaseDO {
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 订单编号
|
||||
*/
|
||||
private String orderNo;
|
||||
|
||||
/**
|
||||
* 归还物品明细
|
||||
*/
|
||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||
private List<BpmOARefundItems> refundItems;
|
||||
|
||||
/**
|
||||
* 扣款金额
|
||||
*/
|
||||
private BigDecimal chargebacksAmount;
|
||||
|
||||
/**
|
||||
* 退款金额
|
||||
*/
|
||||
private BigDecimal refundAmount;
|
||||
|
||||
/**
|
||||
* 退款日期
|
||||
*/
|
||||
private LocalDate refundDate;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String notes;
|
||||
|
||||
/**
|
||||
* 结果
|
||||
* 枚举 {@link BpmProcessInstanceResultEnum}
|
||||
* 考虑到简单,所以直接复用了 BpmProcessInstanceResultEnum 枚举,也可以自己定义一个枚举哈
|
||||
*/
|
||||
private Integer result;
|
||||
|
||||
/**
|
||||
* 对应的流程编号
|
||||
* 关联 ProcessInstance 的 id 属性
|
||||
*/
|
||||
private String processInstanceId;
|
||||
|
||||
/**
|
||||
* 附件基本信息
|
||||
*/
|
||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||
private List<UploadUserFile> fileItems ;
|
||||
}
|
||||
|
@ -0,0 +1,9 @@
|
||||
package cn.iocoder.yudao.module.bpm.dal.mysql.oa;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOARefundDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface BpmOARefundMapper extends BaseMapperX<BpmOARefundDO> {
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package cn.iocoder.yudao.module.bpm.service.oa;
|
||||
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.oa.vo.refund.BpmOARefundCreateReqVO;
|
||||
import cn.iocoder.yudao.module.bpm.dal.dataobject.oa.BpmOARefundDO;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
public interface BpmOARefundService {
|
||||
|
||||
/**
|
||||
* 创建转正申请
|
||||
*
|
||||
* @param userId 用户编号
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createRefund(Long userId, @Valid BpmOARefundCreateReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新转正申请的状态
|
||||
*
|
||||
* @param id 编号
|
||||
* @param result 结果
|
||||
*/
|
||||
void updateRefundResult(String processInstanceId, Long id, Integer result);
|
||||
|
||||
/**
|
||||
* 获得转正申请
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 转正申请
|
||||
*/
|
||||
BpmOARefundDO getRefund(Long id);
|
||||
|
||||
/**
|
||||
* 获得指定的转正申请
|
||||
* @param processInstanceId 流程实例编号
|
||||
* @return 转正申请
|
||||
*/
|
||||
BpmOARefundDO getByProcessInstanceId(String processInstanceId);
|
||||
}
|
@ -0,0 +1,118 @@
|
||||
package cn.iocoder.yudao.module.bpm.service.oa;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.UploadUserFile;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
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.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 org.flowable.engine.runtime.ProcessInstance;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
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_CARD_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* OA 转正申请 Service 实现类
|
||||
*
|
||||
* @author 符溶馨
|
||||
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class BpmOARefundServiceImpl extends BpmOABaseService implements BpmOARefundService{
|
||||
|
||||
/**
|
||||
* OA 转正对应的流程定义 KEY
|
||||
*/
|
||||
public static final String PROCESS_KEY = "oa_refund_2";
|
||||
|
||||
@Resource
|
||||
private BpmOARefundMapper refundMapper;
|
||||
|
||||
@Resource
|
||||
private BpmProcessInstanceApi processInstanceApi;
|
||||
|
||||
@Resource
|
||||
private BpmHistoryProcessInstanceService historyProcessInstanceService;
|
||||
|
||||
@Resource
|
||||
private BpmProcessInstanceService bpmProcessInstanceService;
|
||||
|
||||
@Override
|
||||
public Long createRefund(Long userId, BpmOARefundCreateReqVO createReqVO) {
|
||||
|
||||
//插入OA 转正申请
|
||||
BpmOARefundDO refund = BeanUtils.toBean(createReqVO, BpmOARefundDO.class)
|
||||
.setUserId(userId)
|
||||
.setResult(BpmProcessInstanceResultEnum.PROCESS.getResult());
|
||||
refundMapper.insert(refund) ;
|
||||
|
||||
// 发起 BPM 流程
|
||||
Map<String, Object> processInstanceVariables = new HashMap<>();
|
||||
String processInstanceId = processInstanceApi.createProcessInstance(userId,
|
||||
new BpmProcessInstanceCreateReqDTO().setProcessDefinitionKey(PROCESS_KEY)
|
||||
.setVariables(processInstanceVariables).setBusinessKey(String.valueOf(refund.getId()))).getCheckedData();
|
||||
|
||||
// 将工作流的编号,更新到 OA 转正单中
|
||||
refundMapper.updateById(new BpmOARefundDO().setId(refund.getId()).setProcessInstanceId(processInstanceId));
|
||||
|
||||
// 判断是否为重新发起的流程
|
||||
if (createReqVO.getProcessInstanceId() != null && createReqVO.getResult() == 3) {
|
||||
|
||||
historyProcessInstanceService.createHistoryProcessInstance(processInstanceId, createReqVO.getProcessInstanceId());
|
||||
}
|
||||
|
||||
List<UploadUserFile> fileItems = createReqVO.getFileItems() ;
|
||||
//这里的逻辑,如果fileItems不为空,且有数据,那么说明是上传了附件的,则需要更工作流文件表对应的实例Id
|
||||
if (fileItems != null && !fileItems.isEmpty()) {
|
||||
uploadBpmFileProcessInstanceId(processInstanceId,fileItems) ;
|
||||
}
|
||||
return refund.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateRefundResult(String processInstanceId, Long id, Integer result) {
|
||||
|
||||
validateLeaveExists(id);
|
||||
//审核通过 (最后节点)
|
||||
if (BpmProcessInstanceResultEnum.APPROVE.getResult().equals(result)) {
|
||||
|
||||
ProcessInstance instance = bpmProcessInstanceService.getProcessInstance(processInstanceId);
|
||||
|
||||
if (instance.isEnded()) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
refundMapper.updateById(new BpmOARefundDO().setId(id).setResult(result));
|
||||
}
|
||||
|
||||
private void validateLeaveExists(Long id) {
|
||||
if (refundMapper.selectById(id) == null) {
|
||||
throw exception(OA_REFUND_CARD_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BpmOARefundDO getRefund(Long id) {
|
||||
|
||||
return refundMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BpmOARefundDO getByProcessInstanceId(String processInstanceId) {
|
||||
|
||||
return refundMapper.selectOne(BpmOARefundDO::getProcessInstanceId, processInstanceId);
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package cn.iocoder.yudao.module.bpm.service.oa.listener;
|
||||
|
||||
import cn.iocoder.yudao.module.bpm.framework.bpm.core.event.BpmProcessInstanceResultEvent;
|
||||
import cn.iocoder.yudao.module.bpm.framework.bpm.core.event.BpmProcessInstanceResultEventListener;
|
||||
import cn.iocoder.yudao.module.bpm.service.oa.BpmOARefundService;
|
||||
import cn.iocoder.yudao.module.bpm.service.oa.BpmOARefundServiceImpl;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* OA 转正单的结果的监听器实现类
|
||||
*
|
||||
* @author 符溶馨
|
||||
*/
|
||||
@Component
|
||||
public class BpmOARefundResultListener extends BpmProcessInstanceResultEventListener {
|
||||
|
||||
@Resource
|
||||
private BpmOARefundService refundService;
|
||||
|
||||
@Override
|
||||
protected String getProcessDefinitionKey() {
|
||||
|
||||
return BpmOARefundServiceImpl.PROCESS_KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEvent(BpmProcessInstanceResultEvent event) {
|
||||
refundService.updateRefundResult(event.getId(), Long.parseLong(event.getBusinessKey()), event.getResult());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user