main
tamguo 7 years ago
parent ee067a21c1
commit c6d75c0e41

@ -1,9 +1,16 @@
package com.tamguo.dao; package com.tamguo.dao;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.baomidou.mybatisplus.plugins.pagination.Pagination;
import com.tamguo.config.dao.SuperMapper; import com.tamguo.config.dao.SuperMapper;
import com.tamguo.model.ChapterEntity; import com.tamguo.model.ChapterEntity;
public interface ChapterMapper extends SuperMapper<ChapterEntity>{ public interface ChapterMapper extends SuperMapper<ChapterEntity>{
List<ChapterEntity> queryList(Pagination questionPage);
Integer queryCount(@Param(value="uid")String uid);
} }

@ -3,7 +3,7 @@ package com.tamguo.service;
public interface IChapterService { public interface IChapterService {
/** /**
* *
*/ */
void crawlerChapter(); void modifyQuestionNum();
} }

@ -0,0 +1,40 @@
package com.tamguo.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.plugins.Page;
import com.tamguo.dao.ChapterMapper;
import com.tamguo.model.ChapterEntity;
import com.tamguo.service.IChapterService;
@Service
public class ChapterService implements IChapterService{
@Autowired
ChapterMapper chapterMapper;
@Override
public void modifyQuestionNum() {
int page = 1;
int pageSize = 1000;
while(true) {
Page<ChapterEntity> chapterPage = new Page<ChapterEntity>(page , pageSize);
List<ChapterEntity> chapterList = chapterMapper.queryList(chapterPage);
for(int i=0 ;i<chapterList.size() ; i++) {
// 处理数据
ChapterEntity chapter = chapterList.get(i);
Integer count = chapterMapper.queryCount(chapter.getUid());
chapter.setQuestionNum(count);
chapterMapper.updateById(chapter);
}
page++;
if(chapterList.size() < 1000) {
break;
}
}
}
}

@ -2,5 +2,11 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tamguo.dao.ChapterMapper"> <mapper namespace="com.tamguo.dao.ChapterMapper">
<select id="queryList" resultType="ChapterEntity">
select * from tiku_chapter order by uid desc
</select>
<select id="queryCount" resultType="java.lang.Integer">
select count(1) from tiku_question where chapter_id = #{uid}
</select>
</mapper> </mapper>

@ -0,0 +1,29 @@
package com.tamguo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import com.tamguo.service.IChapterService;
/**
* Num -
*
* @author tamguo
*
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class ModifyChpaterQuestionNum {
@Autowired
IChapterService iChapterService;
@Test
public void crawlerSubject() throws Exception {
iChapterService.modifyQuestionNum();
}
}

@ -17,7 +17,7 @@ $(function(){
var courseId = $(this).attr("courseid"); var courseId = $(this).attr("courseid");
$.ajax({ $.ajax({
type : "get", type : "get",
url : mainHttp + "course/findChapter.html?courseId=" +courseId+".html", url : mainHttp + "course/findChapter.html?courseId=" +courseId,
async : true, async : true,
dataType : "json", dataType : "json",
success : function(data) {// 返回数据根据结果进行相应的处理,无论请求成功还是失败,都会走这个方法的 success : function(data) {// 返回数据根据结果进行相应的处理,无论请求成功还是失败,都会走这个方法的

Loading…
Cancel
Save