lrf402788946 4 年之前
父节点
当前提交
4da224b792
共有 4 个文件被更改,包括 24 次插入1 次删除
  1. 6 1
      app/controller/system/dictionary.js
  2. 2 0
      app/router/system.js
  3. 11 0
      app/service/system/dictionary.js
  4. 5 0
      config/config.local.js

+ 6 - 1
app/controller/system/dictionary.js

@@ -1,6 +1,6 @@
 'use strict';
 
-// const _ = require('lodash');
+const _ = require('lodash');
 const meta = require('./.dictionary.js');
 const Controller = require('egg').Controller;
 const { CrudController } = require('naf-framework-mongoose/lib/controller');
@@ -11,6 +11,11 @@ class DictionaryController extends Controller {
     super(ctx);
     this.service = this.ctx.service.system.dictionary;
   }
+
+  async xzqh() {
+    const data = await this.service.xzqh(this.ctx.query);
+    this.ctx.ok({ data });
+  }
 }
 
 module.exports = CrudController(DictionaryController, meta);

+ 2 - 0
app/router/system.js

@@ -6,6 +6,8 @@ module.exports = app => {
   const prefix = '/api/servicezhwl';
   const index = 'system';
   const { router, controller } = app;
+  // xzqh行政区划
+  router.get(`${prefix}/dictionary/xzqh`, controller[index].dictionary.xzqh);
   router.get(`${prefix}/dictionary/tree`, controller[index].dictionary.tree);
   router.resources('dictionary', `${prefix}/dictionary`, controller[index].dictionary); // index、create、show、destroy
   router.post('dictionary', `${prefix}/dictionary/update/:id`, controller[index].dictionary.update);

+ 11 - 0
app/service/system/dictionary.js

@@ -17,6 +17,17 @@ class DictionaryService extends CrudService {
   //   return await this.model.find({ _id: ObjectId(id) });
   // }
 
+  async xzqh({ pid }) {
+    const query = {};
+    const first = await this.model.findOne({ categroy: 'xzqh' });
+    if (!first) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到行政区划(地区)字典内容,请确认字典表中是否有代码为"xzqh"的主目录字典');
+    const { _id } = first;
+    if (pid) query.pid = pid;
+    else query.pid = _id;
+    const res = await this.model.find(query);
+    return res;
+  }
+
   async delete({ id }) {
     let children = await this.dbFindChildren(id);
     children = children.map(i => ObjectId(i._id));

+ 5 - 0
config/config.local.js

@@ -2,6 +2,11 @@
 
 module.exports = () => {
   const config = (exports = {});
+  config.cluster = {
+    listen: {
+      port: 7002,
+    },
+  };
 
   config.logger = {
     level: 'DEBUG',