guhongwei 3 years ago
parent
commit
a41f7e6062
5 changed files with 97 additions and 6 deletions
  1. 51 0
      app/controller/.apply.js
  2. 18 0
      app/controller/apply.js
  3. 6 0
      app/model/apply.js
  4. 7 6
      app/router.js
  5. 15 0
      app/service/apply.js

+ 51 - 0
app/controller/.apply.js

@@ -0,0 +1,51 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "title",
+      "apply_year",
+      "!project_info",
+      "!apply_index",
+      "status",
+      "record",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "title",
+      "apply_year",
+      "!project_info",
+      "!apply_index",
+      "status",
+      "record",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        "meta.createdAt@start": "meta.createdAt@start",
+        "meta.createdAt@end": "meta.createdAt@end",
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 18 - 0
app/controller/apply.js

@@ -0,0 +1,18 @@
+'use strict';
+const meta = require('./.apply.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose-free/lib/controller');
+
+// 绩效申请表
+class ApplyController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.apply;
+  }
+  async index() {
+    const { skip, limit, ...query } = this.ctx.query;
+    const data = await this.service.query(query, { skip, limit });
+    this.ctx.ok({ ...data });
+  }
+}
+module.exports = CrudController(ApplyController, meta);

+ 6 - 0
app/model/apply.js

@@ -5,6 +5,12 @@ const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
 const { ObjectId } = require('mongoose').Types;
 // 绩效申请表
 const apply = {
+  title: { type: String }, //标题
+  apply_year: { type: String }, // 申请年度
+  project_info: { type: Object }, // 项目信息
+  apply_index: { type: Array }, // 绩效指标
+  status: { type: String, default: "0" }, // 0:草稿,1:待审中,2:审核通过,3:审核拒绝
+  record: { type: Array }, // 记录
   remark: { type: String },
 };
 const schema = new Schema(apply, { toJSON: { virtuals: true } });

+ 7 - 6
app/router.js

@@ -3,10 +3,11 @@
 /**
  * @param {Egg.Application} app - egg application
  */
-module.exports = app => {
+module.exports = (app) => {
   const { router, controller } = app;
-  router.get('/', controller.home.index);
-  router.post('/util', controller.home.util);
-  require('./z_router/setting')(app); // 绩效设置
-  require('./z_router/user')(app); // 用户关系
-};
+  router.get("/", controller.home.index);
+  router.post("/util", controller.home.util);
+  require("./z_router/setting")(app); // 绩效设置
+  require("./z_router/user")(app); // 用户关系
+  require("./z_router/apply")(app); // 绩效申请
+};;

+ 15 - 0
app/service/apply.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 ApplyService extends CrudService {
+  constructor(ctx) {
+    super(ctx, "apply");
+    this.model = this.ctx.model.Apply;
+  }
+}
+
+module.exports = ApplyService;