trainplan.js 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212
  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. const moment = require('moment');
  9. const XLSXStyle = require('xlsx-style');
  10. const Excel = require('exceljs');
  11. const { sep } = require('path');
  12. const { ObjectId } = require('mongoose').Types;
  13. class TrainplanService extends CrudService {
  14. constructor(ctx) {
  15. super(ctx, 'trainplan');
  16. this.model = this.ctx.model.Trainplan;
  17. this.clamodel = this.ctx.model.Class;
  18. this.umodel = this.ctx.model.User;
  19. this.smodel = this.ctx.model.School;
  20. this.tmodel = this.ctx.model.Teacher;
  21. this.stumodel = this.ctx.model.Student;
  22. this.schmodel = this.ctx.model.Schtime;
  23. this.lmmodel = this.ctx.model.Lessonmode;
  24. this.ctmodel = this.ctx.model.Classtype;
  25. }
  26. async create(data) {
  27. const { planyearid, year, title } = data;
  28. assert(planyearid, '缺少大批次信息');
  29. assert(year, '缺少年度');
  30. assert(title, '缺少标题');
  31. const res = await this.model.create(data);
  32. let planid = '';
  33. if (res) planid = res._id;
  34. const schoolList = await this.smodel.find();
  35. const schtimeArr = [];
  36. for (const sch of schoolList) {
  37. const { code } = sch;
  38. const obj = { schid: code, year, planid };
  39. let schtimeres;
  40. schtimeres = await this.schmodel.findOne(obj);
  41. if (!schtimeres)schtimeres = await this.schmodel.create(obj);
  42. if (schtimeres) schtimeArr.push(schtimeres);
  43. }
  44. if (!schtimeArr.every(e => e)) { throw new BusinessError(ErrorCode.DATA_INVALID, '学校计划生成失败'); } else return res;
  45. }
  46. async update({ id }, data) {
  47. const trainplan = await this.model.findById(id);
  48. // 保存原数据
  49. const trainplanold = _.cloneDeep(trainplan);
  50. const { year, title, termnum, festivals, status, school } = data;
  51. if (year) {
  52. trainplan.year = year;
  53. }
  54. if (title) {
  55. trainplan.title = title;
  56. }
  57. if (termnum) {
  58. trainplan.termnum = termnum;
  59. }
  60. if (school) {
  61. trainplan.school = school;
  62. }
  63. if (festivals) {
  64. trainplan.festivals = festivals;
  65. }
  66. if (status === '1') {
  67. trainplan.status = status;
  68. }
  69. // 日历安排中添加课表信息,查询每种班级类型的课表,然后显示
  70. if (trainplan.termnum) {
  71. // trainplan.termnum =
  72. trainplan.termnum = await this.termGetLesson(trainplan.termnum);
  73. // 重新查看每个班级是否有课程
  74. trainplan.termnum = this.setClassLesson(trainplan.termnum);
  75. }
  76. // 如果培训计划状态改为发布,发送培训计划信息,并自动生成班级
  77. const res = await trainplan.save();
  78. if (res) {
  79. if (status === '1') {
  80. // 自动生成班级
  81. // await this.autoclass(res, trainplanold);
  82. // await this.autoclassNew(res, trainplanold);
  83. // 将生成的班级重新将班级排班名
  84. // await this.autoclassname(res);
  85. // 发送培训计划信息通知给相应人员
  86. // 查询所有入库的教师
  87. // 不需要给教师发信息
  88. // const teachers = await this.tmodel.find({ status: '4' });
  89. // for (const teacher of teachers) {
  90. // const teacherid = teacher._id;
  91. // const _teacher = await this.umodel.findOne({
  92. // uid: teacherid,
  93. // type: '3',
  94. // });
  95. // const openid = _teacher.openid;
  96. // const detail = trainplan.title + '已发布,请注意查收!';
  97. // const date = await this.ctx.service.util.updatedate();
  98. // const remark = '感谢您的使用';
  99. // if (openid) {
  100. // this.ctx.service.weixin.sendTemplateMsg(
  101. // this.ctx.app.config.REVIEW_TEMPLATE_ID,
  102. // openid,
  103. // '您有一个新的通知',
  104. // detail,
  105. // date,
  106. // remark
  107. // );
  108. // }
  109. // }
  110. // 查询所有学校用户
  111. // const schools = await this.umodel.find({ type: '2' });
  112. // for (const school of schools) {
  113. // const openid = school.openid;
  114. // const detail = trainplan.title + '已发布,请注意查收!';
  115. // const date = await this.ctx.service.util.updatedate();
  116. // const remark = '感谢您的使用';
  117. // if (openid) {
  118. // this.ctx.service.weixin.sendTemplateMsg(
  119. // this.ctx.app.config.REVIEW_TEMPLATE_ID,
  120. // openid,
  121. // '您有一个新的通知',
  122. // detail,
  123. // date,
  124. // remark
  125. // );
  126. // }
  127. // }
  128. }
  129. // 查哪个学校schtime表没有生成,就给生成了
  130. const schoolList = await this.smodel.find();
  131. for (const school of schoolList) {
  132. const r = await this.schmodel.findOne({ year, planid: id, schid: school.code });
  133. if (r) continue;
  134. const obj = { schid: school.code, year, planid: id };
  135. await this.schmodel.create(obj);
  136. }
  137. }
  138. return res;
  139. }
  140. async termGetLesson(termnum) {
  141. const lessonModelList = await this.lmmodel.find();
  142. for (const term of termnum) {
  143. for (const batch of term.batchnum) {
  144. const { class: classes, startdate, enddate } = batch;
  145. // 获取每批次下每个班的班级类型
  146. const typeList = _.uniq(classes.map(i => i.type));
  147. const h = _.head(typeList);
  148. if (!h) continue;
  149. const tem = lessonModelList.find(f => f.type === h);
  150. if (!tem) continue;
  151. let { lessons } = tem;
  152. if (!lessons) continue;
  153. lessons = JSON.parse(lessons);
  154. // 过滤出上课的时间段
  155. lessons = lessons.filter(f => {
  156. const keys = Object.keys(f).filter(f => f.includes('subid'));
  157. return keys.length > 0;
  158. });
  159. // 记录上课的时间
  160. const times = [];
  161. // 记录所有的科目
  162. let subject = [];
  163. lessons.map(i => {
  164. times.push(i.time);
  165. const keys = Object.keys(i);
  166. let arr = [];
  167. for (const key of keys) {
  168. if (key.match(/\d/g)) arr.push(_.head(key.match(/\d/g)));
  169. }
  170. arr = _.uniq(arr);
  171. for (const ai of arr) {
  172. if (i[`day${ai}subid`]) {
  173. subject.push({
  174. subname: i[`day${ai}`],
  175. subid: i[`day${ai}subid`],
  176. day: ai,
  177. });
  178. }
  179. }
  180. return i;
  181. });
  182. // 去重
  183. subject = _.uniqBy(subject, 'subid');
  184. // 获得天列表
  185. const dnum = moment(enddate).diff(moment(startdate), 'days') + 1;
  186. const dayList = [];
  187. for (let ind = 0; ind < dnum; ind++) {
  188. dayList.push(moment(startdate).add(ind, 'd').format('YYYY-MM-DD'));
  189. }
  190. // 将subject中的day换成日期
  191. for (const sub of subject) {
  192. sub.day = dayList[sub.day * 1 - 1];
  193. sub.time = times;
  194. }
  195. batch.lessons = subject;
  196. }
  197. }
  198. return termnum;
  199. }
  200. // 设置课表模板到班级上
  201. setClassLesson(termnum) {
  202. // 为班级设置lessons,有的就不设置了
  203. for (const t of termnum) {
  204. const { batchnum } = t;
  205. if (!batchnum || !_.isArray(batchnum)) {
  206. this.$message.error(`第${t.term}期的批次数据错误!`);
  207. continue;
  208. }
  209. for (const b of t.batchnum) {
  210. const { class: cla, lessons: ltemplate } = b;
  211. if (!cla) {
  212. console.warn(`${t.term}期${b.batch}批次没有班级列表`);
  213. continue;
  214. }
  215. if (!ltemplate) {
  216. console.warn(`${t.term}期${b.batch}批次没有课表`);
  217. continue;
  218. }
  219. for (const c of b.class) {
  220. const { lessons } = c;
  221. if (lessons) {
  222. if (lessons.length <= 0) c.lessons = ltemplate;
  223. }
  224. }
  225. }
  226. }
  227. return termnum;
  228. }
  229. // 自动生成班级私有方法
  230. async autoclassNew(res) {
  231. // 删除所有计划下的班级
  232. await this.clamodel.deleteMany({ planid: res.id });
  233. // 循环出所有班级进行添加操作
  234. for (const term of res.termnum) {
  235. for (const batch of term.batchnum) {
  236. const classs = await batch.class;
  237. for (const cla of classs) {
  238. const newdata = {
  239. name: cla.name,
  240. number: cla.number,
  241. batchid: batch.id,
  242. termid: term.id,
  243. planid: res.id,
  244. type: cla.type,
  245. headteacherid: cla.headteacherid,
  246. };
  247. await this.clamodel.create(newdata);
  248. }
  249. }
  250. }
  251. }
  252. // 自动生成班级私有方法
  253. async autoclass(res, trainplanold) {
  254. // 首先比较当前数据和原数据的值是否有不同
  255. // 保存后所有期id
  256. const tremid_res = _.map(res.termnum, 'id');
  257. // 保存前所有期id
  258. const tremid_old = _.map(trainplanold.termnum, 'id');
  259. // 取得要删除的期id,进行班级中删除已删除期的班级
  260. const deltrem = _.difference(tremid_old, tremid_res);
  261. // 循环删除已经删除期的所有班级
  262. for (const elm of deltrem) {
  263. await this.clamodel.deleteMany({ termid: elm });
  264. }
  265. // 取得所有新加期id
  266. const addtrem = _.difference(tremid_res, tremid_old);
  267. // 清空后循环取得所有期进行批次操作
  268. const terms = res.termnum;
  269. for (const el of terms) {
  270. // 判断是否新加期
  271. if (_.indexOf(addtrem, el.id) !== -1) {
  272. // 循环当前新加期的批次列表,根据批次id和班级数生成班级信息
  273. const batchnums = el.batchnum;
  274. for (const batchnum of batchnums) {
  275. // 取得当前批次的班级数
  276. const classnum = batchnum.class;
  277. for (const cla of classnum) {
  278. const newdata = {
  279. name: cla.name,
  280. number: cla.number,
  281. batchid: batchnum.id,
  282. termid: el.id,
  283. planid: res.id,
  284. type: cla.type,
  285. };
  286. await this.clamodel.create(newdata);
  287. }
  288. }
  289. } else {
  290. // 不是新加期,更新期信息
  291. // 保存后所有期id
  292. const batchid_res = _.map(el.batchnum, 'id');
  293. // 保存前所有期id
  294. const batchid_old = _.map(
  295. trainplanold.termnum.id(el.id).batchnum,
  296. 'id'
  297. );
  298. // 取得要删除的期id,进行班级中删除已删除期的班级
  299. const delbatchs = _.difference(batchid_old, batchid_res);
  300. // 循环删除已经删除期的所有班级
  301. for (const delba of delbatchs) {
  302. await this.clamodel.deleteMany({ termid: el.id, batchid: delba });
  303. }
  304. // 取得所有新加期id
  305. const addbatch = _.difference(batchid_res, batchid_old);
  306. const batchnums = el.batchnum;
  307. for (const batchnum of batchnums) {
  308. // 取得当前批次是否有删除
  309. // 判断是否新加期
  310. if (_.indexOf(addbatch, batchnum.id) !== -1) {
  311. // 取得当前批次的班级数
  312. const classnum = batchnum.class;
  313. for (const cla of classnum) {
  314. const newdata = {
  315. name: cla.name,
  316. number: cla.number,
  317. batchid: batchnum.id,
  318. termid: el.id,
  319. planid: res.id,
  320. type: cla.type,
  321. };
  322. await this.clamodel.create(newdata);
  323. }
  324. } else {
  325. if (
  326. batchnum.class ===
  327. trainplanold.termnum.id(el.id).batchnum.id(batchnum.id).class
  328. ) {
  329. // 编辑只会针对班级人数进行修改。
  330. const _class = await this.clamodel.find({
  331. termid: el.id,
  332. batchid: batchnum.id,
  333. });
  334. if (_class.length !== 0) {
  335. for (const ee of _class) {
  336. ee.number = batchnum.number;
  337. await ee.save();
  338. }
  339. } else {
  340. const classnum = batchnum.class;
  341. for (const cla of classnum) {
  342. const newdata = {
  343. name: cla.name,
  344. number: cla.number,
  345. batchid: batchnum.id,
  346. termid: el.id,
  347. planid: res.id,
  348. type: cla.type,
  349. };
  350. await this.clamodel.create(newdata);
  351. }
  352. }
  353. } else {
  354. // 当班级数有更改时
  355. // 删除所有班级 并重新生成班级
  356. await this.clamodel.deleteMany({
  357. termid: el.id,
  358. batchid: batchnum.id,
  359. });
  360. const classnum = batchnum.class;
  361. for (const cla of classnum) {
  362. const newdata = {
  363. name: cla.name,
  364. number: cla.number,
  365. batchid: batchnum.id,
  366. termid: el.id,
  367. planid: res.id,
  368. type: cla.type,
  369. };
  370. await this.clamodel.create(newdata);
  371. }
  372. }
  373. }
  374. }
  375. }
  376. }
  377. }
  378. // // 将分好的班级重新编排名字
  379. // async autoclassname(res) {
  380. // // 取得所有期id
  381. // const tremid_res = _.map(res.termnum, 'id');
  382. // for (const termid of tremid_res) {
  383. // const classs = await this.clamodel.find({ planid: res.id, termid });
  384. // let i = 0;
  385. // for (const cla of classs) {
  386. // i = i + 1;
  387. // cla.name = i;
  388. // await cla.save();
  389. // }
  390. // }
  391. // }
  392. async exportExcel({ trainplanIds }) {
  393. const nowDate = new Date().getTime();
  394. const { repos_root_path: rp } = this.ctx.app.config.cdn;
  395. const { baseUrl: bu } = this.ctx.app.config;
  396. const path = `${rp}${sep}train${sep}${nowDate}.xlsx`;
  397. const respath = `${bu}/files/train/${nowDate}.xlsx`;
  398. const wb = {
  399. SheetNames: [],
  400. Sheets: {},
  401. };
  402. for (let i = 0; i < trainplanIds.length; i++) {
  403. // 批次期次都在这里面
  404. const trainplan = await this.model.findOne({ _id: trainplanIds[i] });
  405. // 这个计划下所有的学生
  406. const studentList = await this.stumodel.find({ planid: trainplanIds[i] });
  407. // 计划名称
  408. const trainplandName = trainplan.title;
  409. // 在计划中找到这个学生在哪期以及哪期下的哪批次
  410. for (const student of studentList) {
  411. student.isComming = utils.getIsNot(student.isComming);
  412. student.trainplandName = trainplandName;
  413. // 期次
  414. const term = trainplan.termnum.filter(term => {
  415. return term.id === student.termid;
  416. });
  417. if (term.length > 0) {
  418. student.termName = term[0].term;
  419. }
  420. // 批次
  421. if (term.length !== 0) {
  422. const batch = term[0].batchnum.filter(batch => {
  423. return batch.id === student.batchid;
  424. });
  425. if (batch.length > 0) {
  426. student.batchName = JSON.parse(JSON.stringify(batch[0])).name;
  427. }
  428. }
  429. student.is_fine = utils.getIsNot(student.is_fine);
  430. }
  431. const _headers = [
  432. { key: 'trainplandName', title: '计划标题' },
  433. { key: 'termName', title: '期次' },
  434. { key: 'batchName', title: '批次' },
  435. { key: 'school_name', title: '学校' },
  436. { key: 'faculty', title: '院系' },
  437. { key: 'major', title: '专业' },
  438. { key: 'name', title: '姓名' },
  439. { key: 'id_number', title: '身份证号' },
  440. { key: 'phone', title: '手机号' },
  441. { key: 'gender', title: '性别' },
  442. { key: 'nation', title: '民族' },
  443. { key: 'edua_level', title: '学历层次' },
  444. { key: 'edua_system', title: '学制' },
  445. { key: 'entry_year', title: '入学年份' },
  446. { key: 'finish_year', title: '毕业年份' },
  447. { key: 'school_job', title: '在校职务' },
  448. { key: 'qq', title: 'QQ号' },
  449. { key: 'email', title: '邮箱' },
  450. // { key: 'openid', title: '微信openid' },
  451. { key: 'family_place', title: '家庭位置' },
  452. { key: 'family_is_hard', title: '是否困难' },
  453. { key: 'have_grant', title: ' 是否获得过助学金' },
  454. // { key: 'job', title: '职务' },
  455. { key: 'bedroom', title: '寝室号' },
  456. { key: 'is_fine', title: '是否优秀' },
  457. { key: 'isComming', title: '是否签到' },
  458. { key: 'selfscore', title: '个人分' },
  459. { key: 'score', title: '总分' },
  460. ];
  461. // 需要打出的列表
  462. const _data = studentList;
  463. const headers = _headers
  464. .map(({ title }) => title)
  465. .map((v, i) =>
  466. Object.assign({}, { v, position: String.fromCharCode(65 + i) + 1 })
  467. )
  468. .reduce(
  469. (prev, next) =>
  470. Object.assign({}, prev, { [next.position]: { v: next.v } }),
  471. {}
  472. );
  473. const data = _data
  474. .map((v, i) =>
  475. _headers.map(({ key }, j) =>
  476. Object.assign(
  477. {},
  478. { v: v[key], position: String.fromCharCode(65 + j) + (i + 2) }
  479. )
  480. )
  481. )
  482. .reduce((prev, next) => prev.concat(next))
  483. .reduce(
  484. (prev, next) =>
  485. Object.assign({}, prev, { [next.position]: { v: next.v } }),
  486. {}
  487. );
  488. // 合并 headers 和 data
  489. const output = Object.assign({}, headers, data);
  490. // 获取所有单元格的位置
  491. const outputPos = Object.keys(output);
  492. // 计算出范围
  493. const ref = outputPos[0] + ':' + outputPos[outputPos.length - 1];
  494. // 构建 workbook 对象
  495. wb.SheetNames.push('sheet' + i);
  496. wb.Sheets['sheet' + i] = Object.assign({}, output, { '!ref': ref });
  497. }
  498. // 导出 Excel
  499. XLSX.writeFile(wb, path);
  500. return respath;
  501. }
  502. // 导出学校大表
  503. async exportSchool({ trainplanId }) {
  504. const rows = [
  505. [ '学校名称', '期数' ],
  506. [ ' ', '班级数' ],
  507. [ ' ', '时间' ],
  508. [ ' ', '备注' ],
  509. ];
  510. // 操作
  511. const operaList = [
  512. { startRow: 1, startCol: 1, endRow: 5, endCol: 1 },
  513. ];
  514. // 操作:
  515. // step1: 班级类型的动态列
  516. // step2: 1行:期数需要合并列:需要合并的列数根据下面的批次决定
  517. // step3: 2行:输出批次的班级类型及班级数
  518. // step4: 3行:显示每批次的事件(开始-结束)
  519. // step5: 4行:每批次的备注,和5行同列合并
  520. // 批次期次都在这里面
  521. let trainplan = await this.model.findById(trainplanId);
  522. if (trainplan) trainplan = JSON.parse(JSON.stringify(trainplan));
  523. const fn = trainplan.title;// 文件名
  524. let classType = await this.ctmodel.find();
  525. if (classType) classType = JSON.parse(JSON.stringify(classType));
  526. let schtime = await this.schmodel.find({ planid: trainplanId });
  527. if (schtime) schtime = JSON.parse(JSON.stringify(schtime));
  528. // step1
  529. // 整理班级类型的顺序
  530. if (_.isArray(classType) && classType.length > 0) {
  531. classType = classType.map(i => {
  532. i.sort = parseInt(i.code);
  533. return i;
  534. });
  535. classType = _.orderBy(classType, [ 'sort' ], [ 'desc' ]);
  536. }
  537. const row5 = [ '' ];
  538. for (const ct of classType) {
  539. const { name } = ct;
  540. row5.push(name);
  541. }
  542. row5.push('总人数', '实际分配总人数');
  543. // 整理opera
  544. for (let i = 0; i < rows.length; i++) {
  545. // 结束列-2: -1=> 第二列,有个班级类型,与上面位于同列,需要减掉; -1=>row5初始有个'',占了学校的列,重复了
  546. const opera = { startRow: i + 1, startCol: 2, endRow: i + 1, endCol: rows[i].length + row5.length - 2 };
  547. operaList.push(opera);
  548. for (let k = 1; k < row5.length - 1; k++) {
  549. rows[i].push('');
  550. }
  551. }
  552. rows.push(row5);
  553. // step2:处理计划
  554. let { termnum, school } = trainplan;
  555. termnum = this.sortPlan(termnum);
  556. const batchs = this.getListForBatch(termnum);
  557. // 期数变的是行,不是列
  558. const termRow = 1;
  559. // 因班级类型可能增加,所以此处是动态的
  560. let col = rows[termRow - 1].length + 1;
  561. const classRow = 2;
  562. const timeRow = 3;
  563. const remarkRow = 4;
  564. for (const term of termnum) {
  565. const { term: termstr, batchnum } = term;
  566. // 处理期数据
  567. rows[termRow - 1].push(termstr);
  568. const obj = { startRow: 1, startCol: col, endRow: 1, endCol: col + batchnum.length - 1 };
  569. operaList.push(obj);
  570. // step3,4:
  571. for (const b of batchnum) {
  572. const { startdate, enddate } = b;
  573. const word = this.setClassColunmWord(b, classType);
  574. // 填充班级列数据
  575. rows[classRow - 1].push(word);
  576. // 填充批次的时间
  577. const timeword = `${moment(startdate).format('M.D')} - ${moment(enddate).format('M.D')}`;
  578. rows[timeRow - 1].push(timeword);
  579. // 数据,进行填充
  580. rows[termRow - 1].push('');
  581. // 随之更新列
  582. col++;
  583. }
  584. // 因为期数需要占一个格子,所以得把在循环批次的时候加进去的-1
  585. rows[termRow - 1].pop();
  586. }
  587. // 整理注释
  588. const { data, opera } = this.setRemark(batchs, schtime, rows[remarkRow - 1], remarkRow, 1);
  589. rows[remarkRow - 1] = data;
  590. operaList.push(...opera);
  591. // 整理数据
  592. // ['学校名称','特殊班剩余人数','普通班剩余人数','总人数(预设)','实际分配总人数',...'对应批次的人数,没有就填充']
  593. const schData = await this.setSchoolData(schtime, batchs, school, classType);
  594. rows.push(...schData);
  595. return await this.ctx.service.util.toExcel(rows, null, fn, operaList);
  596. }
  597. /**
  598. * 计划排序
  599. * @param {Array} termnum 计划列表
  600. */
  601. sortPlan(termnum) {
  602. if (_.isArray(termnum) && termnum.length > 0) {
  603. // 数据排序
  604. termnum = termnum.map(t => {
  605. const { batchnum, term } = t;
  606. t.termnum = parseInt(term);
  607. t.batchnum = batchnum.map(b => {
  608. const { batch, class: classes } = b;
  609. b.batchnum = _.isNumber(parseInt(batch)) ? parseInt(batch) : batch;
  610. b.class = classes.map(c => {
  611. const { name } = c;
  612. c.classnum = _.isNumber(parseInt(name)) ? parseInt(name) : name;
  613. return c;
  614. });
  615. b.class = _.orderBy(b.class, [ 'classnum' ], [ 'asc' ]);
  616. return b;
  617. });
  618. return t;
  619. });
  620. termnum = _.orderBy(termnum, [ 'termnum' ], [ 'asc' ]);
  621. }
  622. return termnum;
  623. }
  624. /**
  625. * 整理班级列的输出文字
  626. * @param {Object} b batch,批次数据
  627. * @param {Array} classType 班级类型列表
  628. */
  629. setClassColunmWord(b, classType) {
  630. const { class: classes } = b;
  631. const c = _.head(classes);
  632. let word = '';
  633. if (c) {
  634. const { type } = c;
  635. const r = classType.find(f => f.code === type);
  636. word = classes.length;
  637. if (r) word = `${word}(${r.name})`;
  638. }
  639. return word;
  640. }
  641. /**
  642. * 整理备注
  643. * @param {Array} batchs 批次为元素的计划列表
  644. * @param {Array} schtime 学校计划
  645. * @param {Array} remarkRowData 备注行数据
  646. * @param {Number} remarkRow 备注开始行
  647. * @param {Number} mergeRow 备注要合并的行数
  648. */
  649. setRemark(batchs, schtime, remarkRowData, remarkRow, mergeRow) {
  650. let arr = [];
  651. for (const sp of schtime) {
  652. for (const arrange of sp.arrange) {
  653. if (_.get(arrange, 'remark')) arr.push(arrange);
  654. }
  655. }
  656. arr = _.uniqBy(arr, 'batchid');
  657. // 整理完备注,按照顺序,依次去找,是否有备注,有就推进去备注,没有推空
  658. const remarks = _.cloneDeep(remarkRowData);
  659. for (const b of batchs) {
  660. const r = arr.find(f => ObjectId(f.batchid).equals(b._id));
  661. if (r) remarks.push(r.remark);
  662. else remarks.push('');
  663. }
  664. // 站位填充满
  665. // 整理操作, 主要是行的合并
  666. const opera = [];
  667. for (let i = remarkRowData.length; i < remarks.length; i++) {
  668. // i+1=>i为原数据的最后一个数据的位置,然而要处理的是后面的新添的数据
  669. opera.push({ startRow: remarkRow, startCol: i + 1, endRow: remarkRow + mergeRow, endCol: i + 1 });
  670. }
  671. return { data: remarks, opera };
  672. }
  673. /**
  674. * 整理学校安排的数据
  675. * @param {Array} schtime 学校安排的计划
  676. * @param {Array} batchs 以批次为元素的计划列表
  677. * @param {Array} schPlan 学校的预计划
  678. * @param {Array} classType 班级类型
  679. */
  680. async setSchoolData(schtime, batchs, schPlan, classType) {
  681. let schoolList = await this.smodel.find();
  682. const result = [];
  683. // 学校按code排序
  684. if (schoolList && schoolList.length > 0) {
  685. schoolList = JSON.parse(JSON.stringify(schoolList));
  686. schoolList = schoolList.map(i => {
  687. i.schnum = this.toParseInt(i.code);
  688. return i;
  689. });
  690. schoolList = _.orderBy(schoolList, [ 'schnum' ], [ 'asc' ]);
  691. }
  692. // 实际安排的学校计划
  693. const schArrange = [];
  694. for (const aobj of schtime) {
  695. const { schid, arrange } = aobj;
  696. if (!schid) continue;
  697. if (!_.isArray(arrange)) continue;
  698. for (const arrObj of arrange) {
  699. schArrange.push({ ...arrObj, schid });
  700. }
  701. }
  702. // 计算各个班级类型剩余人数,总人数,实际分配总人数
  703. for (const sch of schoolList) {
  704. const { name, code } = sch;
  705. // 该学校的数据
  706. const arr = [ name ];
  707. // 学校实际分配的计划, 先不管别的,先把计划的问题处理了
  708. const reaFRes = schArrange.filter(f => f.schid === code);
  709. // 过滤出来学校已经分配的数据后,需要知道是什么类型的
  710. const reaObj = { total: 0, reaTotal: 0 }; // key:班级类型, value:为实际分配的人数
  711. for (const rr of reaFRes) {
  712. const { batchid, number } = rr;
  713. const r = batchs.find(f => f._id === batchid);
  714. if (r) {
  715. const { type } = r;
  716. reaObj[type] = (this.toParseInt(reaObj[type]) || 0) + this.toParseInt(number); // 计划人数累加
  717. reaObj.reaTotal = _.add(this.toParseInt(reaObj.reaTotal), this.toParseInt(number)); // 实际人数累加
  718. }
  719. }
  720. // 先查预计划有没有
  721. const p = schPlan.find(f => f.code === code);
  722. if (p) {
  723. // 获取到预设的学校计划
  724. const { classnum } = p;
  725. // 班级类型对应的计划
  726. for (const ct of classType) {
  727. const { code } = ct;
  728. const r = classnum.find(f => f.code === code);
  729. // n为要求的人数
  730. let n = 0;
  731. if (r) {
  732. // 找到对应类型的计划了,计算这个班级类型是否分配完毕
  733. const { number } = r;
  734. if (number) n = this.toParseInt(number);
  735. }
  736. // 用code去reaObj中提取实际分配的人数,就可以算处的值
  737. const rea = this.toParseInt(reaObj[code]) || 0;
  738. let word = _.subtract(n - rea);
  739. // n===0:表示原来计划里没有这个类型,word再为0,说明实际上也没有这个类型,就不需要显示了
  740. if (n === 0 && word === 0) word = '';
  741. reaObj.total = _.add(reaObj.total, n);// 计划人数累加
  742. arr.push(word);
  743. }
  744. } else {
  745. // 如果没有这个学校的计划,就得看看reaObj中有没有分配,有分配还得处理;没分配就跳过下一个
  746. const keys = Object.keys(reaObj);
  747. for (const ct of classType) {
  748. if (keys.length <= 0) {
  749. // 没分配,填充,下一个
  750. arr.push('');
  751. } else {
  752. // 没计划但是实际分配了,就需要体现出来了
  753. const word = reaObj[ct.code];
  754. if (word && word !== 0) {
  755. arr.push(`-${word}`);
  756. } else {
  757. arr.push('');
  758. }
  759. }
  760. }
  761. }
  762. // 处理总人数和实际分配人数
  763. arr.push(reaObj.total);
  764. arr.push(reaObj.reaTotal);
  765. // 循环学校列表,找到学校的所有安排,然后找到对应的索引,进行数据整理
  766. for (const rea of reaFRes) {
  767. const index = batchs.findIndex(f => f._id === rea.batchid);
  768. if (index < 0) continue;
  769. arr[index + 5] = rea.number;
  770. }
  771. result.push(arr);
  772. }
  773. // 合计行:只有学校列不计算,其他的列全部计算=>批次列(batchs.length)+班级类型列(classType.length)+总人数列(1)+实际分配人数列(1)
  774. const colTotal = batchs.length + classType.length + 1 + 1;
  775. const count = [ '合计' ];
  776. // 第一列不需要,是学校/合计列
  777. for (let i = 1; i <= colTotal; i++) {
  778. const cmid = [];
  779. for (const arr of result) {
  780. let number = this.toParseInt(_.get(arr, i, 0));
  781. if (_.isNaN(number)) number = 0;
  782. cmid.push(number);
  783. }
  784. const colCount = cmid.reduce((p, n) => p + n, 0);
  785. count.push(colCount);
  786. }
  787. result.push(count);
  788. return result;
  789. }
  790. toParseInt(number) {
  791. let num = parseInt(number);
  792. if (_.isNaN(num)) num = 0;
  793. return num;
  794. }
  795. /**
  796. * 获取批次列表(排完顺序了,直接拿出来)
  797. * @param {Array} termnum 计划列表
  798. */
  799. getListForBatch(termnum) {
  800. const arr = [];
  801. for (const t of termnum) {
  802. for (const b of t.batchnum) {
  803. const obj = { ...b };
  804. const { class: classes } = b;
  805. if (_.isArray(classes)) {
  806. const head = _.head(classes);
  807. if (head) {
  808. const { type } = head;
  809. if (type)obj.type = type;
  810. }
  811. const all = classes.reduce((p, n) => p + (parseInt(n.number) || 0), 0);
  812. if (_.isNumber(all)) b.all = all;
  813. }
  814. arr.push(obj);
  815. }
  816. }
  817. return arr;
  818. }
  819. // 导出学校大表
  820. async exportPlan({ trainplanId }) {
  821. const wscols = [
  822. { wpx: 50 }, // 第一列宽度设置单位px
  823. ];
  824. const monthList = [];
  825. // 月份合并单元格
  826. const colzb = 0;
  827. let rowzb = 1;
  828. // 头部合并单元格
  829. const coltb = 0;
  830. let rowtb = 0;
  831. // 人数合并单元格
  832. const colrs = 0;
  833. let rowrs = 1;
  834. // 人数数量合并单元格
  835. const colrssl = 0;
  836. let rowrssl = 3;
  837. // 班级数合并单元格
  838. const colbjs = 0;
  839. let rowbjs = 1;
  840. // 班级数数量合并单元格
  841. const colbjssl = 0;
  842. let rowbjssl = 3;
  843. // 数据
  844. const data = [];
  845. let colRowBJSSL = {};
  846. // 这里是头部颜色
  847. const tatleCell = { v: '', s: { fill: { fgColor: { rgb: '191970' } } } };
  848. // 坐标
  849. const tatleCellstyle = 0;
  850. let tatleRowstyle = 0;
  851. const styleTatle = [];
  852. // 这里是月份颜色
  853. const monthCell = [
  854. { v: '一月', s: { fill: { fgColor: { rgb: 'B0E2FF' } } } },
  855. { v: '二月', s: { fill: { fgColor: { rgb: 'B0E2FF' } } } },
  856. { v: '三月', s: { fill: { fgColor: { rgb: 'B0E2FF' } } } },
  857. { v: '四月', s: { fill: { fgColor: { rgb: 'B0E2FF' } } } },
  858. { v: '五月', s: { fill: { fgColor: { rgb: 'B0E2FF' } } } },
  859. { v: '六月', s: { fill: { fgColor: { rgb: 'B0E2FF' } } } },
  860. { v: '七月', s: { fill: { fgColor: { rgb: 'B0E2FF' } } } },
  861. { v: '八月', s: { fill: { fgColor: { rgb: 'B0E2FF' } } } },
  862. { v: '九月', s: { fill: { fgColor: { rgb: 'B0E2FF' } } } },
  863. { v: '十月', s: { fill: { fgColor: { rgb: 'B0E2FF' } } } },
  864. { v: '十一月', s: { fill: { fgColor: { rgb: 'B0E2FF' } } } },
  865. { v: '十二月', s: { fill: { fgColor: { rgb: 'B0E2FF' } } } },
  866. ];
  867. // 坐标
  868. const monthCellstyle = 0;
  869. let monthRowstyle = 1;
  870. const styleMonth = [];
  871. // 这里是假期颜色
  872. const festivalsCell = {
  873. v: '',
  874. s: { fill: { fgColor: { rgb: 'A2CD5A' } } },
  875. };
  876. // 坐标
  877. const festivalsCellstyle = 0;
  878. let festivalsRowstyle = 0;
  879. const stylefestivals = [];
  880. // 计划表
  881. const trainplan = await this.model.findOne({ _id: trainplanId });
  882. const termnum = trainplan.termnum;
  883. let classNum = 0;
  884. // 获取最大的班级数,也就是月份的高
  885. for (const term of termnum) {
  886. if (term.classnum > classNum) {
  887. classNum = parseInt(term.classnum);
  888. }
  889. }
  890. // 得到所有的节日日期的数组,然后循环时注意得到一个删除一个
  891. const festivals = trainplan.festivals;
  892. const festivalList = this.getfestivalList(festivals);
  893. const termnumList = this.gettermnumList(termnum);
  894. // 得到所有班级的数组,然后循环时注意得到一个删除一个
  895. // 循环12个月,得到12个月以及每个月的数据
  896. for (let index = 1; index < 13; index++) {
  897. // 这里增加表格头部下标
  898. const tatleCells = XLSX.utils.encode_cell({
  899. c: tatleCellstyle,
  900. r: tatleRowstyle,
  901. });
  902. tatleRowstyle = tatleRowstyle + classNum + 3;
  903. styleTatle.push(tatleCells);
  904. // 这里是月份颜色
  905. const monthCells = XLSX.utils.encode_cell({
  906. c: monthCellstyle,
  907. r: monthRowstyle,
  908. });
  909. monthRowstyle = monthRowstyle + classNum + 3;
  910. styleMonth.push(monthCells);
  911. for (let j = 0; j < festivalList.length; j++) {
  912. const festival = festivalList[j];
  913. // 如果月份相同时才会增加
  914. const yue = parseInt(festival.substr(5, 2));
  915. const lie = parseInt(festival.substr(8, 2));
  916. if (index === yue) {
  917. // 这里是假期颜色这一列列7行都是这个颜色
  918. for (let k = 0; k < classNum; k++) {
  919. const festivalsCells = XLSX.utils.encode_cell({
  920. // 列
  921. c: festivalsCellstyle + lie,
  922. r: festivalsRowstyle + k + 3,
  923. });
  924. stylefestivals.push(festivalsCells);
  925. }
  926. }
  927. }
  928. festivalsRowstyle = festivalsRowstyle + classNum + 3;
  929. // 添加月份坐标
  930. const colRow = {
  931. s: { c: colzb, r: rowzb },
  932. // 保证留下7个空行,如果需要在上面加值,直接在下面加入即可第几空行加入就行
  933. e: { c: colzb, r: rowzb + classNum + 1 },
  934. };
  935. // rowzb为上一次终止,那么起始需+1,这里加3,代表头部+月份+星期,所以+3
  936. rowzb = rowzb + classNum + 3;
  937. monthList.push(colRow);
  938. // 添加头部坐标
  939. const colRowTB = {
  940. s: { c: coltb, r: rowtb },
  941. // 保证留下7个空行,如果需要在上面加值,直接在下面加入即可第几空行加入就行
  942. e: { c: coltb + 33, r: rowtb },
  943. };
  944. // rowzb为上一次终止,那么起始需+1,
  945. rowtb = rowtb + classNum + 3;
  946. monthList.push(colRowTB);
  947. // 添加人数坐标
  948. const colRowRS = {
  949. s: { c: colrs + 32, r: rowrs },
  950. // 保证留下7个空行,如果需要在上面加值,直接在下面加入即可第几空行加入就行
  951. e: { c: colrs + 32, r: rowrs + 1 },
  952. };
  953. // rowzb为上一次终止,那么起始需+1,
  954. rowrs = rowrs + classNum + 3;
  955. monthList.push(colRowRS);
  956. // 添加人数数量坐标
  957. const colRowRSSL = {
  958. s: { c: colrssl + 32, r: rowrssl },
  959. // 保证留下7个空行,如果需要在上面加值,直接在下面加入即可第几空行加入就行
  960. e: { c: colrssl + 32, r: rowrssl + classNum - 1 },
  961. };
  962. // rowzb为上一次终止,那么起始需+1,
  963. rowrssl = rowrssl + classNum + 3;
  964. monthList.push(colRowRSSL);
  965. // 添加班级数坐标
  966. const colRowBJS = {
  967. s: { c: colbjs + 33, r: rowbjs },
  968. // 保证留下7个空行,如果需要在上面加值,直接在下面加入即可第几空行加入就行
  969. e: { c: colbjs + 33, r: rowbjs + 1 },
  970. };
  971. // rowzb为上一次终止,那么起始需+1,
  972. rowbjs = rowbjs + classNum + 3;
  973. monthList.push(colRowBJS);
  974. // 添加班级数数量坐标
  975. colRowBJSSL = {
  976. s: { c: colbjssl + 33, r: rowbjssl },
  977. // 保证留下7个空行,如果需要在上面加值,直接在下面加入即可第几空行加入就行
  978. e: { c: colbjssl + 33, r: rowbjssl + classNum - 1 },
  979. };
  980. // rowzb为上一次终止,那么起始需+1,
  981. rowbjssl = rowbjssl + classNum + 3;
  982. monthList.push(colRowBJSSL);
  983. const resDate = this.makeCalendar(trainplan.year, index);
  984. data.push([ '' ]);
  985. data.push(
  986. [[ this.getBigMonth(index) + '月' ]]
  987. .concat(resDate.dlist)
  988. .concat([ '人数' ].concat([ '班级数' ]))
  989. );
  990. data.push([ '' ].concat(resDate.tlist));
  991. // 加列数组
  992. for (let i = 0; i < classNum; i++) {
  993. data.push('');
  994. }
  995. }
  996. // ...以此类推即可
  997. /** 头部-行列信息*/
  998. const ws = XLSX.utils.aoa_to_sheet(data);
  999. // 构建 workbook 对象
  1000. const nowDate = new Date().getTime();
  1001. const path =
  1002. 'D:\\wwwroot\\service\\service-file\\upload\\train\\' + nowDate + '.xlsx';
  1003. const respath =
  1004. 'http://free.liaoningdoupo.com:80/files/train/' + nowDate + '.xlsx';
  1005. // 导出
  1006. const wb = XLSX.utils.book_new();
  1007. XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
  1008. ws['!cols'] = wscols;
  1009. ws['!merges'] = monthList;
  1010. // 头部赋值颜色需要计算出坐标
  1011. for (const tatlezb of styleTatle) {
  1012. ws[tatlezb] = tatleCell;
  1013. }
  1014. // 月份赋值颜色需要计算出坐标
  1015. for (let index = 0; index < styleMonth.length; index++) {
  1016. ws[styleMonth[index]] = monthCell[index];
  1017. }
  1018. // 假期赋值颜色需要计算出坐标
  1019. for (const festivals of stylefestivals) {
  1020. ws[festivals] = festivalsCell;
  1021. }
  1022. XLSXStyle.writeFile(wb, path);
  1023. return respath;
  1024. }
  1025. // 获取批次日期列表
  1026. gettermnumList(termnums) {
  1027. const termnumList = [];
  1028. for (const termnum of termnums) {
  1029. termnum.term;
  1030. termnum.classnum;
  1031. for (const batchnum of termnum.batchnum) {
  1032. batchnum.batch;
  1033. batchnum.class.length;
  1034. batchnum.startdate;
  1035. batchnum.enddate;
  1036. }
  1037. }
  1038. return termnumList;
  1039. }
  1040. // 获取节假日集合
  1041. getfestivalList(festivals) {
  1042. let dateList = [];
  1043. for (let index = 0; index < festivals.length; index++) {
  1044. dateList = [
  1045. ...dateList,
  1046. ...utils.begindateEnddateSum(
  1047. festivals[index].begindate,
  1048. festivals[index].finishdate
  1049. ),
  1050. ];
  1051. }
  1052. return dateList;
  1053. }
  1054. // 获取大月份传过来的值是以1月份开始的
  1055. getBigMonth(index) {
  1056. const monthBig = [
  1057. '一',
  1058. '二',
  1059. '三',
  1060. '四',
  1061. '五',
  1062. '六',
  1063. '七',
  1064. '八',
  1065. '九',
  1066. '十',
  1067. '十一',
  1068. '十二',
  1069. ];
  1070. return monthBig[index - 1];
  1071. }
  1072. // 获取这个月份的所有日期1~30号或者31或者28,或者29
  1073. makeCalendar(year, month = 1, month0) {
  1074. month0 = month;
  1075. if (month * 1 < 10) month = '0' + month;
  1076. // 获取这个月份的最大值
  1077. const days = moment(year + '-' + month).daysInMonth();
  1078. const dlist = this.getDayList(year, month, days, month0);
  1079. while (dlist.dlist.length < 31) {
  1080. dlist.dlist.push('');
  1081. }
  1082. return dlist;
  1083. }
  1084. // 获取这个月份的1-30号经过加工的
  1085. getDayList(year, month, days, month0) {
  1086. const dlist = [];
  1087. const tlist = [];
  1088. const all = {};
  1089. for (let index = 0; index < days; index++) {
  1090. dlist.push(
  1091. month0 +
  1092. '月' +
  1093. moment(year + '-' + month)
  1094. .add(index, 'days')
  1095. .format('D') +
  1096. '日'
  1097. );
  1098. let dayy = parseInt(index + 1);
  1099. if (dayy * 1 < 10) dayy = '0' + dayy;
  1100. tlist.push(this.getWeekDay(year + '-' + month + '-' + dayy));
  1101. }
  1102. all.dlist = dlist;
  1103. all.tlist = tlist;
  1104. return all;
  1105. }
  1106. // 获取星期几
  1107. getWeekDay(datestr) {
  1108. const weekday = moment(datestr).weekday();
  1109. if (weekday || weekday === 0) {
  1110. const arr = [ '日', '一', '二', '三', '四', '五', '六' ];
  1111. return '星期' + arr[weekday];
  1112. }
  1113. return '';
  1114. }
  1115. // async updateclass({ trainplanid, classid, rightHeader }) {
  1116. // assert(trainplanid && classid && rightHeader, '缺少参数项');
  1117. async updateclass({ trainplanid, termid, batchid, classid, rightHeader }) {
  1118. assert(
  1119. trainplanid && termid && batchid && classid && rightHeader,
  1120. '缺少参数项'
  1121. );
  1122. // 根据全年计划表id查出对应的全年计划详细信息
  1123. const trainplan = await this.model.findById(trainplanid);
  1124. if (!trainplan) {
  1125. throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '全年计划信息不存在');
  1126. }
  1127. const term = trainplan.termnum.id(termid);
  1128. if (!term) {
  1129. throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '期信息不存在');
  1130. }
  1131. const batch = term.batchnum.id(batchid);
  1132. if (!batch) {
  1133. throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '批次信息不存在');
  1134. }
  1135. const class_ = await batch.class.id(classid);
  1136. if (class_) {
  1137. class_.headteacherid = rightHeader;
  1138. }
  1139. const res = await trainplan.save();
  1140. if (res) {
  1141. const cla_ = await this.clamodel.findOne({
  1142. termid,
  1143. batchid,
  1144. name: class_.name,
  1145. });
  1146. if (cla_) {
  1147. cla_.headteacherid = rightHeader;
  1148. await cla_.save();
  1149. }
  1150. }
  1151. return res;
  1152. }
  1153. async updatereteacher({ trainplanid, termid, reteacher }) {
  1154. assert(trainplanid && termid && reteacher, '缺少参数项');
  1155. // 根据全年计划表id查出对应的全年计划详细信息
  1156. const trainplan = await this.model.findById(trainplanid);
  1157. if (!trainplan) {
  1158. throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '全年计划信息不存在');
  1159. }
  1160. const term = await trainplan.termnum.id(termid);
  1161. if (term) {
  1162. term.reteacher = reteacher;
  1163. }
  1164. return await trainplan.save();
  1165. }
  1166. }
  1167. module.exports = TrainplanService;