|
|
@@ -1,6 +1,7 @@
|
|
|
package com.lc.ibps.org.provider;
|
|
|
|
|
|
import com.lc.ibps.api.base.constants.StateEnum;
|
|
|
+import com.lc.ibps.api.base.file.FileInfo;
|
|
|
import com.lc.ibps.api.base.model.PartyEntity;
|
|
|
import com.lc.ibps.api.base.query.QueryFilter;
|
|
|
import com.lc.ibps.api.base.query.QueryOP;
|
|
|
@@ -18,6 +19,7 @@ import com.lc.ibps.base.web.context.ContextUtil;
|
|
|
import com.lc.ibps.cloud.entity.*;
|
|
|
import com.lc.ibps.cloud.provider.GenericProvider;
|
|
|
import com.lc.ibps.cloud.utils.RequestUtil;
|
|
|
+import com.lc.ibps.components.upload.util.UploadUtil;
|
|
|
import com.lc.ibps.org.api.IPartyRoleMgrService;
|
|
|
import com.lc.ibps.org.api.IPartyRoleService;
|
|
|
import com.lc.ibps.org.auth.persistence.entity.RoleSystemPo;
|
|
|
@@ -34,12 +36,17 @@ import com.lc.ibps.org.util.PartyUtil;
|
|
|
import com.lc.ibps.org.vo.IdKeyVo;
|
|
|
import com.lc.ibps.platform.service.PartyRoleProviderService;
|
|
|
import io.swagger.annotations.*;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFRow;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFSheet;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -817,6 +824,74 @@ public class PartyRoleProvider extends GenericProvider implements IPartyRoleServ
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void getFileStreamPermission(APIRequest request) {
|
|
|
+ try {
|
|
|
+ HttpServletResponse response = this.getResponse();
|
|
|
+
|
|
|
+ // 调用服务获取权限数据
|
|
|
+ APIResult<PermissionPageList<PermissionViewDTO>> result = partyRoleProviderService.getPagePermission(request);
|
|
|
+ if (result == null || result.getData() == null || result.getData().getData() == null) {
|
|
|
+ throw new RuntimeException("获取权限数据失败");
|
|
|
+ }
|
|
|
+ PermissionViewDTO permissionView = result.getData().getData();
|
|
|
+ List<String> roles = permissionView.getRoles();
|
|
|
+ List<PagePermissionDTO> permissions = permissionView.getPermissions();
|
|
|
+
|
|
|
+ // 设置响应头,指定为Excel文件下载
|
|
|
+ response.setContentType("application/vnd.ms-excel");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ String fileName = URLEncoder.encode("权限导出.xls", "UTF-8");
|
|
|
+ response.setHeader("Content-disposition", "attachment;filename=" + fileName);
|
|
|
+
|
|
|
+ // 创建工作簿
|
|
|
+ HSSFWorkbook workbook = new HSSFWorkbook();
|
|
|
+ HSSFSheet sheet = workbook.createSheet("权限列表");
|
|
|
+
|
|
|
+ // 创建标题行(第一行)
|
|
|
+ HSSFRow headerRow = sheet.createRow(0);
|
|
|
+ headerRow.createCell(0).setCellValue("页面名称"); // 第一列固定为页面名称
|
|
|
+ for (int i = 0; i < roles.size(); i++) {
|
|
|
+ headerRow.createCell(i + 1).setCellValue(roles.get(i)); // 后续每列为一个角色
|
|
|
+ }
|
|
|
+
|
|
|
+ // 填充数据行(每个页面一行)
|
|
|
+ for (int i = 0; i < permissions.size(); i++) {
|
|
|
+ PagePermissionDTO page = permissions.get(i);
|
|
|
+ HSSFRow dataRow = sheet.createRow(i + 1);
|
|
|
+ dataRow.createCell(0).setCellValue(page.getPageName()); // 页面名称
|
|
|
+
|
|
|
+ Map<String, Boolean> rolePerms = page.getRolePermissions();
|
|
|
+ for (int j = 0; j < roles.size(); j++) {
|
|
|
+ String role = roles.get(j);
|
|
|
+ Boolean hasPerm = rolePerms.get(role);
|
|
|
+ String cellValue = Boolean.TRUE.equals(hasPerm) ? "√" : ""; // 有权限打勾
|
|
|
+ dataRow.createCell(j + 1).setCellValue(cellValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 自动调整列宽
|
|
|
+ for (int i = 0; i <= roles.size(); i++) {
|
|
|
+ sheet.autoSizeColumn(i);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将工作簿写入响应输出流
|
|
|
+ workbook.write(response.getOutputStream());
|
|
|
+ response.getOutputStream().flush();
|
|
|
+ workbook.close();
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("/upload/getFileStreamPermission", e);
|
|
|
+ // 发生错误时返回JSON错误信息
|
|
|
+ try {
|
|
|
+ HttpServletResponse response = this.getResponse();
|
|
|
+ response.setContentType("application/json;charset=UTF-8");
|
|
|
+ response.getWriter().write("{\"code\":500,\"message\":\"导出失败:" + e.getMessage() + "\"}");
|
|
|
+ } catch (Exception ex) {
|
|
|
+ logger.error("返回错误信息失败", ex);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "查询角色树", notes = "查询角色树")
|