lrf402788946 4 anni fa
parent
commit
0978bd6017
1 ha cambiato i file con 10 aggiunte e 5 eliminazioni
  1. 10 5
      app/service/school.js

+ 10 - 5
app/service/school.js

@@ -48,7 +48,7 @@ class SchoolService extends CrudService {
     if (!plan) {
       throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '计划信息不存在');
     }
-    const isOutOfDate = this.outOfDate(plan, termid);
+    const isOutOfDate = this.outOfDate(plan, termid, batchid);
     if (!isOutOfDate) {
       throw new BusinessError(
         ErrorCode.BUSINESS,
@@ -526,12 +526,17 @@ class SchoolService extends CrudService {
     return row;
   }
   // 判断是否超出该期前3天
-  outOfDate(plan, termid) {
+  outOfDate(plan, termid, batchid) {
     const term = plan.termnum.find(f => ObjectId(termid).equals(f._id));
     const { batchnum } = term;
-    let startList = batchnum.map(i => ({ start: i.startdate }));
-    startList = _.orderBy(startList, [ 'start' ], [ 'asc' ]);
-    const start = _.get(_.head(startList), 'start');
+    if (!batchnum) throw new BusinessError(ErrorCode.BUSINESS, '没有找到该期下的批次');
+    const batch = batchnum.find(f => ObjectId(batchid).equals(f._id));
+    if (!batch) throw new BusinessError(ErrorCode.BUSINESS, '没有找到该批次');
+    // let startList = batchnum.map(i => ({ start: i.startdate }));
+    // startList = _.orderBy(startList, [ 'start' ], [ 'asc' ]);
+    // const start = _.get(_.head(startList), 'start');
+    const start = _.get(batch, 'startdate');
+    if (!start) throw new BusinessError(ErrorCode.BUSINESS, '没有找到开始日期');
     const limit = moment(start).subtract(3, 'days').format('YYYY-MM-DD');
     const now = moment().format('YYYY-MM-DD');
     const res = moment(now).isBefore(limit);