Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ public static FormKey ofKey(String key) {
}

public boolean hasSnapshot() {
return Strings.CI.equalsAny(this.key, CONTRACT.getKey(), INVOICE.getKey(), QUOTATION.getKey());
return Strings.CI.equalsAny(this.key, CONTRACT.getKey(), INVOICE.getKey(), QUOTATION.getKey(), ORDER.getKey());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1359,16 +1359,12 @@ public List<User> resolveApprovers(String userId, String orgId, ApproverTypeEnum

// 获取当前用户的组织用户信息
OrganizationUser currentUser = getOrganizationUser(userId, orgId);
if (currentUser == null) {
return List.of();
}

return switch (approverType) {
case MEMBER -> resolveMemberApprovers(orgId, approverList);
case ROLE -> resolveRoleApprovers(orgId, approverList);
case SUPERIOR -> resolveSuperiorApprovers(orgId, currentUser, approverList);
case MULTIPLE_SUPERIOR -> resolveMultipleSuperiorApprovers(orgId, currentUser, approverList);
case DEPT_HEAD -> resolveDeptHeadApprovers(orgId, currentUser.getDepartmentId(), approverList);
case DEPT_HEAD -> resolveDeptHeadApprovers(orgId, currentUser, approverList);
case MULTIPLE_DEPT_HEAD -> resolveMultipleDeptHeadApprovers(orgId, currentUser, approverList);
};
}
Expand Down Expand Up @@ -1410,6 +1406,9 @@ private List<User> resolveRoleApprovers(String orgId, List<String> roleIds) {
* 解析指定上级审批人
*/
private List<User> resolveSuperiorApprovers(String orgId, OrganizationUser currentUser, List<String> approverList) {
if (currentUser == null) {
return List.of();
}
// 值是单选
Integer approvalLevel = getValidLevel(approverList);

Expand Down Expand Up @@ -1439,6 +1438,9 @@ private List<User> resolveSuperiorApprovers(String orgId, OrganizationUser curre
* 解析多级上级审批人
*/
private List<User> resolveMultipleSuperiorApprovers(String orgId, OrganizationUser currentUser, List<String> approverList) {
if (currentUser == null) {
return List.of();
}
// 值是单选
Integer approvalLevel = getValidLevel(approverList);

Expand Down Expand Up @@ -1483,7 +1485,11 @@ private Integer getValidLevel(List<String> approverList) {
/**
* 解析部门负责人审批人
*/
private List<User> resolveDeptHeadApprovers(String orgId, String departmentId, List<String> approverList) {
private List<User> resolveDeptHeadApprovers(String orgId, OrganizationUser currentUser, List<String> approverList) {
if (currentUser == null) {
return List.of();
}
String departmentId = currentUser.getDepartmentId();
if (StringUtils.isBlank(departmentId)) {
return List.of();
}
Expand Down Expand Up @@ -1523,6 +1529,9 @@ private String getDeptCommander(String orgId, String departmentId) {
* 解析多级部门负责人审批人
*/
private List<User> resolveMultipleDeptHeadApprovers(String orgId, OrganizationUser currentUser, List<String> approverList) {
if (currentUser == null) {
return List.of();
}
String departmentId = currentUser.getDepartmentId();
if (StringUtils.isBlank(departmentId)) {
return List.of();
Expand Down Expand Up @@ -1586,6 +1595,18 @@ public List<User> getCurrentNodeApproverList(String currentNodeId, String userId
return resolveApprovers(userId, currentOrgId, ApproverTypeEnum.valueOf(nodeApprover.getApproverType()), JSON.parseArray(nodeApprover.getApproverList(), String.class));
}

/**
* 获取当前实例节点审批人
* @param approverType 审批类型
* @param approverList 审批人集合
* @param userId 用户ID
* @param currentOrgId 当前组织ID
* @return 审批人ID集合
*/
public List<User> getCurrentNodeApproverList(String approverType, List<String> approverList, String userId, String currentOrgId) {
return resolveApprovers(userId, currentOrgId, ApproverTypeEnum.valueOf(approverType), approverList);
}

/**
* 获取当前实例节点抄送人
* @param currentNodeId 当前节点ID
Expand All @@ -1598,6 +1619,18 @@ public List<User> getCurrentNodeCcList(String currentNodeId, String userId, Stri
return resolveApprovers(userId, currentOrgId, ApproverTypeEnum.valueOf(nodeApprover.getCcType()), JSON.parseArray(nodeApprover.getCcList(), String.class));
}

/**
* 获取当前实例节点抄送人
* @param ccType 抄送类型
* @param ccList 抄送人集合
* @param userId 用户ID
* @param currentOrgId 当前组织ID
* @return 抄送人ID集合
*/
public List<User> getCurrentNodeCcList(String ccType, List<String> ccList, String userId, String currentOrgId) {
return resolveApprovers(userId, currentOrgId, ApproverTypeEnum.valueOf(ccType), ccList);
}

/**
* 获取当前资源审批实例第一个节点
* @param instance 审批实例
Expand Down Expand Up @@ -1643,8 +1676,8 @@ private ApprovalNodeResponse getNextNodeWithExceptionHandler(ApprovalInstance in
ApprovalNodeApproverResponse nextApproverNode = (ApprovalNodeApproverResponse) nextNode;
if (ApprovalTypeEnum.valueOf(nextApproverNode.getApprovalType()) == ApprovalTypeEnum.AUTO_PASS) {
// 自动通过, 插入审批记录, 获取下一个节点
saveAutoRecord(instance.getId(), nodeId, ApprovalStatus.APPROVED, null);
return getNextNodeWithExceptionHandler(instance, nodeId, fieldValues, currentOrgId);
saveAutoRecord(instance.getId(), nextApproverNode.getId(), ApprovalStatus.APPROVED, null);
return getNextNodeWithExceptionHandler(instance, nextApproverNode.getId(), fieldValues, currentOrgId);
}
if (ApprovalTypeEnum.valueOf(nextApproverNode.getApprovalType()) == ApprovalTypeEnum.AUTO_REJECT) {
// 自动驳回, 插入审批记录
Expand All @@ -1654,8 +1687,8 @@ private ApprovalNodeResponse getNextNodeWithExceptionHandler(ApprovalInstance in
return exNode;
}
// 人工审批, 异常处理
List<User> nextApprovers = getCurrentNodeApproverList(nextApproverNode.getId(), instance.getSubmitterId(), currentOrgId);
List<User> nextCcList = getCurrentNodeCcList(nextApproverNode.getId(), instance.getSubmitterId(), currentOrgId);
List<User> nextApprovers = getCurrentNodeApproverList(nextApproverNode.getApproverType(), nextApproverNode.getApproverList(), instance.getSubmitterId(), currentOrgId);
List<User> nextCcList = getCurrentNodeCcList(nextApproverNode.getCcType(), nextApproverNode.getCcList(), instance.getSubmitterId(), currentOrgId);
nextApproverNode.setApproverList(nextApprovers.stream().map(User::getId).collect(Collectors.toList()));
nextApproverNode.setCcList(nextCcList.stream().map(User::getId).collect(Collectors.toList()));
// 审批人为空
Expand All @@ -1664,8 +1697,8 @@ private ApprovalNodeResponse getNextNodeWithExceptionHandler(ApprovalInstance in
switch (emptyAction) {
case AUTO_PASS -> {
// 自动通过, 插入审批记录, 获取下一个节点
saveAutoRecord(instance.getId(), nodeId, ApprovalStatus.APPROVED, "审批人为空,自动通过");
return getNextNodeWithExceptionHandler(instance, nodeId, fieldValues, currentOrgId);
saveAutoRecord(instance.getId(), nextApproverNode.getId(), ApprovalStatus.APPROVED, "审批人为空,自动通过");
return getNextNodeWithExceptionHandler(instance, nextApproverNode.getId(), fieldValues, currentOrgId);
}
case ASSIGN_SPECIFIC -> {
//指定人员处理: 返回人员列表
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package cn.cordys.crm.approval.service;

import cn.cordys.common.constants.FormKey;
import cn.cordys.common.exception.GenericException;
import cn.cordys.common.util.BeanUtils;
import cn.cordys.common.util.CommonBeanFactory;
import cn.cordys.common.util.Translator;
import cn.cordys.crm.approval.constants.ApprovalAction;
import cn.cordys.crm.approval.constants.ApprovalAddSignType;
import cn.cordys.crm.approval.constants.ApprovalStatus;
Expand Down Expand Up @@ -83,6 +85,9 @@ public ApprovalInstance getLatestInstance(String resourceId) {
LambdaQueryWrapper<ApprovalInstance> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ApprovalInstance::getResourceId, resourceId);
List<ApprovalInstance> list = approvalInstanceMapper.selectListByLambda(wrapper);
if (CollectionUtils.isEmpty(list)) {
throw new GenericException(Translator.get("no.approval.instance"));
}
return CollectionUtils.isEmpty(list) ? null : list.stream().sorted(Comparator.comparing(ApprovalInstance::getSubmitTime)).toList().getLast();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ private void updateSnapshotApprovalStatus(FormKey formKey, String resourceId, St
Map<FormKey, String> snapshotServiceMap = Map.of(
FormKey.INVOICE, "contractInvoiceService",
FormKey.QUOTATION, "opportunityQuotationService",
FormKey.CONTRACT, "customerContactService"
FormKey.CONTRACT, "contractService",
FormKey.ORDER, "orderService"
);

String serviceBeanName = snapshotServiceMap.get(formKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ public ModuleFormConfigDTO getBusinessFormConfig(String organizationId) {
}

/**
* 由审批执行操作统一调用, 勿修改
* ⚠️反射调用: 由审批执行操作统一调用, 勿修改
* @param param 参数
*/
public void updateSnapshotApprovalStatus(ResourceSnapshotApprovalParam param) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ private void updateStatusSnapshot(String id, String stage, String approvalStatus
}

/**
* 由审批执行操作统一调用, 勿修改
* ⚠️反射调用: 由审批执行操作统一调用, 勿修改
* @param param 参数
*/
public void updateSnapshotApprovalStatus(ResourceSnapshotApprovalParam param) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ private void updateSnapshot(String id, String approvalStatus, ModuleFormConfigDT
}

/**
* 由审批执行操作统一调用, 勿修改
* ⚠️反射调用: 由审批执行操作统一调用, 勿修改
* @param param 参数
*/
public void updateSnapshotApprovalStatus(ResourceSnapshotApprovalParam param) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@
import cn.cordys.crm.approval.constants.ApprovalFormTypeEnum;
import cn.cordys.crm.approval.constants.ApprovalStatus;
import cn.cordys.crm.approval.constants.ExecuteTimingEnum;
import cn.cordys.crm.approval.dto.ResourceSnapshotApprovalParam;
import cn.cordys.crm.approval.service.ApprovalFlowService;
import cn.cordys.crm.contract.domain.Contract;
import cn.cordys.crm.contract.domain.ContractSnapshot;
import cn.cordys.crm.contract.dto.response.ContractGetResponse;
import cn.cordys.crm.customer.domain.Customer;
import cn.cordys.crm.order.domain.Order;
import cn.cordys.crm.order.domain.OrderSnapshot;
Expand Down Expand Up @@ -446,6 +449,22 @@ public OrderGetResponse getSnapshot(String id) {
return response;
}

/**
* ⚠️反射调用: 由审批执行操作统一调用, 勿修改
* @param param 参数
*/
public void updateSnapshotApprovalStatus(ResourceSnapshotApprovalParam param) {
OrderSnapshot snapshotCriteria = new OrderSnapshot();
snapshotCriteria.setOrderId(param.getResourceId());
OrderSnapshot snapshot = snapshotBaseMapper.selectOne(snapshotCriteria);
if (snapshot != null) {
OrderGetResponse response = JSON.parseObject(snapshot.getOrderValue(), OrderGetResponse.class);
response.setApprovalStatus(param.getApprovalStatus());
snapshot.setOrderValue(JSON.toJSONString(response));
snapshotBaseMapper.update(snapshot);
}
}


/**
* 订单列表
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -851,3 +851,4 @@ no.revoke.approval=Cannot revoke
no.approval.next.node=No subsequent node found, check the approval flow configuration
auto.approval.passed=Auto passed
auto.approval.rejected=Auto rejected
no.approval.instance=No approval instance!
Original file line number Diff line number Diff line change
Expand Up @@ -849,4 +849,5 @@ reject_approval=驳回审批
no.revoke.approval=无法撤销
no.approval.next.node=未找到后续节点,请检查审批流配置
auto.approval.passed=自动通过
auto.approval.rejected=自动驳回
auto.approval.rejected=自动驳回
no.approval.instance=审批实例为空!
Loading