guhongwei 4 éve
szülő
commit
d8955c6d09

+ 62 - 0
app/controller/.thousand.js

@@ -0,0 +1,62 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "!title",
+      "pic",
+      "content",
+      "abstract",
+      "type",
+      "parent_id",
+      "parent",
+      "publish_time",
+      "url",
+      "info_type",
+      "is_use",
+      "news_type",
+      "origin",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "!title",
+      "pic",
+      "content",
+      "abstract",
+      "type",
+      "parent_id",
+      "parent",
+      "publish_time",
+      "url",
+      "info_type",
+      "is_use",
+      "news_type",
+      "origin",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        name: "name",
+        site: "site",
+      },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 28 - 0
app/controller/company.js

@@ -5,6 +5,22 @@ const meta = require('./.company.js');
 const Controller = require('egg').Controller;
 const Controller = require('egg').Controller;
 const { CrudController } = require('naf-framework-mongoose/lib/controller');
 const { CrudController } = require('naf-framework-mongoose/lib/controller');
 
 
+// const http = require('http');
+// const schedule = require('node-schedule');
+// 5分钟
+// const rule2 = new schedule.RecurrenceRule();
+// const times2 = [ 1, 6, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56 ];
+// rule2.minute = times2;
+// schedule.scheduleJob(rule2, function() {
+//   httpGet();
+// });
+// 5秒钟
+// const rule1 = new schedule.RecurrenceRule();
+// const times1 = [ 1, 6, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56 ];
+// rule1.second = times1;
+// schedule.scheduleJob(rule1, function() {
+//   httpGet();
+// });
 // 企业信息表
 // 企业信息表
 class CompanyController extends Controller {
 class CompanyController extends Controller {
   constructor(ctx) {
   constructor(ctx) {
@@ -13,4 +29,16 @@ class CompanyController extends Controller {
   }
   }
 }
 }
 
 
+// function httpGet() {
+//   const uri = 'http://smart.jilinjobs.cn/www/index';
+//   http
+//     .get(uri, function(res) {
+//       console.log('访问个人微博状态码: ' + res.statusCode);
+//     })
+//     .on('error', function(e) {
+//       console.log('个人微博 error: ' + e.message);
+//     });
+// }
+
+
 module.exports = CrudController(CompanyController, meta);
 module.exports = CrudController(CompanyController, meta);

+ 16 - 0
app/controller/thousand.js

@@ -0,0 +1,16 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.thousand.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+//
+class ThousandController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.thousand;
+  }
+}
+
+module.exports = CrudController(ThousandController, meta);

+ 31 - 0
app/model/thousand.js

@@ -0,0 +1,31 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+
+// 信息表
+const ThousandSchema = {
+  title: { type: String, required: false, maxLength: 128 }, // 标题
+  pic: { type: String, required: false, maxLength: 256 }, // 标题图片URL
+  content: { type: String, required: false, maxLength: 102400, select: false }, // 内容详情
+  abstract: { type: String, required: false, maxLength: 500 }, // 内容简介
+  type: { type: String, required: false, maxLength: 5 }, // 所属类型
+  parent_id: { type: String, required: false, maxLength: 64 }, // 所属id
+  parent: { type: String, required: false, maxLength: 100 }, // 所属名称
+  publish_time: String, // 发布时间
+  url: { type: String, required: false, maxLength: 256 }, // 外部链接
+  info_type: { type: String, required: false, maxLength: 256, default: '0' }, // 信息类型 0、普通 1、外链
+  is_use: { type: String, required: false, maxLength: 5 }, // 是否使用,0=>使用中;1=>已禁止
+  news_type: { type: String, default: 1, maxLength: 5 }, // 0抓取,1正常输入
+  origin: { type: String, required: false, maxLength: 200 }, // 发布来源
+};
+
+
+const schema = new Schema(ThousandSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Thousand', schema, 'market_thousand');
+};

+ 5 - 0
app/router.js

@@ -13,4 +13,9 @@ module.exports = app => {
   // 企业信息表设置
   // 企业信息表设置
   router.resources('testmess', '/api/servicetest/testmess', controller.testmess); // index、create、show、destroy
   router.resources('testmess', '/api/servicetest/testmess', controller.testmess); // index、create、show、destroy
   router.post('testmess', '/api/servicetest/testmess/update/:id', controller.testmess.update);
   router.post('testmess', '/api/servicetest/testmess/update/:id', controller.testmess.update);
+  // 1000万数据
+  // 信息表设置路由
+  router.resources('thousand', '/api/servicetest/thousand', controller.thousand); // index、create、show、destroy
+  router.post('thousand', '/api/servicetest/thousand/update/:id', controller.thousand.update);
+
 };
 };

+ 22 - 0
app/schedule/schedule.js

@@ -0,0 +1,22 @@
+'use strict';
+const _ = require('lodash');
+const Subscription = require('egg').Subscription;
+class TaskPortal extends Subscription {
+  // 通过 schedule 属性来设置定时任务的执行间隔等配置
+  static get schedule() {
+    // return {
+    //   interval: '5m',
+    //   type: 'all',
+    // };
+  }
+  // // subscribe 是真正定时任务执行时被运行的函数
+  async subscribe() {
+    // const res = await this.ctx.curl('http://127.0.0.1:8081/api/servicetest/thousand', {
+    //   dataType: 'json',
+    // });
+    // console.log(res.data);
+    await this.ctx.service.thousand.create();
+  }
+}
+
+module.exports = TaskPortal;

+ 25 - 0
app/service/thousand.js

@@ -0,0 +1,25 @@
+'use strict';
+
+const assert = require('assert');
+const _ = require('lodash');
+const { ObjectId } = require('mongoose').Types;
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const test = require('../../test.js');
+class ThousandService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'thousand');
+    this.model = this.ctx.model.Thousand;
+  }
+  async create() {
+    for (const val of test) {
+      const res = await this.model.create(val);
+      console.log(res);
+    }
+    // const res = await this.model.create({ ...test });
+    // console.log(res);
+    // return res;
+  }
+}
+
+module.exports = ThousandService;

+ 1 - 0
package.json

@@ -17,6 +17,7 @@
     "lodash": "^4.17.15",
     "lodash": "^4.17.15",
     "moment": "^2.27.0",
     "moment": "^2.27.0",
     "naf-framework-mongoose": "^0.6.11",
     "naf-framework-mongoose": "^0.6.11",
+    "node-schedule": "^1.3.2",
     "nodemailer": "^6.4.3",
     "nodemailer": "^6.4.3",
     "silly-datetime": "^0.1.2",
     "silly-datetime": "^0.1.2",
     "string-random": "^0.1.3",
     "string-random": "^0.1.3",

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 4525 - 0
test.js