Parcourir la source

云就业登录

lrf il y a 1 an
Parent
commit
46f9d3eef8
6 fichiers modifiés avec 205 ajouts et 430 suppressions
  1. 34 0
      app/controller/yunjiuye.js
  2. 19 0
      app/model/yjyconnect.js
  3. 91 430
      app/router.js
  4. 52 0
      app/service/yunjiuye.js
  5. 5 0
      config/config.local.js
  6. 4 0
      config/config.prod.js

+ 34 - 0
app/controller/yunjiuye.js

@@ -0,0 +1,34 @@
+'use strict';
+const Controller = require('egg').Controller;
+class YunjiuyeController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.yunjiuye;
+  }
+
+  async login() {
+    const body = this.ctx.request.body;
+    const { code, org } = body;
+    const res = await this.service.checkUserIsConnect(body);
+    const { toBindPage, toDealTokenPage } = this.app.config.yunjiuye;
+    // 没关联,转到登录页面
+    if (!res) {
+      this.ctx.redirect(`${toBindPage}?code=${code}&org=${org}`);
+    } else {
+      // 已关联,转到加载token页面
+      const token = await this.service.userToken(res);
+      this.ctx.redirect(`${toDealTokenPage}?token=${token}`);
+    }
+
+  }
+
+  async userBind() {
+    const body = this.ctx.request.body;
+    // 成功返回suid
+    const res = await this.service.userBind(body);
+    // 请求token,返回token
+    const token = await this.service.userToken(res);
+    this.ctx.ok({ data: token });
+  }
+}
+module.exports = YunjiuyeController;

+ 19 - 0
app/model/yjyconnect.js

@@ -0,0 +1,19 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 云就业关联
+const YjyconnectSchema = {
+  ycode: { type: String, required: true, maxLength: 200 }, // 云就业标识
+  yorg: { type: String, required: true, maxLength: 200 }, // 云就业机构
+  suid: { type: String, required: true, maxLength: 200 }, // 双困生用户表id
+};
+
+const schema = new Schema(YjyconnectSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Yjyconnect', schema, 'yjyconnect');
+};

+ 91 - 430
app/router.js

@@ -6,13 +6,14 @@
 module.exports = app => {
   const { router, controller } = app;
   router.get('/', controller.home.index);
+  // 云就业登录
+  router.post('/api/train/y/login', controller.yunjiuye.login);
+  // 云就业登录
+  router.post('/api/train/y/userBind', controller.yunjiuye.userBind);
   // 共通查询单条记录方法
   router.get('/api/train/common/findone/:modelname', controller.common.findone);
   // 共通批量查询方法
-  router.post(
-    '/api/train/common/findbyids/:modelname',
-    controller.common.findbyids
-  );
+  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);
@@ -20,34 +21,18 @@ module.exports = app => {
   router.get('/api/train/setting/termlist', controller.setting.termList); // 请求所有期
   router.get('/api/train/setting/findone', controller.setting.findone);
   router.resources('setting', '/api/train/setting', controller.setting); // index、create、show、destroy
-  router.post(
-    'setting',
-    '/api/train/setting/update/:id',
-    controller.setting.update
-  );
+  router.post('setting', '/api/train/setting/update/:id', controller.setting.update);
 
   // 科目表设置路由
   router.resources('subject', '/api/train/subject', controller.subject); // index、create、show、destroy
-  router.post(
-    'subject',
-    '/api/train/subject/update/:id',
-    controller.subject.update
-  );
+  router.post('subject', '/api/train/subject/update/:id', controller.subject.update);
 
   // 教师表设置路由
   router.post('teacher', '/api/train/teacher/export', controller.teacher.export);
   router.get('teacher', '/api/train/teacher/show/:id', controller.teacher.show);
   router.resources('teacher', '/api/train/teacher', controller.teacher); // index、create、show、destroy
-  router.post(
-    'teacher',
-    '/api/train/teacher/update/:id',
-    controller.teacher.update
-  );
-  router.post(
-    'teacher',
-    '/api/train/teacher/status',
-    controller.teacher.status
-  );
+  router.post('teacher', '/api/train/teacher/update/:id', controller.teacher.update);
+  router.post('teacher', '/api/train/teacher/status', controller.teacher.status);
   router.post('/api/train/teacher/teaimport', controller.teacher.teaimport);
   router.post('/api/train/teacher/fetchteachers', controller.teacher.fetchteachers);
 
@@ -57,111 +42,39 @@ module.exports = app => {
 
   // 问卷题库表配置路由
   router.resources('question', '/api/train/question', controller.question); // index、create、show、destroy
-  router.post(
-    'question',
-    '/api/train/question/update/:id',
-    controller.question.update
-  );
+  router.post('question', '/api/train/question/update/:id', controller.question.update);
 
   // 问卷表配置路由
-  router.post(
-    'questionnaire',
-    '/api/train/questionnaire',
-    controller.questionnaire.create
-  );
-  router.delete(
-    'questionnaire',
-    '/api/train/questionnaire/:id',
-    controller.questionnaire.delete
-  );
-  router.post(
-    'questionnaire',
-    '/api/train/questionnaire/update/:id',
-    controller.questionnaire.update
-  );
-  router.get(
-    'questionnaire',
-    '/api/train/questionnaire',
-    controller.questionnaire.query
-  );
-  router.get(
-    'questionnaire',
-    '/api/train/questionnaire/show/:id',
-    controller.questionnaire.show
-  );
+  router.post('questionnaire', '/api/train/questionnaire', controller.questionnaire.create);
+  router.delete('questionnaire', '/api/train/questionnaire/:id', controller.questionnaire.delete);
+  router.post('questionnaire', '/api/train/questionnaire/update/:id', controller.questionnaire.update);
+  router.get('questionnaire', '/api/train/questionnaire', controller.questionnaire.query);
+  router.get('questionnaire', '/api/train/questionnaire/show/:id', controller.questionnaire.show);
   // 查询学校是否上报学生
   router.get('student', '/api/train/student/school', controller.student.getSchoolStudent);
   // 班级学生排号
   router.get('sutdent', '/api/train/student/arrangeNumber', controller.student.arrangeNumber);
   // 建立导出学生的任务
-  router.post(
-    'student',
-    '/api/train/student/export',
-    controller.student.toExport
-  );
+  router.post('student', '/api/train/student/export', controller.student.toExport);
   // 导出学生
-  router.post(
-    'student',
-    '/api/train/mission/student/export',
-    controller.student.exportStudent
-  );
+  router.post('student', '/api/train/mission/student/export', controller.student.exportStudent);
   // 学生表设置路由
-  router.get(
-    'sutdent',
-    '/api/train/student/finestudent/:id',
-    controller.student.finestudent
-  );
-  router.get(
-    'sutdent',
-    '/api/train/student/findscore',
-    controller.student.findscore
-  );
-  router.get(
-    'sutdent',
-    '/api/train/student/findbedroom',
-    controller.student.findbedroom
-  );
+  router.get('sutdent', '/api/train/student/finestudent/:id', controller.student.finestudent);
+  router.get('sutdent', '/api/train/student/findscore', controller.student.findscore);
+  router.get('sutdent', '/api/train/student/findbedroom', controller.student.findbedroom);
 
   router.get('sutdent', '/api/train/student/seek', controller.student.seek);
   router.resources('student', '/api/train/student', controller.student); // index、create、show、destroy
-  router.post(
-    'student',
-    '/api/train/student/update/:id',
-    controller.student.update
-  );
+  router.post('student', '/api/train/student/update/:id', controller.student.update);
   router.post('student', '/api/train/student/upjob', controller.student.upjob);
-  router.post(
-    'student',
-    '/api/train/student/deleteclass',
-    controller.student.deleteclass
-  ); // 删除学生班级
-  router.post(
-    'student',
-    '/api/train/student/findbystuids',
-    controller.student.findbystuids
-  );
-  router.post(
-    'student',
-    '/api/train/student/deletestus',
-    controller.student.deletestus
-  ); // 删除学生多条
-  router.post(
-    'student',
-    '/api/train/student/updatabedroom',
-    controller.student.updatabedroom
-  ); // 批量学生寝室号
+  router.post('student', '/api/train/student/deleteclass', controller.student.deleteclass); // 删除学生班级
+  router.post('student', '/api/train/student/findbystuids', controller.student.findbystuids);
+  router.post('student', '/api/train/student/deletestus', controller.student.deletestus); // 删除学生多条
+  router.post('student', '/api/train/student/updatabedroom', controller.student.updatabedroom); // 批量学生寝室号
 
   // 班主任表设置路由
-  router.resources(
-    'headteacher',
-    '/api/train/headteacher',
-    controller.headteacher
-  ); // index、create、show、destroy
-  router.post(
-    'headteacher',
-    '/api/train/headteacher/update/:id',
-    controller.headteacher.update
-  );
+  router.resources('headteacher', '/api/train/headteacher', controller.headteacher); // index、create、show、destroy
+  router.post('headteacher', '/api/train/headteacher/update/:id', controller.headteacher.update);
   // 查询该期还可以使用的寝室
   router.get('bedroom', '/api/train/bedroom/assignroom', controller.bedroom.getAssignRoom);
 
@@ -171,109 +84,46 @@ module.exports = app => {
   // 寝室表设置路由
   router.get('/api/train/bedroom/student/:id', controller.bedroom.roomstu); // 根据班级id查询寝室信息
   router.resources('bedroom', '/api/train/bedroom', controller.bedroom); // index、create、show、destroy
-  router.post(
-    'bedroom',
-    '/api/train/bedroom/update/:id',
-    controller.bedroom.update
-  );
+  router.post('bedroom', '/api/train/bedroom/update/:id', controller.bedroom.update);
   router.post('bedroom', '/api/train/bedroom/apart', controller.bedroom.apart);
-  router.post(
-    'bedroom',
-    '/api/train/bedroom/ibeacon',
-    controller.bedroom.ibeacon
-  );
+  router.post('bedroom', '/api/train/bedroom/ibeacon', controller.bedroom.ibeacon);
 
   // 模板设置班级
   router.get('class', '/api/train/class/settemplate', controller.class.toSetClassSetting);
   // 班级表设置路由
-  router.get(
-    'class',
-    '/api/train/class/classinfo/:id',
-    controller.class.classinfo
-  );
-  router.post(
-    'class',
-    '/api/train/class/upclasses',
-    controller.class.upclasses
-  );
+  router.get('class', '/api/train/class/classinfo/:id', controller.class.classinfo);
+  router.post('class', '/api/train/class/upclasses', controller.class.upclasses);
   router.post('class', '/api/train/class/notice', controller.class.notice);
   router.resources('class', '/api/train/class', controller.class); // index、create、show、destroy
   router.post('class', '/api/train/class/update/:id', controller.class.update);
   router.post('class', '/api/train/class/divide', controller.class.divide);
   router.post('class', '/api/train/class/uptea', controller.class.uptea);
-  router.post(
-    'class',
-    '/api/train/class/upstuclass/:id',
-    controller.class.studentupclass
-  ); // 学生修改班级
+  router.post('class', '/api/train/class/upstuclass/:id', controller.class.studentupclass); // 学生修改班级
 
   // 部门表设置路由
-  router.resources(
-    'department',
-    '/api/train/department',
-    controller.department
-  ); // index、create、show、destroy
-  router.post(
-    'department',
-    '/api/train/department/update/:id',
-    controller.department.update
-  );
+  router.resources('department', '/api/train/department', controller.department); // index、create、show、destroy
+  router.post('department', '/api/train/department/update/:id', controller.department.update);
 
   // 位置表设置路由
   router.resources('location', '/api/train/location', controller.location); // index、create、show、destroy
-  router.post(
-    'location',
-    '/api/train/location/update/:id',
-    controller.location.update
-  );
+  router.post('location', '/api/train/location/update/:id', controller.location.update);
 
   // 培训计划表设置路由
   router.resources('trainplan', '/api/train/trainplan', controller.trainplan); // index、create、show、destroy
-  router.post(
-    'trainplan',
-    '/api/train/trainplan/update/:id',
-    controller.trainplan.update
-  );
-  router.post(
-    '/api/train/trainplan/exportExcel',
-    controller.trainplan.exportExcel
-  ); // 导出
-  router.post(
-    '/api/train/trainplan/exportSchool',
-    controller.trainplan.exportSchool
-  ); // 导出计划学校
-  router.post(
-    '/api/train/trainplan/exportPlan',
-    controller.trainplan.exportPlan
-  ); // 导出计划日历
-  router.post(
-    '/api/train/trainplan/updateclass',
-    controller.trainplan.updateclass
-  );
-  router.post(
-    '/api/train/trainplan/updatereteacher',
-    controller.trainplan.updatereteacher
-  );
+  router.post('trainplan', '/api/train/trainplan/update/:id', controller.trainplan.update);
+  router.post('/api/train/trainplan/exportExcel', controller.trainplan.exportExcel); // 导出
+  router.post('/api/train/trainplan/exportSchool', controller.trainplan.exportSchool); // 导出计划学校
+  router.post('/api/train/trainplan/exportPlan', controller.trainplan.exportPlan); // 导出计划日历
+  router.post('/api/train/trainplan/updateclass', controller.trainplan.updateclass);
+  router.post('/api/train/trainplan/updatereteacher', controller.trainplan.updatereteacher);
 
   // 培训计划年度批次表设置路由
-  router.resources(
-    'trainplanyear',
-    '/api/train/trainplanyear',
-    controller.trainplanyear
-  ); // index、create、show、destroy
-  router.post(
-    'trainplanyear',
-    '/api/train/trainplanyear/update/:id',
-    controller.trainplanyear.update
-  );
+  router.resources('trainplanyear', '/api/train/trainplanyear', controller.trainplanyear); // index、create、show、destroy
+  router.post('trainplanyear', '/api/train/trainplanyear/update/:id', controller.trainplanyear.update);
 
   // 节假日表设置路由
   router.resources('festival', '/api/train/festival', controller.festival); // index、create、show、destroy
-  router.post(
-    'festival',
-    '/api/train/festival/update/:id',
-    controller.festival.update
-  );
+  router.post('festival', '/api/train/festival/update/:id', controller.festival.update);
 
   // 新自动排课表
   router.post('/api/train/lesson/newarrange', controller.lesson.newArrange);
@@ -282,52 +132,24 @@ module.exports = app => {
   router.get('/api/train/lesson/timeCollate', controller.lesson.timeCollate);
   // 课程表设置路由
   router.get('/api/train/lesson/teaclass', controller.lesson.teaclass);
-  router.post(
-    'lesson',
-    '/api/train/lesson/uplessones',
-    controller.lesson.uplessones
-  );
+  router.post('lesson', '/api/train/lesson/uplessones', controller.lesson.uplessones);
   router.get('/api/train/lesson/classbyteaid', controller.lesson.classbyteaid); // 根据计划id与教师id查询班级信息
   router.resources('lesson', '/api/train/lesson', controller.lesson); // index、create、show、destroy
-  router.post(
-    'lesson',
-    '/api/train/lesson/update/:id',
-    controller.lesson.update
-  );
-  router.post(
-    'lesson',
-    '/api/train/lesson/autolesson/:id',
-    controller.lesson.autolesson
-  ); // 自动排课
+  router.post('lesson', '/api/train/lesson/update/:id', controller.lesson.update);
+  router.post('lesson', '/api/train/lesson/autolesson/:id', controller.lesson.autolesson); // 自动排课
   router.post('lesson', '/api/train/lesson/check', controller.lesson.check); // 确定(锁死)课表
 
   // 培训计划学校上报时间表设置路由
   router.resources('schtime', '/api/train/schtime', controller.schtime); // index、create、show、destroy
-  router.post(
-    'schtime',
-    '/api/train/schtime/update/:id',
-    controller.schtime.update
-  );
-  router.post(
-    'schtime',
-    '/api/train/schtime/updateschtimes',
-    controller.schtime.updateschtimes
-  );
+  router.post('schtime', '/api/train/schtime/update/:id', controller.schtime.update);
+  router.post('schtime', '/api/train/schtime/updateschtimes', controller.schtime.updateschtimes);
 
   // 班主任全年计划表设置路由
   router.get('teaplan', '/api/train/teaplan/divide', controller.teaplan.divide);
 
-  router.get(
-    'teaplan',
-    '/api/train/teaplan/findteacher',
-    controller.teaplan.findteacher
-  );
+  router.get('teaplan', '/api/train/teaplan/findteacher', controller.teaplan.findteacher);
   router.resources('teaplan', '/api/train/teaplan', controller.teaplan); // index、create、show、destroy
-  router.post(
-    'teaplan',
-    '/api/train/teaplan/update/:id',
-    controller.teaplan.update
-  );
+  router.post('teaplan', '/api/train/teaplan/update/:id', controller.teaplan.update);
 
   // 计划自动排教师
   router.post('apply', '/api/train/apply/arrange', controller.apply.arrange);
@@ -338,11 +160,7 @@ module.exports = app => {
   // 计划自动排教师
   router.post('apply', '/api/train/apply/confirm/:planid', controller.apply.confirm);
   // 教师申请讲课表设置路由
-  router.get(
-    'apply',
-    '/api/train/apply/queryteacher',
-    controller.apply.queryteacher
-  );
+  router.get('apply', '/api/train/apply/queryteacher', controller.apply.queryteacher);
   router.resources('apply', '/api/train/apply', controller.apply); // index、create、show、destroy
   router.post('apply', '/api/train/apply/update/:id', controller.apply.update);
 
@@ -358,12 +176,7 @@ module.exports = app => {
   router.post('group', '/api/train/group/insert', controller.group.insert);
   router.post('group', '/api/train/group/exit', controller.group.exit);
   router.post('group', '/api/train/group/sethead', controller.group.sethead);
-  router.post(
-    'group',
-    '/api/train/group/findbystuid',
-    controller.group.findbystuid
-  );
-
+  router.post('group', '/api/train/group/findbystuid', controller.group.findbystuid);
 
   // 培训心得表设置路由
   router.post('/api/train/experience/docx', controller.experience.docx); // index、create、show、destroy
@@ -374,71 +187,28 @@ module.exports = app => {
   router.post('duty', '/api/train/duty/update/:id', controller.duty.update);
 
   // 学生上传作业表设置路由
-  router.resources(
-    'uploadtask',
-    '/api/train/uploadtask',
-    controller.uploadtask
-  ); // index、create、show、destroy
-  router.post(
-    'uploadtask',
-    '/api/train/uploadtask/update/:id',
-    controller.uploadtask.update
-  );
+  router.resources('uploadtask', '/api/train/uploadtask', controller.uploadtask); // index、create、show、destroy
+  router.post('uploadtask', '/api/train/uploadtask/update/:id', controller.uploadtask.update);
 
   // 学生上传问卷表设置路由
-  router.get(
-    '/api/train/uploadquestion/completion',
-    controller.uploadquestion.completion
-  ); // 统计完成度
-  router.resources(
-    'uploadquestion',
-    '/api/train/uploadquestion',
-    controller.uploadquestion
-  ); // index、create、show、destroy
-  router.post(
-    'uploadquestion',
-    '/api/train/uploadquestion/update/:id',
-    controller.uploadquestion.update
-  );
+  router.get('/api/train/uploadquestion/completion', controller.uploadquestion.completion); // 统计完成度
+  router.resources('uploadquestion', '/api/train/uploadquestion', controller.uploadquestion); // index、create、show、destroy
+  router.post('uploadquestion', '/api/train/uploadquestion/update/:id', controller.uploadquestion.update);
 
   // 考勤表设置路由
   router.get('/api/train/attendance/wxauth', controller.attendance.wxauth); // 统计完成度
-  router.resources(
-    'attendance',
-    '/api/train/attendance',
-    controller.attendance
-  ); // index、create、show、destroy
-  router.post(
-    'attendance',
-    '/api/train/attendance/update/:id',
-    controller.attendance.update
-  );
-  router.post(
-    'attendance',
-    '/api/train/attendance/attendancecreate',
-    controller.attendance.attendancecreate
-  );
-  router.post(
-    'attendance',
-    '/api/train/attendance/attendancecreateList',
-    controller.attendance.attendancecreateList
-  );
+  router.resources('attendance', '/api/train/attendance', controller.attendance); // index、create、show、destroy
+  router.post('attendance', '/api/train/attendance/update/:id', controller.attendance.update);
+  router.post('attendance', '/api/train/attendance/attendancecreate', controller.attendance.attendancecreate);
+  router.post('attendance', '/api/train/attendance/attendancecreateList', controller.attendance.attendancecreateList);
   // 学校上传学生名单
   router.resources('school', '/api/train/school', controller.school); // index、create、show、destroy
-  router.post(
-    'school',
-    '/api/train/school/update/:id',
-    controller.school.update
-  );
+  router.post('school', '/api/train/school/update/:id', controller.school.update);
   router.post('/api/train/school/import', controller.school.stuimport); // 名单上传
 
   // 民族表设置路由
   router.resources('nation', '/api/train/nation', controller.nation); // index、create、show、destroy
-  router.post(
-    'nation',
-    '/api/train/nation/update/:id',
-    controller.nation.update
-  );
+  router.post('nation', '/api/train/nation/update/:id', controller.nation.update);
 
   // 行政区划表设置路由
   router.resources('region', '/api/train/region', controller.region); // index、create、show、destroy
@@ -471,7 +241,6 @@ module.exports = app => {
   router.post('/api/train/wxlogin', controller.login.wxlogin); // 登录
   router.post('/api/train/openidLogin', controller.weixin.openidLogin); // 手机端登录
 
-
   // 计算教师的分数
   router.get('score', '/api/train/score/computed', controller.score.computedScore);
   // 计算所有教师的分数
@@ -482,31 +251,15 @@ module.exports = app => {
 
   // 上传资料表设置路由
   router.resources('material', '/api/train/material', controller.material); // index、create、show、destroy
-  router.post(
-    'material',
-    '/api/train/material/update/:id',
-    controller.material.update
-  );
+  router.post('material', '/api/train/material/update/:id', controller.material.update);
 
   // 资料评分表设置路由
-  router.resources(
-    'materialscore',
-    '/api/train/materialscore',
-    controller.materialscore
-  ); // index、create、show、destroy
-  router.post(
-    'materialscore',
-    '/api/train/materialscore/update/:id',
-    controller.materialscore.update
-  );
+  router.resources('materialscore', '/api/train/materialscore', controller.materialscore); // index、create、show、destroy
+  router.post('materialscore', '/api/train/materialscore/update/:id', controller.materialscore.update);
 
   // 教师在线表设置路由
   router.resources('online', '/api/train/online', controller.online); // index、create、show、destroy
-  router.post(
-    'online',
-    '/api/train/online/update/:id',
-    controller.online.update
-  );
+  router.post('online', '/api/train/online/update/:id', controller.online.update);
 
   // 聊天房间表设置路由
   router.resources('room', '/api/train/room', controller.room); // index、create、show、destroy
@@ -514,45 +267,21 @@ module.exports = app => {
 
   // 聊天记录表设置路由
   router.resources('record', '/api/train/record', controller.record); // index、create、show、destroy
-  router.post(
-    'record',
-    '/api/train/record/update/:id',
-    controller.record.update
-  );
+  router.post('record', '/api/train/record/update/:id', controller.record.update);
 
   // 通知表设置路由
   router.resources('notice', '/api/train/notice', controller.notice); // index、create、show、destroy
-  router.post(
-    'notice',
-    '/api/train/notice/update/:id',
-    controller.notice.update
-  );
+  router.post('notice', '/api/train/notice/update/:id', controller.notice.update);
   router.post('notice', '/api/train/notice/look', controller.notice.look);
   router.post('notice', '/api/train/notice/resend', controller.notice.resend);
 
   // 课程模板表设置路由
-  router.resources(
-    'lessonmode',
-    '/api/train/lessonmode',
-    controller.lessonmode
-  ); // index、create、show、destroy
-  router.post(
-    'lessonmode',
-    '/api/train/lessonmode/update/:id',
-    controller.lessonmode.update
-  );
+  router.resources('lessonmode', '/api/train/lessonmode', controller.lessonmode); // index、create、show、destroy
+  router.post('lessonmode', '/api/train/lessonmode/update/:id', controller.lessonmode.update);
 
   // 全年计划模板表设置路由
-  router.resources(
-    'trainmodel',
-    '/api/train/trainmodel',
-    controller.trainmodel
-  ); // index、create、show、destroy
-  router.post(
-    'trainmodel',
-    '/api/train/trainmodel/update/:id',
-    controller.trainmodel.update
-  );
+  router.resources('trainmodel', '/api/train/trainmodel', controller.trainmodel); // index、create、show、destroy
+  router.post('trainmodel', '/api/train/trainmodel/update/:id', controller.trainmodel.update);
 
   // 统计查询设置路由
   router.get('/api/train/count/countstudent', controller.count.countstudent);
@@ -561,11 +290,7 @@ module.exports = app => {
 
   // 班级类型表配置路由
   router.resources('classtype', '/api/train/classtype', controller.classtype); // index、create、show、destroy
-  router.post(
-    'classtype',
-    '/api/train/classtype/update/:id',
-    controller.classtype.update
-  );
+  router.post('classtype', '/api/train/classtype/update/:id', controller.classtype.update);
 
   // 学校上传任务表设置路由
   router.resources('job', '/api/train/job', controller.job); // index、create、show、destroy
@@ -573,100 +298,36 @@ module.exports = app => {
 
   // 消息表设置路由
   router.resources('message', '/api/train/message', controller.message); // index、create、show、destroy
-  router.post(
-    'message',
-    '/api/train/message/update/:id',
-    controller.message.update
-  );
+  router.post('message', '/api/train/message/update/:id', controller.message.update);
   // 直播房间
   router.resources('liveroom', '/api/train/liveroom', controller.liveroom); // index、create、show、destroy
-  router.post(
-    'liveroom',
-    '/api/train/liveroom/update/:id',
-    controller.liveroom.update
-  );
+  router.post('liveroom', '/api/train/liveroom/update/:id', controller.liveroom.update);
   // 通知看直播
-  router.post(
-    'liveroom',
-    '/api/train/liveroom/sendmsg',
-    controller.liveroom.sendmsg
-  );
+  router.post('liveroom', '/api/train/liveroom/sendmsg', controller.liveroom.sendmsg);
   // 监听人数
-  router.post(
-    'liveroom',
-    '/api/train/liveroom/personcount',
-    controller.liveroom.personcount
-  );
+  router.post('liveroom', '/api/train/liveroom/personcount', controller.liveroom.personcount);
   // 培训视频
-  router.resources(
-    'trainvideo',
-    '/api/train/trainvideo',
-    controller.trainvideo
-  ); // index、create、show、destroy
-  router.post(
-    'trainvideo',
-    '/api/train/trainvideo/update/:id',
-    controller.trainvideo.update
-  );
+  router.resources('trainvideo', '/api/train/trainvideo', controller.trainvideo); // index、create、show、destroy
+  router.post('trainvideo', '/api/train/trainvideo/update/:id', controller.trainvideo.update);
   // 答疑申请(教师)
   router.resources('answerapply', '/api/train/answerapply', controller.answerapply); // index、create、show、destroy
-  router.post(
-    'answerapply',
-    '/api/train/answerapply/update/:id',
-    controller.answerapply.update
-  );
+  router.post('answerapply', '/api/train/answerapply/update/:id', controller.answerapply.update);
   // 答疑房间
   router.resources('chatroom', '/api/train/chatroom', controller.chatroom); // index、create、show、destroy
-  router.post(
-    'chatroom',
-    '/api/train/chatroom/update/:id',
-    controller.chatroom.update
-  );
+  router.post('chatroom', '/api/train/chatroom/update/:id', controller.chatroom.update);
   // 答疑对话
-  router.resources(
-    'answerchat',
-    '/api/train/answerchat',
-    controller.answerchat
-  ); // index、create、show、destroy
-  router.post(
-    'answerchat',
-    '/api/train/answerchat/update/:id',
-    controller.answerchat.update
-  );
+  router.resources('answerchat', '/api/train/answerchat', controller.answerchat); // index、create、show、destroy
+  router.post('answerchat', '/api/train/answerchat/update/:id', controller.answerchat.update);
 
   // 个人分groupscore
-  router.resources(
-    'personalscore',
-    '/api/train/personalscore',
-    controller.personalscore
-  ); // index、create、show、destroy
-  router.post(
-    'personalscore',
-    '/api/train/personalscore/update/:id',
-    controller.personalscore.update
-  );
+  router.resources('personalscore', '/api/train/personalscore', controller.personalscore); // index、create、show、destroy
+  router.post('personalscore', '/api/train/personalscore/update/:id', controller.personalscore.update);
   // 上分(混合操作,有添加,也有修改)
-  router.post(
-    'personalscore',
-    '/api/train/personalscore/opera',
-    controller.personalscore.opera
-  );
-  router.resources(
-    'groupscore',
-    '/api/train/groupscore',
-    controller.groupscore
-  ); // index、create、show、destroy
-  router.post(
-    'groupscore',
-    '/api/train/groupscore/update/:id',
-    controller.groupscore.update
-  );
+  router.post('personalscore', '/api/train/personalscore/opera', controller.personalscore.opera);
+  router.resources('groupscore', '/api/train/groupscore', controller.groupscore); // index、create、show、destroy
+  router.post('groupscore', '/api/train/groupscore/update/:id', controller.groupscore.update);
   // 组上分(混合操作,有添加,也有修改)
-  router.post(
-    'groupscore',
-    '/api/train/groupscore/opera',
-    controller.groupscore.opera
-  );
+  router.post('groupscore', '/api/train/groupscore/opera', controller.groupscore.opera);
   // 证书检验
   router.get('/api/train/cerconfirm', controller.cerconfirm.index);
   // 工具方法

+ 52 - 0
app/service/yunjiuye.js

@@ -0,0 +1,52 @@
+'use strict';
+const Service = require('egg').Service;
+const assert = require('assert');
+const _ = require('lodash');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const { ObjectId } = require('mongoose').Types;
+class YunjiuyeService extends Service {
+  // 检查用户是否和云就业有关联
+  // 没关联就直接重定向到关联页
+  // 有关联就直接去登录
+  async checkUserIsConnect({ code, org }) {
+    assert(code, '缺少用户标识');
+    assert(org, '缺少机构');
+    const yjycModel = this.ctx.model.Yjyconnect;
+    const result = await yjycModel.findOne({ ycode: code, yorg: org }).lean();
+    if (!result) return false;
+    return result.suid;
+  }
+
+  // 用户与云就业关联
+  async userBind({ type, mobile, passwd, code, org }) {
+    assert(mobile, '登录账户不能为空');
+    assert(passwd, '密码不能为空');
+    assert(type, '用户角色不能为空');
+    const userModel = this.ctx.model.User;
+    const res = await userModel.findOne({ mobile, type }, '+passwd');
+    if (!res) {
+      throw new BusinessError(ErrorCode.USER_NOT_EXIST);
+    }
+    if (res.passwd.secret !== passwd) {
+      throw new BusinessError(ErrorCode.BAD_PASSWORD);
+    }
+    const yjycModel = this.ctx.model.Yjyconnect;
+    const obj = { ycode: code, yorg: org, suid: ObjectId(res._id).toString() };
+    const isHas = await yjycModel.count({ suid: obj.suid });
+    if (isHas > 0) throw new BusinessError(ErrorCode.DATA_EXISTED, '账户已绑定,无需再次绑定');
+    await yjycModel.create(obj);
+    return obj.suid;
+  }
+
+  // 用户id获取用户信息,登录获取token返回
+  async userToken(id) {
+    assert(id, '缺少双困生平台用户标识');
+    const userModel = this.ctx.model.User;
+    const userService = this.ctx.service.login;
+    const user = await userModel.findById(id);
+    if (!user) throw new BusinessError(ErrorCode.USER_NOT_EXIST);
+    const token = await userService.createJwt(user);
+    return token;
+  }
+}
+module.exports = YunjiuyeService;

+ 5 - 0
config/config.local.js

@@ -60,5 +60,10 @@ module.exports = () => {
   //   },
   // };
 
+  config.yunjiuye = {
+    toBindPage: 'http://127.0.0.1', // 云就业绑定页面
+    toDealTokenPage: 'http://127.0.0.1', // 云就业免登录处理token路由
+  };
+
   return config;
 };

+ 4 - 0
config/config.prod.js

@@ -67,6 +67,10 @@ module.exports = () => {
       db: 0,
     },
   };
+  config.yunjiuye = {
+    toBindPage: 'http://jytz.jilinjobs.cn/train/y/', // 云就业绑定页面
+    toDealTokenPage: 'http://jytz.jilinjobs.cn/train/y/deal', // 云就业免登录处理token路由
+  };
 
   return config;
 };