6 changed files with 292 additions and 0 deletions
-
34yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/common/CrmAuditStatusEnum.java
-
115yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/dataobject/contract/CrmContractDO.java
-
14yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/mysql/contract/CrmContractMapper.java
-
21yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/contract/CrmContractService.java
-
76yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/contract/CrmContractServiceImpl.java
-
32yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/contract/listener/CrmContractStatusListener.java
@ -0,0 +1,34 @@ |
|||||
|
package cn.iocoder.yudao.module.bpm.enums.common; |
||||
|
|
||||
|
import cn.iocoder.yudao.framework.common.core.ArrayValuable; |
||||
|
import lombok.Getter; |
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
|
||||
|
import java.util.Arrays; |
||||
|
|
||||
|
/** |
||||
|
* CRM 的审批状态 |
||||
|
* |
||||
|
* @author 赤焰 |
||||
|
*/ |
||||
|
@RequiredArgsConstructor |
||||
|
@Getter |
||||
|
public enum CrmAuditStatusEnum implements ArrayValuable<Integer> { |
||||
|
|
||||
|
DRAFT(0, "未提交"), |
||||
|
PROCESS(10, "审批中"), |
||||
|
APPROVE(20, "审核通过"), |
||||
|
REJECT(30, "审核不通过"), |
||||
|
CANCEL(40, "已取消"); |
||||
|
|
||||
|
private final Integer status; |
||||
|
private final String name; |
||||
|
|
||||
|
public static final Integer[] ARRAYS = Arrays.stream(values()).map(CrmAuditStatusEnum::getStatus).toArray(Integer[]::new); |
||||
|
|
||||
|
@Override |
||||
|
public Integer[] array() { |
||||
|
return ARRAYS; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,115 @@ |
|||||
|
package cn.iocoder.yudao.module.bpm.dal.dataobject.contract; |
||||
|
|
||||
|
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
||||
|
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; |
||||
|
|
||||
|
/** |
||||
|
* CRM 合同 DO |
||||
|
* |
||||
|
* @author dhb52 |
||||
|
*/ |
||||
|
@TableName("crm_contract") |
||||
|
@KeySequence("crm_contract_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 |
||||
|
@Data |
||||
|
@EqualsAndHashCode(callSuper = true) |
||||
|
@ToString(callSuper = true) |
||||
|
@Builder |
||||
|
@NoArgsConstructor |
||||
|
@AllArgsConstructor |
||||
|
public class CrmContractDO extends BaseDO { |
||||
|
|
||||
|
/** |
||||
|
* 合同编号 |
||||
|
*/ |
||||
|
@TableId |
||||
|
private Long id; |
||||
|
/** |
||||
|
* 合同名称 |
||||
|
*/ |
||||
|
private String name; |
||||
|
/** |
||||
|
* 合同编号 |
||||
|
*/ |
||||
|
private String no; |
||||
|
/** |
||||
|
* 客户编号 |
||||
|
* |
||||
|
*/ |
||||
|
private Long customerId; |
||||
|
/** |
||||
|
* 商机编号,非必须 |
||||
|
* |
||||
|
*/ |
||||
|
private Long businessId; |
||||
|
|
||||
|
/** |
||||
|
* 最后跟进时间 |
||||
|
*/ |
||||
|
private LocalDateTime contactLastTime; |
||||
|
|
||||
|
/** |
||||
|
* 负责人的用户编号 |
||||
|
* |
||||
|
* 关联 AdminUserDO 的 id 字段 |
||||
|
*/ |
||||
|
private Long ownerUserId; |
||||
|
|
||||
|
/** |
||||
|
* 工作流编号 |
||||
|
* |
||||
|
* 关联 ProcessInstance 的 id 属性 |
||||
|
*/ |
||||
|
private String processInstanceId; |
||||
|
/** |
||||
|
* 审批状态 |
||||
|
* |
||||
|
*/ |
||||
|
private Integer auditStatus; |
||||
|
|
||||
|
/** |
||||
|
* 下单日期 |
||||
|
*/ |
||||
|
private LocalDateTime orderDate; |
||||
|
/** |
||||
|
* 开始时间 |
||||
|
*/ |
||||
|
private LocalDateTime startTime; |
||||
|
/** |
||||
|
* 结束时间 |
||||
|
*/ |
||||
|
private LocalDateTime endTime; |
||||
|
/** |
||||
|
* 产品总金额,单位:元 |
||||
|
*/ |
||||
|
private BigDecimal totalProductPrice; |
||||
|
/** |
||||
|
* 整单折扣 |
||||
|
*/ |
||||
|
private BigDecimal discountPercent; |
||||
|
/** |
||||
|
* 合同总金额,单位:分 |
||||
|
*/ |
||||
|
private BigDecimal totalPrice; |
||||
|
/** |
||||
|
* 客户签约人,非必须 |
||||
|
* |
||||
|
*/ |
||||
|
private Long signContactId; |
||||
|
/** |
||||
|
* 公司签约人,非必须 |
||||
|
* |
||||
|
* 关联 AdminUserDO 的 id 字段 |
||||
|
*/ |
||||
|
private Long signUserId; |
||||
|
/** |
||||
|
* 备注 |
||||
|
*/ |
||||
|
private String remark; |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,14 @@ |
|||||
|
package cn.iocoder.yudao.module.bpm.dal.mysql.contract; |
||||
|
|
||||
|
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
||||
|
import cn.iocoder.yudao.module.bpm.dal.dataobject.contract.CrmContractDO; |
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
/** |
||||
|
* CRM 合同 Mapper |
||||
|
* |
||||
|
* @author dhb52 |
||||
|
*/ |
||||
|
@Mapper |
||||
|
public interface CrmContractMapper extends BaseMapperX<CrmContractDO> { |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,21 @@ |
|||||
|
package cn.iocoder.yudao.module.bpm.service.contract; |
||||
|
|
||||
|
|
||||
|
import java.util.Collection; |
||||
|
|
||||
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; |
||||
|
|
||||
|
/** |
||||
|
* CRM 合同 Service 接口 |
||||
|
* |
||||
|
* @author dhb52 |
||||
|
*/ |
||||
|
public interface CrmContractService { |
||||
|
/** |
||||
|
* 更新合同流程审批结果 |
||||
|
* |
||||
|
* @param id 合同编号 |
||||
|
* @param bpmResult BPM 审批结果 |
||||
|
*/ |
||||
|
void updateContractAuditStatus(Long id, Integer bpmResult); |
||||
|
} |
||||
@ -0,0 +1,76 @@ |
|||||
|
package cn.iocoder.yudao.module.bpm.service.contract; |
||||
|
|
||||
|
|
||||
|
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.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.transaction.annotation.Transactional; |
||||
|
import org.springframework.validation.annotation.Validated; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
||||
|
import cn.iocoder.yudao.module.bpm.dal.dataobject.contract.CrmContractDO; |
||||
|
import cn.iocoder.yudao.module.bpm.dal.mysql.contract.CrmContractMapper; |
||||
|
|
||||
|
/** |
||||
|
* CRM 合同 Service 实现类 |
||||
|
* |
||||
|
* @author dhb52 |
||||
|
*/ |
||||
|
@Service |
||||
|
@Validated |
||||
|
@Slf4j |
||||
|
public class CrmContractServiceImpl implements CrmContractService { |
||||
|
|
||||
|
/** |
||||
|
* BPM 合同审批流程标识 |
||||
|
*/ |
||||
|
public static final String BPM_PROCESS_DEFINITION_KEY = "crm-contract-audit"; |
||||
|
|
||||
|
@Resource |
||||
|
private CrmContractMapper contractMapper; |
||||
|
|
||||
|
@Resource |
||||
|
private AdminUserApi adminUserApi; |
||||
|
@Resource |
||||
|
private BpmProcessInstanceApi bpmProcessInstanceApi; |
||||
|
|
||||
|
@Override |
||||
|
public void updateContractAuditStatus(Long id, Integer bpmResult) { |
||||
|
// 1.1 校验合同是否存在 |
||||
|
CrmContractDO contract = validateContractExists(id); |
||||
|
// 1.2 只有审批中,可以更新审批结果 |
||||
|
if (ObjUtil.notEqual(contract.getAuditStatus(), CrmAuditStatusEnum.PROCESS.getStatus())) { |
||||
|
log.error("[updateContractAuditStatus][contract({}) 不处于审批中,无法更新审批结果({})]", |
||||
|
contract.getId(), bpmResult); |
||||
|
throw exception(new ErrorCode(1_020_000_003, "更新合同审核状态失败,原因:合同不是审核中状态")); |
||||
|
} |
||||
|
|
||||
|
// 2. 更新合同审批结果 |
||||
|
Integer auditStatus = convertBpmResultToAuditStatus(bpmResult); |
||||
|
contractMapper.updateById(new CrmContractDO().setId(id).setAuditStatus(auditStatus)); |
||||
|
} |
||||
|
|
||||
|
private CrmContractDO validateContractExists(Long id) { |
||||
|
CrmContractDO contract = contractMapper.selectById(id); |
||||
|
if (contract == null) { |
||||
|
throw exception(new ErrorCode(1_020_000_000, "合同不存在")); |
||||
|
} |
||||
|
return contract; |
||||
|
} |
||||
|
|
||||
|
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.contract.listener; |
||||
|
|
||||
|
import cn.iocoder.yudao.module.bpm.event.BpmProcessInstanceStatusEvent; |
||||
|
import cn.iocoder.yudao.module.bpm.event.BpmProcessInstanceStatusEventListener; |
||||
|
import cn.iocoder.yudao.module.bpm.service.contract.CrmContractService; |
||||
|
import cn.iocoder.yudao.module.bpm.service.contract.CrmContractServiceImpl; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
|
||||
|
/** |
||||
|
* 合同审批的结果的监听器实现类 |
||||
|
* |
||||
|
* @author HUIHUI |
||||
|
*/ |
||||
|
@Component |
||||
|
public class CrmContractStatusListener extends BpmProcessInstanceStatusEventListener { |
||||
|
|
||||
|
@Resource |
||||
|
private CrmContractService contractService; |
||||
|
|
||||
|
@Override |
||||
|
public String getProcessDefinitionKey() { |
||||
|
return CrmContractServiceImpl.BPM_PROCESS_DEFINITION_KEY; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
protected void onEvent(BpmProcessInstanceStatusEvent event) { |
||||
|
contractService.updateContractAuditStatus(Long.parseLong(event.getBusinessKey()), event.getStatus()); |
||||
|
} |
||||
|
|
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue