fuyu пре 4 година
родитељ
комит
5c50b928a2
5 измењених фајлова са 129 додато и 6 уклоњено
  1. 4 2
      bin/server.js
  2. 9 2
      src/modules/api/controller.js
  3. 6 2
      src/modules/api/router.js
  4. 37 0
      src/service/image.js
  5. 73 0
      src/service/imagehtml.js

+ 4 - 2
bin/server.js

@@ -2,8 +2,8 @@
  * @Author: fuyu
  * @Date: 2021-03-23 11:56:31
  * @LastEditors: fuyu
- * @LastEditTime: 2021-03-26 11:31:48
- * @FilePath: /202103/code/sql_merge/bin/server.js
+ * @LastEditTime: 2021-03-30 23:15:16
+ * @FilePath: /project/sql_merge/bin/server.js
  */
 // import mongoose from 'mongoose'
 
@@ -21,6 +21,8 @@ import config from '../config'
 //建立MYSQL连接
 require('../src/dao_new');
 require('../src/dao_old');
+require('../src/dao_by_new');
+require('../src/dao_by_old');
 //创建Koa对象
 const app = new Koa()
   // app.keys  = [config.session]

+ 9 - 2
src/modules/api/controller.js

@@ -2,10 +2,11 @@
  * @Author: fuyu
  * @Date: 2021-03-23 11:56:31
  * @LastEditors: fuyu
- * @LastEditTime: 2021-03-28 19:38:15
- * @FilePath: /sql_merge/src/modules/api/controller.js
+ * @LastEditTime: 2021-03-30 23:08:50
+ * @FilePath: /project/sql_merge/src/modules/api/controller.js
  */
 import {moveReport, movePacs} from '../../service/move'
+import {moveImage} from '../../service/image'
 import {_check} from '../../service/check'
 export async function move(ctx) {
   const institution_id = ctx.request.body.institution_id
@@ -18,6 +19,12 @@ export async function pacs(ctx) {
   await movePacs(institution_id, offset)
 }
 
+
+export async function image(ctx) {
+  const offset = ctx.request.body.offset
+  await moveImage(offset)
+}
+
 export async function check(ctx) {
   await _check()
   ctx.redirect('/html');

+ 6 - 2
src/modules/api/router.js

@@ -2,8 +2,8 @@
  * @Author: fuyu
  * @Date: 2021-02-26 17:17:47
  * @LastEditors: fuyu
- * @LastEditTime: 2021-03-28 19:20:09
- * @FilePath: /sql_merge/src/modules/api/router.js
+ * @LastEditTime: 2021-03-30 23:08:00
+ * @FilePath: /project/sql_merge/src/modules/api/router.js
  */
 import * as api from './controller'
 
@@ -17,6 +17,10 @@ export default [{
   method: 'POST',
   route: '/pacs',
   handlers: [api.pacs]
+}, ,{
+  method: 'POST',
+  route: '/image',
+  handlers: [api.image]
 }, {
   method: 'ALL',
   route: '/check',

+ 37 - 0
src/service/image.js

@@ -0,0 +1,37 @@
+/*
+ * @Author: fuyu
+ * @Date: 2021-03-30 23:08:53
+ * @LastEditors: fuyu
+ * @LastEditTime: 2021-03-30 23:16:30
+ * @FilePath: /project/sql_merge/src/service/image.js
+ */
+
+import {Images as NewImage} from '../dao_by_new'
+import {Images as OldImage} from '../dao_by_old'
+const limit = 100
+import {getInt} from './common'
+export async function moveImage(offset) {
+
+  while(true) {
+    let images = await OldImage.findAll({where: {image_status:0}, limit, getInt(offset)})
+    for(let i = 0; i > images.length; i++) {
+      await fixImage(images[i])
+    }
+    if(limit > images.length) {
+      return
+    }
+  }
+}
+
+async function fixImage(image) {
+  const newImage = await NewImage.findOne({where: {imageId: image.image_id}})
+  if(newImage) {
+    newImage.metadata = image.metadata
+    await newImage.save()
+    image.image_status = 1
+    await image.save()
+    return
+  }
+  image.image_status = 2
+  await image.save()
+}

+ 73 - 0
src/service/imagehtml.js

@@ -0,0 +1,73 @@
+/*
+ * @Author: fuyu
+ * @Date: 2021-03-26 16:38:25
+ * @LastEditors: fuyu
+ * @LastEditTime: 2021-03-30 23:19:48
+ * @FilePath: /project/sql_merge/src/service/imagehtml.js
+ */
+
+import {Images } from '../dao_by_old'
+export async function getHtml() {
+  const sum = await Images.count()
+  const setup0 = await Images.count({where: {image_status: 0}})
+  const setup1 = await Images.count({where: {image_status: 0}})
+  const setup2 = await Images.count({where: {image_status: 0}})
+  const tbody = `
+  <tr>
+  <td>${sum}</td>
+  <td>${setup0}</td>
+  <td>${setup1}</td>
+  <td>${setup2}</td>
+  </tr>
+  `
+  return `<html>
+  <title>白银市数据同步报告</title>
+  <body>
+  <style>
+  .report {
+    color:#FF8C00
+  }
+  .undo {
+    color:#FF0000
+  }
+  table {
+    width: 100%;
+    font-size: .938em;
+    border-collapse: collapse;/*边框会合并为一个单一的边框*/
+  }
+  caption {
+      margin: 1em 0 .7em 0;
+      text-align: center;
+      font-weight: bold;
+      font-size: 120%;
+      letter-spacing: .5px;
+      color: #fff;
+  }
+
+  th {
+      text-align: left;
+      padding: .5em .5em;
+      font-weight: bold;
+      background: #66677c;color: #fff;
+  }
+
+  td {
+      padding: .5em .5em;
+      border-bottom: solid 1px #ccc;
+  }
+
+  table,table tr th, table tr td { border:1px solid #0094ff; }/*设置边框的*/
+  </style>
+  <table border="0" cellspacing="1" cellpadding="0">
+    <thead>
+    <th>总数</th>
+    <th>未处理</th>
+    <th>已同步</th>
+    <th>未找到</th>
+    </thead>
+    <tbody>${tbody}</tbody>
+  </table>
+  <script>setTimeout(_ => window.location.reload(), 60000)</script>
+  </body>
+</html>`
+}