poi导入
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE html> <html> <head> <jsp:include page="/static/common/head.jsp" flush="true"/> <link rel="stylesheet" href="<%=basePath%>static/skin/css/base.css"> <script src="<%=basePath%>static/plugins/jQuery/jQuery-2.1.4.min.js"></script> <script src="<%=basePath%>static/plugins/pace/pace.min.js"></script> <script src="<%=basePath%>static/plugins/layer/layer.js"></script> <script src="<%=basePath%>static/plugins/JQueryValidate/jquery.validate.min.js"></script> <script src="<%=basePath%>static/plugins/JQueryValidate/localization/messages_zh.js"></script> <script src="<%=basePath%>static/skin/js/common.js"></script> <script type="text/javascript"> $(function(){ validateForm= $("#krtForm").validate(); //立即验证 validateForm.form(); $("#uploadBtn").click(function(){ $("#excelFile").click(); }); $("#uploadDiv").on("change","input[type='file']",function(){ var filePath=$(this).val(); if(filePath.indexOf("xls")!=-1 || filePath.indexOf("xlsx")!=-1){ $("#excelName").html(filePath); }else{ top.layer.msg("您未上传文件,或者您上传文件类型有误!"); return false; } }); }); function doSubmit(){//回调函数,在编辑和保存动作时,供openDialog调用提交表单。 if(validateForm.form()){ $("#krtForm").submit(); } } var result = '${result}'; if(result!=null){ if(result=='success'){ top.layer.msg("导入成功"); setTimeout(function(){ refreshIframe(); var index = parent.layer.getFrameIndex(window.name); parent.layer.close(index); }, 1000); }else if(result=='error'){ top.layer.msg("导入失败!"); } } </script> </head> <body class="hold-transition skin-blue sidebar-mini"> <div class="wrapper"> <div class="form-box"> <form action="<%=basePath %>admin/enterprise/info/enterprise_export_insert" method="post" enctype="multipart/form-data" id="krtForm" class="form-horizontal"> <div class="col-xs-12"> <div style="border:3px dashed #e6e6e6;margin:20px;min-height:240px;color: #cccccc;text-align: center;"> <div style="margin-top: 40px;" id="uploadDiv"> <i class="fa fa-cloud-upload fa-btn" style="color: #bbb;font-size: 70px;margin-bottom: 6px;display: block;"></i> <button class="btn btn-primary btn-lg" id="uploadBtn" type="button">点击上传企业信息</button> <span id="excelName" style="display: block;margin-top: 6px; color: #77777"></span> <!-- file --> <input type="file" name="excelFile" id="excelFile" style="display: none"> </div> </div> </div> </form> </div> </div><!-- ./wrapper --> </body> </html>
/** * 批量导入添加企业信息 * * @param @param request * @param @param file * @param @return ReturnBean * @author donghao * @date 2016年10月20日 上午11:58:17 */ @LogAop(description = "批量导入添加企业信息") @RequiresPermissions("enterprise:export_insert") @RequestMapping("admin/enterprise/info/enterprise_export_insert") @ResponseBody public ReturnBean enterprise_export_insert(HttpServletRequest request, @RequestParam("excelFile") MultipartFile file) { ReturnBean rb; // 导入参数设置 ImportParams params = new ImportParams(); params.setTitleRows(0); params.setHeadRows(1); params.setNeedSave(false); try { List<Enterprise_export> dataList = ExcelImportUtil.importExcel(file.getInputStream(), Enterprise_export.class, params); System.out.println(dataList); enterpriseService.insertExport(dataList); rb = ReturnBean.getSuccessReturnBean(); } catch (Exception e) { logger.error("添加企业信息失败", e); rb = ReturnBean.getErrorReturnBean(); } return rb; }
/** * 批量添加用户 * @param dataList 企业信息集合 * @throws Exception */ public void insertExport(List<Enterprise_export> dataList) throws Exception{ Enterprise enterprise = new Enterprise(); User user = new User(); for(int i = 0; i < dataList.size(); i++){ String uscc = Common.isBlank(dataList.get(i).getUscc()); String ename = Common.isBlank(dataList.get(i).getEname()); String legalName = Common.isBlank(dataList.get(i).getLegalName()); String legalPhone = Common.isBlank(dataList.get(i).getLegalPhone()); String linkMan = Common.isBlank(dataList.get(i).getLinkMan()); String linkPhone = Common.isBlank(dataList.get(i).getLinkPhone()); String address = Common.isBlank(dataList.get(i).getAddress()); String region = Common.isBlank(dataList.get(i).getRegion()); String industry = Common.isBlank(dataList.get(i).getIndustry()); String reg_type = Common.isBlank(dataList.get(i).getReg_type()); String affiliation = Common.isBlank(dataList.get(i).getAffiliation()); String industrial = Common.isBlank(dataList.get(i).getIndustrial()); String scale = Common.isBlank(dataList.get(i).getScale()); String industry_elec = Common.isBlank(dataList.get(i).getIndustry_elec()); String industry_food = Common.isBlank(dataList.get(i).getIndustry_food()); String industry_new = Common.isBlank(dataList.get(i).getIndustry_new()); String isGood = Common.isBlank(dataList.get(i).getIsGood()); String isPoint = Common.isBlank(dataList.get(i).getIsPoint()); address = address.endsWith("无") ? "" : address; legalPhone = legalPhone.endsWith("无") ? "" : legalPhone; legalName = legalName.endsWith("无") ? "" : legalName; region = region.endsWith("无") ? "" : region; isGood = "".equals(isGood) ? "0" : isGood ; isPoint = "".equals(isPoint) ? "1" : isPoint ; UUID uuid= UUID.randomUUID(); String uuids=uuid.toString().replace("-", ""); uuid = UUID.randomUUID(); String uuid_qy=uuid.toString(); enterprise.setUuid(uuid_qy); enterprise.setUscc(uscc); enterprise.setEname(ename); enterprise.setLegalPhone(legalPhone); enterprise.setLegalName(legalName); enterprise.setLinkMan(linkMan); enterprise.setLinkPhone(linkPhone); enterprise.setAddress(address); enterprise.setRegion(region); enterprise.setIndustry(industry); enterprise.setReg_type(reg_type); enterprise.setAffiliation(affiliation); enterprise.setIndustrial(industrial); enterprise.setScale(scale); enterprise.setIndustry_elec(industry_elec); enterprise.setIndustry_food(industry_food); enterprise.setIndustry_new(industry_new); enterprise.setIsGood(isGood); enterprise.setIsPoint(isPoint); enterprise.setType("5,2,4,8,7,6,9,10,11"); //保存企业信息 insert(enterprise); System.out.println("--------保存企业信息-----------"); //创建统一登录用户 user.setName(enterprise.getEname()); user.setUsername("jacom"+enterprise.getId());//自定义用户名 //user.setPassword(AESvbjavajs.getAESEncrypt("123456", Constant.PASS_KEY));//自定义密码 user.setPassword(MD5Utils.encoderByMd5With32Bit("123456")); user.setStatus("0"); user.setUuid(uuids); user.setRegion(region); //保存统一登录用户和角色 userService.insert(user,Constant.ENT); System.out.println("--------保存统一登录用户和角色-----------"); //保存企业云登陆用户和角色 YunUser yunUser = new YunUser(); yunUser.setAddress(enterprise.getAddress()); yunUser.setEnterpriceId(enterprise.getId()); yunUser.setImgSrcType("3"); yunUser.setName(enterprise.getEname()); yunUser.setPhone(enterprise.getLegalPhone()); yunUser.setRoleType("2"); yunUser.setSex(1); yunUser.setState(1); yunUser.setSystemSource("3"); yunUser.setTel(enterprise.getLegalPhone()); yunUser.setUuid(uuids); yunUser.setUuid_qy(enterprise.getUuid()); yunUser.setAddTimes(new Date()); //userService.insertYun_user(yunUser); System.out.println("--------保存企业云登陆用户和角色-----------"); //保存企业帮扶登陆用户和角色 Qyhelp_user qyhelp_user = new Qyhelp_user(); qyhelp_user.setDescription(enterprise.getEname()); qyhelp_user.setIs_login(0); qyhelp_user.setState(1); qyhelp_user.setT_id(enterprise.getId()); qyhelp_user.setT_lx(1); qyhelp_user.setT_name(enterprise.getEname()); qyhelp_user.setUuid(uuids); qyhelp_user.setUuid_qy(enterprise.getUuid()); //userService.insertQyhelp_user(qyhelp_user); System.out.println("--------保存企业帮扶登陆用户和角色-----------"); enterprise.setId(null); user.setId(null); //同步至企业精准帮扶内企业的信息 // PropertyUtil p = new PropertyUtil("port.properties"); // JSONObject ent = new JSONObject(); // ent.put("name", enterprise.getEname());//企业名称 // ent.put("credit_code", enterprise.getUscc());//统一社会信用代码 // ent.put("county", enterprise.getRegion());//地区编码 // ent.put("address", enterprise.getAddress());//详细地址 // ent.put("lat", enterprise.getLat()); // ent.put("lng", enterprise.getLng()); // ent.put("description", enterprise.getProfile());//公司简介 // ent.put("updateTime", enterprise.getUpdateTime()); // ent.put("uuid", enterprise.getUuid()); // // ent.put("legal_code", enterprise.getLegal_code());//企业法人代码/组织机构代码 // ent.put("postcode", enterprise.getPostcode());//邮政编码 // ent.put("room_tel", enterprise.getEphone());//企业办公室电话 // ent.put("legal_man", enterprise.getLinkMan());//企业主要负责人姓名 // ent.put("legal_mobile", enterprise.getLinkPhone());//企业主要负责人移动电话 // ent.put("is_point", enterprise.getIsPoint());//是否规上企业 //// 图片地址 imgSrc(img) // String rs = SendPost.send("http://111.75.240.74:56794/port/sendCompanyInfo", p.getValue("tokenUrl"), p.getValue("tag"),p.getValue("key"), "{"+"\"data\":"+"["+ent.toString()+"]}"); // logger.error(rs); } }