你们看不懂为什么写这个博客吧
Posted xuyatao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了你们看不懂为什么写这个博客吧相关的知识,希望对你有一定的参考价值。
package com.wedo.bvision.schedule;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.LineIterator;
import org.apache.commons.lang.StringUtils;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Created by wedo on 25/9/2017.
*/
public class BugGender {
private final static Logger logger = LoggerFactory.getLogger(BugGender.class);
@Test
public void test(){
LineIterator it;
String filePath = "C:\\Users\\usr\\Desktop\\杨嘴小学.csv";
File dirFile = new File(filePath);
String fileUpdate = "C:\\Users\\usr\\Desktop\\genderUpate.txt";
File updateFile = new File(fileUpdate);
if (!updateFile.exists()){
try {
updateFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
logger.info("Begin import file:{}", filePath);
try {
it = FileUtils.lineIterator(dirFile, "UTF-8");
PrintWriter pw = new PrintWriter(new FileWriter(fileUpdate,true),true);
if (it.hasNext()) {
String firstLine = it.nextLine();
if (!firstLine.startsWith("name")) {
logger.error("Invalid line, please follow template, add first line");
}
}
while (it.hasNext()) {
try {
String line = it.nextLine();
String checkUserInfoUpadate = CheckUserInfohandleLine(line);
String userProfileUpdate = UserProfilehandleLine(line);
pw.write(checkUserInfoUpadate);
pw.write(userProfileUpdate);
}catch (Exception e){
e.printStackTrace();
}
}
pw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private String CheckUserInfohandleLine(String line) {
String[] elements = line.split(",");
//性别
if (StringUtils.isNotEmpty(elements[3]) && elements[3].indexOf("女")>-1) {
return "update sight_check_user_info set gendar = 2 WHERE campaign_sequence=‘"+elements[0].trim()+"‘;\r\n";
}
return "update sight_check_user_info set gendar = 1 WHERE campaign_sequence=‘"+elements[0].trim()+"‘;\r\n";
}
private String UserProfilehandleLine(String line) {
String[] elements = line.split(",");
String userId = elements[1].trim();
//性别
if (StringUtils.isNotEmpty(elements[3]) && elements[3].indexOf("女")>-1) {
return "update user_profile set gender = 2 WHERE user_id=‘"+userId+"‘;\r\n";
}
return "update user_profile set gender = 1 WHERE user_id=‘"+userId+"‘;\r\n";
}
}
以上是关于你们看不懂为什么写这个博客吧的主要内容,如果未能解决你的问题,请参考以下文章