فهرست منبع

Merge branch 'patent' of http://git.cc-lotus.info/live/service-live into patent

lrf 3 سال پیش
والد
کامیت
ee4d4c0676

+ 152 - 150
app/controller/patent/.patentinfo.js

@@ -1,169 +1,169 @@
 module.exports = {
   create: {
     requestBody: [
-      'create_number',
-      'create_date',
-      'success_number',
-      'success_date',
-      'inventor',
-      'agent',
-      'agent_personal',
-      'abstract',
-      'address',
-      'name',
-      'apply_personal',
-      'term',
-      'type',
-      'img_url',
-      'nationality',
-      'ipc_type',
-      'onlegal_status',
-      'legal_status',
-      'law_date',
-      'on_obligee',
-      'apply_address',
-      'apply_other',
-      'law_num',
-      'first_opendate',
-      'empower_date',
-      'lose_date',
-      'examine_date',
-      'invention_design',
-      'incopat_link',
-      'first_ask',
-      'first_apply',
-      'apply_city',
-      'business_code',
-      'business_address',
-      'first_inventor',
-      'shared_value',
-      'techol_stable',
-      'techol_advanced',
-      'pct_apply',
-      'pct_publish',
-      'status',
-      'trans_status',
-      'user_id',
+      "create_number",
+      "create_date",
+      "success_number",
+      "success_date",
+      "inventor",
+      "agent",
+      "agent_personal",
+      "abstract",
+      "address",
+      "name",
+      "apply_personal",
+      "term",
+      "type",
+      "img_url",
+      "nationality",
+      "ipc_type",
+      "onlegal_status",
+      "legal_status",
+      "law_date",
+      "on_obligee",
+      "apply_address",
+      "apply_other",
+      "law_num",
+      "first_opendate",
+      "empower_date",
+      "lose_date",
+      "examine_date",
+      "invention_design",
+      "incopat_link",
+      "first_ask",
+      "first_apply",
+      "apply_city",
+      "business_code",
+      "business_address",
+      "first_inventor",
+      "shared_value",
+      "techol_stable",
+      "techol_advanced",
+      "pct_apply",
+      "pct_publish",
+      "status",
+      "trans_status",
+      "user_id",
     ],
   },
   destroy: {
-    params: ['!id'],
-    service: 'delete',
+    params: ["!id"],
+    service: "delete",
   },
   update: {
-    params: ['!id'],
+    params: ["!id"],
     requestBody: [
-      'create_number',
-      'create_date',
-      'success_number',
-      'success_date',
-      'inventor',
-      'agent',
-      'agent_personal',
-      'abstract',
-      'address',
-      'name',
-      'apply_personal',
-      'term',
-      'type',
-      'img_url',
-      'nationality',
-      'ipc_type',
-      'onlegal_status',
-      'legal_status',
-      'law_date',
-      'on_obligee',
-      'apply_address',
-      'apply_other',
-      'law_num',
-      'first_opendate',
-      'empower_date',
-      'lose_date',
-      'examine_date',
-      'invention_design',
-      'incopat_link',
-      'first_ask',
-      'first_apply',
-      'apply_city',
-      'business_code',
-      'business_address',
-      'first_inventor',
-      'shared_value',
-      'techol_stable',
-      'techol_advanced',
-      'pct_apply',
-      'pct_publish',
-      'status',
-      'trans_status',
-      'user_id',
+      "create_number",
+      "create_date",
+      "success_number",
+      "success_date",
+      "inventor",
+      "agent",
+      "agent_personal",
+      "abstract",
+      "address",
+      "name",
+      "apply_personal",
+      "term",
+      "type",
+      "img_url",
+      "nationality",
+      "ipc_type",
+      "onlegal_status",
+      "legal_status",
+      "law_date",
+      "on_obligee",
+      "apply_address",
+      "apply_other",
+      "law_num",
+      "first_opendate",
+      "empower_date",
+      "lose_date",
+      "examine_date",
+      "invention_design",
+      "incopat_link",
+      "first_ask",
+      "first_apply",
+      "apply_city",
+      "business_code",
+      "business_address",
+      "first_inventor",
+      "shared_value",
+      "techol_stable",
+      "techol_advanced",
+      "pct_apply",
+      "pct_publish",
+      "status",
+      "trans_status",
+      "user_id",
     ],
   },
   show: {
     parameters: {
-      params: ['!id'],
+      params: ["!id"],
     },
-    service: 'fetch',
+    service: "fetch",
   },
   index: {
     parameters: {
       query: {
-        create_number: 'create_number',
-        create_date: 'create_date',
-        success_number: 'success_number',
-        success_date: 'success_date',
-        inventor: '%inventor%',
-        agent: '%agent%',
-        agent_personal: '%agent_personal%',
-        abstract: '%abstract%',
-        address: '%address%',
-        name: '%name%',
-        apply_personal: '%apply_personal%',
-        term: 'term',
-        type: 'type',
-        nationality: '%nationality%',
-        ipc_type: '%ipc_type%',
-        onlegal_status: '%onlegal_status%',
-        legal_status: '%legal_status%',
-        law_date: 'law_date',
-        on_obligee: '%on_obligee%',
-        apply_address: '%apply_address%',
-        apply_other: '%apply_other%',
-        law_num: '%law_num%',
-        first_opendate: 'first_opendate',
-        empower_date: 'empower_date',
-        lose_date: 'lose_date',
-        examine_date: 'examine_date',
-        invention_design: '%invention_design%',
-        incopat_link: '%incopat_link%',
-        first_ask: '%first_ask%',
-        first_apply: '%first_apply%',
-        apply_city: '%apply_city%',
-        business_code: '%business_code%',
-        business_address: '%business_address%',
-        first_inventor: '%first_inventor%',
-        shared_value: '%shared_value%',
-        techol_stable: '%techol_stable%',
-        techol_advanced: '%techol_advanced%',
-        pct_apply: '%pct_apply%',
-        pct_publish: '%pct_publish%',
-        status: 'status',
-        trans_status: 'trans_status',
-        'create_date@start': 'create_date@start',
-        'create_date@end': 'create_date@end',
-        'success_date@start': 'success_date@start',
-        'success_date@end': 'success_date@end',
-        'empower_date@start': 'empower_date@start',
-        'empower_date@end': 'empower_date@end',
-        key_word: 'key_word',
-        single_inventor: 'single_inventor',
-        code: 'code',
-        user_id: 'user_id',
+        create_number: "create_number",
+        create_date: "create_date",
+        success_number: "success_number",
+        success_date: "success_date",
+        inventor: "%inventor%",
+        agent: "%agent%",
+        agent_personal: "%agent_personal%",
+        abstract: "%abstract%",
+        address: "%address%",
+        name: "%name%",
+        apply_personal: "%apply_personal%",
+        term: "term",
+        type: "type",
+        nationality: "%nationality%",
+        ipc_type: "%ipc_type%",
+        onlegal_status: "%onlegal_status%",
+        legal_status: "%legal_status%",
+        law_date: "law_date",
+        on_obligee: "%on_obligee%",
+        apply_address: "%apply_address%",
+        apply_other: "%apply_other%",
+        law_num: "%law_num%",
+        first_opendate: "first_opendate",
+        empower_date: "empower_date",
+        lose_date: "lose_date",
+        examine_date: "examine_date",
+        invention_design: "%invention_design%",
+        incopat_link: "%incopat_link%",
+        first_ask: "%first_ask%",
+        first_apply: "%first_apply%",
+        apply_city: "%apply_city%",
+        business_code: "%business_code%",
+        business_address: "%business_address%",
+        first_inventor: "%first_inventor%",
+        shared_value: "%shared_value%",
+        techol_stable: "%techol_stable%",
+        techol_advanced: "%techol_advanced%",
+        pct_apply: "%pct_apply%",
+        pct_publish: "%pct_publish%",
+        status: "status",
+        trans_status: "trans_status",
+        "create_date@start": "create_date@start",
+        "create_date@end": "create_date@end",
+        "success_date@start": "success_date@start",
+        "success_date@end": "success_date@end",
+        "empower_date@start": "empower_date@start",
+        "empower_date@end": "empower_date@end",
+        key_word: "key_word",
+        single_inventor: "single_inventor",
+        code: "code",
+        user_id: "user_id",
       },
     },
-    service: 'query',
+    service: "query",
     options: {
-      query: ['skip', 'limit'],
-      sort: ['create_date'],
+      query: ["skip", "limit"],
+      sort: ["create_date"],
       desc: true,
       count: true,
       projection: {
@@ -175,18 +175,20 @@ module.exports = {
         term: 1,
         type: 1,
         onlegal_status: 1,
+        status: 1,
+        trans_status: 1,
       },
     },
   },
   toImport: {
-    requestBody: ['uri', 'code'],
-    service: 'toImport',
+    requestBody: ["uri", "code"],
+    service: "toImport",
   },
   toExport: {
-    requestBody: ['user', 'query'],
-    service: 'toExport',
+    requestBody: ["user", "query"],
+    service: "toExport",
   },
   updateUser: {
-    requestBody: ['patentData', 'user_id'],
+    requestBody: ["patentData", "user_id"],
   },
 };

+ 4 - 0
app/controller/patent/.patenttrans.js

@@ -106,6 +106,10 @@ module.exports = {
       count: true,
     },
   },
+  toImport: {
+    requestBody: ["uri"],
+    service: "toImport",
+  },
   check: {
     requestBody: ["id", "status", "remark", "transfer_date"],
   },

+ 1 - 0
app/router/patent/patenttrans.js

@@ -12,4 +12,5 @@ module.exports = app => {
   router.resources(target, `${profix}${vision}/${index}/${target}`, metaTime, record, controller[index][target]); // index、create、show、destroy
   router.post(target, `${profix}${vision}/${index}/${target}/update/:id`, record, controller[index][target].update);
   router.post(target, `${profix}${vision}/${index}/${target}/check`, controller[index][target].check);
+  router.post(target, `${profix}${vision}/${index}/${target}/toImport`, controller[index][target].toImport);
 };

+ 6 - 2
app/service/patent/patentinfo.js

@@ -33,9 +33,13 @@ class PatentinfoService extends CrudService {
     this.export_limit = 50;
   }
 
-  async query(query, { skip = 0, limit = 0 }) {
+  async query(query, { skip = 0, limit = 0, projection }) {
     const newquery = await this.resetCode(query);
-    const res = await this.model.find(newquery).skip(parseInt(skip)).limit(parseInt(limit)).sort({ create_date: -1 });
+    const res = await this.model
+      .find(newquery, projection)
+      .skip(parseInt(skip))
+      .limit(parseInt(limit))
+      .sort({ create_date: -1 });
     return res;
   }
   async count(query) {

+ 105 - 5
app/service/patent/patenttrans.js

@@ -1,17 +1,35 @@
 'use strict';
+
+const assert = require('assert');
+const moment = require('moment');
+const Excel = require('exceljs');
+const Path = require('path');
+const _ = require('lodash');
+const { sep } = require('path');
+const fs = require('fs');
 const { CrudService } = require('naf-framework-mongoose/lib/service');
 const { BusinessError, ErrorCode } = require('naf-core').Error;
-const _ = require('lodash');
-const assert = require('assert');
+const { trimData } = require('naf-core').Util;
 const { ObjectId } = require('mongoose').Types;
-const moment = require('moment');
 
-// 专利信息
+// 专利交易
 class Patent_transService extends CrudService {
   constructor(ctx) {
     super(ctx, 'patenttrans');
     this.model = this.ctx.model.Patent.Patenttrans;
     this.notice = this.ctx.model.Patent.Patentexamine;
+    this.root_path = _.get(this.ctx.app.config.export, 'root_path');
+    if (process.env.NODE_ENV === 'development') {
+      this.root_path = 'E:\\exportFile\\';
+    }
+    this.file_type = '';
+    if (!fs.existsSync(`${this.root_path}${this.file_type}`)) {
+      // 如果不存在文件夹,就创建
+      fs.mkdirSync(`${this.root_path}${this.file_type}`);
+    }
+    this.excel_path = `${sep}excel${sep}`;
+    this.domain = 'http://127.0.0.1';
+    this.export_limit = 50;
   }
   /**
    * 专利交易审核
@@ -22,7 +40,10 @@ class Patent_transService extends CrudService {
    * @property info 其他数据,当做多个备注,记录使用
    */
   async check({ id, status, remark, transfer_date }) {
-    await this.model.updateOne({ _id: ObjectId(id) }, { status, transfer_date });
+    await this.model.updateOne(
+      { _id: ObjectId(id) },
+      { status, transfer_date }
+    );
     // 换成对应的状态码,record在下面
     return await this.record({ id, method: status, remark });
   }
@@ -141,6 +162,85 @@ class Patent_transService extends CrudService {
       await this.notice.create(obj);
     }
   }
+  async toImport({ uri }) {
+    assert(uri, '未获取到文件地址');
+    const file = await this.ctx.curl(`${this.domain}${uri}`);
+    if (!(file && file.data)) {
+      throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到指定文件');
+    }
+    const workbook = new Excel.Workbook();
+    await workbook.xlsx.load(file.data);
+    const sheet = workbook.getWorksheet(1);
+    const arr = [];
+    const allNotice = [];
+    sheet.eachRow((row, rindex) => {
+      if (rindex !== 1) {
+        const create_number = row.getCell(2).value || undefined,
+          patent_name = row.getCell(3).value || undefined,
+          type = row.getCell(4).value || undefined,
+          budget = row.getCell(5).value || undefined,
+          on_obligee = row.getCell(6).value || undefined,
+          on_afterobligee = row.getCell(7).value || undefined,
+          transfer_date = moment(row.getCell(8).value).format('YYYY-MM-DD') || undefined,
+          contact = row.getCell(9).value || undefined,
+          phone = row.getCell(10).value || undefined,
+          email = row.getCell(11).value || undefined,
+          requirementdesc = row.getCell(12).value || undefined,
+          expect = row.getCell(13).value || undefined,
+          condition = row.getCell(14).value || undefined,
+          status = row.getCell(15).value || '0';
+        const obj = {
+          create_number,
+          patent_name,
+          type,
+          budget,
+          on_obligee,
+          on_afterobligee,
+          transfer_date,
+          contact,
+          phone,
+          email,
+          requirementdesc,
+          expect,
+          condition,
+          status,
+        };
+        // 此处添加判断条件,不限制则不需要加,直接放过即可
+        const { result, notice } = this.tocheckData(obj);
+        if (result) {
+          arr.push(obj);
+        } else {
+          allNotice.push(notice);
+        }
+      }
+    });
+    if (allNotice.length > 0) return allNotice;
+    await this.model.insertMany(arr);
+  }
+  /**
+   * 检查数据是否没填 必填项
+   * @param {Object} object 每行数据,已转换成model的字段名
+   */
+  tocheckData(object) {
+    let result = true;
+    const { number } = object;
+    let notice;
+    const arr = [
+      { column: 'create_number', zh: '专利号' },
+    ];
+    const word = [];
+    for (const o of arr) {
+      const { column, zh } = o;
+      if (!_.get(object, column)) {
+        result = false;
+        word.push(`${zh}`);
+      }
+    }
+    if (!result) {
+      notice = `序号${number}缺少:${word.join(';')}`;
+    }
+    return { result, notice };
+  }
 }
 
 module.exports = Patent_transService;