|
@@ -28,6 +28,41 @@ class PatentinfoService extends CrudService {
|
|
this.export_limit = 50;
|
|
this.export_limit = 50;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ async query(query, { skip = 0, limit = 0 }) {
|
|
|
|
+ query = await this.resetCode(query);
|
|
|
|
+ const res = await this.model.find(query).skip(parseInt(skip)).limit(parseInt(limit))
|
|
|
|
+ .sort({ 'meta.createdAt': -1 });
|
|
|
|
+ return res;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ async count(query) {
|
|
|
|
+ query = await this.resetCode(query);
|
|
|
|
+ const res = await this.model.countDocuments(trimData(query)).exec();
|
|
|
|
+ return res;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async resetCode(query) {
|
|
|
|
+ query = this.ctx.service.util.util.dealQuery(query);
|
|
|
|
+ const { type } = query;
|
|
|
|
+ if (type === 'else') {
|
|
|
|
+ query.$and = [{ type: { $ne: '发明' } }, { type: { $ne: '实用新型' } }];
|
|
|
|
+ delete query.type;
|
|
|
|
+ }
|
|
|
|
+ const { code } = query;
|
|
|
|
+ let ids = [];
|
|
|
|
+ if (code) {
|
|
|
|
+ const plist = await this.personalModel.find({ code });
|
|
|
|
+ ids = plist.map(i => i._id);
|
|
|
|
+ const olist = await this.organizationModel.find({ code });
|
|
|
|
+ ids = [ ...ids, ...olist.map(i => i._id) ];
|
|
|
|
+ }
|
|
|
|
+ if (ids.length > 0) {
|
|
|
|
+ query.user_id = { $elemMatch: { $in: ids } };
|
|
|
|
+ delete query.code;
|
|
|
|
+ }
|
|
|
|
+ return query;
|
|
|
|
+ }
|
|
|
|
+
|
|
async toImport({ uri, origin, user_id }) {
|
|
async toImport({ uri, origin, user_id }) {
|
|
assert(uri, '未获取到文件地址');
|
|
assert(uri, '未获取到文件地址');
|
|
const file = await this.ctx.curl(`${this.domain}${uri}`);
|
|
const file = await this.ctx.curl(`${this.domain}${uri}`);
|