lrf402788946 4 yıl önce
ebeveyn
işleme
139498785b

+ 83 - 0
app/controller/.achieve_apply.js

@@ -0,0 +1,83 @@
+module.exports = {
+  create: {
+    requestBody: ["basic", "brief", "research", "datalist"],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: ["basic", "brief", "research", "datalist"],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        "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,
+    },
+  },
+  getOne: {
+    parameters: {
+      query: {
+        basic_id: "basic._id",
+        brief_id: "brief._id",
+        research_id: "research._id",
+        datalist_id: "datalist._id",
+      },
+    },
+    service: "getOne",
+  },
+
+  researchCreate: {
+    params: ["!id"],
+    requestBody: [
+      "research_name",
+      "card",
+      "gender",
+      "position",
+      "education",
+      "degree",
+      "abroad",
+      "research_company",
+      "devote",
+    ],
+    service: "researchCreate",
+  },
+  researchUpdate: {
+    params: ["!id", "!research_id"],
+    requestBody: [
+      "research_name",
+      "card",
+      "gender",
+      "position",
+      "education",
+      "degree",
+      "abroad",
+      "research_company",
+      "devote",
+    ],
+    service: "researchUpdate",
+  },
+  researchDelete: {
+    params: ["!id", "!research_id"],
+    service: "researchDelete",
+  },
+};

+ 13 - 0
app/controller/achieve_apply.js

@@ -0,0 +1,13 @@
+'use strict';
+const meta = require('./.achieve_apply.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 成果评价申请
+class Achieve_applyController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.achieveApply;
+  }
+}
+module.exports = CrudController(Achieve_applyController, meta);

+ 0 - 1
app/model/achieve_apply.js

@@ -29,7 +29,6 @@ const brief = new Schema({
   achieve_brief: { type: String }, // 成果简介
   field: { type: String }, // 应用领域和技术原理
   kpi_index: { type: String }, // 性能指标
-  revenue: { type: String }, // 经济效益税收
   compare: { type: String }, // 与国内外同类技术比较
   advanced: { type: String }, // 成果的创造性,先进性
   sense: { type: String }, // 作用意义

+ 1 - 0
app/router.js

@@ -6,4 +6,5 @@
 module.exports = app => {
   const { router, controller } = app;
   router.get('/', controller.home.index);
+  require('./router/achieve_apply')(app); // 成果评价申请
 };

+ 15 - 0
app/router/achieve_apply.js

@@ -0,0 +1,15 @@
+'use strict';
+
+
+module.exports = app => {
+  const { router, controller } = app;
+  const profix = '/api/achieve/';
+  const vision = 'v0';
+  const target = 'achieveApply';
+  router.get(target, `${profix}${vision}/${target}/get`, controller[target].getOne);
+  router.post(target, `${profix}${vision}/${target}/:id/research`, controller[target].researchCreate);
+  router.post(target, `${profix}${vision}/${target}/:id/research/:research_id`, controller[target].researchUpdate);
+  router.delete(target, `${profix}${vision}/${target}/:id/research/:research_id`, controller[target].researchDelete);
+  router.resources(target, `${profix}${vision}/${target}`, controller[target]); // index、create、show、destroy
+  router.post(target, `${profix}${vision}/${target}/update/:id`, controller[target].update);
+};

+ 49 - 0
app/service/achieve_apply.js

@@ -0,0 +1,49 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const _ = require('lodash');
+const assert = require('assert');
+const { ObjectId } = require('mongoose').Types;
+
+// 成果评价申请
+class Achieve_applyService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'achieve_apply');
+    this.model = this.ctx.model.AchieveApply;
+  }
+
+  async getOne(query) {
+    const keys = Object.keys(query);
+    if (keys.length <= 0) throw new BusinessError(ErrorCode.BADPARAM, '缺少参数');
+    const res = await this.model.findOne(query);
+    return res;
+  }
+
+  async researchCreate({ id }, body) {
+    const res = await this.model.findById(id);
+    if (!res) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到成果评价申请数据');
+    res.research.push(body);
+    await res.save();
+    return;
+  }
+  async researchUpdate({ id, research_id }, body) {
+    const res = await this.model.findById(id);
+    if (!res) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到成果评价申请数据');
+    const person = res.research.id(research_id);
+    if (!person) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到该申请下指定的主研人员');
+    const keys = Object.keys(body);
+    for (const key of keys) {
+      person[key] = body[key];
+    }
+    await res.save();
+  }
+
+  async researchDelete({ id, research_id }) {
+    const res = await this.model.findById(id);
+    if (!res) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到成果评价申请数据');
+    res.research.remove(research_id);
+    await res.save();
+  }
+}
+
+module.exports = Achieve_applyService;

+ 2 - 2
config/config.default.js

@@ -24,11 +24,11 @@ module.exports = appInfo => {
   };
   config.cluster = {
     listen: {
-      port: 9102,
+      port: 9103,
     },
   };
 
-  config.dbName = 'platform';
+  config.dbName = 'new-platform';
   config.mongoose = {
     url: `mongodb://localhost:27017/${config.dbName}`,
     options: {