原文:https://www.2cto.com/kf/201612/581174.html

import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor; <em>/**
</em><em> * Created by admin
</em><em> */
</em>@RestController
@RequestMapping("/importData")
public class HpImportController extends BaseController{
private static final Logger <em>logger </em>= Logger.getLogger(HpImportController.class); @Reference(interfaceClass = SidCustManageService.class,version = Constants.<em>SERVICE_VERSION</em>)
private SidCustManageService sidCustManageService; @RequestMapping(value = "importDate")
@ResponseBody
public Response getOrdertDate(HttpServletRequest request,MultipartFile importData){ //创建Excel工作薄
try {
HSSFWorkbook hwb = new HSSFWorkbook(importData.getInputStream());
//得到第一个工作表
HSSFSheet sheet = hwb.getSheetAt(0);
HSSFRow row = null; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
List<sidcustpersoncontactinfo> list = new ArrayList<sidcustpersoncontactinfo>(); //遍历该表格中所有的工作表,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 = new SidCustPersonContactInfo();
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 = new ScheduledThreadPoolExecutor(RunSize);
CountDownLatch countDownLatch = new CountDownLatch(RunSize);
List<sidcustpersoncontactinfo> 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 = new ExecupteHp(newList);
executor.execute(hpRunnable);
} countDownLatch.await();
executor.shutdown(); }catch (Exception e){
<em>logger</em>.info("导入数据开始.");
e.printStackTrace();
}
return Response.ok(GlobalEnum.<em>GLOBAL_ENUM_SUCCESS_CODE</em>.getValue() , SidCustEnum.<em>SID_CRST_ERROR_SID_SUCCESS_07</em>.getValue()); } class ExecupteHp implements Runnable{
private List <sidcustpersoncontactinfo> list;
public ExecupteHp (List <sidcustpersoncontactinfo> list){
this.list = list ;
} @Override
public void run() {
if(null!=list){
for (SidCustPersonContactInfo scpc : list){
System.<em>out</em>.print("更新会员联系方式" +scpc.getFirstName() + "---"+scpc.getCustCode() );
SidCustContactInfo custContactInfo = new SidCustContactInfo();
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); }
} }
} }

java多线程处理导入数据拆分List集合 同步处理插入数据的更多相关文章

  1. python,java操作mysql数据库,数据引擎设置为myisam时能够插入数据,转为innodb时无法插入数据

    今天想给数据库换一个数据引擎,mysiam转为 innodb 结果 python 插入数据时失败,但是自增id值是存在的, 换回mysiam后,又可以插入了~~ 想换php插入试试,结果php数据引擎 ...

  2. 往hbase插入数据,你会选择哪种?

    好久,好久没有写个博客了,自从上次封闭开始,到“自闭”,有了一段时间了,哈哈^_^ . 多亏了云桌面的歇菜, 一下午啥都干不了, 突然想到,好久没有写点啥了,就写的,让时间流走有点痕迹吧 _(:з」∠ ...

  3. AGS中通过FeatureServer插入数据失败、插入数据在WMTS请求中无法显示以及version概念的讨论

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/. 1.背景 在多个项目中,当我方接口给其他部门人员使用时出现了插入数据失 ...

  4. OracleBulkCopy批量插入数据

    1.OracleBulk程序集引用using ODAC = Oracle.DataAccess.Client 2.有时候不做字段映射,会使导入的数据出错 上代码 /// <summary> ...

  5. 7 Hbase put方式插入数据

    package com.hikvision.hbase.vertify.test; import org.apache.hadoop.conf.Configuration; import org.ap ...

  6. myBatis获取批量插入数据的主键id

    在myBatis中获取刚刚插入的数据的主键id是比较容易的 , 一般来说下面的一句话就可以搞定了 , 网上也有很多相关资料去查. @Options(useGeneratedKeys = true, k ...

  7. [Hive_4] Hive 插入数据

    0. 说明 Hive 插入数据的方法 && Hive 插入数据的顺序 && 插入复杂数据的方法 && load 命令详解 1. Hive 插入数据的方法 ...

  8. 插入数据:insert,replace

    *insert高级用法* 1.语法:insert into tbname(字段列表) values 值列表; 1.1可以不将所有的字段都插入数据.如果说需要完成部分字段的插入,需要必须存在字段列表. ...

  9. MySql数据库-查询、插入数据时转义函数的使用

    最近在看一部php的基础视频教程,在做案例的时,当通过用户名查询用户信息的时候,先使用了转义函数对客户提交的内容进行过滤之后再交给sql语句进行后续的操作.虽然能看到转义函数本身的作用,但是仍然有一些 ...

随机推荐

  1. 2017多校第8场 HDU 6138 Fleet of the Eternal Throne 思维,暴力

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6138 题意:给了初始区间[-1,1],然后有一些操作,可以r加上一个数,l减掉一个数,或者同时操作,问 ...

  2. [转载] 更改pip源至国内镜像,显著提升下载速度

    原文地址: https://blog.csdn.net/lambert310/article/details/52412059 经常在使用python的时候需要安装各种模块,而pip是很强大的模块安装 ...

  3. 【转】kubernetes 中 deployment 支持哪些键值

    这个比较全,可以参考 ================= https://www.addops.cn/post/kubernetes-deployment-fileds.html ========== ...

  4. kubernetes如何要使用用户名和密码登陆harbor以拉取docker镜像,应该如何操作?

    还好,网上有相应的CASE处理. http://www.jianshu.com/p/ffbfb44dc496 =========================== 先生成名为为regsecret的S ...

  5. Linux(CentOS)下的JDK的安装和环境配置

    下载对应版本JDK,如jdk-6u45-linux-i586-rpm.bin添加执行权限:#chmod +x jdk-6u45-linux-i586-rpm.bin安装:#./jdk-6u45-lin ...

  6. Nodejs项目重复文件扫描

    项目地址:https://github.com/danielstjules/jsinspect 1.安装jsinspect npm install -g jsinspect 2.进入至项目目录 d c ...

  7. 用Fiddler进行弱网测试

    1.作为一个好的程序猿,不但要写一手高质量的代码,而且要学会用高质量的测试工具测试自己的代码效果,接下来给大家推荐一下:用Fiddler进行弱网环境下的测试,请不要忽略这一点,因为用户在网速慢的情况下 ...

  8. CodeForces 738E Subordinates

    排序,构造. 相当于告诉我们一棵树$n$个节点,每个节点在哪一层,至少需要移动多少个节点,才能让这些节点变成一棵树. 按照层次排个序移动一下就可以了,优先选择那些不是$s$但是层次是$0$的节点,如果 ...

  9. devops basic

  10. 洛谷——P1609 最小回文数

    题目描述 回文数是从左向右读和从右向左读结果一样的数字串. 例如:121.44 和3是回文数,175和36不是. 对于一个给定的N,请你寻找一个回文数P,满足P>N. 满足这样条件的回文数很多, ...