update 标准征求意见详情代码
This commit is contained in:
+54
@@ -5,12 +5,14 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.system.query.QueryGenerator;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.beanutils.PropertyUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.jeecgframework.poi.excel.ExcelImportCheckUtil;
|
||||
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
||||
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||
@@ -224,4 +226,56 @@ public class JeroController<T, S extends IService<T>> {
|
||||
}
|
||||
return Result.error("文件导入失败!");
|
||||
}
|
||||
/**
|
||||
* 通过excel获取导入数据
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
protected List<T> getExcelData(HttpServletRequest request, Class<T> clazz) {
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
||||
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
||||
// 获取上传文件对象
|
||||
MultipartFile file = entity.getValue();
|
||||
//校验文件名
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
if (originalFilename != null) {
|
||||
String substring = originalFilename.substring(originalFilename.lastIndexOf("."));
|
||||
if (!".xlsx".equals(substring)&&!".xls".equals(substring)) {
|
||||
throw new JeroBootException("文件类型错误:" + "请上传.xlsx或.xls文件!");
|
||||
}
|
||||
} else {
|
||||
throw new JeroBootException("文件错误:" + "文件名丢失,请上传正确的文件!");
|
||||
}
|
||||
ImportParams params = new ImportParams();
|
||||
params.setSheetNum(1);
|
||||
params.setTitleRows(1);
|
||||
params.setHeadRows(1);
|
||||
try {
|
||||
//导入Excel格式校验,看匹配的字段文本概率
|
||||
Boolean t = ExcelImportCheckUtil.check(file.getInputStream(), clazz, params);
|
||||
if (t == null) {
|
||||
throw new JeroBootException("导入数据为空!");
|
||||
}
|
||||
if(!t){
|
||||
throw new JeroBootException("文件格式有误,请下载模板后上传 !");
|
||||
}
|
||||
return ExcelImportUtil.importExcel(file.getInputStream(), clazz, params);
|
||||
} catch (Exception e) {
|
||||
if(Objects.isNull(e.getMessage())){
|
||||
throw new JeroBootException("文件导入失败:请填写内容标题!");
|
||||
}
|
||||
log.error("文件导入失败:",e);
|
||||
throw new JeroBootException("文件导入失败:" + e.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
file.getInputStream().close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new JeroBootException("文件导入失败!");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user