lrf402788946 %!s(int64=4) %!d(string=hai) anos
pai
achega
5766ce2a90

+ 80 - 0
app/controller/patent/.disclosure.js

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

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

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

+ 32 - 0
app/middleware/disclosure_record.js

@@ -0,0 +1,32 @@
+'use strict';
+const _ = require('lodash');
+
+const addRecord = async (ctx, id, method) => {
+  return await ctx.service.patent.disclosure.record({ id, method });
+};
+
+module.exports = options => {
+  return async function disclosure_record(ctx, next) {
+    console.log('function in disclosure_record middleware');
+    await next();
+    const { url, method } = ctx.request;
+    if (method === 'POST') {
+      // 将添加,修改拦截,给加上记录
+      const arr = url.split('/');
+      const last = _.last(arr);
+      const { data } = ctx.body;
+      const id = data._id;
+      let word = '';
+      if (last === 'disclosure') {
+        // create
+        word = 'create';
+      } else {
+        // update
+        word = 'update';
+      }
+      const nd = await addRecord(ctx, id, word);
+      ctx.body.data = nd;
+    }
+
+  };
+};

+ 41 - 0
app/model/patent/disclosure.js

@@ -0,0 +1,41 @@
+'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 disclosure = {
+  user_id: { type: ObjectId }, // 用户id
+  admin_id: { type: ObjectId }, // 管理员id
+  name: { type: String }, // 发明名称
+  apply_name: { type: String }, // 申请人
+  type: { type: String }, // 申请类型
+  inventer: { type: String }, // 发明人
+  contact: { type: String }, // 技术联系人
+  phone: { type: String }, // 联系人电话
+  email: { type: String }, // 联系人邮箱
+  desc: { type: String }, // 特殊情况说明
+  questions: { type: Object }, // 问题
+  is_mech: { type: String }, // 是否需要机构
+  mechanism_id: { type: ObjectId }, // 机构id
+  mechanism_name: { type: String }, // 机构名称
+  status: { type: String, default: '0' }, // 状态:0-已申请;1-机构审核;-1-机构审核未通过;2-管理员评估;-2-管理员评估未通过;3-管理员评估通过,等待上传至国家库;4-上传完成
+  record: { type: Array }, // 记录
+  remark: { type: String },
+};
+const schema = new Schema(disclosure, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ admin_id: 1 });
+schema.index({ user_id: 1 });
+schema.index({ apply_name: 1 });
+schema.index({ name: 1 });
+schema.index({ status: 1 });
+schema.index({ is_mech: 1 });
+schema.index({ mechanism_id: 1 });
+schema.index({ mechanism_name: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Disclosure', schema, 'disclosure');
+};

+ 32 - 0
app/model/patent/mechanism.js

@@ -0,0 +1,32 @@
+'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 { Secret } = require('naf-framework-mongoose/lib/model/schema');
+// 机构表
+const mechanism = {
+  name: { type: String }, // 机构名
+  contacts: { type: String }, // 联系人
+  phone: { type: String }, // 联系电话
+  passwd: { type: Secret, select: false }, // 密码
+  email: { type: String }, // 电子邮箱
+  address: { type: String }, // 联系地址
+  industry: { type: String }, // 所属行业
+  // 21-05-07添加区字段
+  juris: { type: String }, // 辖区
+  status: { type: String, required: false, default: '0', maxLength: 200 }, // 审核状态,0-注册,1-通过,2-拒绝
+  isdel: { type: String, required: false, default: '0' }, // 0=>未删除;1=>已删除
+  remark: { type: String },
+  create_time: { type: String, default: moment(new Date()).format('YYYY-MM-DD HH:mm:ss') },
+};
+const schema = new Schema(mechanism, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ name: 1 });
+schema.index({ industry: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('PatentMechanism', schema, 'patent_mechanism');
+};

+ 3 - 0
app/router.js

@@ -68,4 +68,7 @@ module.exports = app => {
   require('./router/kjzl/kjzl_chat')(app); // 科教之旅-评价
   require('./router/kjzl/kjzl_order')(app); // 科教之旅-订单表
   require('./router/kjzl/kjzl_expert_view')(app); // 科教之旅-专家视点
+
+  // 专利运营
+  require('./router/patent/disclosure')(app); // 交底表
 };

+ 14 - 0
app/router/patent/disclosure.js

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

+ 67 - 0
app/service/patent/disclosure.js

@@ -0,0 +1,67 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const _ = require('lodash');
+const moment = require('moment');
+const assert = require('assert');
+
+// 交底书
+class DisclosureService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'disclosure');
+    this.model = this.ctx.model.Patent.Disclosure;
+  }
+
+  /**
+   * 交底书审核
+   * @param {body} body 参数
+   * @property id 数据id
+   * @property status 交底书要改变成的状态
+   * @property info 其他数据,当做多个备注,记录使用
+   */
+  async check({ id, status, remark }) {
+    console.log(remark);
+    await this.model.updateOne({ id }, { status });
+    // 换成对应的状态码,record在下面
+    return await this.record({ id, status, remark });
+  }
+
+  async record({ id, method, remark }) {
+    let word = '';
+    switch (method) {
+      case 'create':
+        word = '创建';
+        break;
+      case 'update':
+        word = '修改';
+        break;
+      case '1':
+        word = '预评估审核通过';
+        break;
+      case '-1':
+        word = '预评估审核失败';
+        break;
+      case '2':
+        word = '申请审核成功';
+        break;
+      case '-2':
+        word = '申请审核失败';
+        break;
+      default:
+        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);
+    return await data.save();
+
+  }
+}
+
+module.exports = DisclosureService;

+ 38 - 0
app/service/util/util.js

@@ -12,7 +12,45 @@ class UtilService extends CrudService {
   async utilMethod(query, body) {
     const Path = require('path');
     const Excel = require('exceljs');
+    const wb = new Excel.Workbook();
+    await wb.xlsx.readFile('achieve.xlsx');
+    const ws = wb.getWorksheet('Sheet1');
+    const meta = [ 'type', 'contacts', 'phone', 'name', 'company', 'team', 'achievebrief', 'features' ];
+    const arr = [];
+    const getValue = v => {
+      const rt = _.get(v, 'richText');
+      let value = '';
+      if (rt) {
+        for (const o of rt) {
+          const { text } = o;
+          value = `${value} ${text}`;
+        }
+      } else {
+        value = _.get(v, 'text');
+      }
+      return value;
+
+    };
+    ws.eachRow((row, i) => {
+      const vs = row.values;
+      const obj = {};
+      let mi = 1;
+      for (const m of meta) {
+        let v = vs[mi];
+        if (_.isObject(v)) {
+          v = getValue(v);
+        }
+        obj[m] = v;
+        mi++;
+      }
+      // 添加user_id
+      obj.user_id = ObjectId('60f7ad9f7b02eb03888cb7c3');
+      arr.push(obj);
+    });
+    await this.ctx.model.Product.insertMany(arr);
+  }
 
+  async expertExport() {
     const { data } = await this.ctx.service.users.expert.query();
     const root_path = 'E:\\exportFile\\';
     const file_type = '';