|
@@ -17,8 +17,7 @@ class PatentearlyService extends CrudService {
|
|
}
|
|
}
|
|
async query(query, { skip = 0, limit = 0 }) {
|
|
async query(query, { skip = 0, limit = 0 }) {
|
|
const newquery = await this.resetCode(query);
|
|
const newquery = await this.resetCode(query);
|
|
- const res = await this.model.find(newquery).skip(parseInt(skip)).limit(parseInt(limit))
|
|
|
|
- .sort({ 'meta.createdAt': -1 });
|
|
|
|
|
|
+ const res = await this.model.find(newquery).skip(parseInt(skip)).limit(parseInt(limit)).sort({ 'meta.createdAt': -1 });
|
|
return res;
|
|
return res;
|
|
}
|
|
}
|
|
async count(query) {
|
|
async count(query) {
|
|
@@ -34,13 +33,13 @@ class PatentearlyService extends CrudService {
|
|
let ids = [];
|
|
let ids = [];
|
|
if (code) {
|
|
if (code) {
|
|
const plist = await this.personalModel.find({ code });
|
|
const plist = await this.personalModel.find({ code });
|
|
- ids = plist.map(i => i._id);
|
|
|
|
|
|
+ ids = plist.map((i) => i._id);
|
|
if (ids.length > 0) {
|
|
if (ids.length > 0) {
|
|
newquery.user_id = { $elemMatch: { $in: ids } };
|
|
newquery.user_id = { $elemMatch: { $in: ids } };
|
|
delete newquery.code;
|
|
delete newquery.code;
|
|
}
|
|
}
|
|
} else if (user_id) {
|
|
} else if (user_id) {
|
|
- newquery.user_id = { $elemMatch: { $in: [ ObjectId(user_id) ] } };
|
|
|
|
|
|
+ newquery.user_id = { $elemMatch: { $in: [ObjectId(user_id)] } };
|
|
}
|
|
}
|
|
|
|
|
|
return newquery;
|
|
return newquery;
|
|
@@ -50,10 +49,9 @@ class PatentearlyService extends CrudService {
|
|
assert(code, '缺少机构信息');
|
|
assert(code, '缺少机构信息');
|
|
let pids = await this.personalModel.find({ code }, { _id: 1 });
|
|
let pids = await this.personalModel.find({ code }, { _id: 1 });
|
|
if (pids.length <= 0) return { data: [], total: 0 };
|
|
if (pids.length <= 0) return { data: [], total: 0 };
|
|
- pids = pids.map(i => i._id);
|
|
|
|
|
|
+ pids = pids.map((i) => i._id);
|
|
const query = { user_id: { $elemMatch: { $in: pids } } };
|
|
const query = { user_id: { $elemMatch: { $in: pids } } };
|
|
- const data = await this.model.find(query).skip(parseInt(skip)).limit(parseInt(limit))
|
|
|
|
- .sort({ 'meta.createdAt': -1 });
|
|
|
|
|
|
+ const data = await this.model.find(query).skip(parseInt(skip)).limit(parseInt(limit)).sort({ 'meta.createdAt': -1 });
|
|
const total = await this.model.count(query);
|
|
const total = await this.model.count(query);
|
|
return { data, total };
|
|
return { data, total };
|
|
}
|
|
}
|
|
@@ -72,77 +70,90 @@ class PatentearlyService extends CrudService {
|
|
skip += limit;
|
|
skip += limit;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 查找并处理
|
|
|
|
+ * @param {Number} skip 开始位置
|
|
|
|
+ * @param {Number} limit 结束位置
|
|
|
|
+ */
|
|
async searchAndDeal(skip, limit) {
|
|
async searchAndDeal(skip, limit) {
|
|
let total = 0;
|
|
let total = 0;
|
|
let data = await this.patentinfo.find({ term: '有效' }, { name: 1, user_id: 1, create_date: 1 }).skip(skip).limit(limit);
|
|
let data = await this.patentinfo.find({ term: '有效' }, { name: 1, user_id: 1, create_date: 1 }).skip(skip).limit(limit);
|
|
if (data.length > 0) data = JSON.parse(JSON.stringify(data));
|
|
if (data.length > 0) data = JSON.parse(JSON.stringify(data));
|
|
|
|
+ total = data.length || 0;
|
|
|
|
+ await this.dealData(data);
|
|
|
|
+ return total;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ * @param {Array} data 处理数据
|
|
|
|
+ */
|
|
|
|
+ async dealData(data) {
|
|
// 取出今天是不是在失效时间的前${limitMonth}个月范围内
|
|
// 取出今天是不是在失效时间的前${limitMonth}个月范围内
|
|
const limitMonth = 3;
|
|
const limitMonth = 3;
|
|
for (const i of data) {
|
|
for (const i of data) {
|
|
- const { create_date } = i;
|
|
|
|
- // 取专利日期
|
|
|
|
- const month = moment(create_date).format('MM-DD');
|
|
|
|
- // // 取得当前年份
|
|
|
|
- const nowYear = moment(new Date()).format('YYYY');
|
|
|
|
- // // 当前年份+一年
|
|
|
|
- const afterYear = moment(nowYear).add(1, 'year').format('YYYY');
|
|
|
|
- // // 开始时间(先组合日期,减去三个月)
|
|
|
|
- const nowDate = afterYear + '-' + month;
|
|
|
|
- const start = moment(nowDate).subtract(limitMonth, 'months').format('YYYY-MM-DD');
|
|
|
|
- // 结束时间
|
|
|
|
- const end = afterYear + '-' + month;
|
|
|
|
- const endbeforeone = moment(end).subtract(1, 'd').format('YYYY-MM-DD');
|
|
|
|
- const r = moment().isBetween(start, end, null, '[]');
|
|
|
|
- if (r) {
|
|
|
|
- total++;
|
|
|
|
- // 2021-11-08 第一天/最后一天/相差天数被10整出的天数(并不算是严格的每隔10天) 发送消息
|
|
|
|
- // 是否发送的变量
|
|
|
|
- let dr = false;
|
|
|
|
- if (
|
|
|
|
- moment().format('YYYY-MM-DD') === start ||
|
|
|
|
- moment().format('YYYY-MM-DD') === endbeforeone
|
|
|
|
- ) {
|
|
|
|
- // 第一天/最后一天发送
|
|
|
|
- dr = true;
|
|
|
|
- } else {
|
|
|
|
- // 差10天就发
|
|
|
|
- const dur = 10;
|
|
|
|
- const subDay = moment(end).diff(moment(), 'days');
|
|
|
|
- // 判断是不是整数.整数就发送
|
|
|
|
- dr = _.isInteger(_.floor(_.divide(subDay, dur)));
|
|
|
|
- }
|
|
|
|
- // 不发就继续
|
|
|
|
- if (!dr) continue;
|
|
|
|
- const { user_id, name } = i;
|
|
|
|
- // 2021-11-04 修改,因为inventor修改为发明人[Object],所以发明人需要处理成字符串
|
|
|
|
- const users = user_id.map(i => i.user_id);
|
|
|
|
- // // const inventorNameString = inventor.map(i => i.name).join(';');
|
|
|
|
- // // const content = `发明人 【${inventorNameString}】 的已授权专利 【${name}】 即将失效,避免专利失效过期,请用户及时查看消息并处理! `;
|
|
|
|
- const content = '您可能需缴年费了,具体以缴费通知书为准 ';
|
|
|
|
- const nobj = {
|
|
|
|
- ..._.omit(i, [ '_id', 'id', 'users' ]),
|
|
|
|
- content,
|
|
|
|
- parent_id: i._id,
|
|
|
|
- user_id: users,
|
|
|
|
- };
|
|
|
|
- this.model.create(nobj);
|
|
|
|
- // 2021-11-04添加 向 patentexamine 表中添加数据
|
|
|
|
- const patentexamineArray = [];
|
|
|
|
- for (const i of user_id) {
|
|
|
|
- const { user_id } = i;
|
|
|
|
- // const peContent = `【${name}】 专利即将过期,请用户及时到相应功能模块中处理专利信息!`;
|
|
|
|
- const peContent = '您可能需缴年费了,具体以缴费通知书为准';
|
|
|
|
- const patentexamineObject = {
|
|
|
|
- to: user_id,
|
|
|
|
- content: peContent,
|
|
|
|
|
|
+ try {
|
|
|
|
+ const { create_date } = i;
|
|
|
|
+ // 取专利日期
|
|
|
|
+ const month = moment(create_date).format('MM-DD');
|
|
|
|
+ // // 取得当前年份
|
|
|
|
+ const nowYear = moment(new Date()).format('YYYY');
|
|
|
|
+ // // 当前年份+一年
|
|
|
|
+ const afterYear = moment(nowYear).add(1, 'year').format('YYYY');
|
|
|
|
+ // // 开始时间(先组合日期,减去三个月)
|
|
|
|
+ const nowDate = afterYear + '-' + month;
|
|
|
|
+ const start = moment(nowDate).subtract(limitMonth, 'months').format('YYYY-MM-DD');
|
|
|
|
+ // 结束时间
|
|
|
|
+ const end = afterYear + '-' + month;
|
|
|
|
+ const endbeforeone = moment(end).subtract(1, 'd').format('YYYY-MM-DD');
|
|
|
|
+ const r = moment().isBetween(start, end, null, '[]');
|
|
|
|
+ if (r) {
|
|
|
|
+ // 2021-11-08 第一天/最后一天/相差天数被10整出的天数(并不算是严格的每隔10天) 发送消息
|
|
|
|
+ // 是否发送的变量
|
|
|
|
+ let dr = false;
|
|
|
|
+ if (moment().format('YYYY-MM-DD') === start || moment().format('YYYY-MM-DD') === endbeforeone) {
|
|
|
|
+ // 第一天/最后一天发送
|
|
|
|
+ dr = true;
|
|
|
|
+ } else {
|
|
|
|
+ // 差10天就发
|
|
|
|
+ const dur = 10;
|
|
|
|
+ const subDay = moment(end).diff(moment(), 'days');
|
|
|
|
+ // 判断是不是整数.整数就发送
|
|
|
|
+ dr = _.isInteger(_.floor(_.divide(subDay, dur)));
|
|
|
|
+ }
|
|
|
|
+ // 不发就继续
|
|
|
|
+ if (!dr) continue;
|
|
|
|
+ const { user_id, name } = i;
|
|
|
|
+ // 2021-11-04 修改,因为inventor修改为发明人[Object],所以发明人需要处理成字符串
|
|
|
|
+ const users = user_id.map((i) => i.user_id);
|
|
|
|
+ // // const inventorNameString = inventor.map(i => i.name).join(';');
|
|
|
|
+ // // const content = `发明人 【${inventorNameString}】 的已授权专利 【${name}】 即将失效,避免专利失效过期,请用户及时查看消息并处理! `;
|
|
|
|
+ const content = '您可能需缴年费了,具体以缴费通知书为准 ';
|
|
|
|
+ const nobj = {
|
|
|
|
+ ..._.omit(i, ['_id', 'id', 'users']),
|
|
|
|
+ content,
|
|
|
|
+ parent_id: i._id,
|
|
|
|
+ user_id: users,
|
|
};
|
|
};
|
|
- patentexamineArray.push(patentexamineObject);
|
|
|
|
|
|
+ this.model.create(nobj);
|
|
|
|
+ // 2021-11-04添加 向 patentexamine 表中添加数据
|
|
|
|
+ const patentexamineArray = [];
|
|
|
|
+ for (const i of user_id) {
|
|
|
|
+ const { user_id } = i;
|
|
|
|
+ // const peContent = `【${name}】 专利即将过期,请用户及时到相应功能模块中处理专利信息!`;
|
|
|
|
+ const peContent = '您可能需缴年费了,具体以缴费通知书为准';
|
|
|
|
+ const patentexamineObject = {
|
|
|
|
+ to: user_id,
|
|
|
|
+ content: peContent,
|
|
|
|
+ };
|
|
|
|
+ patentexamineArray.push(patentexamineObject);
|
|
|
|
+ }
|
|
|
|
+ this.patentexamineModel.insertMany(patentexamineArray);
|
|
}
|
|
}
|
|
- this.patentexamineModel.insertMany(patentexamineArray);
|
|
|
|
|
|
+ } catch (error) {
|
|
|
|
+ continue;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return total;
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|