lrf402788946 4 years ago
parent
commit
dd82a92460

+ 1 - 0
app/controller/.article.js

@@ -42,6 +42,7 @@ module.exports = {
         title: "title",
         user: "user",
         user_id: "user_id",
+        patientid: "patientid",
         "create_time@start": "create_time@start",
         "create_time@end": "create_time@end",
       },

+ 39 - 36
app/controller/.doctor.js

@@ -1,57 +1,60 @@
 module.exports = {
   create: {
     requestBody: [
-      'name',
-      '!mobile',
-      '!passwd',
-      'hosname',
-      'deptname',
-      'title',
-      'post',
-      'content',
-      'openid',
-      'remark'
-    ]
+      "name",
+      "!mobile",
+      "!passwd",
+      "hosname",
+      "deptname",
+      "title",
+      "post",
+      "content",
+      "openid",
+      "remark",
+      "invite_id",
+    ],
   },
   destroy: {
-    params: ['!id'],
-    service: 'delete'
+    params: ["!id"],
+    service: "delete",
   },
   update: {
-    params: ['!id'],
+    params: ["!id"],
     requestBody: [
-      'name',
-      '!mobile',
-      'passwd',
-      'hosname',
-      'deptname',
-      'title',
-      'post',
-      'content',
-      'openid',
-      'remark'
-    ]
+      "name",
+      "!mobile",
+      "passwd",
+      "hosname",
+      "deptname",
+      "title",
+      "post",
+      "content",
+      "openid",
+      "remark",
+      "invite_id",
+    ],
   },
   show: {
     parameters: {
-      params: ['!id']
+      params: ["!id"],
     },
-    service: 'fetch'
+    service: "fetch",
   },
   index: {
     parameters: {
       query: {
-        name: 'name',
-        mobile: 'mobile',
-        openid: 'openid'
-      }
+        name: "name",
+        mobile: "mobile",
+        openid: "openid",
+        invite_id: "invite_id",
+      },
     },
-    service: 'query',
+    service: "query",
     options: {
-      query: ['skip', 'limit'],
-      sort: ['meta.createdAt'],
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
       desc: true,
-      count: true
-    }
+      count: true,
+    },
   },
 };

+ 5 - 0
app/controller/article.js

@@ -9,5 +9,10 @@ class ArticleController extends Controller {
     super(ctx);
     this.service = this.ctx.service.article;
   }
+
+  async index() {
+    const { data, total } = await this.service.query(this.ctx.query);
+    this.ctx.ok({ data, total });
+  }
 }
 module.exports = CrudController(ArticleController, meta);

+ 1 - 0
app/model/adv.js

@@ -17,6 +17,7 @@ const adv = {
 const schema = new Schema(adv, { toJSON: { virtuals: true } });
 schema.index({ id: 1 });
 schema.index({ pos: 1 });
+schema.index({ 'meta.createdAt': 1 });
 schema.plugin(metaPlugin);
 module.exports = app => {
   const { mongoose } = app;

+ 1 - 0
app/model/article.js

@@ -20,6 +20,7 @@ schema.index({ id: 1 });
 schema.index({ title: 1 });
 schema.index({ user: 1 });
 schema.index({ user_id: 1 });
+schema.index({ 'meta.createdAt': 1 });
 schema.plugin(metaPlugin);
 module.exports = app => {
   const { mongoose } = app;

+ 1 - 0
app/model/chat.js

@@ -20,6 +20,7 @@ const ChatSchema = {
 const schema = new Schema(ChatSchema, { toJSON: { virtuals: true } });
 schema.index({ sendid: 1 });
 schema.index({ receiveid: 1 });
+schema.index({ 'meta.createdAt': 1 });
 schema.plugin(metaPlugin);
 
 module.exports = app => {

+ 3 - 0
app/model/doctor.js

@@ -2,6 +2,7 @@
 const Schema = require('mongoose').Schema;
 const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
 const { Secret } = require('naf-framework-mongoose/lib/model/schema');
+const { ObjectId } = require('mongoose').Types;
 
 // 医生表
 const DoctorSchema = {
@@ -18,11 +19,13 @@ const DoctorSchema = {
   money: { type: String, required: false, maxLength: 200 }, // 总金额
   balance: { type: String, required: false, maxLength: 200 }, // 剩余金额
   remark: { type: String, required: false }, // 备注
+  invite_id: { type: ObjectId, required: false }, // 邀请医生id
 };
 
 
 const schema = new Schema(DoctorSchema, { toJSON: { virtuals: true } });
 schema.index({ openid: 1 });
+schema.index({ 'meta.createdAt': 1 });
 schema.plugin(metaPlugin);
 
 module.exports = app => {

+ 1 - 0
app/model/doctormoney.js

@@ -16,6 +16,7 @@ const DoctormoneySchema = {
 
 const schema = new Schema(DoctormoneySchema, { toJSON: { virtuals: true } });
 schema.index({ doctorid: 1 });
+schema.index({ 'meta.createdAt': 1 });
 schema.plugin(metaPlugin);
 
 module.exports = app => {

+ 1 - 0
app/model/group.js

@@ -21,6 +21,7 @@ const GroupSchema = {
 
 const schema = new Schema(GroupSchema, { toJSON: { virtuals: true } });
 schema.index({ doctorid: 1 });
+schema.index({ 'meta.createdAt': 1 });
 schema.plugin(metaPlugin);
 
 module.exports = app => {

+ 1 - 0
app/model/groupchat.js

@@ -20,6 +20,7 @@ const GroupchatSchema = {
 const schema = new Schema(GroupchatSchema, { toJSON: { virtuals: true } });
 schema.index({ groupid: 1 });
 schema.index({ sendid: 1 });
+schema.index({ 'meta.createdAt': 1 });
 schema.plugin(metaPlugin);
 
 module.exports = app => {

+ 1 - 0
app/model/nurse.js

@@ -21,6 +21,7 @@ const NurseSchema = {
 
 const schema = new Schema(NurseSchema, { toJSON: { virtuals: true } });
 schema.index({ openid: 1 });
+schema.index({ 'meta.createdAt': 1 });
 schema.plugin(metaPlugin);
 
 module.exports = app => {

+ 1 - 0
app/model/patient.js

@@ -31,6 +31,7 @@ const PatientSchema = {
 
 const schema = new Schema(PatientSchema, { toJSON: { virtuals: true } });
 schema.index({ openid: 1 });
+schema.index({ 'meta.createdAt': 1 });
 schema.plugin(metaPlugin);
 
 module.exports = app => {

+ 1 - 0
app/model/patientdocs.js

@@ -12,6 +12,7 @@ const PatientdocsSchema = {
 const schema = new Schema(PatientdocsSchema, { toJSON: { virtuals: true } });
 schema.index({ patientid: 1 });
 schema.index({ doctorid: 1 });
+schema.index({ 'meta.createdAt': 1 });
 schema.plugin(metaPlugin);
 
 module.exports = app => {

+ 1 - 0
app/model/room.js

@@ -13,6 +13,7 @@ const RoomSchema = {
 const schema = new Schema(RoomSchema, { toJSON: { virtuals: true } });
 schema.index({ patientid: 1 });
 schema.index({ doctorid: 1 });
+schema.index({ 'meta.createdAt': 1 });
 schema.plugin(metaPlugin);
 
 module.exports = app => {

+ 1 - 0
app/model/user.js

@@ -16,6 +16,7 @@ const UserSchema = {
 const schema = new Schema(UserSchema, { toJSON: { virtuals: true } });
 schema.index({ openid: 1 });
 schema.index({ mobile: 1 });
+schema.index({ 'meta.createdAt': 1 });
 schema.plugin(metaPlugin);
 
 module.exports = app => {

+ 15 - 0
app/service/article.js

@@ -9,6 +9,21 @@ class ArticleService extends CrudService {
   constructor(ctx) {
     super(ctx, 'article');
     this.model = this.ctx.model.Article;
+    this.pdModel = this.ctx.model.Patientdocs;
+  }
+  async query(query) {
+    query = this.ctx.service.util.dealQuery(query);
+    const { patientid, skip = 0, limit = 0 } = query;
+    if (patientid) {
+      // 需要查出这个病人所属的医生,然后添加医生范围的条件
+      const doctors = await this.pdModel.find({ patientid }, 'doctorid');
+      const ids = doctors.map(i => JSON.parse(JSON.stringify(i.doctorid)));
+      query.user_id = ids;
+    }
+    const data = await this.model.find(query).skip(parseInt(skip)).limit(parseInt(limit))
+      .sort({ 'meta.createdAt': -1 });
+    const total = await this.model.count(query);
+    return { data, total };
   }
 }
 

+ 68 - 0
app/service/util.js

@@ -0,0 +1,68 @@
+'use strict';
+const _ = require('lodash');
+const moment = require('moment');
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const fs = require('fs');
+
+class UtilService extends CrudService {
+  constructor(ctx) {
+    super(ctx);
+    this.mq = this.ctx.mq;
+  }
+  async utilMethod(query, body) { }
+
+
+  dealQuery(query) {
+    return this.turnFilter(this.turnDateRangeQuery(query));
+  }
+
+  /**
+   * 将查询条件中模糊查询的标识转换成对应object
+   * @param {Object} filter 查询条件
+   */
+  turnFilter(filter) {
+    const str = /^%\S*%$/;
+    const keys = Object.keys(filter);
+    for (const key of keys) {
+      const res = key.match(str);
+      console.log(res);
+      if (res) {
+        const newKey = key.slice(1, key.length - 1);
+        filter[newKey] = new RegExp(filter[key]);
+        delete filter[key];
+      }
+    }
+    return filter;
+  }
+  /**
+   * 将时间转换成对应查询Object
+   * @param {Object} filter 查询条件
+   */
+  turnDateRangeQuery(filter) {
+    const keys = Object.keys(filter);
+    for (const k of keys) {
+      if (k.includes('@')) {
+        const karr = k.split('@');
+        //  因为是针对处理范围日期,所以必须只有,开始时间和结束时间
+        if (karr.length === 2) {
+          const type = karr[1];
+          if (type === 'start') {
+            filter[karr[0]] = {
+              ..._.get(filter, karr[0], {}),
+              $gte: filter[k],
+            };
+          } else {
+            filter[karr[0]] = {
+              ..._.get(filter, karr[0], {}),
+              $lte: filter[k],
+            };
+          }
+          delete filter[k];
+        }
+      }
+    }
+    return filter;
+  }
+
+}
+module.exports = UtilService;