瀏覽代碼

Merge branch 'master' of http://code.pacsonline.cn/fuyu/sql_merge

fuyu 4 年之前
父節點
當前提交
d34ea4635e
共有 9 個文件被更改,包括 72 次插入44 次删除
  1. 3 3
      merge.config.js
  2. 0 3
      move.sh
  3. 0 22
      pacs.sh
  4. 10 4
      src/modules/api/controller.js
  5. 5 1
      src/modules/api/router.js
  6. 22 0
      src/service/check.js
  7. 8 3
      src/service/html.js
  8. 7 4
      src/service/log.js
  9. 17 4
      src/service/move.js

+ 3 - 3
merge.config.js

@@ -2,8 +2,8 @@
  * @Author: fuyu
  * @Date: 2021-03-23 11:56:31
  * @LastEditors: fuyu
- * @LastEditTime: 2021-03-26 12:11:41
- * @FilePath: /202103/code/sql_merge/merge.config.js
+ * @LastEditTime: 2021-03-28 19:37:12
+ * @FilePath: /sql_merge/merge.config.js
  */
 /**
  * PM2启动配置
@@ -21,7 +21,7 @@ module.exports = {
 
       max_memory_restart: '2G', //超过多大内存自动重启,仅防止内存泄露有意义,需要根据自己的业务设置
       exec_mode: 'cluster', //开启多线程模式,用于负载均衡
-      instances: '4', //启用多少个实例,可用于负载均衡
+      instances: '1', //启用多少个实例,可用于负载均衡
       autorestart: true, //程序崩溃后自动重启
 
       env: { NODE_ENV: 'production' },

+ 0 - 3
move.sh

@@ -1,3 +0,0 @@
-curl -d 'institution_id=73090018' 127.0.0.1:22399/api/move &
-curl -d 'institution_id=73090026' 127.0.0.1:22399/api/move &
-curl -d 'institution_id=73090030' 127.0.0.1:22399/api/move &

+ 0 - 22
pacs.sh

@@ -1,22 +0,0 @@
-curl -d 'institution_id=73090001&offset=0' 127.0.0.1:22399/api/pacs &
-curl -d 'institution_id=73090001&offset=1000' 127.0.0.1:22399/api/pacs &
-curl -d 'institution_id=73090001&offset=2000' 127.0.0.1:22399/api/pacs &
-curl -d 'institution_id=73090001&offset=3000' 127.0.0.1:22399/api/pacs &
-curl -d 'institution_id=73090001&offset=4000' 127.0.0.1:22399/api/pacs &
-curl -d 'institution_id=73090001&offset=5000' 127.0.0.1:22399/api/pacs &
-curl -d 'institution_id=73090001&offset=6000' 127.0.0.1:22399/api/pacs &
-curl -d 'institution_id=73090001&offset=7000' 127.0.0.1:22399/api/pacs &
-curl -d 'institution_id=73090001&offset=8000' 127.0.0.1:22399/api/pacs &
-curl -d 'institution_id=73090001&offset=9000' 127.0.0.1:22399/api/pacs &
-curl -d 'institution_id=73090004&offset=0' 127.0.0.1:22399/api/pacs &
-curl -d 'institution_id=73090004&offset=1000' 127.0.0.1:22399/api/pacs &
-curl -d 'institution_id=73090004&offset=2000' 127.0.0.1:22399/api/pacs &
-curl -d 'institution_id=73090006&offset=0' 127.0.0.1:22399/api/pacs &
-curl -d 'institution_id=73090006&offset=1000' 127.0.0.1:22399/api/pacs &
-curl -d 'institution_id=73090006&offset=2000' 127.0.0.1:22399/api/pacs &
-curl -d 'institution_id=73090006&offset=3000' 127.0.0.1:22399/api/pacs &
-curl -d 'institution_id=73090006&offset=4000' 127.0.0.1:22399/api/pacs &
-curl -d 'institution_id=73090010&offset=0' 127.0.0.1:22399/api/pacs &
-curl -d 'institution_id=73090010&offset=1000' 127.0.0.1:22399/api/pacs &
-curl -d 'institution_id=73090010&offset=2000' 127.0.0.1:22399/api/pacs &
-curl -d 'institution_id=73090010&offset=3000' 127.0.0.1:22399/api/pacs &

+ 10 - 4
src/modules/api/controller.js

@@ -2,13 +2,14 @@
  * @Author: fuyu
  * @Date: 2021-03-23 11:56:31
  * @LastEditors: fuyu
- * @LastEditTime: 2021-03-26 10:46:27
- * @FilePath: /202103/code/sql_merge/src/modules/api/controller.js
+ * @LastEditTime: 2021-03-28 19:38:15
+ * @FilePath: /sql_merge/src/modules/api/controller.js
  */
-import {moveAll, movePacs} from '../../service/move'
+import {moveReport, movePacs} from '../../service/move'
+import {_check} from '../../service/check'
 export async function move(ctx) {
   const institution_id = ctx.request.body.institution_id
-  await moveAll(institution_id)
+  await moveReport(institution_id)
 }
 
 export async function pacs(ctx) {
@@ -16,3 +17,8 @@ export async function pacs(ctx) {
   const offset = ctx.request.body.offset
   await movePacs(institution_id, offset)
 }
+
+export async function check(ctx) {
+  await _check()
+  ctx.redirect('/html');
+}

+ 5 - 1
src/modules/api/router.js

@@ -2,7 +2,7 @@
  * @Author: fuyu
  * @Date: 2021-02-26 17:17:47
  * @LastEditors: fuyu
- * @LastEditTime: 2021-03-24 15:12:18
+ * @LastEditTime: 2021-03-28 19:20:09
  * @FilePath: /sql_merge/src/modules/api/router.js
  */
 import * as api from './controller'
@@ -17,5 +17,9 @@ export default [{
   method: 'POST',
   route: '/pacs',
   handlers: [api.pacs]
+}, {
+  method: 'ALL',
+  route: '/check',
+  handlers: [api.check]
 }
 ]

+ 22 - 0
src/service/check.js

@@ -0,0 +1,22 @@
+/*
+ * @Author: fuyu
+ * @Date: 2021-03-28 19:21:26
+ * @LastEditors: fuyu
+ * @LastEditTime: 2021-03-28 22:20:36
+ * @FilePath: /sql_merge/src/service/check.js
+ */
+let flag = false
+import {moveAll} from './move'
+
+export function getFlag() {
+  return flag
+}
+
+export async function _check() {
+  if(flag) {
+    return
+  }
+  flag = true
+  await moveAll()
+  flag = false
+}

+ 8 - 3
src/service/html.js

@@ -2,8 +2,8 @@
  * @Author: fuyu
  * @Date: 2021-03-26 16:38:25
  * @LastEditors: fuyu
- * @LastEditTime: 2021-03-26 18:31:29
- * @FilePath: /202103/code/sql_merge/src/service/html.js
+ * @LastEditTime: 2021-03-28 19:35:06
+ * @FilePath: /sql_merge/src/service/html.js
  */
 
 const FLAG_DELAULT = 0
@@ -11,6 +11,7 @@ const FLAG_REPORT = 1
 const FLAG_PACS = 2
 import {Exams as OldExams} from '../dao_old'
 import {Exams as NewExams, Institution} from '../dao_new'
+import {getFlag} from './check'
 export async function getHtml() {
   const institution = await Institution.findAll({order: ['id', 'name']})
   const map = {}, ids = []
@@ -22,7 +23,6 @@ export async function getHtml() {
   })
   const oldExams = await OldExams.count({attributes: ['institution_id', 'flag'], where: {institution_id: ids}, group: ['institution_id', 'flag']})
   const newExams = await NewExams.count({attributes: ['institution_id', 'flag'], where: {institution_id: ids}, group: ['institution_id', 'flag']})
-  
   oldExams.forEach(item => {
     const id = item['institution_id']
     const flag = item['flag']
@@ -97,8 +97,12 @@ export async function getHtml() {
   </tr>`)
   // return data
   const tbody = trs.join('')
+  const flag = getFlag()
   return `<html>
     <title>白银市数据同步报告</title>
+    <body>
+    <div>${flag ? '同步中...': '同步完成(<a href="./api/check">同步报告</a>)'}</div>
+    
     <style>
     .report {
       color:#FF8C00
@@ -150,5 +154,6 @@ export async function getHtml() {
       <tbody>${tbody}</tbody>
     </table>
     <script>setTimeout(_ => window.location.reload(), 60000)</script>
+    </body>
   </html>`
 }

+ 7 - 4
src/service/log.js

@@ -2,14 +2,17 @@
  * @Author: fuyu
  * @Date: 2021-03-23 16:25:59
  * @LastEditors: fuyu
- * @LastEditTime: 2021-03-25 17:28:20
- * @FilePath: /202103/code/sql_merge/src/service/log.js
+ * @LastEditTime: 2021-03-28 22:26:51
+ * @FilePath: /sql_merge/src/service/log.js
  */
 const fs = require('fs')
 const path = require('path');
 const rootPath = path.join(__dirname, '..', '..', 'logs')
 import {getNowDay, getNowTime} from './time'
-export async function logSum(institution_id, count) {
+export async function logSum(institution_id, count, prefix = '') {
+  if(institution_id instanceof Array) {
+    institution_id = 'all'
+  }
   const dirPath = path.join(rootPath, 'sum')
   checkPath(dirPath)
   const filePath = path.join(dirPath, getNowDay() + '.log')
@@ -18,7 +21,7 @@ export async function logSum(institution_id, count) {
     time: time, institution_id, count,
   }
   fs.appendFileSync(filePath, JSON.stringify(obj) + '\r\n')
-  fs.writeFileSync(path.join(dirPath, institution_id + '-' + getNowDay() + '.log'), count + '')
+  fs.writeFileSync(path.join(dirPath, prefix + institution_id + '-' + getNowDay() + '.log'), count + '')
 }
 export async function logSingle(name) {
   checkPath(rootPath)

+ 17 - 4
src/service/move.js

@@ -2,8 +2,8 @@
  * @Author: fuyu
  * @Date: 2021-03-23 12:00:09
  * @LastEditors: fuyu
- * @LastEditTime: 2021-03-26 10:54:02
- * @FilePath: /202103/code/sql_merge/src/service/move.js
+ * @LastEditTime: 2021-03-28 22:25:22
+ * @FilePath: /sql_merge/src/service/move.js
  */
 
 import config from '../../config'
@@ -16,7 +16,16 @@ import {logSum, logSingle} from './log'
 import {RemoteApplication as OldRemoteApplication, ApplicationProgressLog as OldApplicationProgressLog, Bbs as OldBbs, RemoteOrder as OldRemoteOrder, RemoteWater as OldRemoteWater, Register as OldRegister, Exams as OldExams, PatientInfos as OldPatientInfos, Studies as OldStudies, Series as OldSeries, Images as OldImages, Report as OldReport, ReportRecord as OldReportRecord, QualityControl as OldQualityControl, QualityCause as OldQualityCause} from '../dao_old'
 import {Institution,  RemoteApplication as NewRemoteApplication, ApplicationProgressLog as NewApplicationProgressLog, Bbs as NewBbs, RemoteOrder as NewRemoteOrder, RemoteWater as NewRemoteWater, Register as NewRegister, Exams as NewExams, PatientInfos as NewPatientInfos, Studies as NewStudies, Series as NewSeries, Images as NewImages, Report as NewReport, ReportRecord as NewReportRecord, QualityControl as NewQualityControl, QualityCause as NewQualityCause} from '../dao_new'
 import {getInt} from './common'
-export async function moveAll(institution_id) {
+
+export async function moveAll() {
+  const res = await Institution.findAll({attributes: ['id']})
+  const ids = res.map(item => item['id'])
+  await moveSingle(ids)
+  await moveSinglePacs(ids, 0)
+}
+
+
+export async function moveReport(institution_id) {
   if(institution_id) {
     await moveSingle(institution_id)
     return
@@ -44,7 +53,7 @@ const moveSinglePacs = async (institution_id, offset = 0) => {
     count = await moveExamsPacs(institution_id, offset)
     sum += count
   }
-  logSum('pacs-' + institution_id, sum)
+  logSum(institution_id, sum, 'pacs-')
 }
 
 const moveExamsPacs = async (institution_id, offset) => {
@@ -186,6 +195,10 @@ const updateExamFlag = async (exam, flag) => {
   old.flag = flag;
   await old.save()
   const newExam = await NewExams.findOne({where: {id: exam.id}})
+  if(!newExam) {
+    console.log('id')
+    return
+  }
   newExam.flag = flag;
   await newExam.save()
   return true