zoukankan      html  css  js  c++  java
  • 你们看不懂为什么写这个博客吧

    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()+"'; ";
    }

    return "update sight_check_user_info set gendar = 1 WHERE campaign_sequence='"+elements[0].trim()+"'; ";
    }

    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+"'; ";
    }

    return "update user_profile set gender = 1 WHERE user_id='"+userId+"'; ";
    }
    }
  • 相关阅读:
    Linux下环境搭建(一)——java、tomcat配置
    Fiddler使用过程中容易忽略的小技巧
    Jenkins环境搭建(6)-修改自动化测试报告的样式
    Jmeter——JSON Extractor后置处理器介绍2
    Jmeter——实现Basic Auth方式登录
    Jmeter——JSON Extractor后置处理器介绍1
    基础拾遗------泛型详解
    利用委托与Lambada创建和调用webapi接口
    quartz.net任务调度:源码及使用文档
    quartz.net插件类库封装(含源码)
  • 原文地址:https://www.cnblogs.com/xuyatao/p/7594608.html
Copyright © 2011-2022 走看看