/**
* 解析Excel里面的数据
*
* @param wb
* @return
*/
private String readExcelValue(Workbook wb, File tempFile) throws ParseException {
//错误信息接收器
String errorMsg = "";
//得到第一个shell
Sheet sheet = wb.getSheetAt(0);
//得到Excel的行数
int totalRows = sheet.getPhysicalNumberOfRows();
//总列数
int totalCells = 0;
//得到Excel的列数(前提是有行数),从第二行算起
if (totalRows >= 2 && sheet.getRow(1) != null) {
totalCells = sheet.getRow(0).getPhysicalNumberOfCells();
}
List<CustomerDO> userKnowledgeBaseList = new ArrayList<>();
CustomerDO tempUserKB = null;
AddressDO addressDO = null;
String br = "<br/>";
//循环Excel行数,从第二行开始。标题不入库
for (int r = 1; r < totalRows; r++) {
String rowMessage = "";
Row row = sheet.getRow(r);
if (row == null) {
errorMsg += br + "第" + (r + 1) + "行数据有问题,请仔细检查!";
continue;
}
tempUserKB = new CustomerDO();
//地址id
String id = "";
//国家
String countryid = "";
//省份
String provinceid = "";
//城市
String cityid = "";
//地址
String addressid = "";
String countryName;
String provinceName;
String cityName;
String addressName;
//乡镇
String township = "";
//村组
String village = "";
//详细地址
String address = "";
//客户类别
String hzkhtypeid = "";
//具体类型
String jtlxid = "";
String hzjtlx = "";
//客户名称
String name = "";
//一级名称
String first_name = "";
//二级名称
String second_name = "";
//三级名称
String third_name = "";
//网址
String website = "";
//公众号名称
String official_account_name = "";
//小程序
String applet_name = "";
//联系人
String contacts = "";
//职位
String position = "";
//性别
String sex = "";
//出生日期
String birthday = "";
//籍贯
String natives = "";
//民族
String nation = "";
//学历
String education = "";
//职称
String title = "";
//婚姻状况
String marital = "";
//兴趣爱好
String hobby = "";
//潜在商机
String potential = "";
//信息来源
String source = "";
// 社会资源
String sources = "";
//qq
String qq = "";
//微信
String wechat = "";
//手机
String phone = "";
//电话
String telphone = "";
//邮箱
String email = "";
//传真
String fax = "";
//合作类型id
String khhztypeid = "";
//合作具体类型id
String hzjtlxid = "";
//具体项目名称
String hzjtlxnameid = "";
//
String remarks = "";
String khhztypeName = "";
String hzjtlxName = "";
//
String hzjtlxnameName = "";
//
String hzkhtypeName = "";
// 、、初次见面
String first_time = "";
// 是否合作过
String cooperation = "";
//最后一次见面
String last_time = "";
// 合作意向
String intention = "";
//合作内容
String content = "";
//合作金额
String money = "";
//合作日期
String date = "";
//创建人
String create_by = "";
//创建时间
String create_date = "";
//标记
String enabled_flag = "";
//确认状态(0,未确认,1.确认)
String confirm_status="";
for (int c = 0; c < totalCells; c++) {
Cell cell = row.getCell(c);
//循环Excel的行
if (null != cell) {
//cell.setCellType(CellType.STRING);
// if (c == 0) {
// id = cell.getStringCellValue();
// if (StringUtils.isEmpty(id)) {
// rowMessage += "班级id不能为空";
// } else if (id.length() > 100) {
// rowMessage += "班级id的长度不能超过10";
// }
// tempUserKB.setId(Integer.valueOf(id));
//
// } else
if (c == 0) {
countryid = cell.getStringCellValue();
if (StringUtils.isEmpty(countryid)) {
rowMessage += "国家ID不能为空";
} else if (countryid.length() > 11) {
rowMessage += "国家ID长度不能超过11";
}
// 第一种方法取值(每次都要查询数据库,效率不高)
// Map<String, Object> map = new HashMap<>();
// map.put("name", countryid);
//
// List<AddressDO> list = commonService.listAddress(map);
// if (list.size() > 0) {
// for (AddressDO addDO : list) {
// countryid = Integer.toString(addDO.getId());
// }
// }
//
// tempUserKB.setCountryid(Integer.valueOf(countryid));
String s = FieldDictUtil.get("khsjgl", "kh_customer", "countryid", countryid);
System.out.println(s);
// 第二种方法从缓存获取值 appid 数据库索引值 kh_customer需要使用的数据库 countryid使用的数据库的字段名 要从缓存获取的id值
tempUserKB.setCountryid(Integer.valueOf(s));
} else if (c == 1) {
provinceid = cell.getStringCellValue();
if (StringUtils.isEmpty(provinceid)) {
rowMessage += "省份ID不能为空";
} else if (provinceid.length() > 11) {
rowMessage += "省份ID长度不能超过11";
}
// Map<String, Object> map = new HashMap<>();
// map.put("name", provinceid);
//
// List<AddressDO> list = commonService.listAddress(map);
// if (list.size() > 0) {
// for (AddressDO addDO : list) {
// provinceid = Integer.toString(addDO.getId());
// }
// }
// tempUserKB.setProvinceid(Integer.valueOf(provinceid));
tempUserKB.setProvinceid(Integer.valueOf(FieldDictUtil.get("khsjgl", "kh_customer", "provinceid", provinceid)));
} else if (c == 2) {
cityid = cell.getStringCellValue();
if (StringUtils.isEmpty(cityid)) {
rowMessage += "市县ID不能为空";
} else if (cityid.length() > 11) {
rowMessage += "市县ID不能超过11";
}
// Map<String, Object> map = new HashMap<>();
// map.put("name", cityid);
//
// List<AddressDO> list = commonService.listAddress(map);
// if (list.size() > 0) {
// for (AddressDO addDO : list) {
// cityid = Integer.toString(addDO.getId());
// }
// }
// tempUserKB.setCityid(Integer.valueOf(cityid));
tempUserKB.setCityid(Integer.valueOf(FieldDictUtil.get("khsjgl", "kh_customer", "cityid", cityid)));
} else if (c == 3) {
addressid = cell.getStringCellValue();
if (StringUtils.isEmpty(addressid)) {
rowMessage += "市县ID不能为空;";
} else if (addressid.length() > 11) {
rowMessage += "市县ID长度不能超过11;";
}
// tempUserKB.setAddressid(Integer.valueOf(addressid));
tempUserKB.setAddress(FieldDictUtil.get("khsjgl", "kh_customer", "addressid", addressid));
}
// else if (c == 4) {
// township = cell.getStringCellValue();
// if (StringUtils.isEmpty(township)) {
// rowMessage += "乡镇不能为空;";
// } else if (township.length() > 100) {
// rowMessage += "乡镇长度长度不能超过100";
// }
//
// Map<String, Object> map = new HashMap<>();
// map.put("name", township);
//
// List<AddressDO> list = commonService.listAddress(map);
// if (list.size() > 0) {
// for (AddressDO addDO : list) {
// township = Integer.toString(addDO.getId());
// }
// }
//
// tempUserKB.setTownship(township);
//
// }
// else if (c == 5) {
// hzjtlx = cell.getStringCellValue();
// if (StringUtils.isEmpty(hzjtlx)) {
// rowMessage += "类别不能为空;";
// } else if (hzjtlx.length() > 240) {
// rowMessage += "类别有误;";
// }
// List<String> list = new ArrayList<>();
//
// String[] split = hzjtlx.split(",");
// for (int i = 0; i <split.length; i++) {
// list.add(split[i]);
// }
//
传值
// Map<String, Object> map = new HashMap<>();
// map.put("list", list);
//
// List<HzjtlxDO> listDo = hzjtlxService.selectId(map);
//
// if (listDo.size() > 0) {
// for (HzjtlxDO hzjtlxDO2 : listDo) {
// hzjtlxid = String.valueOf(hzjtlxDO2.getId())+","+hzjtlxid;
// }
// }
//
// tempUserKB.setHzjtlxid(hzjtlxid);
// }
//
// }
else if (c == 4) {
township = cell.getStringCellValue();
if (StringUtils.isEmpty(township)) {
rowMessage += "具体地址不能为空;";
} else if (township.length() > 100) {
rowMessage += "具体地址长度不能超过100";
}
// tempUserKB.setTownship(township);
tempUserKB.setTownship(FieldDictUtil.get("khsjgl", "kh_customer", "township", township));
} else if (c == 5) {
village = cell.getStringCellValue();
if (StringUtils.isEmpty(village)) {
rowMessage += "village不能为空;";
} else if (village.length() > 100) {
rowMessage += "village长度不能超过100;";
}
// tempUserKB.setVillage(village);
tempUserKB.setVillage(FieldDictUtil.get("khsjgl", "kh_customer", "village", village));
} else if (c == 6) {
address = cell.getStringCellValue();
if (StringUtils.isEmpty(address)) {
rowMessage += "详细地址不能为空;";
} else if (address.length() > 200) {
rowMessage += "详细地址长度不能超过200;";
}
// tempUserKB.setAddress(address);
tempUserKB.setAddress(FieldDictUtil.get("khsjgl", "kh_customer", "address", address));
} else if (c == 7) {
hzkhtypeid = cell.getStringCellValue();
if (StringUtils.isEmpty(hzkhtypeid)) {
rowMessage += "客户类别不能为空;";
} else if (hzkhtypeid.length() > 11) {
rowMessage += "客户类别长度不能超过11;";
}
// tempUserKB.setHzkhtypeid(Integer.valueOf(hzkhtypeid));
tempUserKB.setHzkhtypeid(Integer.valueOf(FieldDictUtil.get("khsjgl", "kh_customer", "hzkhtypeid", hzkhtypeid)));
} else if (c == 8) {
jtlxid = cell.getStringCellValue();
if (StringUtils.isEmpty(jtlxid)) {
rowMessage += "具体类型不能为空;";
} else if (jtlxid.length() > 11) {
rowMessage += "具体类型长度不能超过11";
}
// tempUserKB.setJtlxid(Integer.valueOf(jtlxid));
tempUserKB.setJtlxid(Integer.valueOf(FieldDictUtil.get("khsjgl", "kh_customer", "jtlxid", jtlxid)));
} else if (c == 9) {
name = cell.getStringCellValue();
if (StringUtils.isEmpty(name)) {
rowMessage += "客户名称不能为空;";
} else if (name.length() > 200) {
rowMessage += "客户名称长度不能超过200";
}
// tempUserKB.setName(name);
tempUserKB.setName(FieldDictUtil.get("khsjgl", "kh_customer", "name", name));
} else if (c == 10) {
first_name = cell.getStringCellValue();
if (StringUtils.isEmpty(first_name)) {
rowMessage += "一级名称不能为空;";
} else if (first_name.length() > 200) {
rowMessage += "一级名称长度不能超过200;";
}
// tempUserKB.setFirstName(first_name);
tempUserKB.setFirstName(FieldDictUtil.get("khsjgl", "kh_customer", "first_name", first_name));
} else if (c == 11) {
second_name = cell.getStringCellValue();
if (StringUtils.isEmpty(second_name)) {
rowMessage += "二级名称不能为空;";
} else if (second_name.length() > 200) {
rowMessage += "二级名称长度不能超过200;";
}
// tempUserKB.setSecondName(second_name);
tempUserKB.setSecondName(FieldDictUtil.get("khsjgl", "kh_customer", "second_name", second_name));
} else if (c == 12) {
third_name = cell.getStringCellValue();
if (StringUtils.isEmpty(third_name)) {
rowMessage += "三级名称不能为空;";
} else if (third_name.length() > 200) {
rowMessage += "三级名称长度不能超过200;";
}
// tempUserKB.setThirdName(third_name);
tempUserKB.setThirdName(FieldDictUtil.get("khsjgl", "kh_customer", "third_name", third_name));
} else if (c == 13) {
website = cell.getStringCellValue();
if (StringUtils.isEmpty(website)) {
rowMessage += "网址不能为空;";
} else if (website.length() > 100) {
rowMessage += "网址长度不能超过100;";
}
// tempUserKB.setWebsite(website);
tempUserKB.setWebsite(FieldDictUtil.get("khsjgl", "kh_customer", "website", website));
} else if (c == 14) {
official_account_name = cell.getStringCellValue();
if (StringUtils.isEmpty(official_account_name)) {
rowMessage += "公众号名称不能为空;";
} else if (official_account_name.length() > 200) {
rowMessage += "公众号名称长度不能超过200;";
}
// tempUserKB.setOfficialAccountName(official_account_name);
tempUserKB.setOfficialAccountName(FieldDictUtil.get("khsjgl", "kh_customer", "official_account_name", official_account_name));
} else if (c == 15) {
applet_name = cell.getStringCellValue();
if (StringUtils.isEmpty(applet_name)) {
rowMessage += "小程序不能为空;";
} else if (applet_name.length() > 200) {
rowMessage += "小程序长度不能超过200;";
}
// tempUserKB.setAppletName(applet_name);
tempUserKB.setAppletName(FieldDictUtil.get("khsjgl", "kh_customer", "applet_name", applet_name));
} else if (c == 16) {
contacts = cell.getStringCellValue();
if (StringUtils.isEmpty(contacts)) {
rowMessage += "联系人不能为空;";
} else if (contacts.length() > 200) {
rowMessage += "联系人长度不能超过200;";
}
// tempUserKB.setContacts(contacts);
tempUserKB.setContacts(FieldDictUtil.get("khsjgl", "kh_customer", "contacts", contacts));
} else if (c == 17) {
position = cell.getStringCellValue();
if (StringUtils.isEmpty(position)) {
rowMessage += "职位不能为空;";
} else if (position.length() > 100) {
rowMessage += "职位长度不能超过100;";
}
// tempUserKB.setPosition(position);
tempUserKB.setPosition(FieldDictUtil.get("khsjgl", "kh_customer", "position", position));
} else if (c == 18) {
sex = cell.getStringCellValue();
if (StringUtils.isEmpty(sex)) {
rowMessage += "性别不能为空;";
} else if (sex.length() > 2) {
rowMessage += "性别长度不能超过2;";
}
// String s = FieldDictUtil.get("khsjgl", "sys_worker", "gender", sex);
// System.out.println(s);
tempUserKB.setSex(FieldDictUtil.get("khsjgl", "sys_worker", "sex", sex));
} else if (c == 19) {
birthday = cell.getStringCellValue();
if (StringUtils.isEmpty(birthday)) {
rowMessage += "生日不能为空;";
} else if (birthday.length() > 40) {
rowMessage += "生日长度不能超过40;";
}
// tempUserKB.setBirthday(new SimpleDateFormat().parse(birthday));
tempUserKB.setBirthday(new SimpleDateFormat().parse(FieldDictUtil.get("khsjgl", "kh_customer", "birthday", birthday)));
} else if (c == 20) {
natives = cell.getStringCellValue();
if (StringUtils.isEmpty(natives)) {
rowMessage += "籍贯不能为空;";
} else if (natives.length() > 240) {
rowMessage += "籍贯长度不能超过24;";
}
// tempUserKB.setNatives(natives);
tempUserKB.setNatives(FieldDictUtil.get("khsjgl", "kh_customer", "natives", natives));
} else if (c == 21) {
nation = cell.getStringCellValue();
if (StringUtils.isEmpty(nation)) {
rowMessage += "民族不能为空;";
} else if (nation.length() > 240) {
rowMessage += "民族长度不能超过24;";
}
// tempUserKB.setNation(nation);
tempUserKB.setNation(FieldDictUtil.get("khsjgl", "kh_customer", "nation", nation));
} else if (c == 22) {
education = cell.getStringCellValue();
if (StringUtils.isEmpty(education)) {
rowMessage += "学历不能为空;";
} else if (education.length() > 240) {
rowMessage += "学历长度不能超过24;";
}
// tempUserKB.setEducation(education);
tempUserKB.setEducation(FieldDictUtil.get("khsjgl", "kh_customer", "education", education));
} else if (c == 23) {
title = cell.getStringCellValue();
if (StringUtils.isEmpty(title)) {
rowMessage += "职称不能为空;";
} else if (title.length() > 240) {
rowMessage += "职称长度不能超过24;";
}
// tempUserKB.setTitle(title);
tempUserKB.setTitle(FieldDictUtil.get("khsjgl", "kh_customer", "title", title));
} else if (c == 24) {
marital = cell.getStringCellValue();
if (StringUtils.isEmpty(marital)) {
rowMessage += "婚姻状况不能为空;";
} else if (marital.length() > 240) {
rowMessage += "婚姻状况长度不能超过24;";
}
// tempUserKB.setMarital(marital);
tempUserKB.setMarital(FieldDictUtil.get("khsjgl", "kh_customer", "marital", marital));
} else if (c == 25) {
hobby = cell.getStringCellValue();
if (StringUtils.isEmpty(hobby)) {
rowMessage += "爱好不能为空;";
} else if (hobby.length() > 240) {
rowMessage += "爱好不能超过24;";
}
// tempUserKB.setHobby(hobby);
tempUserKB.setHobby(FieldDictUtil.get("khsjgl", "kh_customer", "hobby", hobby));
} else if (c == 27) {
potential = cell.getStringCellValue();
if (StringUtils.isEmpty(potential)) {
rowMessage += "潜在商机不能为空;";
} else if (potential.length() > 240) {
rowMessage += "潜在商机长度不能超过24;";
}
// tempUserKB.setPotential(potential);
tempUserKB.setPotential(FieldDictUtil.get("khsjgl", "kh_customer", "potential", potential));
} else if (c == 28) {
source = cell.getStringCellValue();
if (StringUtils.isEmpty(source)) {
rowMessage += "信息来源不能为空;";
} else if (source.length() > 240) {
rowMessage += "信息来源长度不能超过24;";
}
// tempUserKB.setSource(source);
tempUserKB.setSource(FieldDictUtil.get("khsjgl", "kh_customer", "source", source));
} else if (c == 29) {
qq = cell.getStringCellValue();
if (StringUtils.isEmpty(qq)) {
rowMessage += "qq不能为空;";
} else if (qq.length() > 240) {
rowMessage += "qq长度不能超过24;";
}
// tempUserKB.setQq(qq);
tempUserKB.setQq(FieldDictUtil.get("khsjgl", "kh_customer", "qq", qq));
} else if (c == 30) {
wechat = cell.getStringCellValue();
if (StringUtils.isEmpty(wechat)) {
rowMessage += "微信不能为空;";
} else if (wechat.length() > 240) {
rowMessage += "微信长度不能超过24;";
}
// tempUserKB.setWechat(wechat);
tempUserKB.setWechat(FieldDictUtil.get("khsjgl", "kh_customer", "wechat", wechat));
} else if (c == 31) {
phone = cell.getStringCellValue();
if (StringUtils.isEmpty(phone)) {
rowMessage += "手机不能为空;";
} else if (phone.length() > 240) {
rowMessage += "手机长度不能超过24;";
}
// tempUserKB.setPhone(phone);
tempUserKB.setPhone(FieldDictUtil.get("khsjgl", "kh_customer", "phone", phone));
} else if (c == 32) {
telphone = cell.getStringCellValue();
if (StringUtils.isEmpty(telphone)) {
rowMessage += "telphone不能为空;";
} else if (email.length() > 240) {
rowMessage += "telphone长度不能超过24;";
}
// List<CustomerDO> list = customerDao.selectId(userKnowledgeBaseList);
//
// if (list.size() > 0) {
// for (CustomerDO Customer : list) {
// hobby += Customer.getId() ;
// }
// }
// tempUserKB.setTelphone(telphone);
tempUserKB.setTelphone(FieldDictUtil.get("khsjgl", "kh_customer", "telphone", telphone));
} else if (c == 33) {
email = cell.getStringCellValue();
if (StringUtils.isEmpty(email)) {
rowMessage += "邮箱不能为空;";
} else if (email.length() > 240) {
rowMessage += "邮箱长度不能超过24;";
}
// tempUserKB.setEmail(email);
tempUserKB.setEmail(FieldDictUtil.get("khsjgl", "kh_customer", "email", email));
} else if (c == 34) {
fax = cell.getStringCellValue();
if (StringUtils.isEmpty(fax)) {
rowMessage += "传真不能为空;";
} else if (source.length() > 240) {
rowMessage += "传真长度不能超过24;";
}
// tempUserKB.setFax(fax);
tempUserKB.setFax(FieldDictUtil.get("khsjgl", "kh_customer", "fax", fax));
} else if (c == 35) {
khhztypeid = cell.getStringCellValue();
if (StringUtils.isEmpty(khhztypeid)) {
rowMessage += "合作类型id不能为空;";
} else if (khhztypeid.length() > 240) {
rowMessage += "合作类型id长度不能超过24;";
}
// tempUserKB.setKhhztypeid(khhztypeid);
tempUserKB.setKhhztypeid(FieldDictUtil.get("khsjgl", "kh_customer", "khhztypeid", khhztypeid));
} else if (c == 36) {
hzjtlxid = cell.getStringCellValue();
if (StringUtils.isEmpty(hzjtlxid)) {
rowMessage += "合作具体类型id不能为空;";
} else if (hzjtlxid.length() > 240) {
rowMessage += "合作具体类型id长度不能超过24;";
}
// tempUserKB.setHzjtlxid(hzjtlxid);
tempUserKB.setHzjtlxid(FieldDictUtil.get("khsjgl", "kh_customer", "hzjtlxid", hzjtlxid));
} else if (c == 37) {
hzjtlxnameid = cell.getStringCellValue();
if (StringUtils.isEmpty(hzjtlxnameid)) {
rowMessage += "具体项目名称不能为空;";
} else if (hzjtlxnameid.length() > 240) {
rowMessage += "具体项目名称长度不能超过24;";
}
// tempUserKB.setHzjtlxnameid(hzjtlxnameid);
tempUserKB.setHzjtlxnameid(FieldDictUtil.get("khsjgl", "kh_customer", "hzjtlxnameid", hzjtlxnameid));
} else if (c == 38) {
remarks = cell.getStringCellValue();
if (StringUtils.isEmpty(remarks)) {
rowMessage += "remarks不能为空;";
} else if (remarks.length() > 240) {
rowMessage += "remarks长度不能超过24;";
}
// tempUserKB.setRemarks(remarks);
tempUserKB.setRemarks(FieldDictUtil.get("khsjgl", "kh_customer", "remarks", remarks));
} else if (c == 39) {
cooperation = cell.getStringCellValue();
if (StringUtils.isEmpty(cooperation)) {
rowMessage += "是否合作过不能为空;";
} else if (cooperation.length() > 240) {
rowMessage += "是否合作过长度不能超过24;";
}
// tempUserKB.setCooperation(cooperation);
tempUserKB.setCooperation(FieldDictUtil.get("khsjgl", "kh_customer", "cooperation", cooperation));
} else if (c == 40) {
first_time = cell.getStringCellValue();
if (StringUtils.isEmpty(first_time)) {
rowMessage += "初次见面不能为空;";
} else if (last_time.length() > 240) {
rowMessage += "初次见面长度不能超过24;";
}
// tempUserKB.setFirstTime(new SimpleDateFormat().parse(first_time));
tempUserKB.setFirstTime(new SimpleDateFormat().parse(FieldDictUtil.get("khsjgl", "kh_customer", "first_time", first_time)));
} else if (c == 41) {
last_time = cell.getStringCellValue();
if (StringUtils.isEmpty(last_time)) {
rowMessage += "最后一次见面不能为空;";
} else if (last_time.length() > 240) {
rowMessage += "最后一次见面长度不能超过24;";
}
// tempUserKB.setLastTime(new SimpleDateFormat().parse(last_time));
tempUserKB.setLastTime(new SimpleDateFormat().parse(FieldDictUtil.get("khsjgl", "kh_customer", "last_time", last_time)));
} else if (c == 42) {
intention = cell.getStringCellValue();
if (StringUtils.isEmpty(intention)) {
rowMessage += "合作意向不能为空;";
} else if (intention.length() > 240) {
rowMessage += "合作意向长度不能超过24;";
}
// tempUserKB.setIntention(intention);
tempUserKB.setIntention(FieldDictUtil.get("khsjgl", "kh_customer", "intention", intention));
} else if (c == 43) {
content = cell.getStringCellValue();
if (StringUtils.isEmpty(content)) {
rowMessage += "合作内容不能为空;";
} else if (content.length() > 240) {
rowMessage += "合作内容长度不能超过24;";
}
// tempUserKB.setContent(content);
tempUserKB.setContent(FieldDictUtil.get("khsjgl", "kh_customer", "content", content));
} else if (c == 44) {
money = cell.getStringCellValue();
if (StringUtils.isEmpty(money)) {
rowMessage += "合作金额不能为空;";
} else if (money.length() > 240) {
rowMessage += "合作金额的长度不能超过24;";
}
// tempUserKB.setMoney(money);
tempUserKB.setMoney(FieldDictUtil.get("khsjgl", "kh_customer", "money", money));
} else if (c == 45) {
date = cell.getStringCellValue();
if (StringUtils.isEmpty(date)) {
rowMessage += "合作日期不能为空;";
} else if (date.length() > 240) {
rowMessage += "合作日期长度不能超过24;";
}
// tempUserKB.setDate(date);
tempUserKB.setDate(FieldDictUtil.get("khsjgl", "kh_customer", "date", date));
} else if (c == 46) {
sources = cell.getStringCellValue();
if (StringUtils.isEmpty(sources)) {
rowMessage += "社会资源不能为空;";
} else if (sources.length() > 500) {
rowMessage += "社会资源长度不能超过24;";
}
// tempUserKB.setResources(sources);
tempUserKB.setResources(FieldDictUtil.get("khsjgl", "kh_customer", "sources", sources));
} else if (c == 47) {
create_by = cell.getStringCellValue();
if (StringUtils.isEmpty(create_by)) {
rowMessage += "客户创建人不能为空;";
} else if (create_by.length() > 5) {
rowMessage += "客户创建人长度不能超过24;";
}
// tempUserKB.setCreateBy(create_by);
tempUserKB.setCreateBy(FieldDictUtil.get("khsjgl", "kh_customer", "create_by", create_by));
} else if (c == 48) {
create_date = cell.getStringCellValue();
if (StringUtils.isEmpty(create_date)) {
rowMessage += "客户创建时间不能为空;";
}
// else if (create_date.length() > 240) {
// rowMessage += "客户创建时间长度不能超过24;";
// }
// tempUserKB.setCreateDate(new SimpleDateFormat().parse(create_date));
tempUserKB.setCreateDate(new SimpleDateFormat().parse(FieldDictUtil.get("khsjgl", "kh_customer", "create_date", create_date)));
}
else if (c == 49) {
enabled_flag = cell.getStringCellValue();
if (StringUtils.isEmpty(enabled_flag)) {
rowMessage += "客户创建时间不能为空;";
}
// else if (create_date.length() > 240) {
// rowMessage += "客户创建时间长度不能超过24;";
// }
// tempUserKB.setCreateDate(new SimpleDateFormat().parse(create_date));
tempUserKB.setEnabledFlag(Integer.valueOf(FieldDictUtil.get("khsjgl", "kh_customer", "enabled_flag", enabled_flag)));
}
else if (c == 50) {
confirm_status = cell.getStringCellValue();
if (StringUtils.isEmpty(create_date)) {
rowMessage += "客户创建时间不能为空;";
}
else if (confirm_status.length() > 240) {
rowMessage += "客户创建时间长度不能超过24;";
}
// tempUserKB.setCreateDate(new SimpleDateFormat().parse(create_date));
tempUserKB.setConfirmStatus(FieldDictUtil.get("khsjgl", "kh_customer", "confirm_status", confirm_status));
}
} else {
rowMessage += "第" + (c + 1) + "列数据有问题,请仔细检查;";
}
}
//拼接每行的错误提示
if (!StringUtils.isEmpty(rowMessage)) {
errorMsg += br + "第" + (r + 1) + "行," + rowMessage;
} else {
userKnowledgeBaseList.add(tempUserKB);
}
}
使用
//新建一个文件
File tempFile = new File(Filepath + System.currentTimeMillis() + ".xlsx");
//初始化输入流
InputStream is = null;
try {
//将上传的文件写入新建的文件中
file.transferTo(tempFile);
//根据新建的文件实例化输入流
is = new FileInputStream(tempFile);
//根据版本选择创建Workbook的方式
Workbook wb = null;
//根据文件名判断文件是2003版本还是2007版本
if (ExcelImportUtils.isExcel2007(fileName)) {
wb = new XSSFWorkbook(is);
} else {
wb = new HSSFWorkbook(is);
}
//根据excel里面的内容读取知识库信息
return readExcelValue(wb, tempFile);