liuyu 4 年 前
コミット
d54ffdfb7d

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

@@ -0,0 +1,62 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "dock_id",
+      "!title",
+      "titlejj",
+      "orgin",
+      "publish",
+      "publish_time",
+      "content",
+      "uid",
+      "picture",
+      "filepath",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "dock_id",
+      "!title",
+      "titlejj",
+      "orgin",
+      "publish",
+      "publish_time",
+      "content",
+      "uid",
+      "picture",
+      "filepath",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        dock_id: "dock_id",
+        title: "title",
+        orgin: "orgin",
+        publish: "publish",
+        publish_time: "publish_time",
+        content: "content",
+        uid: 'uid',
+        picture: "picture",
+      },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

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

@@ -0,0 +1,62 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "dock_id",
+      "!title",
+      "titlejj",
+      "orgin",
+      "publish",
+      "publish_time",
+      "content",
+      "uid",
+      "picture",
+      "filepath",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "dock_id",
+      "!title",
+      "titlejj",
+      "orgin",
+      "publish",
+      "publish_time",
+      "content",
+      "uid",
+      "picture",
+      "filepath",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        dock_id: "dock_id",
+        title: "title",
+        orgin: "orgin",
+        publish: "publish",
+        publish_time: "publish_time",
+        content: "content",
+        uid: 'uid',
+        picture: "picture",
+      },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 19 - 0
app/controller/newsguidance.js

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

+ 19 - 0
app/controller/newsroadshow.js

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

+ 28 - 0
app/model/newsguidance.js

@@ -0,0 +1,28 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 信息表
+const NewsguidanceSchema = {
+  dock_id: { type: String, required: false, maxLength: 500 }, // 栏目id
+  title: { type: String, required: false, maxLength: 500 }, // 标题
+  titlejj: { type: String, required: false, maxLength: 500 }, // 标题简介
+  orgin: { type: String, required: false, maxLength: 500 }, // 来源
+  publish: { type: String, required: false, maxLength: 500 }, // 发布者
+  publish_time: { type: String, required: false, maxLength: 500 }, // 发布时间
+  uid: { type: String, required: false, maxLength: 500 }, // 用户id
+  content: { type: String, required: false }, // 正文
+  picture: { type: String, required: false }, // 图片路径
+  filepath: { type: String, required: false }, // 文件路径
+};
+
+
+const schema = new Schema(NewsguidanceSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ dock_id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Newsguidance', schema, 'live_news_guidance');
+};

+ 28 - 0
app/model/newsroadshow.js

@@ -0,0 +1,28 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 信息表
+const NewsroadshowSchema = {
+  dock_id: { type: String, required: false, maxLength: 500 }, // 栏目id
+  title: { type: String, required: false, maxLength: 500 }, // 标题
+  titlejj: { type: String, required: false, maxLength: 500 }, // 标题简介
+  orgin: { type: String, required: false, maxLength: 500 }, // 来源
+  publish: { type: String, required: false, maxLength: 500 }, // 发布者
+  publish_time: { type: String, required: false, maxLength: 500 }, // 发布时间
+  uid: { type: String, required: false, maxLength: 500 }, // 用户id
+  content: { type: String, required: false }, // 正文
+  picture: { type: String, required: false }, // 图片路径
+  filepath: { type: String, required: false }, // 文件路径
+};
+
+
+const schema = new Schema(NewsroadshowSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ dock_id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Newsroadshow', schema, 'live_news_roadshow');
+};

+ 8 - 0
app/router.js

@@ -74,6 +74,14 @@ module.exports = app => {
   router.resources('news', '/api/live/news', controller.news); // index、create、show、destroy
   router.post('news', '/api/live/news/update/:id', controller.news.update);
 
+  // 在线指导信息表设置路由
+  router.resources('newsguidance', '/api/live/newsguidance', controller.newsguidance); // index、create、show、destroy
+  router.post('newsguidance', '/api/live/newsguidance/update/:id', controller.newsguidance.update);
+
+  // 项目路演表设置路由
+  router.resources('newsroadshow', '/api/live/newsroadshow', controller.newsroadshow); // index、create、show、destroy
+  router.post('newsroadshow', '/api/live/newsroadshow/update/:id', controller.newsroadshow.update);
+
   // 信息表设置路由
   router.resources('comment', '/api/live/comment', controller.comment); // index、create、show、destroy
   router.post('comment', '/api/live/comment/update/:id', controller.comment.update);

+ 37 - 0
app/service/newsguidance.js

@@ -0,0 +1,37 @@
+'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;
+
+class NewsguidanceService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'newsguidance');
+    this.model = this.ctx.model.Newsguidance;
+  }
+
+  async fetch({ id }) {
+    const news = await this.model.findById(id);
+    const newdata = { ...JSON.parse(JSON.stringify(news)) };
+    if (news) {
+      const url = 'http://127.0.0.1:9999/api/auth/user/' + news.uid;
+      const user = await this.ctx.curl(url, {
+        method: 'get',
+        headers: {
+          'content-type': 'application/json',
+        },
+        dataType: 'json',
+      });
+      if (user.data.errcode === 0) {
+        newdata.uname = user.data.data.name;
+      }
+    }
+    return newdata;
+  }
+
+}
+
+module.exports = NewsguidanceService;

+ 37 - 0
app/service/newsroadshow.js

@@ -0,0 +1,37 @@
+'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;
+
+class NewsroadshowService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'newsroadshow');
+    this.model = this.ctx.model.Newsroadshow;
+  }
+
+  async fetch({ id }) {
+    const news = await this.model.findById(id);
+    const newdata = { ...JSON.parse(JSON.stringify(news)) };
+    if (news) {
+      const url = 'http://127.0.0.1:9999/api/auth/user/' + news.uid;
+      const user = await this.ctx.curl(url, {
+        method: 'get',
+        headers: {
+          'content-type': 'application/json',
+        },
+        dataType: 'json',
+      });
+      if (user.data.errcode === 0) {
+        newdata.uname = user.data.data.name;
+      }
+    }
+    return newdata;
+  }
+
+}
+
+module.exports = NewsroadshowService;