diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/enums/OAStatusEnum.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/enums/OAStatusEnum.java new file mode 100644 index 00000000..957e93b9 --- /dev/null +++ b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/enums/OAStatusEnum.java @@ -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 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; + } + +} diff --git a/ruoyi-modules/ruoyi-oa/pom.xml b/ruoyi-modules/ruoyi-oa/pom.xml index ab199088..69f70aa8 100644 --- a/ruoyi-modules/ruoyi-oa/pom.xml +++ b/ruoyi-modules/ruoyi-oa/pom.xml @@ -105,6 +105,11 @@ ruoyi-api-workflow + + org.dromara + ruoyi-common-bus + + diff --git a/ruoyi-modules/ruoyi-oa/src/main/java/org/dromara/oa/erp/service/impl/ErpContractInfoServiceImpl.java b/ruoyi-modules/ruoyi-oa/src/main/java/org/dromara/oa/erp/service/impl/ErpContractInfoServiceImpl.java index d9d605f5..fa9c8263 100644 --- a/ruoyi-modules/ruoyi-oa/src/main/java/org/dromara/oa/erp/service/impl/ErpContractInfoServiceImpl.java +++ b/ruoyi-modules/ruoyi-oa/src/main/java/org/dromara/oa/erp/service/impl/ErpContractInfoServiceImpl.java @@ -1,7 +1,12 @@ 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.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.utils.MapstructUtils; 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.wrapper.MPJLambdaWrapper; import lombok.RequiredArgsConstructor; +import org.dromara.common.tenant.helper.TenantHelper; import org.dromara.oa.erp.domain.ErpContractMaterial; import org.dromara.oa.erp.mapper.ErpContractMaterialMapper; import org.dromara.workflow.api.RemoteWorkflowService; 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.dromara.oa.erp.domain.bo.ErpContractInfoBo; 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.springframework.transaction.annotation.Transactional; -import java.util.List; -import java.util.Map; -import java.util.Collection; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; /** @@ -37,6 +42,7 @@ import java.util.stream.Collectors; */ @RequiredArgsConstructor @Service +@Slf4j public class ErpContractInfoServiceImpl implements IErpContractInfoService { private final ErpContractInfoMapper baseMapper; @@ -205,30 +211,47 @@ public class ErpContractInfoServiceImpl implements IErpContractInfoService { public ErpContractInfoVo contractSubmitAndFlowStart(ErpContractInfoBo bo) { ErpContractInfo add = MapstructUtils.convert(bo, ErpContractInfo.class); validEntityBeforeSave(add); - List contractMaterialList = bo.getContractMaterialList(); - boolean flag = baseMapper.insert(add) > 0; - if (flag && contractMaterialList != null && !contractMaterialList.isEmpty()) { - bo.setContractId(add.getContractId()); - for (ErpContractMaterial erpContractMaterial : contractMaterialList) { - erpContractMaterial.setContractId(add.getContractId()); - contractMaterialMapper.insert(erpContractMaterial); - } + if (StringUtils.isNull(bo.getContractId())) { + this.insertByBo(bo); + } else { + this.updateByBo(bo); } - if (flag) { - // 后端发起需要忽略权限 - bo.getVariables().put("ignore", true); - RemoteStartProcess startProcess = new RemoteStartProcess(); - startProcess.setBusinessId(bo.getContractId().toString()); - startProcess.setFlowCode(bo.getFlowCode()); - startProcess.setVariables(bo.getVariables()); - startProcess.setBizExt(bo.getBizExt()); - bo.getBizExt().setBusinessId(startProcess.getBusinessId()); - boolean flagOne = remoteWorkflowService.startCompleteTask(startProcess); - if (!flagOne) { - throw new ServiceException("流程发起异常"); - } + // 后端发起需要忽略权限 + bo.getVariables().put("ignore", true); + RemoteStartProcess startProcess = new RemoteStartProcess(); + startProcess.setBusinessId(bo.getContractId().toString()); + startProcess.setFlowCode(bo.getFlowCode()); + startProcess.setVariables(bo.getVariables()); + startProcess.setBizExt(bo.getBizExt()); + bo.getBizExt().setBusinessId(startProcess.getBusinessId()); + boolean flagOne = remoteWorkflowService.startCompleteTask(startProcess); + if (!flagOne) { + throw new ServiceException("流程发起异常"); } 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 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); + }); + } + }