lrf402788946 4 years ago
parent
commit
9212f4ee85

+ 2 - 1
README.md

@@ -1,5 +1,6 @@
-# serveci-center
+# servec-zhwl
 
+此项目没有修改框架,所以model部分如果使用子目录,会引发错误,controller和service,router使用子目录不会产生bug
 
 
 ## QuickStart

+ 3 - 0
app/controller/.zhwldriver.js

@@ -10,6 +10,7 @@ module.exports = {
       "ccu_time",
       "cc_time",
       "qc_time",
+      "status",
     ],
   },
   destroy: {
@@ -28,6 +29,7 @@ module.exports = {
       "ccu_time",
       "cc_time",
       "qc_time",
+      "status",
     ],
   },
   show: {
@@ -43,6 +45,7 @@ module.exports = {
         tel: "tel",
         id_card: "id_card",
         drive_card: "drive_card",
+        status: "status",
       },
     },
     service: "query",

+ 4 - 4
app/controller/zhwldriver.js

@@ -1,16 +1,16 @@
 'use strict';
 
 // const _ = require('lodash');
-const meta = require('./.zhwldriver.js');
+const meta = require('./.driver.js');
 const Controller = require('egg').Controller;
 const { CrudController } = require('naf-framework-mongoose/lib/controller');
 
 // 司机表
-class ZhwldriverController extends Controller {
+class DriverController extends Controller {
   constructor(ctx) {
     super(ctx);
-    this.service = this.ctx.service.zhwldriver;
+    this.service = this.ctx.service.personnel.driver;
   }
 }
 
-module.exports = CrudController(ZhwldriverController, meta);
+module.exports = CrudController(DriverController, meta);

+ 22 - 0
app/controller/util.js

@@ -0,0 +1,22 @@
+'use strict';
+
+const Controller = require('egg').Controller;
+
+// 教师申请讲课表管理
+class UtilController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.util;
+  }
+  async findModel() {
+    const data = await this.service.findModel(this.ctx.params);
+    this.ctx.ok({ data });
+  }
+
+  async utilMethod() {
+    await this.service.utilMethod(this.ctx.query, this.ctx.request.body);
+    this.ctx.ok();
+  }
+}
+
+module.exports = UtilController;

+ 26 - 0
app/model/driver.js

@@ -0,0 +1,26 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+// 司机表
+const Driverchema = {
+  name: { type: String, required: true, maxLength: 200, field: { required: true, label: '姓名', filter: true } }, // 姓名
+  tel: { type: String, required: true, maxLength: 200, field: { required: true, label: '联系电话', filter: true } }, // 电话/固定电话
+  id_card: { type: Number, required: true, maxLength: 200, field: { required: true, label: '身份证', filter: true, options: { maxLength: 18, minLength: 18 } } }, // 身份证
+  drive_card: { type: String, required: true, maxLength: 200, field: { required: true, label: '驾驶证号' } }, // 驾驶证号
+  fhc_time: { type: String, required: false, maxLength: 200, field: { label: '初次领证时间', type: 'date', notable: true } }, // 初次领证时间=年月日
+  car_type: { type: String, required: false, maxLength: 200, field: { label: '准驾车型', notable: true } }, // 准驾车型
+  ccu_time: { type: String, required: false, maxLength: 200, field: { required: true, label: '驾驶证有效日期', notable: true, type: 'date' } }, // 驾驶证有效日期
+  cc_time: { type: String, required: false, maxLength: 200, field: { required: true, label: '驾驶证年检日期', notable: true, type: 'date' } }, // 驾驶证年检日期
+  qc_time: { type: String, required: false, maxLength: 200, field: { required: true, label: '资格证年检日期', notable: true, type: 'date' } }, // 资格证年检日期
+  status: { type: String, required: false, maxLength: 200, default: '在籍', field: { label: '状态', type: 'radio', list: [{ label: '在籍', value: '在籍' }, { label: '注销', value: '注销' }] } },
+};
+
+
+const schema = new Schema(Driverchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Diver', schema, 'driver');
+};

+ 0 - 25
app/model/zhwldriver.js

@@ -1,25 +0,0 @@
-'use strict';
-const Schema = require('mongoose').Schema;
-const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
-// 司机表
-const Zhwldriverchema = {
-  name: { type: String, required: true, maxLength: 200 }, // 姓名
-  tel: { type: String, required: true, maxLength: 200 }, // 电话/固定电话
-  id_card: { type: Number, required: true, maxLength: 200 }, // 身份证
-  drive_card: { type: String, required: true, maxLength: 200 }, // 驾驶证号
-  fhc_time: { type: String, required: false, maxLength: 200 }, // 初次领证时间=年月日
-  car_type: { type: String, required: false, maxLength: 200 }, // 准驾车型
-  ccu_time: { type: String, required: false, maxLength: 200 }, // 驾驶证有效日期
-  cc_time: { type: String, required: false, maxLength: 200 }, // 驾驶证年检日期
-  qc_time: { type: String, required: false, maxLength: 200 }, // 资格证年检日期
-};
-
-
-const schema = new Schema(Zhwldriverchema, { toJSON: { virtuals: true } });
-schema.index({ id: 1 });
-schema.plugin(metaPlugin);
-
-module.exports = app => {
-  const { mongoose } = app;
-  return mongoose.model('Zhwldriver', schema, 'zhwldriver');
-};

+ 4 - 3
app/router.js

@@ -5,13 +5,13 @@
  */
 module.exports = app => {
   const { router, controller } = app;
+  const prefix = '/api/servicezhwl';
+  router.get(`${prefix}/model/:model`, controller.util.findModel);
+  router.post(`${prefix}/util`, controller.util.utilMethod);
   // 測試
   router.resources('test', '/api/servicezhwl/test', controller.test); // index、create、show、destroy
   router.post('test', '/api/servicezhwl/test/update/:id', controller.test.update);
 
-  // 司机表
-  router.resources('zhwldriver', '/api/servicezhwl/zhwldriver', controller.zhwldriver); // index、create、show、destroy
-  router.post('zhwldriver', '/api/servicezhwl/zhwldriver/update/:id', controller.zhwldriver.update);
 
   // 车辆表
   router.resources('zhwlcar', '/api/servicezhwl/zhwlcar', controller.zhwlcar); // index、create、show、destroy
@@ -19,5 +19,6 @@ module.exports = app => {
 
   // 系统设置路由
   require('./router/system')(app);
+  require('./router/personnel')(app);
 
 };

+ 11 - 0
app/router/personnel.js

@@ -0,0 +1,11 @@
+'use strict';
+/**
+ * @param {Egg.Application} app - egg application
+ */
+module.exports = app => {
+  const prefix = '/api/servicezhwl';
+  const index = 'personnel';
+  const { router, controller } = app;
+  router.resources('driver', `${prefix}/driver`, controller[index].driver); // index、create、show、destroy
+  router.post('driver', `${prefix}/driver/update/:id`, controller[index].driver.update);
+};

+ 4 - 11
app/router/system.js

@@ -4,17 +4,10 @@
  */
 module.exports = app => {
   const prefix = '/api/servicezhwl';
+  const index = 'system';
   const { router, controller } = app;
-  router.get(`${prefix}/dictionary/tree`, controller.system.dictionary.tree);
-  router.resources(
-    'dictionary',
-    `${prefix}/dictionary`,
-    controller.system.dictionary
-  ); // index、create、show、destroy
-  router.post(
-    'dictionary',
-    `${prefix}/dictionary/update/:id`,
-    controller.system.dictionary.update
-  );
+  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);
 
 };

+ 4 - 4
app/service/zhwldriver.js

@@ -6,11 +6,11 @@ const { ObjectId } = require('mongoose').Types;
 const { CrudService } = require('naf-framework-mongoose/lib/service');
 const { ZhwldriverError, ErrorCode } = require('naf-core').Error;
 
-class ZhwldriverService extends CrudService {
+class DriverService extends CrudService {
   constructor(ctx) {
-    super(ctx, 'zhwldriver');
-    this.model = this.ctx.model.Zhwldriver;
+    super(ctx, 'driver');
+    this.model = this.ctx.model.Driver;
   }
 }
 
-module.exports = ZhwldriverService;
+module.exports = DriverService;

+ 33 - 0
app/service/util.js

@@ -0,0 +1,33 @@
+'use strict';
+const assert = require('assert');
+const _ = require('lodash');
+const { ObjectId } = require('mongoose').Types;
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+
+class UtilService extends CrudService {
+  constructor(ctx) {
+    super(ctx);
+    this.mq = this.ctx.mq;
+  }
+  async findModel({ model }) {
+    const _model = _.capitalize(model);
+    const data = this.ctx.model[_model].prototype.schema.obj;
+    const keys = Object.keys(data);
+    let res = [];
+    for (const k of keys) {
+      const field = _.get(data[k], 'field');
+      if (field && _.get(field, 'label')) {
+        field.model = k;
+        res.push(field);
+      }
+    }
+    res = _.orderBy(res, [ 'row' ], [ 'asc' ]);
+    return res;
+  }
+
+  async utilMethod() {
+    console.log('in function:');
+  }
+}
+module.exports = UtilService;