1.0.19 提交合同信息并提交流程、合同流程监听

dev
yinq 2 months ago
parent 02ff40fe97
commit 66099d81ef

@ -0,0 +1,77 @@
package org.dromara.common.core.enums;
import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.utils.StringUtils;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* OA
*
* @author may
*/
@Getter
@AllArgsConstructor
public enum OAStatusEnum {
/**
*
*/
DRAFT("1", "暂存"),
/**
*
*/
APPROVING("2", "审批中"),
/**
*
*/
COMPLETED("3", "可用");
/**
*
*/
private final String status;
/**
*
*/
private final String desc;
private static final Map<String, OAStatusEnum> STATUS_MAP = Arrays.stream(OAStatusEnum.values())
.collect(Collectors.toConcurrentMap(OAStatusEnum::getStatus, Function.identity()));
/**
* BusinessStatusEnum
*
* @param status
* @return BusinessStatusEnum null
*/
public static OAStatusEnum getByStatus(String status) {
// 使用 STATUS_MAP 获取对应的枚举,若找不到则返回 null
return STATUS_MAP.get(status);
}
/**
*
*
* @param status
* @return
*/
public static String findByStatus(String status) {
if (StringUtils.isBlank(status)) {
return StrUtil.EMPTY;
}
OAStatusEnum statusEnum = STATUS_MAP.get(status);
return (statusEnum != null) ? statusEnum.getDesc() : StrUtil.EMPTY;
}
}

@ -105,6 +105,11 @@
<artifactId>ruoyi-api-workflow</artifactId> <artifactId>ruoyi-api-workflow</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.dromara</groupId>
<artifactId>ruoyi-common-bus</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>

@ -1,7 +1,12 @@
package org.dromara.oa.erp.service.impl; package org.dromara.oa.erp.service.impl;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.map.MapUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.seata.spring.annotation.GlobalTransactional; import org.apache.seata.spring.annotation.GlobalTransactional;
import org.dromara.common.core.enums.BusinessStatusEnum;
import org.dromara.common.core.enums.OAStatusEnum;
import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StringUtils; import org.dromara.common.core.utils.StringUtils;
@ -11,10 +16,13 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.toolkit.JoinWrappers; import com.github.yulichang.toolkit.JoinWrappers;
import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.github.yulichang.wrapper.MPJLambdaWrapper;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.dromara.common.tenant.helper.TenantHelper;
import org.dromara.oa.erp.domain.ErpContractMaterial; import org.dromara.oa.erp.domain.ErpContractMaterial;
import org.dromara.oa.erp.mapper.ErpContractMaterialMapper; import org.dromara.oa.erp.mapper.ErpContractMaterialMapper;
import org.dromara.workflow.api.RemoteWorkflowService; import org.dromara.workflow.api.RemoteWorkflowService;
import org.dromara.workflow.api.domain.RemoteStartProcess; import org.dromara.workflow.api.domain.RemoteStartProcess;
import org.dromara.workflow.api.event.ProcessEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.dromara.oa.erp.domain.bo.ErpContractInfoBo; import org.dromara.oa.erp.domain.bo.ErpContractInfoBo;
import org.dromara.oa.erp.domain.vo.ErpContractInfoVo; import org.dromara.oa.erp.domain.vo.ErpContractInfoVo;
@ -23,10 +31,7 @@ import org.dromara.oa.erp.mapper.ErpContractInfoMapper;
import org.dromara.oa.erp.service.IErpContractInfoService; import org.dromara.oa.erp.service.IErpContractInfoService;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.*;
import java.util.Map;
import java.util.Collection;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -37,6 +42,7 @@ import java.util.stream.Collectors;
*/ */
@RequiredArgsConstructor @RequiredArgsConstructor
@Service @Service
@Slf4j
public class ErpContractInfoServiceImpl implements IErpContractInfoService { public class ErpContractInfoServiceImpl implements IErpContractInfoService {
private final ErpContractInfoMapper baseMapper; private final ErpContractInfoMapper baseMapper;
@ -205,30 +211,47 @@ public class ErpContractInfoServiceImpl implements IErpContractInfoService {
public ErpContractInfoVo contractSubmitAndFlowStart(ErpContractInfoBo bo) { public ErpContractInfoVo contractSubmitAndFlowStart(ErpContractInfoBo bo) {
ErpContractInfo add = MapstructUtils.convert(bo, ErpContractInfo.class); ErpContractInfo add = MapstructUtils.convert(bo, ErpContractInfo.class);
validEntityBeforeSave(add); validEntityBeforeSave(add);
List<ErpContractMaterial> contractMaterialList = bo.getContractMaterialList(); if (StringUtils.isNull(bo.getContractId())) {
boolean flag = baseMapper.insert(add) > 0; this.insertByBo(bo);
if (flag && contractMaterialList != null && !contractMaterialList.isEmpty()) { } else {
bo.setContractId(add.getContractId()); this.updateByBo(bo);
for (ErpContractMaterial erpContractMaterial : contractMaterialList) {
erpContractMaterial.setContractId(add.getContractId());
contractMaterialMapper.insert(erpContractMaterial);
}
} }
if (flag) { // 后端发起需要忽略权限
// 后端发起需要忽略权限 bo.getVariables().put("ignore", true);
bo.getVariables().put("ignore", true); RemoteStartProcess startProcess = new RemoteStartProcess();
RemoteStartProcess startProcess = new RemoteStartProcess(); startProcess.setBusinessId(bo.getContractId().toString());
startProcess.setBusinessId(bo.getContractId().toString()); startProcess.setFlowCode(bo.getFlowCode());
startProcess.setFlowCode(bo.getFlowCode()); startProcess.setVariables(bo.getVariables());
startProcess.setVariables(bo.getVariables()); startProcess.setBizExt(bo.getBizExt());
startProcess.setBizExt(bo.getBizExt()); bo.getBizExt().setBusinessId(startProcess.getBusinessId());
bo.getBizExt().setBusinessId(startProcess.getBusinessId()); boolean flagOne = remoteWorkflowService.startCompleteTask(startProcess);
boolean flagOne = remoteWorkflowService.startCompleteTask(startProcess); if (!flagOne) {
if (!flagOne) { throw new ServiceException("流程发起异常");
throw new ServiceException("流程发起异常");
}
} }
return MapstructUtils.convert(add, ErpContractInfoVo.class); return MapstructUtils.convert(add, ErpContractInfoVo.class);
} }
/**
* (: 稿退)
*
* @param processEvent
*/
@EventListener(condition = "#processEvent.flowCode =='OAC'")
public void processHandler(ProcessEvent processEvent) {
TenantHelper.dynamic(processEvent.getTenantId(), () -> {
log.info("当前任务执行了{}", processEvent.toString());
ErpContractInfo contractInfo = baseMapper.selectById(Convert.toLong(processEvent.getBusinessId()));
contractInfo.setFlowStatus(processEvent.getStatus());
Map<String, Object> params = processEvent.getParams();
if (MapUtil.isNotEmpty(params)) {
// 办理人
String handler = Convert.toStr(params.get("handler"));
}
if (Objects.equals(processEvent.getStatus(), BusinessStatusEnum.FINISH.getStatus())) {
contractInfo.setContractStatus(OAStatusEnum.COMPLETED.getStatus());
}
baseMapper.updateById(contractInfo);
});
}
} }

Loading…
Cancel
Save