|
@@ -37,47 +37,96 @@ class PatentwarningService extends CrudService {
|
|
|
} catch (error) {
|
|
|
throw new BusinessError(ErrorCode.FILE_FAULT, '解压失败');
|
|
|
}
|
|
|
- // 找到
|
|
|
- let filePaths = [];
|
|
|
- try {
|
|
|
- filePaths = await this.findFileNameLoop(uncompressFilePath, fileName);
|
|
|
- } catch (error) {
|
|
|
- throw new BusinessError(ErrorCode.SERVICE_FAULT, '解析文件具体位置失败');
|
|
|
- }
|
|
|
- if (filePaths.length <= 0) {
|
|
|
- throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到文件');
|
|
|
- }
|
|
|
- const xmlPath = filePaths.find(f => f.includes('.xml'));
|
|
|
- if (!xmlPath) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到xml文件');
|
|
|
- let create_number;
|
|
|
- try {
|
|
|
- create_number = await this.dealXml(xmlPath);
|
|
|
- } catch (error) {
|
|
|
- throw new BusinessError(ErrorCode.SERVICE_FAULT, '解析申请号失败');
|
|
|
- }
|
|
|
- if (!create_number) throw new BusinessError(ErrorCode.FILE_FAULT, '未找到申请号');
|
|
|
- let result;
|
|
|
- try {
|
|
|
- result = await this.getPatentFromInfo(create_number);
|
|
|
- } catch (error) {
|
|
|
- throw new BusinessError(ErrorCode.SERVICE_FAULT, '查询专利信息失败');
|
|
|
- }
|
|
|
- // 再找
|
|
|
- if (!result) result = await this.getPatentFromApply(create_number);
|
|
|
- // 找不到就算了,弹回去了
|
|
|
- if (!result) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未通过申请号找到指定专利');
|
|
|
- let warningData;
|
|
|
- try {
|
|
|
- warningData = await this.getWarningData(result);
|
|
|
- } catch (error) {
|
|
|
- throw new BusinessError(ErrorCode.SERVICE_FAULT, '组织专利信息警告数据失败');
|
|
|
- }
|
|
|
- const tifPaths = filePaths.filter(f => f.includes('.tif'));
|
|
|
- let lastResult;
|
|
|
- if (tifPaths && tifPaths.length > 0) lastResult = await this.toUploadTif(warningData, tifPaths);
|
|
|
- if (lastResult) {
|
|
|
- await this.dirDelete(`${uncompressFilePath}`);
|
|
|
+ // 修改,多个专利:需要扫描下解压后的文件夹,然后循环处理下面所有的内容
|
|
|
+ const tempDirRootPath = `${uncompressFilePath}${sep}${fileName}`;
|
|
|
+ const tempDir = await fs.readdirSync(tempDirRootPath);
|
|
|
+ const errorList = [];
|
|
|
+ for (const tempDirPath of tempDir) {
|
|
|
+ const thisDirPath = `${tempDirRootPath}${sep}${tempDirPath}`;
|
|
|
+ const patentNumber = tempDirPath;
|
|
|
+ // 找到
|
|
|
+ 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文件');
|
|
|
+ }
|
|
|
+ let create_number;
|
|
|
+ try {
|
|
|
+ create_number = await this.dealXml(xmlPath);
|
|
|
+ } catch (error) {
|
|
|
+ errorList.push({ key: patentNumber, word: '解析申请号失败' });
|
|
|
+ continue;
|
|
|
+ // throw new BusinessError(ErrorCode.SERVICE_FAULT, '解析申请号失败');
|
|
|
+ }
|
|
|
+ if (!create_number) {
|
|
|
+ errorList.push({ key: patentNumber, word: '未找到申请号' });
|
|
|
+ continue;
|
|
|
+ // 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) {
|
|
|
+ try {
|
|
|
+ result = await this.getPatentFromApply(create_number);
|
|
|
+ } catch (error) {
|
|
|
+ errorList.push({ key: patentNumber, word: '查询申请信息失败' });
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 找不到就算了,弹回去了
|
|
|
+ if (!result) {
|
|
|
+ errorList.push({ key: patentNumber, word: '未通过申请号找到指定专利' });
|
|
|
+ continue;
|
|
|
+ // throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未通过申请号找到指定专利');
|
|
|
+ }
|
|
|
+ console.log(result);
|
|
|
+ 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) {
|
|
|
+ try {
|
|
|
+ lastResult = await this.toUploadTif(warningData, tifPaths);
|
|
|
+ } catch (error) {
|
|
|
+ errorList.push({ key: patentNumber, word: '存储数据失败' });
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (lastResult) {
|
|
|
+ try {
|
|
|
+ await this.dirDelete(`${uncompressFilePath}`);
|
|
|
+ } catch (error) {
|
|
|
+ errorList.push({ key: patentNumber, word: '清除缓存失败' });
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+ if (errorList.length > 0) return errorList;
|
|
|
return 'ok';
|
|
|
}
|
|
|
|