5 changed files with 231 additions and 0 deletions
-
87yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/dataobject/receivable/CrmReceivableDO.java
-
15yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/mysql/receivable/CrmReceivableMapper.java
-
18yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/receivable/CrmReceivableService.java
-
79yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/receivable/CrmReceivableServiceImpl.java
-
32yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/receivable/listener/CrmReceivableStatusListener.java
@ -0,0 +1,87 @@ |
|||
package cn.iocoder.yudao.module.bpm.dal.dataobject.receivable; |
|||
|
|||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
|||
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; |
|||
import com.baomidou.mybatisplus.annotation.KeySequence; |
|||
import com.baomidou.mybatisplus.annotation.TableId; |
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import lombok.*; |
|||
|
|||
import java.math.BigDecimal; |
|||
import java.time.LocalDateTime; |
|||
|
|||
/** |
|||
* 回款 DO |
|||
* |
|||
* @author 赤焰 |
|||
*/ |
|||
@TableName("crm_receivable") |
|||
@KeySequence("crm_receivable_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 |
|||
@Data |
|||
@EqualsAndHashCode(callSuper = true) |
|||
@ToString(callSuper = true) |
|||
@Builder |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
public class CrmReceivableDO extends BaseDO { |
|||
|
|||
/** |
|||
* ID |
|||
*/ |
|||
@TableId |
|||
private Long id; |
|||
/** |
|||
* 回款编号 |
|||
*/ |
|||
private String no; |
|||
/** |
|||
* 回款计划编号 |
|||
* |
|||
*/ |
|||
private Long planId; |
|||
/** |
|||
* 客户编号 |
|||
* |
|||
*/ |
|||
private Long customerId; |
|||
/** |
|||
* 合同编号 |
|||
* |
|||
*/ |
|||
private Long contractId; |
|||
/** |
|||
* 负责人编号,关联 {@link AdminUserRespDTO#getId()} |
|||
*/ |
|||
private Long ownerUserId; |
|||
|
|||
/** |
|||
* 回款日期 |
|||
*/ |
|||
private LocalDateTime returnTime; |
|||
/** |
|||
* 回款方式 |
|||
* |
|||
*/ |
|||
private Integer returnType; |
|||
/** |
|||
* 计划回款金额,单位:元 |
|||
*/ |
|||
private BigDecimal price; |
|||
/** |
|||
* 备注 |
|||
*/ |
|||
private String remark; |
|||
|
|||
/** |
|||
* 工作流编号 |
|||
* |
|||
* 关联 ProcessInstance 的 id 属性 |
|||
*/ |
|||
private String processInstanceId; |
|||
/** |
|||
* 审批状态 |
|||
* |
|||
*/ |
|||
private Integer auditStatus; |
|||
|
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
package cn.iocoder.yudao.module.bpm.dal.mysql.receivable; |
|||
|
|||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
|||
import cn.iocoder.yudao.module.bpm.dal.dataobject.receivable.CrmReceivableDO; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
|
|||
/** |
|||
* 回款 Mapper |
|||
* |
|||
* @author 赤焰 |
|||
*/ |
|||
@Mapper |
|||
public interface CrmReceivableMapper extends BaseMapperX<CrmReceivableDO> { |
|||
|
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
package cn.iocoder.yudao.module.bpm.service.receivable; |
|||
|
|||
|
|||
/** |
|||
* CRM 回款 Service 接口 |
|||
* |
|||
* @author 赤焰 |
|||
*/ |
|||
public interface CrmReceivableService { |
|||
|
|||
/** |
|||
* 更新回款流程审批结果 |
|||
* |
|||
* @param id 回款编号 |
|||
* @param bpmResult BPM 审批结果 |
|||
*/ |
|||
void updateReceivableAuditStatus(Long id, Integer bpmResult); |
|||
} |
|||
@ -0,0 +1,79 @@ |
|||
package cn.iocoder.yudao.module.bpm.service.receivable; |
|||
|
|||
import cn.hutool.core.lang.Assert; |
|||
import cn.hutool.core.util.ObjUtil; |
|||
import cn.iocoder.yudao.framework.common.exception.ErrorCode; |
|||
import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi; |
|||
import cn.iocoder.yudao.module.bpm.dal.dataobject.receivable.CrmReceivableDO; |
|||
import cn.iocoder.yudao.module.bpm.dal.mysql.receivable.CrmReceivableMapper; |
|||
import cn.iocoder.yudao.module.bpm.enums.common.CrmAuditStatusEnum; |
|||
import cn.iocoder.yudao.module.bpm.enums.task.BpmTaskStatusEnum; |
|||
import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.context.annotation.Lazy; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.validation.annotation.Validated; |
|||
import javax.annotation.Resource; |
|||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
|||
|
|||
|
|||
/** |
|||
* CRM 回款 Service 实现类 |
|||
* |
|||
* @author 赤焰 |
|||
*/ |
|||
@Service |
|||
@Validated |
|||
@Slf4j |
|||
public class CrmReceivableServiceImpl implements CrmReceivableService { |
|||
|
|||
/** |
|||
* BPM 合同审批流程标识 |
|||
*/ |
|||
public static final String BPM_PROCESS_DEFINITION_KEY = "crm-receivable-audit"; |
|||
|
|||
@Resource |
|||
private CrmReceivableMapper receivableMapper; |
|||
|
|||
@Resource |
|||
private AdminUserApi adminUserApi; |
|||
@Resource |
|||
private BpmProcessInstanceApi bpmProcessInstanceApi; |
|||
|
|||
@Override |
|||
public void updateReceivableAuditStatus(Long id, Integer bpmResult) { |
|||
// 1.1 校验存在 |
|||
CrmReceivableDO receivable = validateReceivableExists(id); |
|||
// 1.2 只有审批中,可以更新审批结果 |
|||
if (ObjUtil.notEqual(receivable.getAuditStatus(), CrmAuditStatusEnum.PROCESS.getStatus())) { |
|||
log.error("[updateReceivableAuditStatus][receivable({}) 不处于审批中,无法更新审批结果({})]", |
|||
receivable.getId(), bpmResult); |
|||
throw exception(new ErrorCode(1_020_004_004, "更新回款审核状态失败,原因:回款不是审核中状态")); |
|||
} |
|||
|
|||
// 2. 更新回款审批状态 |
|||
Integer auditStatus = convertBpmResultToAuditStatus(bpmResult); |
|||
receivableMapper.updateById(new CrmReceivableDO().setId(id).setAuditStatus(auditStatus)); |
|||
} |
|||
|
|||
private CrmReceivableDO validateReceivableExists(Long id) { |
|||
CrmReceivableDO receivable = receivableMapper.selectById(id); |
|||
if (receivable == null) { |
|||
throw exception(new ErrorCode(1_020_004_000, "回款不存在")); |
|||
} |
|||
return receivable; |
|||
} |
|||
|
|||
/** |
|||
* BPM 审批结果转换 |
|||
* |
|||
* @param bpmResult BPM 审批结果 |
|||
*/ |
|||
public static Integer convertBpmResultToAuditStatus(Integer bpmResult) { |
|||
Integer auditStatus = BpmTaskStatusEnum.APPROVE.getStatus().equals(bpmResult) ? CrmAuditStatusEnum.APPROVE.getStatus() |
|||
: BpmTaskStatusEnum.REJECT.getStatus().equals(bpmResult) ? CrmAuditStatusEnum.REJECT.getStatus() |
|||
: BpmTaskStatusEnum.CANCEL.getStatus().equals(bpmResult) ? BpmTaskStatusEnum.CANCEL.getStatus() : null; |
|||
Assert.notNull(auditStatus, "BPM 审批结果({}) 转换失败", bpmResult); |
|||
return auditStatus; |
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
package cn.iocoder.yudao.module.bpm.service.receivable.listener; |
|||
|
|||
import cn.iocoder.yudao.module.bpm.event.BpmProcessInstanceStatusEvent; |
|||
import cn.iocoder.yudao.module.bpm.event.BpmProcessInstanceStatusEventListener; |
|||
import cn.iocoder.yudao.module.bpm.service.receivable.CrmReceivableService; |
|||
import cn.iocoder.yudao.module.bpm.service.receivable.CrmReceivableServiceImpl; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import javax.annotation.Resource; |
|||
|
|||
/** |
|||
* 回款审批的结果的监听器实现类 |
|||
* |
|||
* @author HUIHUI |
|||
*/ |
|||
@Component |
|||
public class CrmReceivableStatusListener extends BpmProcessInstanceStatusEventListener { |
|||
|
|||
@Resource |
|||
private CrmReceivableService receivableService; |
|||
|
|||
@Override |
|||
public String getProcessDefinitionKey() { |
|||
return CrmReceivableServiceImpl.BPM_PROCESS_DEFINITION_KEY; |
|||
} |
|||
|
|||
@Override |
|||
public void onEvent(BpmProcessInstanceStatusEvent event) { |
|||
receivableService.updateReceivableAuditStatus(Long.parseLong(event.getBusinessKey()), event.getStatus()); |
|||
} |
|||
|
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue