Jelajahi Sumber

Merge branch 'master' of http://git.cc-lotus.info/live/service-live

lrf 3 tahun lalu
induk
melakukan
3f52fa6a1f

+ 3 - 0
app/controller/patent/.patentearly.js

@@ -38,4 +38,7 @@ module.exports = {
       count: true,
     },
   },
+  warning: {
+    service: "needWarning",
+  },
 };

+ 1 - 0
app/router/patent/patentearly.js

@@ -8,6 +8,7 @@ module.exports = app => {
   const index = 'patent';
   const target = 'patentearly';
   const metaTime = app.middleware.createTime();
+  router.post(target, `${profix}${vision}/${index}/${target}/warning`, controller[index][target].warning);
   router.get(target, `${profix}${vision}/${index}/${target}/queryByOrg`, metaTime, controller[index][target].queryByOrg);
   router.resources(target, `${profix}${vision}/${index}/${target}`, controller[index][target]); // index、create、show、destroy
   router.post(target, `${profix}${vision}/${index}/${target}/update/:id`, controller[index][target].update);

+ 5 - 5
app/service/patent/patentapply.js

@@ -117,20 +117,20 @@ class PatentapplyService extends CrudService {
         break;
       case '1':
         arr.push({
-          content: `您的专利申请书【${name}】已通过机构的审核,请您耐心等待管理员进行审查受理`,
+          content: `您的专利申请书【${name}】已通过机构的审核,请您耐心等待管理员进行受理`,
           to: user_id,
         });
         arr.push({
-          content: `${apply_name}的专利申请书【${name}】已通过机构的审核,请您尽快对其进行审查受理`,
+          content: `${apply_name}的专利申请书【${name}】已通过机构的审核,请您尽快对其进行受理`,
           to: admin_id,
         });
         break;
       case '-2':
-        content = `您的专利申请书【${name}】未通过管理员的审查受理,请您及时修改,重新提交申请`;
+        content = `您的专利申请书【${name}】未通过管理员的受理,请您及时修改,重新提交申请`;
         to = user_id;
         break;
       case '2':
-        content = `您的专利申请书【${name}】已通过管理员的审查受理,请及时准备申请文件,并上传`;
+        content = `您的专利申请书【${name}】已通过管理员的受理,请及时准备申请文件,并上传`;
         to = user_id;
         break;
       case '-3':
@@ -138,7 +138,7 @@ class PatentapplyService extends CrudService {
         to = user_id;
         break;
       case '4':
-        content = `您的专利申请书【${name}】已通过管理员的审查受理,待系统管理员上报国知局`;
+        content = `您的专利申请书【${name}】已通过管理员的受理,待系统管理员上报国知局`;
         to = user_id;
         break;
       case '5':

+ 43 - 10
app/service/patent/patentearly.js

@@ -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,

+ 2 - 2
app/service/patent/patentinfo.js

@@ -497,8 +497,8 @@ class PatentinfoService extends CrudService {
   async dealCode(code) {
     let pids = await this.personalModel.find({ code }, { _id: 1 });
     if (pids.length <= 0) return { data: [], total: 0 };
-    pids = pids.map((i) => i._id);
-    const query = { user_id: { $elemMatch: { $in: pids } } };
+    pids = pids.map(i => i._id);
+    const query = { 'inventor.user_id': { $in: pids } };
     return query;
   }
   async dealYearRange(year) {

+ 43 - 0
test/test.js

@@ -0,0 +1,43 @@
+'use strict';
+
+const moment = require('moment');
+const _ = require('lodash');
+
+describe('test/test.js', () => {
+  const create_date = '2020-05-18';
+  const limitMonth = 3;
+  const today = '2022-03-19';
+  // 取专利日期
+  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(today).isBetween(start, end, null, '[]');
+  console.log(`${start} - ${end}`);
+  console.log(r);
+  if (r) {
+    // 结束日期 和 今天 差的天数
+    const day = moment(end).diff(moment(today), 'days');
+    console.log(`今天和最后一天相差天数:${day}`);
+    // 是否发送的变量
+    let dr = false;
+    if (moment().format('YYYY-MM-DD') === start) {
+      // 第一天发送
+      dr = true;
+    } else {
+      // 差10天就发
+      const dur = 10;
+      // 判断是不是整数.整数就发送
+      dr = _.isInteger(_.floor(_.divide(day, dur)));
+    }
+
+
+  }
+
+});