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);
}
}
}
}
}