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

更新课程学习总进度

parent 08f09eec
...@@ -53,6 +53,15 @@ public interface BChapterService{ ...@@ -53,6 +53,15 @@ public interface BChapterService{
*/ */
Map queryBChaptersWithProgress(String lessonId, CurUser curUser); Map queryBChaptersWithProgress(String lessonId, CurUser curUser);
/**
*
* @param model
* @param corpId
* @return
*/
List<QueryChapterListResDTO> queryChapterListResDTO(QueryChapterListDTO model, String corpId);
/** /**
* 插入 * 插入
* @param chapterDTO * @param chapterDTO
......
...@@ -118,8 +118,8 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -118,8 +118,8 @@ public class BChapterServiceImpl implements BChapterService {
model.setLessonId(lessonId); model.setLessonId(lessonId);
model.setStudentId(curUser.getUserId()); model.setStudentId(curUser.getUserId());
List<QueryChapterListResDTO> queryChapterListResDTOS = queryChapterListResDTO(model, curUser.getCorpId()); List<QueryChapterListResDTO> queryChapterListResDTOS = queryChapterListResDTO(model, curUser.getCorpId());
int i = 0; // int i = 0;
int percent = 0; // int percent = 0;
for (QueryChapterListResDTO queryChapterListResDTO : queryChapterListResDTOS) { for (QueryChapterListResDTO queryChapterListResDTO : queryChapterListResDTOS) {
for (QueryChapterListResDTO childList : queryChapterListResDTO.getChildList()) { for (QueryChapterListResDTO childList : queryChapterListResDTO.getChildList()) {
// 遍历学生章节中间表 查询学生观看章节进度 // 遍历学生章节中间表 查询学生观看章节进度
...@@ -127,15 +127,21 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -127,15 +127,21 @@ public class BChapterServiceImpl implements BChapterService {
if (null != brStudentChapterList && brStudentChapterList.size() > 0) { if (null != brStudentChapterList && brStudentChapterList.size() > 0) {
childList.setProgress(brStudentChapterList.get(0).getProgress() * 100 + "%"); childList.setProgress(brStudentChapterList.get(0).getProgress() * 100 + "%");
childList.setCurrentLocation(brStudentChapterList.get(0).getCurrentLocation()); childList.setCurrentLocation(brStudentChapterList.get(0).getCurrentLocation());
percent += brStudentChapterList.get(0).getProgress(); // percent += brStudentChapterList.get(0).getProgress();
} }
i++; // i++;
} }
} }
Map map = new HashMap(); Map map = new HashMap();
DecimalFormat df = new DecimalFormat("0.00");//设置保留位数 DecimalFormat df = new DecimalFormat("0.00");//设置保留位数
map.put("chapterList", queryChapterListResDTOS); map.put("chapterList", queryChapterListResDTOS);
map.put("totalProgress", i == 0 ? "0%" : df.format((float) percent / i) + "%"); BLessonPerson bLessonPerson = bLessonPersonRepository.getAppointInTraining(lessonId, curUser.getUserId());
if (null != bLessonPerson) {
map.put("totalProgress", bLessonPerson.getLearnProgress());
}else {
map.put("totalProgress", "0%");
}
// map.put("totalProgress", i == 0 ? "0%" : df.format((float) percent / i) + "%");
BLesson bLesson = bLessonRepository.selectByPrimaryKey(lessonId); BLesson bLesson = bLessonRepository.selectByPrimaryKey(lessonId);
if (bLesson == null){ if (bLesson == null){
throw new ServiceException(ResultServiceEnums.LESSON_NOT_EXISTA); throw new ServiceException(ResultServiceEnums.LESSON_NOT_EXISTA);
...@@ -170,6 +176,7 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -170,6 +176,7 @@ public class BChapterServiceImpl implements BChapterService {
* @param model * @param model
* @return * @return
*/ */
@Override
public List<QueryChapterListResDTO> queryChapterListResDTO(QueryChapterListDTO model, String corpId) { public List<QueryChapterListResDTO> queryChapterListResDTO(QueryChapterListDTO model, String corpId) {
Map param = new HashMap<String, Object>(); Map param = new HashMap<String, Object>();
if (model.getLessonId() != null && !"".equals(model.getLessonId())) { if (model.getLessonId() != null && !"".equals(model.getLessonId())) {
......
...@@ -44,7 +44,7 @@ public class BRStudentChapterController extends PaginationController<BRStudentCh ...@@ -44,7 +44,7 @@ public class BRStudentChapterController extends PaginationController<BRStudentCh
@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());
PersistModel data = bRStudentChapterServiceImpl.save(brStudentChapterDto); PersistModel data = bRStudentChapterServiceImpl.save(brStudentChapterDto, curUser);
return Result.builder(data, return Result.builder(data,
MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR, MessageConstant.MESSAGE_ALERT_ERROR,
......
...@@ -4,6 +4,7 @@ import org.rcisoft.business.brstudentchapter.dto.BRStudentChapterDto; ...@@ -4,6 +4,7 @@ import org.rcisoft.business.brstudentchapter.dto.BRStudentChapterDto;
import org.rcisoft.business.brstudentchapter.entity.BRStudentChapter; import org.rcisoft.business.brstudentchapter.entity.BRStudentChapter;
import org.rcisoft.core.model.PersistModel; import org.rcisoft.core.model.PersistModel;
import org.rcisoft.core.aop.PageUtil; import org.rcisoft.core.aop.PageUtil;
import org.rcisoft.sys.user.bean.CurUser;
import java.util.List; import java.util.List;
...@@ -17,7 +18,7 @@ public interface BRStudentChapterService { ...@@ -17,7 +18,7 @@ public interface BRStudentChapterService {
* @param bRStudentChapter * @param bRStudentChapter
* @return * @return
*/ */
PersistModel save(BRStudentChapterDto bRStudentChapter); PersistModel save(BRStudentChapterDto bRStudentChapter, CurUser curUser);
/** /**
* 根据id查询 * 根据id查询
......
package org.rcisoft.business.brstudentchapter.service.impl; package org.rcisoft.business.brstudentchapter.service.impl;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.netflix.discovery.converters.Auto;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.rcisoft.business.bchapter.dao.BChapterRepository; import org.rcisoft.business.bchapter.dao.BChapterRepository;
import org.rcisoft.business.bchapter.dto.QueryChapterListDTO;
import org.rcisoft.business.bchapter.dto.QueryChapterListResDTO;
import org.rcisoft.business.bchapter.entity.BChapter; import org.rcisoft.business.bchapter.entity.BChapter;
import org.rcisoft.business.bchapter.service.BChapterService;
import org.rcisoft.business.blesson.dao.BLessonPersonRepository; import org.rcisoft.business.blesson.dao.BLessonPersonRepository;
import org.rcisoft.business.blesson.dto.AddMyLearnLessonDTO; import org.rcisoft.business.blesson.dto.AddMyLearnLessonDTO;
import org.rcisoft.business.blesson.entity.BLesson; import org.rcisoft.business.blesson.entity.BLesson;
...@@ -18,6 +22,7 @@ import org.rcisoft.business.brstudentchapter.entity.BRStudentChapter; ...@@ -18,6 +22,7 @@ import org.rcisoft.business.brstudentchapter.entity.BRStudentChapter;
import org.rcisoft.business.brstudentchapter.service.BRStudentChapterService; import org.rcisoft.business.brstudentchapter.service.BRStudentChapterService;
import org.rcisoft.sys.user.bean.CurUser;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Isolation;
...@@ -45,6 +50,10 @@ public class BRStudentChapterServiceImpl implements BRStudentChapterService { ...@@ -45,6 +50,10 @@ public class BRStudentChapterServiceImpl implements BRStudentChapterService {
private BLessonPersonRepository bLessonPersonRepository; private BLessonPersonRepository bLessonPersonRepository;
@Autowired @Autowired
private BChapterRepository bChapterRepository; private BChapterRepository bChapterRepository;
@Autowired
private BChapterService bChapterServiceImpl;
@Autowired
BRStudentChapterRepository brStudentChapterRepository;
/** /**
* *
...@@ -53,16 +62,43 @@ public class BRStudentChapterServiceImpl implements BRStudentChapterService { ...@@ -53,16 +62,43 @@ public class BRStudentChapterServiceImpl implements BRStudentChapterService {
*/ */
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT) @Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT)
@Override @Override
public PersistModel save(BRStudentChapterDto brStudentChapterDto){ public PersistModel save(BRStudentChapterDto brStudentChapterDto, CurUser curUser){
int line = 0; int line = 0;
DecimalFormat df=new DecimalFormat("0.00");//设置保留位数
AddMyLearnLessonDTO addMy = new AddMyLearnLessonDTO(); AddMyLearnLessonDTO addMy = new AddMyLearnLessonDTO();
addMy.setUserId(brStudentChapterDto.getStudentId()); addMy.setUserId(brStudentChapterDto.getStudentId());
addMy.setLessonId(brStudentChapterDto.getLessonId()); addMy.setLessonId(brStudentChapterDto.getLessonId());
List<BLessonPerson> bLessonPersonList = bLessonPersonRepository.selectByPersonAndLesson(addMy); List<BLessonPerson> bLessonPersonList = bLessonPersonRepository.selectByPersonAndLesson(addMy);
// 将课程总进度存进数据库
QueryChapterListDTO model = new QueryChapterListDTO();
model.setLessonId(brStudentChapterDto.getLessonId());
model.setStudentId(brStudentChapterDto.getStudentId());
List<QueryChapterListResDTO> queryChapterListResDTOS = bChapterServiceImpl.queryChapterListResDTO(model, curUser.getCorpId());
int i = 0;
int percent = 0;
for (QueryChapterListResDTO queryChapterListResDTO : queryChapterListResDTOS) {
for (QueryChapterListResDTO childList : queryChapterListResDTO.getChildList()) {
// 遍历学生章节中间表 查询学生观看章节进度
List<BRStudentChapter> brStudentChapters = brStudentChapterRepository.queryByStuIdAndChapter(childList.getBusinessId(), curUser.getUserId());
if (null != brStudentChapters && brStudentChapters.size() > 0) {
childList.setProgress(brStudentChapters.get(0).getProgress() * 100 + "%");
childList.setCurrentLocation(brStudentChapters.get(0).getCurrentLocation());
percent += brStudentChapters.get(0).getProgress();
}
i++;
}
}
String totalProgress = "";
if (i==0){
totalProgress = "0%";
}else {
totalProgress = df.format((float) percent / i) + "%";
};
// 判斷是否已經開始觀看此課程 // 判斷是否已經開始觀看此課程
if (null != bLessonPersonList && bLessonPersonList.size() >0){ if (null != bLessonPersonList && bLessonPersonList.size() >0){
BLessonPerson bLessonPerson = bLessonPersonList.get(0); BLessonPerson bLessonPerson = bLessonPersonList.get(0);
bLessonPerson.setChapterId(brStudentChapterDto.getChapterId()); bLessonPerson.setChapterId(brStudentChapterDto.getChapterId());
bLessonPerson.setLearnProgress(totalProgress); // 保存课程学习进度
bLessonPersonRepository.updateByPrimaryKeySelective(bLessonPerson); bLessonPersonRepository.updateByPrimaryKeySelective(bLessonPerson);
}else { }else {
BLessonPerson bLessonPerson = new BLessonPerson(); BLessonPerson bLessonPerson = new BLessonPerson();
...@@ -70,11 +106,11 @@ public class BRStudentChapterServiceImpl implements BRStudentChapterService { ...@@ -70,11 +106,11 @@ public class BRStudentChapterServiceImpl implements BRStudentChapterService {
bLessonPerson.setChapterId(brStudentChapterDto.getChapterId()); bLessonPerson.setChapterId(brStudentChapterDto.getChapterId());
bLessonPerson.setPersonId(brStudentChapterDto.getStudentId()); bLessonPerson.setPersonId(brStudentChapterDto.getStudentId());
bLessonPerson.setLessonId(brStudentChapterDto.getLessonId()); bLessonPerson.setLessonId(brStudentChapterDto.getLessonId());
bLessonPerson.setLearnProgress(totalProgress); // 保存课程学习进度
bLessonPersonRepository.insertSelective(bLessonPerson); bLessonPersonRepository.insertSelective(bLessonPerson);
} }
// 查詢是否已經開始觀看此章節 // 查詢是否已經開始觀看此章節
List<BRStudentChapter> brStudentChapterList = bRStudentChapterRepository.queryByStuIdAndChapter(brStudentChapterDto.getChapterId(),brStudentChapterDto.getStudentId()); List<BRStudentChapter> brStudentChapterList = bRStudentChapterRepository.queryByStuIdAndChapter(brStudentChapterDto.getChapterId(),brStudentChapterDto.getStudentId());
DecimalFormat df=new DecimalFormat("0.00");//设置保留位数
// 沒有開始看-新增信息 // 沒有開始看-新增信息
if (null != brStudentChapterList && brStudentChapterList.size() >0){ if (null != brStudentChapterList && brStudentChapterList.size() >0){
BRStudentChapter brStudentChapter = brStudentChapterList.get(0); BRStudentChapter brStudentChapter = brStudentChapterList.get(0);
...@@ -98,22 +134,19 @@ public class BRStudentChapterServiceImpl implements BRStudentChapterService { ...@@ -98,22 +134,19 @@ public class BRStudentChapterServiceImpl implements BRStudentChapterService {
brStudentChapter.setCurrentLocation(brStudentChapterDto.getCurrent()); // 保存當前學習進度 brStudentChapter.setCurrentLocation(brStudentChapterDto.getCurrent()); // 保存當前學習進度
if (brStudentChapterDto.getCurrent() == brStudentChapterDto.getDuration()){ // 判断是否已经完成 if (brStudentChapterDto.getCurrent() == brStudentChapterDto.getDuration()){ // 判断是否已经完成
brStudentChapter.setIsComplete("1"); brStudentChapter.setIsComplete("1");
// brStudentChapter.setAutomatic("1");
brStudentChapter.setProgress(1); brStudentChapter.setProgress(1);
}else { }else {
brStudentChapter.setIsComplete("0"); brStudentChapter.setIsComplete("0");
// brStudentChapter.setAutomatic("0");
brStudentChapter.setProgress(new BigDecimal((float)brStudentChapterDto.getCurrent()/brStudentChapterDto.getDuration()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()); brStudentChapter.setProgress(new BigDecimal((float)brStudentChapterDto.getCurrent()/brStudentChapterDto.getDuration()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
} }
line = bRStudentChapterRepository.insertSelective(brStudentChapter); line = bRStudentChapterRepository.insertSelective(brStudentChapter);
} }
// 更新章节总进度 // 获取章节总进度 存库
BChapter bChapter = bChapterRepository.selectByPrimaryKey(brStudentChapterDto.getChapterId()); BChapter bChapter = bChapterRepository.selectByPrimaryKey(brStudentChapterDto.getChapterId());
if (null!=bChapter && StringUtils.isNotBlank(bChapter.getBusinessId())){ if (null!=bChapter && StringUtils.isNotBlank(bChapter.getBusinessId())){
bChapter.setCourseTime(brStudentChapterDto.getDuration().toString()); bChapter.setCourseTime(brStudentChapterDto.getDuration().toString());
bChapterRepository.updateByPrimaryKeySelective(bChapter); bChapterRepository.updateByPrimaryKeySelective(bChapter);
} }
//增加操作
return new PersistModel(line); return new PersistModel(line);
} }
......
...@@ -14,6 +14,8 @@ import org.rcisoft.common.util.feignDto.*; ...@@ -14,6 +14,8 @@ import org.rcisoft.common.util.feignDto.*;
import org.rcisoft.core.exception.ServiceException; import org.rcisoft.core.exception.ServiceException;
import org.rcisoft.core.result.ResultServiceEnums; import org.rcisoft.core.result.ResultServiceEnums;
import org.rcisoft.core.result.Ret; import org.rcisoft.core.result.Ret;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.rcisoft.core.util.UserUtil; import org.rcisoft.core.util.UserUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
...@@ -32,7 +34,6 @@ import java.util.*; ...@@ -32,7 +34,6 @@ import java.util.*;
@Component @Component
public class MTCotactApiRequestClient { public class MTCotactApiRequestClient {
public static String zxClientType = "app"; public static String zxClientType = "app";
public static Long zxAccountId = (long)1; public static Long zxAccountId = (long)1;
...@@ -540,8 +541,8 @@ public class MTCotactApiRequestClient { ...@@ -540,8 +541,8 @@ public class MTCotactApiRequestClient {
public void login() { public void login() {
Map<String, String> queries = new HashMap<>(1); Map<String, String> queries = new HashMap<>(1);
queries.put("username", "15202226641"); queries.put("username", "18622227181");
queries.put("password", "whh111222"); queries.put("password", "zx111222");
Map<String, String> headerParams = new HashMap<>(2); Map<String, String> headerParams = new HashMap<>(2);
headerParams.put("clientType", "app"); headerParams.put("clientType", "app");
String json = okHttpUtil.get(api + "app/login", queries, headerParams); String json = okHttpUtil.get(api + "app/login", queries, headerParams);
......
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