lrf402788946 4 năm trước cách đây
mục cha
commit
b5b3403a7b
6 tập tin đã thay đổi với 100 bổ sung2 xóa
  1. 40 0
      app/controller/.remark.js
  2. 13 0
      app/controller/remark.js
  3. 20 0
      app/model/remark.js
  4. 3 0
      app/router.js
  5. 9 2
      app/service/groupchat.js
  6. 15 0
      app/service/remark.js

+ 40 - 0
app/controller/.remark.js

@@ -0,0 +1,40 @@
+module.exports = {
+  create: {
+    requestBody: ["!remarkid", "!benoteid", "!name"],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: ["!remarkid", "!benoteid", "!name"],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        remarkid: "remarkid",
+        benoteid: "benoteid",
+        name: "name",
+        "create_time@start": "create_time@start",
+        "create_time@end": "create_time@end",
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 13 - 0
app/controller/remark.js

@@ -0,0 +1,13 @@
+'use strict';
+const meta = require('./.remark.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 备注
+class RemarkController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.remark;
+  }
+}
+module.exports = CrudController(RemarkController, meta);

+ 20 - 0
app/model/remark.js

@@ -0,0 +1,20 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const moment = require('moment');
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+const { ObjectId } = require('mongoose').Types;
+// 备注表
+const remark = {
+  remarkid: { type: ObjectId, required: true }, // 做 备注人id
+  benoteid: { type: ObjectId, required: true }, // 被 备注人id
+  name: { type: String, required: true }, // 备注名称
+  create_time: { type: String, default: moment().format('YYYY-MM-DD HH:mm:ss') },
+};
+const schema = new Schema(remark, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('remark', schema, 'remark');
+};

+ 3 - 0
app/router.js

@@ -81,4 +81,7 @@ module.exports = app => {
   // 医疗科普文章
   router.resources('article', '/api/visit/article', controller.article); // index、create、show、destroy
   router.post('/api/visit/article/update/:id', controller.article.update);
+  // 备注
+  router.resources('remark', '/api/visit/remark', controller.remark); // index、create、show、destroy
+  router.post('/api/visit/remark/update/:id', controller.remark.update);
 };

+ 9 - 2
app/service/groupchat.js

@@ -4,6 +4,7 @@ const assert = require('assert');
 const _ = require('lodash');
 const { CrudService } = require('naf-framework-mongoose/lib/service');
 const { BusinessError, ErrorCode } = require('naf-core').Error;
+const { ObjectId } = require('mongoose').Types;
 
 class GroupChatService extends CrudService {
   constructor(ctx) {
@@ -12,17 +13,19 @@ class GroupChatService extends CrudService {
     this.cGroup = this.ctx.model.Group;
     this.cDoctor = this.ctx.model.Doctor;
     this.cPatient = this.ctx.model.Patient;
+    this.remark = this.ctx.model.Remark;
   }
 
-  async query({ groupid, sort = 1 }, { skip, limit }) {
+  async query({ groupid, sort = 1, userid }, { skip, limit }) {
     assert(groupid, 'groupid不能为空');
     const groupall = await this.model.find({ groupid });
     const groups = await this.model.find({ groupid }).sort({ sendtime: sort }).limit(limit)
       .skip(skip);
     const newgroups = [];
+    const remarks = await this.remark.find({ remarkid: userid });
     for (const el of groups) {
       let icon;
-      const { id, doctorid, doctorname, groupid, groupname, type, sendid, sendname, sendtime, contenttype, content, audiotime } = el;
+      let { id, doctorid, doctorname, groupid, groupname, type, sendid, sendname, sendtime, contenttype, content, audiotime } = el;
       if (el.type === '1') {
         const patient = await this.cPatient.findById(el.sendid);
         if (patient) {
@@ -33,6 +36,10 @@ class GroupChatService extends CrudService {
         const doctor = await this.cDoctor.findById(el.sendid);
         if (doctor) icon = doctor.icon;
       }
+      const d_r = remarks.find(f => ObjectId(f.benoteid).equals(doctorid));
+      if (d_r) doctorname = d_r.name;
+      const p_r = remarks.find(f => ObjectId(f.benoteid).equals(sendid));
+      if (p_r) sendname = p_r.name;
       const group = { id, doctorid, doctorname, groupid, groupname, type, sendid, sendname, sendtime, contenttype, content, icon, audiotime };
       newgroups.push(group);
     }

+ 15 - 0
app/service/remark.js

@@ -0,0 +1,15 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const _ = require('lodash');
+const assert = require('assert');
+
+// 备注
+class RemarkService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'remark');
+    this.model = this.ctx.model.Remark;
+  }
+}
+
+module.exports = RemarkService;