diff --git a/backend/crm/src/main/java/cn/cordys/crm/approval/aspect/HitApprovalAspect.java b/backend/crm/src/main/java/cn/cordys/crm/approval/aspect/HitApprovalAspect.java index 1b9f024ed2..e0e0b82d82 100644 --- a/backend/crm/src/main/java/cn/cordys/crm/approval/aspect/HitApprovalAspect.java +++ b/backend/crm/src/main/java/cn/cordys/crm/approval/aspect/HitApprovalAspect.java @@ -5,7 +5,7 @@ import cn.cordys.crm.approval.annotation.HitApproval; import cn.cordys.crm.approval.constants.ApprovalStatus; import cn.cordys.crm.approval.constants.ExecuteTimingEnum; -import cn.cordys.crm.approval.domain.ApprovalFlowVersion; +import cn.cordys.crm.approval.domain.ApprovalFlow; import cn.cordys.crm.approval.service.ApprovalFlowService; import cn.cordys.crm.approval.service.ApprovalResourceService; import jakarta.annotation.Resource; @@ -161,7 +161,7 @@ private String resolveResourceIdFromArgs(Method method, Object[] args, String ex private boolean checkHitApprovalFlow(FormKey formKey, ExecuteTimingEnum executeTiming, String organizationId) { try { // 查询当前组织表单审批流配置 - ApprovalFlowVersion flow = approvalFlowService.getEnabledFlow(formKey.getKey(), organizationId); + ApprovalFlow flow = approvalFlowService.getEnabledFlow(formKey.getKey(), organizationId); if (flow == null) { return false; diff --git a/backend/crm/src/main/java/cn/cordys/crm/approval/controller/ApprovalFlowController.java b/backend/crm/src/main/java/cn/cordys/crm/approval/controller/ApprovalFlowController.java index 13e31264f6..9385e988c9 100644 --- a/backend/crm/src/main/java/cn/cordys/crm/approval/controller/ApprovalFlowController.java +++ b/backend/crm/src/main/java/cn/cordys/crm/approval/controller/ApprovalFlowController.java @@ -1,26 +1,22 @@ package cn.cordys.crm.approval.controller; -import cn.cordys.aspectj.annotation.OperationLog; -import cn.cordys.aspectj.constants.LogModule; -import cn.cordys.aspectj.constants.LogType; import cn.cordys.common.constants.PermissionConstants; import cn.cordys.common.pager.Pager; import cn.cordys.context.OrganizationContext; +import cn.cordys.crm.approval.dto.request.ApprovalFlowAddRequest; +import cn.cordys.crm.approval.dto.request.ApprovalFlowPageRequest; +import cn.cordys.crm.approval.dto.request.ApprovalFlowUpdateRequest; import cn.cordys.crm.approval.dto.response.ApprovalFlowByFormTypeResponse; import cn.cordys.crm.approval.dto.response.ApprovalFlowDetailResponse; import cn.cordys.crm.approval.dto.response.ApprovalFlowListResponse; import cn.cordys.crm.approval.dto.response.StatusPermissionSettingResponse; -import cn.cordys.crm.approval.dto.request.ApprovalFlowAddRequest; -import cn.cordys.crm.approval.dto.request.ApprovalFlowPageRequest; -import cn.cordys.crm.approval.dto.request.ApprovalFlowUpdateRequest; -import cn.cordys.crm.approval.domain.ApprovalFlow; import cn.cordys.crm.approval.service.ApprovalFlowService; import cn.cordys.security.SessionUtils; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; -import org.springframework.validation.annotation.Validated; import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -45,7 +41,6 @@ public Pager> list(@Validated @RequestBody Approv @PostMapping("/add") @RequiresPermissions(PermissionConstants.APPROVAL_FLOW_ADD) - @OperationLog(module = LogModule.APPROVAL_FLOW, type = LogType.ADD) @Operation(summary = "新建审批流") public ApprovalFlowDetailResponse add(@Validated @RequestBody ApprovalFlowAddRequest request) { return approvalFlowService.add(request, SessionUtils.getUserId(), OrganizationContext.getOrganizationId()); @@ -53,7 +48,6 @@ public ApprovalFlowDetailResponse add(@Validated @RequestBody ApprovalFlowAddReq @PostMapping("/update") @RequiresPermissions(PermissionConstants.APPROVAL_FLOW_UPDATE) - @OperationLog(module = LogModule.APPROVAL_FLOW, type = LogType.UPDATE) @Operation(summary = "更新审批流") public ApprovalFlowDetailResponse update(@Validated @RequestBody ApprovalFlowUpdateRequest request) { return approvalFlowService.update(request, SessionUtils.getUserId(), OrganizationContext.getOrganizationId()); @@ -61,7 +55,6 @@ public ApprovalFlowDetailResponse update(@Validated @RequestBody ApprovalFlowUpd @GetMapping("/delete/{id}") @RequiresPermissions(PermissionConstants.APPROVAL_FLOW_DELETE) - @OperationLog(module = LogModule.APPROVAL_FLOW, type = LogType.DELETE) @Operation(summary = "删除审批流") public void delete(@PathVariable("id") String id) { approvalFlowService.delete(id, OrganizationContext.getOrganizationId()); @@ -76,7 +69,6 @@ public ApprovalFlowDetailResponse get(@PathVariable("id") String id) { @GetMapping("/enable/{id}") @RequiresPermissions(PermissionConstants.APPROVAL_FLOW_UPDATE) - @OperationLog(module = LogModule.APPROVAL_FLOW, type = LogType.UPDATE) @Operation(summary = "启用/禁用审批流") public void updateEnable(@PathVariable("id") String id, @RequestParam("enable") Boolean enable) { approvalFlowService.updateEnable(id, enable, SessionUtils.getUserId(), OrganizationContext.getOrganizationId()); diff --git a/backend/crm/src/main/java/cn/cordys/crm/approval/domain/ApprovalFlow.java b/backend/crm/src/main/java/cn/cordys/crm/approval/domain/ApprovalFlow.java index e89d3b8431..740c4e5401 100644 --- a/backend/crm/src/main/java/cn/cordys/crm/approval/domain/ApprovalFlow.java +++ b/backend/crm/src/main/java/cn/cordys/crm/approval/domain/ApprovalFlow.java @@ -23,12 +23,39 @@ public class ApprovalFlow extends BaseModel { @Schema(description = "表单类型:quotation/contract/invoice/order") private String formType; + @Schema(description = "新建时执行") + private Boolean createExecute; + + @Schema(description = "编辑时执行") + private Boolean updateExecute; + + @Schema(description = "允许提交人撤销") + private Boolean submitterCanRevoke; + + @Schema(description = "允许批量处理") + private Boolean allowBatchProcess; + + @Schema(description = "允许撤回") + private Boolean allowWithdraw; + + @Schema(description = "允许加签") + private Boolean allowAddSign; + + @Schema(description = "重复审批人规则:FIRST_ONLY/SEQUENTIAL_ALL/EACH") + private String duplicateApproverRule; + + @Schema(description = "是否必须填写审批意见") + private Boolean requireComment; + @Schema(description = "启用状态") private Boolean enable; @Schema(description = "流程描述") private String description; + @Schema(description = "状态权限配置(JSON格式)") + private String statusPermissions; + @Schema(description = "组织id") private String organizationId; } diff --git a/backend/crm/src/main/java/cn/cordys/crm/approval/domain/ApprovalFlowVersion.java b/backend/crm/src/main/java/cn/cordys/crm/approval/domain/ApprovalFlowVersion.java index a81dbb6a74..8bcb256718 100644 --- a/backend/crm/src/main/java/cn/cordys/crm/approval/domain/ApprovalFlowVersion.java +++ b/backend/crm/src/main/java/cn/cordys/crm/approval/domain/ApprovalFlowVersion.java @@ -20,36 +20,9 @@ public class ApprovalFlowVersion implements Serializable { @Schema(description = "审批流ID") private String flowId; - @Schema(description = "新建时执行") - private Boolean createExecute; - - @Schema(description = "编辑时执行") - private Boolean updateExecute; - - @Schema(description = "允许提交人撤销") - private Boolean submitterCanRevoke; - - @Schema(description = "允许批量处理") - private Boolean allowBatchProcess; - - @Schema(description = "允许撤回") - private Boolean allowWithdraw; - - @Schema(description = "允许加签") - private Boolean allowAddSign; - - @Schema(description = "重复审批人规则:FIRST_ONLY/SEQUENTIAL_ALL/EACH") - private String duplicateApproverRule; - - @Schema(description = "是否必须填写审批意见") - private Boolean requireComment; - @Schema(description = "组织id") private String organizationId; - @Schema(description = "状态权限配置(JSON格式)") - private String statusPermissions; - @Schema(description = "创建人") private String createUser; diff --git a/backend/crm/src/main/java/cn/cordys/crm/approval/mapper/ExtApprovalFlowMapper.java b/backend/crm/src/main/java/cn/cordys/crm/approval/mapper/ExtApprovalFlowMapper.java index 037f365d2c..d2a0a66959 100644 --- a/backend/crm/src/main/java/cn/cordys/crm/approval/mapper/ExtApprovalFlowMapper.java +++ b/backend/crm/src/main/java/cn/cordys/crm/approval/mapper/ExtApprovalFlowMapper.java @@ -17,14 +17,4 @@ public interface ExtApprovalFlowMapper { List list( @Param("request") ApprovalFlowPageRequest request, @Param("organizationId") String organizationId); - - /** - * 批量禁用同类型审批流 - */ - int disableByFormType( - @Param("formType") String formType, - @Param("organizationId") String organizationId, - @Param("excludeId") String excludeId, - @Param("updateUser") String updateUser, - @Param("updateTime") Long updateTime); } \ No newline at end of file diff --git a/backend/crm/src/main/java/cn/cordys/crm/approval/mapper/ExtApprovalFlowMapper.xml b/backend/crm/src/main/java/cn/cordys/crm/approval/mapper/ExtApprovalFlowMapper.xml index cf3fb22cda..c19c706018 100644 --- a/backend/crm/src/main/java/cn/cordys/crm/approval/mapper/ExtApprovalFlowMapper.xml +++ b/backend/crm/src/main/java/cn/cordys/crm/approval/mapper/ExtApprovalFlowMapper.xml @@ -147,18 +147,4 @@ - - - UPDATE approval_flow - SET enable = 0, - update_user = #{updateUser}, - update_time = #{updateTime} - WHERE form_type = #{formType} - AND organization_id = #{organizationId} - AND enable = 1 - - AND id != #{excludeId} - - - diff --git a/backend/crm/src/main/java/cn/cordys/crm/approval/service/ApprovalActionService.java b/backend/crm/src/main/java/cn/cordys/crm/approval/service/ApprovalActionService.java index 8551cdb071..71d7f51fc0 100644 --- a/backend/crm/src/main/java/cn/cordys/crm/approval/service/ApprovalActionService.java +++ b/backend/crm/src/main/java/cn/cordys/crm/approval/service/ApprovalActionService.java @@ -51,8 +51,6 @@ public class ApprovalActionService { @Resource private ApprovalInstanceService approvalInstanceService; @Resource - private BaseMapper approvalFlowVersionMapper; - @Resource private BaseMapper approvalInstanceMapper; @Resource private BaseMapper approvalTaskMapper; @@ -87,12 +85,14 @@ public class ApprovalActionService { * @param orgId 当前组织 */ public void sign(ApprovalAddSignRequest request, String userId, String orgId) { + ApprovalInstance instance = approvalInstanceMapper.selectByPrimaryKey(request.getInstanceId()); + // 审批流是否允许加签 - ApprovalFlowVersion flowVersion = getFlowVersionOfInstanceId(request.getInstanceId()); - if (flowVersion == null || !flowVersion.getAllowAddSign()) { + ApprovalFlow approvalFlow = approvalFlowService.selectApprovalFlowByFormType(instance.getType(), orgId); + if (approvalFlow == null || !approvalFlow.getAllowAddSign()) { throw new GenericException(Translator.get("no.operation.permission")); } - ApprovalInstance instance = approvalInstanceMapper.selectByPrimaryKey(request.getInstanceId()); + // 刷新被加签任务状态 && 插入审批记录 ApprovalTask currentTask = saveActionTask(request, ApprovalAction.SIGN, userId, orgId, ApprovalAddSignType.valueOf(request.getType())); // 加签操作的待办任务 @@ -134,12 +134,12 @@ public void back(ApprovalReturnBackRequest request, String userId, String orgId) */ public void revoke(ApprovalRevokeRequest request, String currentUserId, String orgId) { ApprovalTask currentTask = getTaskById(request.getId()); + ApprovalInstance instance = approvalInstanceMapper.selectByPrimaryKey(currentTask.getInstanceId()); // 审批流是否允许撤回 - ApprovalFlowVersion flowVersion = getFlowVersionOfInstanceId(currentTask.getInstanceId()); - if (flowVersion == null || !flowVersion.getAllowWithdraw()) { + ApprovalFlow approvalFlow = approvalFlowService.selectApprovalFlowByFormType(currentTask.getType(), orgId); + if (approvalFlow == null || !approvalFlow.getAllowWithdraw()) { throw new GenericException(Translator.get("no.operation.permission")); } - ApprovalInstance instance = approvalInstanceMapper.selectByPrimaryKey(currentTask.getInstanceId()); revokeProcess(currentTask, instance, orgId); refreshRevokeTask(currentTask, instance, currentUserId); } @@ -168,17 +168,6 @@ public void reject(ApprovalActionRequest request, String currentUserId, String c rejectProcess(currentTask, currentUserId, currentOrgId); } - /** - * 获取流程配置相关权限 - * - * @param id 审批实例ID - * @return 审批流 - */ - private ApprovalFlowVersion getFlowVersionOfInstanceId(String id) { - ApprovalInstance approvalInstance = approvalInstanceMapper.selectByPrimaryKey(id); - return approvalFlowVersionMapper.selectByPrimaryKey(approvalInstance.getFlowVersionId()); - } - /** * 保存加签任务的信息 * diff --git a/backend/crm/src/main/java/cn/cordys/crm/approval/service/ApprovalFlowService.java b/backend/crm/src/main/java/cn/cordys/crm/approval/service/ApprovalFlowService.java index c2e9d5b81b..2f74f7bb41 100644 --- a/backend/crm/src/main/java/cn/cordys/crm/approval/service/ApprovalFlowService.java +++ b/backend/crm/src/main/java/cn/cordys/crm/approval/service/ApprovalFlowService.java @@ -112,11 +112,11 @@ public class ApprovalFlowService { */ public StatusPermissionSettingResponse getStatusPermissionsByFormType(String formType, String organizationId) { StatusPermissionSettingResponse response = new StatusPermissionSettingResponse(); - + // 获取权限列表 List permissions = getResourcePermissions(getPermissionsByFormType(formType)); response.setPermissions(permissions); - + // 查询该表单类型对应的审批流 ApprovalFlow criteria = new ApprovalFlow(); criteria.setFormType(formType); @@ -135,19 +135,14 @@ public StatusPermissionSettingResponse getStatusPermissionsByFormType(String for .findFirst() .orElse(flows.getFirst()); - // 查询当前版本获取状态权限配置 - if (StringUtils.isBlank(targetFlow.getCurrentVersionId())) { - response.setStatusPermissions(List.of()); - return response; - } - ApprovalFlowVersion version = approvalFlowVersionMapper.selectByPrimaryKey(targetFlow.getCurrentVersionId()); - if (version == null || StringUtils.isBlank(version.getStatusPermissions())) { + // 从主表获取状态权限配置 + if (StringUtils.isBlank(targetFlow.getStatusPermissions())) { response.setStatusPermissions(List.of()); return response; } // 解析状态权限配置 - response.setStatusPermissions(parseStatusPermissions(permissions, version.getStatusPermissions())); + response.setStatusPermissions(parseStatusPermissions(permissions, targetFlow.getStatusPermissions())); return response; } @@ -290,21 +285,8 @@ public ApprovalFlowDetailResponse getDetail(String id, String organizationId) { // 设置对应资源的权限列表 response.setPermissions(getResourcePermissions(permissions)); - // 查询当前版本 - if (StringUtils.isNotBlank(flow.getCurrentVersionId())) { - ApprovalFlowVersion version = approvalFlowVersionMapper.selectByPrimaryKey(flow.getCurrentVersionId()); - if (version != null) { - response.setCreateExecute(version.getCreateExecute()); - response.setUpdateExecute(version.getUpdateExecute()); - response.setSubmitterCanRevoke(version.getSubmitterCanRevoke()); - response.setAllowBatchProcess(version.getAllowBatchProcess()); - response.setAllowWithdraw(version.getAllowWithdraw()); - response.setAllowAddSign(version.getAllowAddSign()); - response.setDuplicateApproverRule(version.getDuplicateApproverRule()); - response.setRequireComment(version.getRequireComment()); - response.setStatusPermissions(parseStatusPermissions(response.getPermissions(), version.getStatusPermissions())); - } - } + // 解析状态权限配置 + response.setStatusPermissions(parseStatusPermissions(response.getPermissions(), flow.getStatusPermissions())); // 查询节点配置和连接关系 buildNodesAndLinks(flow.getCurrentVersionId(), response, organizationId); @@ -336,21 +318,8 @@ public ApprovalFlowByFormTypeResponse getByFormType(String formType, String orga List permissions = getPermissionsByFormType(targetFlow.getFormType()); response.setPermissions(getResourcePermissions(permissions)); - // 查询当前版本 - if (StringUtils.isNotBlank(targetFlow.getCurrentVersionId())) { - ApprovalFlowVersion version = approvalFlowVersionMapper.selectByPrimaryKey(targetFlow.getCurrentVersionId()); - if (version != null) { - response.setCreateExecute(version.getCreateExecute()); - response.setUpdateExecute(version.getUpdateExecute()); - response.setSubmitterCanRevoke(version.getSubmitterCanRevoke()); - response.setAllowBatchProcess(version.getAllowBatchProcess()); - response.setAllowWithdraw(version.getAllowWithdraw()); - response.setAllowAddSign(version.getAllowAddSign()); - response.setDuplicateApproverRule(version.getDuplicateApproverRule()); - response.setRequireComment(version.getRequireComment()); - response.setStatusPermissions(parseStatusPermissions(response.getPermissions(), version.getStatusPermissions())); - } - } + // 解析状态权限配置(从主表获取) + response.setStatusPermissions(parseStatusPermissions(response.getPermissions(), targetFlow.getStatusPermissions())); return response; } @@ -360,9 +329,10 @@ public ApprovalFlowByFormTypeResponse getByFormType(String formType, String orga */ @OperationLog(module = LogModule.APPROVAL_FLOW, type = LogType.ADD, resourceName = "{#request.name}") public ApprovalFlowDetailResponse add(ApprovalFlowAddRequest request, String userId, String organizationId) { - // 如果启用,先关闭同类型的其他审批流 - if (Boolean.TRUE.equals(request.getEnable())) { - disableOtherFlows(request.getFormType(), null, userId, organizationId); + // 检查该表单类型是否已存在审批流(每个表单类型只能创建一个) + ApprovalFlow existFlow = selectApprovalFlowByFormType(request.getFormType(), organizationId); + if (existFlow != null) { + throw new GenericException(Translator.get("approval_flow.type.already.exists")); } // 创建审批流主表 @@ -375,8 +345,13 @@ public ApprovalFlowDetailResponse add(ApprovalFlowAddRequest request, String use flow.setUpdateTime(System.currentTimeMillis()); flow.setOrganizationId(organizationId); - // 创建版本 - ApprovalFlowVersion version = createFlowVersion(flow.getId(), request, userId, organizationId); + // 保存状态权限配置到主表 + if (request.getStatusPermissions() != null) { + flow.setStatusPermissions(JSON.toJSONString(request.getStatusPermissions())); + } + + // 创建版本(版本表只存储节点配置的关联) + ApprovalFlowVersion version = createFlowVersion(flow.getId(), userId, organizationId); approvalFlowVersionMapper.insert(version); // 更新当前版本ID @@ -399,25 +374,25 @@ public ApprovalFlowDetailResponse add(ApprovalFlowAddRequest request, String use return detail; } + public ApprovalFlow selectApprovalFlowByFormType(String formType, String organizationId) { + ApprovalFlow existCriteria = new ApprovalFlow(); + existCriteria.setFormType(formType); + existCriteria.setOrganizationId(organizationId); + List existFlows = approvalFlowMapper.select(existCriteria); + if (CollectionUtils.isEmpty(existFlows)) { + return null; + } + return existFlows.getFirst(); + } + /** * 创建审批流版本 */ - private ApprovalFlowVersion createFlowVersion(String flowId, ApprovalFlowAddRequest request, String userId, String organizationId) { + private ApprovalFlowVersion createFlowVersion(String flowId, String userId, String organizationId) { ApprovalFlowVersion version = new ApprovalFlowVersion(); version.setId(IDGenerator.nextStr()); version.setFlowId(flowId); - version.setCreateExecute(request.getCreateExecute()); - version.setUpdateExecute(request.getUpdateExecute()); - version.setSubmitterCanRevoke(request.getSubmitterCanRevoke()); - version.setAllowBatchProcess(request.getAllowBatchProcess()); - version.setAllowWithdraw(request.getAllowWithdraw()); - version.setAllowAddSign(request.getAllowAddSign()); - version.setDuplicateApproverRule(request.getDuplicateApproverRule()); - version.setRequireComment(request.getRequireComment()); version.setOrganizationId(organizationId); - if (request.getStatusPermissions() != null) { - version.setStatusPermissions(JSON.toJSONString(request.getStatusPermissions())); - } version.setCreateUser(userId); version.setCreateTime(System.currentTimeMillis()); return version; @@ -431,28 +406,28 @@ public ApprovalFlowDetailResponse update(ApprovalFlowUpdateRequest request, Stri // 获取原始日志DTO ApprovalFlowDetailResponse originDetail = getDetail(request.getId(), organizationId); - // 如果启用,先关闭同类型的其他审批流 - if (Boolean.TRUE.equals(request.getEnable())) { - disableOtherFlows(originDetail.getFormType(), request.getId(), userId, organizationId); - } - + // 更新审批流主表(配置字段直接保存到主表) ApprovalFlow flow = BeanUtils.copyBean(new ApprovalFlow(), request); + flow.setUpdateUser(userId); + flow.setUpdateTime(System.currentTimeMillis()); - ApprovalFlowVersion originApprovalFlowVersion = approvalFlowVersionMapper.selectByPrimaryKey(originDetail.getCurrentVersionId()); - // 创建新版本 - ApprovalFlowVersion newVersion = createFlowVersionFromUpdate(request, originApprovalFlowVersion, userId, organizationId); - approvalFlowVersionMapper.insert(newVersion); + // 保存状态权限配置到主表 + if (request.getStatusPermissions() != null) { + flow.setStatusPermissions(JSON.toJSONString(request.getStatusPermissions())); + } - // 更新当前版本ID - flow.setCurrentVersionId(newVersion.getId()); - String versionId = newVersion.getId(); + // 如果有节点更新,创建新版本 + if (CollectionUtils.isNotEmpty(request.getNodes())) { + ApprovalFlowVersion newVersion = createFlowVersion(originDetail.getId(), userId, organizationId); + approvalFlowVersionMapper.insert(newVersion); - // 保存新节点配置 - saveNodesAndLinks(request.getNodes(), request.getLinks(), versionId, userId); + // 更新当前版本ID + flow.setCurrentVersionId(newVersion.getId()); + + // 保存新节点配置 + saveNodesAndLinks(request.getNodes(), request.getLinks(), newVersion.getId(), userId); + } - // 更新审批流主表 - flow.setUpdateUser(userId); - flow.setUpdateTime(System.currentTimeMillis()); approvalFlowMapper.updateById(flow); ApprovalFlowDetailResponse detail = getDetail(flow.getId(), organizationId); @@ -469,28 +444,6 @@ public ApprovalFlowDetailResponse update(ApprovalFlowUpdateRequest request, Stri return detail; } - /** - * 从更新请求创建新版本 - */ - private ApprovalFlowVersion createFlowVersionFromUpdate(ApprovalFlowUpdateRequest request, ApprovalFlowVersion originVersion, String userId, String organizationId) { - ApprovalFlowVersion version = new ApprovalFlowVersion(); - version.setId(IDGenerator.nextStr()); - version.setFlowId(originVersion.getFlowId()); - version.setCreateExecute(request.getCreateExecute() != null ? request.getCreateExecute() : originVersion.getCreateExecute()); - version.setUpdateExecute(request.getUpdateExecute() != null ? request.getUpdateExecute() : originVersion.getUpdateExecute()); - version.setSubmitterCanRevoke(request.getSubmitterCanRevoke() != null ? request.getSubmitterCanRevoke() : originVersion.getSubmitterCanRevoke()); - version.setAllowBatchProcess(request.getAllowBatchProcess() != null ? request.getAllowBatchProcess() : originVersion.getAllowBatchProcess()); - version.setAllowWithdraw(request.getAllowWithdraw() != null ? request.getAllowWithdraw() : originVersion.getAllowWithdraw()); - version.setAllowAddSign(request.getAllowAddSign() != null ? request.getAllowAddSign() : originVersion.getAllowAddSign()); - version.setDuplicateApproverRule(request.getDuplicateApproverRule() != null ? request.getDuplicateApproverRule() : originVersion.getDuplicateApproverRule()); - version.setRequireComment(request.getRequireComment() != null ? request.getRequireComment() : originVersion.getRequireComment()); - version.setOrganizationId(organizationId); - version.setStatusPermissions(request.getStatusPermissions() != null ? JSON.toJSONString(request.getStatusPermissions()) : originVersion.getStatusPermissions()); - version.setCreateUser(userId); - version.setCreateTime(System.currentTimeMillis()); - return version; - } - /** * 删除审批流 */ @@ -531,7 +484,6 @@ public void delete(String id, String organizationId) { /** * 启用/禁用审批流 - * 启用时直接启用当前审批流,并关闭同类型的其他审批流 */ @OperationLog(module = LogModule.APPROVAL_FLOW, type = LogType.UPDATE, resourceId = "{#id}") public void updateEnable(String id, Boolean enable, String userId, String organizationId) { @@ -542,11 +494,6 @@ public void updateEnable(String id, Boolean enable, String userId, String organi Boolean oldEnable = flow.getEnable(); - if (Boolean.TRUE.equals(enable)) { - // 关闭同类型的其他审批流 - disableOtherFlows(flow.getFormType(), id, userId, organizationId); - } - ApprovalFlow update = new ApprovalFlow(); update.setId(id); update.setEnable(enable); @@ -568,13 +515,6 @@ public void updateEnable(String id, Boolean enable, String userId, String organi ); } - /** - * 关闭同类型的其他审批流 - */ - private void disableOtherFlows(String formType, String excludeId, String userId, String organizationId) { - extApprovalFlowMapper.disableByFormType(formType, organizationId, excludeId, userId, System.currentTimeMillis()); - } - /** * 生成流程编码 */ @@ -1339,7 +1279,7 @@ private List findPermissionsByPermissionId(List nodes = getNodesByFlowVersionId(flow.getCurrentVersionId()); @@ -246,6 +248,17 @@ void testAdd() throws Exception { @Test @Order(2) + void testAddDuplicateType() throws Exception { + // 测试重复创建同一表单类型的审批流应该失败 + ApprovalFlowAddRequest duplicateRequest = buildAddRequest("重复的报价审批流", ApprovalFormTypeEnum.QUOTATION, true); + MvcResult result = this.requestPost(DEFAULT_ADD, duplicateRequest).andReturn(); + // 应该返回错误状态码而不是成功 + String response = result.getResponse().getContentAsString(); + Assertions.assertTrue(response.contains("该表单类型的审批流已存在") || response.contains("already exists")); + } + + @Test + @Order(3) void testUpdate() throws Exception { // 请求成功 ApprovalFlowUpdateRequest request = new ApprovalFlowUpdateRequest(); @@ -288,19 +301,17 @@ void testUpdate() throws Exception { Assertions.assertEquals(request.getName(), updatedFlow.getName()); Assertions.assertEquals(request.getDescription(), updatedFlow.getDescription()); + // 校验配置字段存储在主表 + Assertions.assertEquals(request.getSubmitterCanRevoke(), updatedFlow.getSubmitterCanRevoke()); + Assertions.assertEquals(request.getAllowBatchProcess(), updatedFlow.getAllowBatchProcess()); + Assertions.assertEquals(request.getAllowWithdraw(), updatedFlow.getAllowWithdraw()); + Assertions.assertEquals(request.getAllowAddSign(), updatedFlow.getAllowAddSign()); + Assertions.assertEquals(request.getDuplicateApproverRule(), updatedFlow.getDuplicateApproverRule()); + Assertions.assertEquals(request.getRequireComment(), updatedFlow.getRequireComment()); + // 校验更新后产生了新版本 Assertions.assertNotEquals(addApprovalFlow.getCurrentVersionId(), updatedFlow.getCurrentVersionId()); - // 校验版本配置 - ApprovalFlowVersion updatedVersion = approvalFlowVersionMapper.selectByPrimaryKey(updatedFlow.getCurrentVersionId()); - Assertions.assertNotNull(updatedVersion); - Assertions.assertEquals(request.getSubmitterCanRevoke(), updatedVersion.getSubmitterCanRevoke()); - Assertions.assertEquals(request.getAllowBatchProcess(), updatedVersion.getAllowBatchProcess()); - Assertions.assertEquals(request.getAllowWithdraw(), updatedVersion.getAllowWithdraw()); - Assertions.assertEquals(request.getAllowAddSign(), updatedVersion.getAllowAddSign()); - Assertions.assertEquals(request.getDuplicateApproverRule(), updatedVersion.getDuplicateApproverRule()); - Assertions.assertEquals(request.getRequireComment(), updatedVersion.getRequireComment()); - // 校验节点配置已更新(删除旧节点,插入新节点) List updatedNodes = getNodesByFlowVersionId(updatedFlow.getCurrentVersionId()); Assertions.assertEquals(3, updatedNodes.size()); @@ -315,7 +326,7 @@ void testUpdate() throws Exception { } @Test - @Order(4) + @Order(5) void testPage() throws Exception { ApprovalFlowPageRequest request = new ApprovalFlowPageRequest(); request.setCurrent(1); @@ -357,7 +368,7 @@ void testPage() throws Exception { } @Test - @Order(5) + @Order(6) void testGet() throws Exception { // 请求成功 MvcResult mvcResult = this.requestGetWithOkAndReturn(DEFAULT_GET, addApprovalFlow.getId()); @@ -373,15 +384,13 @@ void testGet() throws Exception { Assertions.assertEquals(approvalFlow.getEnable(), response.getEnable()); Assertions.assertEquals(approvalFlow.getDescription(), response.getDescription()); - // 校验版本配置 - ApprovalFlowVersion version = approvalFlowVersionMapper.selectByPrimaryKey(approvalFlow.getCurrentVersionId()); - Assertions.assertNotNull(version); - Assertions.assertEquals(response.getSubmitterCanRevoke(), version.getSubmitterCanRevoke()); - Assertions.assertEquals(response.getAllowBatchProcess(), version.getAllowBatchProcess()); - Assertions.assertEquals(response.getAllowWithdraw(), version.getAllowWithdraw()); - Assertions.assertEquals(response.getAllowAddSign(), version.getAllowAddSign()); - Assertions.assertEquals(response.getDuplicateApproverRule(), version.getDuplicateApproverRule()); - Assertions.assertEquals(response.getRequireComment(), version.getRequireComment()); + // 校验配置字段从主表获取 + Assertions.assertEquals(approvalFlow.getSubmitterCanRevoke(), response.getSubmitterCanRevoke()); + Assertions.assertEquals(approvalFlow.getAllowBatchProcess(), response.getAllowBatchProcess()); + Assertions.assertEquals(approvalFlow.getAllowWithdraw(), response.getAllowWithdraw()); + Assertions.assertEquals(approvalFlow.getAllowAddSign(), response.getAllowAddSign()); + Assertions.assertEquals(approvalFlow.getDuplicateApproverRule(), response.getDuplicateApproverRule()); + Assertions.assertEquals(approvalFlow.getRequireComment(), response.getRequireComment()); // 校验节点配置 Assertions.assertFalse(CollectionUtils.isEmpty(response.getNodes())); @@ -394,7 +403,7 @@ void testGet() throws Exception { } @Test - @Order(6) + @Order(7) void testEnable() throws Exception { // 启用之前创建的禁用审批流 ApprovalFlow disabledFlow = getDisabledFlow(); @@ -418,7 +427,7 @@ void testEnable() throws Exception { } @Test - @Order(7) + @Order(8) void testPageWithEnableFilter() throws Exception { // 筛选启用的审批流 ApprovalFlowPageRequest request = new ApprovalFlowPageRequest(); @@ -511,7 +520,7 @@ private ApprovalFlow getDisabledFlow() { } @Test - @Order(8) + @Order(9) void testGetStatusPermissionSetting() throws Exception { // 请求成功 - 获取报价审批流的状态权限配置 MvcResult mvcResult = this.requestGetWithOkAndReturn(STATUS_PERMISSION_SETTING, ApprovalFormTypeEnum.QUOTATION.getValue()); @@ -540,7 +549,7 @@ void testGetStatusPermissionSetting() throws Exception { } @Test - @Order(9) + @Order(10) void testGetByFormType() throws Exception { // 请求成功 - 根据表单类型获取审批流信息 MvcResult mvcResult = this.requestGetWithOkAndReturn(GET_BY_FORM_TYPE, ApprovalFormTypeEnum.QUOTATION.getValue()); @@ -555,15 +564,15 @@ void testGetByFormType() throws Exception { Assertions.assertTrue(response.getEnable()); Assertions.assertNotNull(response.getDescription()); - // 校验版本配置 - ApprovalFlowVersion version = approvalFlowVersionMapper.selectByPrimaryKey(response.getCurrentVersionId()); - Assertions.assertNotNull(version); - Assertions.assertEquals(response.getSubmitterCanRevoke(), version.getSubmitterCanRevoke()); - Assertions.assertEquals(response.getAllowBatchProcess(), version.getAllowBatchProcess()); - Assertions.assertEquals(response.getAllowWithdraw(), version.getAllowWithdraw()); - Assertions.assertEquals(response.getAllowAddSign(), version.getAllowAddSign()); - Assertions.assertEquals(response.getDuplicateApproverRule(), version.getDuplicateApproverRule()); - Assertions.assertEquals(response.getRequireComment(), version.getRequireComment()); + // 校验配置字段从主表获取 + ApprovalFlow flow = approvalFlowMapper.selectByPrimaryKey(response.getId()); + Assertions.assertNotNull(flow); + Assertions.assertEquals(flow.getSubmitterCanRevoke(), response.getSubmitterCanRevoke()); + Assertions.assertEquals(flow.getAllowBatchProcess(), response.getAllowBatchProcess()); + Assertions.assertEquals(flow.getAllowWithdraw(), response.getAllowWithdraw()); + Assertions.assertEquals(flow.getAllowAddSign(), response.getAllowAddSign()); + Assertions.assertEquals(flow.getDuplicateApproverRule(), response.getDuplicateApproverRule()); + Assertions.assertEquals(flow.getRequireComment(), response.getRequireComment()); // 校验权限列表 Assertions.assertNotNull(response.getPermissions()); diff --git a/backend/framework/src/main/java/cn/cordys/aspectj/constants/LogModule.java b/backend/framework/src/main/java/cn/cordys/aspectj/constants/LogModule.java index 3f78990ce5..447db5f4f8 100644 --- a/backend/framework/src/main/java/cn/cordys/aspectj/constants/LogModule.java +++ b/backend/framework/src/main/java/cn/cordys/aspectj/constants/LogModule.java @@ -148,5 +148,5 @@ public class LogModule { */ public static final String ORDER_INDEX = "ORDER_INDEX"; - public static final String APPROVAL_FLOW = "APPROVAL_FLOW"; + public static final String APPROVAL_FLOW = "SYSTEM_PROCESS_APPROVAL"; }