reloaded пре 5 година
родитељ
комит
0a53c717d6

+ 40 - 0
app/controller/.festival.js

@@ -0,0 +1,40 @@
+module.exports = {
+  create: {
+    requestBody: [
+      '!year',
+      'festivals'
+    ]
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete'
+  },
+  update: {
+    params: ['!id'],
+    requestBody: [
+      'year',
+      'festivals'
+    ]
+  },
+  show: {
+    parameters: {
+      params: ['!id']
+    },
+    service: 'fetch'
+  },
+  index: {
+    parameters: {
+      query: {
+        year:'year',
+        festivals :'festivals'
+      }
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true
+    }
+  },
+};

+ 46 - 0
app/controller/.lesson.js

@@ -0,0 +1,46 @@
+module.exports = {
+  create: {
+    requestBody: [
+      '!class',
+      '!term',
+      '!batch',
+      'lessons'
+    ]
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete'
+  },
+  update: {
+    params: ['!id'],
+    requestBody: [
+      'class',
+      'term',
+      'batch',
+      'lessons'
+    ]
+  },
+  show: {
+    parameters: {
+      params: ['!id']
+    },
+    service: 'fetch'
+  },
+  index: {
+    parameters: {
+      query: {
+        class :'class',
+        term:'term',
+        batch :'batch',
+        lessons :'lessons'
+      }
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true
+    }
+  },
+};

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

@@ -21,6 +21,7 @@ module.exports = {
       'term',
       'batch',
       'class',
+      'bedroomid',
       'is_fine'
     ]
   },
@@ -51,6 +52,7 @@ module.exports = {
       'term',
       'batch',
       'class',
+      'bedroomid',
       'is_fine'
     ]
   },
@@ -83,6 +85,7 @@ module.exports = {
         term :'term',
         batch :'batch',
         class :'class',
+        bedroomid : 'bedroomid',
         is_fine:'is_fine'
       }
     },

+ 46 - 0
app/controller/.trainplan.js

@@ -0,0 +1,46 @@
+module.exports = {
+  create: {
+    requestBody: [
+      '!year',
+      '!title',
+      'status',
+      'termnum'
+    ]
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete'
+  },
+  update: {
+    params: ['!id'],
+    requestBody: [
+      'year',
+      'title',
+      'status',
+      'termnum'
+    ]
+  },
+  show: {
+    parameters: {
+      params: ['!id']
+    },
+    service: 'fetch'
+  },
+  index: {
+    parameters: {
+      query: {
+        year :'year',
+        title :'title',
+        status :'status',
+        termnum :'termnum'
+      }
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true
+    }
+  },
+};

+ 1 - 1
app/controller/bedroom.js

@@ -5,7 +5,7 @@ const meta = require('./.bedroom.js');
 const Controller = require('egg').Controller;
 const { CrudController } = require('naf-framework-mongoose/lib/controller');
 
-// 科目管理
+// 寝室管理
 class BedroomController extends Controller {
 
   constructor(ctx) {

+ 1 - 1
app/controller/class.js

@@ -5,7 +5,7 @@ const meta = require('./.class.js');
 const Controller = require('egg').Controller;
 const { CrudController } = require('naf-framework-mongoose/lib/controller');
 
-// 科目管理
+// 班级管理
 class ClassController extends Controller {
 
   constructor(ctx) {

+ 1 - 1
app/controller/department.js

@@ -5,7 +5,7 @@ const meta = require('./.department.js');
 const Controller = require('egg').Controller;
 const { CrudController } = require('naf-framework-mongoose/lib/controller');
 
-// 科目管理
+// 部门管理
 class DepartmentController extends Controller {
 
   constructor(ctx) {

+ 18 - 0
app/controller/festival.js

@@ -0,0 +1,18 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.festival.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 节假日管理
+class FestivalController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.festival;
+  }
+
+}
+
+module.exports = CrudController(FestivalController, meta);

+ 19 - 0
app/controller/lesson.js

@@ -0,0 +1,19 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.lesson.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 课程表管理
+class LessonController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.lesson;
+  }
+
+
+}
+
+module.exports = CrudController(LessonController, meta);

+ 1 - 1
app/controller/location.js

@@ -5,7 +5,7 @@ const meta = require('./.location.js');
 const Controller = require('egg').Controller;
 const { CrudController } = require('naf-framework-mongoose/lib/controller');
 
-// 科目管理
+// 位置管理
 class LocationController extends Controller {
 
   constructor(ctx) {

+ 3 - 2
app/controller/question.js

@@ -33,12 +33,13 @@ class QusetionController extends Controller {
     await this.service.update(this.ctx.params, this.ctx.request.body);
     this.ctx.ok({ msg: 'accepted' });
   }
-  
+
   // GET
   // 查询
   async query() {
     const res = await this.service.query(this.ctx.query);
-    this.ctx.ok({ msg: 'queried', data: res });
+    console.log(res);
+    this.ctx.ok({ ...res });
   }
 
   // GET

+ 1 - 1
app/controller/task.js

@@ -4,7 +4,7 @@ const _ = require('lodash');
 const Controller = require('egg').Controller;
 const { CrudController } = require('naf-framework-mongoose/lib/controller');
 
-// 科目管理
+// 作业管理
 class TaskController extends Controller {
 
   constructor(ctx) {

+ 1 - 1
app/controller/teacher.js

@@ -4,7 +4,7 @@ const _ = require('lodash');
 const Controller = require('egg').Controller;
 const { CrudController } = require('naf-framework-mongoose/lib/controller');
 
-// 科目管理
+// 老师管理
 class TeacherController extends Controller {
 
   constructor(ctx) {

+ 19 - 0
app/controller/trainplan.js

@@ -0,0 +1,19 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.trainplan.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 科目管理
+class TrainplanController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.trainplan;
+  }
+
+
+}
+
+module.exports = CrudController(TrainplanController, meta);

+ 2 - 0
app/model/class.js

@@ -7,6 +7,8 @@ const ClassSchema = {
   name: { type: String, required: true, maxLength: 500 }, // 班级名称
   number: { type: String, required: false, maxLength: 200 }, // 人数
   batch: { type: String, required: false, maxLength: 200 }, // 批次
+  term: { type: String, required: false, maxLength: 200 }, // 期
+  headteacherid: { type: String, required: false, maxLength: 200 }, // 班主任id
 };
 
 

+ 26 - 0
app/model/festival.js

@@ -0,0 +1,26 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 节假日信息表
+const festivalInfo = new Schema({
+  begindate: { type: String, required: false, maxLength: 200 }, // 开始日期
+  finishdate: { type: String, required: false, maxLength: 200 }, // 结束日期
+  name: { type: String, required: false, maxLength: 200 }, // 名称
+});
+
+// 节假日表
+const FestivalSchema = {
+  year: { type: String, required: true, maxLength: 200 }, // 年份
+  festivals: { type: [ festivalInfo ], select: true }, // 期
+};
+
+
+const schema = new Schema(FestivalSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Festival', schema, 'festival');
+};

+ 27 - 0
app/model/lesson.js

@@ -0,0 +1,27 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 课程信息表
+const lessonInfo = new Schema({
+  name: { type: String, required: false, maxLength: 500 }, // 名称
+  teacherid: { type: String, required: false, maxLength: 500 }, // 教师id
+  date: { type: String, required: false, maxLength: 500 }, // 日期
+});
+
+// 课程表
+const LessonSchema = {
+  class: { type: String, required: true, maxLength: 500 }, // 班级
+  term: { type: String, required: true, maxLength: 500 }, // 期
+  batch: { type: String, required: true, maxLength: 500 }, // 批次
+  lessons: { type: [ lessonInfo ], select: true }, // 课程信息
+};
+
+const schema = new Schema(LessonSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Lesson', schema, 'lesson');
+};

+ 1 - 0
app/model/student.js

@@ -24,6 +24,7 @@ const StudentSchema = {
   term: { type: String, required: false, maxLength: 200 }, // 期
   batch: { type: String, required: false, maxLength: 200 }, // 批次
   class: { type: String, required: false, maxLength: 200 }, // 班级
+  bedroomid: { type: String, required: false, maxLength: 200 }, // 寝室id
   is_fine: { type: String, required: false, maxLength: 200 }, // 是否优秀,0-否,1-是
 }
   ;

+ 0 - 1
app/model/subject.js

@@ -1,7 +1,6 @@
 'use strict';
 const Schema = require('mongoose').Schema;
 const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
-const { Secret } = require('naf-framework-mongoose/lib/model/schema');
 
 // 科目表
 const SubjectSchema = {

+ 39 - 0
app/model/trainplan.js

@@ -0,0 +1,39 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 批次信息表
+const batchInfo = new Schema({
+  batch: { type: String, required: false, maxLength: 200 }, // 批次
+  class: { type: String, required: false, maxLength: 200 }, // 班级数
+  begindate: { type: String, required: false, maxLength: 200 }, // 开始日期
+  finishdate: { type: String, required: false, maxLength: 200 }, // 结束日期
+  type: { type: String, required: false, maxLength: 200 }, // 类型:0-正常,1-特殊
+  name: { type: String, required: false, maxLength: 200 }, // 名称
+  number: { type: String, required: false, maxLength: 200 }, // 人数
+});
+
+// 期信息表
+const termInfo = new Schema({
+  term: { type: String, required: false, maxLength: 200 }, // 期数
+  classnum: { type: String, required: false, maxLength: 200 }, // 班级数
+  batchnum: { type: [ batchInfo ], select: true }, // 批
+});
+
+// 培训计划表
+const TrainplanSchema = {
+  year: { type: String, required: true, maxLength: 200 }, // 年份
+  title: { type: String, required: true, maxLength: 500 }, // 标题
+  status: { type: String, required: false, maxLength: 200 }, // 状态,0-筹备中,1-发布,2-结束
+  termnum: { type: [ termInfo ], select: true }, // 期
+};
+
+
+const schema = new Schema(TrainplanSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Trainplan', schema, 'trainplan');
+};

+ 12 - 0
app/router.js

@@ -62,4 +62,16 @@ module.exports = app => {
   // 位置表设置路由
   router.resources('location', '/api/location', controller.location); // index、create、show、destroy
   router.post('location', '/api/location/update/:id', controller.location.update);
+
+  // 培训计划表设置路由
+  router.resources('trainplan', '/api/trainplan', controller.trainplan); // index、create、show、destroy
+  router.post('trainplan', '/api/trainplan/update/:id', controller.trainplan.update);
+
+  // 节假日表设置路由
+  router.resources('festival', '/api/festival', controller.festival); // index、create、show、destroy
+  router.post('festival', '/api/festival/update/:id', controller.festival.update);
+
+  // 课程表设置路由
+  router.resources('lesson', '/api/lesson', controller.lesson); // index、create、show、destroy
+  router.post('lesson', '/api/lesson/update/:id', controller.lesson.update);
 };

+ 18 - 0
app/service/festival.js

@@ -0,0 +1,18 @@
+'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 FestivalService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'festival');
+    this.model = this.ctx.model.Festival;
+  }
+
+}
+
+module.exports = FestivalService;

+ 18 - 0
app/service/lesson.js

@@ -0,0 +1,18 @@
+'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 LessonService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'lesson');
+    this.model = this.ctx.model.Lesson;
+  }
+
+}
+
+module.exports = LessonService;

+ 4 - 1
app/service/question.js

@@ -48,7 +48,10 @@ class QuestionService extends CrudService {
 
   // 查询
   async query({ skip, limit, ...num }) {
-    return await this.model.find(num).skip(Number(skip)).limit(Number(limit));
+    const total = await (await this.model.find(num)).length;
+    const data = await this.model.find(num).skip(Number(skip)).limit(Number(limit));
+    const result = { total, data };
+    return result;
   }
 
   // 查询详情

+ 18 - 0
app/service/trainplan.js

@@ -0,0 +1,18 @@
+'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 TrainplanService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'trainplan');
+    this.model = this.ctx.model.Trainplan;
+  }
+
+}
+
+module.exports = TrainplanService;