Commit b3fbf409 authored by luzhuang's avatar luzhuang

删除章节更新lesson中时长

parent dccfd9a3
......@@ -76,7 +76,7 @@ public class BChapterController extends PaginationController<BChapter> {
@ApiOperation(value = "202 删除章节", notes = "根据ID删除一条记录")
@ApiImplicitParam(name = "id", value = "章节Id", required = true, dataType = "varchar")
@PostMapping(value = "/remove")
public Result remove(CurUser curUser,@Valid String id,BindingResult br) {
public Result remove(CurUser curUser,String id) {
PersistModel data = bChapterService.removeBChapter(id);
return Result.builder(data,
MessageConstant.MESSAGE_ALERT_SUCCESS,
......
......@@ -365,17 +365,37 @@ public interface BChapterRepository extends BaseMapper<BChapter> {
int updateVideoTimeInLesson(@Param("time") String time,@Param("id") String id);
/**
* 根据lessonid获取它第一章第一节的章节id
* 根据lessonid获取它第一节的章节id
* @param lessonId
* @return
*/
@Select("SELECT business_id FROM b_chapter " +
"WHERE pid = " +
"( SELECT business_id FROM b_chapter " +
"WHERE lesson_id = #{lessonId} AND chapter_level = 1 AND del_flag != 1 AND flag = 1 ORDER BY sort LIMIT 1 ) " +
"ORDER BY sort LIMIT 1")
@Select("select c1.business_id from b_chapter c1 " +
"left join b_chapter c2 on c1.pid = c2.business_id " +
"where c1.lesson_id = #{lessonId} " +
"and c1.chapter_level = 2 " +
"and c1.del_flag != 1 " +
"and c1.flag = 1 " +
"and c2.del_flag != 1 " +
"and c2.flag = 1 " +
"ORDER BY c2.sort ,c1.sort limit 1")
String getFirstChapter(@Param("lessonId") String lessonId);
/**
* 更新b_lesson 表中 course_time
* @param time
* @param id
* @return
*/
@Update("update b_lesson set course_time = #{time} where business_id = #{id}")
int updateCourseTimeForLesson(@Param("time") String time ,@Param("id") String id);
/**
* 根据businessid 获取 该节 的课程时长
* @param id
* @return
*/
@Select("select course_time from b_chapter where business_id = #{id}")
String getTimeByChapterId(@Param("id") String id);
/**
* 根据章节id查询所在课程id
* @param businessId
......
......@@ -240,7 +240,7 @@ public class BChapterServiceImpl implements BChapterService {
chapterDTO.setIsTest(dto.getType());
line = bChapterRepository.insertSelective(model);
//先判断该课程的第一章的第一节是否是本节 更新blesson表中course_time字段
//先判断该课程的第一节是否是本节 更新blesson表中course_time字段
String cid = bChapterRepository.getFirstChapter(model.getLessonId());
if (cid.equals(model.getBusinessId())) {
bChapterRepository.updateVideoTimeInLesson(model.getCourseTime(), model.getLessonId());
......@@ -314,10 +314,19 @@ public class BChapterServiceImpl implements BChapterService {
if (isChapter && hasChild) {
throw new ServiceException(ResultServiceEnums.CHAPTER_HAS_CHILD);
}
int line = bChapterRepository.removeByPrimaryKey(id);
String lessonId = bChapterRepository.getLessonIdBychaperId(id);
//获取第一节课的id 与当前id对比
String firstId = bChapterRepository.getFirstChapter(lessonId);
int line = bChapterRepository.removeByPrimaryKey(id);
bChapterRepository.updateClassHourInLesson(lessonId);
if(firstId.equals(id)){
//当前节为第一节 获取下一节的课程时长
String secondId = bChapterRepository.getFirstChapter(lessonId);
String time = bChapterRepository.getTimeByChapterId(secondId);
//更新到b_lesson 表
bChapterRepository.updateCourseTimeForLesson(time,lessonId);
}
return new PersistModel(line);
}
......
......@@ -19,10 +19,7 @@ import org.rcisoft.core.util.UserUtil;
import org.rcisoft.sys.user.bean.CurUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment