fuyu 4 years ago
parent
commit
df2a308799
5 changed files with 162 additions and 14 deletions
  1. 12 13
      config/env/development.js
  2. 2 1
      src/dao_new/Institution.js
  3. 13 0
      src/modules/html/controller.js
  4. 17 0
      src/modules/html/router.js
  5. 118 0
      src/service/html.js

+ 12 - 13
config/env/development.js

@@ -2,7 +2,7 @@
  * @Author: fuyu
  * @Date: 2019-12-12 18:12:16
  * @LastEditors: fuyu
- * @LastEditTime: 2021-03-26 12:05:57
+ * @LastEditTime: 2021-03-26 16:42:03
  * @FilePath: /202103/code/sql_merge/config/env/development.js
  */
 export default {
@@ -11,7 +11,6 @@ export default {
   mongodb: 'mongodb://localhost:27017/koa2-boilerplate-dev',
   limit: 100,
   old_db_config: {
-
     // database: 'pacsonline_pro',
     // username: 'by-pacs',
     // password: 'By@2021~!@#',
@@ -33,19 +32,19 @@ export default {
     // host: '117.50.71.166',
     // port: 7001,
     // db_type: 'mysql',
-    // database: 'by_yj',
-    // username: 'root',
-    // password: 'admin123',
-    // host: '127.0.0.1',
-    // port: 3306,
-    // db_type: 'mysql'
-    
-    database: 'pacsonline_pro',
-    username: 'by-pacs',
-    password: 'By@2021~!@#',
+    database: 'by_yj',
+    username: 'root',
+    password: 'admin123',
     host: '127.0.0.1',
     port: 3306,
-    db_type: 'mysql',
+    db_type: 'mysql'
+    
+    // database: 'pacsonline_pro',
+    // username: 'by-pacs',
+    // password: 'By@2021~!@#',
+    // host: '127.0.0.1',
+    // port: 3306,
+    // db_type: 'mysql',
   },
 
 

+ 2 - 1
src/dao_new/Institution.js

@@ -2,7 +2,7 @@
  * @Author: fuyu
  * @Date: 2021-03-22 19:10:00
  * @LastEditors: fuyu
- * @LastEditTime: 2021-03-23 18:59:46
+ * @LastEditTime: 2021-03-26 17:46:48
  * @FilePath: /202103/code/sql_merge/src/dao_new/Institution.js
  */
 
@@ -16,6 +16,7 @@ import sequelize from './db/sequelize';
 
 const Institution = sequelize.define('institution', {
   id: {type: Sequelize.STRING(32), allowNull: false, primaryKey: true}, // id,
+  name: {type: Sequelize.STRING(200), allowNull: true, defaultValue: null}, // name,
   }, {
   freezeTableName: true,
   charset: 'utf8',

+ 13 - 0
src/modules/html/controller.js

@@ -0,0 +1,13 @@
+/*
+ * @Author: fuyu
+ * @Date: 2021-03-23 11:56:31
+ * @LastEditors: fuyu
+ * @LastEditTime: 2021-03-26 16:38:19
+ * @FilePath: /202103/code/sql_merge/src/modules/html/controller.js
+ */
+import {getHtml} from '../../service/html'
+
+export async function html(ctx) {
+  const html = await getHtml()
+  ctx.body = html
+}

+ 17 - 0
src/modules/html/router.js

@@ -0,0 +1,17 @@
+/*
+ * @Author: fuyu
+ * @Date: 2021-02-26 17:17:47
+ * @LastEditors: fuyu
+ * @LastEditTime: 2021-03-26 16:41:21
+ * @FilePath: /202103/code/sql_merge/src/modules/html/router.js
+ */
+import * as html from './controller'
+
+export const baseUrl = '/html'
+
+export default [{
+  method: 'ALL',
+  route: '/',
+  handlers: [html.html]
+}
+]

+ 118 - 0
src/service/html.js

@@ -0,0 +1,118 @@
+/*
+ * @Author: fuyu
+ * @Date: 2021-03-26 16:38:25
+ * @LastEditors: fuyu
+ * @LastEditTime: 2021-03-26 18:10:51
+ * @FilePath: /202103/code/sql_merge/src/service/html.js
+ */
+
+const FLAG_DELAULT = 0
+const FLAG_REPORT = 1
+const FLAG_PACS = 2
+import {Exams as OldExams} from '../dao_old'
+import {Exams as NewExams, Institution} from '../dao_new'
+export async function getHtml() {
+  const institution = await Institution.findAll({order: ['id', 'name']})
+  const map = {}, ids = []
+  institution.forEach(i => {
+    const id = i['id']
+    const name = i['name']
+    map[id] = {id, name}
+    ids.push(id)
+  })
+  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']
+    const count = item['count']
+    const tmp = map[id]
+    tmp['old-' + flag] = count
+  });
+
+  newExams.forEach(item => {
+    const id = item['institution_id']
+    const flag = item['flag']
+    const count = item['count']
+    const tmp = map[id]
+    tmp['new-' + flag] = count
+  });
+
+  const data = []
+  const trs = []
+  for(let key in map) {
+    const tmp = map[key]
+    const id = tmp['id']
+    const name = tmp['name']
+    const old0 = parseInt(tmp['old-0'] || 0)
+    const old1 = parseInt(tmp['old-1'] || 0)
+    const old2 = parseInt(tmp['old-2'] || 0)
+    const new0 = parseInt(tmp['new-0'] || 0)
+    const new1 = parseInt(tmp['new-1'] || 0)
+    const new2 = parseInt(tmp['new-2'] || 0)
+    const oldsum = old0 + old1 + old2
+    const newsum = new0 + new1 + new2
+    data.push({ id, name, old0, old1, old2, new0, new1, new2, oldsum, newsum})
+    trs.push(`<tr>
+    <td>${id}</td>
+    <td>${name}</td>
+    <td>${oldsum}</td>
+    <td>${old2}</td>
+    <td>${old1}</td>
+    <td>${old0}</td>
+    <td>${newsum}</td>
+    <td>${new0}</td>
+    <td>${new1}</td>
+    <td>${new2}</td>
+    </tr>`)
+  }
+  // return data
+  const tbody = trs.join('')
+  return `<html>
+    <style>
+    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>医院id</th>
+      <th>医院名称</th>
+      <th>公网总数</th>
+      <th>同步完成</th>
+      <th>同步报告</th>
+      <th>未同步</th>
+      <th>内网总数</th>
+      <th>未同步</th>
+      <th>同步报告</th>
+      <th>同步完成</th>
+      </thead>
+      <tbody>${tbody}</tbody>
+    </table>
+  </html>`
+}