美文网首页
openwiki: DumpExcelHandler

openwiki: DumpExcelHandler

作者: java修炼 | 来源:发表于2018-06-11 11:21 被阅读0次
    import cn.hutool.core.convert.Convert;
    import cn.hutool.core.io.FileUtil;
    import cn.hutool.poi.excel.ExcelWriter;
    import com.iqibai.gamedata.model.ResultUser;
    import lombok.extern.slf4j.Slf4j;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.data.mongodb.core.MongoTemplate;
    import org.springframework.data.mongodb.core.query.Criteria;
    import org.springframework.data.mongodb.core.query.Query;
    import org.springframework.stereotype.Component;
    
    import java.util.ArrayList;
    import java.util.List;
    
    @Component
    @Slf4j
    public class DumpExcelHandler {
    
        @Autowired
        private MongoTemplate mongoTemplate;
    
        public void processExcel(){
    
            String filePrefix = "/data/work/user/redis-user";
            for (int i = 1; i <= 4; i++) {
                String file = filePrefix + i +".txt";
                List<String> userIds = FileUtil.readLines(file,"utf-8");
                List<ResultUser> resultUsers = new ArrayList<>();
                for(String userId:userIds){
                    Integer userIdInt = Convert.toInt(userId,0);
                    if(userIdInt == 0){
                        continue;
                    }
                    Query findQuery = new Query(Criteria.where("userId").is(userIdInt));
                    ResultUser findUser = mongoTemplate.findOne(findQuery,ResultUser.class);
                    if(findUser == null){
                        continue;
                    }
                    resultUsers.add(findUser);
                }
                ExcelWriter excelWriter = new ExcelWriter(filePrefix+i+".xls");
                excelWriter.write(resultUsers);
                excelWriter.flush();
                log.info("end process {}",file);
    
            }
        }
    }
    

    相关文章

      网友评论

          本文标题:openwiki: DumpExcelHandler

          本文链接:https://www.haomeiwen.com/subject/lkgceftx.html