cheny 4 年 前
コミット
f33f6c0c05

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

@@ -6,6 +6,7 @@ module.exports = {
       'planid',
       'termid',
       'term',
+      'batchid',
       'filepath',
       'studs',
       'plannum',
@@ -28,6 +29,7 @@ module.exports = {
       'planid',
       'termid',
       'term',
+      'batchid',
       'filepath',
       'studs',
       'plannum',
@@ -52,6 +54,7 @@ module.exports = {
         planid: 'planid',
         termid: 'termid',
         term: 'term',
+        batchid: 'batchid',
         filepath: 'filepath',
         studs: 'studs',
         plannum: 'plannum',

+ 55 - 0
app/controller/.message.js

@@ -0,0 +1,55 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "openid",
+      "name",
+      "title",
+      "detail",
+      "date",
+      "remark",
+      "status",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "openid",
+      "name",
+      "title",
+      "detail",
+      "date",
+      "remark",
+      "status",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        openid:  "openid",
+        name: "name",
+        title: "title",
+        detail: "detail",
+        date: "date",
+        remark: "remark",
+        status: "status",
+      },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 3 - 3
app/controller/.teacher.js

@@ -5,7 +5,7 @@ module.exports = {
       '!phone',
       '!idnumber',
       '!gender',
-      '!zynumber',
+      // '!zynumber',
       '!zynumberfile',
       'schid',
       'schname',
@@ -47,7 +47,7 @@ module.exports = {
       'phone',
       'idnumber',
       'gender',
-      'zynumber',
+      // 'zynumber',
       'zynumberfile',
       'schid',
       'schname',
@@ -91,7 +91,7 @@ module.exports = {
         phone :'phone',
         idnumber :'idnumber',
         gender :'gender',
-        zynumber :'zynumber',
+        // zynumber :'zynumber',
         zynumberfile :'zynumberfile',
         schid :'schid',
         schname:'schname',

+ 16 - 0
app/controller/message.js

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

+ 28 - 10
app/controller/weixin.js

@@ -25,7 +25,7 @@ class WeixinController extends Controller {
   //       store - 默认,认证结果写入sessionStore,然后重定向回请求页面(要求请求页面和认证服务在同一域名下)
   //       token - url带上token参数重定向到原始地址
   async auth() {
-    const { redirect_uri, code, test, type, response_type = 'store', uid, qrcode } = this.ctx.query;
+    const { redirect_uri, code, test, type, response_type = 'store', uid, qrcode, msgid, objid } = this.ctx.query;
     if (test) {
       return await this.authTest();
     }
@@ -43,7 +43,7 @@ class WeixinController extends Controller {
     // TODO: 保存原始请求地址
     const state = uuid();
     const key = `visit:auth:state:${state}`;
-    const val = JSON.stringify({ redirect_uri, type, uid, qrcode });
+    const val = JSON.stringify({ redirect_uri, type, uid, qrcode, msgid, objid });
     await this.app.redis.set(key, val, 'EX', 600);
 
     // TODO: 生成回调地址
@@ -77,7 +77,7 @@ class WeixinController extends Controller {
     if (openid) {
       const key = `visit:auth:state:${state}`;
       const val = await this.app.redis.get(key);
-      const { redirect_uri, type, uid, qrcode } = JSON.parse(val);
+      const { redirect_uri, type, uid, qrcode, msgid, objid } = JSON.parse(val);
       console.log('redirect_uri-->' + redirect_uri);
       const user = await this.ctx.service.user.findByOpenid(openid);
       console.log('type-->' + type);
@@ -124,6 +124,12 @@ class WeixinController extends Controller {
         // TODO: 重定性页面
         console.log('22222---?' + to_uri);
         this.ctx.redirect(to_uri);
+      } else if (type === '9') {
+        // const token = await this.ctx.service.login.createJwt(user);
+        const to_uri = urljoin(redirect_uri, `?openid=${openid}&type=${type}&msgid=${msgid}&objid=${objid}`);
+        // TODO: 重定性页面
+        console.log('99999---?' + to_uri);
+        this.ctx.redirect(to_uri);
       }
     }
 
@@ -131,17 +137,18 @@ class WeixinController extends Controller {
 
   // GET 用户授权内部测试接口
   async authTest() {
-    const { redirect_uri, type, uid, qrcode, openid } = this.ctx.query;
+    const { redirect_uri, type, uid, qrcode, openid, msgid, objid } = this.ctx.query;
     // const openid = stringRandom();
     this.ctx.logger.debug(`[auth-test] reditect_uri - ${redirect_uri}, openid - ${openid}`);
     assert(redirect_uri, '回调地址不能为空');
     assert(openid, 'openid不能为空');
-
+    const user = await this.ctx.service.user.findByOpenid(openid);
     if (type === '0') {
       // 通过openid取得用户信息
-      const user = await this.ctx.service.user.findByOpenid(openid);
       if (user) {
         const token = await this.ctx.service.login.createJwt(user);
+        console.log('token-->' + token);
+        console.log('user.type-->' + user.type);
         if (user.type === '4') {
           const to_uri = urljoin(redirect_uri, `?token=${token}`);
           // TODO: 重定性页面
@@ -149,30 +156,41 @@ class WeixinController extends Controller {
           this.ctx.redirect(to_uri);
         } else if (user.type === '1') {
           const touri = `${this.app.config.baseUrl}/mobiledirtea`;
-          const to_uri = urljoin(redirect_uri, `?token=${token}`);
+          const to_uri = urljoin(touri, `?token=${token}`);
           // TODO: 重定性页面
           console.log('to_uri000-->' + to_uri);
           this.ctx.redirect(to_uri);
         } else if (user.type === '3') {
           const touri = `${this.app.config.baseUrl}/mobiledirtea`;
-          const to_uri = urljoin(redirect_uri, `?token=${token}`);
+          const to_uri = urljoin(touri, `?token=${token}`);
           // TODO: 重定性页面
           console.log('to_uri000-->' + to_uri);
           this.ctx.redirect(to_uri);
         }
+
       } else {
-        console.log('rrr--->' + redirect_uri);
-        const to_uri = urljoin(redirect_uri, `?openid=${openid}`);
+        console.log('rrr0000--->' + redirect_uri);
+        const resunionid = await weixin.fetchUnionID(openid);
+        const touri = `${this.app.config.baseUrl}/student/bind`;
+        const to_uri = urljoin(touri, `?openid=${openid}&unionid=${resunionid.unionid}`);
         // TODO: 重定性页面
         this.ctx.redirect(to_uri);
       }
     } else if (type === '1') {
       const to_uri = urljoin(redirect_uri, `?openid=${openid}&uid=${uid}&type=${type}&qrcode=${qrcode}`);
       // TODO: 重定性页面
+      console.log('1111---?' + to_uri);
       this.ctx.redirect(to_uri);
     } else if (type === '2') {
       const to_uri = urljoin(redirect_uri, `?openid=${openid}&type=${type}&qrcode=${qrcode}`);
       // TODO: 重定性页面
+      console.log('22222---?' + to_uri);
+      this.ctx.redirect(to_uri);
+    } else if (type === '9') {
+      // const token = await this.ctx.service.login.createJwt(user);
+      const to_uri = urljoin(redirect_uri, `?openid=${openid}&type=${type}&msgid=${msgid}&objid=${objid}`);
+      // TODO: 重定性页面
+      console.log('99999---?' + to_uri);
       this.ctx.redirect(to_uri);
     }
   }

+ 1 - 0
app/model/job.js

@@ -9,6 +9,7 @@ const JobSchema = {
   planid: { type: String, required: false, maxLength: 200 }, // 计划id
   termid: { type: String, required: false, maxLength: 200 }, // 期id
   term: { type: String, required: false, maxLength: 500 }, // 期名称
+  batchid: { type: String, required: false, maxLength: 200 }, // 批次id
   filepath: { type: String, required: false, maxLength: 500 }, // 文件地址
   studs: { type: String, required: false }, // 学生数据
   plannum: { type: String, required: false, maxLength: 20 }, // 计划人数

+ 1 - 1
app/model/location.js

@@ -6,7 +6,7 @@ const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
 const LocationSchema = {
   name: { type: String, required: true, maxLength: 500 }, // 名称
   type: { type: String, required: true, maxLength: 10 }, // 0、教室位置 1、开班仪式地点 2、拓展计划地点 3、用餐地点
-  ibeacon: { type: String, required: true, maxLength: 500 }, // 蓝牙设备号
+  ibeacon: { type: String, required: false, maxLength: 500 }, // 蓝牙设备号
 };
 
 

+ 24 - 0
app/model/message.js

@@ -0,0 +1,24 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 消息表
+const MessageSchema = {
+  openid: { type: String, required: false, maxLength: 200 }, // openid
+  name: { type: String, required: false, maxLength: 200 }, // openid
+  title: { type: String, required: false, maxLength: 200 }, // 标题
+  detail: { type: String, required: false, maxLength: 200 }, // 详细
+  date: { type: String, required: false, maxLength: 200 }, // 时间
+  remark: { type: String, required: false, maxLength: 200 }, // 备注
+  status: { type: String, required: false, default: '0' }, // 状态 0、未读 1、已读
+};
+
+
+const schema = new Schema(MessageSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Message', schema, 'message');
+};

+ 1 - 1
app/model/teacher.js

@@ -42,7 +42,7 @@ const TeacherSchema = {
   phone: { type: String, required: true, maxLength: 200 }, // 手机号
   idnumber: { type: String, required: true, maxLength: 200 }, // 身份证号
   gender: { type: String, required: true, maxLength: 200 }, // 教师性别
-  zynumber: { type: String, required: true, maxLength: 200 }, // 职业资格证号
+  // zynumber: { type: String, required: false, maxLength: 200 }, // 职业资格证号
   zynumberfile: { type: [ zynumberfileInfo ], select: true }, // 职业资格证图片
   schid: { type: String, required: false, maxLength: 200 }, // 学校id
   schname: { type: String, required: false, maxLength: 200 }, // 学校名称

+ 4 - 0
app/router.js

@@ -489,4 +489,8 @@ module.exports = app => {
   // 学校上传任务表设置路由
   router.resources('job', '/api/train/job', controller.job); // index、create、show、destroy
   router.post('job', '/api/train/job/update/:id', controller.job.update);
+
+  // 消息表设置路由
+  router.resources('message', '/api/train/message', controller.message); // index、create、show、destroy
+  router.post('message', '/api/train/message/update/:id', controller.message.update);
 };

+ 4 - 1
app/service/bedroom.js

@@ -126,7 +126,7 @@ class BedroomService extends CrudService {
       // 取得每个班级的班主任id
       const headteacherid = _class.headteacherid;
       const headteacher = await this.umodel.findOne({ uid: headteacherid, type: '1' });
-      if (headteacher.openid) {
+      if (headteacher && headteacher.openid) {
         const openid = headteacher.openid;
         const remark = '感谢您的使用';
         const date = await this.ctx.service.util.updatedate();
@@ -142,6 +142,9 @@ class BedroomService extends CrudService {
     // 根据期id查找所有当期学生列表
     const cltype = await this.ctmodel.find({ bedroom: '0' });
     const types = _.map(cltype, 'code');
+    console.log('-----types-start--');
+    console.log(types);
+    console.log('-----types-end--');
     const studentList = await this.smodel.find({ termid, batchid, type: { $in: types } }).sort({ gender: -1 });
     return studentList;
   }

+ 54 - 6
app/service/class.js

@@ -164,14 +164,62 @@ class ClassService extends CrudService {
   // 根据传入的学生列表和班级id更新学生信息
   async studentupclass({ id }, data) {
     assert(id, '班级id为必填项');
-    // 循环学生id
-    for (const stuid of data) {
-      const student = await this.stumodel.findById(stuid);
-      if (student) {
-        student.classid = id;
-        await student.save();
+    // 根据全年计划表id查出对应的全年计划详细信息
+    const trainplan = await this.tmodel.findOne({ 'termnum.batchnum.class._id': ObjectId(id) });
+    if (!trainplan) {
+      throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '全年计划信息不存在');
+    }
+    // 取得计划期批次信息
+    let termid = '';
+    let batchid = '';
+    let classname = '';
+    let class_ = {};
+    for (const term of trainplan.termnum) {
+      for (const batch of term.batchnum) {
+        const _class = await batch.class.id(id);
+        if (_class) {
+          termid = term.id;
+          batchid = batch.id;
+          classname = _class.name;
+          class_ = _class;
+          break;
+        }
       }
     }
+    if (!class_) {
+      throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '班级信息不存在');
+    }
+    let classid_ = '';
+    if (classname) {
+      const cla_ = await this.model.findOne({ termid, batchid, name: classname });
+      if (cla_) {
+        classid_ = cla_.id;
+      } else {
+        const newdata = {
+          name: class_.name,
+          number: class_.number,
+          batchid,
+          termid,
+          planid: trainplan.id,
+          type: class_.type,
+        };
+        const rescla = await this.model.create(newdata);
+        if (rescla) {
+          classid_ = rescla.id;
+        }
+      }
+    }
+    if (classid_) {
+      // 循环学生id
+      for (const stuid of data) {
+        const student = await this.stumodel.findById(stuid);
+        if (student) {
+          student.classid = classid_;
+          await student.save();
+        }
+      }
+    }
+
   }
 
   async notice(data) {

+ 2 - 2
app/service/headteacher.js

@@ -32,14 +32,14 @@ class HeadteacherService extends CrudService {
     const user = await this.umodel.findOne({ mobile: phone });
     const res = await this.model.update({ _id: ObjectId(id) }, data);
     if (res) {
-      const _user = await this.umodel.findOne({ uid: id, thpe: '1' });
+      const _user = await this.umodel.findOne({ uid: id, type: '1' });
       if (_user) {
         _user.mobile = phone;
         _user.name = name;
         if (openid) {
           _user.openid = openid;
         }
-        user.save();
+        _user.save();
       }
     }
     return res;

+ 1 - 1
app/service/lesson.js

@@ -46,6 +46,7 @@ class LessonService extends CrudService {
           batchid: batch.id,
         });
         // 循环班级
+        const teachids = [];
         for (const cla of _classs) {
           // 取得课程模板信息
           let lessonmode_ = _.find(_lessonmode, { type: cla.type });
@@ -63,7 +64,6 @@ class LessonService extends CrudService {
           const newlesson = [];
           for (const day of sedays) {
             // 循环课程模板,将模板信息排入班级课程表中
-            const teachids = [];
             for (const lessm of lessons_) {
               // 循环插入模板信息
               if (lessm['day' + i] !== '--') {

+ 12 - 0
app/service/message.js

@@ -0,0 +1,12 @@
+'use strict';
+
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+
+class MessageService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'message');
+    this.model = this.ctx.model.Message;
+  }
+}
+
+module.exports = MessageService;

+ 7 - 3
app/service/school.js

@@ -21,7 +21,7 @@ class SchoolService extends CrudService {
   }
 
   async stuimport(data) {
-    const { filepath, termid, schid, type } = data;
+    const { filepath, termid, schid, type, batchid } = data;
     assert(filepath, 'filepath不能为空');
     assert(termid, 'termid不能为空');
     assert(schid, 'schid不能为空');
@@ -46,7 +46,8 @@ class SchoolService extends CrudService {
       schid,
       planid,
       planyearid,
-      type
+      type,
+      batchid
     );
     // 将得到的数据校验
     const datacheck = await this.datacheck(studatas);
@@ -70,6 +71,7 @@ class SchoolService extends CrudService {
         planid: plan.id,
         termid,
         term: trem_.term,
+        batchid,
         filepath,
         studs: JSON.stringify(studatas),
         plannum: num_,
@@ -91,6 +93,7 @@ class SchoolService extends CrudService {
         planid: plan.id,
         termid,
         term: trem_.term,
+        batchid,
         filepath,
         studs: JSON.stringify(studatas),
         plannum: num_,
@@ -152,7 +155,7 @@ class SchoolService extends CrudService {
   }
 
   // 获取导入的XLSX文件中的数据
-  async getImportXLSXData(filepath, termid, schid, planid, planyearid, type) {
+  async getImportXLSXData(filepath, termid, schid, planid, planyearid, type, batchid) {
     console.log(filepath);
     const file = await this.ctx.curl(filepath);
     const workbook = XLSX.read(file.data);
@@ -209,6 +212,7 @@ class SchoolService extends CrudService {
         edua_system: data[theadRule[17]],
         diy: diy_,
         termid,
+        batchid,
         schid,
         planid,
         planyearid,

+ 3 - 2
app/service/student.js

@@ -52,14 +52,15 @@ class StudentService extends CrudService {
   }
 
   // 查询
-  async seek({ termid, type, skip, limit }) {
+  async seek({ termid, type, batchid, skip, limit }) {
     const total = await this.model.count({
       termid,
       type,
+      batchid,
       $or: [{ classid: null }, { classid: '' }],
     });
     const data = await this.model
-      .find({ termid, type, $or: [{ classid: null }, { classid: '' }] })
+      .find({ termid, type, batchid, $or: [{ classid: null }, { classid: '' }] })
       .skip(Number(skip))
       .limit(Number(limit));
     const result = { total, data };

+ 15 - 20
app/service/teaplan.js

@@ -90,34 +90,30 @@ class TeaplanService extends CrudService {
     const teaplanList = await this.model.find({ trainplanid });
     // 查询所有班主任信息
     const headteacherList = await this.hmodel.find();
-    for (const teaplan of teaplanList) {
-      // 过滤出班主任信息表中id为此班主任全年计划信息班主任id的数据
-      const headteacherInfo = _.filter(headteacherList, item => item.id === teaplan.headteacherid);
-      // 如果班主任信息列表中班主任上报了班主任全年计划,将其移除
-      if (headteacherInfo.length === 0) {
-        _.remove(headteacherList, item => item.id === teaplan.headteacherid);
-      }
-    }
+    // for (const teaplan of teaplanList) {
+    //   // 过滤出班主任信息表中id为此班主任全年计划信息班主任id的数据
+    //   const headteacherInfo = _.filter(headteacherList, item => item.id === teaplan.headteacherid);
+    //   // 如果班主任信息列表中班主任上报了班主任全年计划,将其移除
+    //   if (headteacherInfo.length === 0) {
+    //     _.remove(headteacherList, item => item.id === teaplan.headteacherid);
+    //   }
+    // }
     // 遍历所有批次信息
     // 将全年计划中的批次信息取出放在一个数组中
-    let teaListKfp = [];
-    let teaListAll = headteacherList;
     for (const term of trainplan.termnum) {
       for (const batch of term.batchnum) {
-        if (teaListAll.length === 0) {
-          teaListAll = teaListKfp;
-          teaListKfp = [];
-        }
+        const teaListAll = _.cloneDeep(JSON.parse(JSON.stringify(headteacherList)));
         for (const teaplan of teaplanList) {
           if (teaplan.nodate && (teaplan.nodate).length > 0) {
             // 遍历班主任全年计划表中的不能上课的日期
             for (const nodate of teaplan.nodate) {
             // 如果不能上课的日期在该批次的开始时间和结束时间中,将该班主任从班主任列表中删除
-              if (!moment(nodate).isBetween(batch.startdate, batch.enddate, null, '[]')) {
-                const headteacher_ = await this.hmodel.findById(teaplan.headteacherid);
-                if (headteacher_) {
-                  teaListAll.push(headteacher_);
-                }
+              if (moment(nodate).isBetween(batch.startdate, batch.enddate, null, '[]')) {
+                // const headteacher_ = await this.hmodel.findById(teaplan.headteacherid);
+                // if (headteacher_) {
+                //   teaListAll.push(headteacher_);
+                // }
+                _.remove(teaListAll, item => item.id === teaplan.headteacherid);
               }
             }
           }
@@ -147,7 +143,6 @@ class TeaplanService extends CrudService {
               _class.headteacherid = _tea.id;
               _.remove(teaListAll_, item => item.id === _tea.id);
               _.remove(teaListAll, item => item.id === _tea.id);
-              teaListKfp.push(_tea);
               index = index + 1;
               break;
             }

+ 24 - 9
app/service/trainplan.js

@@ -765,22 +765,37 @@ class TrainplanService extends CrudService {
     }
     return '';
   }
-  async updateclass({ trainplanid, classid, rightHeader }) {
-    assert(trainplanid && classid && rightHeader, '缺少参数项');
+  // async updateclass({ trainplanid, classid, rightHeader }) {
+  //   assert(trainplanid && classid && rightHeader, '缺少参数项');
+
+  async updateclass({ trainplanid, termid, batchid, classid, rightHeader }) {
+    assert(trainplanid && termid && batchid && classid && rightHeader, '缺少参数项');
     // 根据全年计划表id查出对应的全年计划详细信息
     const trainplan = await this.model.findById(trainplanid);
     if (!trainplan) {
       throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '全年计划信息不存在');
     }
-    for (const term of trainplan.termnum) {
-      for (const batch of term.batchnum) {
-        const class_ = await batch.class.id(classid);
-        if (class_) {
-          class_.headteacherid = rightHeader;
-        }
+    const term = trainplan.termnum.id(termid);
+    if (!term) {
+      throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '期信息不存在');
+    }
+    const batch = term.batchnum.id(batchid);
+    if (!batch) {
+      throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '批次信息不存在');
+    }
+    const class_ = await batch.class.id(classid);
+    if (class_) {
+      class_.headteacherid = rightHeader;
+    }
+    const res = await trainplan.save();
+    if (res) {
+      const cla_ = await this.clamodel.findOne({ termid, batchid, name: class_.name });
+      if (cla_) {
+        cla_.headteacherid = rightHeader;
+        await cla_.save();
       }
     }
-    return await trainplan.save();
+    return res;
   }
 
   async updatereteacher({ trainplanid, termid, reteacher }) {

+ 6 - 1
app/service/weixin.js

@@ -186,7 +186,12 @@ class WeixinAuthService extends AxiosService {
     const url = this.ctx.app.config.sendDirMq + this.ctx.app.config.appid;
     let _url = '';
     if (tourl) {
-      _url = this.ctx.app.config.baseUrl + '/api/train/auth?state=1&redirect_uri=' + this.ctx.app.config.baseUrl + '/classinfo/&type=template&objid=' + tourl;
+      // 通过openid取得用户基本信息
+      const user = await this.ctx.model.User.findOne({ openid });
+      const newdata = { openid, name: user.name, title: first, detail: keyword1, date: keyword2, remark, status: '0' };
+      const res = await this.ctx.model.Message.create(newdata);
+      // 需要回执的时候进行保存处理
+      _url = this.ctx.app.config.baseUrl + '/api/train/auth?state=1&redirect_uri=' + this.ctx.app.config.baseUrl + '/classinfo/&type=9&objid=' + tourl + '&msgid=' + res.id;
     }
     const requestData = { // 发送模板消息的数据
       touser: openid,