导入excel校验示例代码

pull/2310/head
zhangdaiscott 2021-02-01 20:32:41 +08:00
parent 88a0bb2d2d
commit 4a5ff61ef7
1 changed files with 30 additions and 29 deletions

View File

@ -26,11 +26,11 @@ import org.jeecg.modules.system.model.TreeSelectModel;
import org.jeecg.modules.system.service.ISysDictItemService;
import org.jeecg.modules.system.service.ISysDictService;
import org.jeecg.modules.system.vo.SysDictPage;
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;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.entity.result.ExcelImportResult;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -293,12 +293,13 @@ public class SysDictController {
}
/**
* APP
* APP
* @param query
* @param pageNo
* @param pageSize
* @return
*/
@Deprecated
@GetMapping("/queryTableData")
public Result<List<DictModel>> queryTableData(DictQuery query,
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@ -319,7 +320,7 @@ public class SysDictController {
* @param sysDict
* @return
*/
//@RequiresRoles({"admin"})
@RequiresRoles({"admin"})
@RequestMapping(value = "/add", method = RequestMethod.POST)
public Result<SysDict> add(@RequestBody SysDict sysDict) {
Result<SysDict> result = new Result<SysDict>();
@ -340,7 +341,7 @@ public class SysDictController {
* @param sysDict
* @return
*/
//@RequiresRoles({"admin"})
@RequiresRoles({"admin"})
@RequestMapping(value = "/edit", method = RequestMethod.PUT)
public Result<SysDict> edit(@RequestBody SysDict sysDict) {
Result<SysDict> result = new Result<SysDict>();
@ -362,7 +363,7 @@ public class SysDictController {
* @param id
* @return
*/
//@RequiresRoles({"admin"})
@RequiresRoles({"admin"})
@RequestMapping(value = "/delete", method = RequestMethod.DELETE)
@CacheEvict(value=CacheConstant.SYS_DICT_CACHE, allEntries=true)
public Result<SysDict> delete(@RequestParam(name="id",required=true) String id) {
@ -381,7 +382,7 @@ public class SysDictController {
* @param ids
* @return
*/
//@RequiresRoles({"admin"})
@RequiresRoles({"admin"})
@RequestMapping(value = "/deleteBatch", method = RequestMethod.DELETE)
@CacheEvict(value= CacheConstant.SYS_DICT_CACHE, allEntries=true)
public Result<SysDict> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
@ -460,7 +461,7 @@ public class SysDictController {
* @param
* @return
*/
//@RequiresRoles({"admin"})
@RequiresRoles({"admin"})
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
@ -473,8 +474,8 @@ public class SysDictController {
params.setNeedSave(true);
try {
//导入Excel格式校验看匹配的字段文本概率
ExcelImportResult t = ExcelImportUtil.importExcelVerify(file.getInputStream(), SysDictPage.class, params);
if(t.isVerfiyFail()){
Boolean t = ExcelImportCheckUtil.check(file.getInputStream(), SysDictPage.class, params);
if(!t){
throw new RuntimeException("导入Excel校验失败 ");
}
List<SysDictPage> list = ExcelImportUtil.importExcel(file.getInputStream(), SysDictPage.class, params);