apply.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. 'use strict';
  2. const assert = require('assert');
  3. const { after } = require('lodash');
  4. const _ = require('lodash');
  5. const moment = require('moment');
  6. const { ObjectId } = require('mongoose').Types;
  7. const { CrudService } = require('naf-framework-mongoose/lib/service');
  8. const { BusinessError, ErrorCode } = require('naf-core').Error;
  9. class ApplyService extends CrudService {
  10. constructor(ctx) {
  11. super(ctx, 'apply');
  12. this.model = this.ctx.model.Apply;
  13. this.tmodel = this.ctx.model.Teacher;
  14. this.submodel = this.ctx.model.Subject;
  15. this.trainmodel = this.ctx.model.Trainplan;
  16. this.umodel = this.ctx.model.User;
  17. this.nmodel = this.ctx.model.Notice;
  18. this.dayList = [ '日', '一', '二', '三', '四', '五', '六' ];
  19. }
  20. // 查询
  21. async queryteacher(query) {
  22. const { termid, subid, date } = query;
  23. const data = await this.model
  24. .find({ termid, subid, date })
  25. .sort({ msscore: -1 });
  26. const teachers = [];
  27. for (const _data of data) {
  28. const teacherid = _data.teacherid;
  29. const teacher = await this.tmodel.findById(teacherid);
  30. teachers.push(teacher);
  31. }
  32. return teachers;
  33. }
  34. /**
  35. * 教师计划初步课表安排,可反复使用
  36. * @param {Object} body planid:计划id,ids:期数id列表;classtype:班级类型
  37. */
  38. async arrangeteacher({ planid, ids, classtype }) {
  39. assert(planid, '缺少计划信息');
  40. const trainplan = await this.trainmodel.findById(planid);
  41. if (!trainplan) {
  42. throw new BusinessError(ErrorCode.DATA_EXISTED, '年度计划不存在');
  43. }
  44. // trainplan = JSON.parse(JSON.stringify(trainplan));
  45. // 查找所有教师列表
  46. let teacherList = await this.tmodel.find({ xsscore: { $exists: true } });
  47. teacherList = JSON.parse(JSON.stringify(teacherList));
  48. // 查找所有教师上报列表
  49. let teaplanList = await this.model.find();
  50. teaplanList = JSON.parse(JSON.stringify(teaplanList));
  51. // 课程
  52. let subjectList = await this.submodel.find();
  53. subjectList = JSON.parse(JSON.stringify(subjectList));
  54. const termList = _.cloneDeep(trainplan);
  55. let { termnum } = termList;
  56. if (!termnum) return;
  57. termnum = JSON.parse(JSON.stringify(termnum));
  58. // 整理出课表
  59. const arr = this.setLessonList(termnum);
  60. // 安排后的课表
  61. const afterList = [];
  62. // 排课
  63. for (const l of arr) {
  64. const { termid, subid, day: date, status, type, classid } = l;
  65. // 检验是否在需要安排的期内
  66. if (!ids.includes(termid)) {
  67. // 不在要求安排的期内,就直接放回去
  68. afterList.push(l);
  69. continue;
  70. }
  71. // 检查是否符合要求的班级类型
  72. if (classtype || `${classtype}` === '0') {
  73. // 不符合,放回去,下一个
  74. if (`${classtype}` !== `${type}`) {
  75. afterList.push(l);
  76. continue;
  77. }
  78. }
  79. if (status && `${status}` === '1') {
  80. afterList.push(l);
  81. continue;
  82. }
  83. // 重置教师
  84. l.teaid = null;
  85. l.teaname = null;
  86. const subject = subjectList.find(f => ObjectId(subid).equals(f._id));
  87. if (subject.need_teacher !== '0') {
  88. afterList.push(l);
  89. continue;
  90. }
  91. // 申请该天,该科目的教师,并查出教师的名字,分数;并按分数排序
  92. let applyList = teaplanList.filter(
  93. f => f.date === date && f.subid === subid
  94. );
  95. applyList = applyList.map(i => {
  96. let obj = { ...JSON.parse(JSON.stringify(i)) };
  97. const r = teacherList.find(f => i.teacherid === f._id);
  98. if (r) {
  99. const { name: teaname, xsscore: score } = r;
  100. i.teaname = teaname;
  101. i.score = score * 1;
  102. obj = { ...obj, teaname, score };
  103. }
  104. return obj;
  105. });
  106. // 过滤出没有分数的,不排
  107. applyList = applyList.filter(f => f.score);
  108. // 按成绩排序
  109. applyList = _.orderBy(applyList, [ 'score' ], [ 'desc' ]);
  110. // 本期超过2次的教师列表,如果没有人就用这里分最高的排 + 教过这个班的教师列表,不过内容都一样
  111. let outTwoTimesList = [];
  112. // 依次循环申请的教师列表,往这个课程安排中放教师
  113. for (const atea of applyList) {
  114. // 先查询,该教师,是否在今天有安排 条件1:同一天,一个教师只能有一次,因为一上一天课
  115. const tr = afterList.find(
  116. f => f.teaid === atea.teacherid && f.day === atea.date
  117. );
  118. if (tr) continue;
  119. // 条件2:优先排一期2次以内的教师,超过2次的教师延后排,根据 次数升序,分数降序找合适的;
  120. // 查看这期内,每个申请上课的教师时候超过2天(2条记录),如果超过,则不排,但是如果最后没有人了,就得硬排了
  121. const r = afterList.filter(
  122. f => f.termid === termid && f.teaid === atea.teacherid
  123. );
  124. if (r.length >= 2) {
  125. // 需要记录这个老师已经有几次
  126. const obj = { ...atea, times: r.length };
  127. outTwoTimesList = [ ...outTwoTimesList, obj ];
  128. continue;
  129. } else {
  130. // 条件3:尽量不让一个教师在一个班出现2次及其以上,但是如果没人,之前又排完了,还是会出现一个教师教1个班2天的情况,所以需要最后收尾检查
  131. const alreadyTeach = afterList.find(
  132. f => f.classid === classid && f.teaid === atea.teacherid
  133. );
  134. if (alreadyTeach) {
  135. // 已经教过这个班了,也暂时放到2次以上列表中,将次数记录下来
  136. const obj = { ...atea, times: r.length };
  137. outTwoTimesList = [ ...outTwoTimesList, obj ];
  138. continue;
  139. }
  140. l.teaid = atea.teacherid;
  141. l.teaname = atea.teaname;
  142. break;
  143. }
  144. }
  145. // 检查,该天,该科的课是否有教师
  146. const has_teaid = _.get(l, 'teaid');
  147. if (!has_teaid) {
  148. // 如果没有教师,就需要在outTowTimesList列表中找分最高的教师
  149. // 排序需要根据,次数(后加的),分数排序,优先选次数最少,分数最高的教师
  150. const list = _.orderBy(
  151. outTwoTimesList,
  152. [ 'times', 'score' ],
  153. [ 'asc', 'desc' ]
  154. );
  155. for (const i of list) {
  156. const tr = afterList.find(
  157. f => f.teaid === i.teacherid && f.day === i.date
  158. );
  159. if (tr) continue;
  160. else {
  161. l.teaid = i.teacherid;
  162. l.teaname = i.teaname;
  163. break;
  164. }
  165. }
  166. }
  167. afterList.push(l);
  168. }
  169. // 需要按classid分组,然后查每组下,有没有重复教师,如果有重复教师,提取出这个教师的日期,科目,分2种情况:
  170. // 1)可以和其他班教师换下位置;2)没法换,只能排下个教师
  171. // 查找这天,这科的 课程安排 且 这些课程的教师 没给这个班级上过课 (undefined也算,每排教师)
  172. // =>如果有满足条件的教师, 找到该班, 然后查看,现在需要换的这个教师是否也满足 没给这个班上过课 的条件
  173. // =>满足条件,两个班级的教师对调
  174. // =>不满足条件直至没有教师,需要整理出 applyList,然后将现在这个教师排除掉(放到一个空间),然后找其他满足条件的教师,如果没有,那就只能有他了
  175. const checkList = afterList.filter(f => ids.includes(f.termid) && f.type === classtype && f.teaid);
  176. const groupObj = _.groupBy(checkList, 'classid');
  177. const keys = Object.keys(groupObj);
  178. const exchangeList = [];
  179. for (const key of keys) {
  180. const arr = groupObj[key];
  181. const teaids = arr.map(i => _.pick(i, [ 'day', 'subid', 'teaid' ]));
  182. for (const l of arr) {
  183. const { day, subid, teaid, teaname, termid } = l;
  184. // 找下这个教师在这个班级中,是否教了多科
  185. let findres = teaids.filter(f => f.teaid === teaid);
  186. // 2科以下,跳过不看
  187. if (findres.length < 2) continue;
  188. // 2科以上,需要找到每一天的申请名单,可最多的那天先换
  189. // 先查下同一天,同一科的教师能不能换
  190. const toDaySubjectList = afterList.filter(f => f.subid === subid && f.day === day && f.teaid !== teaid);
  191. let sameSubChange = false;
  192. for (const tdstea of toDaySubjectList) {
  193. // 找一下,这个教师能不能换到这个班和当前重复教一个班的教师能不能带这个教师的班
  194. // 为什么这么找:因为到这里之前,所有需要安排的课程,已经按照1,2原则排完,是最优解,所以尽可能在最优解之间进行调换,
  195. // 如果最优解没有办法调换,那就只能往下找了,对于两个班的情况可能常见,但是对于三个班来说基本就很少了,如果开4个班,基本就不存在这个问题了,
  196. // 循环的教师,需要在teaids中找有没有这个教师
  197. const first = teaids.find(f => f.teaid === tdstea.teaid);
  198. if (first) continue;
  199. else {
  200. // 如果这个教师可以,需要进行反查,查当前有问题的这个教师,在没在要和他换的教师班级里讲过课
  201. const { classid } = tdstea;
  202. const tdsLessonClass = groupObj[classid];
  203. const sec = tdsLessonClass.find(f => f.teaid === teaid);
  204. // 如果这个教师教过要调换教师那个班,就继续找看下个老师
  205. if (sec) continue;
  206. sameSubChange = tdstea;
  207. }
  208. }
  209. // 判断sameSubChange,如果不为false,则说明当天教师可以替换,接着continue就行
  210. if (sameSubChange) {
  211. const { teaid: oteaid, teaname: oteaname } = sameSubChange;
  212. // 要替换的索引
  213. const oindex = afterList.findIndex(f => _.isEqual(f, sameSubChange));
  214. // 重复老师的索引
  215. const tindex = afterList.findIndex(f => _.isEqual(f, l));
  216. // 交换
  217. afterList[oindex].teaid = teaid;
  218. afterList[oindex].teaname = teaname;
  219. afterList[tindex].teaid = oteaid;
  220. afterList[tindex].teaname = oteaname;
  221. continue;
  222. }
  223. // 如果到这里了,也就是说同天同科的教师都替换不了,那就是一点血找也没有了
  224. for (const les of findres) {
  225. // 申请的教师
  226. let applyList = teaplanList.filter(
  227. f => f.date === les.day && f.subid === les.subid && f.teacherid !== les.teaid
  228. );
  229. applyList = applyList.map(i => {
  230. let obj = { ...JSON.parse(JSON.stringify(i)) };
  231. const r = teacherList.find(f => i.teacherid === f._id);
  232. if (r) {
  233. const { name: teaname, xsscore: score } = r;
  234. i.teaname = teaname;
  235. i.score = score * 1;
  236. obj = { ...obj, teaname, score };
  237. }
  238. return obj;
  239. });
  240. // 过滤出没有分数的,不排
  241. applyList = applyList.filter(f => f.score);
  242. // 过滤出当天有课的教师
  243. applyList = applyList.filter(f => !(afterList.find(af => af.day === f.day && af.teaid === f.teaid)));
  244. // 过滤出这期有几次
  245. applyList = applyList.map(i => {
  246. // 找到这个教师在这期有几次
  247. const r = afterList.filter(f => f.termid === termid && f.teaid === i.teaid);
  248. i.times = r.length;
  249. return i;
  250. });
  251. // 按成绩排序
  252. applyList = _.orderBy(applyList, [ 'times', 'score' ], [ 'asc', 'desc' ]);
  253. // 整理出教师教这个班的所有科目的其他可选教师(排除已经排完课的教师)
  254. les.applyList = applyList;
  255. les.applynum = applyList.length;
  256. }
  257. // 按照申请人数排序,然后看看人最多那天是不是这天,如果是这天,就处理
  258. findres = _.orderBy(findres, [ 'applynum' ], [ 'desc' ]);
  259. const head = _.head(findres);
  260. if (head.day === day) {
  261. // 如果当前日期,是申请人数最多的,就处理它
  262. const { applyList } = head;
  263. if (applyList.length >= 0) {
  264. // 将排完序的第一个教师拿出来(一定是符合要求的)
  265. const apply = _.head(applyList);
  266. const { teaid, teaname } = apply;
  267. const tindex = afterList.findIndex(f => _.isEqual(f, l));
  268. afterList[tindex].teaid = teaid;
  269. afterList[tindex].teaname = teaname;
  270. }
  271. }
  272. }
  273. }
  274. // 将afterList还原回正常的termnum;
  275. const newTermnum = this.returnTermnum(afterList, termnum);
  276. // 保存至计划
  277. trainplan.termnum = newTermnum;
  278. await trainplan.save();
  279. }
  280. // 确认计划安排
  281. async arrangeConfirm({ planid, ids, classtype }) {
  282. const trainplan = await this.trainmodel.findById(planid);
  283. if (!trainplan) {
  284. throw new BusinessError(ErrorCode.DATA_EXISTED, '年度计划不存在');
  285. }
  286. const plan = _.cloneDeep(trainplan);
  287. let { termnum } = plan;
  288. if (!termnum) return;
  289. termnum = JSON.parse(JSON.stringify(termnum));
  290. // 过滤出确认的期,TODO:没有做通知
  291. // termnum = termnum.filter(f => );
  292. // 找到每个教师的位置,然后把状态(status)改成1=>已确认
  293. for (const t of termnum) {
  294. if (!ids.includes(t._id)) continue;
  295. const { term } = t;
  296. if (!(t.batchnum && _.isArray(t.batchnum))) continue;
  297. for (const b of t.batchnum) {
  298. const { batch } = b;
  299. if (!(b.class && _.isArray(b.class))) continue;
  300. for (const c of b.class) {
  301. // 检查是否要求班级类型
  302. if (classtype || `${classtype}` === '0') {
  303. // 获取这个班级的班级类型
  304. const { type } = c;
  305. // 判断班级类型与要求的符不符合,不符合就跳过不改
  306. if (`${type}` !== `${classtype}`) continue;
  307. }
  308. if (!(c.lessons && _.isArray(c.lessons))) continue;
  309. for (const l of c.lessons) {
  310. l.status = '1';
  311. }
  312. }
  313. }
  314. }
  315. trainplan.termnum = termnum;
  316. await trainplan.save();
  317. }
  318. /**
  319. * 拍平了的课表=>termnum
  320. * @param {Array} list 拍平了的课表,详情参考页面的初步课表的数据
  321. * @param {Array} termnum 原termnum
  322. */
  323. returnTermnum(list, termnum) {
  324. let newTermnum = [];
  325. for (const l of list) {
  326. const { termid, batchid, classid, ...info } = l;
  327. const updata = _.pick(info, [
  328. 'day',
  329. 'subid',
  330. 'subname',
  331. 'teaid',
  332. 'teaname',
  333. 'time',
  334. 'status',
  335. ]);
  336. newTermnum = termnum.map(t => {
  337. // 找到期
  338. if (termid === t._id) {
  339. t.batchnum = t.batchnum.map(b => {
  340. if (batchid === b._id) {
  341. // 找到批次
  342. b.class = b.class.map(c => {
  343. if (classid === c._id) {
  344. if (c.lessons) {
  345. // 说明有课程安排,找有没有重复的,没有就推进去,有就更改,subid查
  346. const r = c.lessons.find(f => f.subid === updata.subid);
  347. if (r) {
  348. const rindex = c.lessons.findIndex(
  349. f => f.subid === updata.subid
  350. );
  351. c.lessons[rindex] = updata;
  352. } else {
  353. c.lessons.push(updata);
  354. }
  355. } else {
  356. // 说明没有课程安排,放进去一条保存
  357. c.lessons = [ updata ];
  358. }
  359. }
  360. return c;
  361. });
  362. }
  363. return b;
  364. });
  365. }
  366. return t;
  367. });
  368. }
  369. return newTermnum;
  370. }
  371. /**
  372. * 将课表拍平了,从多维=>一维
  373. * @param {Array} termnum 计划的termnum
  374. */
  375. setLessonList(termnum) {
  376. let arr = [];
  377. for (const t of termnum) {
  378. const { batchnum, term, _id: termid } = t;
  379. // 班级和课程一一匹
  380. for (const b of batchnum) {
  381. const { class: classes, lessons, _id: batchid } = b;
  382. const claslesList = this.setList(
  383. term * 1,
  384. termid,
  385. batchid,
  386. classes,
  387. lessons
  388. );
  389. arr.push(...claslesList);
  390. }
  391. }
  392. arr = _.orderBy(arr, [ 'term', 'day' ], [ 'asc', 'asc' ]);
  393. return arr;
  394. }
  395. /**
  396. * 将课表模板和班级整理成一维数组
  397. * @param {String} term 期数
  398. * @param {String} termid 期id
  399. * @param {String} batchid 批id
  400. * @param {Array} classes 班级列表
  401. * @param {Array} lessonTemplate 课表模板
  402. */
  403. setList(term, termid, batchid, classes, lessonTemplate) {
  404. const arr = [];
  405. // 班级和课程匹配
  406. for (const cla of classes) {
  407. let { lessons } = cla;
  408. if (!lessons) lessons = lessonTemplate;
  409. for (const i of lessons) {
  410. let nobj = {};
  411. nobj.term = term;
  412. nobj.termid = termid;
  413. nobj.batchid = batchid;
  414. nobj.type = cla.type;
  415. const obj = _.omit(cla, [ 'lessons' ]);
  416. nobj.classid = _.clone(cla._id);
  417. nobj = _.assign(nobj, obj);
  418. nobj = _.assign(nobj, i);
  419. arr.push(nobj);
  420. }
  421. }
  422. return arr;
  423. }
  424. /**
  425. * 发送消息
  426. * @param {Object} param planid:年度计划id,ids,发送的期列表;classtype:发送班级类型 undefined 都发,有的话就找指定班级类型发
  427. */
  428. async arrangeSendMsg({ planid, ids, classtype }) {
  429. const trainplan = await this.trainmodel.findById(planid);
  430. if (!trainplan) {
  431. throw new BusinessError(ErrorCode.DATA_EXISTED, '年度计划不存在');
  432. }
  433. // 大批次id,年度计划id
  434. const plan = _.cloneDeep(trainplan);
  435. let { termnum, planyearid } = plan;
  436. if (!termnum) return;
  437. termnum = JSON.parse(JSON.stringify(termnum));
  438. // 整理出课表
  439. let arr = this.setLessonList(termnum);
  440. // 过滤出需要发送的教师
  441. arr = arr.filter(f => ids.find(id => f.termid === id) && f.teaid);
  442. // && f.status !== '1'
  443. // 整理出要发送的教师列表
  444. let teaids = arr.map(i => i.teaid);
  445. teaids = _.uniq(teaids);
  446. // 找到教师信息
  447. let teaList = await this.tmodel.find({ _id: teaids });
  448. // 找到教师用户信息
  449. let teauserList = await this.umodel.find({ uid: teaids });
  450. if (teaList) teaList = JSON.parse(JSON.stringify(teaList));
  451. if (teauserList) teauserList = JSON.parse(JSON.stringify(teauserList));
  452. // 发送,此处是根据安排,给教师发.还有一种方案是根据教师,整理安排一起发送
  453. // 查询是否发送过这期的通知
  454. // 排序
  455. arr = _.orderBy(arr, [ 'day' ], [ 'asc' ]);
  456. for (const l of arr) {
  457. // 教师id,期数,班级名,上课的日期,课程名
  458. const {
  459. teaid,
  460. term,
  461. name,
  462. day,
  463. subname,
  464. termid,
  465. classid,
  466. type,
  467. status,
  468. } = l;
  469. // 已确认的教师不发信息
  470. if (status === '1') continue;
  471. // 判断发送的班级类型
  472. if (!(classtype && classtype === type)) continue;
  473. const tea = teaList.find(f => f._id === teaid);
  474. const teauser = teauserList.find(f => f.uid === teaid);
  475. // 文案
  476. let msg = `${_.get(tea, 'name', '')}老师您好:
  477. 吉林省高等学校毕业生就业指导中心-双困生培训系统提醒您:
  478. ${term}期-${name.includes('班') ? name : `${name}班`}
  479. ${day}(星期${this.dayList[moment(day).days()]})
  480. 有您的课程安排:${subname}`;
  481. msg = `${msg}\n 如果您无法进行授课,请及时联系中心负责人`;
  482. const { openid } = teauser;
  483. let tourl;
  484. let to_send = false;
  485. if (openid) {
  486. let notice = await this.nmodel.findOne({
  487. planid,
  488. termid,
  489. classid,
  490. type: '6',
  491. });
  492. // 找下是否发过信息
  493. if (notice) {
  494. // 发过信息,找有没有这个教师
  495. const { notified } = notice;
  496. if (_.isArray(notified)) {
  497. const has_notice = notified.find(f => f.notifiedid === teaid);
  498. if (has_notice) {
  499. const { status } = has_notice;
  500. if (status !== '1') to_send = true;
  501. } else {
  502. const obj = {
  503. notifiedid: teaid,
  504. username: _.get(tea, 'name', ''),
  505. content: msg,
  506. };
  507. notice.notified.push(obj);
  508. await notice.save();
  509. to_send = true;
  510. }
  511. }
  512. } else {
  513. const notified = [
  514. {
  515. notifiedid: teaid,
  516. username: _.get(tea, 'name', ''),
  517. content: msg,
  518. },
  519. ];
  520. const noticeObj = {
  521. planyearid,
  522. planid,
  523. termid,
  524. classid,
  525. noticeid: 'system',
  526. type: '6',
  527. content: `${term}期-${
  528. name.includes('班') ? name : `${name}班`
  529. }教师计划初步信息确认`,
  530. notified,
  531. };
  532. await this.nmodel.create(noticeObj);
  533. notice = await this.nmodel.findOne({
  534. planid,
  535. termid,
  536. classid,
  537. type: '6',
  538. });
  539. to_send = true;
  540. }
  541. tourl =
  542. this.ctx.app.config.baseUrl +
  543. '/msgconfirm/?userid=' +
  544. teaid +
  545. '&noticeid=' +
  546. notice._id;
  547. }
  548. if (to_send) {
  549. // 邮箱与微信都发送
  550. const { email } = tea;
  551. if (email) {
  552. this.toSendEmail(email, msg, tea.name);
  553. }
  554. if (openid) {
  555. this.toSendWxMsg(openid, msg, tea.name, tourl);
  556. }
  557. }
  558. }
  559. }
  560. /**
  561. * 计划-教师初步课表发送邮件
  562. * @param {String} email 邮件
  563. * @param {String} content 内容
  564. * @param {String} teaname 教师姓名
  565. */
  566. async toSendEmail(email, content, teaname) {
  567. if (!email) {
  568. console.error(`计划教师发送通知:${teaname}没有email`);
  569. return;
  570. }
  571. const subject = '吉林省高等学校毕业生就业指导中心通知(系统邮件,请勿回复)'; //
  572. this.ctx.service.util.sendMail(email, subject, content);
  573. }
  574. /**
  575. * 计划-教师初步课表发送微信推送
  576. * @param {String} openid 微信公众号的openid
  577. * @param {String} content 内容
  578. * @param {String} teaname 教师姓名
  579. * @param {String} tourl 确认地址
  580. */
  581. async toSendWxMsg(openid, content, teaname, tourl) {
  582. if (!openid) {
  583. console.error(`计划教师发送微信推送:${teaname}没有openid`);
  584. return;
  585. }
  586. // TODO or notTODO 发送微信推送记录
  587. await this.ctx.service.weixin.sendTemplateDesign(
  588. this.ctx.app.config.REVIEW_TEMPLATE_ID,
  589. openid,
  590. '您有一个新的通知',
  591. '您有新的安排',
  592. content,
  593. '感谢您的使用',
  594. tourl
  595. );
  596. }
  597. async repealConfirm({ planid, ids }) {
  598. // 将指定计划,期数的教师状态解除确认
  599. let trainPlan = await this.ctx.model.Trainplan.findById(planid);
  600. trainPlan = JSON.parse(JSON.stringify(trainPlan));
  601. let terms = {};
  602. for (const term of trainPlan.termnum) {
  603. const in_ids = ids.find(f => ObjectId(f).equals(term._id));
  604. if (in_ids) {
  605. for (const batch of term.batchnum) {
  606. for (const c of batch.class) {
  607. for (const l of c.lessons) {
  608. l.status = '0';
  609. }
  610. }
  611. }
  612. terms = term;
  613. }
  614. }
  615. // const i = trainPlan.termnum.findIndex(f => ObjectId('5f5aed5e69b4221aedaa5005').equals(f._id));
  616. // trainPlan.termnum[i] = terms;
  617. delete trainPlan.meta;
  618. const r = await this.ctx.model.Trainplan.update(
  619. { _id: ObjectId('5f5adb337ceb003386c9b0d4') },
  620. { ...trainPlan }
  621. );
  622. }
  623. }
  624. module.exports = ApplyService;