2021-06-02 12:47:30 +05:00
|
|
|
|
import React, { useState, useEffect } from "react";
|
|
|
|
|
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-02 12:47:30 +05:00
|
|
|
|
Table
|
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)
|
|
|
|
|
const [reportProgress, setReportProgress] = useState(0.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-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-06-04 09:22:25 +05:00
|
|
|
|
render: name => <a href="" download={name}>{name}</a>
|
2021-06-02 12:47:30 +05:00
|
|
|
|
},
|
|
|
|
|
];
|
2021-05-12 17:53:35 +05:00
|
|
|
|
|
2021-06-04 09:22:25 +05:00
|
|
|
|
const handleReportProgress = (data) => {
|
|
|
|
|
console.log('data: ' + data)
|
|
|
|
|
if(data) {
|
|
|
|
|
setReportProgress(data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log('reportProgress: ' + reportProgress)
|
|
|
|
|
//console.log(data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleReportCreation = async (values) => {
|
2021-06-02 12:47:30 +05:00
|
|
|
|
let begin = rangeDate[0].toISOString()
|
|
|
|
|
let end = rangeDate[1].toISOString()
|
2021-06-04 09:22:25 +05:00
|
|
|
|
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)
|
|
|
|
|
})
|
|
|
|
|
|
2021-06-02 12:47:30 +05:00
|
|
|
|
};
|
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')
|
|
|
|
|
console.error(error)
|
|
|
|
|
} finally {
|
|
|
|
|
setLoader(false)
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-04 09:22:25 +05:00
|
|
|
|
|
2021-06-04 10:13:40 +05:00
|
|
|
|
getRepostSizeAsync()
|
|
|
|
|
},[rangeDate, step, format])
|
|
|
|
|
|
|
|
|
|
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')
|
|
|
|
|
console.error(error)
|
|
|
|
|
} 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-06-02 12:47:30 +05:00
|
|
|
|
},[rangeDate, step, format])
|
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-06-04 09:22:25 +05:00
|
|
|
|
//return ()=>{uns && uns()}
|
2021-06-02 12:47:30 +05:00
|
|
|
|
},[])
|
2021-05-13 13:50:25 +05:00
|
|
|
|
|
|
|
|
|
return (<>
|
2021-06-02 12:47:30 +05:00
|
|
|
|
<Form
|
|
|
|
|
layout="vertical"
|
|
|
|
|
name="reportForm"
|
|
|
|
|
initialValues={{ remember: true }}
|
|
|
|
|
onFinish={handleReportCreation}
|
|
|
|
|
style={{marginTop:'20px'}}
|
|
|
|
|
>
|
|
|
|
|
<div style={{display: 'flex'}}>
|
|
|
|
|
<Form.Item
|
|
|
|
|
label="Выбор за период времени и расширение файла"
|
|
|
|
|
name="period"
|
2021-06-04 09:22:25 +05:00
|
|
|
|
initialValue = { [rangeDate[0], rangeDate[1]] }
|
2021-06-02 12:47:30 +05:00
|
|
|
|
>
|
|
|
|
|
<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"
|
2021-06-04 09:22:25 +05:00
|
|
|
|
initialValue = {step}
|
2021-06-02 12:47:30 +05:00
|
|
|
|
style={{marginLeft: '30px'}}
|
|
|
|
|
>
|
|
|
|
|
<Select
|
|
|
|
|
onChange={(value) => setStep(value)}
|
|
|
|
|
style={{ width: 100 }}
|
|
|
|
|
>
|
|
|
|
|
<Option value={600}>1 минута</Option>
|
|
|
|
|
<Option value={86400}>1 день</Option>
|
|
|
|
|
<Option value={604800}>1 неделя</Option>
|
|
|
|
|
</Select>
|
|
|
|
|
</Form.Item>
|
|
|
|
|
<Form.Item
|
|
|
|
|
label="Формат отчета"
|
|
|
|
|
name="format"
|
2021-06-04 09:22:25 +05:00
|
|
|
|
initialValue = {format}
|
2021-06-02 12:47:30 +05:00
|
|
|
|
onChange={(e) => setFormat(e.target.value)}
|
|
|
|
|
style={{marginLeft: '30px'}}
|
|
|
|
|
>
|
|
|
|
|
<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="submit_button"
|
|
|
|
|
style={{marginTop: '30px', marginLeft: '30px'}}>
|
|
|
|
|
<span>Получить рапорт</span>
|
|
|
|
|
<span style={{marginLeft: '5px'}}>
|
|
|
|
|
({approxPages} стр.)
|
|
|
|
|
</span>
|
|
|
|
|
<span style={{display: approxPages > 100 ? 'inline' : 'none' ,marginLeft: '5px'}}>
|
|
|
|
|
!!!
|
|
|
|
|
</span>
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</Form>
|
|
|
|
|
<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
|
|
|
|
</>
|
|
|
|
|
)
|
|
|
|
|
}
|