|
@@ -4,15 +4,58 @@ const { BusinessError, ErrorCode } = require('naf-core').Error;
|
|
|
const { ObjectId } = require('mongoose').Types;
|
|
|
const _ = require('lodash');
|
|
|
const assert = require('assert');
|
|
|
-
|
|
|
-
|
|
|
+const moment = require('moment');
|
|
|
// 专利运营已授权专利预警表
|
|
|
class PatentearlyService extends CrudService {
|
|
|
constructor(ctx) {
|
|
|
super(ctx, 'patentearly');
|
|
|
this.model = this.ctx.model.Patent.Patentearly;
|
|
|
+ this.patentinfo = this.ctx.model.Patent.Patentinfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 产生警告
|
|
|
+ */
|
|
|
+ async needWarning() {
|
|
|
+ const limit = 3;
|
|
|
+ let skip = 0;
|
|
|
+ // 一段一段查数据
|
|
|
+ // skip += limit;
|
|
|
+ let loop = true;
|
|
|
+ while (loop) {
|
|
|
+ const total = await this.searchAndDeal(skip, limit);
|
|
|
+ if (total <= 0) loop = false;
|
|
|
+ skip += limit;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async searchAndDeal(skip, limit) {
|
|
|
+ let total = 0;
|
|
|
+ let data = await this.patentinfo
|
|
|
+ .find(
|
|
|
+ { term: '有效' },
|
|
|
+ { name: 1, inventor: 1, lose_date: 1, user_id: 1 }
|
|
|
+ )
|
|
|
+ .skip(skip)
|
|
|
+ .limit(limit);
|
|
|
+ if (data.length > 0) data = JSON.parse(JSON.stringify(data));
|
|
|
+ // 取出今天是不是在失效时间的前1个月范围内
|
|
|
+ for (const i of data) {
|
|
|
+ i.user_id = i.user_id.map(i => ObjectId(i));
|
|
|
+ const { lose_date } = i;
|
|
|
+ const start = moment(lose_date).subtract(1, 'M');
|
|
|
+ const end = moment(lose_date).add(1, 'M');
|
|
|
+ const r = moment().isBetween(start, end, null, '[]');
|
|
|
+ if (r) {
|
|
|
+ total++;
|
|
|
+ const { inventor, name } = i;
|
|
|
+ const content = `发明人 ${inventor} 的已授权专利 ${name} 即将失效,避免专利失效过期,请用户及时查看消息并处理! `;
|
|
|
+ const nobj = { ..._.omit(i, [ '_id', 'id' ]), content, parent_id: i._id };
|
|
|
+ this.model.create(nobj);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return total;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
module.exports = PatentearlyService;
|
|
|
-
|