Преглед на файлове

添加机构菜单,添加机构网关配置,修改机构绑定、解绑

asd123a20 преди 3 години
родител
ревизия
75982721b0

+ 5 - 5
service-gateway/app/controller/home.js

@@ -54,11 +54,11 @@ class HomeController extends Controller {
     result = '成功';
     // 错误异常处理(返回值)
     // 异常抛出检测
-    if (res.status === 500) {
-      msg = { errcode: -1002, errmsg: '系统错误', details: '未知错误类型' };
-      details = {};
-      result = '失败';
-    }
+    // if (res.status === 500) {
+    //   msg = { errcode: -1002, errmsg: '系统错误', details: '未知错误类型' };
+    //   details = {};
+    //   result = '失败';
+    // }
     // 缺少字段检测返回asser
     if (res.status === 500 && res.data.name === 'AssertionError') {
       msg = { errcode: -1002, errmsg: res.data.message, data: '' };

+ 54 - 0
service-gateway/config/org.js

@@ -0,0 +1,54 @@
+'use strict';
+
+module.exports = [
+  // 机构
+  {
+    url: '/api/org/org/create',
+    jwt: true,
+    issuer: [ 'naf' ],
+    log: true,
+  },
+  {
+    url: '/api/org/org/update',
+    jwt: true,
+    issuer: [ 'naf' ],
+    log: true,
+  },
+  {
+    url: '/api/org/org/delete/:id',
+    jwt: true,
+    issuer: [ 'naf' ],
+    log: true,
+  },
+  {
+    url: '/api/org/org/query',
+    jwt: false,
+    issuer: [ 'naf' ],
+    log: false,
+  },
+  // 绑定关系
+  {
+    url: '/api/org/orgbind/create',
+    jwt: true,
+    issuer: [ 'naf' ],
+    log: true,
+  },
+  {
+    url: '/api/org/orgbind/update',
+    jwt: true,
+    issuer: [ 'naf' ],
+    log: true,
+  },
+  {
+    url: '/api/org/orgbind/delete/:id',
+    jwt: true,
+    issuer: [ 'naf' ],
+    log: true,
+  },
+  {
+    url: '/api/org/orgbind/query',
+    jwt: false,
+    issuer: [ 'naf' ],
+    log: false,
+  },
+];

+ 9 - 0
service-naf/config/menu.js

@@ -157,5 +157,14 @@ const data = [
     parentCode: null,
     icon: 'el-icon-star-on',
   },
+  // 机构管理
+  {
+    module: 'org',
+    path: '/org/home',
+    title: '机构管理',
+    code: 'orgHome',
+    parentCode: null,
+    icon: 'el-icon-star-on',
+  },
 ];
 module.exports.data = data;

+ 1 - 1
service-org/app/controller/orgbind.js

@@ -11,7 +11,7 @@ class OrgbindController extends Controller {
     this.ctx.body = res;
   }
   async delete() {
-    const res = await this.ctx.service.orgbind.delete(this.ctx.params);
+    const res = await this.ctx.service.orgbind.delete(this.ctx.request.body);
     this.ctx.body = res;
   }
   async query() {

+ 1 - 1
service-org/app/router.js

@@ -13,6 +13,6 @@ module.exports = app => {
   // 绑定
   router.post('/api/org/orgbind/create', controller.orgbind.create);
   router.post('/api/org/orgbind/update', controller.orgbind.update);
-  router.delete('/api/org/orgbind/delete/:id', controller.orgbind.delete);
+  router.post('/api/org/orgbind/delete', controller.orgbind.delete);
   router.get('/api/org/orgbind/query', controller.orgbind.query);
 };

+ 16 - 7
service-org/app/service/orgbind.js

@@ -7,11 +7,16 @@ class OrgbindService extends Service {
     super(ctx);
     this.model = this.ctx.model.Orgbind;
   }
-  async create({ source, target }) {
+  async create({ source, ids = [] }) {
     assert(source, 'source不存在');
-    assert(target, 'target不存在');
+    assert(ids, 'ids不存在');
     try {
-      const res = await this.model.create({ source, target });
+      const res = await Promise.all(
+        ids.filter(async e => {
+          const info = await this.model.findOne({ source, target: e });
+          if (!info) await this.model.create({ source, target: e });
+        })
+      );
       return { errcode: 0, errmsg: 'ok', data: res };
     } catch (error) {
       throw error;
@@ -26,11 +31,15 @@ class OrgbindService extends Service {
       throw error;
     }
   }
-  async delete({ id }) {
-    assert(id, 'id不存在');
+  async delete({ source, ids = [] }) {
+    assert(ids, 'ids不存在');
     try {
-      await this.model.deleteOne({ _id: id });
-      return { errcode: 0, errmsg: 'ok', data: '' };
+      const res = await Promise.all(
+        ids.filter(async e => {
+          await this.model.deleteOne({ source, target: e });
+        })
+      );
+      return { errcode: 0, errmsg: 'ok', data: res };
     } catch (error) {
       throw error;
     }