liujie
2026-06-25 4e8da8055692c845345f48e891850b6a685977be
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>报告下载与图片预览</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
 
        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 20px;
        }
 
        .container {
            max-width: 1200px;
            margin: 0 auto;
            background: white;
            border-radius: 10px;
            box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
            overflow: hidden;
        }
 
        .header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 30px;
            text-align: center;
        }
 
        .header h1 {
            font-size: 32px;
            margin-bottom: 10px;
        }
 
        .header p {
            font-size: 16px;
            opacity: 0.9;
        }
 
        .content {
            padding: 30px;
        }
 
        .section {
            margin-bottom: 30px;
        }
 
        .section-title {
            font-size: 20px;
            color: #333;
            margin-bottom: 15px;
            padding-bottom: 10px;
            border-bottom: 2px solid #667eea;
        }
 
        .form-group {
            margin-bottom: 15px;
        }
 
        .form-group label {
            display: block;
            margin-bottom: 5px;
            color: #555;
            font-weight: bold;
        }
 
        .form-group input {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-size: 14px;
        }
 
        .form-group input:focus {
            outline: none;
            border-color: #667eea;
        }
 
        .btn-group {
            display: flex;
            gap: 10px;
            margin-top: 20px;
        }
 
        .btn {
            flex: 1;
            padding: 12px 24px;
            border: none;
            border-radius: 5px;
            font-size: 16px;
            cursor: pointer;
            transition: all 0.3s;
        }
 
        .btn-primary {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }
 
        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
        }
 
        .btn-secondary {
            background: #6c757d;
            color: white;
        }
 
        .btn-secondary:hover {
            background: #5a6268;
        }
 
        .btn:disabled {
            opacity: 0.5;
            cursor: not-allowed;
        }
 
        .status-box {
            background: #f8f9fa;
            border-left: 4px solid #667eea;
            padding: 15px;
            margin-top: 15px;
            border-radius: 5px;
        }
 
        .status-box p {
            margin: 5px 0;
            color: #555;
        }
 
        .status-box .label {
            font-weight: bold;
            color: #333;
        }
 
        .image-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
            gap: 20px;
            margin-top: 20px;
        }
 
        .image-card {
            background: white;
            border: 1px solid #ddd;
            border-radius: 8px;
            overflow: hidden;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
            transition: transform 0.3s;
        }
 
        .image-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
        }
 
        .image-card img {
            width: 100%;
            height: auto;
            display: block;
        }
 
        .image-card .image-info {
            padding: 10px;
            text-align: center;
            background: #f8f9fa;
        }
 
        .loading {
            text-align: center;
            padding: 40px;
            color: #667eea;
        }
 
        .loading::after {
            content: '...';
            animation: dots 1.5s steps(4, end) infinite;
        }
 
        @keyframes dots {
            0%, 20% { content: '.'; }
            40% { content: '..'; }
            60%, 100% { content: '...'; }
        }
 
        .alert {
            padding: 12px 20px;
            border-radius: 5px;
            margin-top: 15px;
        }
 
        .alert-success {
            background: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }
 
        .alert-error {
            background: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }
 
        .alert-info {
            background: #d1ecf1;
            color: #0c5460;
            border: 1px solid #bee5eb;
        }
 
        .progress-bar {
            width: 100%;
            height: 30px;
            background: #f0f0f0;
            border-radius: 15px;
            overflow: hidden;
            margin-top: 15px;
        }
 
        .progress-bar-fill {
            height: 100%;
            background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
            transition: width 0.3s;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-weight: bold;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>📄 报告下载与图片预览系统</h1>
            <p>下载Word报告并自动转换为高清图片</p>
        </div>
 
        <div class="content">
            <!-- 下载表单 -->
            <div class="section">
                <h2 class="section-title">1️⃣ 下载报告</h2>
                <div class="form-group">
                    <label for="checkTaskId">检查任务ID:</label>
                    <input type="number" id="checkTaskId" value="1" placeholder="请输入检查任务ID">
                </div>
                <div class="form-group">
                    <label for="templateId">报告模板ID:</label>
                    <input type="number" id="templateId" value="1" placeholder="请输入报告模板ID">
                </div>
                <div class="form-group">
                    <label for="uuid">文件UUID (自动生成):</label>
                    <input type="text" id="uuid" readonly placeholder="点击下载按钮自动生成">
                </div>
                <div class="btn-group">
                    <button class="btn btn-primary" onclick="downloadOnly()">仅下载</button>
                    <button class="btn btn-primary" onclick="downloadAndConvert()">下载并转图片</button>
                </div>
            </div>
 
            <!-- 转换状态 -->
            <div class="section" id="statusSection" style="display: none;">
                <h2 class="section-title">2️⃣ 转换状态</h2>
                <div class="progress-bar">
                    <div class="progress-bar-fill" id="progressBar" style="width: 0%;">0%</div>
                </div>
                <div class="status-box" id="statusBox">
                    <p><span class="label">UUID:</span> <span id="statusUuid">-</span></p>
                    <p><span class="label">Word文件:</span> <span id="statusWord">-</span></p>
                    <p><span class="label">图片数量:</span> <span id="statusImages">-</span></p>
                    <p><span class="label">转换状态:</span> <span id="statusConversion">-</span></p>
                </div>
            </div>
 
            <!-- 图片预览 -->
            <div class="section" id="imageSection" style="display: none;">
                <h2 class="section-title">3️⃣ 图片预览</h2>
                <div id="imageContainer"></div>
            </div>
 
            <!-- 消息提示 -->
            <div id="messageContainer"></div>
        </div>
    </div>
 
    <script>
        const API_BASE = 'http://localhost:8080';
 
        // 生成UUID
        function generateUUID() {
            return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
                const r = Math.random() * 16 | 0;
                const v = c === 'x' ? r : (r & 0x3 | 0x8);
                return v.toString(16);
            });
        }
 
        // 显示消息
        function showMessage(message, type = 'info') {
            const container = document.getElementById('messageContainer');
            const alert = document.createElement('div');
            alert.className = `alert alert-${type}`;
            alert.textContent = message;
            container.appendChild(alert);
 
            setTimeout(() => {
                alert.remove();
            }, 5000);
        }
 
        // 仅下载
        function downloadOnly() {
            const checkTaskId = document.getElementById('checkTaskId').value;
            const templateId = document.getElementById('templateId').value;
 
            if (!checkTaskId || !templateId) {
                showMessage('请填写检查任务ID和报告模板ID', 'error');
                return;
            }
 
            const url = `${API_BASE}/admin/stat/report/fuzzyReport?checkTaskId=${checkTaskId}&templateId=${templateId}`;
            window.location.href = url;
            showMessage('开始下载报告...', 'success');
        }
 
        // 下载并转换
        async function downloadAndConvert() {
            const checkTaskId = document.getElementById('checkTaskId').value;
            const templateId = document.getElementById('templateId').value;
 
            if (!checkTaskId || !templateId) {
                showMessage('请填写检查任务ID和报告模板ID', 'error');
                return;
            }
 
            // 生成UUID
            const uuid = generateUUID();
            document.getElementById('uuid').value = uuid;
 
            // 显示状态区域
            document.getElementById('statusSection').style.display = 'block';
            document.getElementById('imageSection').style.display = 'none';
            document.getElementById('statusUuid').textContent = uuid;
 
            // 开始下载
            const url = `${API_BASE}/admin/stat/report/fuzzyReport?checkTaskId=${checkTaskId}&templateId=${templateId}&uuid=${uuid}`;
            window.location.href = url;
            showMessage('开始下载报告并转换为图片...', 'success');
 
            // 等待转换完成
            await waitForConversion(uuid);
        }
 
        // 等待转换完成
        async function waitForConversion(uuid, maxAttempts = 30, interval = 2000) {
            let progress = 0;
            const progressBar = document.getElementById('progressBar');
 
            for (let i = 0; i < maxAttempts; i++) {
                try {
                    const response = await fetch(`${API_BASE}/admin/stat/report/checkConversionStatus?uuid=${uuid}`);
                    const result = await response.json();
 
                    if (result.code === 0) {
                        const status = result.data;
 
                        // 更新状态显示
                        document.getElementById('statusWord').textContent = status.wordFileExists ? '✅ 已保存' : '❌ 未保存';
                        document.getElementById('statusImages').textContent = status.imageCount + ' 张';
                        document.getElementById('statusConversion').textContent = status.conversionCompleted ? '✅ 已完成' : '⏳ 转换中...';
 
                        // 更新进度条
                        progress = Math.min(100, (i + 1) * (100 / maxAttempts));
                        progressBar.style.width = progress + '%';
                        progressBar.textContent = Math.round(progress) + '%';
 
                        if (status.conversionCompleted) {
                            progressBar.style.width = '100%';
                            progressBar.textContent = '100%';
                            showMessage(`转换完成!共生成 ${status.imageCount} 张图片`, 'success');
                            await loadImages(uuid);
                            return;
                        }
                    }
                } catch (error) {
                    console.error('检查状态失败:', error);
                }
 
                await new Promise(resolve => setTimeout(resolve, interval));
            }
 
            showMessage('转换超时,请稍后手动查询', 'error');
        }
 
        // 加载图片
        async function loadImages(uuid) {
            try {
                const response = await fetch(`${API_BASE}/admin/stat/report/getReportImages?uuid=${uuid}`);
                const result = await response.json();
 
                if (result.code === 0 && result.data.length > 0) {
                    const imageSection = document.getElementById('imageSection');
                    const imageContainer = document.getElementById('imageContainer');
 
                    imageSection.style.display = 'block';
                    imageContainer.innerHTML = '<div class="image-grid"></div>';
                    const grid = imageContainer.querySelector('.image-grid');
 
                    result.data.forEach((filename, index) => {
                        const card = document.createElement('div');
                        card.className = 'image-card';
 
                        const img = document.createElement('img');
                        img.src = `${API_BASE}/files/reports/images/${filename}`;
                        img.alt = `第 ${index + 1} 页`;
                        img.loading = 'lazy';
 
                        const info = document.createElement('div');
                        info.className = 'image-info';
                        info.textContent = `第 ${index + 1} 页`;
 
                        card.appendChild(img);
                        card.appendChild(info);
                        grid.appendChild(card);
                    });
 
                    showMessage(`成功加载 ${result.data.length} 张图片`, 'success');
                } else {
                    showMessage('未找到图片文件', 'error');
                }
            } catch (error) {
                console.error('加载图片失败:', error);
                showMessage('加载图片失败: ' + error.message, 'error');
            }
        }
 
        // 页面加载完成
        window.onload = function() {
            showMessage('系统已就绪,请选择操作', 'info');
        };
    </script>
</body>
</html>