reloaded il y a 4 ans
Parent
commit
cd5bcfdef5
4 fichiers modifiés avec 62 ajouts et 33 suppressions
  1. 10 0
      app/controller/common.js
  2. 31 31
      app/model/student.js
  3. 4 0
      app/router.js
  4. 17 2
      app/service/util.js

+ 10 - 0
app/controller/common.js

@@ -17,6 +17,16 @@ class CommonController extends Controller {
     this.ctx.ok({ data });
   }
 
+  async findbyids() {
+    const data = await this.service.findbyids(this.ctx.params, this.ctx.request.body);
+    this.ctx.ok({ data });
+  }
+
+  async findbymodel() {
+    const data = await this.service.findmodel(this.ctx.request.query);
+    this.ctx.ok({ data });
+  }
+
   async findyear() {
     const url = 'http://v.juhe.cn/calendar/year?key=ed73fa73956ff995bad705d664002595&year=' + this.ctx.query.year;
     const res = await this.ctx.curl(url, {

+ 31 - 31
app/model/student.js

@@ -4,37 +4,37 @@ const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
 
 // 学生表
 const StudentSchema = {
-  name: { type: String, required: true, maxLength: 200 }, // 姓名
-  id_number: { type: String, required: true, maxLength: 200 }, // 身份证号
-  phone: { type: String, required: true, maxLength: 200 }, // 手机号
-  gender: { type: String, required: false, maxLength: 200 }, // 性别
-  nation: { type: String, required: false, maxLength: 200 }, // 民族
-  school_name: { type: String, required: false, maxLength: 200 }, // 学校名称
-  schid: { type: String, required: false, maxLength: 200 }, // 学校id
-  faculty: { type: String, required: false, maxLength: 200 }, // 院系
-  major: { type: String, required: false, maxLength: 200 }, // 专业
-  entry_year: { type: String, required: false, maxLength: 200 }, // 入学年份
-  finish_year: { type: String, required: false, maxLength: 200 }, // 毕业年份
-  school_job: { type: String, required: false, maxLength: 200 }, // 在校担任何种职务
-  qq: { type: String, required: false, maxLength: 200 }, // QQ号
-  email: { type: String, required: false, maxLength: 200 }, // 邮箱
-  openid: { type: String, required: false, maxLength: 200 }, // 微信openid
-  family_place: { type: String, required: false, maxLength: 200 }, // 家庭所在地
-  family_is_hard: { type: String, required: false, maxLength: 200 }, // 家庭是否困难,0-否,1-是
-  have_grant: { type: String, required: false, maxLength: 200 }, // 是否获得过助学金,0-否,1-是
-  job: { type: String, required: false, maxLength: 200, default: '普通学生' }, // 职务
-  planyearid: { type: String, required: false, maxLength: 200 }, // 大批次id
-  planid: { type: String, required: false, maxLength: 200 }, // 计划id
-  termid: { type: String, required: false, maxLength: 200 }, // 期id
-  batchid: { type: String, required: false, maxLength: 200 }, // 批次id
-  classid: { type: String, required: false, maxLength: 200 }, // 班级id
-  bedroomid: { type: String, required: false, maxLength: 200 }, // 寝室id
-  bedroom: { type: String, required: false, maxLength: 200 }, // 寝室号
-  is_fine: { type: String, required: false, maxLength: 200, default: '0' }, // 是否优秀,0-否,1-是,2-无资格
-  selfscore: { type: String, required: false, maxLength: 200 }, // 个人分
-  score: { type: String, required: false, maxLength: 200 }, // 总分
-}
-  ;
+  name: { type: String, required: true, maxLength: 200, zh: '姓名' }, // 姓名
+  id_number: { type: String, required: true, maxLength: 200, zh: '身份证号' }, // 身份证号
+  phone: { type: String, required: true, maxLength: 200, zh: '手机号' }, // 手机号
+  gender: { type: String, required: false, maxLength: 200, zh: '性别' }, // 性别
+  nation: { type: String, required: false, maxLength: 200, zh: '民族' }, // 民族
+  school_name: { type: String, required: false, maxLength: 200, zh: '学校名称' }, // 学校名称
+  schid: { type: String, required: false, maxLength: 200, zh: '学校id' }, // 学校id
+  faculty: { type: String, required: false, maxLength: 200, zh: '院系' }, // 院系
+  major: { type: String, required: false, maxLength: 200, zh: '专业' }, // 专业
+  entry_year: { type: String, required: false, maxLength: 200, zh: '入学年份' }, // 入学年份
+  finish_year: { type: String, required: false, maxLength: 200, zh: '毕业年份' }, // 毕业年份
+  school_job: { type: String, required: false, maxLength: 200, zh: '在校担任何种职务' }, // 在校担任何种职务
+  qq: { type: String, required: false, maxLength: 200, zh: 'QQ号' }, // QQ号
+  email: { type: String, required: false, maxLength: 200, zh: '邮箱' }, // 邮箱
+  openid: { type: String, required: false, maxLength: 200, zh: '微信openid' }, // 微信openid
+  family_place: { type: String, required: false, maxLength: 200, zh: '家庭所在地' }, // 家庭所在地
+  family_is_hard: { type: String, required: false, maxLength: 200, zh: '家庭是否困难' }, // 家庭是否困难,0-否,1-是
+  have_grant: { type: String, required: false, maxLength: 200, zh: '是否获得过助学金' }, // 是否获得过助学金,0-否,1-是
+  job: { type: String, required: false, maxLength: 200, default: '普通学生', zh: '职务' }, // 职务
+  planyearid: { type: String, required: false, maxLength: 200, zh: '大批次id' }, // 大批次id
+  planid: { type: String, required: false, maxLength: 200, zh: '计划id' }, // 计划id
+  termid: { type: String, required: false, maxLength: 200, zh: '期id' }, // 期id
+  batchid: { type: String, required: false, maxLength: 200, zh: '批次id' }, // 批次id
+  classid: { type: String, required: false, maxLength: 200, zh: '班级id' }, // 班级id
+  bedroomid: { type: String, required: false, maxLength: 200, zh: '寝室id' }, // 寝室id
+  bedroom: { type: String, required: false, maxLength: 200, zh: '寝室号' }, // 寝室号
+  is_fine: { type: String, required: false, maxLength: 200, default: '0', zh: '是否优秀' }, // 是否优秀,0-否,1-是,2-无资格
+  selfscore: { type: String, required: false, maxLength: 200, zh: '个人分' }, // 个人分
+  score: { type: String, required: false, maxLength: 200, zh: '总分' }, // 总分
+};
+
 
 const schema = new Schema(StudentSchema, { toJSON: { virtuals: true } });
 schema.index({ id: 1 });

+ 4 - 0
app/router.js

@@ -8,6 +8,10 @@ module.exports = app => {
   router.get('/', controller.home.index);
   // 共通查询单条记录方法
   router.get('/api/train/common/findone/:modelname', controller.common.findone);
+  // 共通批量查询方法
+  router.post('/api/train/common/findbyids/:modelname', controller.common.findbyids);
+  // 共通查询表
+  router.get('/api/train/common/findbymodel', controller.common.findbymodel);
   router.get('/api/train/common/findyear', controller.common.findyear);
   // 基础设置表路由
   router.get('/api/train/setting/findone', controller.setting.findone);

+ 17 - 2
app/service/util.js

@@ -10,7 +10,6 @@ const moment = require('moment');
 const nodemailer = require('nodemailer');
 
 class UtilService extends CrudService {
-
   async updatedate() {
     let date = new Date();
     date = moment(date).format('YYYY-MM-DD HH:mm:ss');
@@ -32,7 +31,6 @@ class UtilService extends CrudService {
       auth: {
         user: user_email, // 账号
         pass: auth_code, // 授权码
-
       },
     });
     const mailOptions = {
@@ -57,6 +55,23 @@ class UtilService extends CrudService {
     const res = await this.ctx.model[_model].findOne({ ...data });
     return res;
   }
+
+  async findbyids({ modelname }, { data }) {
+    // 共通批量查询方法
+    const _model = _.capitalize(modelname);
+    const res = [];
+    for (const elm of data) {
+      const result = await this.ctx.model[_model].findById(elm);
+      res.push(result);
+    }
+    return res;
+  }
+
+  async findmodel({ modelname }) {
+    const _model = _.capitalize(modelname);
+    const data = this.ctx.model[_model].prototype.schema.obj;
+    return data;
+  }
 }
 
 module.exports = UtilService;