前端jsp
根据需求添加至想要的地方
导入审批清单
根据需求选择需要的数据
<
!--导入数据模态框-->
导入数据前请先下载审批清单导入样表 审批清单样表下载
前端js
需要定义的
//新选择文件集合 var selectedPics = new Array(); //原始文件集合 var originalPics = new Array(); var allowedFileExtensions = ['xls', 'xlsx'];// 接收的文件后缀
我的项目中还有这些需求
//导入数据方法
function initPutExcelUpload() {
showLoading();//调用加载数据方法
//上传的路径
// uploadFileSetting['uploadUrl'] = basePath + "baseCommunicationInfo/importbaseCommunicationInfo";
uploadFileSetting['allowedFileExtensions'] = allowedFileExtensions;
uploadFileSetting['dropZoneEnabled'] = false;
uploadFileSetting['showPreview'] = true;
uploadFileSetting['showRemove'] = true;
uploadFileSetting['showUpload'] = false;
uploadFileSetting['showCancel'] = true;
uploadFileSetting['maxFileCount'] = 1;
initUploadFile("excelContent", selectedPics, originalPics, "phoneInstallationExcel");
var fileObj = document.getElementsByClassName('file-caption-name')[0];
if (fileObj) fileObj.innerHTML = '';
$('.file-preview').addClass('hide'); //隐藏文件预览组件
$('.kv-upload-progress').hide();//隐藏进度条
$(".fileinput-cancel-button").hide();
//文件上传成功
$("#excelContent").on("fileuploaded", function (event, data, previewId, index) {
$("#putExcel").modal("hide");
var attachmentPath = getFileUrl(selectedPics, originalPics);
initBizParam();
showLoading();
putBizParam("filePath", attachmentPath);
ajaxRequest("baseCommunicationInfo/importbaseCommunicationInfo", getBizString(), function (data) {//路径
hideLoading();
if (data.returnData) {
//直接清空
$("#addPersonnelList").html("");
for (var i = 0; i < data.returnData.length; i++) {
var item = data.returnData[i];
parseDetailInfo1("#addPersonnelList", ".SB_1","",item.useUserName,item.dutyUserName,
item.depName,"",item.serviceProviderName,item.communicationNum,item.sysUserName,
item.useApplyTypeName,item.useStartTime,item.isCollectionFlag,"",item.useRemark)//需上传的字段名
}
}
},"POST");
// 刷新表格
info("上传成功");
});
//文件上传失败
$("#excelContent").on("fileuploaderror", function (event, data, msg) {
hideLoading();
bootstrapQ.alert({
id:"model1",
title: "提示",
msg: msg,
close: true,
keyboard: false
}, function aa() {
var obj = document.getElementsByClassName('file-caption-name')[0];
obj.innerHTML = '';
obj.title = '';
$("#putExcel").modal("show");
});
});
$("#putExcelOK").on("click", function () {
var attachmentPath = $("#excelContent").val()
if (attachmentPath == undefined || attachmentPath == null || attachmentPath == '') {
info("请选择文件!");
return;
}
$("#putExcel").modal("hide");
showLoading();
$("#excelContent").fileinput("upload");
});
}
// 获取上传的文件地址
function getFileUrl(selectedPics, originalPics) {
var urls = "";
$.each(selectedPics, function (index, item) {
item = JSON.parse(item);
if (item.hasUpload) {
urls += ";"+item.picUrl;
}
});
$.each(originalPics, function (index, item) {
urls += ";"+item;
});
if(urls&&urls!=""){
urls=urls.substring(1);
}
return urls;
}
controller层
@PostMapping("/importbaseCommunicationInfo")
public String importbaseCommunicationInfo(@RequestParam(value = "data") String data) throws Exception {
Map bizmap = (Map) JacksonUtils.json2map(data).get("biz");
return baseCommunicationService.importbaseCommunicationInfo(bizmap);
}
实体类(pojo层)
@Excel(name = "系统用户名称"):对应excel表列名
@Excel(name = "是否托收",replace = "1_是,-1_否")
replace:把数字替换成文本
service层
接口
String importbaseCommunicationInfo(MapbizMap) throws Exception;
class类
//上传 @Override public String importbaseCommunicationInfo(MapbizMap){ try { String path = rootPath + MapUtils.getValueString(bizMap, "filePath"); String companyId = MapUtils.getValueString(bizMap, "companyId"); List list =null; try { ExcelimportResult result = EasyPoiUtils.importExcelMore(path, 1, 1, baseCommunicationInfo.class); list = result.getList(); //部门名称传到前端 for (baseCommunicationInfo baseCommunicationInfo: list) { HashMap stringObjectHashMap = new HashMap<>(); stringObjectHashMap.put("companyId",companyId); stringObjectHashMap.put("departmentName",baseCommunicationInfo.getDeptName()); List department = departmentMapper.queryByDepName(stringObjectHashMap); if(department.size() == 1){ baseCommunicationInfo.setDepId(new BigDecimal(department.get(0).getDepartmentNo())); baseCommunicationInfo.setDeptName(department.get(0).getDepartmentName()); }else{ baseCommunicationInfo.setDepId(null); baseCommunicationInfo.setDeptName(""); } } return ResultInfoUtils.success(list); }catch (ExcelimportException e){ e.printStackTrace(); return ResultInfoUtils.businessError("1001","Excel模板不合法,请下载示例模板并按要求填写数据",""); } } catch (Exception e) { e.printStackTrace(); return ResultInfoUtils.systemError(); } }



