From df0a8b4003106e5431b91c40704f034752594e55 Mon Sep 17 00:00:00 2001 From: KharchenkoVV Date: Fri, 4 Jun 2021 09:22:25 +0500 Subject: [PATCH] =?UTF-8?q?CF2-8:=20=D0=91=D0=B0=D0=B7=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D1=8F=20=D1=81=D1=82?= =?UTF-8?q?=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D1=8B=20=D1=80=D0=B5=D0=BF=D0=BE?= =?UTF-8?q?=D1=80=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Report.jsx | 113 +++++++++++++----- src/pages/TelemetryView.jsx | 4 +- src/services/api/services/ReportService.ts | 15 +-- src/services/api/services/TelemetryService.ts | 2 +- src/services/signalr/index.ts | 43 ++++--- 5 files changed, 123 insertions(+), 54 deletions(-) diff --git a/src/pages/Report.jsx b/src/pages/Report.jsx index cccc2fd..dfd8efb 100644 --- a/src/pages/Report.jsx +++ b/src/pages/Report.jsx @@ -11,29 +11,41 @@ import { import 'moment/locale/ru'; import locale from 'antd/lib/locale/ru_RU'; import moment from "moment"; -import { ReportService } from '../services/api' +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; -const initialBegin = moment() -const initialEnd = moment() -const initialStep = 600 -const initialFormat = 1 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' +} + // Экспорт рендера export default function Report(props) { - const [rangeDate, setRangeDate] = useState([moment(), moment()]) - const [step, setStep] = useState(initialStep) - const [format, setFormat] = useState(initialFormat) + const [rangeDate, setRangeDate] = useState([moment().subtract(1,'days'), moment()]) + const [step, setStep] = useState(600) + const [format, setFormat] = useState(0) + const [reportProgress, setReportProgress] = useState(0.0) const [approxPages, setPagesCount] = useState(0) const [suitableReports, setSuitableReports] = useState([]) + const [loader, setLoader] = useState(false) let wellId = useParams().id; const columns = [ @@ -41,6 +53,7 @@ export default function Report(props) { title: '', dataIndex: 'reportFormat', key: 'reportFormat', + render: format => {format} }, { title: 'Параметры отчета', @@ -51,14 +64,40 @@ export default function Report(props) { title: 'Название отчета', dataIndex: 'reportName', key: 'reportName', - render: name => {name} + render: name => {name} }, ]; - let handleReportCreation = async (values) => { + const handleReportProgress = (data) => { + console.log('data: ' + data) + if(data) { + setReportProgress(data) + } + + console.log('reportProgress: ' + reportProgress) + //console.log(data) + } + + const handleReportCreation = async (values) => { let begin = rangeDate[0].toISOString() let end = rangeDate[1].toISOString() - let taskId = await ReportService.createReport(wellId, values.step, values.format, begin, end) + let taskId = null; + + ReportService.createReport(wellId, values.step, values.format, begin, end) + .then((data) => { + if(data) { + taskId = data + let unSubscribeReportHub = Subscribe('hubs/reports', 'GetReportProgress', `Report_${taskId}`, handleReportProgress) + //unSubscribeReportHub() + } + }) + .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.error(error) + }) + }; function disabledDate(current) { @@ -69,17 +108,32 @@ export default function Report(props) { async function getRepostSizeAsync() { let begin = rangeDate[0].toISOString() let end = rangeDate[1].toISOString() - let approxPagesResponse = await ReportService.getReportSize(wellId, step, format, begin, end) - setPagesCount(approxPagesResponse) - let suitableReportsResponse = await ReportService.getSuitableReportsNames(wellId, step, format, begin, end) - let suitableReports = suitableReportsResponse.map(value => { - return { - reportFormat: value.format, - reportParams: `Дата создания: ${value.date}, Данные от ${value.begin} до ${value.end}, Шаг: ${value.step}`, - reportName: value.name - } - }) - setSuitableReports(suitableReports) + try { + let approxPagesResponse = await ReportService.getReportSize(wellId, step, format, begin, end) + setPagesCount(approxPagesResponse) + + 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(`Не удалось загрузить данные по скважине (${wellId}) c + ${rangeDate[0].format("DD.MM.YYYY hh:mm:ss")} по + ${rangeDate[1].format("DD.MM.YYYY hh:mm:ss")}`, 'error') + console.error(error) + } finally { + setLoader(false) + } } getRepostSizeAsync() @@ -93,6 +147,7 @@ export default function Report(props) { } getDatesRange() + //return ()=>{uns && uns()} },[]) return (<> @@ -107,7 +162,7 @@ export default function Report(props) {