java多线程处理数据list_java多线程处理导入数据拆分List集合 同步处理插入数据...

importorg.apache.log4j.Logger;importorg.apache.poi.hssf.usermodel.HSSFRow;importorg.apache.poi.hssf.usermodel.HSSFSheet;importorg.apache.poi.hssf.usermodel.HSSFWorkbook;importorg.springframework.web.bind.annotation.RequestMapping;importorg.springframework.web.bind.annotation.ResponseBody;importorg.springframework.web.bind.annotation.RestController;importorg.springframework.web.multipart.MultipartFile;importjavax.servlet.http.HttpServletRequest;importjava.text.SimpleDateFormat;importjava.util.ArrayList;importjava.util.HashMap;importjava.util.List;importjava.util.Map;importjava.util.concurrent.CountDownLatch;importjava.util.concurrent.ScheduledThreadPoolExecutor;importjava.util.concurrent.ThreadPoolExecutor;/** * Created by admin

*/

@RestController

@RequestMapping("/importData")public class HpImportController extendsBaseController{private static final Logger logger = Logger.getLogger(HpImportController.class);

@Reference(interfaceClass= SidCustManageService.class,version = Constants.SERVICE_VERSION)privateSidCustManageService sidCustManageService;

@RequestMapping(value= "importDate")

@ResponseBodypublicResponse getOrdertDate(HttpServletRequest request,MultipartFile importData){//创建Excel工作薄

try{

HSSFWorkbook hwb= newHSSFWorkbook(importData.getInputStream());//得到第一个工作表

HSSFSheet sheet = hwb.getSheetAt(0);

HSSFRow row= null;

SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");

List list = new ArrayList();//遍历该表格中所有的工作表,i表示工作表的数量 getNumberOfSheets表示工作表的总数

for(int i = 0; i < hwb.getNumberOfSheets(); i++) {

sheet=hwb.getSheetAt(i);//遍历该行所有的行,j表示行数 getPhysicalNumberOfRows行的总数

for(int j = 1; j < sheet.getPhysicalNumberOfRows(); j++) {

row=sheet.getRow(j);

String loginName= ExcelUtils.getStringValue(row, 0);

String agentName= ExcelUtils.getStringValue(row, 1);

String pwd= "123123";

String amount= ExcelUtils.getStringValue(row, 3);

String cust_lev= ExcelUtils.getStringValue(row,4);

String name= ExcelUtils.getStringValue(row, 5);

String tel= ExcelUtils.getStringValue(row, 6);

String qq= ExcelUtils.getStringValue(row, 7);

String birday= ExcelUtils.getStringValue(row, 8);

String email= ExcelUtils.getStringValue(row, 9);

String createTp= ExcelUtils.getStringValue(row, 10);

String bankAccountName= ExcelUtils.getStringValue(row, 11);

String bankNo= ExcelUtils.getStringValue(row, 12);

String bankName= ExcelUtils.getStringValue(row, 13);

String bankType= ExcelUtils.getStringValue(row, 14);

SidCustPersonContactInfo custCpci= newSidCustPersonContactInfo();

custCpci.setCustCode(loginName);

custCpci.setAmount(Double.valueOf(amount));

custCpci.setPasswd(pwd);

custCpci.setBankName(bankName);

custCpci.setBankNo(bankNo);

custCpci.setBankAccountName(bankAccountName);if(!birday.equals("")){

custCpci.setBirthDate(sdf.parse(birday));

}

custCpci.setFirstName(name);

custCpci.setNickName(name);

custCpci.setQq(qq);

custCpci.setBankType(bankType);

custCpci.setEmailAddress(email);

custCpci.setMobileNumber(tel);

custCpci.setHallId(Long.valueOf(5));

list.add(custCpci);

}

}int count = 50;int listSize =list.size();int RunSize = (listSize / count)+1;

ThreadPoolExecutor executor= newScheduledThreadPoolExecutor(RunSize);

CountDownLatch countDownLatch= newCountDownLatch(RunSize);

List newList = null;for (int i = 0; i < RunSize; i++) {if((i+1)==RunSize){int startIndex = (i*count);;int endIndex =list.size();

newList=list.subList(startIndex,endIndex);

}else{int startIndex = i*count;;int endIndex = (i+1)*count;

newList=list.subList(startIndex,endIndex);

}

ExecupteHp hpRunnable= newExecupteHp(newList);

executor.execute(hpRunnable);

}

countDownLatch.await();

executor.shutdown();

}catch(Exception e){logger.info("导入数据开始.");

e.printStackTrace();

}return Response.ok(GlobalEnum.GLOBAL_ENUM_SUCCESS_CODE.getValue() , SidCustEnum.SID_CRST_ERROR_SID_SUCCESS_07.getValue());

}class ExecupteHp implementsRunnable{private List list;public ExecupteHp (List list){this.list =list ;

}

@Overridepublic voidrun() {if(null!=list){for(SidCustPersonContactInfo scpc : list){

System.out.print("更新会员联系方式" +scpc.getFirstName() + "---"+scpc.getCustCode() );

SidCustContactInfo custContactInfo= newSidCustContactInfo();

custContactInfo.setCustCode(scpc.getCustCode());

custContactInfo.setEmailAddress(scpc.getEmailAddress());

custContactInfo.setMobileNumber(scpc.getMobileNumber());

custContactInfo.setFirstName(scpc.getFirstName());

custContactInfo.setNicName(scpc.getNickName());

custContactInfo.setQq(scpc.getQq());

custContactInfoService.updateByContactByCustCode(custContactInfo);

}

}

}

}

}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值