lrf 2 years ago
parent
commit
8df6a4b8c1

+ 5 - 1
app/controller/matchSmallGroupSchedule.js

@@ -3,11 +3,15 @@ const meta = require('./config/.matchSmallGroupSchedule.js');
 const Controller = require('egg').Controller;
 const Controller = require('egg').Controller;
 const { CrudController } = require('naf-framework-mongoose-free/lib/controller');
 const { CrudController } = require('naf-framework-mongoose-free/lib/controller');
 
 
-// 
+//
 class MatchSmallGroupScheduleController extends Controller {
 class MatchSmallGroupScheduleController extends Controller {
   constructor(ctx) {
   constructor(ctx) {
     super(ctx);
     super(ctx);
     this.service = this.ctx.service.matchSmallGroupSchedule;
     this.service = this.ctx.service.matchSmallGroupSchedule;
   }
   }
+  async saveAll() {
+    const data = await this.service.saveAll(this.ctx.request.body);
+    this.ctx.ok({ data });
+  }
 }
 }
 module.exports = CrudController(MatchSmallGroupScheduleController, meta);
 module.exports = CrudController(MatchSmallGroupScheduleController, meta);

+ 1 - 1
app/controller/matchTeamGroup.js

@@ -11,7 +11,7 @@ class MatchTeamGroupController extends Controller {
   }
   }
 
 
   async saveAll() {
   async saveAll() {
-    const data = await this.service.saveAll();
+    const data = await this.service.saveAll(this.ctx.request.body);
     this.ctx.ok({ data });
     this.ctx.ok({ data });
   }
   }
 }
 }

+ 12 - 1
app/service/matchSmallGroupSchedule.js

@@ -4,13 +4,24 @@ const { BusinessError, ErrorCode } = require('naf-core').Error;
 const _ = require('lodash');
 const _ = require('lodash');
 const assert = require('assert');
 const assert = require('assert');
 
 
-// 
+//
 class MatchSmallGroupScheduleService extends CrudService {
 class MatchSmallGroupScheduleService extends CrudService {
   constructor(ctx) {
   constructor(ctx) {
     super(ctx, 'matchsmallgroupschedule');
     super(ctx, 'matchsmallgroupschedule');
     this.model = this.ctx.model.Race.MatchSmallGroupSchedule;
     this.model = this.ctx.model.Race.MatchSmallGroupSchedule;
   }
   }
 
 
+  async saveAll(data) {
+    for (const i of data) {
+      const { _id } = i;
+      if (!_id) {
+        // TODO: 创建前:需要检查这些人员是否出现在这个项目中的别的组中
+        await this.model.create(i);
+      } else {
+        await this.model.updateOne({ _id }, i);
+      }
+    }
+  }
 }
 }
 
 
 module.exports = MatchSmallGroupScheduleService;
 module.exports = MatchSmallGroupScheduleService;

+ 2 - 1
app/z_router/matchSmallGroupSchedule.js

@@ -7,9 +7,10 @@ const rkey = 'msgs';
 const ckey = 'matchSmallGroupSchedule';
 const ckey = 'matchSmallGroupSchedule';
 const keyZh = '小组赛赛程';
 const keyZh = '小组赛赛程';
 const routes = [
 const routes = [
+  { method: 'post', path: `${rkey}/saveAll`, controller: `${ckey}.saveAll`, name: `${ckey}saveAll`, zh: `${keyZh}全部保存` },
   { method: 'get', path: `${rkey}`, controller: `${ckey}.index`, name: `${ckey}Query`, zh: `${keyZh}列表查询` },
   { method: 'get', path: `${rkey}`, controller: `${ckey}.index`, name: `${ckey}Query`, zh: `${keyZh}列表查询` },
   { method: 'get', path: `${rkey}/:id`, controller: `${ckey}.show`, name: `${ckey}Show`, zh: `${keyZh}查询` },
   { method: 'get', path: `${rkey}/:id`, controller: `${ckey}.show`, name: `${ckey}Show`, zh: `${keyZh}查询` },
-  { method: 'post', path: `${rkey}`, controller: `${ckey}.create`, middleware: [ 'password' ], name: `${ckey}Create`, zh: `创建${keyZh}` },
+  { method: 'post', path: `${rkey}`, controller: `${ckey}.create`, middleware: ['password'], name: `${ckey}Create`, zh: `创建${keyZh}` },
   { method: 'post', path: `${rkey}/:id`, controller: `${ckey}.update`, name: `${ckey}Update`, zh: `修改${keyZh}` },
   { method: 'post', path: `${rkey}/:id`, controller: `${ckey}.update`, name: `${ckey}Update`, zh: `修改${keyZh}` },
   { method: 'delete', path: `${rkey}/:id`, controller: `${ckey}.destroy`, name: `${ckey}Delete`, zh: `删除${keyZh}` },
   { method: 'delete', path: `${rkey}/:id`, controller: `${ckey}.destroy`, name: `${ckey}Delete`, zh: `删除${keyZh}` },
 ];
 ];