Browse Source

更新框架,2级账号对3级账号的申请查询参数修改中间件

lrf 3 năm trước cách đây
mục cha
commit
fa05e39e6a

+ 4 - 3
app/controller/.apply.js

@@ -1,6 +1,6 @@
 module.exports = {
   create: {
-    requestBody: ['title', 'apply_year', 'project_info', 'apply_index', 'status', 'record', 'user_id'],
+    requestBody: ['title', 'user_name', 'apply_year', 'project_info', 'apply_index', 'status', 'record', 'user_id', 'excel'],
   },
   destroy: {
     params: ['!id'],
@@ -8,7 +8,7 @@ module.exports = {
   },
   update: {
     params: ['!id'],
-    requestBody: ['title', 'apply_year', 'project_info', 'apply_index', 'status', 'record', 'user_id'],
+    requestBody: ['title', 'user_name', 'apply_year', 'project_info', 'apply_index', 'status', 'record', 'user_id', 'excel'],
   },
   show: {
     parameters: {
@@ -19,7 +19,8 @@ module.exports = {
   index: {
     parameters: {
       query: {
-        user_id:'user_id',
+        user_id: 'user_id',
+        user_name: 'user_name',
         'meta.createdAt@start': 'meta.createdAt@start',
         'meta.createdAt@end': 'meta.createdAt@end',
       },

+ 15 - 0
app/middleware/apply-query.js

@@ -0,0 +1,15 @@
+'use strict';
+const _ = require('lodash');
+module.exports = options => {
+  return async function applyQuery(ctx, next) {
+    const query = ctx.query;
+    if (query.superior_id) {
+      // 有上级id,查出这个2级账号下的3级账号
+      const relations = await ctx.model.UserRelation.find({ superior_id: query.superior_id });
+      const user_ids = relations.map(i => i.user_id);
+      query.user_id = user_ids;
+      delete query.superior_id;
+    }
+    await next();
+  };
+};

+ 1 - 1
app/middleware/flow.js

@@ -19,7 +19,7 @@ module.exports = options => {
     const desc = statusOpera[status];
     const id = data._id || data.id;
     const record = data.record || [];
-    record.push({ desc, time: moment().format('YYYY-MM-DD HH:mm:ss') });
+    record.push({ desc, status, time: moment().format('YYYY-MM-DD HH:mm:ss') });
     // try {
     //   // 加记录,不需要等待
     //   ctx.service.apply.update({ id }, { record });

+ 10 - 7
app/model/apply.js

@@ -1,25 +1,28 @@
-"use strict";
-const Schema = require("mongoose").Schema;
-const moment = require("moment");
-const metaPlugin = require("naf-framework-mongoose-free/lib/model/meta-plugin");
-const { ObjectId } = require("mongoose").Types;
+'use strict';
+const Schema = require('mongoose').Schema;
+const moment = require('moment');
+const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
+const { ObjectId } = require('mongoose').Types;
 // 绩效申请表
 const apply = {
   user_id: { type: String }, // 用户id
+  user_name: { type: String }, // 用户名
   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 }, // 记录
+  excel: { type: Object }, // excel数据
   remark: { type: String },
 };
 const schema = new Schema(apply, { toJSON: { virtuals: true } });
 schema.index({ id: 1 });
 schema.index({ user_id: 1 });
+schema.index({ user_name: 1 });
 schema.index({ 'meta.createdAt': 1 });
 schema.plugin(metaPlugin);
-module.exports = (app) => {
+module.exports = app => {
   const { mongoose } = app;
-  return mongoose.model("Apply", schema, "apply");
+  return mongoose.model('Apply', schema, 'apply');
 };

+ 1 - 1
app/z_router/apply.js

@@ -1,7 +1,7 @@
 'use strict';
 // 路由配置
 const routes = [
-  { method: 'get', path: '/apply', controller: 'apply.index', name: 'applyQuery', zh: '绩效申请设置列表查询' },
+  { method: 'get', path: '/apply', controller: 'apply.index', middleware: [ 'applyQuery' ], name: 'applyQuery', zh: '绩效申请设置列表查询' },
   { method: 'get', path: '/apply/:id', controller: 'apply.show', name: 'applyFetch', zh: '绩效申请设置查询' },
   { method: 'post', path: '/apply', controller: 'apply.create', name: 'applyCreate', middleware: [ 'flow' ], zh: '创建绩效申请设置' },
   { method: 'post', path: '/apply/:id', controller: 'apply.update', name: 'applyUpdate', middleware: [ 'flow' ], zh: '修改绩效申请' },

+ 1 - 1
package.json

@@ -14,7 +14,7 @@
     "egg-scripts": "^2.11.0",
     "lodash": "^4.17.21",
     "moment": "^2.29.1",
-    "naf-framework-mongoose-free": "^0.0.13"
+    "naf-framework-mongoose-free": "^0.0.14"
   },
   "devDependencies": {
     "autod": "^3.0.1",