main
tamguo 7 years ago
parent a563265f7c
commit c75416a2eb

@ -0,0 +1,27 @@
package com.tamguo.modules.tiku.model.queue;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import com.tamguo.modules.tiku.model.ChapterEntity;
public class LearnChapterQueue {
// 章节
private static BlockingQueue<ChapterEntity> chapterQueue = new ArrayBlockingQueue<ChapterEntity>(5);
public static void add(ChapterEntity chapter) throws InterruptedException {
if(chapterQueue.size() == 5) {
chapterQueue.take();
}
chapterQueue.put(chapter);
}
public static BlockingQueue<ChapterEntity> getChapterQueue() {
return chapterQueue;
}
public static void setChapterQueue(BlockingQueue<ChapterEntity> chapterQueue) {
LearnChapterQueue.chapterQueue = chapterQueue;
}
}

@ -1,5 +1,7 @@
package com.tamguo.web.tiku;
import java.util.concurrent.BlockingQueue;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -8,6 +10,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import com.tamguo.modules.tiku.model.ChapterEntity;
import com.tamguo.modules.tiku.model.queue.LearnChapterQueue;
import com.tamguo.utils.BrowserUtils;
@Controller
@ -19,6 +24,8 @@ public class IndexController {
public ModelAndView indexAction(ModelAndView model , HttpServletRequest request) {
// request url
logger.info("request url :{}" , request.getRequestURI());
BlockingQueue<ChapterEntity> chapterQueue = LearnChapterQueue.getChapterQueue();
model.addObject("chapterList", chapterQueue.toArray());
if(BrowserUtils.isMobile(request.getHeader("user-agent"))) {
model.setViewName("mobile/index");
}else {

@ -1,6 +1,9 @@
package com.tamguo.web.tiku;
import java.util.Arrays;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
@ -21,6 +24,7 @@ import com.tamguo.modules.tiku.model.CourseEntity;
import com.tamguo.modules.tiku.model.QuestionEntity;
import com.tamguo.modules.tiku.model.SubjectEntity;
import com.tamguo.modules.tiku.model.enums.QuestionTypeEnum;
import com.tamguo.modules.tiku.model.queue.LearnChapterQueue;
import com.tamguo.modules.tiku.service.IChapterService;
import com.tamguo.modules.tiku.service.ICourseService;
import com.tamguo.modules.tiku.service.IQuestionAnswerService;
@ -44,10 +48,13 @@ public class QuestionContrller {
@Autowired
private IQuestionAnswerService iQuestionAnswerService;
// 章节
BlockingQueue<ChapterEntity> chapterQueue = new LinkedBlockingQueue<ChapterEntity>(10);
@SuppressWarnings("unchecked")
@RequestMapping(value = {"questionlist/{chapterId}-{current}-{size}.html"}, method = RequestMethod.GET)
public ModelAndView questionList(@PathVariable String chapterId , @PathVariable Integer current ,
@PathVariable Integer size , ModelAndView model , HttpServletRequest request){
@PathVariable Integer size , ModelAndView model , HttpServletRequest request) throws InterruptedException{
// request url
logger.info("request url :{} " , request.getRequestURI());
@ -74,6 +81,8 @@ public class QuestionContrller {
model.addObject("subjectId", course.getSubjectId());
model.addObject("courseId", course.getId());
LearnChapterQueue.add(chapter);
if(BrowserUtils.isMobile(request.getHeader("user-agent"))) {
model.setViewName("mobile/questionList");
}else {

@ -89,12 +89,12 @@
</h3>
<div class="feed-list-content">
<ul class="feed-list" style="top: 0px;">
<li class="feed-list-item list-border">
<li class="feed-list-item list-border" th:each="c,cStat:${chapterList}">
<img th:src="${domainName + 'images/avatar.png'}" class="item-img">
<div class="feed-list-detail">
<p class="detail-item"><span class="item-name">Tom</span>已学完了70个知识点</p>
<p class="detail-item">今天学了
<a class="item-link" th:href="${domainName}" target="_blank">光的干涉</a><span class="course-num">16</span>个知识点</p>
<a class="item-link" th:href="${domainName + 'questionlist/' + c.id + '-1-5.html'}" target="_blank" th:text="${c.name}">光的干涉</a><span class="course-num">16</span>个知识点</p>
</div>
</li>
</ul>

Loading…
Cancel
Save