厦门在线制作网站,网站建站方案说明书,上海外贸网站推广方法,建设教育协会官网#本次做一个将患者数据导入到某个模块的功能#xff0c;前期集成的代码时不时出现异常#xff0c;本次进行修改记录
//controller层/*** 导入患者数据*/RejectReplayRequestPostMapping(/importData)public Result? importData(HttpServletRequest req…#本次做一个将患者数据导入到某个模块的功能前期集成的代码时不时出现异常本次进行修改记录
//controller层/*** 导入患者数据*/RejectReplayRequestPostMapping(/importData)public Result? importData(HttpServletRequest request, LoginUser loginUser, Param(value articleExtDataReq) String articleExtDataReq) throws IOException, ParseException {JSONObject jsonObject JSONObject.parseObject(articleExtDataReq);String merchantId jsonObject.getString(articleId);return articleExtDataService.importData(request, loginUser, merchantId);}//service层
/*** 导入更新商品*/Result? importData(HttpServletRequest request, LoginUser loginUser, String articleId) throws IOException, ParseException;//impl实现Overridepublic Result? importData(HttpServletRequest request, LoginUser loginUser, String articleId) throws IOException, ParseException {log.info(importData in articleId: articleId);//获取厂商信息Article byId articleService.getById(articleId);if (Objects.isNull(byId)) {return Result.error(您选择的文章不存在);}MapString, Long titleAndIdMap new HashMap();MapInteger, Long columnIndexAndExtIdMap new HashMap();ListArticleExt articleExts sysArticleExtService.listByArticleId(articleId, loginUser);articleExts.forEach(item - {titleAndIdMap.put(item.getTitle(), item.getId());});MultipartHttpServletRequest multipartRequest (MultipartHttpServletRequest) request;MapString, MultipartFile fileMap multipartRequest.getFileMap();for (Map.EntryString, MultipartFile entity : fileMap.entrySet()) {ListArticleExtData articleExtDataList new ArrayList();// 获取上传文件对象MultipartFile file entity.getValue();InputStream inputStream file.getInputStream();// 创建工作簿对象Workbook workbook new XSSFWorkbook(inputStream);Date uploadDate null;// 读取第一个工作表的数据Sheet sheet workbook.getSheetAt(0);for (Row row : sheet) {int rowNum row.getRowNum();IteratorCell cellIterator row.cellIterator();JSONObject jsonObject new JSONObject();while (cellIterator.hasNext()) {Cell cell cellIterator.next();cell.setCellType(CellType.STRING);int columnIndex cell.getColumnIndex();// 处理单元格数据这里只是简单地打印出来String stringCellValue cell.getStringCellValue();
// System.out.print(rowNum columnIndex stringCellValue \t);if (rowNum 0) {Long ExtId titleAndIdMap.get(stringCellValue);if (ExtId null !stringCellValue.contains(时间)) {//判断excel标题是否存在于系统return Result.error(系统不存在【 stringCellValue 】参数请在扩展数据中添加该参数信息);}if (ExtId ! null) {columnIndexAndExtIdMap.put(columnIndex, ExtId);}} else {if (rowNum 1 columnIndex 5 stringCellValue.length() 5) {stringCellValue DateUtils.ExcelDoubleToDate(stringCellValue);uploadDate DateUtils.parseDate(stringCellValue, yyyy-MM-dd);}if (columnIndex ! 5) {jsonObject.put(String.valueOf(columnIndexAndExtIdMap.get(columnIndex)), stringCellValue);}}}ArticleExtData articleExtData new ArticleExtData();articleExtData.setArticleId(articleId).setCreatedBy(loginUser.getId()).setUpdatedBy(loginUser.getId()).setValue(jsonObject.toJSONString()).setCreatedTime(uploadDate).setUpdatedTime(uploadDate);articleExtDataList.add(articleExtData);
// System.err.println(jsonObject);}articleExtDataService.saveBatch(articleExtDataList);}return Result.OK(导入完成);}
前端代码
//html
el-uploadclassupload-demoaction#:show-file-listfalse:on-changeimportData:auto-uploadfalseaccept.xlsx, .xlsstyledisplay: inline; margin-right: 10pxel-button typeprimary iconel-icon-download导入/el-button/el-uploadel-button typetext clickdownTemplate()下载导入模板/el-button//jsimport axios from axios;importData(param) {const that this;showLoading(); //显示加载中let formData new FormData(); //声明一个FormDate对象formData.append(file, param.raw); //把文件信息放入对象中formData.append(articleExtDataReq,JSON.stringify(this.articleExtDataObj.formData));this.path localStorage.getItem(urlcode);let text ${this.path}/articleExtData/importData;axios({url: text,method: post,async: false,processData: false,contentType: false, // 不设置数据类型data: formData,headers: {X-Access-Token: sessionStorage.getItem(token)}}).then(res {if (res.data.success true) {that.$message({type: success,message: res.data.message});setTimeout(() {that.getlist();}, 600);} else {that.$message.error(res.data.message);}}).catch(err {that.$message({type: error,message: 导入失败});});setTimeout(() {hideLoading();}, 1200);},// 下载导入模板downTemplate() {window.open(https://qiniu.sjhlwyy.com/ExcelTemp/Free_consultation_activities_Patient_data.xlsx);},