| | |
| | | import com.ruoyi.sales.pojo.ShippingInfo; |
| | | import com.ruoyi.staff.mapper.HolidayApplicationMapper; |
| | | import com.ruoyi.staff.pojo.HolidayApplication; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.ruoyi.device.pojo.DeviceStatusChangeRecord; |
| | | import com.ruoyi.device.service.IDeviceStatusChangeRecordService; |
| | | import com.ruoyi.device.pojo.DeviceLedger; |
| | | import com.ruoyi.device.service.IDeviceLedgerService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | private final EnterpriseNewsMapper enterpriseNewsMapper; |
| | | private final EnterpriseNewsScopeDeptMapper enterpriseNewsScopeDeptMapper; |
| | | private final ApprovalTemplateNodeApproverMapper approvalTemplateNodeApproverMapper; |
| | | private final IDeviceStatusChangeRecordService deviceStatusChangeRecordService; |
| | | private final IDeviceLedgerService deviceLedgerService; |
| | | |
| | | @Override |
| | | public R listPage(Page<ApprovalInstanceVo> page, ApprovalInstanceDto approvalInstanceDto) { |
| | |
| | | if (TypeEnums.PURCHASE_APPROVAL.getCode().equals(vo.getBusinessType())) { |
| | | // 采购审批 - 查询采购单号 |
| | | PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectById(vo.getBusinessId()); |
| | | System.out.println("业务类型:" + purchaseLedger.getPurchaseContractNumber()); |
| | | if (purchaseLedger != null) { |
| | | vo.setPurchaseContractNumber(purchaseLedger.getPurchaseContractNumber()); |
| | | } |
| | |
| | | approvalInstanceDto.setInstanceNo(instanceNo); |
| | | approvalInstanceDto.setStatus("PENDING"); |
| | | approvalInstanceDto.setCurrentLevel(1); |
| | | |
| | | if (approvalInstanceDto.getApplicantId() == null) { |
| | | approvalInstanceDto.setApplicantId(SecurityUtils.getUserId()); |
| | | LoginUser loginUser = SecurityUtils.getLoginUser(); |
| | | if (loginUser != null && loginUser.getUser() != null) { |
| | | approvalInstanceDto.setApplicantName(loginUser.getUser().getNickName()); |
| | | } |
| | | } |
| | | |
| | | // 校验设备状态变更审批:如果该设备已有正在审批的任务,无法再次进行审批 |
| | | if (TypeEnums.DEVICE_STATUS_CHANGE_APPROVAL.getCode().equals(approvalInstanceDto.getBusinessType())) { |
| | | Long deviceId = approvalInstanceDto.getBusinessId(); |
| | | |
| | | long pendingCount = deviceStatusChangeRecordService.count(Wrappers.<DeviceStatusChangeRecord>lambdaQuery() |
| | | .eq(DeviceStatusChangeRecord::getDeviceId, deviceId) |
| | | .eq(DeviceStatusChangeRecord::getApprovalStatus, "PENDING") |
| | | .eq(DeviceStatusChangeRecord::getDeleted, 0) |
| | | ); |
| | | if (pendingCount > 0) { |
| | | throw new ServiceException("该设备已有正在进行的状态变更审批,无法再次提交"); |
| | | } |
| | | |
| | | DeviceLedger device = deviceLedgerService.getById(deviceId); |
| | | if (device == null) { |
| | | throw new ServiceException("设备不存在"); |
| | | } |
| | | |
| | | Integer targetStatus = null; |
| | | String reason = ""; |
| | | if (StringUtils.hasText(approvalInstanceDto.getFormConfig())) { |
| | | try { |
| | | JSONObject formObj = JSONObject.parseObject(approvalInstanceDto.getFormConfig()); |
| | | if (formObj.containsKey("targetStatus")) { |
| | | targetStatus = formObj.getInteger("targetStatus"); |
| | | } else if (formObj.containsKey("status")) { |
| | | targetStatus = formObj.getInteger("status"); |
| | | } |
| | | if (formObj.containsKey("reason")) { |
| | | reason = formObj.getString("reason"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("解析状态变更表单失败", e); |
| | | } |
| | | } |
| | | |
| | | DeviceStatusChangeRecord record = new DeviceStatusChangeRecord(); |
| | | record.setDeviceId(deviceId); |
| | | record.setOriginalStatus(Integer.valueOf(device.getStatus())); |
| | | record.setTargetStatus(targetStatus); |
| | | record.setReason(reason); |
| | | record.setApprovalStatus("PENDING"); |
| | | deviceStatusChangeRecordService.save(record); |
| | | |
| | | // 绑定到关联记录的主键 |
| | | approvalInstanceDto.setBusinessId(record.getId()); |
| | | } |
| | | |
| | | boolean saved = this.save(approvalInstanceDto); |
| | | if (!saved) { |
| | | return false; |
| | |
| | | ); |
| | | //审批拒绝的处理 |
| | | if ("REJECTED".equals(approveAction)) { |
| | | return rejectCurrentNode(instance, currentNode, now); |
| | | return rejectCurrentNode(instance, currentNode, approvalInstanceDto.getApproveComment(), now); |
| | | } |
| | | if (!approveProcessConfigNodeUtils.canProceedToNextLevel(instance.getId(), currentNode.getApproveType())) { |
| | | return R.ok("审批成功,等待其他审批人处理"); |
| | |
| | | currentInstance.setStatus("APPROVED"); |
| | | currentInstance.setFinishTime(LocalDateTime.now()); |
| | | this.updateById(currentInstance); |
| | | handleBusinessAfterApprovalFinished(currentInstance); |
| | | handleBusinessAfterApprovalFinished(currentInstance, null); |
| | | return R.ok("审批已完成"); |
| | | } |
| | | |
| | |
| | | ); |
| | | } |
| | | |
| | | private R rejectCurrentNode(ApprovalInstance instance, ApprovalInstanceNode currentNode, LocalDateTime now) { |
| | | private R rejectCurrentNode(ApprovalInstance instance, ApprovalInstanceNode currentNode, String approveComment, LocalDateTime now) { |
| | | if (!updateCurrentNodeStatus(currentNode.getId(), "REJECTED", now)) { |
| | | return R.ok("当前节点已处理完成"); |
| | | } |
| | |
| | | instance.setFinishTime(now); |
| | | this.updateById(instance); |
| | | // 统一处理业务状态更新 |
| | | handleBusinessAfterApprovalFinished(instance); |
| | | handleBusinessAfterApprovalFinished(instance, approveComment); |
| | | return R.ok("审批已驳回"); |
| | | } |
| | | |
| | |
| | | instance.setStatus("APPROVED"); |
| | | instance.setFinishTime(now); |
| | | this.updateById(instance); |
| | | handleBusinessAfterApprovalFinished(instance); |
| | | handleBusinessAfterApprovalFinished(instance, null); |
| | | return R.ok("审批已完成"); |
| | | } |
| | | |
| | |
| | | ); |
| | | } |
| | | |
| | | private void handleBusinessAfterApprovalFinished(ApprovalInstance instance) { |
| | | private void handleBusinessAfterApprovalFinished(ApprovalInstance instance, String rejectReason) { |
| | | String status = instance.getStatus(); |
| | | Long businessType = instance.getBusinessType(); |
| | | if (TypeEnums.PURCHASE_APPROVAL.getCode().equals(businessType)) { |
| | |
| | | } |
| | | if (TypeEnums.ENTERPRISE_NEWS_APPROVAL.getCode().equals(businessType)) { |
| | | handleNewsApprovalFinished(instance, status); |
| | | return; |
| | | } |
| | | if (TypeEnums.DEVICE_STATUS_CHANGE_APPROVAL.getCode().equals(businessType)) { |
| | | handleDeviceStatusChangeApprovalFinished(instance, status, rejectReason); |
| | | return; |
| | | } |
| | | } |
| | | |
| | | private void handleDeviceStatusChangeApprovalFinished(ApprovalInstance instance, String status, String rejectReason) { |
| | | if (instance == null || instance.getBusinessId() == null) { |
| | | return; |
| | | } |
| | | DeviceStatusChangeRecord record = deviceStatusChangeRecordService.getById(instance.getBusinessId()); |
| | | if (record == null) { |
| | | return; |
| | | } |
| | | if ("APPROVED".equals(status)) { |
| | | record.setApprovalStatus("APPROVED"); |
| | | if (record.getTargetStatus() != null) { |
| | | DeviceLedger device = new DeviceLedger(); |
| | | device.setId(record.getDeviceId()); |
| | | device.setStatus(String.valueOf(record.getTargetStatus())); |
| | | deviceLedgerService.updateById(device); |
| | | } |
| | | } else if ("REJECTED".equals(status)) { |
| | | record.setApprovalStatus("REJECTED"); |
| | | if (rejectReason != null) { |
| | | record.setRejectReason(rejectReason); |
| | | } |
| | | } else if ("PENDING".equals(status)) { |
| | | record.setApprovalStatus("PENDING"); |
| | | } |
| | | deviceStatusChangeRecordService.updateById(record); |
| | | } |
| | | |
| | | private void handleReimbursementApprovalFinished(ApprovalInstance instance, String status) { |
| | |
| | | |
| | | String title = StringUtils.hasText(instance.getTemplateName()) ? instance.getTemplateName() : "审批提醒"; |
| | | String message = "审批单号 " + instance.getInstanceNo() + " 需要您审批"; |
| | | String jumpPath = "/officeProcessAutomation/ApproveManage/approve-list?id=" + instance.getId(); |
| | | String jumpPath = getJumpPathByBusinessType(instance.getBusinessType(), instance.getId()); |
| | | sysNoticeService.simpleNoticeByUser(title, message, approverIds, jumpPath); |
| | | } |
| | | |
| | | private String getJumpPathByBusinessType(Long businessType, Long instanceId) { |
| | | if (businessType == null) { |
| | | return "/collaborativeApproval/approve-list?id=" + instanceId; |
| | | } |
| | | if (TypeEnums.LEAVE_APPROVAL.getCode().equals(businessType)) { |
| | | return "/collaborativeApproval/AttendManage/leave-apply?id=" + instanceId; |
| | | } |
| | | if (TypeEnums.OVERTIME_APPROVAL.getCode().equals(businessType)) { |
| | | return "/collaborativeApproval/AttendManage/overtime-apply?id=" + instanceId; |
| | | } |
| | | if (TypeEnums.TRAVEL_REIMBURSEMENT_APPROVAL.getCode().equals(businessType)) { |
| | | return "/collaborativeApproval/ReimburseManage/travel-reimburse?id=" + instanceId; |
| | | } |
| | | if (TypeEnums.EXPENSE_APPROVAL.getCode().equals(businessType)) { |
| | | return "/collaborativeApproval/ReimburseManage/cost-reimburse?id=" + instanceId; |
| | | } |
| | | return "/collaborativeApproval/approve-list?id=" + instanceId; |
| | | } |
| | | |
| | | private void sendEnterpriseNewsNotice(Long newsId) { |
| | | EnterpriseNews enterpriseNews = enterpriseNewsMapper.selectById(newsId); |
| | | if (enterpriseNews == null) { |