瀏覽代碼

Merge branch 'master' of http://git.dayaedu.com/yonge/cooleshow

liujunchi 3 年之前
父節點
當前提交
8819d340f4

+ 2 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/dao/CourseScheduleDao.java

@@ -203,5 +203,7 @@ public interface CourseScheduleDao extends BaseMapper<CourseSchedule> {
 
     //查询老师声部价格
     BigDecimal selectPrice(@Param("teacherId") Long teacherId, @Param("subjectId") Long subjectId);
+
+    List<CourseSchedule> selectSchedule(Integer courseId);
 }
 

+ 1 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/CourseScheduleService.java

@@ -184,7 +184,7 @@ public interface CourseScheduleService extends IService<CourseSchedule> {
 
     void buyPracticeCourseFailed(UserOrderDetailVo orderParam);
 
-    void courseAdjust(CourseAdjustVo adjustVo);
+    void courseAdjust(CourseAdjustVo adjustVo,Long teacherId);
 
     StudentHomePage queryLiveAndVideo(Long studentId, Long teacherId, YesOrNoEnum appAuditVersion);
 

+ 52 - 4
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/CourseScheduleServiceImpl.java

@@ -33,6 +33,7 @@ import com.yonge.toolset.base.exception.BizException;
 import com.yonge.toolset.base.page.PageInfo;
 import com.yonge.toolset.thirdparty.message.MessageSenderPluginContext;
 import com.yonge.toolset.utils.date.DateUtil;
+import com.yonge.toolset.utils.obj.ObjectUtil;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.redisson.api.RMap;
@@ -53,6 +54,8 @@ import java.util.function.BiFunction;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 
+import static com.yonge.cooleshow.biz.dal.support.WrapperUtil.inInterSection;
+
 /**
  * 老师课程表(CourseSchedule)表服务实现类
  *
@@ -881,11 +884,11 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
         if (dateList.size() != courseNum) {
             throw new BizException("课程数与课时数不符");
         }
-        BigDecimal price=baseMapper.selectPrice(scheduleDto.getTeacherId(), scheduleDto.getSubjectId());//老师设置声部价格
+        BigDecimal price = baseMapper.selectPrice(scheduleDto.getTeacherId(), scheduleDto.getSubjectId());//老师设置声部价格
         BigDecimal decimal = new BigDecimal(courseNum);//选购课程节数
         BigDecimal multiply = price.multiply(decimal);//预计总价
-        if (multiply.compareTo(scheduleDto.getCoursePrice())!=0){
-            throw new BizException("价格异常。预计价格:{},实际价格:{}",multiply,scheduleDto.getCoursePrice());
+        if (multiply.compareTo(scheduleDto.getCoursePrice()) != 0) {
+            throw new BizException("价格异常。预计价格:{},实际价格:{}", multiply, scheduleDto.getCoursePrice());
         }
 
         //批量检查老师课时在数据库是否重复
@@ -1039,7 +1042,52 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
      * @Date: 2022/4/21
      */
     @Override
-    public void courseAdjust(CourseAdjustVo adjustVo) {
+    public void courseAdjust(CourseAdjustVo adjustVo, Long teacherId) {
+        Integer courseId = adjustVo.getCourseId();
+        Date classDate = adjustVo.getClassDate();
+        Date startTime = adjustVo.getStartTime();
+        Date endTime = adjustVo.getEndTime();
+        Date now = new Date();
+        //校验时间是否为未来时刻
+        if (classDate.before(now) || startTime.before(now) || endTime.before(now)) {
+            throw new BizException("时间不正确");
+        }
+
+        //校验课程是否存在
+        CourseSchedule schedule = baseMapper.selectOne(Wrappers.<CourseSchedule>lambdaQuery()
+                .eq(CourseSchedule::getId, courseId)
+                .eq(CourseSchedule::getLock, 1)
+                .eq(CourseSchedule::getStatus, CourseScheduleEnum.NOT_START)
+                .eq(CourseSchedule::getType, CourseScheduleEnum.PRACTICE));
+        if (ObjectUtil.isEmpty(schedule)) {
+            throw new BizException("课程不存在");
+        }
+
+        //查询是否有人购买
+        CourseScheduleStudentPayment studentPayment = paymentDao.selectOne(Wrappers.<CourseScheduleStudentPayment>lambdaQuery()
+                .eq(CourseScheduleStudentPayment::getCourseId, courseId)
+                .eq(CourseScheduleStudentPayment::getCourseType, CourseScheduleEnum.PRACTICE));
+        if (ObjectUtil.isEmpty(studentPayment)) {
+            throw new BizException("课程无人购买");
+        }
+
+        //批量检查老师课时在数据库是否重复
+        List<CourseSchedule> scheduleList = this.list(Wrappers.<CourseSchedule>lambdaQuery()
+                .eq(CourseSchedule::getTeacherId, teacherId)
+                .in(CourseSchedule::getStatus, Lists.newArrayList(CourseScheduleEnum.NOT_START.getCode(), CourseScheduleEnum.ING.getCode())));
+        for (CourseSchedule courseSchedule : scheduleList) {
+            if (inInterSection(startTime, endTime, courseSchedule.getStartTime(), courseSchedule.getEndTime(), true)) {
+                throw new BizException("老师排课冲突,课程id:{}", courseSchedule.getId());
+            }
+        }
+        //批量检查学生课时在数据库是否重复
+        List<CourseSchedule> studentList = baseMapper.selectSchedule(courseId);
+        for (CourseSchedule courseSchedule : studentList) {
+            if (inInterSection(startTime, endTime, courseSchedule.getStartTime(), courseSchedule.getEndTime(), true)) {
+                throw new BizException("学生排课冲突,课程id:{}", courseSchedule.getId());
+            }
+        }
+
         baseMapper.courseAdjust(adjustVo);
     }
 

+ 9 - 1
cooleshow-user/user-biz/src/main/resources/config/mybatis/CourseScheduleMapper.xml

@@ -698,4 +698,12 @@
         AND p.subject_id_=#{subjectId}
         AND t.default_flag_=1
     </select>
-</mapper>
+    <select id="selectSchedule" resultType="com.yonge.cooleshow.biz.dal.entity.CourseSchedule"
+            parameterType="java.lang.Integer">
+        SELECT * FROM course_schedule
+        WHERE id_ IN (
+            SELECT course_id_ FROM course_schedule_student_payment
+            WHERE user_id_=(SELECT user_id_ FROM course_schedule_student_payment WHERE course_id_=200 AND course_type_='PRACTICE')
+        )
+    </select>
+</mapper>

+ 5 - 1
cooleshow-user/user-teacher/src/main/java/com/yonge/cooleshow/teacher/controller/TeacherCourseScheduleController.java

@@ -132,7 +132,11 @@ public class TeacherCourseScheduleController extends BaseController {
     @ApiOperation(value = "老师端-课表-日历-调课")
     @PostMapping("/courseAdjust")
     public HttpResponseResult<Object> courseAdjust(@Validated @RequestBody CourseAdjustVo adjustVo) {
-        courseScheduleService.courseAdjust(adjustVo);
+        SysUser user = sysUserFeignService.queryUserInfo();
+        if (user == null || null == user.getId()) {
+            return failed(HttpStatus.FORBIDDEN, "请登录");
+        }
+        courseScheduleService.courseAdjust(adjustVo,user.getId());
         return succeed();
     }
 

+ 44 - 9
toolset/utils/src/main/java/com/yonge/toolset/utils/date/DateUtil.java

@@ -950,6 +950,41 @@ public class DateUtil {
 	}
 
 	/**
+	 * 将字符串转换为指定格式的日期 yyyy-MM-dd HH:mm:ss
+	 *
+	 * @param dateStr
+	 * @return
+	 */
+	public static Date strToDate(String dateStr) {
+		Date date = null;
+		try {
+			SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", DEFAULT_LOCALE);
+			date = simpleDateFormat.parse(dateStr);
+		} catch (ParseException e) {
+			e.printStackTrace();
+		}
+		return date;
+	}
+
+	/**
+	 * 是否大于当前时间
+	 * @param dateStr
+	 * @return
+	 */
+	public static boolean afterNow(String dateStr){
+		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+		Date date = null;
+		Date now = null;
+		try {
+			date = format.parse(dateStr);
+			now = new Date();
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return date.after(now);
+	}
+
+	/**
 	 * 时间转字符串
 	 * @param date
 	 * @return
@@ -1016,15 +1051,15 @@ public class DateUtil {
 		calendar.set(Calendar.SECOND, 59);
 		return calendar.getTime();
 	}
-	
-	public static Date formatHMSToZero(Date date) {    
-        Calendar cal = Calendar.getInstance();  
-        cal.setTime(date);  
-        cal.set(Calendar.HOUR_OF_DAY, 0);  
-        cal.set(Calendar.MINUTE, 0);  
-        cal.set(Calendar.SECOND, 0);  
-        cal.set(Calendar.MILLISECOND, 0);  
-        return cal.getTime(); 
+
+	public static Date formatHMSToZero(Date date) {
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(date);
+        cal.set(Calendar.HOUR_OF_DAY, 0);
+        cal.set(Calendar.MINUTE, 0);
+        cal.set(Calendar.SECOND, 0);
+        cal.set(Calendar.MILLISECOND, 0);
+        return cal.getTime();
     }
 
 	/**