trainplan.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. 'use strict';
  2. const _ = require('lodash');
  3. const { CrudService } = require('naf-framework-mongoose/lib/service');
  4. const assert = require('assert');
  5. const { BusinessError, ErrorCode } = require('naf-core').Error;
  6. const XLSX = require('xlsx');
  7. const utils = require('../utils/utils.js');
  8. class TrainplanService extends CrudService {
  9. constructor(ctx) {
  10. super(ctx, 'trainplan');
  11. this.model = this.ctx.model.Trainplan;
  12. this.clamodel = this.ctx.model.Class;
  13. this.umodel = this.ctx.model.User;
  14. this.smodel = this.ctx.model.School;
  15. this.tmodel = this.ctx.model.Teacher;
  16. this.stumodel = this.ctx.model.Student;
  17. this.schmodel = this.ctx.model.Schtime;
  18. }
  19. // async create(data) {
  20. // const terminfo = await data.termnum;
  21. // console.log(terminfo);
  22. // const { batchnum: { type, name, number }, term } = terminfo;
  23. // console.log(type);
  24. // if (type === 1) {
  25. // const classdata = { name, number, term, type };
  26. // await this.clamodel.create(classdata);
  27. // }
  28. // if (type === 0) {
  29. // for (let i = 0; i < class; i++) {
  30. // const name = '第' + term + '期' + batch + '批次' + i + '班';
  31. // const classdate = { name, number, term, type, newbatch };
  32. // await this.clamodel.create(classdate);
  33. // }
  34. // }
  35. // return this.tpmodel.create(data);
  36. // }
  37. // }
  38. async update({ id }, data) {
  39. const trainplan = await this.model.findById(id);
  40. // 保存原数据
  41. const trainplanold = _.cloneDeep(trainplan);
  42. const { year, title, termnum, festivals, status, school } = data;
  43. if (year) {
  44. trainplan.year = year;
  45. }
  46. if (title) {
  47. trainplan.title = title;
  48. }
  49. if (termnum) {
  50. trainplan.termnum = termnum;
  51. }
  52. if (school) {
  53. trainplan.school = school;
  54. }
  55. if (festivals) {
  56. trainplan.festivals = festivals;
  57. }
  58. if (status === '1') {
  59. trainplan.status = status;
  60. }
  61. // 如果培训计划状态改为发布,发送培训计划信息,并自动生成班级
  62. const res = await trainplan.save();
  63. if (res) {
  64. if (status === '1') {
  65. // 自动生成班级
  66. // await this.autoclass(res, trainplanold);
  67. // await this.autoclassNew(res, trainplanold);
  68. // 将生成的班级重新将班级排班名
  69. // await this.autoclassname(res);
  70. // 发送培训计划信息通知给相应人员
  71. // 查询所有入库的教师
  72. const teachers = await this.tmodel.find({ status: '4' });
  73. for (const teacher of teachers) {
  74. const teacherid = teacher._id;
  75. const _teacher = await this.umodel.findOne({
  76. uid: teacherid,
  77. type: '3',
  78. });
  79. const openid = _teacher.openid;
  80. const detail = trainplan.title + '已发布,请注意查收!';
  81. const date = await this.ctx.service.util.updatedate();
  82. const remark = '感谢您的使用';
  83. if (openid) {
  84. this.ctx.service.weixin.sendTemplateMsg(
  85. this.ctx.app.config.REVIEW_TEMPLATE_ID,
  86. openid,
  87. '您有一个新的通知',
  88. detail,
  89. date,
  90. remark
  91. );
  92. }
  93. }
  94. // 查询所有学校用户
  95. const schools = await this.umodel.find({ type: '2' });
  96. for (const school of schools) {
  97. const openid = school.openid;
  98. const detail = trainplan.title + '已发布,请注意查收!';
  99. const date = await this.ctx.service.util.updatedate();
  100. const remark = '感谢您的使用';
  101. if (openid) {
  102. this.ctx.service.weixin.sendTemplateMsg(
  103. this.ctx.app.config.REVIEW_TEMPLATE_ID,
  104. openid,
  105. '您有一个新的通知',
  106. detail,
  107. date,
  108. remark
  109. );
  110. }
  111. }
  112. }
  113. }
  114. return res;
  115. }
  116. // 自动生成班级私有方法
  117. async autoclassNew(res) {
  118. // 删除所有计划下的班级
  119. await this.clamodel.deleteMany({ planid: res.id });
  120. // 循环出所有班级进行添加操作
  121. for (const term of res.termnum) {
  122. for (const batch of term.batchnum) {
  123. const classs = await batch.class;
  124. for (const cla of classs) {
  125. const newdata = {
  126. name: cla.name,
  127. number: cla.number,
  128. batchid: batch.id,
  129. termid: term.id,
  130. planid: res.id,
  131. type: cla.type,
  132. headteacherid: cla.headteacherid,
  133. };
  134. await this.clamodel.create(newdata);
  135. }
  136. }
  137. }
  138. }
  139. // 自动生成班级私有方法
  140. async autoclass(res, trainplanold) {
  141. // 首先比较当前数据和原数据的值是否有不同
  142. // 保存后所有期id
  143. const tremid_res = _.map(res.termnum, 'id');
  144. // 保存前所有期id
  145. const tremid_old = _.map(trainplanold.termnum, 'id');
  146. // 取得要删除的期id,进行班级中删除已删除期的班级
  147. const deltrem = _.difference(tremid_old, tremid_res);
  148. // 循环删除已经删除期的所有班级
  149. for (const elm of deltrem) {
  150. await this.clamodel.deleteMany({ termid: elm });
  151. }
  152. // 取得所有新加期id
  153. const addtrem = _.difference(tremid_res, tremid_old);
  154. // 清空后循环取得所有期进行批次操作
  155. const terms = res.termnum;
  156. for (const el of terms) {
  157. // 判断是否新加期
  158. if (_.indexOf(addtrem, el.id) !== -1) {
  159. // 循环当前新加期的批次列表,根据批次id和班级数生成班级信息
  160. const batchnums = el.batchnum;
  161. for (const batchnum of batchnums) {
  162. // 取得当前批次的班级数
  163. const classnum = batchnum.class;
  164. for (const cla of classnum) {
  165. const newdata = {
  166. name: cla.name,
  167. number: cla.number,
  168. batchid: batchnum.id,
  169. termid: el.id,
  170. planid: res.id,
  171. type: cla.type,
  172. };
  173. await this.clamodel.create(newdata);
  174. }
  175. }
  176. } else {
  177. // 不是新加期,更新期信息
  178. // 保存后所有期id
  179. const batchid_res = _.map(el.batchnum, 'id');
  180. // 保存前所有期id
  181. const batchid_old = _.map(
  182. trainplanold.termnum.id(el.id).batchnum,
  183. 'id'
  184. );
  185. // 取得要删除的期id,进行班级中删除已删除期的班级
  186. const delbatchs = _.difference(batchid_old, batchid_res);
  187. // 循环删除已经删除期的所有班级
  188. for (const delba of delbatchs) {
  189. await this.clamodel.deleteMany({ termid: el.id, batchid: delba });
  190. }
  191. // 取得所有新加期id
  192. const addbatch = _.difference(batchid_res, batchid_old);
  193. const batchnums = el.batchnum;
  194. for (const batchnum of batchnums) {
  195. // 取得当前批次是否有删除
  196. // 判断是否新加期
  197. if (_.indexOf(addbatch, batchnum.id) !== -1) {
  198. // 取得当前批次的班级数
  199. const classnum = batchnum.class;
  200. for (const cla of classnum) {
  201. const newdata = {
  202. name: cla.name,
  203. number: cla.number,
  204. batchid: batchnum.id,
  205. termid: el.id,
  206. planid: res.id,
  207. type: cla.type,
  208. };
  209. await this.clamodel.create(newdata);
  210. }
  211. } else {
  212. if (
  213. batchnum.class ===
  214. trainplanold.termnum.id(el.id).batchnum.id(batchnum.id).class
  215. ) {
  216. // 编辑只会针对班级人数进行修改。
  217. const _class = await this.clamodel.find({
  218. termid: el.id,
  219. batchid: batchnum.id,
  220. });
  221. if (_class.length !== 0) {
  222. for (const ee of _class) {
  223. ee.number = batchnum.number;
  224. await ee.save();
  225. }
  226. } else {
  227. const classnum = batchnum.class;
  228. for (const cla of classnum) {
  229. const newdata = {
  230. name: cla.name,
  231. number: cla.number,
  232. batchid: batchnum.id,
  233. termid: el.id,
  234. planid: res.id,
  235. type: cla.type,
  236. };
  237. await this.clamodel.create(newdata);
  238. }
  239. }
  240. } else {
  241. // 当班级数有更改时
  242. // 删除所有班级 并重新生成班级
  243. await this.clamodel.deleteMany({
  244. termid: el.id,
  245. batchid: batchnum.id,
  246. });
  247. const classnum = batchnum.class;
  248. for (const cla of classnum) {
  249. const newdata = {
  250. name: cla.name,
  251. number: cla.number,
  252. batchid: batchnum.id,
  253. termid: el.id,
  254. planid: res.id,
  255. type: cla.type,
  256. };
  257. await this.clamodel.create(newdata);
  258. }
  259. }
  260. }
  261. }
  262. }
  263. }
  264. }
  265. // // 将分好的班级重新编排名字
  266. // async autoclassname(res) {
  267. // // 取得所有期id
  268. // const tremid_res = _.map(res.termnum, 'id');
  269. // for (const termid of tremid_res) {
  270. // const classs = await this.clamodel.find({ planid: res.id, termid });
  271. // let i = 0;
  272. // for (const cla of classs) {
  273. // i = i + 1;
  274. // cla.name = i;
  275. // await cla.save();
  276. // }
  277. // }
  278. // }
  279. async exportExcel({ trainplanIds }) {
  280. const nowDate = new Date().getTime();
  281. const path =
  282. 'D:\\wwwroot\\service\\service-file\\upload\\train\\' + nowDate + '.xlsx';
  283. const respath =
  284. 'http://free.liaoningdoupo.com:80/files/train/' + nowDate + '.xlsx';
  285. const wb = {
  286. SheetNames: [],
  287. Sheets: {},
  288. };
  289. for (let i = 0; i < trainplanIds.length; i++) {
  290. // 批次期次都在这里面
  291. const trainplan = await this.model.findOne({ _id: trainplanIds[i] });
  292. // 这个计划下所有的学生
  293. const studentList = await this.stumodel.find({ planid: trainplanIds[i] });
  294. // 计划名称
  295. const trainplandName = trainplan.title;
  296. // 在计划中找到这个学生在哪期以及哪期下的哪批次
  297. for (const student of studentList) {
  298. student.isComming = utils.getIsNot(student.isComming);
  299. student.trainplandName = trainplandName;
  300. // 期次
  301. const term = trainplan.termnum.filter(term => {
  302. return term.id === student.termid;
  303. });
  304. if (term.length > 0) {
  305. student.termName = term[0].term;
  306. }
  307. // 批次
  308. if (term.length !== 0) {
  309. const batch = term[0].batchnum.filter(batch => {
  310. return batch.id === student.batchid;
  311. });
  312. if (batch.length > 0) {
  313. student.batchName = JSON.parse(JSON.stringify(batch[0])).name;
  314. }
  315. }
  316. student.is_fine = utils.getIsNot(student.is_fine);
  317. }
  318. const _headers = [
  319. { key: 'trainplandName', title: '计划标题' },
  320. { key: 'termName', title: '期次' },
  321. { key: 'batchName', title: '批次' },
  322. { key: 'school_name', title: '学校' },
  323. { key: 'faculty', title: '院系' },
  324. { key: 'major', title: '专业' },
  325. { key: 'name', title: '姓名' },
  326. { key: 'id_number', title: '身份证号' },
  327. { key: 'phone', title: '手机号' },
  328. { key: 'gender', title: '性别' },
  329. { key: 'nation', title: '民族' },
  330. { key: 'edua_level', title: '学历层次' },
  331. { key: 'edua_system', title: '学制' },
  332. { key: 'entry_year', title: '入学年份' },
  333. { key: 'finish_year', title: '毕业年份' },
  334. { key: 'school_job', title: '在校职务' },
  335. { key: 'qq', title: 'QQ号' },
  336. { key: 'email', title: '邮箱' },
  337. // { key: 'openid', title: '微信openid' },
  338. { key: 'family_place', title: '家庭位置' },
  339. { key: 'family_is_hard', title: '是否困难' },
  340. { key: 'have_grant', title: ' 是否获得过助学金' },
  341. // { key: 'job', title: '职务' },
  342. { key: 'bedroom', title: '寝室号' },
  343. { key: 'is_fine', title: '是否优秀' },
  344. { key: 'isComming', title: '是否签到' },
  345. { key: 'selfscore', title: '个人分' },
  346. { key: 'score', title: '总分' },
  347. ];
  348. // 需要打出的列表
  349. const _data = studentList;
  350. const headers = _headers.map(({ title }) =>
  351. title).map((v, i) =>
  352. Object.assign({}, { v, position: String.fromCharCode(65 + i) + 1 })
  353. ).reduce((prev, next) =>
  354. Object.assign({}, prev, { [next.position]: { v: next.v } }),
  355. {}
  356. );
  357. const data = _data.map((v, i) =>
  358. _headers.map(({ key }, j) =>
  359. Object.assign(
  360. {},
  361. { v: v[key], position: String.fromCharCode(65 + j) + (i + 2) }
  362. )
  363. )
  364. ).reduce((prev, next) =>
  365. prev.concat(next)).reduce(
  366. (prev, next) =>
  367. Object.assign({}, prev, { [next.position]: { v: next.v } }),
  368. {}
  369. );
  370. // 合并 headers 和 data
  371. const output = Object.assign({}, headers, data);
  372. // 获取所有单元格的位置
  373. const outputPos = Object.keys(output);
  374. // 计算出范围
  375. const ref = outputPos[0] + ':' + outputPos[outputPos.length - 1];
  376. // 构建 workbook 对象
  377. wb.SheetNames.push('sheet' + i);
  378. wb.Sheets['sheet' + i] = Object.assign({}, output, { '!ref': ref });
  379. }
  380. // 导出 Excel
  381. XLSX.writeFile(wb, path);
  382. return respath;
  383. }
  384. // 导出学校大表
  385. async exportSchool({ trainplanId }) {
  386. // 备注
  387. const remarks = [];
  388. // 期数
  389. let termCount = [];
  390. // 班级数
  391. const classCount = [];
  392. // 日期
  393. const studyTime = [];
  394. // 合并单元格坐标
  395. const colRows = [];
  396. // 列起始
  397. let colzb = 3;
  398. // 行起始
  399. const rowzb = 1;
  400. // const colRow = {
  401. // s: { c: 3, r: rowzb },
  402. // e: { c: 6, r: rowzb },
  403. // };
  404. // colRows.push(colRow);
  405. const shcoolList = [];
  406. // 计划表
  407. const trainplan = await this.model.findOne({ _id: trainplanId });
  408. // 学校报名表
  409. const schtime = await this.schmodel.find({ planid: trainplanId });
  410. // 期次
  411. const termnums = trainplan.termnum;
  412. // 学校学校数据
  413. // const schools = trainplan.school;
  414. const schools = await this.smodel.find({});
  415. // 组装学校数据
  416. for (let i = 0; i < schools.length; i++) {
  417. // 学校数据
  418. const shcool = [];
  419. // 序号
  420. shcool.push(i + 1);
  421. // 学校名
  422. shcool.push(schools[i].name);
  423. // 总人数
  424. shcool.push('');
  425. for (const termnum of termnums) {
  426. // 批次
  427. const batchnum = termnum.batchnum;
  428. // 期次所占的格(期占格)
  429. const qizhange = batchnum.length - 1;
  430. /**
  431. * 合并单元格元素(decode_range方法解析数据格式)
  432. {
  433. s: { //s start 开始
  434. c: 1,//cols 开始列
  435. r: 0 //rows 开始行
  436. },
  437. e: {//e end 结束
  438. c: 4,//cols 结束列
  439. r: 0 //rows 结束行
  440. }
  441. }
  442. */
  443. // 添加坐标
  444. const colRow = {
  445. s: { c: colzb, r: rowzb },
  446. e: { c: colzb + qizhange, r: rowzb },
  447. };
  448. // colzb为上一次终止,那么起始需+1,
  449. colzb = colzb + qizhange + 1;
  450. colRows.push(colRow);
  451. // 向其中加入空格,以备合并单元格使用
  452. const qi = [];
  453. qi.push(termnum.term);
  454. for (let index = 0; index < qizhange; index++) {
  455. qi.push('');
  456. }
  457. termCount = [ ...termCount, ...qi ];
  458. // 循环
  459. for (const batch of batchnum) {
  460. // 把班级数与日期放入数组中
  461. classCount.push(batch.class.length);
  462. let startDate = batch.startdate;
  463. startDate = startDate.substr(5, 2) + '.' + startDate.substr(8, 2);
  464. let endDate = batch.enddate;
  465. endDate = endDate.substr(5, 2) + '.' + endDate.substr(8, 2);
  466. studyTime.push(startDate + '-' + endDate);
  467. // 拿着batch的id去schtime表中的arrange中查remark,将结果存入remarks中即可完成备注数组
  468. let remark = '';
  469. for (const sch of schtime) {
  470. // 计划中学校的code=上报时的code
  471. if (schools[i].code === sch.schid) {
  472. for (const arrange of sch.arrange) {
  473. if (arrange.batchid === batch.id) {
  474. remark = arrange.remark;
  475. // 查到了退出即可因为是个数组
  476. // 总人数
  477. shcool.push(arrange.number);
  478. }
  479. }
  480. }
  481. }
  482. remarks.push(remark);
  483. }
  484. }
  485. shcoolList.push(shcool);
  486. }
  487. const wscols = [
  488. { wpx: 50 }, // 第一列宽度设置单位px
  489. ];
  490. let xuhao = [ XLSX.utils.decode_range('A1:A4') ];
  491. const xuexiao = [ XLSX.utils.decode_range('B1:B4') ];
  492. xuhao = [ ...xuhao, ...xuexiao, ...colRows ];
  493. // console.log(xuhao);
  494. const data = [];
  495. // 第一行
  496. const row0 = [ '序号', '学校名称', '备注' ].concat(remarks);
  497. data.push(row0);
  498. // 第二行
  499. const row1 = [ '', '', '期数' ].concat(termCount);
  500. data.push(row1);
  501. // 第三行
  502. const row2 = [ '', '', '班级数' ].concat(classCount);
  503. data.push(row2);
  504. // 第四行
  505. const row3 = [ '', '', '日期' ].concat(studyTime);
  506. data.push(row3);
  507. for (const shcoolL of shcoolList) {
  508. let count = 0;
  509. for (let i = 3; i < shcoolL.length; i++) {
  510. count += parseInt(shcoolL[i]);
  511. }
  512. // 计算出总人数,开始总认识默认的是'',这里赋值
  513. shcoolL[2] = count;
  514. data.push(shcoolL);
  515. }
  516. // ...以此类推即可
  517. /** 头部-行列信息*/
  518. const ws = XLSX.utils.aoa_to_sheet(data);
  519. // 构建 workbook 对象
  520. const nowDate = new Date().getTime();
  521. const path =
  522. 'D:\\wwwroot\\service\\service-file\\upload\\train\\' +
  523. nowDate +
  524. '.xlsx';
  525. const respath =
  526. 'http://free.liaoningdoupo.com:80/files/train/' + nowDate + '.xlsx';
  527. // 导出
  528. const wb = XLSX.utils.book_new();
  529. XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
  530. ws['!cols'] = wscols;
  531. // xuhao.push(XLSX.utils.decode_range('B1:D1')) // 测试数据 仓库1模拟数据
  532. ws['!merges'] = xuhao;
  533. // console.log(xuhao);
  534. XLSX.writeFile(wb, path);
  535. return respath;
  536. // // 批次期次都在这里面
  537. // const trainplan = await this.model.find({ _id: trainplanId });
  538. // const _headers = [
  539. // { key: 'title', title: '计划标题' },
  540. // { key: 'year', title: '年度' },
  541. // ];
  542. // // 需要打出的列表
  543. // const _data = trainplan;
  544. // const headers = _headers.map(({ title }) =>
  545. // title).map((v, i) =>
  546. // Object.assign({}, { v, position: String.fromCharCode(65 + i) + 1 })
  547. // ).reduce((prev, next) =>
  548. // Object.assign({}, prev, { [next.position]: { v: next.v } }),
  549. // {}
  550. // );
  551. // console.log('--------------------headers');
  552. // console.log(headers);
  553. // const data = _data.map((v, i) =>
  554. // _headers.map(({ key }, j) =>
  555. // Object.assign(
  556. // {},
  557. // { v: v[key], position: String.fromCharCode(65 + j) + (i + 2) }
  558. // )
  559. // )
  560. // ).reduce((prev, next) =>
  561. // prev.concat(next)).reduce((prev, next) =>
  562. // Object.assign({}, prev, { [next.position]: { v: next.v } }),
  563. // {}
  564. // );
  565. // console.log('--------------------data');
  566. // console.log(data);
  567. // // 合并 headers 和 data
  568. // const output = Object.assign({}, headers, data);
  569. // console.log('----------output');
  570. // console.log(output);
  571. // // 获取所有单元格的位置
  572. // const outputPos = Object.keys(output);
  573. // console.log('--------------------outputPos');
  574. // console.log(outputPos);
  575. // // 计算出范围
  576. // const ref = outputPos[0] + ':' + outputPos[outputPos.length - 1];
  577. // console.log('--------------------ref');
  578. // console.log(ref);
  579. // // 构建 workbook 对象
  580. // const nowDate = new Date().getTime();
  581. // const path =
  582. // 'D:\\wwwroot\\service\\service-file\\upload\\train\\' +
  583. // nowDate +
  584. // '.xlsx';
  585. // const respath =
  586. // 'http://free.liaoningdoupo.com:80/files/train/' + nowDate + '.xlsx';
  587. // const wb = {
  588. // SheetNames: [ 'sheet0' ],
  589. // Sheets: { sheet0: Object.assign({}, output, { '!ref': ref }) },
  590. // // 导出 Excel
  591. // };
  592. // console.log('----------wb');
  593. // console.log(wb);
  594. // XLSX.writeFile(wb, path);
  595. // return respath;
  596. }
  597. async updateclass({ trainplanid, termid, batchid, classid, rightHeader }) {
  598. assert(trainplanid && termid && batchid && classid && rightHeader, '缺少参数项');
  599. // 根据全年计划表id查出对应的全年计划详细信息
  600. const trainplan = await this.model.findById(trainplanid);
  601. if (!trainplan) {
  602. throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '全年计划信息不存在');
  603. }
  604. const term = trainplan.termnum.id(termid);
  605. if (!term) {
  606. throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '期信息不存在');
  607. }
  608. const batch = term.batchnum.id(batchid);
  609. if (!batch) {
  610. throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '批次信息不存在');
  611. }
  612. const class_ = await batch.class.id(classid);
  613. if (class_) {
  614. class_.headteacherid = rightHeader;
  615. }
  616. const res = await trainplan.save();
  617. if (res) {
  618. const cla_ = await this.clamodel.findOne({ termid, batchid, name: class_.name });
  619. if (cla_) {
  620. cla_.headteacherid = rightHeader;
  621. await cla_.save();
  622. }
  623. }
  624. return res;
  625. }
  626. async updatereteacher({ trainplanid, termid, reteacher }) {
  627. assert(trainplanid && termid && reteacher, '缺少参数项');
  628. // 根据全年计划表id查出对应的全年计划详细信息
  629. const trainplan = await this.model.findById(trainplanid);
  630. if (!trainplan) {
  631. throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '全年计划信息不存在');
  632. }
  633. const term = await trainplan.termnum.id(termid);
  634. if (term) {
  635. term.reteacher = reteacher;
  636. }
  637. return await trainplan.save();
  638. }
  639. }
  640. module.exports = TrainplanService;