|
@@ -11,15 +11,18 @@ import com.management.platform.service.PermissionService;
|
|
|
import com.management.platform.service.SysRoleFunctionService;
|
|
|
import com.management.platform.service.SysRoleModuleService;
|
|
|
import com.management.platform.util.HttpRespMsg;
|
|
|
+import org.apache.poi.hssf.usermodel.*;
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
+import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -33,6 +36,8 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
@Transactional
|
|
|
public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permission> implements PermissionService {
|
|
|
+ @Value(value = "${upload.path}")
|
|
|
+ private String path;
|
|
|
@Resource
|
|
|
private UserMapper userMapper;
|
|
|
@Resource
|
|
@@ -335,6 +340,97 @@ public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permiss
|
|
|
return new HttpRespMsg();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg exportData(Integer role, Integer companyId) {
|
|
|
+ HttpRespMsg msg = getAuthority(role, companyId);
|
|
|
+ List<SysModule> menuList= (List<SysModule>) msg.data;
|
|
|
+ HSSFWorkbook wb=new HSSFWorkbook();
|
|
|
+ HSSFSheet sheet=wb.createSheet("权限数据统计");
|
|
|
+ //设置每一列的列宽
|
|
|
+ sheet.setColumnWidth(0,256*15);
|
|
|
+ sheet.setColumnWidth(1,256*20);
|
|
|
+ sheet.setColumnWidth(2,256*50);
|
|
|
+
|
|
|
+ List<String> titles = Arrays.asList("模块","功能","备注");
|
|
|
+ HSSFRow row = sheet.createRow(0);
|
|
|
+ HSSFCellStyle style = wb.createCellStyle();
|
|
|
+ style.setBorderBottom(BorderStyle.valueOf((short)1));
|
|
|
+ style.setBorderLeft(BorderStyle.valueOf((short)1));
|
|
|
+ style.setBorderRight(BorderStyle.valueOf((short)1));
|
|
|
+ style.setBorderTop(BorderStyle.valueOf((short)1));
|
|
|
+ //水平居中
|
|
|
+ style.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+ //垂直对齐
|
|
|
+ style.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
+ style.setBottomBorderColor(IndexedColors.BLACK.index);
|
|
|
+ //背景颜色
|
|
|
+ style.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex());
|
|
|
+ HSSFFont headerFont1 = (HSSFFont) wb.createFont();
|
|
|
+ //字体加粗
|
|
|
+ headerFont1.setBold(true);
|
|
|
+ //字体类型
|
|
|
+ headerFont1.setFontName("黑体");
|
|
|
+ //字体大小
|
|
|
+ headerFont1.setFontHeightInPoints((short)15);
|
|
|
+ style.setFont(headerFont1);
|
|
|
+ //创建标题
|
|
|
+ HSSFCell cell = null;
|
|
|
+ for (int i = 0; i < titles.size(); i++) {
|
|
|
+ cell = row.createCell(i);
|
|
|
+ cell.setCellValue(titles.get(i));
|
|
|
+ cell.setCellStyle(style);
|
|
|
+ }
|
|
|
+ //初始化起始行和结束行
|
|
|
+ int startRow = 1;
|
|
|
+ for (int i = 0; i < menuList.size(); i++) {
|
|
|
+ //利用模块合并单元格(合并行)
|
|
|
+ List<SysFunction> functionList = menuList.get(i).getFunctionList();
|
|
|
+ int endRow = startRow + functionList.size() -1;
|
|
|
+ if (functionList.size() > 1){
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(startRow,endRow, 0, 0));
|
|
|
+ for (int j = 0; j < functionList.size(); j++) {
|
|
|
+ row = sheet.createRow(startRow + j);
|
|
|
+ row.createCell(0).setCellValue(menuList.get(i).getName());
|
|
|
+ row.createCell(1).setCellValue(functionList.get(j).getName());
|
|
|
+ row.createCell(2).setCellValue(functionList.get(j).getRemarks());
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ row = sheet.createRow(startRow);
|
|
|
+ row.createCell(0).setCellValue(menuList.get(i).getName());
|
|
|
+ List<SysModule> children = menuList.get(i).getChildren();
|
|
|
+ if(children.size()>0){
|
|
|
+ for (int k = 0; k < children.size(); k++) {
|
|
|
+ row = sheet.createRow(startRow+k);
|
|
|
+ row.createCell(0).setCellValue(children.get(k).getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ startRow = endRow + 1;
|
|
|
+ }
|
|
|
+ //导出excel
|
|
|
+ String result="系统提示:Excel文件导出成功!";
|
|
|
+ String title= "权限数据统计_"+System.currentTimeMillis();
|
|
|
+ String fileName= title+".xls";
|
|
|
+ try {
|
|
|
+ File dir = null;
|
|
|
+ dir = new File(path);
|
|
|
+ // D://cloud/upload 文件上传后所存储的位置,部署到服务器上时配置服务器地址即可
|
|
|
+ if (!dir.exists()) {
|
|
|
+ dir.mkdirs();
|
|
|
+ }
|
|
|
+ FileOutputStream os = new FileOutputStream(path+fileName);//保存到本地
|
|
|
+ wb.write(os);
|
|
|
+ os.flush();
|
|
|
+ os.close();
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
+ httpRespMsg.data ="/upload/"+fileName;
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+
|
|
|
private List<Integer> getCheckedFunList(JSONObject menu) {
|
|
|
List<Integer> funIds = new ArrayList<>();
|
|
|
JSONArray funList = menu.getJSONArray("functionList");
|