码迷,mamicode.com
首页 > 其他好文 > 详细

你们看不懂为什么写这个博客吧

时间:2017-09-26 01:08:44      阅读:207      评论:0      收藏:0      [点我收藏+]

标签: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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!