|
@@ -1,12 +1,18 @@
|
|
|
'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');
|
|
|
+const { has } = require('lodash');
|
|
|
|
|
|
-// 专利信息
|
|
|
+// 专利交易
|
|
|
class Patent_transService extends CrudService {
|
|
|
constructor(ctx) {
|
|
|
super(ctx, 'patenttrans');
|
|
@@ -22,7 +28,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 +150,43 @@ 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(async (row, rindex) => {
|
|
|
+ if (rindex !== 1) {
|
|
|
+ // 组织数据
|
|
|
+ const create_number = row.getCell(3).value || undefined,
|
|
|
+ patent_name = row.getCell(2).value || undefined,
|
|
|
+ on_obligee = row.getCell(4).value || undefined,
|
|
|
+ transfer_date = moment(row.getCell(5).value).format('YYYY-MM-DD') || undefined,
|
|
|
+ on_afterobligee = row.getCell(6).value || undefined,
|
|
|
+ status = row.getCell(7).value || undefined,
|
|
|
+ const has_data = await this.model.count({ create_number });
|
|
|
+ if (!has_data) {
|
|
|
+ const obj = {patent_name,create_number,on_obligee,transfer_date,on_afterobligee,status };
|
|
|
+ // 此处添加判断条件,不限制则不需要加,直接放过即可
|
|
|
+ const { result, notice } = this.tocheckData(obj);
|
|
|
+ if (result) {
|
|
|
+ arr.push(obj);
|
|
|
+ } else {
|
|
|
+ allNotice.push(notice);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (allNotice.length > 0) return allNotice;
|
|
|
+ const res = await this.model.insertMany(arr);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
module.exports = Patent_transService;
|