标签:int etl name where factor test lease sts iter
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";
}
}
标签:int etl name where factor test lease sts iter
原文地址:http://www.cnblogs.com/xuyatao/p/7594608.html