| | |
| | | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_IMPORT_FILE_EMPTY; |
| | | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_IMPORT_FILE_INVALID; |
| | | |
| | | @Tag(name = "管理后台 - 用户") |
| | | @RestController |
| | |
| | | @PreAuthorize("@ss.hasPermission('system:user:import')") |
| | | public CommonResult<UserImportRespVO> importExcel(@RequestParam("file") MultipartFile file, |
| | | @RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) throws Exception { |
| | | // 空文件 / 非法文件给出明确提示,避免底层异常变成「系统异常」 |
| | | if (file == null || file.isEmpty()) { |
| | | throw exception(USER_IMPORT_FILE_EMPTY); |
| | | } |
| | | List<UserImportExcelVO> list; |
| | | try { |
| | | list = ExcelUtils.read(file, UserImportExcelVO.class); |
| | | } catch (Exception ex) { |
| | | throw exception(USER_IMPORT_FILE_INVALID); |
| | | } |
| | | // 空文件 / 坏文件 / 模板不匹配等,ExcelUtils.read 已统一转换为可读的中文提示 |
| | | List<UserImportExcelVO> list = ExcelUtils.read(file, UserImportExcelVO.class); |
| | | return success(userService.importUserList(list, updateSupport)); |
| | | } |
| | | |