guhongwei 3 年 前
コミット
11acd2bc50

+ 64 - 0
app/controller/tecinfo/.dimension.js

@@ -0,0 +1,64 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "user_id",
+      "title",
+      "publish_time",
+      "origin",
+      "brief",
+      "is_show",
+      "filepath",
+      "content",
+      "remark",
+      "create_time",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "user_id",
+      "title",
+      "publish_time",
+      "origin",
+      "brief",
+      "is_show",
+      "filepath",
+      "content",
+      "remark",
+      "create_time",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        title: "title",
+        publish_time: "publish_time",
+        origin: "origin",
+        "publish_time@start": "publish_time@start",
+        "publish_time@end": "publish_time@end",
+        "create_time@start": "create_time@start",
+        "create_time@end": "create_time@end",
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 13 - 0
app/controller/tecinfo/dimension.js

@@ -0,0 +1,13 @@
+'use strict';
+const meta = require('./.dimension.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 专利维权
+class dimensionController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.tecinfo.dimension;
+  }
+}
+module.exports = CrudController(dimensionController, meta);

+ 29 - 0
app/model/dimension.js

@@ -0,0 +1,29 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const moment = require('moment');
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+const { ObjectId } = require('mongoose').Types;
+// 专利维权表
+const dimension = {
+  user_id: { type: ObjectId }, //
+  title: { type: String }, // 标题
+  publish_time: { type: String }, // 时间
+  origin: { type: String, default: '网站管理员' }, // 来源
+  brief: { type: String }, // 简介
+  is_show: { type: Boolean, default: false }, // 是否展示
+  filepath: { type: Object }, // 附件
+  content: { type: String }, // 正文内容
+  remark: { type: String },
+  create_time: { type: String }, // 创建时间
+};
+const schema = new Schema(dimension, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ title: 1 });
+schema.index({ publish_time: 1 });
+schema.index({ origin: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Dimension', schema, 'dimension');
+};

+ 2 - 0
app/router.js

@@ -52,6 +52,8 @@ module.exports = app => {
   require('./router/tecinfo/science')(app); // 科技新闻
   require('./router/tecinfo/science')(app); // 科技新闻
   require('./router/tecinfo/universal')(app); // 科学普及
   require('./router/tecinfo/universal')(app); // 科学普及
   require('./router/tecinfo/view_point')(app); // 智库视点
   require('./router/tecinfo/view_point')(app); // 智库视点
+  require('./router/tecinfo/dimension')(app); // 专利维权
+
   // statistics
   // statistics
   require('./router/statistics/index')(app); // 首页统计
   require('./router/statistics/index')(app); // 首页统计
   // cysci
   // cysci

+ 12 - 0
app/router/tecinfo/dimension.js

@@ -0,0 +1,12 @@
+'use strict';
+
+
+module.exports = app => {
+  const { router, controller } = app;
+  const profix = '/api/live/';
+  const vision = 'v0';
+  const index = 'tecinfo';
+  const target = 'dimension';
+  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);
+};

+ 15 - 0
app/service/tecinfo/dimension.js

@@ -0,0 +1,15 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const _ = require('lodash');
+const assert = require('assert');
+
+// 专利维权
+class dimensionService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'dimension');
+    this.model = this.ctx.model.Dimension;
+  }
+}
+
+module.exports = dimensionService;