From fbd98134ea373c89aec3a273bc6ae17e9c31e336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A4=D1=80=D0=BE=D0=BB=D0=BE=D0=B2?= Date: Wed, 18 Aug 2021 10:35:39 +0500 Subject: [PATCH] reports refactoring --- src/pages/Report/ReportCreationNotify.jsx | 30 +++ src/pages/Report/index.jsx | 255 ++++++++++++++++++++++ 2 files changed, 285 insertions(+) create mode 100644 src/pages/Report/ReportCreationNotify.jsx create mode 100644 src/pages/Report/index.jsx diff --git a/src/pages/Report/ReportCreationNotify.jsx b/src/pages/Report/ReportCreationNotify.jsx new file mode 100644 index 0000000..9541d43 --- /dev/null +++ b/src/pages/Report/ReportCreationNotify.jsx @@ -0,0 +1,30 @@ + +import { Progress } from "antd" +import { download } from "../../components/factory"; +import notify from '../../components/notify' + +export const getReportFile = async (idWell, reportName) => { + try { + await download(`/api/well/${idWell}/report/${reportName}`, reportName) + } catch (error) { + notify(`Не удалось скачать отчет ${reportName} по скважине (${idWell})`, 'error') + console.log(error) + } +} + +export const ReportCreationNotify = ({idWell, progressData}) => { + progressData = progressData ?? {progress: 0.0, operation: 'Создание отчета', reportName: ''} + + return ( + <> + +
+ { progressData.operation } +
+ + + ) +} \ No newline at end of file diff --git a/src/pages/Report/index.jsx b/src/pages/Report/index.jsx new file mode 100644 index 0000000..da6db59 --- /dev/null +++ b/src/pages/Report/index.jsx @@ -0,0 +1,255 @@ +import { useState, useEffect } from "react" +import { + Form, + DatePicker, + Radio, + Button, + Select, + Table, + notification, +} from "antd" +import "moment/locale/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" +import { ReportCreationNotify, getReportFile } from "./ReportCreationNotify" +import { invokeWebApiWrapperAsync } from "../../components/factory" + +const { RangePicker } = DatePicker +const { Option } = Select + +const timePeriodNames = [ + { label: "1 секунда", value: 1 }, + { label: "10 секунд", value: 10 }, + { label: "1 минута", value: 60 }, + { label: "5 минут", value: 300 }, + { label: "30 минут", value: 1800 }, + { label: "1 час", value: 3600 }, + { label: "6 часов", value: 21600 }, + { label: "12 часов", value: 43200 }, + { label: "1 день", value: 86400 }, + { label: "1 неделя", value: 604800 }, +] + +const imgPaths = { + ".pdf": "/images/pdf.png", + ".las": "/images/las.png", +} + +const dateTimeFormat = "DD.MM.YYYY hh:mm:ss" + +export default function Report({ idWell }) { + const [aviableDateRange, setAviableDateRange] = useState([moment(),moment()]) + const [filterDateRange, setFilterDateRange] = useState([moment().subtract(1, "days"),moment(),]) + const [step, setStep] = useState(timePeriodNames[2].value) + const [format, setFormat] = useState(0) + const [pagesCount, setPagesCount] = useState(0) + const [suitableReports, setSuitableReports] = useState([]) + const [showLoader, setShowLoader] = useState(false) + + const periodOptions = timePeriodNames.map((item) => ( + + )) + + const columns = [ + { + title: "", + dataIndex: "reportFormat", + key: "reportFormat", + render: (format) => ( + {format} + ), + }, + { + title: "Параметры отчета", + dataIndex: "reportParams", + key: "reportParams", + }, + { + title: "Название отчета", + dataIndex: "reportName", + key: "reportName", + render: (reportName) => ( + + ), + }, + ] + + const handleReportCreation = async (values) => { + let begin = aviableDateRange[0].toISOString() + let end = aviableDateRange[1].toISOString() + + try { + const idUser = localStorage["userId"] + + const taskId = await ReportService.createReport( + idWell, + idUser, + 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( + `Не удалось создать отчет по скважине (${idWell}) c + ${aviableDateRange[0].format("DD.MM.YYYY hh:mm:ss")} по + ${aviableDateRange[1].format("DD.MM.YYYY hh:mm:ss")}`, + "error" + ) + console.log(error) + } + } + + const disabledDate = (current) => { + return current < aviableDateRange[0] || current > aviableDateRange[1] + } + + const updateSuitableReports = (suitableReports) => { + const reports = suitableReports?.map(report => { + const creationDate = new Date(report.begin).toLocaleString() + const begin = new Date(report.begin).toLocaleString() + const end = new Date(report.end).toLocaleString() + const step = timePeriodNames[report.step] + const reportParams = `Дата создания: ${creationDate}, Данные от ${begin} до ${end}, Шаг: ${step}` + return { + key: report.id, + reportFormat: report.format, + reportParams: reportParams, + reportName: report.name, + }}) + setSuitableReports(reports??[]) + } + + const updateAviableDatesRange = (aviableDatesRange) =>{ + const datesRange = [ + moment(aviableDatesRange.from), + moment(aviableDatesRange.to) + ] + setAviableDateRange(datesRange) + } + + useEffect(() => invokeWebApiWrapperAsync(async() => { + const aviableDatesRange = await ReportService.getReportsDateRange(idWell) + updateAviableDatesRange(aviableDatesRange) + }), [idWell]) + + useEffect(() => invokeWebApiWrapperAsync(async() => { + if(!filterDateRange || filterDateRange.length < 2) + return + const begin = filterDateRange[0].toISOString() + const end = filterDateRange[1].toISOString() + const pagesCount = await ReportService.getReportSize(idWell, step, format, begin, end) + setPagesCount(pagesCount) + const suitableReports = await ReportService.getSuitableReportsNames(idWell, step, format, begin, end) + updateSuitableReports(suitableReports) + }, + setShowLoader, + `Не удалось получить предварительные параметры отчета c + ${filterDateRange[0].format(dateTimeFormat)} по + ${filterDateRange[1].format(dateTimeFormat)}` + ), [filterDateRange, step, format, idWell]) + + return ( + +
+
+
+ + { + setFilterDateRange(dates) + }} + showTime + /> + + + + + setFormat(e.target.value)} + className="ml-30px" + > + + PDF + LAS + + + +
+
+
+
+

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

{" "} +
+ + + + ) +}