Commit b45050c6 authored by 王淑君's avatar 王淑君

修改接口

parent 79b1e8a6
package org.rcisoft.business.blesson.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
@Data
@EqualsAndHashCode
@AllArgsConstructor
@NoArgsConstructor
public class SynUserDTO {
private String userId;
}
package org.rcisoft.business.blesson.util; package org.rcisoft.business.blesson.util;
import org.rcisoft.business.blesson.dto.SynLessonDTO; import org.rcisoft.business.blesson.dto.SynLessonDTO;
import org.rcisoft.business.blesson.dto.SynUserDTO;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
...@@ -15,6 +16,8 @@ public class LessonSyncUtil { ...@@ -15,6 +16,8 @@ public class LessonSyncUtil {
private static Map<String, SynLessonDTO> synLessonDTOList = new HashMap<>(); private static Map<String, SynLessonDTO> synLessonDTOList = new HashMap<>();
private static Map<String, SynUserDTO> synUserDTOList = new HashMap<>();
public static SynLessonDTO getSynLessonDTO(String lessonId){ public static SynLessonDTO getSynLessonDTO(String lessonId){
if(synLessonDTOList.containsKey(lessonId)) if(synLessonDTOList.containsKey(lessonId))
...@@ -29,4 +32,17 @@ public class LessonSyncUtil { ...@@ -29,4 +32,17 @@ public class LessonSyncUtil {
synLessonDTOList.remove(lessonId); synLessonDTOList.remove(lessonId);
} }
public static SynUserDTO getSynUserDTO(String userId){
if(synUserDTOList.containsKey(userId))
return synUserDTOList.get(userId);
SynUserDTO synUserDTO = new SynUserDTO(userId);
synUserDTOList.put(userId,synUserDTO);
return synUserDTO;
}
public static void removeSynUserDTO(String userId){
if(synUserDTOList.containsKey(userId))
synUserDTOList.remove(userId);
}
} }
...@@ -7,6 +7,7 @@ import io.swagger.annotations.ApiImplicitParam; ...@@ -7,6 +7,7 @@ import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.rcisoft.business.blesson.entity.BLessonPerson; import org.rcisoft.business.blesson.entity.BLessonPerson;
import org.rcisoft.business.blesson.util.LessonSyncUtil;
import org.rcisoft.business.brstudentchapter.dto.BRStudentChapterDto; import org.rcisoft.business.brstudentchapter.dto.BRStudentChapterDto;
import org.rcisoft.common.controller.PaginationController; import org.rcisoft.common.controller.PaginationController;
import org.rcisoft.sys.user.bean.CurUser; import org.rcisoft.sys.user.bean.CurUser;
...@@ -27,6 +28,7 @@ import org.rcisoft.business.brstudentchapter.entity.BRStudentChapter; ...@@ -27,6 +28,7 @@ import org.rcisoft.business.brstudentchapter.entity.BRStudentChapter;
import org.rcisoft.business.brstudentchapter.service.BRStudentChapterService; import org.rcisoft.business.brstudentchapter.service.BRStudentChapterService;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* Created by on 2019-9-25 10:01:43. * Created by on 2019-9-25 10:01:43.
...@@ -41,14 +43,15 @@ public class BRStudentChapterController extends PaginationController<BRStudentCh ...@@ -41,14 +43,15 @@ public class BRStudentChapterController extends PaginationController<BRStudentCh
@ApiOperation(value="1201 添加/更新学生端观看章节进度", notes="添加/更新") @ApiOperation(value="1201 添加/更新学生端观看章节进度", notes="添加/更新")
//@ApiImplicitParams({@ApiImplicitParam(name = "businessId", value = "businessId", required = false, dataType = "varchar")})
@PostMapping(value = "/add") @PostMapping(value = "/add")
public Result addOrUpdate(CurUser curUser, @Valid BRStudentChapterDto brStudentChapterDto, BindingResult bindingResult) { public Result addOrUpdate(CurUser curUser, @Valid BRStudentChapterDto brStudentChapterDto, BindingResult bindingResult) {
brStudentChapterDto.setStudentId(curUser.getUserId()); brStudentChapterDto.setStudentId(curUser.getUserId());
Map map = bRStudentChapterServiceImpl.save(brStudentChapterDto, curUser);
LessonSyncUtil.removeSynLessonDTO(brStudentChapterDto.getStudentId());
return Result.builder( new PersistModel(1), return Result.builder( new PersistModel(1),
MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR, MessageConstant.MESSAGE_ALERT_ERROR,
bRStudentChapterServiceImpl.save(brStudentChapterDto, curUser)); map );
} }
} }
...@@ -13,6 +13,7 @@ import org.rcisoft.business.blesson.entity.BLesson; ...@@ -13,6 +13,7 @@ import org.rcisoft.business.blesson.entity.BLesson;
import org.rcisoft.business.blesson.entity.BLessonPerson; import org.rcisoft.business.blesson.entity.BLessonPerson;
import org.rcisoft.business.blesson.enums.IsFinishEnum; import org.rcisoft.business.blesson.enums.IsFinishEnum;
import org.rcisoft.business.blesson.service.impl.BLessonServiceImpl; import org.rcisoft.business.blesson.service.impl.BLessonServiceImpl;
import org.rcisoft.business.blesson.util.LessonSyncUtil;
import org.rcisoft.business.bpersonvalue.entity.BPersonValue; import org.rcisoft.business.bpersonvalue.entity.BPersonValue;
import org.rcisoft.business.brstudentchapter.dto.BRStudentChapterDto; import org.rcisoft.business.brstudentchapter.dto.BRStudentChapterDto;
import org.rcisoft.core.util.IdGen; import org.rcisoft.core.util.IdGen;
...@@ -36,6 +37,7 @@ import java.util.Date; ...@@ -36,6 +37,7 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Semaphore;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -74,33 +76,35 @@ public class BRStudentChapterServiceImpl implements BRStudentChapterService { ...@@ -74,33 +76,35 @@ public class BRStudentChapterServiceImpl implements BRStudentChapterService {
String currentProgress = ""; String currentProgress = "";
NumberFormat numberFormat = NumberFormat.getInstance(); NumberFormat numberFormat = NumberFormat.getInstance();
numberFormat.setMaximumFractionDigits(0); numberFormat.setMaximumFractionDigits(0);
// 查詢是否已經開始觀看此章節 synchronized (LessonSyncUtil.getSynUserDTO(brStudentChapterDto.getStudentId())) {
List<BRStudentChapter> brStudentChapterList = bRStudentChapterRepository.queryByStuIdAndChapter(brStudentChapterDto.getChapterId(),brStudentChapterDto.getStudentId()); // 查詢是否已經開始觀看此章節
// 沒有開始看-新增信息 List<BRStudentChapter> brStudentChapterList = bRStudentChapterRepository.queryByStuIdAndChapter(brStudentChapterDto.getChapterId(),brStudentChapterDto.getStudentId());
if (null != brStudentChapterList && brStudentChapterList.size() >0 && brStudentChapterList.get(0) != null){ // 沒有開始看-新增信息
double old = brStudentChapterList.get(0).getProgress(); if (null != brStudentChapterList && brStudentChapterList.size() >0 && brStudentChapterList.get(0) != null){
BRStudentChapter brStudentChapter = this.dealBrstudentChapter(brStudentChapterList.get(0), brStudentChapterDto); double old = brStudentChapterList.get(0).getProgress() ;
// 判断进度 是否大于数据库已经存在的进度 BRStudentChapter brStudentChapter = this.dealBrstudentChapter(brStudentChapterList.get(0), brStudentChapterDto);
double now = brStudentChapter.getProgress(); // 判断进度 是否大于数据库已经存在的进度
if (now >= old){ // 进度大于以前的进度 double now = brStudentChapter.getProgress();
currentProgress = (now*100)+"%"; if (now >= old){ // 进度大于以前的进度
if (brStudentChapterDto.getMaxPosition() != null){ currentProgress = (now*100)+"%";
brStudentChapter.setMaxPosition(brStudentChapterDto.getMaxPosition()); if (brStudentChapterDto.getMaxPosition() != null){
brStudentChapter.setMaxPosition(brStudentChapterDto.getMaxPosition());
}
line = bRStudentChapterRepository.updateById(brStudentChapter);
}else { // 反之,只需更新最近看的时间
brStudentChapter.setProgress(old);
currentProgress = (old*100)+"%";
line = bRStudentChapterRepository.updateById(brStudentChapter);
} }
line = bRStudentChapterRepository.updateById(brStudentChapter); }else { // 更新
}else { // 反之,只需更新最近看的时间 BRStudentChapter brStudentChapter = new BRStudentChapter();
brStudentChapter.setProgress(old); brStudentChapter.setBusinessId(IdGen.uuid());
currentProgress = (old*100)+"%"; brStudentChapter = this.dealBrstudentChapter(brStudentChapter, brStudentChapterDto);
line = bRStudentChapterRepository.updateById(brStudentChapter); brStudentChapter.setStudentId(brStudentChapterDto.getStudentId());
brStudentChapter.setChapterId(brStudentChapterDto.getChapterId());
currentProgress = (brStudentChapter.getProgress()*100)+"%";
line = bRStudentChapterRepository.insertSelective(brStudentChapter);
} }
}else { // 更新
BRStudentChapter brStudentChapter = new BRStudentChapter();
brStudentChapter.setBusinessId(IdGen.uuid());
brStudentChapter = this.dealBrstudentChapter(brStudentChapter, brStudentChapterDto);
brStudentChapter.setStudentId(brStudentChapterDto.getStudentId());
brStudentChapter.setChapterId(brStudentChapterDto.getChapterId());
currentProgress = (brStudentChapter.getProgress()*100)+"%";
line = bRStudentChapterRepository.insertSelective(brStudentChapter);
} }
// b_lesson_person // b_lesson_person
LessonAndUserDTO addMy = new LessonAndUserDTO(); LessonAndUserDTO addMy = new LessonAndUserDTO();
......
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