瀏覽代碼

改了很多,忘了

lrf 3 年之前
父節點
當前提交
9a6ce4725f

+ 13 - 26
app/controller/.apply.js

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

+ 42 - 0
app/controller/.template.js

@@ -0,0 +1,42 @@
+module.exports = {
+  create: {
+    requestBody: ['title', 'is_use', 'excel'],
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete',
+  },
+  update: {
+    params: ['!id'],
+    requestBody: ['title', 'is_use', 'excel'],
+  },
+  show: {
+    parameters: {
+      params: ['!id'],
+    },
+    service: 'fetch',
+  },
+  index: {
+    parameters: {
+      query: {
+        title: 'title',
+        is_use: 'is_use',
+        '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,
+    },
+  },
+  toUse: {
+    params: ['!id'],
+  },
+};

+ 0 - 5
app/controller/apply.js

@@ -9,10 +9,5 @@ class ApplyController extends Controller {
     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);

+ 13 - 0
app/controller/template.js

@@ -0,0 +1,13 @@
+'use strict';
+const meta = require('./.template.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose-free/lib/controller');
+
+// 模板
+class TemplateController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.template;
+  }
+}
+module.exports = CrudController(TemplateController, meta);

+ 31 - 0
app/middleware/flow.js

@@ -0,0 +1,31 @@
+'use strict';
+const _ = require('lodash');
+const moment = require('moment');
+const statusOpera = {
+  0: '保存为草稿',
+  1: '提交审核',
+  2: '审核通过',
+  3: '审核拒绝',
+};
+module.exports = options => {
+  return async function flow(ctx, next) {
+    // 记录申请流程的中间件
+    await next();
+    const body = ctx.response.body;
+    const { data } = body;
+    const status = data.status;
+    console.log(status); // 2的情况应该生成副本
+    // 获取当前状态应该是什么样的描述
+    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') });
+    try {
+      // 加记录,不需要等待
+      ctx.service.apply.update({ id }, { record });
+    } catch (error) {
+      console.log('记录添加失败');
+    }
+
+  };
+};

+ 0 - 17
app/model/apply-update.js

@@ -1,17 +0,0 @@
-'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 applyUpdate = {
-  remark: { type: String },
-};
-const schema = new Schema(applyUpdate, { toJSON: { virtuals: true } });
-schema.index({ id: 1 });
-schema.index({ 'meta.createdAt': 1 });
-schema.plugin(metaPlugin);
-module.exports = app => {
-  const { mongoose } = app;
-  return mongoose.model('applyUpdate', schema, 'applyUpdate');
-};

+ 4 - 2
app/model/apply.js

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

+ 25 - 0
app/model/duplicate.js

@@ -0,0 +1,25 @@
+'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 duplicate = {
+  apply_id: { type: String }, // 原数据id
+  user_id: { type: String }, // 用户id
+  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(duplicate, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Duplicate', schema, 'duplicate');
+};

+ 0 - 17
app/model/flow.js

@@ -1,17 +0,0 @@
-'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 flow = {
-  remark: { type: String },
-};
-const schema = new Schema(flow, { toJSON: { virtuals: true } });
-schema.index({ id: 1 });
-schema.index({ 'meta.createdAt': 1 });
-schema.plugin(metaPlugin);
-module.exports = app => {
-  const { mongoose } = app;
-  return mongoose.model('Flow', schema, 'flow');
-};

+ 5 - 0
app/model/template.js

@@ -5,10 +5,15 @@ const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
 const { ObjectId } = require('mongoose').Types;
 // 模板表
 const template = {
+  title: { type: String }, // 模板标题
+  is_use: { type: Boolean, default: false }, // 启用/禁用; 只能启用1个
+  excel: { type: Object }, // excel数据
   remark: { type: String },
 };
 const schema = new Schema(template, { toJSON: { virtuals: true } });
 schema.index({ id: 1 });
+schema.index({ is_use: 1 });
+schema.index({ title: 1 });
 schema.index({ 'meta.createdAt': 1 });
 schema.plugin(metaPlugin);
 module.exports = app => {

+ 8 - 7
app/router.js

@@ -3,11 +3,12 @@
 /**
  * @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); // 用户关系
-  require("./z_router/apply")(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); // 绩效申请
+  require('./z_router/template')(app); // 绩效模板
+};

+ 6 - 6
app/service/apply.js

@@ -1,13 +1,13 @@
-"use strict";
-const { CrudService } = require("naf-framework-mongoose/lib/service");
-const { BusinessError, ErrorCode } = require("naf-core").Error;
-const _ = require("lodash");
-const assert = require("assert");
+'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 ApplyService extends CrudService {
   constructor(ctx) {
-    super(ctx, "apply");
+    super(ctx, 'apply');
     this.model = this.ctx.model.Apply;
   }
 }

+ 21 - 0
app/service/template.js

@@ -0,0 +1,21 @@
+'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');
+const { ObjectId } = require('mongoose').Types;
+
+// 模板
+class TemplateService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'template');
+    this.model = this.ctx.model.Template;
+  }
+
+  async toUse({ id }) {
+    await this.model.updateMany({}, { is_use: false });
+    await this.model.updateOne({ _id: ObjectId(id) }, { is_use: true });
+  }
+}
+
+module.exports = TemplateService;

+ 11 - 0
app/service/user.js

@@ -22,6 +22,17 @@ class UserService extends CrudService {
     const table = 'sys_user';
     let { data } = await this.mysql.query(table, { user_id: ids, ...others });
     data = data.map(i => _.omit(i, [ 'password' ]));
+    // 将key转换成java部分的驼峰显示
+    data = data.map(i => {
+      const keys = Object.keys(i);
+      const newObject = {};
+      for (const key of keys) {
+        const value = i[key];
+        const newKey = _.camelCase(key);
+        newObject[newKey] = value;
+      }
+      return newObject;
+    });
     return { data, total };
 
   }

+ 25 - 0
app/z_router/apply.js

@@ -0,0 +1,25 @@
+'use strict';
+// 路由配置
+const routes = [
+  { method: 'get', path: '/apply', controller: 'apply.index', 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: '修改绩效申请' },
+  { method: 'delete', path: '/apply/:id', controller: 'apply.destroy', name: 'applyDelete', zh: '删除绩效申请' },
+];
+
+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);
+  }
+};

+ 28 - 0
app/z_router/template.js

@@ -0,0 +1,28 @@
+'use strict';
+// 路由配置
+const mainKey = 'template';
+const keyZh = '绩效模板';
+const routes = [
+  { method: 'get', path: `/${mainKey}`, controller: `${mainKey}.index`, name: `${mainKey}Query`, zh: `${keyZh}设置列表查询` },
+  { method: 'get', path: `/${mainKey}/:id`, controller: `${mainKey}.show`, name: `${mainKey}Fetch`, zh: `${keyZh}设置查询` },
+  { method: 'post', path: `/${mainKey}`, controller: `${mainKey}.create`, name: `${mainKey}Create`, zh: `创建${keyZh}设置` },
+  { method: 'post', path: `/${mainKey}/:id`, controller: `${mainKey}.update`, name: `${mainKey}Update`, zh: `修改${keyZh}` },
+  { method: 'delete', path: `/${mainKey}/:id`, controller: `${mainKey}.destroy`, name: `${mainKey}Delete`, zh: `删除${keyZh}` },
+  { method: 'post', path: `/${mainKey}/toUse/:id`, controller: `${mainKey}.toUse`, name: `${mainKey}toUse`, zh: `设置${keyZh}为使用` },
+];
+
+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);
+  }
+};

二進制
中央对地方共同财政事权转移支付区域绩效目标表2022-定稿.xls


二進制
绩效目标申报表说明.doc