guhongwei 2 роки тому
батько
коміт
94fc2d398e

+ 1 - 0
.gitignore

@@ -11,3 +11,4 @@ run/
 *.un~
 typings/
 .nyc_output/
+*.history

+ 81 - 0
app/controller/config/.videos.js

@@ -0,0 +1,81 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "title",
+      "brief",
+      "time_num",
+      "origin",
+      "firm_id",
+      "type_id",
+      "place_id",
+      "year",
+      "head_actor",
+      "actor",
+      "img_url",
+      "video_url",
+      "view_num",
+      "is_use",
+      "is_hot",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "title",
+      "brief",
+      "time_num",
+      "origin",
+      "firm_id",
+      "type_id",
+      "place_id",
+      "year",
+      "head_actor",
+      "actor",
+      "img_url",
+      "video_url",
+      "view_num",
+      "is_use",
+      "is_hot",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        "meta.createdAt@start": "meta.createdAt@start",
+        "meta.createdAt@end": "meta.createdAt@end",
+        title: "title",
+        brief: "brief",
+        time_num: "time_num",
+        origin: "origin",
+        firm_id: "firm_id",
+        type_id: "type_id",
+        place_id: "place_id",
+        year: "year",
+        head_actor: "head_actor",
+        view_num: "view_num",
+        is_use: "is_use",
+        is_hot: "is_hot",
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 13 - 0
app/controller/videos.js

@@ -0,0 +1,13 @@
+'use strict';
+const meta = require('./config/.videos.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose-free/lib/controller');
+
+// 视频信息
+class VideosController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.videos;
+  }
+}
+module.exports = CrudController(VideosController, meta);

+ 45 - 0
app/model/videos.js

@@ -0,0 +1,45 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
+
+
+// 视频信息
+const videos = {
+  title: { type: String, required: false, zh: '名称' }, //
+  brief: { type: String, required: false, zh: '简介' }, //
+  time_num: { type: String, required: false, zh: '时长' }, //
+  origin: { type: String, required: false, zh: '来源' }, //
+  firm_id: { type: String, required: false, zh: '厂商' }, //
+  type_id: { type: String, required: false, zh: '类型' }, //
+  place_id: { type: String, required: false, zh: '产地' }, //
+  year: { type: String, required: false, zh: '年份' }, //
+  head_actor: { type: String, required: false, zh: '领衔演员' }, //
+  actor: { type: String, required: false, zh: '演员' }, //
+  img_url: { type: Array, required: false, zh: '图片' }, //
+  video_url: { type: Array, required: false, zh: '视频路径' }, //
+  view_num: { type: Number, required: false, default: '0', zh: '观看次数' }, //
+  is_use: { type: String, required: false, default: '0', zh: '是否启用' }, //
+  is_hot: { type: String, required: false, default: '0', zh: '是否热推' }, //
+};
+const schema = new Schema(videos, { toJSON: { getters: true, virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.index({ title: 1 });
+schema.index({ brief: 1 });
+schema.index({ time_num: 1 });
+schema.index({ origin: 1 });
+schema.index({ firm_id: 1 });
+schema.index({ type_id: 1 });
+schema.index({ place_id: 1 });
+schema.index({ year: 1 });
+schema.index({ head_actor: 1 });
+schema.index({ view_num: 1 });
+schema.index({ is_use: 1 });
+schema.index({ is_hot: 1 });
+
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Videos', schema, 'videos');
+};

+ 1 - 0
app/router.js

@@ -25,4 +25,5 @@ module.exports = app => {
   require('./z_router/appapk')(app); // 应用管理
   require('./z_router/scenetype')(app); // 视频场景分类
   require('./z_router/scenedata')(app); // 视频场景信息
+  require('./z_router/videos')(app); // 视频
 };

+ 15 - 0
app/service/videos.js

@@ -0,0 +1,15 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose-free/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const _ = require('lodash');
+const assert = require('assert');
+
+// 视频
+class VideosService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'videos');
+    this.model = this.ctx.model.Videos;
+  }
+}
+
+module.exports = VideosService;

+ 28 - 0
app/z_router/videos.js

@@ -0,0 +1,28 @@
+'use strict';
+// 测试接口
+const rKey = 'videos'; // routerKey,路由前缀变量
+const cKey = 'videos'; // controllerKey,controller名
+const zhKey = '视频';
+const routes = [
+  { method: 'get', path: `/${rKey}`, controller: `${cKey}.index`, name: `${cKey}Query`, zh: `${zhKey}列表查询` },
+  { method: 'get', path: `/${rKey}/:id`, controller: `${cKey}.show`, name: `${cKey}Show`, zh: `${zhKey}查询` },
+  { method: 'post', path: `/${rKey}`, controller: `${cKey}.create`, name: `${cKey}Create`, zh: `创建${zhKey}` },
+  { method: 'post', path: `/${rKey}/:id`, controller: `${cKey}.update`, name: `${cKey}Update`, zh: `修改${zhKey}` },
+  { method: 'delete', path: `/${rKey}/:id`, controller: `${cKey}.destroy`, name: `${cKey}Delete`, zh: `删除${zhKey}` },
+];
+
+module.exports = app => {
+  const { router, config } = app;
+  const mwares = app.middleware;
+  for (const route of routes) {
+    const { method, path, controller: ctl, zh } = route;
+    let { middleware = [] } = route;
+    if (!method || !path || !ctl) continue;
+    // 拼全路径
+    const allPath = `${config.routePrefix}${path}`;
+    // 处理中间件
+    if (middleware.length > 0) middleware = middleware.map(i => mwares[i]());
+    // 注册路由
+    router[method](zh, allPath, ...middleware, ctl);
+  }
+};