lrf402788946 4 年之前
父節點
當前提交
21f2b66dda

+ 0 - 8
app/controller/.teaplan.js

@@ -33,12 +33,4 @@ module.exports = {
       count: true,
     },
   },
-  arrange: {
-    parameters: {
-      query: {
-        planid: "planid",
-      },
-    },
-    service: "arrangeteacher",
-  },
 };

+ 4 - 2
app/controller/apply.js

@@ -7,7 +7,6 @@ const { CrudController } = require('naf-framework-mongoose/lib/controller');
 
 // 教师申请讲课表管理
 class ApplyController extends Controller {
-
   constructor(ctx) {
     super(ctx);
     this.service = this.ctx.service.apply;
@@ -17,7 +16,10 @@ class ApplyController extends Controller {
     const data = await this.service.queryteacher(this.ctx.request.query);
     this.ctx.ok({ data });
   }
-
+  async arrange() {
+    const data = await this.service.arrangeteacher(this.ctx.query);
+    this.ctx.ok({ data });
+  }
 }
 
 module.exports = CrudController(ApplyController, meta);

+ 0 - 1
app/controller/attendance.js

@@ -14,7 +14,6 @@ class AttendanceController extends Controller {
 
   // 考勤专用页面
   async wxauth() {
-    console.log(this.ctx.query);
     const res = '{}';
     this.ctx.ok({ res });
   }

+ 0 - 1
app/controller/bedroom.js

@@ -20,7 +20,6 @@ class BedroomController extends Controller {
   }
 
   async ibeacon() {
-    console.log(this.ctx.request.body);
     const res = await this.service.ibeacon(this.ctx.request.body);
     this.ctx.ok({ ...res });
   }

+ 0 - 1
app/controller/schtime.js

@@ -14,7 +14,6 @@ class SchtimeController extends Controller {
   }
 
   async updateschtimes() {
-    console.log(_.isArray(this.ctx.request.body));
     const res = await this.service.updateschtimes(this.ctx.request.body);
     this.ctx.ok({ msg: 'updated', data: res });
   }

+ 3 - 25
app/controller/weixin.js

@@ -26,7 +26,6 @@ class WeixinController extends Controller {
   //       token - url带上token参数重定向到原始地址
   async auth() {
     const { redirect_uri, code, test, type, response_type = 'store', uid, qrcode, msgid, objid } = this.ctx.query;
-    console.log(`code=${code}`);
     if (test) {
       return await this.authTest();
     }
@@ -45,7 +44,6 @@ class WeixinController extends Controller {
     const state = uuid();
     const key = `visit:auth:state:${state}`;
     const val = JSON.stringify({ redirect_uri, type, uid, qrcode, msgid, objid });
-    console.log(`key=>${key}`);
     await this.app.redis.set(key, val, 'EX', 600);
 
     // TODO: 生成回调地址
@@ -54,23 +52,18 @@ class WeixinController extends Controller {
     const to_uri = encodeURI(`${wxapi.baseUrl}/api/auth?appid=${wxapi.appid}&response_type=code&redirect_uri=${backUrl}#wechat`);
     // const backUrl = encodeURI(`${this.app.config.baseUrl}${this.config.authUrl}/`);
     // const to_uri = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${wxapi.appid}&response_type=code&scope=snsapi_base&redirect_uri=${backUrl}&state=${state}&connect_redirect=1#wechat_redirect`;
-    console.log('url-->' + to_uri);
     this.ctx.redirect(to_uri);
   }
 
   // GET 认证回调
   async authBack({ code, state }) {
     // const { code, state, type, redirecturi } = this.ctx.query;
-    console.log(this.ctx.query);
     this.ctx.logger.debug(`[auth-back] code - ${code}, state - ${state}`);
     assert(code, 'code不能为空');
     assert(state, 'state不能为空');
-    console.log('code-->' + code);
     const { weixin } = this.ctx.service;
     const key = `visit:auth:state:${state}`;
     const val = await this.app.redis.get(key);
-    console.log(key);
-    console.log(val);
     let openid;
     try {
       ({ openid } = await weixin.fetch(code));
@@ -78,41 +71,31 @@ class WeixinController extends Controller {
       await this.ctx.render('error.njk', { title: err.message, message: err.details });
       return;
     }
-    console.log('function in');
-    console.log('openid--->' + openid);
     if (openid) {
 
       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);
       if (type === '0') {
         // 通过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: 重定性页面
-            console.log('to_uri000-->' + to_uri);
             this.ctx.redirect(to_uri);
           } else if (user.type === '1') {
             const touri = `${this.app.config.baseUrl}/mobiledirtea`;
             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(touri, `?token=${token}`);
             // TODO: 重定性页面
-            console.log('to_uri000-->' + to_uri);
             this.ctx.redirect(to_uri);
           }
 
         } else {
-          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}
@@ -122,18 +105,15 @@ class WeixinController extends Controller {
       } 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);
       }
     }
@@ -152,24 +132,19 @@ class WeixinController extends Controller {
       // 通过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: 重定性页面
-          console.log('to_uri000-->' + to_uri);
           this.ctx.redirect(to_uri);
         } else if (user.type === '1') {
           const touri = `${this.app.config.baseUrl}/mobiledirtea`;
           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(touri, `?token=${token}`);
           // TODO: 重定性页面
-          console.log('to_uri000-->' + to_uri);
           this.ctx.redirect(to_uri);
         }
 
@@ -208,6 +183,9 @@ class WeixinController extends Controller {
     if (!login) this.ctx.ok(appopenid);
     console.warn('-------');
     console.warn(`openid=>${appopenid}`);
+    const state = uuid();
+    const key = `appopenid:${state}`;
+    await this.app.redis.set(key, appopenid, 'EX', 600);
     const res = await this.ctx.service.user.findByAppOpenid(appopenid);
     console.warn({ user: res, openid: appopenid });
     this.ctx.ok({ user: res, openid: appopenid });

+ 3 - 2
app/router.js

@@ -286,6 +286,7 @@ module.exports = app => {
 
   // 班主任全年计划表设置路由
   router.get('teaplan', '/api/train/teaplan/divide', controller.teaplan.divide);
+
   router.get(
     'teaplan',
     '/api/train/teaplan/findteacher',
@@ -297,9 +298,9 @@ module.exports = app => {
     '/api/train/teaplan/update/:id',
     controller.teaplan.update
   );
-  // 计划自动排教师
-  router.get('teaplan', '/api/train/teaplan/arrange', controller.teaplan.arrange);
 
+  // 计划自动排教师
+  router.get('apply', '/api/train/apply/arrange', controller.apply.arrange);
   // 教师申请讲课表设置路由
   router.get(
     'apply',

+ 4 - 0
app/service/teacher.js

@@ -31,6 +31,10 @@ class TeacherService extends CrudService {
   async fetchteachers({ ids }) {
     return await this.model.find({ _id: { $in: ids } });
   }
+  // 检查教师
+  async checkarrange({ id, date }) {
+    
+  }
 
 
   async status(data) {

+ 0 - 116
app/service/teaplan.js

@@ -221,123 +221,7 @@ class TeaplanService extends CrudService {
     return departmentList;
   }
 
-  async arrangeteacher({ planid }) {
-    const trainplan = await this.tmodel.findOne({ id: planid });
-    if (!trainplan) { throw new BusinessError(ErrorCode.DATA_EXISTED, '年度计划不存在'); }
-    // 查找所有教师列表
-    const teacherList = await this.teamodel.find();
-    // 查找所有教师上报列表
-    const teaplanList = await this.model.find();
-    // 课程
-    const subjectList = await this.submodel.find();
-    const termList = _.cloneDeep(trainplan.termnum);
-    const { termnum } = termList;
-    if (!termnum) return;
-    // 整理出课表
-    const arr = [];
-    for (const t of termnum) {
-      const { batchnum, term, _id: termid } = t;
-      // 班级和课程一一匹配显示在列表上
-      for (const b of batchnum) {
-        const { class: classes, lessons, startdate, enddate, _id: batchid } = b;
-        const claslesList = this.setList(term, termid, batchid, classes, lessons);
-        arr.push(...claslesList);
-      }
-    }
-    // 安排后的课表
-    const afterList = [];
-    // 排课
-    for (const l of arr) {
-      const { termid, subid, day: date, teaid } = l;
-      if (teaid) { afterList.push(l); continue; }
-      const subject = subjectList.find(f => ObjectId(subid).equals(f._id));
-      if (subject.need_teacher !== '0') continue;
-      // 申请该天,该科目的教师,并查出教师的名字,分数;并按分数排序
-      let applyList = teaplanList.filter(f => f.termid === termid && f.subid === subid && f.date === date);
-      applyList = applyList.map(i => {
-        const r = this.teacherList.find(f => ObjectId(i.teacherid).equals(f._id));
-        if (r) {
-          const { name: teaname, xsscore: score } = r;
-          i.teaname = teaname;
-          i.score = score * 1;
-        }
-        return i;
-      });
-      applyList = _.orderBy(applyList, [ 'score' ], [ 'desc' ]);
-      // 依次循环申请的教师列表,往这个课程安排中放教师
-      for (const atea of applyList) {
-        // 先查询,该教师,是否在今天有安排
-        const tr = afterList.find(f => f.teaid === atea.teacherid && f.day === atea.date);
-        if (tr) continue;
-        else {
-          l.teaid = tr.teacherid;
-          l.teaname = tr.teaname;
-          break;
-        }
-      }
-      afterList.push(l);
-    }
-    // 将afterList还原回正常的termnum
-    let newTermnum = [];
-    for (const l of afterList) {
-      const { termid, batchid, classid, ...info } = l;
-      const updata = _.pick(info, [ 'day', 'subid', 'subname', 'teaid', 'teaname', 'time' ]);
-      newTermnum = trainplan.termnum.map(t => {
-        // 找到期
-        if (ObjectId(termid).equals(t._id)) {
-          t.batchnum = t.batchnum.map(b => {
-            if (ObjectId(batchid).equals(b._id)) {
-              // 找到批次
-              b.class = b.class.map(c => {
-                if (ObjectId(classid).equals(c._id)) {
-                  if (c.lessons) {
-                    // 说明有课程安排,找有没有重复的,没有就推进去,有就更改,subid查
-                    const r = c.lessons.find(f => f.subid === updata.subid);
-                    if (r) {
-                      const rindex = c.lessons.findIndex(
-                        f => f.subid === updata.subid
-                      );
-                      c.lessons[rindex] = updata;
-                    } else {
-                      c.lessons.push(updata);
-                    }
-                  } else {
-                    // 说明没有课程安排,放进去一条保存
-                    c.lessons = [ updata ];
-                  }
-                }
-                return c;
-              });
-            }
-            return b;
-          });
-        }
-        return t;
-      });
-    }
-    // 保存至计划
-    trainplan.termnum = newTermnum;
-    return await trainplan.save();
-  }
 
-
-  setList(term, termid, batchid, classes, lessonTemplate) {
-    const arr = [];
-    // 班级和课程匹配
-    for (const cla of classes) {
-      cla.term = term;
-      cla.termid = termid;
-      cla.batchid = batchid;
-      const { lessons } = cla;
-      if (!lessons) cla.lessons = lessonTemplate;
-      cla.lessons.map(i => {
-        let obj = _.omit(cla, [ 'lessons' ]);
-        obj = { ...obj, ...i, classid: _.clone(cla._id) };
-        arr.push(obj);
-      });
-    }
-    return arr;
-  }
 }
 
 module.exports = TeaplanService;

+ 1 - 0
app/service/weixin.js

@@ -297,6 +297,7 @@ class WeixinAuthService extends AxiosService {
     });
     const { openid } = res.data;
     if (!openid) throw new BusinessError(ErrorCode.BUSINESS, '未获取到openid', '未获取到openid');
+
     return openid;
   }