import { useState, useEffect } from "react"; import { useParams } from 'react-router-dom'; import { Form, DatePicker, Radio, Button, Select, Table, Progress, notification } from 'antd'; import 'moment/locale/ru'; import locale from 'antd/lib/locale/ru_RU'; import moment from "moment"; import {Subscribe} from '../services/signalr'; import notify from '../components/notify'; import LoaderPortal from '../components/LoaderPortal'; import { ReportService } from '../services/api'; const { RangePicker } = DatePicker; const { Option } = Select; let reportDatesRange = { from: moment("0001-01-01T00:00:00"), to: moment("9999-12-31T23:59:59.9999999") } const timePeriodNames = { 600: '1 минута', 86400:'1 день', 604800:'1 неделя' } const imgPaths = { '.pdf': '/images/pdf.png', '.las': '/images/las.png' } const contentTypes = { '.pdf': 'application/pdf', '.las': 'application/octet-stream' } // Экспорт рендера export default function Report(props) { const [rangeDate, setRangeDate] = useState([moment().subtract(1,'days'), moment()]) const [step, setStep] = useState(600) const [format, setFormat] = useState(0) const [approxPages, setPagesCount] = useState(0) const [suitableReports, setSuitableReports] = useState([]) const [loader, setLoader] = useState(false) let wellId = useParams().id; const columns = [ { title: '', dataIndex: 'reportFormat', key: 'reportFormat', render: format => {format} }, { title: 'Параметры отчета', dataIndex: 'reportParams', key: 'reportParams', }, { title: 'Название отчета', dataIndex: 'reportName', key: 'reportName', render: name => getReportFile(event, name)} download={name}>{name} }, ]; const ReportCreationNotify = ({progressData}) => { progressData = progressData ?? {progress: 0.0, operation: 'Создание отчета', reportName: ''} return ( <>
{ progressData.operation }
getReportFile(event, progressData.reportName)} download> { progressData.reportName } ) } const getReportFile = async (event, reportFileName) => { try { const element = event.target let bytesArray = await ReportService.getReport(wellId, reportFileName) const contentType = contentTypes[reportFileName.slice(-4)] let reportUrl = URL.createObjectURL(new File(bytesArray, {type: contentType})) element.href = reportUrl } catch (error) { notify(`Не удалось скачать отчет по скважине (${wellId}) c ${rangeDate[0].format("DD.MM.YYYY hh:mm:ss")} по ${rangeDate[1].format("DD.MM.YYYY hh:mm:ss")}`, 'error') console.log(error) } } const handleReportCreation = async (values) => { let begin = rangeDate[0].toISOString() let end = rangeDate[1].toISOString() try { const taskId = await ReportService.createReport(wellId, values.step, values.format, begin, end) if(!taskId) return const handleReportProgress = (progressData) => { if(progressData) { notification.open({ key: taskId, message: 'Создание отчета:', description: , duration: 0 }); if (progressData.reportName?.length) unSubscribeReportHub() } } const unSubscribeReportHub = Subscribe('hubs/reports', 'GetReportProgress', `Report_${taskId}`, handleReportProgress) } catch(error) { notify(`Не удалось создать отчет по скважине (${wellId}) c ${rangeDate[0].format("DD.MM.YYYY hh:mm:ss")} по ${rangeDate[1].format("DD.MM.YYYY hh:mm:ss")}`, 'error') console.log(error) } } function disabledDate(current) { return reportDatesRange.From >= current || reportDatesRange.To <= current; } useEffect(()=>{ async function getRepostSizeAsync() { let begin = rangeDate[0].toISOString() let end = rangeDate[1].toISOString() try { let approxPagesResponse = await ReportService.getReportSize(wellId, step, format, begin, end) setPagesCount(approxPagesResponse) } catch(error) { notify(`Не удалось получить предварительный размер отчета c ${rangeDate[0].format("DD.MM.YYYY hh:mm:ss")} по ${rangeDate[1].format("DD.MM.YYYY hh:mm:ss")}`, 'error') console.log(error) } finally { setLoader(false) } } getRepostSizeAsync() },[rangeDate, step, format]) useEffect(()=>{ async function getSuitableReportsAsync() { let begin = rangeDate[0].toISOString() let end = rangeDate[1].toISOString() try { setLoader(true) let suitableReportsResponse = await ReportService.getSuitableReportsNames(wellId, step, format, begin, end) let suitableReports = suitableReportsResponse.map(value => { return { key: value.id, reportFormat: value.format, reportParams: `Дата создания: ${new Date(value.date).toLocaleDateString()}, Данные от ${new Date(value.begin).toLocaleString()} до ${new Date(value.end).toLocaleString()}, Шаг: ${timePeriodNames[value.step]}`, reportName: value.name } }) setSuitableReports(suitableReports) } catch(error) { notify(`Не удалось получить подходящие по параметрам отчеты c ${rangeDate[0].format("DD.MM.YYYY hh:mm:ss")} по ${rangeDate[1].format("DD.MM.YYYY hh:mm:ss")}`, 'error') console.log(error) } finally { setLoader(false) } } getSuitableReportsAsync() },[rangeDate, step, format]) useEffect(()=>{ async function getDatesRange() { let response = await ReportService.getReportsDateRange(wellId) reportDatesRange.from = moment(response.from) reportDatesRange.to = moment(response.to) } getDatesRange() },[]) return (<>
{ setRangeDate([moment(dateStrings[0]), moment(dateStrings[1])]) } } locale={locale} showTime /> setFormat(e.target.value)} className="ml-30px" > PDF LAS

Отчеты с аналогичными параметрами, доступные для скачивания:


) }