main
			
			
		
		
							parent
							
								
									ee067a21c1
								
							
						
					
					
						commit
						c6d75c0e41
					
				@ -1,9 +1,16 @@
 | 
				
			||||
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.model.ChapterEntity;
 | 
				
			||||
 | 
				
			||||
public interface ChapterMapper extends SuperMapper<ChapterEntity>{
 | 
				
			||||
 | 
				
			||||
	List<ChapterEntity> queryList(Pagination questionPage);
 | 
				
			||||
 | 
				
			||||
	Integer queryCount(@Param(value="uid")String uid);
 | 
				
			||||
}
 | 
				
			||||
 | 
				
			||||
@ -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;
 | 
				
			||||
			}
 | 
				
			||||
		}
 | 
				
			||||
	}
 | 
				
			||||
 | 
				
			||||
}
 | 
				
			||||
@ -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();
 | 
				
			||||
    }
 | 
				
			||||
    
 | 
				
			||||
}
 | 
				
			||||
					Loading…
					
					
				
		Reference in new issue