|
|
@ -29,6 +29,8 @@ import javax.annotation.Resource; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import javax.validation.Valid; |
|
|
|
import java.io.IOException; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.time.ZoneOffset; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
import static com.win.framework.common.pojo.CommonResult.success; |
|
|
@ -135,11 +137,9 @@ public class UserController { |
|
|
|
@Operation(summary = "导出用户") |
|
|
|
@PreAuthorize("@ss.hasPermission('system:user:export')") |
|
|
|
@OperateLog(type = EXPORT) |
|
|
|
public void exportUserList(@Validated UserExportReqVO reqVO, |
|
|
|
HttpServletResponse response) throws IOException { |
|
|
|
public void exportUserList(@Validated UserExportReqVO reqVO, HttpServletResponse response) throws IOException { |
|
|
|
// 获得用户列表
|
|
|
|
List<AdminUserDO> users = userService.getUserList(reqVO); |
|
|
|
|
|
|
|
// 获得拼接需要的数据
|
|
|
|
Collection<Long> deptIds = convertList(users, AdminUserDO::getDeptId); |
|
|
|
Map<Long, DeptDO> deptMap = deptService.getDeptMap(deptIds); |
|
|
@ -160,7 +160,7 @@ public class UserController { |
|
|
|
}); |
|
|
|
|
|
|
|
// 输出
|
|
|
|
ExcelUtils.write(response, "用户数据.xls", "用户列表", UserExcelVO.class, excelUsers); |
|
|
|
ExcelUtils.write(response, "用户数据.xlsx", "用户列表", UserExcelVO.class, excelUsers); |
|
|
|
} |
|
|
|
|
|
|
|
@GetMapping("/get-import-template") |
|
|
@ -179,7 +179,7 @@ public class UserController { |
|
|
|
String[] status = DictFrameworkUtils.dictTypeDictDataValue(DictTypeConstants.COMMON_STATUS); |
|
|
|
mapDropDown.put(6, status); |
|
|
|
// 输出
|
|
|
|
ExcelUtils.write(response, "用户导入模板.xls", "用户列表", UserImportExcelVO.class, list, mapDropDown); |
|
|
|
ExcelUtils.write(response, "用户导入模板.xlsx", "用户列表", UserImportExcelVO.class, list, mapDropDown); |
|
|
|
} |
|
|
|
|
|
|
|
@PostMapping("/import") |
|
|
@ -190,10 +190,16 @@ public class UserController { |
|
|
|
@Parameter(name = "updatePart", description = "部分更新,默认为 true", example = "true") |
|
|
|
}) |
|
|
|
@PreAuthorize("@ss.hasPermission('system:user:import')") |
|
|
|
public void importExcel(HttpServletResponse response, @RequestParam("file") MultipartFile file, @RequestParam(value = "mode") Integer mode, @RequestParam(value = "updatePart") Boolean updatePart) throws Exception { |
|
|
|
public CommonResult<Map<String, Object>> importExcel(HttpServletResponse response, @RequestParam("file") MultipartFile file, @RequestParam(value = "mode") Integer mode, @RequestParam(value = "updatePart") Boolean updatePart) throws Exception { |
|
|
|
List<UserImportExcelVO> list = ExcelUtils.read(file, UserImportExcelVO.class); |
|
|
|
List<UserImportExcelVO> errorList = userService.importUserList(list, mode, updatePart); |
|
|
|
ExcelUtils.write(response, "用户导入错误数据.xls", "错误列表", UserImportExcelVO.class, errorList); |
|
|
|
Map<String, Object> returnMap = new HashMap<>(); |
|
|
|
returnMap.put("errorCount", errorList.size()); |
|
|
|
if(!errorList.isEmpty()) { |
|
|
|
String url = ExcelUtils.writeLocalFile("用户导入错误数据" + LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")) + ".xls", "错误列表", errorList); |
|
|
|
returnMap.put("errorFile", url); |
|
|
|
} |
|
|
|
return success(returnMap); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|