|
@@ -19,6 +19,8 @@ const compressing = require('compressing');
|
|
|
import * as fs from 'node:fs';
|
|
|
import * as Path from 'node:path';
|
|
|
const sep = Path.sep;
|
|
|
+import { Types } from 'mongoose';
|
|
|
+const ObjectId = Types.ObjectId;
|
|
|
type modelType = ReturnModelType<typeof Patent>;
|
|
|
@Provide()
|
|
|
export class PatentService extends BaseService<modelType> {
|
|
@@ -187,15 +189,17 @@ export class PatentService extends BaseService<modelType> {
|
|
|
const has_data = await this.model.count({
|
|
|
create_number: obj.create_number,
|
|
|
});
|
|
|
- let res;
|
|
|
+ const res = await this.model.findOne({
|
|
|
+ create_number: obj.create_number,
|
|
|
+ });
|
|
|
if (has_data === 0) {
|
|
|
- res = await this.model.create(obj);
|
|
|
+ await this.model.create(obj);
|
|
|
} else {
|
|
|
- await this.model.updateOne({ create_number: obj.create_number }, obj);
|
|
|
- res = await this.model.findOne({ create_number: obj.create_number });
|
|
|
+ await this.model.updateOne(new ObjectId(res._id), obj);
|
|
|
+ // res = await this.model.findOne({ create_number: obj.create_number });
|
|
|
}
|
|
|
- // 处理警告
|
|
|
- if (res.term === '1') this.dealData([res]);
|
|
|
+ // // 处理警告
|
|
|
+ // if (res.term === '1') this.dealData([res]);
|
|
|
} catch (error) {
|
|
|
allNotice.push(`申请号 为${create_number} 的 专利信息 创建失败!`);
|
|
|
continue;
|
|
@@ -203,10 +207,14 @@ export class PatentService extends BaseService<modelType> {
|
|
|
}
|
|
|
}
|
|
|
// 导出
|
|
|
- async export({ missionid, query }) {
|
|
|
- const path = `${this.root_path}${sep}${this.file_type}${sep}${
|
|
|
- this.patentInfo_dir
|
|
|
- }${new Date().getTime()}`;
|
|
|
+ async export(query) {
|
|
|
+ const termList: any = await this.adminAxios.get(
|
|
|
+ 'dictData?type=patent_term'
|
|
|
+ );
|
|
|
+ const typeList: any = await this.adminAxios.get(
|
|
|
+ 'dictData?type=patent_type'
|
|
|
+ );
|
|
|
+ const path = `${this.root_path}${sep}${this.file_type}`;
|
|
|
if (!path) {
|
|
|
throw new ServiceError(
|
|
|
'服务端没有设置存储路径',
|
|
@@ -240,9 +248,9 @@ export class PatentService extends BaseService<modelType> {
|
|
|
const d = list[k];
|
|
|
const arr = [];
|
|
|
for (const m of meta) {
|
|
|
- const { key } = m;
|
|
|
- if (key === 'img_url') {
|
|
|
- const value = d[key];
|
|
|
+ const { model } = m;
|
|
|
+ if (model === 'file') {
|
|
|
+ const value = d[model];
|
|
|
// 需要图片占列,否则会窜位置
|
|
|
arr.push('');
|
|
|
if (_.isArray(value)) {
|
|
@@ -261,7 +269,13 @@ export class PatentService extends BaseService<modelType> {
|
|
|
sheet.addImage(imgId, sheetRange);
|
|
|
}
|
|
|
}
|
|
|
- } else arr.push(d[key]);
|
|
|
+ } else if (model === 'type') {
|
|
|
+ const data = typeList.data.find(i => i.value === d[model]);
|
|
|
+ arr.push(data.label);
|
|
|
+ } else if (model === 'term') {
|
|
|
+ const data = termList.data.find(i => i.value === d[model]);
|
|
|
+ arr.push(data.label);
|
|
|
+ } else arr.push(d[model]);
|
|
|
}
|
|
|
sheet.addRow(arr);
|
|
|
}
|
|
@@ -278,7 +292,7 @@ export class PatentService extends BaseService<modelType> {
|
|
|
const data = {
|
|
|
progress,
|
|
|
status: '1',
|
|
|
- id: missionid,
|
|
|
+ // id: missionid,
|
|
|
remark: '组织数据生成excel中...',
|
|
|
};
|
|
|
await this.sendToMQ(data);
|
|
@@ -289,7 +303,7 @@ export class PatentService extends BaseService<modelType> {
|
|
|
const data = {
|
|
|
progress: 0,
|
|
|
status: '-1',
|
|
|
- id: missionid,
|
|
|
+ // id: missionid,
|
|
|
remark: '组织数据进入excel失败',
|
|
|
};
|
|
|
this.sendToMQ(data);
|
|
@@ -300,7 +314,7 @@ export class PatentService extends BaseService<modelType> {
|
|
|
const data = {
|
|
|
progress: 98,
|
|
|
status: '1',
|
|
|
- id: missionid,
|
|
|
+ // id: missionid,
|
|
|
remark: '正在打包',
|
|
|
};
|
|
|
this.sendToMQ(data);
|
|
@@ -322,7 +336,7 @@ export class PatentService extends BaseService<modelType> {
|
|
|
progress: 100,
|
|
|
status: '2',
|
|
|
uri: downloadPath,
|
|
|
- id: missionid,
|
|
|
+ // id: missionid,
|
|
|
remark: '打包成功',
|
|
|
};
|
|
|
this.sendToMQ(data);
|
|
@@ -330,7 +344,7 @@ export class PatentService extends BaseService<modelType> {
|
|
|
const data = {
|
|
|
progress: 0,
|
|
|
status: '-2',
|
|
|
- id: missionid,
|
|
|
+ // id: missionid,
|
|
|
remark: '打包失败',
|
|
|
};
|
|
|
this.sendToMQ(data);
|