2021-06-07 16:03:50 +05:00
|
|
|
|
import { useState, useEffect } from "react";
|
2021-06-02 12:47:30 +05:00
|
|
|
|
import { useParams } from 'react-router-dom';
|
2021-05-13 13:50:25 +05:00
|
|
|
|
import {
|
2021-06-02 12:47:30 +05:00
|
|
|
|
Form,
|
2021-05-13 13:50:25 +05:00
|
|
|
|
DatePicker,
|
|
|
|
|
Radio,
|
|
|
|
|
Button,
|
|
|
|
|
Select,
|
2021-06-07 16:03:50 +05:00
|
|
|
|
Table,
|
|
|
|
|
Progress,
|
|
|
|
|
notification
|
2021-05-13 13:50:25 +05:00
|
|
|
|
} from 'antd';
|
|
|
|
|
import 'moment/locale/ru';
|
|
|
|
|
import locale from 'antd/lib/locale/ru_RU';
|
2021-05-19 16:05:01 +05:00
|
|
|
|
import moment from "moment";
|
2021-06-04 09:22:25 +05:00
|
|
|
|
import {Subscribe} from '../services/signalr';
|
|
|
|
|
import notify from '../components/notify';
|
|
|
|
|
import LoaderPortal from '../components/LoaderPortal';
|
|
|
|
|
import { ReportService } from '../services/api';
|
2021-05-12 17:53:35 +05:00
|
|
|
|
|
2021-05-13 13:50:25 +05:00
|
|
|
|
const { RangePicker } = DatePicker;
|
|
|
|
|
const { Option } = Select;
|
2021-05-12 17:53:35 +05:00
|
|
|
|
|
2021-06-02 12:47:30 +05:00
|
|
|
|
let reportDatesRange = {
|
|
|
|
|
from: moment("0001-01-01T00:00:00"),
|
|
|
|
|
to: moment("9999-12-31T23:59:59.9999999")
|
|
|
|
|
}
|
2021-05-12 17:53:35 +05:00
|
|
|
|
|
2021-06-04 09:22:25 +05:00
|
|
|
|
const timePeriodNames = {
|
|
|
|
|
600: '1 минута',
|
|
|
|
|
86400:'1 день',
|
|
|
|
|
604800:'1 неделя'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const imgPaths = {
|
|
|
|
|
'.pdf': '/images/pdf.png',
|
|
|
|
|
'.las': '/images/las.png'
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-19 16:05:01 +05:00
|
|
|
|
|
2021-06-02 12:47:30 +05:00
|
|
|
|
// Экспорт рендера
|
|
|
|
|
export default function Report(props) {
|
|
|
|
|
|
2021-06-04 09:22:25 +05:00
|
|
|
|
const [rangeDate, setRangeDate] = useState([moment().subtract(1,'days'), moment()])
|
|
|
|
|
const [step, setStep] = useState(600)
|
|
|
|
|
const [format, setFormat] = useState(0)
|
2021-06-02 12:47:30 +05:00
|
|
|
|
const [approxPages, setPagesCount] = useState(0)
|
|
|
|
|
const [suitableReports, setSuitableReports] = useState([])
|
2021-06-04 09:22:25 +05:00
|
|
|
|
const [loader, setLoader] = useState(false)
|
2021-06-07 16:03:50 +05:00
|
|
|
|
|
|
|
|
|
|
2021-06-02 12:47:30 +05:00
|
|
|
|
let wellId = useParams().id;
|
2021-05-19 16:05:01 +05:00
|
|
|
|
|
2021-06-02 12:47:30 +05:00
|
|
|
|
const columns = [
|
|
|
|
|
{
|
|
|
|
|
title: '',
|
|
|
|
|
dataIndex: 'reportFormat',
|
|
|
|
|
key: 'reportFormat',
|
2021-06-04 09:22:25 +05:00
|
|
|
|
render: format => <img src={imgPaths[format]} width="50" alt={format}></img>
|
2021-06-02 12:47:30 +05:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'Параметры отчета',
|
|
|
|
|
dataIndex: 'reportParams',
|
|
|
|
|
key: 'reportParams',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'Название отчета',
|
|
|
|
|
dataIndex: 'reportName',
|
|
|
|
|
key: 'reportName',
|
2021-07-19 16:19:01 +05:00
|
|
|
|
render: name => <a href='#' onClick={event => getReportFile(event, name)} download={name}>{name}</a>
|
2021-06-02 12:47:30 +05:00
|
|
|
|
},
|
|
|
|
|
];
|
2021-06-07 16:03:50 +05:00
|
|
|
|
|
|
|
|
|
const ReportCreationNotify = ({progressData}) => {
|
|
|
|
|
progressData = progressData ?? {progress: 0.0, operation: 'Создание отчета', reportName: ''}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Progress percent={ progressData.progress } />
|
|
|
|
|
<br />
|
|
|
|
|
<span> { progressData.operation } </span>
|
|
|
|
|
<br />
|
2021-07-19 16:19:01 +05:00
|
|
|
|
<a href='#' onClick={event => {getReportFile(event, progressData.reportName)}}
|
2021-06-09 17:25:54 +05:00
|
|
|
|
download={progressData.reportName}>
|
2021-06-07 16:03:50 +05:00
|
|
|
|
{ progressData.reportName }
|
|
|
|
|
</a>
|
|
|
|
|
</>
|
|
|
|
|
)
|
|
|
|
|
}
|
2021-05-12 17:53:35 +05:00
|
|
|
|
|
2021-06-07 16:03:50 +05:00
|
|
|
|
const getReportFile = async (event, reportFileName) => {
|
2021-06-09 17:25:54 +05:00
|
|
|
|
const element = event.target
|
|
|
|
|
|
|
|
|
|
if(!element.href.length) {
|
|
|
|
|
try {
|
|
|
|
|
await fetch(`/api/report/${wellId}/${reportFileName}`, {
|
|
|
|
|
headers: {
|
|
|
|
|
Authorization: 'Bearer ' + localStorage['token']
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.then(async (response) => {
|
|
|
|
|
const blob = await response.blob();
|
|
|
|
|
|
|
|
|
|
let reader = new FileReader();
|
|
|
|
|
reader.readAsDataURL(blob);
|
|
|
|
|
reader.onload = function (e) {
|
|
|
|
|
element.href = e.target.result
|
|
|
|
|
element.click()
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
} 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)
|
|
|
|
|
}
|
2021-06-04 09:22:25 +05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleReportCreation = async (values) => {
|
2021-06-02 12:47:30 +05:00
|
|
|
|
let begin = rangeDate[0].toISOString()
|
|
|
|
|
let end = rangeDate[1].toISOString()
|
2021-06-07 16:03:50 +05:00
|
|
|
|
|
|
|
|
|
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: <ReportCreationNotify progressData={progressData}></ReportCreationNotify>,
|
|
|
|
|
duration: 0
|
|
|
|
|
});
|
|
|
|
|
|
2021-06-07 18:12:21 +05:00
|
|
|
|
if (progressData.reportName?.length)
|
2021-06-07 16:03:50 +05:00
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-13 13:50:25 +05:00
|
|
|
|
|
2021-05-19 16:05:01 +05:00
|
|
|
|
function disabledDate(current) {
|
2021-06-02 12:47:30 +05:00
|
|
|
|
return reportDatesRange.From >= current || reportDatesRange.To <= current;
|
2021-05-19 16:05:01 +05:00
|
|
|
|
}
|
2021-05-13 13:50:25 +05:00
|
|
|
|
|
2021-06-02 12:47:30 +05:00
|
|
|
|
useEffect(()=>{
|
|
|
|
|
async function getRepostSizeAsync() {
|
|
|
|
|
let begin = rangeDate[0].toISOString()
|
|
|
|
|
let end = rangeDate[1].toISOString()
|
2021-06-04 09:22:25 +05:00
|
|
|
|
try {
|
|
|
|
|
let approxPagesResponse = await ReportService.getReportSize(wellId, step, format, begin, end)
|
|
|
|
|
setPagesCount(approxPagesResponse)
|
2021-06-04 10:13:40 +05:00
|
|
|
|
} catch(error) {
|
|
|
|
|
notify(`Не удалось получить предварительный размер отчета c
|
|
|
|
|
${rangeDate[0].format("DD.MM.YYYY hh:mm:ss")} по
|
|
|
|
|
${rangeDate[1].format("DD.MM.YYYY hh:mm:ss")}`, 'error')
|
2021-06-07 16:03:50 +05:00
|
|
|
|
console.log(error)
|
2021-06-04 10:13:40 +05:00
|
|
|
|
} finally {
|
|
|
|
|
setLoader(false)
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-04 09:22:25 +05:00
|
|
|
|
|
2021-06-04 10:13:40 +05:00
|
|
|
|
getRepostSizeAsync()
|
2021-07-19 16:19:01 +05:00
|
|
|
|
},[rangeDate, step, format, wellId])
|
2021-06-04 10:13:40 +05:00
|
|
|
|
|
|
|
|
|
useEffect(()=>{
|
|
|
|
|
async function getSuitableReportsAsync() {
|
|
|
|
|
let begin = rangeDate[0].toISOString()
|
|
|
|
|
let end = rangeDate[1].toISOString()
|
|
|
|
|
try {
|
2021-06-04 09:22:25 +05:00
|
|
|
|
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) {
|
2021-06-04 10:13:40 +05:00
|
|
|
|
notify(`Не удалось получить подходящие по параметрам отчеты c
|
2021-06-04 09:22:25 +05:00
|
|
|
|
${rangeDate[0].format("DD.MM.YYYY hh:mm:ss")} по
|
|
|
|
|
${rangeDate[1].format("DD.MM.YYYY hh:mm:ss")}`, 'error')
|
2021-06-07 16:03:50 +05:00
|
|
|
|
console.log(error)
|
2021-06-04 09:22:25 +05:00
|
|
|
|
} finally {
|
|
|
|
|
setLoader(false)
|
|
|
|
|
}
|
2021-06-02 12:47:30 +05:00
|
|
|
|
}
|
2021-05-13 13:50:25 +05:00
|
|
|
|
|
2021-06-04 10:13:40 +05:00
|
|
|
|
getSuitableReportsAsync()
|
2021-07-19 16:19:01 +05:00
|
|
|
|
},[rangeDate, step, format, wellId])
|
2021-05-13 13:50:25 +05:00
|
|
|
|
|
2021-06-02 12:47:30 +05:00
|
|
|
|
useEffect(()=>{
|
|
|
|
|
async function getDatesRange() {
|
|
|
|
|
let response = await ReportService.getReportsDateRange(wellId)
|
|
|
|
|
reportDatesRange.from = moment(response.from)
|
|
|
|
|
reportDatesRange.to = moment(response.to)
|
|
|
|
|
}
|
2021-05-13 13:50:25 +05:00
|
|
|
|
|
2021-06-02 12:47:30 +05:00
|
|
|
|
getDatesRange()
|
2021-07-19 16:19:01 +05:00
|
|
|
|
},[wellId])
|
2021-05-13 13:50:25 +05:00
|
|
|
|
|
|
|
|
|
return (<>
|
2021-06-07 16:03:50 +05:00
|
|
|
|
<div className="w-100 mt-20px">
|
|
|
|
|
<Form
|
|
|
|
|
layout="vertical"
|
|
|
|
|
name="reportForm"
|
|
|
|
|
initialValues={{ remember: true }}
|
|
|
|
|
onFinish={handleReportCreation}
|
|
|
|
|
>
|
|
|
|
|
<div className={'d-flex'}>
|
|
|
|
|
<Form.Item
|
|
|
|
|
label="Диапазон дат отчета"
|
|
|
|
|
name="period"
|
|
|
|
|
initialValue = { [rangeDate[0], rangeDate[1]] }
|
|
|
|
|
>
|
|
|
|
|
<RangePicker
|
|
|
|
|
disabledDate={disabledDate}
|
|
|
|
|
allowClear={false}
|
|
|
|
|
onCalendarChange = { (dates, dateStrings, info) => {
|
|
|
|
|
setRangeDate([moment(dateStrings[0]), moment(dateStrings[1])])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
locale={locale}
|
|
|
|
|
showTime
|
|
|
|
|
/>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
<Form.Item
|
|
|
|
|
label="Шаг графиков"
|
|
|
|
|
name="step"
|
|
|
|
|
initialValue = {step}
|
|
|
|
|
className="ml-30px"
|
|
|
|
|
>
|
|
|
|
|
<Select
|
|
|
|
|
onChange={(value) => setStep(value)}
|
|
|
|
|
>
|
|
|
|
|
<Option value={600}>1 минута</Option>
|
|
|
|
|
<Option value={86400}>1 день</Option>
|
|
|
|
|
<Option value={604800}>1 неделя</Option>
|
|
|
|
|
</Select>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
<Form.Item
|
|
|
|
|
label="Формат отчета"
|
|
|
|
|
name="format"
|
|
|
|
|
initialValue = {format}
|
|
|
|
|
onChange={(e) => setFormat(e.target.value)}
|
|
|
|
|
className="ml-30px"
|
2021-06-02 12:47:30 +05:00
|
|
|
|
>
|
2021-06-07 16:03:50 +05:00
|
|
|
|
<Radio.Group>
|
|
|
|
|
<Radio.Button value={0}>PDF</Radio.Button>
|
|
|
|
|
<Radio.Button value={1}>LAS</Radio.Button>
|
|
|
|
|
</Radio.Group>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
<Button
|
|
|
|
|
type="primary"
|
|
|
|
|
htmlType="submit"
|
|
|
|
|
className="mt-30px ml-30px">
|
|
|
|
|
<span>Получить рапорт</span>
|
|
|
|
|
<span className={'ml-5px'}>
|
|
|
|
|
({approxPages} стр.)
|
|
|
|
|
</span>
|
|
|
|
|
<span style={{display: approxPages > 100 ? 'inline' : 'none'}} className={'ml-5px'}>
|
|
|
|
|
!!!
|
|
|
|
|
</span>
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</Form>
|
|
|
|
|
</div>
|
2021-06-02 12:47:30 +05:00
|
|
|
|
<br/>
|
2021-06-04 09:22:25 +05:00
|
|
|
|
<h3>
|
2021-06-02 12:47:30 +05:00
|
|
|
|
Отчеты с аналогичными параметрами, доступные для скачивания:
|
2021-06-04 09:22:25 +05:00
|
|
|
|
</h3> <br/>
|
2021-05-13 13:50:25 +05:00
|
|
|
|
|
2021-06-04 09:22:25 +05:00
|
|
|
|
<LoaderPortal show={loader}>
|
|
|
|
|
<Table dataSource={suitableReports} columns={columns} />
|
|
|
|
|
</LoaderPortal>
|
2021-05-13 13:50:25 +05:00
|
|
|
|
</>
|
|
|
|
|
)
|
|
|
|
|
}
|