Files
smeta-web/static/batch.html
T
anorandClaude Opus 4.6 4d52c53702 feat: пакетная обработка смет (batch processor)
Новая страница /batch для массовых операций с файлами:
1. Загрузка zip со сметами + сводный файл
2. GLM-5 анализирует 3 примера → генерирует Python-скрипт
3. Пользователь подтверждает алгоритм
4. Скрипт обрабатывает ВСЕ файлы без LLM

- batch.py: XML-чтение xlsx, LLM-анализ, exec скрипта
- static/batch.html: UI с прогрессом и скачиванием результата
- Кнопка "Пакетная" в шапке чата

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 19:26:55 +10:00

158 lines
7.8 KiB
HTML

<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Пакетная обработка смет</title>
<style>
:root { --bg: #f5f0eb; --card: #fff; --text: #3a3a3a; --muted: #6b6b6b; --accent: #c4463a; --border: #d4c5b2; --radius: 10px; }
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', -apple-system, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; padding: 2rem; }
.container { max-width: 700px; margin: 0 auto; }
h1 { font-size: 1.3rem; margin-bottom: .3rem; }
.subtitle { color: var(--muted); font-size: .9rem; margin-bottom: 1.5rem; }
.card { background: var(--card); border-radius: var(--radius); padding: 1.5rem; margin-bottom: 1rem; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
label { display: block; font-weight: 600; margin-bottom: .4rem; font-size: .9rem; }
.hint { color: var(--muted); font-size: .8rem; margin-bottom: .6rem; }
input[type=file] { width: 100%; padding: .5rem; border: 1.5px dashed var(--border); border-radius: var(--radius); margin-bottom: 1rem; }
textarea { width: 100%; padding: .6rem; border: 1.5px solid var(--border); border-radius: var(--radius); font-family: inherit; font-size: .9rem; resize: vertical; min-height: 60px; }
button { padding: .7rem 1.5rem; background: var(--accent); color: #fff; border: none; border-radius: var(--radius); font-size: .95rem; font-weight: 600; cursor: pointer; }
button:hover { background: #a83830; }
button:disabled { background: var(--border); cursor: not-allowed; }
.back { display: inline-block; margin-bottom: 1rem; color: var(--accent); text-decoration: none; font-size: .85rem; }
#status { display: none; }
#analysis { display: none; }
.progress { background: #ede5db; border-radius: 6px; height: 8px; margin: .5rem 0; }
.progress-bar { background: var(--accent); height: 100%; border-radius: 6px; transition: width .3s; }
.error-list { color: #c4463a; font-size: .8rem; margin-top: .5rem; }
pre { background: #2c2c2c; color: #f5f0eb; padding: .8rem; border-radius: 6px; overflow-x: auto; font-size: .8rem; margin: .5rem 0; }
</style>
</head>
<body>
<div class="container">
<a class="back" href="/">← Вернуться в чат</a>
<h1>Пакетная обработка смет</h1>
<p class="subtitle">Загрузите архив со сметами и сводный файл — ИИ проанализирует структуру и перенесёт данные</p>
<div class="card" id="upload-form">
<label>Архив со сметами (.zip)</label>
<p class="hint">Все файлы локальных смет в одном архиве</p>
<input type="file" id="zip-file" accept=".zip">
<label>Сводный файл (.xlsx)</label>
<p class="hint">Файл, в который нужно внести данные (ССР, ведомость и т.д.)</p>
<input type="file" id="target-file" accept=".xlsx,.xls">
<label>Описание задачи</label>
<textarea id="task-desc" placeholder="Например: Из каждой сметы взять итого строительных работ (тыс.руб.) и внести в соответствующую строку ССР"></textarea>
<br><br>
<button onclick="startBatch()">Анализировать</button>
</div>
<div class="card" id="analysis">
<h3>Результат анализа</h3>
<p id="analysis-desc"></p>
<details>
<summary>Сгенерированный скрипт</summary>
<pre id="analysis-script"></pre>
</details>
<p id="analysis-files" style="margin:.5rem 0;color:var(--muted);font-size:.85rem"></p>
<button onclick="runBatch()">Запустить обработку</button>
</div>
<div class="card" id="status">
<h3>Обработка</h3>
<p id="status-text"></p>
<div class="progress"><div class="progress-bar" id="progress-bar" style="width:0%"></div></div>
<p id="status-count" style="font-size:.85rem;color:var(--muted)"></p>
<div class="error-list" id="error-list"></div>
<button id="download-btn" style="display:none" onclick="downloadResult()">Скачать результат</button>
</div>
</div>
<script>
const API = '';
let token = localStorage.getItem('token');
let jobId = null;
if (!token) { window.location.href = '/'; }
function authHeaders() { return {'Authorization': 'Bearer ' + token}; }
async function startBatch() {
const zipFile = document.getElementById('zip-file').files[0];
const targetFile = document.getElementById('target-file').files[0];
const taskDesc = document.getElementById('task-desc').value;
if (!zipFile || !targetFile) { alert('Загрузите оба файла'); return; }
const fd = new FormData();
fd.append('zip_file', zipFile);
fd.append('target_file', targetFile);
fd.append('task_description', taskDesc || 'Перенести итоги из смет в сводный файл');
document.querySelector('#upload-form button').disabled = true;
document.querySelector('#upload-form button').textContent = 'Анализирую...';
try {
const r = await fetch(API + '/api/batch/upload', {method: 'POST', headers: authHeaders(), body: fd});
if (r.status === 401) { window.location.href = '/'; return; }
const data = await r.json();
if (data.analysis?.error) { alert('Ошибка: ' + data.analysis.error); return; }
jobId = data.job_id;
document.getElementById('analysis-desc').textContent = data.analysis.description || 'Анализ завершён';
document.getElementById('analysis-script').textContent = data.analysis.python_script || '(нет скрипта)';
document.getElementById('analysis-files').textContent = 'Файлов: ' + data.total_files;
document.getElementById('analysis').style.display = 'block';
} catch(e) { alert('Ошибка: ' + e.message); }
finally {
document.querySelector('#upload-form button').disabled = false;
document.querySelector('#upload-form button').textContent = 'Анализировать';
}
}
async function runBatch() {
if (!jobId) return;
document.querySelector('#analysis button').disabled = true;
const r = await fetch(API + '/api/batch/run/' + jobId, {method: 'POST', headers: authHeaders()});
if (!r.ok) { alert('Ошибка запуска'); return; }
document.getElementById('status').style.display = 'block';
pollStatus();
}
async function pollStatus() {
const r = await fetch(API + '/api/batch/status/' + jobId, {headers: authHeaders()});
const data = await r.json();
const pct = data.total > 0 ? (data.processed / data.total * 100) : 0;
document.getElementById('progress-bar').style.width = pct + '%';
document.getElementById('status-count').textContent = data.processed + ' / ' + data.total + ' файлов';
if (data.status === 'running') {
document.getElementById('status-text').textContent = 'Обработка...';
setTimeout(pollStatus, 2000);
} else if (data.status === 'completed') {
document.getElementById('status-text').textContent = 'Готово!';
document.getElementById('download-btn').style.display = 'inline-block';
} else if (data.status === 'failed') {
document.getElementById('status-text').textContent = 'Ошибка: ' + (data.errors[0] || 'неизвестная');
}
if (data.errors.length > 0) {
document.getElementById('error-list').innerHTML = '<b>Ошибки:</b><br>' + data.errors.map(e => '• ' + e).join('<br>');
}
}
function downloadResult() {
const a = document.createElement('a');
a.href = API + '/api/batch/download/' + jobId;
fetch(a.href, {headers: authHeaders()}).then(r => r.blob()).then(b => {
const u = URL.createObjectURL(b);
const l = document.createElement('a'); l.href = u; l.download = 'result.xlsx'; l.click();
});
}
</script>
</body>
</html>