check-duplication.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>文档重复检查工具</title>
  7. <style>
  8. body {
  9. font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  10. max-width: 1200px;
  11. margin: 0 auto;
  12. padding: 20px;
  13. background: #f5f5f5;
  14. }
  15. .container {
  16. background: white;
  17. padding: 30px;
  18. border-radius: 8px;
  19. box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  20. }
  21. h1 {
  22. color: #333;
  23. border-bottom: 3px solid #1890ff;
  24. padding-bottom: 10px;
  25. }
  26. .section {
  27. margin: 20px 0;
  28. padding: 15px;
  29. background: #fafafa;
  30. border-left: 4px solid #1890ff;
  31. border-radius: 4px;
  32. }
  33. .input-group {
  34. margin: 15px 0;
  35. }
  36. label {
  37. display: block;
  38. margin-bottom: 5px;
  39. font-weight: 600;
  40. color: #555;
  41. }
  42. input, select {
  43. width: 100%;
  44. padding: 10px;
  45. border: 1px solid #d9d9d9;
  46. border-radius: 4px;
  47. font-size: 14px;
  48. box-sizing: border-box;
  49. }
  50. button {
  51. background: #1890ff;
  52. color: white;
  53. border: none;
  54. padding: 12px 24px;
  55. border-radius: 4px;
  56. cursor: pointer;
  57. font-size: 14px;
  58. font-weight: 600;
  59. margin-right: 10px;
  60. margin-top: 10px;
  61. }
  62. button:hover {
  63. background: #40a9ff;
  64. }
  65. button:disabled {
  66. background: #d9d9d9;
  67. cursor: not-allowed;
  68. }
  69. .results {
  70. margin-top: 20px;
  71. }
  72. .result-box {
  73. background: white;
  74. border: 1px solid #e8e8e8;
  75. padding: 15px;
  76. margin: 10px 0;
  77. border-radius: 4px;
  78. white-space: pre-wrap;
  79. font-family: 'Courier New', monospace;
  80. font-size: 12px;
  81. max-height: 400px;
  82. overflow-y: auto;
  83. }
  84. .success {
  85. color: #52c41a;
  86. font-weight: 600;
  87. }
  88. .error {
  89. color: #ff4d4f;
  90. font-weight: 600;
  91. }
  92. .warning {
  93. color: #faad14;
  94. font-weight: 600;
  95. }
  96. .info {
  97. color: #1890ff;
  98. font-weight: 600;
  99. }
  100. .stat {
  101. display: inline-block;
  102. background: #e6f7ff;
  103. padding: 5px 15px;
  104. margin: 5px 5px 5px 0;
  105. border-radius: 20px;
  106. font-size: 13px;
  107. font-weight: 600;
  108. color: #0050b3;
  109. }
  110. </style>
  111. </head>
  112. <body>
  113. <div class="container">
  114. <h1>🔍 文档重复检查工具</h1>
  115. <div class="section">
  116. <h3>步骤 1: 从数据库获取文档</h3>
  117. <div class="input-group">
  118. <label>后端 API 地址:</label>
  119. <input type="text" id="apiBase" value="http://192.168.0.195:8000" />
  120. </div>
  121. <div class="input-group">
  122. <label>文档 ID:</label>
  123. <input type="text" id="documentId" placeholder="例如: doc-7791bc371ad7" />
  124. </div>
  125. <button onclick="fetchDocument()">获取文档</button>
  126. <button onclick="fetchLatestDocument()">获取最新文档</button>
  127. </div>
  128. <div class="section">
  129. <h3>步骤 2: 检查导出的Word文件</h3>
  130. <div class="input-group">
  131. <label>导出记录 ID:</label>
  132. <input type="text" id="recordId" placeholder="例如: rec-xxx" />
  133. </div>
  134. <div class="input-group">
  135. <label>用户 ID:</label>
  136. <input type="text" id="userId" value="default-user" />
  137. </div>
  138. <button onclick="checkExportedWord()">下载并检查Word文件</button>
  139. </div>
  140. <div id="results" class="results"></div>
  141. </div>
  142. <script>
  143. const API_BASE = () => document.getElementById('apiBase').value;
  144. function showResult(message, type = 'info') {
  145. const results = document.getElementById('results');
  146. const box = document.createElement('div');
  147. box.className = 'result-box';
  148. box.innerHTML = `<span class="${type}">[${type.toUpperCase()}]</span> ${message}`;
  149. results.appendChild(box);
  150. results.scrollTop = results.scrollHeight;
  151. }
  152. async function fetchLatestDocument() {
  153. showResult('正在获取最新文档...', 'info');
  154. try {
  155. const response = await fetch(`${API_BASE()}/api/v1/documents?userId=default-user&page=1&pageSize=1&sortBy=createdAt&sortOrder=desc`);
  156. if (!response.ok) {
  157. throw new Error(`HTTP ${response.status}: ${response.statusText}`);
  158. }
  159. const data = await response.json();
  160. if (data.code === 200 && data.data.documents.length > 0) {
  161. const doc = data.data.documents[0];
  162. document.getElementById('documentId').value = doc.id;
  163. showResult(`最新文档 ID: ${doc.id}`, 'success');
  164. // 自动获取文档详情
  165. await fetchDocument();
  166. } else {
  167. showResult('未找到文档', 'warning');
  168. }
  169. } catch (error) {
  170. showResult(`错误: ${error.message}`, 'error');
  171. }
  172. }
  173. async function fetchDocument() {
  174. const docId = document.getElementById('documentId').value;
  175. if (!docId) {
  176. showResult('请输入文档ID', 'warning');
  177. return;
  178. }
  179. showResult(`正在获取文档 ${docId}...`, 'info');
  180. try {
  181. const response = await fetch(`${API_BASE()}/api/v1/documents/${docId}`);
  182. if (!response.ok) {
  183. throw new Error(`HTTP ${response.status}: ${response.statusText}`);
  184. }
  185. const data = await response.json();
  186. if (data.code === 200) {
  187. const doc = data.data;
  188. const content = doc.content;
  189. showResult(`文档ID: ${doc.id}`, 'info');
  190. showResult(`格式: ${doc.format}`, 'info');
  191. showResult(`创建时间: ${new Date(doc.createdAt).toLocaleString()}`, 'info');
  192. // 统计信息
  193. const totalLength = content.length;
  194. const lines = content.split('\n');
  195. const totalLines = lines.length;
  196. showResult(`
  197. <span class="stat">总长度: ${totalLength} 字符</span>
  198. <span class="stat">总行数: ${totalLines} 行</span>
  199. `, 'info');
  200. // 检查是否有重复
  201. const halfLength = Math.floor(totalLength / 2);
  202. const firstHalf = content.substring(0, halfLength);
  203. const secondHalf = content.substring(halfLength);
  204. // 检查前500字符是否在后半部分重复出现
  205. const sample = content.substring(0, Math.min(500, halfLength));
  206. const isDuplicated = secondHalf.includes(sample);
  207. if (isDuplicated) {
  208. showResult('⚠️ 警告: 检测到内容可能重复!前500字符在后半部分也出现了', 'warning');
  209. } else {
  210. showResult('✓ 数据库内容没有重复', 'success');
  211. }
  212. // 显示前1000字符
  213. showResult('数据库中的前1000字符:\n' + content.substring(0, 1000), 'info');
  214. // 显示后500字符
  215. showResult('数据库中的后500字符:\n' + content.substring(totalLength - 500), 'info');
  216. } else {
  217. showResult(`API错误: ${data.message}`, 'error');
  218. }
  219. } catch (error) {
  220. showResult(`错误: ${error.message}`, 'error');
  221. }
  222. }
  223. async function checkExportedWord() {
  224. const recordId = document.getElementById('recordId').value;
  225. const userId = document.getElementById('userId').value;
  226. if (!recordId || !userId) {
  227. showResult('请输入导出记录ID和用户ID', 'warning');
  228. return;
  229. }
  230. showResult(`正在下载并检查Word文件...`, 'info');
  231. try {
  232. const downloadUrl = `${API_BASE()}/api/v1/export/records/${recordId}/download?userId=${encodeURIComponent(userId)}`;
  233. showResult(`下载URL: ${downloadUrl}`, 'info');
  234. const response = await fetch(downloadUrl);
  235. if (!response.ok) {
  236. throw new Error(`HTTP ${response.status}: ${response.statusText}`);
  237. }
  238. const blob = await response.blob();
  239. const arrayBuffer = await blob.arrayBuffer();
  240. showResult(`Word文件大小: ${arrayBuffer.byteLength} bytes`, 'info');
  241. // 使用mammoth解析Word文件
  242. showResult('正在解析Word文档...', 'info');
  243. // 动态加载mammoth库
  244. if (typeof mammoth === 'undefined') {
  245. const script = document.createElement('script');
  246. script.src = 'https://cdn.jsdelivr.net/npm/mammoth@1.6.0/mammoth.browser.min.js';
  247. document.head.appendChild(script);
  248. await new Promise((resolve, reject) => {
  249. script.onload = resolve;
  250. script.onerror = reject;
  251. });
  252. }
  253. const result = await mammoth.convertToHtml({ arrayBuffer });
  254. const html = result.value;
  255. showResult(`HTML长度: ${html.length} 字符`, 'info');
  256. // 提取纯文本
  257. const parser = new DOMParser();
  258. const doc = parser.parseFromString(html, 'text/html');
  259. const text = doc.body.textContent || '';
  260. showResult(`纯文本长度: ${text.length} 字符`, 'info');
  261. // 检查是否有重复
  262. const lines = text.split('\n').filter(line => line.trim());
  263. const halfPoint = Math.floor(lines.length / 2);
  264. let matchCount = 0;
  265. for (let i = 0; i < Math.min(10, halfPoint); i++) {
  266. if (lines[i] === lines[halfPoint + i]) {
  267. matchCount++;
  268. }
  269. }
  270. if (matchCount >= 8) {
  271. showResult(`⚠️ 警告: Word文件中检测到重复内容!前10行有${matchCount}行与后半部分匹配`, 'warning');
  272. } else {
  273. showResult('✓ Word文件内容没有明显重复', 'success');
  274. }
  275. // 显示前1000字符
  276. showResult('Word文件的前1000字符:\n' + text.substring(0, 1000), 'info');
  277. } catch (error) {
  278. showResult(`错误: ${error.message}`, 'error');
  279. console.error(error);
  280. }
  281. }
  282. // 初始化
  283. showResult('工具已就绪。请使用上面的按钮检查文档。', 'success');
  284. </script>
  285. </body>
  286. </html>