|
@@ -15,6 +15,9 @@ class DisclosureService extends CrudService {
|
|
this.model = this.ctx.model.Patent.Disclosure;
|
|
this.model = this.ctx.model.Patent.Disclosure;
|
|
this.notice = this.ctx.model.Patent.Notice;
|
|
this.notice = this.ctx.model.Patent.Notice;
|
|
this.patent = this.ctx.model.Dock.Patent;
|
|
this.patent = this.ctx.model.Dock.Patent;
|
|
|
|
+ this.personalModel = this.ctx.model.Personal;
|
|
|
|
+ this.organizationModel = this.ctx.model.Organization;
|
|
|
|
+ this.itemp = this.ctx.model.Patent.ImportTemp;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -184,7 +187,7 @@ class DisclosureService extends CrudService {
|
|
|
|
|
|
// 导入
|
|
// 导入
|
|
async import({ uri }) {
|
|
async import({ uri }) {
|
|
- const domain = 'http://127.0.0.1';
|
|
|
|
|
|
+ const domain = process.env.NODE_ENV === 'development' ? 'http://broadcast.waityou24.cn/' : 'http://127.0.0.1';
|
|
assert(uri, '未获取到文件地址');
|
|
assert(uri, '未获取到文件地址');
|
|
const file = await this.ctx.curl(`${domain}${uri}`);
|
|
const file = await this.ctx.curl(`${domain}${uri}`);
|
|
if (!(file && file.data)) {
|
|
if (!(file && file.data)) {
|
|
@@ -240,6 +243,7 @@ class DisclosureService extends CrudService {
|
|
type,
|
|
type,
|
|
img_url,
|
|
img_url,
|
|
number,
|
|
number,
|
|
|
|
+ user_id: [],
|
|
};
|
|
};
|
|
// 此处添加判断条件,不限制则不需要加,直接放过即可
|
|
// 此处添加判断条件,不限制则不需要加,直接放过即可
|
|
const { result, notice } = this.tocheckData(obj);
|
|
const { result, notice } = this.tocheckData(obj);
|
|
@@ -250,8 +254,72 @@ class DisclosureService extends CrudService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
- if (allNotice.length > 0) return allNotice;
|
|
|
|
- await this.patent.insertMany(arr);
|
|
|
|
|
|
+ if (allNotice.length > 0) return { data: allNotice, errcode: '1' };
|
|
|
|
+ // 信息合格后,将发明人分出来,然后在个人/企业查出来,如果不是一个人,那就返回给前端,让前端选择后进行存储
|
|
|
|
+ // 提取出所有人,分割,放到数组里(重不重复无所谓,这个地方无所谓);然后用人名去查出来所有的用户(企业/个人),如果有重复的,那就提出来返回给前端
|
|
|
|
+ let nameList = [];
|
|
|
|
+ for (const i of arr) {
|
|
|
|
+ const { inventor } = i;
|
|
|
|
+ const midList = inventor.split(/[,;/]/);
|
|
|
|
+ nameList = [ ...nameList, ...midList ];
|
|
|
|
+ }
|
|
|
|
+ const l1 = await this.personalModel.find({ name: nameList });
|
|
|
|
+ const l2 = await this.organizationModel.find({ name: nameList });
|
|
|
|
+ // 查出来的所有人
|
|
|
|
+ const nList = [ ...l1, ...l2 ];
|
|
|
|
+ const groups = _.groupBy(nList, 'name');
|
|
|
|
+ // 重复的名单
|
|
|
|
+ const rList = {};
|
|
|
|
+ for (const key in groups) {
|
|
|
|
+ if (groups[key].length > 1) {
|
|
|
|
+ rList[key] = groups[key];
|
|
|
|
+ } else {
|
|
|
|
+ // 剩下的都是1个的,直接找所有项目里有没有这个人,有就扔进去
|
|
|
|
+ for (const i of arr) {
|
|
|
|
+ const { inventor } = i;
|
|
|
|
+ if (inventor.includes(key)) {
|
|
|
|
+ const acct = _.head(groups[key]);
|
|
|
|
+ if (acct) i.user_id.push(acct._id);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 将有这些重复人名的专利找到,返回前端
|
|
|
|
+ const errorArr = [];
|
|
|
|
+ const dealList = [];
|
|
|
|
+ for (const i of arr) {
|
|
|
|
+ const { inventor } = i;
|
|
|
|
+ const key = Object.keys(rList).find(i => inventor.includes(i));
|
|
|
|
+ if (key) errorArr.push({ ...i, nameList: rList[key] });
|
|
|
|
+ else dealList.push(i);
|
|
|
|
+ }
|
|
|
|
+ // 不导入,缓存
|
|
|
|
+ if (errorArr.length > 0) {
|
|
|
|
+ const tempRes = await this.itemp.create({ data: dealList });
|
|
|
|
+ const { _id } = tempRes;
|
|
|
|
+ return { data: errorArr, errcode: '2', temp_id: _id };
|
|
|
|
+ }
|
|
|
|
+ await this.importAction(dealList);
|
|
|
|
+ }
|
|
|
|
+ // 继续导入
|
|
|
|
+ async cacheImport({ data, temp_id }) {
|
|
|
|
+ data = data.map(i => {
|
|
|
|
+ const acct = i.nameList.find(f => f.is_select);
|
|
|
|
+ if (acct) {
|
|
|
|
+ const { _id } = acct;
|
|
|
|
+ i.user_id.push(_id);
|
|
|
|
+ }
|
|
|
|
+ delete i.nameList;
|
|
|
|
+ return i;
|
|
|
|
+ });
|
|
|
|
+ const tempList = await this.itemp.findById(temp_id);
|
|
|
|
+ data = [ ...data, ...tempList.data ];
|
|
|
|
+ await this.importAction(data);
|
|
|
|
+ await this.itemp.deleteOne({ _id: temp_id });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async importAction(data) {
|
|
|
|
+ await this.patent.insertMany(data);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|