guhongwei 3 년 전
부모
커밋
fac8cd5018
3개의 변경된 파일24개의 추가작업 그리고 10개의 파일을 삭제
  1. 2 0
      app/controller/patent/.patentnotice.js
  2. 1 0
      app/model/patent/patentnotice.js
  3. 21 10
      app/service/patent/patentnotice.js

+ 2 - 0
app/controller/patent/.patentnotice.js

@@ -5,6 +5,7 @@ module.exports = {
       "send_name",
       "to_type",
       "to_id",
+      "to_name",
       "is_read",
       "content",
       "notice_file",
@@ -21,6 +22,7 @@ module.exports = {
       "send_name",
       "to_type",
       "to_id",
+      "to_name",
       "is_read",
       "content",
       "notice_file",

+ 1 - 0
app/model/patent/patentnotice.js

@@ -9,6 +9,7 @@ const patentnotice = {
   send_name: { type: String }, // 发送人姓名
   to_type: { type: String }, // 0-所有人;1-机构用户;2-平台用户;3机构发给自己用户,4:科企发给个人用户
   to_id: { type: [ ObjectId ] }, // 接收人id
+  to_name: { type: String }, // 接收人姓名
   is_read: { type: Boolean, default: false }, // 是否已读
   content: { type: String }, // 内容
   notice_file: { type: Array }, // 通知文件

+ 21 - 10
app/service/patent/patentnotice.js

@@ -17,7 +17,10 @@ class PatentnoticeService extends CrudService {
 
   async query(query, { skip = 0, limit = 0 } = {}) {
     const nq = await this.resetQuery(_.cloneDeep(query));
-    const data = await this.model.find(nq).skip(parseInt(skip)).limit(parseInt(limit))
+    const data = await this.model
+      .find(nq)
+      .skip(parseInt(skip))
+      .limit(parseInt(limit))
       .sort({ 'meta.createdAt': -1 });
     return data;
   }
@@ -38,33 +41,41 @@ class PatentnoticeService extends CrudService {
 
   /**
    * 根据send_id,和to_type,查询范围内的用户数据
-   * to_type=1:只查机构用户
+   * to_type=0:都查
+   * ...=1:只查机构用户
    * ...=2:只查平台用户
    * ...=3:机构给自己的平台用户发送信息
-   * ...=0:都查
+   * ...=4:给指定用户发送消息
    * @param {Object} body 数据
    */
   async create(body) {
     let object = {}; // 最后insert的数据集
     // 先判断是不是3,如果不是3,就说明是管理员发送的
-    const { send_id, to_type, content, send_name } = body;
+    const { send_id, send_name, to_type, to_id, to_name, content, notice_file } = body;
     const admin = await this.adminModel.findById(send_id);
     // 获取自己的信息
-    if (!admin) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到发送人信息');
+    if (!admin) { throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到发送人信息'); }
     if (to_type === '3') {
       // 获取自己下的用户
       const data = await this.getOrgUser(admin.code);
       // 整理->添加
-      object = { send_id, send_name, to_type, to_id: data.map(i => i._id), content };
+      object = { send_id, send_name, to_type, to_id: data.map(i => i._id), to_name: data.map(i => i.name), content, notice_file };
+    } else if (to_type === '4') {
+      object = { send_id, send_name, to_type, to_id, to_name, content, notice_file };
     } else {
       // 获取该管理员下的机构用户
-      const org = await this.adminModel.find({ pid: admin._id }, { id: 1, code: 1 });
-      if (org.length <= 0) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到相关机构信息');
+      const org = await this.adminModel.find(
+        { pid: admin._id },
+        { id: 1, code: 1 }
+      );
+      if (org.length <= 0) {
+        throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到相关机构信息');
+      }
       // 然后进行数据整合
       if (to_type === '1') {
         // 将机构用户整理->添加
         const ids = org.map(i => i._id);
-        object = { send_id, send_name, to_type, to_id: ids, content };
+        object = { send_id, send_name, to_type, to_id: ids, content, notice_file };
       } else {
         // 再用机构的信息去查机构下的用户,整理->添加
         const p1 = await this.getOrgUser(admin.code);
@@ -73,7 +84,7 @@ class PatentnoticeService extends CrudService {
         if (to_type === '0') {
           ids = [ ...ids, ...org.map(i => i._id) ];
         }
-        object = { send_id, send_name, to_type, to_id: ids, content };
+        object = { send_id, send_name, to_type, to_id: ids, content, notice_file };
       }
     }