|
@@ -36,92 +36,94 @@ class PatentwarningService extends CrudService {
|
|
throw new BusinessError(ErrorCode.FILE_FAULT, '解压失败');
|
|
throw new BusinessError(ErrorCode.FILE_FAULT, '解压失败');
|
|
}
|
|
}
|
|
// 修改,多个专利:需要扫描下解压后的文件夹,然后循环处理下面所有的内容
|
|
// 修改,多个专利:需要扫描下解压后的文件夹,然后循环处理下面所有的内容
|
|
- const tempDirRootPath = `${uncompressFilePath}${sep}${fileName}`;
|
|
|
|
|
|
+ const tempDirRootPath = `${uncompressFilePath}${sep}`;
|
|
const tempDir = await fs.readdirSync(tempDirRootPath);
|
|
const tempDir = await fs.readdirSync(tempDirRootPath);
|
|
const errorList = [];
|
|
const errorList = [];
|
|
for (const tempDirPath of tempDir) {
|
|
for (const tempDirPath of tempDir) {
|
|
const thisDirPath = `${tempDirRootPath}${sep}${tempDirPath}`;
|
|
const thisDirPath = `${tempDirRootPath}${sep}${tempDirPath}`;
|
|
const patentNumber = tempDirPath;
|
|
const patentNumber = tempDirPath;
|
|
- // 找到
|
|
|
|
- let filePaths = [];
|
|
|
|
try {
|
|
try {
|
|
- filePaths = await this.findFileNameLoop(thisDirPath);
|
|
|
|
- } catch (error) {
|
|
|
|
- errorList.push({ key: patentNumber, word: '解析文件具体位置失败' });
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- if (filePaths.length <= 0) {
|
|
|
|
- errorList.push({ key: patentNumber, word: '未找到文件' });
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- const xmlPath = filePaths.find(f => f.includes('.xml'));
|
|
|
|
- if (!xmlPath) {
|
|
|
|
- errorList.push({ key: patentNumber, word: '未找到xml文件' });
|
|
|
|
- continue;
|
|
|
|
|
|
+ // 找到
|
|
|
|
+ let filePaths = [];
|
|
|
|
+ try {
|
|
|
|
+ filePaths = await this.findFileNameLoop(thisDirPath);
|
|
|
|
+ } catch (error) {
|
|
|
|
+ errorList.push({ key: patentNumber, word: '解析文件具体位置失败' });
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ if (filePaths.length <= 0) {
|
|
|
|
+ errorList.push({ key: patentNumber, word: '未找到文件' });
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ const xmlPath = filePaths.find(f => f.includes('.xml'));
|
|
|
|
+ if (!xmlPath) {
|
|
|
|
+ errorList.push({ key: patentNumber, word: '未找到xml文件' });
|
|
|
|
+ continue;
|
|
// throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到xml文件');
|
|
// throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到xml文件');
|
|
- }
|
|
|
|
- let create_number;
|
|
|
|
- try {
|
|
|
|
- create_number = await this.dealXml(xmlPath);
|
|
|
|
- } catch (error) {
|
|
|
|
- errorList.push({ key: patentNumber, word: '解析申请号失败' });
|
|
|
|
- continue;
|
|
|
|
|
|
+ }
|
|
|
|
+ let xmlData;
|
|
|
|
+ try {
|
|
|
|
+ xmlData = await this.dealXml(xmlPath);
|
|
|
|
+ } catch (error) {
|
|
|
|
+ errorList.push({ key: patentNumber, word: '解析xml数据中的 申请号 和 专利名称 失败' });
|
|
|
|
+ continue;
|
|
// throw new BusinessError(ErrorCode.SERVICE_FAULT, '解析申请号失败');
|
|
// throw new BusinessError(ErrorCode.SERVICE_FAULT, '解析申请号失败');
|
|
- }
|
|
|
|
- if (!create_number) {
|
|
|
|
- errorList.push({ key: patentNumber, word: '未找到申请号' });
|
|
|
|
- continue;
|
|
|
|
|
|
+ }
|
|
|
|
+ if (!xmlData) {
|
|
|
|
+ errorList.push({ key: patentNumber, word: '未找到xml的数据' });
|
|
|
|
+ continue;
|
|
// throw new BusinessError(ErrorCode.FILE_FAULT, '未找到申请号');
|
|
// throw new BusinessError(ErrorCode.FILE_FAULT, '未找到申请号');
|
|
- }
|
|
|
|
- let result;
|
|
|
|
- try {
|
|
|
|
- result = await this.getPatentFromInfo(create_number);
|
|
|
|
- } catch (error) {
|
|
|
|
- errorList.push({ key: patentNumber, word: '查询专利信息失败' });
|
|
|
|
- continue;
|
|
|
|
- // throw new BusinessError(ErrorCode.SERVICE_FAULT, '查询专利信息失败');
|
|
|
|
- }
|
|
|
|
- // 再找
|
|
|
|
- if (!result) {
|
|
|
|
|
|
+ }
|
|
|
|
+ let result;
|
|
try {
|
|
try {
|
|
- result = await this.getPatentFromApply(create_number);
|
|
|
|
|
|
+ result = await this.getPatent(xmlData);
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- errorList.push({ key: patentNumber, word: '查询申请信息失败' });
|
|
|
|
|
|
+ errorList.push({ key: patentNumber, word: '查询专利信息失败' });
|
|
continue;
|
|
continue;
|
|
|
|
+ // throw new BusinessError(ErrorCode.SERVICE_FAULT, '查询专利信息失败');
|
|
}
|
|
}
|
|
- }
|
|
|
|
- // 找不到就算了,弹回去了
|
|
|
|
- if (!result) {
|
|
|
|
- errorList.push({ key: patentNumber, word: '未通过申请号找到指定专利' });
|
|
|
|
- continue;
|
|
|
|
|
|
+ // 找不到就算了,弹回去了
|
|
|
|
+ if (!result || !_.get(result, 'patent')) {
|
|
|
|
+ errorList.push({ key: patentNumber, word: '未通过 申请号 或 专利名称 找到指定专利' });
|
|
|
|
+ continue;
|
|
// throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未通过申请号找到指定专利');
|
|
// throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未通过申请号找到指定专利');
|
|
- }
|
|
|
|
- let warningData;
|
|
|
|
- try {
|
|
|
|
- warningData = await this.getWarningData(result);
|
|
|
|
- } catch (error) {
|
|
|
|
- errorList.push({ key: patentNumber, word: '组织专利信息警告数据失败' });
|
|
|
|
- continue;
|
|
|
|
- // throw new BusinessError(ErrorCode.SERVICE_FAULT, '组织专利信息警告数据失败');
|
|
|
|
- }
|
|
|
|
- const tifPaths = filePaths.filter(f => f.includes('.tif'));
|
|
|
|
- let lastResult;
|
|
|
|
- if (tifPaths && tifPaths.length > 0) {
|
|
|
|
|
|
+ }
|
|
|
|
+ const patent = _.get(result, 'patent');
|
|
|
|
+ let warningData;
|
|
try {
|
|
try {
|
|
- lastResult = await this.toUploadTif(warningData, tifPaths);
|
|
|
|
|
|
+ warningData = await this.getWarningData(patent);
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- errorList.push({ key: patentNumber, word: '存储数据失败' });
|
|
|
|
|
|
+ errorList.push({ key: patentNumber, word: '组织专利信息警告数据失败' });
|
|
continue;
|
|
continue;
|
|
|
|
+ // throw new BusinessError(ErrorCode.SERVICE_FAULT, '组织专利信息警告数据失败');
|
|
}
|
|
}
|
|
- }
|
|
|
|
- if (lastResult) {
|
|
|
|
|
|
+ const tifPaths = filePaths.filter(f => f.includes('.tif'));
|
|
|
|
+ if (tifPaths && tifPaths.length > 0) {
|
|
|
|
+ try {
|
|
|
|
+ await this.toUploadTif(warningData, tifPaths);
|
|
|
|
+ } catch (error) {
|
|
|
|
+ errorList.push({ key: patentNumber, word: '存储数据失败' });
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 查看是否需要更改申请号
|
|
|
|
+ const needChange = _.get(result, 'needChange');
|
|
|
|
+ if (needChange) {
|
|
|
|
+ try {
|
|
|
|
+ await this.patentApply.updateOne({ _id: patent._id }, patent);
|
|
|
|
+ } catch (error) {
|
|
|
|
+ errorList.push({ key: patentNumber, word: 'xml申请号同步至专利申请号失败' });
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } finally {
|
|
try {
|
|
try {
|
|
- await this.dirDelete(`${uncompressFilePath}`);
|
|
|
|
|
|
+ await this.dirDelete(`${thisDirPath}`);
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- errorList.push({ key: patentNumber, word: '清除缓存失败' });
|
|
|
|
- continue;
|
|
|
|
|
|
+ this.ctx.logger.error('清除缓存失败');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
if (errorList.length > 0) return errorList;
|
|
if (errorList.length > 0) return errorList;
|
|
return 'ok';
|
|
return 'ok';
|
|
@@ -203,17 +205,13 @@ class PatentwarningService extends CrudService {
|
|
if (_.get(patent, 'id'))object.patent_id = _.get(patent, 'id');
|
|
if (_.get(patent, 'id'))object.patent_id = _.get(patent, 'id');
|
|
if (_.get(patent, 'name'))object.patent_name = _.get(patent, 'name');
|
|
if (_.get(patent, 'name'))object.patent_name = _.get(patent, 'name');
|
|
// 找人的信息
|
|
// 找人的信息
|
|
- let userIds = _.get(patent, 'user_id', _.get(patent, 'inventor'));
|
|
|
|
- if (!userIds) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到专利的发明人');
|
|
|
|
- if (!_.isArray(userIds)) userIds = [ userIds ];
|
|
|
|
- userIds = userIds.map(i => ObjectId(i));
|
|
|
|
- const users = await this.personalModel.find({ _id: userIds });
|
|
|
|
|
|
+ const users = _.get(patent, 'inventor');
|
|
const arr = [];
|
|
const arr = [];
|
|
for (const user of users) {
|
|
for (const user of users) {
|
|
- if (!_.get(user, '_id') || !_.get(user, 'name')) continue;
|
|
|
|
- const { _id, name } = user;
|
|
|
|
|
|
+ if (!_.get(user, 'user_id') || !_.get(user, 'name')) continue;
|
|
|
|
+ const { user_id, name } = user;
|
|
const obj = _.cloneDeep(object);
|
|
const obj = _.cloneDeep(object);
|
|
- obj.to_id = _id;
|
|
|
|
|
|
+ obj.to_id = user_id;
|
|
obj.to_name = name;
|
|
obj.to_name = name;
|
|
arr.push(obj);
|
|
arr.push(obj);
|
|
}
|
|
}
|
|
@@ -222,25 +220,40 @@ class PatentwarningService extends CrudService {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 在patentApply表中找指定的专利
|
|
|
|
- * @param {String} create_number 专利的申请号
|
|
|
|
|
|
+ * 在patentApply/patentInfo表中找指定的专利
|
|
|
|
+ * @param {Object} object xml的数据
|
|
*/
|
|
*/
|
|
- async getPatentFromApply(create_number) {
|
|
|
|
- const res = await this.patentApply.findOne({ create_number });
|
|
|
|
- return res;
|
|
|
|
|
|
+ async getPatent(object) {
|
|
|
|
+ const { name, create_number } = object;
|
|
|
|
+ let res;
|
|
|
|
+ let needChange = false;
|
|
|
|
+ res = await this.patentApply.findOne({ create_number });
|
|
|
|
+ // 如果在申请中,使用名称找到,则之后需要将该数据的专利号改为xml中的专利号
|
|
|
|
+ if (!res) {
|
|
|
|
+ res = await this.patentApply.findOne({ name });
|
|
|
|
+ needChange = true;
|
|
|
|
+ }
|
|
|
|
+ if (!res) {
|
|
|
|
+ res = await this.patentInfo.findOne({ create_number });
|
|
|
|
+ }
|
|
|
|
+ if (!res) {
|
|
|
|
+ res = await this.patentInfo.findOne({ name });
|
|
|
|
+ }
|
|
|
|
+ const returnObject = {};
|
|
|
|
+ if (res) {
|
|
|
|
+ if (needChange) {
|
|
|
|
+ res.create_number = create_number;
|
|
|
|
+ returnObject.needChange = needChange;
|
|
|
|
+ }
|
|
|
|
+ returnObject.patent = res;
|
|
|
|
+ return returnObject;
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * 在patentInfo表中找指定的专利
|
|
|
|
- * @param {String} create_number 专利的申请号
|
|
|
|
- */
|
|
|
|
- async getPatentFromInfo(create_number) {
|
|
|
|
- const res = await this.patentInfo.findOne({ create_number });
|
|
|
|
- return res;
|
|
|
|
- }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 根据路径找到xml,再找到该xml的申请号
|
|
|
|
|
|
+ * 根据路径找到xml,再找到该xml的申请号和专利名称
|
|
* @param {String} filePath xml的文件路径
|
|
* @param {String} filePath xml的文件路径
|
|
*/
|
|
*/
|
|
async dealXml(filePath) {
|
|
async dealXml(filePath) {
|
|
@@ -250,7 +263,9 @@ class PatentwarningService extends CrudService {
|
|
str = str.toString();
|
|
str = str.toString();
|
|
const json = fxp.parse(str);
|
|
const json = fxp.parse(str);
|
|
const create_number = _.get(json, 'data-bus.TONGZHISXJ.SHUXINGXX.SHENQINGH');
|
|
const create_number = _.get(json, 'data-bus.TONGZHISXJ.SHUXINGXX.SHENQINGH');
|
|
- return create_number;
|
|
|
|
|
|
+ const name = _.get(json, 'data-bus.TONGZHISXJ.SHUXINGXX.FAMINGMC');
|
|
|
|
+ if (!name) return null;
|
|
|
|
+ return { name, create_number };
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|