|
@@ -2,6 +2,7 @@ package course
|
2
|
2
|
|
3
|
3
|
import (
|
4
|
4
|
"spaceofcheng/services/models"
|
|
5
|
+ "spaceofcheng/services/models/cases"
|
5
|
6
|
"spaceofcheng/services/models/course"
|
6
|
7
|
"spaceofcheng/services/models/model"
|
7
|
8
|
"spaceofcheng/services/service"
|
|
@@ -13,15 +14,17 @@ import (
|
13
|
14
|
|
14
|
15
|
// CourseServ 系统处理
|
15
|
16
|
type CourseServ struct {
|
16
|
|
- ctx *utils.Context
|
17
|
|
- dao *course.CourseDAO
|
|
17
|
+ ctx *utils.Context
|
|
18
|
+ dao *course.CourseDAO
|
|
19
|
+ casedao *cases.CaseDAO
|
18
|
20
|
}
|
19
|
21
|
|
20
|
22
|
// NewCourseServ 初始化
|
21
|
23
|
func NewCourseServ(ctx *utils.Context) *CourseServ {
|
22
|
24
|
return &CourseServ{
|
23
|
|
- ctx: ctx,
|
24
|
|
- dao: course.NewCourseDAO(ctx),
|
|
25
|
+ ctx: ctx,
|
|
26
|
+ dao: course.NewCourseDAO(ctx),
|
|
27
|
+ casedao: cases.NewCaseDAO(ctx),
|
25
|
28
|
}
|
26
|
29
|
}
|
27
|
30
|
|
|
@@ -83,6 +86,11 @@ func (s *CourseServ) GetCourseByID(courseid string) (*course.CourseDetail, error
|
83
|
86
|
return nil, err
|
84
|
87
|
}
|
85
|
88
|
info.CourseImgs = imgs
|
|
89
|
+ caseinfo, err := s.casedao.GetCaseByID(info.CaseId)
|
|
90
|
+ if err != nil {
|
|
91
|
+ return nil, err
|
|
92
|
+ }
|
|
93
|
+ info.CaseInfo = caseinfo
|
86
|
94
|
return info, nil
|
87
|
95
|
}
|
88
|
96
|
|
|
@@ -180,7 +188,18 @@ func (s *CourseServ) DelCourse(courseid string) error {
|
180
|
188
|
if courseid == "" {
|
181
|
189
|
return utils.LogError("没有对应的课程!")
|
182
|
190
|
}
|
183
|
|
- err := s.dao.DelCourse(courseid)
|
|
191
|
+ courseinfo, err := s.dao.GetCourseByID(courseid)
|
|
192
|
+ if err != nil {
|
|
193
|
+ return err
|
|
194
|
+ }
|
|
195
|
+ if courseinfo.Status != course.STATUS_UNPUBLISH {
|
|
196
|
+ return utils.LogError("课程状态异常!不允许删除!")
|
|
197
|
+ }
|
|
198
|
+ err = s.dao.DelCourse(courseid)
|
|
199
|
+ if err != nil {
|
|
200
|
+ return err
|
|
201
|
+ }
|
|
202
|
+ err = s.dao.DeleteScheduleByCourse(courseid)
|
184
|
203
|
return err
|
185
|
204
|
}
|
186
|
205
|
|
|
@@ -316,14 +335,25 @@ func (s *CourseServ) SaveDetail(detail model.TaCourseDetail) (*model.TaCourseDet
|
316
|
335
|
if detail.BeginDate.After(detail.EndDate) {
|
317
|
336
|
return nil, utils.LogError("课程截止时间必须大于开始时间!")
|
318
|
337
|
}
|
|
338
|
+ courseinfo, err := s.dao.GetCourseByID(detail.CourseId)
|
|
339
|
+ if err != nil {
|
|
340
|
+ return nil, err
|
|
341
|
+ }
|
|
342
|
+ if courseinfo.Status != course.STATUS_UNPUBLISH {
|
|
343
|
+ return nil, utils.LogError("课程状态异常!不允许排课!请刷新后重试!")
|
|
344
|
+ }
|
319
|
345
|
if detail.DetailId == "" {
|
320
|
|
- course, err := s.dao.GetCourseByID(detail.CourseId)
|
|
346
|
+ detail.OrgId = courseinfo.OrgId
|
|
347
|
+ detail.CaseId = courseinfo.CaseId
|
|
348
|
+ newinfo, err = s.dao.AddCourseDetail(detail)
|
321
|
349
|
if err != nil {
|
322
|
350
|
return nil, err
|
323
|
351
|
}
|
324
|
|
- detail.OrgId = course.OrgId
|
325
|
|
- detail.CaseId = course.CaseId
|
326
|
|
- newinfo, err = s.dao.AddCourseDetail(detail)
|
|
352
|
+ num, err := s.dao.GetCourseDetailCount(courseinfo.CourseId)
|
|
353
|
+ if err != nil {
|
|
354
|
+ return nil, err
|
|
355
|
+ }
|
|
356
|
+ err = s.dao.UpdateCourseScheduleNum(courseinfo.CourseId, num)
|
327
|
357
|
if err != nil {
|
328
|
358
|
return nil, err
|
329
|
359
|
}
|
|
@@ -342,6 +372,66 @@ func (s *CourseServ) DelCourseDetail(detailid string) error {
|
342
|
372
|
if detailid == "" {
|
343
|
373
|
return utils.LogError("没有对应的排课信息!")
|
344
|
374
|
}
|
345
|
|
- err := s.dao.DelCourseDetail(detailid)
|
346
|
|
- return err
|
|
375
|
+ detail, err := s.dao.GetDetailByID(detailid)
|
|
376
|
+ if err != nil {
|
|
377
|
+ return err
|
|
378
|
+ }
|
|
379
|
+ courseinfo, err := s.dao.GetCourseByID(detail.CourseId)
|
|
380
|
+ if err != nil {
|
|
381
|
+ return err
|
|
382
|
+ }
|
|
383
|
+ if courseinfo.Status != course.STATUS_UNPUBLISH {
|
|
384
|
+ return utils.LogError("课程状态异常!不允许删除!")
|
|
385
|
+ }
|
|
386
|
+ err = s.dao.DelCourseDetail(detailid)
|
|
387
|
+ if err != nil {
|
|
388
|
+ return err
|
|
389
|
+ }
|
|
390
|
+ num, err := s.dao.GetCourseDetailCount(courseinfo.CourseId)
|
|
391
|
+ if err != nil {
|
|
392
|
+ return err
|
|
393
|
+ }
|
|
394
|
+ err = s.dao.UpdateCourseScheduleNum(courseinfo.CourseId, num)
|
|
395
|
+ if err != nil {
|
|
396
|
+ return err
|
|
397
|
+ }
|
|
398
|
+ return nil
|
|
399
|
+}
|
|
400
|
+
|
|
401
|
+// GetCourseBySelect 获取精选课程
|
|
402
|
+func (s *CourseServ) GetSelectCourseList(orgid string) ([]course.CourseDetail, error) {
|
|
403
|
+ if orgid == "" {
|
|
404
|
+ return nil, utils.LogError("参数错误!")
|
|
405
|
+ }
|
|
406
|
+ list, err := s.dao.GetSelectCourseList(orgid)
|
|
407
|
+ if err != nil {
|
|
408
|
+ return nil, err
|
|
409
|
+ }
|
|
410
|
+ for i, v := range list {
|
|
411
|
+ caseinfo, err := s.casedao.GetCaseByID(v.CaseId)
|
|
412
|
+ if err != nil {
|
|
413
|
+ return nil, err
|
|
414
|
+ }
|
|
415
|
+ list[i].CaseInfo = caseinfo
|
|
416
|
+ }
|
|
417
|
+ return list, err
|
|
418
|
+}
|
|
419
|
+
|
|
420
|
+// GetCourseByLocation 根据位置获取课程
|
|
421
|
+func (s *CourseServ) GetCourseByLocation(orgid, locationid string) ([]course.CourseDetail, error) {
|
|
422
|
+ if orgid == "" || locationid == "" {
|
|
423
|
+ return nil, utils.LogError("参数错误!")
|
|
424
|
+ }
|
|
425
|
+ list, err := s.dao.GetCourseByLocation(orgid, locationid)
|
|
426
|
+ if err != nil {
|
|
427
|
+ return nil, err
|
|
428
|
+ }
|
|
429
|
+ for i, v := range list {
|
|
430
|
+ caseinfo, err := s.casedao.GetCaseByID(v.CaseId)
|
|
431
|
+ if err != nil {
|
|
432
|
+ return nil, err
|
|
433
|
+ }
|
|
434
|
+ list[i].CaseInfo = caseinfo
|
|
435
|
+ }
|
|
436
|
+ return list, err
|
347
|
437
|
}
|