guhongwei %!s(int64=3) %!d(string=hai) anos
pai
achega
00ede32759

+ 75 - 0
app/controller/patent/.patentsafeg.js

@@ -0,0 +1,75 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "user_id",
+      "admin_id",
+      "create_number",
+      "name",
+      "apply_name",
+      "type",
+      "inventor",
+      "contact",
+      "phone",
+      "email",
+      "questions",
+      "status",
+      "file",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "user_id",
+      "admin_id",
+      "create_number",
+      "name",
+      "apply_name",
+      "type",
+      "inventor",
+      "contact",
+      "phone",
+      "email",
+      "questions",
+      "status",
+      "file",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        user_id: "user_id",
+        admin_id: "admin_id",
+        create_number: "create_number",
+        name: "name",
+        apply_name: "apply_name",
+        type: "type",
+        status: "status",
+        "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,
+    },
+  },
+  check: {
+    requestBody: ["id", "status", "remark"],
+  },
+};

+ 13 - 0
app/controller/patent/patentsafeg.js

@@ -0,0 +1,13 @@
+'use strict';
+const meta = require('./.patentsafeg.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 专利维权-维权书
+class patentsafegController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.patent.patentsafeg;
+  }
+}
+module.exports = CrudController(patentsafegController, meta);

+ 35 - 0
app/model/patent/patentsafeg.js

@@ -0,0 +1,35 @@
+'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 patentsafeg = {
+  user_id: { type: ObjectId }, // 用户id
+  admin_id: { type: ObjectId }, // 管理员id
+  create_number: { type: String }, // 申请号
+  name: { type: String }, // 发明名称
+  apply_name: { type: String }, // 申请人
+  type: { type: String }, // 申请类型
+  inventor: { type: String }, // 发明人
+  contact: { type: String }, // 联系人
+  phone: { type: String }, // 联系人电话
+  email: { type: String }, // 联系人邮箱
+  questions: { type: Object }, // 问题
+  file: { type: Array }, // 报告文件
+  record: { type: Array }, // 记录
+  status: { type: String, default: '0' }, // 状态
+  remark: { type: String },
+};
+const schema = new Schema(patentsafeg, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ user_id: 1 });
+schema.index({ admin_id: 1 });
+schema.index({ create_number: 1 });
+schema.index({ status: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Patentsafeg', schema, 'patent_safeg');
+};

+ 2 - 0
app/router.js

@@ -91,4 +91,6 @@ module.exports = app => {
   require('./router/patent/patentearly')(app); // 专利信息已授权专利预警表
   require('./router/patent/patenttrans')(app); // 专利交易表
   require('./router/patent/patenttechol')(app); // 专利需求表
+  require('./router/patent/patentsafeg')(app); // 专利维权表
+
 };

+ 15 - 0
app/router/patent/patentsafeg.js

@@ -0,0 +1,15 @@
+'use strict';
+
+
+module.exports = app => {
+  const { router, controller } = app;
+  const profix = '/api/live/';
+  const vision = 'v0';
+  const index = 'patent';
+  const target = 'patentsafeg';
+  const metaTime = app.middleware.createTime();
+  const record = app.middleware.patentapplyRecord(`${index}.${target}`);
+  router.resources(target, `${profix}${vision}/${index}/${target}`, metaTime, record, controller[index][target]); // index、create、show、destroy
+  router.post(target, `${profix}${vision}/${index}/${target}/check`, controller[index][target].check);
+  router.post(target, `${profix}${vision}/${index}/${target}/update/:id`, record, controller[index][target].update);
+};

+ 108 - 0
app/service/patent/patentsafeg.js

@@ -0,0 +1,108 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const Path = require('path');
+const _ = require('lodash');
+const moment = require('moment');
+const assert = require('assert');
+const { ObjectId } = require('mongoose').Types;
+const Excel = require('exceljs');
+const { sep } = require('path');
+const fs = require('fs');
+
+// 专利维权-维权书
+class PatentsafegService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'patentsafeg');
+    this.model = this.ctx.model.Patent.Patentsafeg;
+    this.notice = this.ctx.model.Patent.Patentexamine;
+  }
+  /**
+   * 维权书
+   * @param {body} body 参数
+   * @property id 数据id
+   * @property status 交底书要改变成的状态
+   * @property info 其他数据,当做多个备注,记录使用
+   */
+  async check({ id, status, remark }) {
+    const data = { status };
+    await this.model.updateOne({ _id: ObjectId(id) }, data);
+    // 换成对应的状态码,record在下面
+    return await this.record({ id, method: status, remark });
+  }
+  async record({ id, method, remark }) {
+    let word = '';
+    switch (`${method}`) {
+      case 'create':
+        word = '已申请';
+        break;
+      case 'update':
+        word = '修改';
+        break;
+      case '0':
+        word = '管理员审核';
+        break;
+      case '1':
+        word = '管理员审核通过';
+        break;
+      case '-1':
+        word = '管理员审核未通过';
+        break;
+      default:
+        word = '未知状态';
+        break;
+    }
+    const data = await this.model.findById(id);
+    if (!data) {
+      throw new BusinessError(
+        ErrorCode.DATA_NOT_EXIST,
+        '添加记录----未找到数据'
+      );
+    }
+    const obj = {
+      time: moment().format('YYYY-MM-DD HH:mm:ss'),
+      word,
+      remark,
+    };
+    data.record.push(obj);
+    const res = await data.save();
+    this.toNotice(id, method);
+    return res;
+  }
+  async toNotice(id, code) {
+    const data = await this.model.findById(id);
+    if (!data) return;
+    const { user_id, admin_id, name, apply_name } = data;
+    const arr = [];
+    let content = '';
+    let to = '';
+    switch (code) {
+      case 'create':
+        content = `${apply_name}提交了专利维权书【${name}】的申报,请及时前往申请管理进行处理`;
+        to = admin_id;
+        break;
+      case 'update':
+        content = `${apply_name}重新提交了专利维权书【${name}】的申报,请及时前往申请管理进行处理`;
+        to = admin_id;
+        break;
+      case '-1':
+        content = `您的专利维权书【${name}】未通过管理员的审核,请您及时修改,重新申请`;
+        to = user_id;
+        break;
+      case '1':
+        content = `您的专利维权书【${name}】已通过管理员的审核,请您耐心等待管理员审核`;
+        to = user_id;
+        break;
+      default:
+        break;
+    }
+    if (arr.length > 0) {
+      await this.notice.insertMany(arr);
+    } else {
+      const obj = { to, content };
+      await this.notice.create(obj);
+    }
+  }
+}
+
+module.exports = PatentsafegService;