|
@@ -28,12 +28,13 @@ class PatentinfoService extends CrudService {
|
|
|
}
|
|
|
this.excel_path = `${sep}excel${sep}`;
|
|
|
this.domain = 'http://127.0.0.1';
|
|
|
- if (process.env.NODE_ENV === 'development') { this.domain = 'http://127.0.0.1:8000'; }
|
|
|
+ if (process.env.NODE_ENV === 'development') { this.domain = 'http://127.0.0.1:9999'; }
|
|
|
this.export_limit = 50;
|
|
|
}
|
|
|
|
|
|
async query(query, { skip = 0, limit = 0 }) {
|
|
|
const newquery = await this.resetCode(query);
|
|
|
+ console.log(newquery);
|
|
|
const res = await this.model
|
|
|
.find(newquery)
|
|
|
.skip(parseInt(skip))
|
|
@@ -58,19 +59,19 @@ class PatentinfoService extends CrudService {
|
|
|
];
|
|
|
delete newquery.type;
|
|
|
}
|
|
|
- const { code, inventor } = newquery;
|
|
|
+ const { code, user_id } = newquery;
|
|
|
let ids = [];
|
|
|
if (code) {
|
|
|
const plist = await this.personalModel.find({ code });
|
|
|
ids = plist.map(i => i._id);
|
|
|
if (ids.length > 0) {
|
|
|
- newquery.inventor = { $elemMatch: { $in: ids } };
|
|
|
+ newquery['inventor.user_id'] = { $in: ids };
|
|
|
delete newquery.code;
|
|
|
}
|
|
|
- } else if (inventor) {
|
|
|
- newquery.inventor = { $elemMatch: { $in: [ ObjectId(inventor) ] } };
|
|
|
+ } else if (user_id) {
|
|
|
+ newquery['inventor.user_id'] = ObjectId(user_id);
|
|
|
+ delete newquery.user_id;
|
|
|
}
|
|
|
-
|
|
|
return newquery;
|
|
|
}
|
|
|
|
|
@@ -79,9 +80,10 @@ class PatentinfoService extends CrudService {
|
|
|
let pids = await this.personalModel.find({ code }, { _id: 1 });
|
|
|
if (pids.length <= 0) return { data: [], total: 0 };
|
|
|
pids = pids.map(i => i._id);
|
|
|
- const query = { inventor: { $elemMatch: { $in: pids } } };
|
|
|
+ const query = { 'inventor.user_id': { $in: pids } };
|
|
|
if (status) query.status = status;
|
|
|
if (term) query.term = term;
|
|
|
+ console.log(query);
|
|
|
const data = await this.model
|
|
|
.find(query)
|
|
|
.skip(parseInt(skip))
|
|
@@ -94,7 +96,6 @@ class PatentinfoService extends CrudService {
|
|
|
async toImport({ uri, origin }) {
|
|
|
assert(uri, '未获取到文件地址');
|
|
|
const file = await this.ctx.curl(`${this.domain}${uri}`);
|
|
|
- console.log(file);
|
|
|
if (!(file && file.data)) {
|
|
|
throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到指定文件');
|
|
|
}
|
|
@@ -111,7 +112,7 @@ class PatentinfoService extends CrudService {
|
|
|
if (row) return { row, imageId };
|
|
|
})
|
|
|
);
|
|
|
- sheet.eachRow((row, rindex) => {
|
|
|
+ sheet.eachRow(async (row, rindex) => {
|
|
|
if (rindex !== 1) {
|
|
|
// 组织数据,图片的索引和行索引不一致,准确的说是:图片索引比行索引少1
|
|
|
// 原因:图片在工作簿中获取,按照1,2,3...顺序排序,但是行的第一行是表头(当前文件),所以当前行数需要减掉表头那一行
|
|
@@ -122,6 +123,7 @@ class PatentinfoService extends CrudService {
|
|
|
url: this.turnImageToBase64(workbook.getImage(imgid.imageId)),
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
const create_number = row.getCell(2).value || undefined,
|
|
|
create_date =
|
|
|
moment(row.getCell(3).value).format('YYYY-MM-DD') || undefined,
|
|
@@ -213,19 +215,26 @@ class PatentinfoService extends CrudService {
|
|
|
nameList = nameList.map(i => _.trim(i));
|
|
|
const l1 = await this.personalModel.find({ name: nameList });
|
|
|
const l2 = await this.organizationModel.find({ name: nameList });
|
|
|
- // 查出来的所有人,添加到user_id中
|
|
|
+ // 查出来的所有人
|
|
|
const nList = [ ...l1, ...l2 ];
|
|
|
for (const i of arr) {
|
|
|
const { inventor } = i;
|
|
|
let midNameList = inventor.split(/[,;/]/);
|
|
|
midNameList = midNameList.map(i => _.trim(i));
|
|
|
- if (!_.isArray(i.user_id)) i.user_id = [];
|
|
|
+ const iList = [];
|
|
|
+ if (!_.isArray(i.user_id)) i.inventor = iList;
|
|
|
for (const name of midNameList) {
|
|
|
const rList = nList.filter(f => f.name === name);
|
|
|
- i.user_id = [ ...i.user_id, ...rList.map(i => i._id) ];
|
|
|
+ if (rList && rList.length > 0) {
|
|
|
+ for (const r of rList) {
|
|
|
+ iList.push({ user_id: r._id, name: r.name });
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+ i.inventor = iList;
|
|
|
}
|
|
|
- await this.model.insertMany(arr);
|
|
|
+ const res = await this.model.insertMany(arr);
|
|
|
+ return res;
|
|
|
}
|
|
|
async toExport({ user }) {
|
|
|
const data = {
|
|
@@ -510,6 +519,22 @@ class PatentinfoService extends CrudService {
|
|
|
const obj = { $gte: start, $lte: end };
|
|
|
return obj;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据人名数组查询每个人的数据.组织数据返回
|
|
|
+ * @param {Array[String]} nameList 名单
|
|
|
+ */
|
|
|
+ async toGetUser(nameList) {
|
|
|
+ const res = await this.personalModel.find({ name: { $in: nameList } });
|
|
|
+ const result = [];
|
|
|
+ if (res && res.length > 0) {
|
|
|
+ for (const i of res) {
|
|
|
+ const { _id: id, name } = i;
|
|
|
+ result.push({ id, name });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
module.exports = PatentinfoService;
|