浏览代码

feat:作业布置接口抽取

Joburgess 4 年之前
父节点
当前提交
e069bffcf1

+ 10 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/CourseHomeworkService.java

@@ -13,6 +13,15 @@ import java.util.Map;
 public interface CourseHomeworkService extends BaseService<Long, CourseHomework> {
 
 	/**
+	 * @describe 布置作业
+	 * @author qnc99
+	 * @date 2020/12/2 0002
+	 * @param courseHomework:
+	 * @return void
+	 */
+	void addCourseHomework(CourseHomework courseHomework);
+
+	/**
 	 * @describe 根据班级获取教师布置的作业
 	 * @author Joburgess
 	 * @date 2019/10/20
@@ -46,4 +55,4 @@ public interface CourseHomeworkService extends BaseService<Long, CourseHomework>
 	 * @return
 	 */
 	PageInfo<WebCourseHomeworkListDto> queryHomePage(CourseHomeWorkTemplateQueryInfo queryInfo);
-}
+}

+ 44 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/CourseHomeworkServiceImpl.java

@@ -1,12 +1,14 @@
 package com.ym.mec.biz.service.impl;
 
 import com.ym.mec.biz.dal.dao.CourseHomeworkDao;
+import com.ym.mec.biz.dal.dao.CourseScheduleDao;
 import com.ym.mec.biz.dal.dao.StudentCourseHomeworkDao;
 import com.ym.mec.biz.dal.dao.StudentCourseHomeworkReplyDao;
 import com.ym.mec.biz.dal.dto.Mapper;
 import com.ym.mec.biz.dal.dto.TeacherHomeworkListDto;
 import com.ym.mec.biz.dal.dto.WebCourseHomeworkListDto;
 import com.ym.mec.biz.dal.entity.CourseHomework;
+import com.ym.mec.biz.dal.entity.CourseSchedule;
 import com.ym.mec.biz.dal.entity.StudentCourseHomework;
 import com.ym.mec.biz.dal.enums.MessageTypeEnum;
 import com.ym.mec.biz.dal.enums.YesOrNoEnum;
@@ -15,11 +17,13 @@ import com.ym.mec.biz.dal.page.CourseHomeworkQueryInfo;
 import com.ym.mec.biz.service.CourseHomeworkService;
 import com.ym.mec.biz.service.SysMessageService;
 import com.ym.mec.common.dal.BaseDAO;
+import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.thirdparty.message.MessageSenderPluginContext.MessageSender;
 import com.ym.mec.util.collection.MapUtil;
 import com.ym.mec.util.date.DateUtil;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
@@ -43,6 +47,8 @@ public class CourseHomeworkServiceImpl extends BaseServiceImpl<Long, CourseHomew
 
 	@Autowired
 	private SysMessageService sysMessageService;
+	@Autowired
+	private CourseScheduleDao courseScheduleDao;
 
 	@Override
 	public BaseDAO<Long, CourseHomework> getDAO() {
@@ -50,6 +56,44 @@ public class CourseHomeworkServiceImpl extends BaseServiceImpl<Long, CourseHomew
 	}
 
 	@Override
+	public void addCourseHomework(CourseHomework courseHomework) {
+		if(Objects.isNull(courseHomework.getCourseScheduleId())){
+			throw new BizException("课程不存在");
+		}
+		if(StringUtils.isBlank(courseHomework.getContent())){
+			throw new BizException("请填写作业内容");
+		}
+		CourseSchedule courseSchedule = courseScheduleDao.get(courseHomework.getCourseScheduleId());
+		if(Objects.isNull(courseSchedule)){
+			throw new BizException("课程不存在");
+		}
+		Date date=new Date();
+		CourseHomework oldCourseHomework = courseHomeworkDao.findByCourseSchedule(courseHomework.getCourseScheduleId());
+		if(Objects.isNull(oldCourseHomework)){
+			//新增课堂作业
+			oldCourseHomework=courseHomework;
+			oldCourseHomework.setCourseScheduleId(courseSchedule.getId());
+			oldCourseHomework.setMusicGroupId(courseSchedule.getMusicGroupId());
+			oldCourseHomework.setGroupType(courseSchedule.getGroupType());
+			oldCourseHomework.setClassGroupId(courseSchedule.getClassGroupId());
+			oldCourseHomework.setExpiryDate(DateUtil.addDays(date,7));
+			oldCourseHomework.setExpectNum(courseScheduleDao.countCourseStudentNum(courseSchedule.getId()));
+			courseHomeworkDao.insert(oldCourseHomework);
+			List<StudentCourseHomework> studentCourseHomeworks = studentCourseHomeworkDao
+					.constructInitialStudentHomeworkRecordsWithPayment(courseSchedule.getId(),
+							oldCourseHomework.getId());
+			if(CollectionUtils.isEmpty(studentCourseHomeworks)){
+				throw new BizException("此课程没有学生");
+			}
+			studentCourseHomeworkDao.batchInsertStudentCourseHomeworkRecord(studentCourseHomeworks);
+		}else{
+			oldCourseHomework.setContent(courseHomework.getContent());
+			oldCourseHomework.setAttachments(courseHomework.getAttachments());
+			courseHomeworkDao.update(oldCourseHomework);
+		}
+	}
+
+	@Override
 	public List<Map<String, Object>> findTeacherCourseHomeworkByClassGroup(CourseHomeworkQueryInfo queryInfo) {
 		Map<String, Object> params = new HashMap<>();
 		MapUtil.populateMap(params, queryInfo);

+ 11 - 2
mec-teacher/src/main/java/com/ym/mec/teacher/controller/CourseHomeworkController.java

@@ -3,6 +3,7 @@ package com.ym.mec.teacher.controller;
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dto.CourseHomeworkStudentDetailDto;
+import com.ym.mec.biz.dal.entity.CourseHomework;
 import com.ym.mec.biz.dal.entity.ExtracurricularExercisesReply;
 import com.ym.mec.biz.dal.entity.StudentCourseHomework;
 import com.ym.mec.biz.dal.enums.YesOrNoEnum;
@@ -11,6 +12,7 @@ import com.ym.mec.biz.service.CourseHomeworkService;
 import com.ym.mec.biz.service.ExtracurricularExercisesReplyService;
 import com.ym.mec.biz.service.StudentCourseHomeworkService;
 import com.ym.mec.common.controller.BaseController;
+import com.ym.mec.common.entity.HttpResponseResult;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -31,7 +33,7 @@ import java.util.Objects;
 public class CourseHomeworkController extends BaseController {
 
     @Autowired
-    private CourseHomeworkService courseScheduleService;
+    private CourseHomeworkService courseHomeworkService;
     @Autowired
     private StudentCourseHomeworkService studentCourseHomeworkService;
     @Autowired
@@ -39,6 +41,13 @@ public class CourseHomeworkController extends BaseController {
     @Autowired
     private SysUserFeignService sysUserFeignService;
 
+    @ApiOperation(value = "布置课堂作业")
+    @GetMapping("/addCourseHomework")
+    public HttpResponseResult addCourseHomework(CourseHomework courseHomework){
+        courseHomeworkService.addCourseHomework(courseHomework);
+        return succeed();
+    }
+
     @ApiOperation(value = "根据班级获取教师布置的作业")
     @GetMapping("/findTeacherCourseHomeworkByClassGroup")
     public Object findTeacherCourseHomeworkByClassGroup(CourseHomeworkQueryInfo queryInfo){
@@ -47,7 +56,7 @@ public class CourseHomeworkController extends BaseController {
             return failed(HttpStatus.FORBIDDEN,"请登录");
         }
         queryInfo.setUserId(sysUser.getId().longValue());
-        return succeed(courseScheduleService.findTeacherCourseHomeworkByClassGroup(queryInfo));
+        return succeed(courseHomeworkService.findTeacherCourseHomeworkByClassGroup(queryInfo));
     }
 
     @ApiOperation(value = "根据课程计划获取需要交作业的学生")