|
@@ -61,7 +61,7 @@ class PatentearlyService extends CrudService {
|
|
|
* 产生警告
|
|
|
*/
|
|
|
async needWarning() {
|
|
|
- const limit = 3;
|
|
|
+ const limit = 5000;
|
|
|
let skip = 0;
|
|
|
// 一段一段查数据
|
|
|
// skip += limit;
|
|
@@ -75,28 +75,61 @@ class PatentearlyService extends CrudService {
|
|
|
|
|
|
async searchAndDeal(skip, limit) {
|
|
|
let total = 0;
|
|
|
- let data = await this.patentinfo.find({ term: '有效' }, { name: 1, inventor: 1, create_date: 1, user_id: 1 }).skip(skip).limit(limit);
|
|
|
+ let data = await this.patentinfo.find({ term: '有效' }, { name: 1, inventor: 1, create_date: 1 }).skip(skip).limit(limit);
|
|
|
if (data.length > 0) data = JSON.parse(JSON.stringify(data));
|
|
|
- // 取出今天是不是在失效时间的前1个月范围内
|
|
|
+ // 取出今天是不是在失效时间的前${limitMonth}个月范围内
|
|
|
+ const limitMonth = 3;
|
|
|
for (const i of data) {
|
|
|
const { create_date } = i;
|
|
|
- const start = moment(create_date).subtract(1, 'M');
|
|
|
- const end = moment(create_date).add(3, 'M');
|
|
|
+ // 取专利日期
|
|
|
+ const month = moment(create_date).format('MM-DD');
|
|
|
+ // // 取得当前年份
|
|
|
+ const nowYear = moment().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 r = moment().isBetween(start, end, null, '[]');
|
|
|
+ console.log(r);
|
|
|
if (r) {
|
|
|
total++;
|
|
|
+ // 2021-11-08 第一天/最后一天/相差天数被10整出的天数(并不算是严格的每隔10天) 发送消息
|
|
|
+ // 是否发送的变量
|
|
|
+ let dr = false;
|
|
|
+ if (moment().format('YYYY-MM-DD') === start || moment().format('YYYY-MM-DD') === end) {
|
|
|
+ // 第一天/最后一天发送
|
|
|
+ dr = true;
|
|
|
+ } else {
|
|
|
+ // 差10天就发
|
|
|
+ const dur = 10;
|
|
|
+ const subDay = moment(end).diff(moment(), 'days');
|
|
|
+ // 判断是不是整数.整数就发送
|
|
|
+ dr = _.isInteger(_.floor(_.divide(subDay, dur)));
|
|
|
+ }
|
|
|
+ // 不发就继续
|
|
|
+ if (!dr) continue;
|
|
|
const { inventor, name } = i;
|
|
|
// 2021-11-04 修改,因为inventor修改为发明人[Object],所以发明人需要处理成字符串
|
|
|
- const user_id = inventor.map((i) => ObjectId(i.user_id));
|
|
|
- const inventorNameString = inventor.map((i) => i.name).join(';');
|
|
|
- const content = `发明人 【${inventorNameString}】 的已授权专利 【${name}】 即将失效,避免专利失效过期,请用户及时查看消息并处理! `;
|
|
|
- const nobj = { ..._.omit(i, ['_id', 'id', 'user_id', 'inventor']), content, parent_id: i._id, user_id };
|
|
|
+ const user_id = inventor.map(i => ObjectId(i.user_id));
|
|
|
+ // const inventorNameString = inventor.map(i => i.name).join(';');
|
|
|
+ // const content = `发明人 【${inventorNameString}】 的已授权专利 【${name}】 即将失效,避免专利失效过期,请用户及时查看消息并处理! `;
|
|
|
+ const content = '您可能需缴年费了,具体以缴费通知书为准 ';
|
|
|
+ const nobj = {
|
|
|
+ ..._.omit(i, [ '_id', 'id', 'user_id', 'inventor' ]),
|
|
|
+ content,
|
|
|
+ parent_id: i._id,
|
|
|
+ user_id,
|
|
|
+ };
|
|
|
this.model.create(nobj);
|
|
|
// 2021-11-04添加 向 patentexamine 表中添加数据
|
|
|
const patentexamineArray = [];
|
|
|
for (const i of inventor) {
|
|
|
const { user_id } = i;
|
|
|
- const peContent = `【${name}】 专利即将过期,请用户及时到相应功能模块中处理专利信息!`;
|
|
|
+ // const peContent = `【${name}】 专利即将过期,请用户及时到相应功能模块中处理专利信息!`;
|
|
|
+ const peContent = '您可能需缴年费了,具体以缴费通知书为准';
|
|
|
const patentexamineObject = {
|
|
|
to: user_id,
|
|
|
content: peContent,
|