Ver Fonte

权限导出 bug修改

yurk há 2 anos atrás
pai
commit
ab984e4524

+ 5 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/PermissionController.java

@@ -83,6 +83,11 @@ public class PermissionController {
         return permissionService.getAuthority(role, companyId);
     }
 
+    @RequestMapping("/exportData")
+    public HttpRespMsg exportData(@RequestParam Integer role, @RequestParam Integer companyId){
+        return permissionService.exportData(role,companyId);
+    }
+
     @RequestMapping("/switchAuthority")
     public HttpRespMsg switchAuthority(@RequestParam Integer role, @RequestParam Integer id) {
         return permissionService.switchAuthority(role, id);

+ 10 - 4
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/entity/SysFunction.java

@@ -1,21 +1,22 @@
 package com.management.platform.entity;
 
 import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.extension.activerecord.Model;
-import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableField;
-import java.io.Serializable;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
 
+import java.io.Serializable;
+
 /**
  * <p>
  * 菜单功能权限关联表
  * </p>
  *
  * @author Seyason
- * @since 2022-04-05
+ * @since 2022-06-30
  */
 @Data
 @EqualsAndHashCode(callSuper = false)
@@ -129,6 +130,11 @@ public class SysFunction extends Model<SysFunction> {
     @TableField("finance_audit")
     private Integer financeAudit;
 
+    /**
+     * 备注
+     */
+    @TableField("remarks")
+    private String remarks;
 
     @TableField(exist = false)
     private boolean checked;

+ 2 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/PermissionService.java

@@ -34,4 +34,6 @@ public interface PermissionService extends IService<Permission> {
     HttpRespMsg savePermission(Integer role, String moduleList);
 
     HttpRespMsg setDefaultRole(Integer id, Integer companyId);
+
+    HttpRespMsg exportData(Integer role, Integer companyId);
 }

+ 100 - 4
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/PermissionServiceImpl.java

@@ -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");

+ 2 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/resources/mapper/ProjectMapper.xml

@@ -713,6 +713,7 @@
             and rp.dept_id=#{departmentId}
         </if>
         group by us.id
+        order by rp.dept_id
         <if test="start!=null and size!=null">
             limit #{start},#{size}
         </if>
@@ -732,6 +733,7 @@
             and rp.dept_id=#{departmentId}
         </if>
         group by us.id
+        order by rp.dept_id
         <if test="start!=null and size!=null">
             limit #{start},#{size}
         </if>) total

+ 0 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/resources/mapper/ReportMapper.xml

@@ -162,7 +162,6 @@
         <if test="departmentId != null">
             AND department.department_id = #{departmentId}
         </if>
-
         ORDER BY a.creator_id, a.create_date desc
     </select>
 

+ 2 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/resources/mapper/SysFunctionMapper.xml

@@ -22,6 +22,7 @@
         <result column="package_finance" property="packageFinance" />
         <result column="sync_corpwx_time" property="syncCorpwxTime" />
         <result column="finance_audit" property="financeAudit" />
+        <result column="remarks" property="remarks" />
     </resultMap>
     <resultMap id="BaseResultMap1" type="com.management.platform.entity.vo.SysRichFunction">
         <id column="id" property="id" />
@@ -34,7 +35,7 @@
     </resultMap>
     <!-- 通用查询结果列 -->
     <sql id="Base_Column_List">
-        id, name, icon, code, module_id, seq, use_state, package_time, package_project, package_oa, package_expense, package_customer, package_engineering, package_contract, package_etimecard, package_finance, sync_corpwx_time, finance_audit
+        id, name, icon, code, module_id, seq, use_state, package_time, package_project, package_oa, package_expense, package_customer, package_engineering, package_contract, package_etimecard, package_finance, sync_corpwx_time, finance_audit, remarks
     </sql>
     <select id="getRoleFunctions" resultMap="BaseResultMap1" >
         select sys_function.id, sys_function.name, sys_function.icon, sys_function.code, sys_function.module_id, sys_function.seq, sys_module.name as module_name