| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- <!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>
- body {
- font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
- max-width: 1200px;
- margin: 0 auto;
- padding: 20px;
- background: #f5f5f5;
- }
- .container {
- background: white;
- padding: 30px;
- border-radius: 8px;
- box-shadow: 0 2px 8px rgba(0,0,0,0.1);
- }
- h1 {
- color: #333;
- border-bottom: 3px solid #1890ff;
- padding-bottom: 10px;
- }
- .section {
- margin: 20px 0;
- padding: 15px;
- background: #fafafa;
- border-left: 4px solid #1890ff;
- border-radius: 4px;
- }
- .input-group {
- margin: 15px 0;
- }
- label {
- display: block;
- margin-bottom: 5px;
- font-weight: 600;
- color: #555;
- }
- input, select {
- width: 100%;
- padding: 10px;
- border: 1px solid #d9d9d9;
- border-radius: 4px;
- font-size: 14px;
- box-sizing: border-box;
- }
- button {
- background: #1890ff;
- color: white;
- border: none;
- padding: 12px 24px;
- border-radius: 4px;
- cursor: pointer;
- font-size: 14px;
- font-weight: 600;
- margin-right: 10px;
- margin-top: 10px;
- }
- button:hover {
- background: #40a9ff;
- }
- button:disabled {
- background: #d9d9d9;
- cursor: not-allowed;
- }
- .results {
- margin-top: 20px;
- }
- .result-box {
- background: white;
- border: 1px solid #e8e8e8;
- padding: 15px;
- margin: 10px 0;
- border-radius: 4px;
- white-space: pre-wrap;
- font-family: 'Courier New', monospace;
- font-size: 12px;
- max-height: 400px;
- overflow-y: auto;
- }
- .success {
- color: #52c41a;
- font-weight: 600;
- }
- .error {
- color: #ff4d4f;
- font-weight: 600;
- }
- .warning {
- color: #faad14;
- font-weight: 600;
- }
- .info {
- color: #1890ff;
- font-weight: 600;
- }
- .stat {
- display: inline-block;
- background: #e6f7ff;
- padding: 5px 15px;
- margin: 5px 5px 5px 0;
- border-radius: 20px;
- font-size: 13px;
- font-weight: 600;
- color: #0050b3;
- }
- </style>
- </head>
- <body>
- <div class="container">
- <h1>🔍 文档重复检查工具</h1>
-
- <div class="section">
- <h3>步骤 1: 从数据库获取文档</h3>
- <div class="input-group">
- <label>后端 API 地址:</label>
- <input type="text" id="apiBase" value="http://192.168.0.195:8000" />
- </div>
- <div class="input-group">
- <label>文档 ID:</label>
- <input type="text" id="documentId" placeholder="例如: doc-7791bc371ad7" />
- </div>
- <button onclick="fetchDocument()">获取文档</button>
- <button onclick="fetchLatestDocument()">获取最新文档</button>
- </div>
- <div class="section">
- <h3>步骤 2: 检查导出的Word文件</h3>
- <div class="input-group">
- <label>导出记录 ID:</label>
- <input type="text" id="recordId" placeholder="例如: rec-xxx" />
- </div>
- <div class="input-group">
- <label>用户 ID:</label>
- <input type="text" id="userId" value="default-user" />
- </div>
- <button onclick="checkExportedWord()">下载并检查Word文件</button>
- </div>
- <div id="results" class="results"></div>
- </div>
- <script>
- const API_BASE = () => document.getElementById('apiBase').value;
- function showResult(message, type = 'info') {
- const results = document.getElementById('results');
- const box = document.createElement('div');
- box.className = 'result-box';
- box.innerHTML = `<span class="${type}">[${type.toUpperCase()}]</span> ${message}`;
- results.appendChild(box);
- results.scrollTop = results.scrollHeight;
- }
- async function fetchLatestDocument() {
- showResult('正在获取最新文档...', 'info');
-
- try {
- const response = await fetch(`${API_BASE()}/api/v1/documents?userId=default-user&page=1&pageSize=1&sortBy=createdAt&sortOrder=desc`);
-
- if (!response.ok) {
- throw new Error(`HTTP ${response.status}: ${response.statusText}`);
- }
- const data = await response.json();
-
- if (data.code === 200 && data.data.documents.length > 0) {
- const doc = data.data.documents[0];
- document.getElementById('documentId').value = doc.id;
- showResult(`最新文档 ID: ${doc.id}`, 'success');
-
- // 自动获取文档详情
- await fetchDocument();
- } else {
- showResult('未找到文档', 'warning');
- }
- } catch (error) {
- showResult(`错误: ${error.message}`, 'error');
- }
- }
- async function fetchDocument() {
- const docId = document.getElementById('documentId').value;
-
- if (!docId) {
- showResult('请输入文档ID', 'warning');
- return;
- }
- showResult(`正在获取文档 ${docId}...`, 'info');
-
- try {
- const response = await fetch(`${API_BASE()}/api/v1/documents/${docId}`);
-
- if (!response.ok) {
- throw new Error(`HTTP ${response.status}: ${response.statusText}`);
- }
- const data = await response.json();
-
- if (data.code === 200) {
- const doc = data.data;
- const content = doc.content;
-
- showResult(`文档ID: ${doc.id}`, 'info');
- showResult(`格式: ${doc.format}`, 'info');
- showResult(`创建时间: ${new Date(doc.createdAt).toLocaleString()}`, 'info');
-
- // 统计信息
- const totalLength = content.length;
- const lines = content.split('\n');
- const totalLines = lines.length;
-
- showResult(`
- <span class="stat">总长度: ${totalLength} 字符</span>
- <span class="stat">总行数: ${totalLines} 行</span>
- `, 'info');
-
- // 检查是否有重复
- const halfLength = Math.floor(totalLength / 2);
- const firstHalf = content.substring(0, halfLength);
- const secondHalf = content.substring(halfLength);
-
- // 检查前500字符是否在后半部分重复出现
- const sample = content.substring(0, Math.min(500, halfLength));
- const isDuplicated = secondHalf.includes(sample);
-
- if (isDuplicated) {
- showResult('⚠️ 警告: 检测到内容可能重复!前500字符在后半部分也出现了', 'warning');
- } else {
- showResult('✓ 数据库内容没有重复', 'success');
- }
-
- // 显示前1000字符
- showResult('数据库中的前1000字符:\n' + content.substring(0, 1000), 'info');
-
- // 显示后500字符
- showResult('数据库中的后500字符:\n' + content.substring(totalLength - 500), 'info');
-
- } else {
- showResult(`API错误: ${data.message}`, 'error');
- }
- } catch (error) {
- showResult(`错误: ${error.message}`, 'error');
- }
- }
- async function checkExportedWord() {
- const recordId = document.getElementById('recordId').value;
- const userId = document.getElementById('userId').value;
-
- if (!recordId || !userId) {
- showResult('请输入导出记录ID和用户ID', 'warning');
- return;
- }
- showResult(`正在下载并检查Word文件...`, 'info');
-
- try {
- const downloadUrl = `${API_BASE()}/api/v1/export/records/${recordId}/download?userId=${encodeURIComponent(userId)}`;
- showResult(`下载URL: ${downloadUrl}`, 'info');
-
- const response = await fetch(downloadUrl);
-
- if (!response.ok) {
- throw new Error(`HTTP ${response.status}: ${response.statusText}`);
- }
- const blob = await response.blob();
- const arrayBuffer = await blob.arrayBuffer();
-
- showResult(`Word文件大小: ${arrayBuffer.byteLength} bytes`, 'info');
-
- // 使用mammoth解析Word文件
- showResult('正在解析Word文档...', 'info');
-
- // 动态加载mammoth库
- if (typeof mammoth === 'undefined') {
- const script = document.createElement('script');
- script.src = 'https://cdn.jsdelivr.net/npm/mammoth@1.6.0/mammoth.browser.min.js';
- document.head.appendChild(script);
-
- await new Promise((resolve, reject) => {
- script.onload = resolve;
- script.onerror = reject;
- });
- }
-
- const result = await mammoth.convertToHtml({ arrayBuffer });
- const html = result.value;
-
- showResult(`HTML长度: ${html.length} 字符`, 'info');
-
- // 提取纯文本
- const parser = new DOMParser();
- const doc = parser.parseFromString(html, 'text/html');
- const text = doc.body.textContent || '';
-
- showResult(`纯文本长度: ${text.length} 字符`, 'info');
-
- // 检查是否有重复
- const lines = text.split('\n').filter(line => line.trim());
- const halfPoint = Math.floor(lines.length / 2);
-
- let matchCount = 0;
- for (let i = 0; i < Math.min(10, halfPoint); i++) {
- if (lines[i] === lines[halfPoint + i]) {
- matchCount++;
- }
- }
-
- if (matchCount >= 8) {
- showResult(`⚠️ 警告: Word文件中检测到重复内容!前10行有${matchCount}行与后半部分匹配`, 'warning');
- } else {
- showResult('✓ Word文件内容没有明显重复', 'success');
- }
-
- // 显示前1000字符
- showResult('Word文件的前1000字符:\n' + text.substring(0, 1000), 'info');
-
- } catch (error) {
- showResult(`错误: ${error.message}`, 'error');
- console.error(error);
- }
- }
- // 初始化
- showResult('工具已就绪。请使用上面的按钮检查文档。', 'success');
- </script>
- </body>
- </html>
|