| | |
| | | import com.ruoyi.common.utils.OrderUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.project.system.service.ISysNoticeService; |
| | | import com.ruoyi.project.system.service.ISysDeptService; |
| | | import com.ruoyi.project.system.domain.SysDept; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | private final FinReimbursementDetailMapper finReimbursementDetailMapper; |
| | | private final FileUtil fileUtil; |
| | | private final ISysNoticeService sysNoticeService; |
| | | private final ISysDeptService sysDeptService; |
| | | @Override |
| | | public IPage<FinReimbursementVo> listPage(FinReimbursementDto finReimbursementDto, Page<FinReimbursementVo> page) { |
| | | IPage<FinReimbursementVo> finReimbursementVoIPage = finReimbursementMapper.listPage(finReimbursementDto, page); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<FinReimbursementVo> list(FinReimbursementDto finReimbursementDto) { |
| | | return finReimbursementMapper.list(finReimbursementDto); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean add(FinReimbursementDto finReimbursementDto) { |
| | | String billStatus = validateAddParam(finReimbursementDto); |
| | | |
| | | // 生成报销单号 |
| | | String billNo = OrderUtils.countTodayByCreateTime(finReimbursementMapper, "BXD", "bill_no"); |
| | | String billNo = OrderUtils.countTodayByCreateTime(finReimbursementMapper, "BXD", "bill_no", finReimbursementDto.getCreateTime() != null ? finReimbursementDto.getCreateTime() : LocalDateTime.now()); |
| | | List<FinReimbursementDetail> details = finReimbursementDto.getDetails(); |
| | | BigDecimal totalAmount = details.stream() |
| | | .map(FinReimbursementDetail::getAmount) |
| | |
| | | vo.setDeptId(reimbursement.getDeptId()); |
| | | vo.setDeleted(reimbursement.getDeleted()); |
| | | |
| | | if (reimbursement.getDeptId() != null) { |
| | | SysDept dept = sysDeptService.selectDeptById(reimbursement.getDeptId()); |
| | | if (dept != null) { |
| | | vo.setDeptName(dept.getDeptName()); |
| | | } |
| | | } |
| | | |
| | | vo.setDetails(finReimbursementDetailMapper.selectList( |
| | | new LambdaQueryWrapper<FinReimbursementDetail>() |
| | | .eq(FinReimbursementDetail::getReimbursementId, reimbursement.getId()) |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean delete(List<Long> ids) { |
| | | if (ids == null || ids.isEmpty()) { |
| | | throw new ServiceException("删除失败,请选择要删除的数据"); |
| | | } |
| | | // 查询报销单关联的审批实例ID |
| | | List<FinReimbursement> reimbursements = finReimbursementMapper.selectList( |
| | | new LambdaQueryWrapper<FinReimbursement>() |
| | | .in(FinReimbursement::getId, ids) |
| | | .isNotNull(FinReimbursement::getApprovalInstanceId) |
| | | ); |
| | | List<Long> approvalInstanceIds = reimbursements.stream() |
| | | .map(FinReimbursement::getApprovalInstanceId) |
| | | .filter(Objects::nonNull) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 删除关联的审批记录 |
| | | if (!approvalInstanceIds.isEmpty()) { |
| | | approvalInstanceService.delete(approvalInstanceIds); |
| | | } |
| | | |
| | | fileUtil.deleteStorageAttachmentsByApplicationAndRecordTypeAndRecordIds(ApplicationTypeEnum.FILE, RecordTypeEnum.FIN_REIMBURSEMENT, ids); |
| | | //先删除明细 |
| | | finReimbursementDetailMapper.delete(new LambdaQueryWrapper<FinReimbursementDetail>().in(FinReimbursementDetail::getReimbursementId, ids)); |
| | |
| | | private void startApproval(FinReimbursement reimbursement, FinReimbursementDto finReimbursementDto) { |
| | | Long businessType = resolveBusinessType(finReimbursementDto.getReimbursementType()); |
| | | ApprovalInstanceDto approvalInstanceDto = new ApprovalInstanceDto(); |
| | | approvalInstanceDto.setInstanceNo(OrderUtils.countTodayByCreateTime(approvalInstanceMapper, "SP", "instance_no")); |
| | | approvalInstanceDto.setInstanceNo(OrderUtils.countTodayByCreateTime(approvalInstanceMapper, "SP", "instance_no", approvalInstanceDto.getCreateTime() != null ? approvalInstanceDto.getCreateTime() : LocalDateTime.now())); |
| | | approvalInstanceDto.setBusinessId(reimbursement.getId()); |
| | | approvalInstanceDto.setTemplateId(null); |
| | | approvalInstanceDto.setTemplateName(TypeEnums.getLabelByValue(businessType) + "审批"); |
| | |
| | | } |
| | | String title = "报销审批"; |
| | | String message = "审批单号 " + instance.getInstanceNo() + " 需要您审批"; |
| | | String jumpPath = "/approvalInstance?id=" + instance.getId(); |
| | | String jumpPath = getJumpPathByBusinessType(instance.getBusinessType(), instance.getId()); |
| | | sysNoticeService.simpleNoticeByUser(title, message, approverIds, jumpPath); |
| | | } |
| | | |
| | | private String getJumpPathByBusinessType(Long businessType, Long 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 "/approvalInstance?id=" + instanceId; |
| | | } |
| | | |
| | | private void resetApprovalFlow(FinReimbursement existing, Long reimbursementId) { |
| | | if (existing == null || existing.getApprovalInstanceId() == null) { |
| | | return; |