Browse Source

1.日报导出将部门所有层级列出
2.修复父级部门导出不了数据的问题

cs 2 years ago
parent
commit
c2a3203157

+ 3 - 3
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/mapper/ReportMapper.java

@@ -26,7 +26,7 @@ public interface ReportMapper extends BaseMapper<Report> {
                                                      @Param("endDate") String endDate,
                                                      @Param("projectId") Integer projectId,
                                                      @Param("stateKey") Integer stateKey,
-                                                     @Param("departmentId")Integer departmentId
+                                                     @Param("branchDepartment")List<Integer> branchDepartment
                                                  );
 
     List<HashMap<String, Object>> getProjectMembReportByDate(@Param("startDate") String startDate,
@@ -35,13 +35,13 @@ public interface ReportMapper extends BaseMapper<Report> {
                                                      @Param("endDate") String endDate,
                                                      @Param("projectId") Integer projectId,
                                                      @Param("stateKey") Integer stateKey,
-                                                     @Param("departmentId")Integer departmentId);
+                                                     @Param("branchDepartment")List<Integer> branchDepartment);
 
     //获取部门下的人员的日报
     List<HashMap<String, Object>> getDeptMembReportByDate(@Param("startDate") String startDate,
                                                              @Param("companyId") Integer companyId,
                                                              @Param("deptIds") List<Integer> deptIds,
-                                                             @Param("endDate") String endDate, @Param("projectId") Integer projectId,@Param("stateKey")Integer stateKey,@Param("departmentId")Integer departmentId);
+                                                             @Param("endDate") String endDate, @Param("projectId") Integer projectId,@Param("stateKey")Integer stateKey,@Param("branchDepartment")List<Integer> branchDepartment);
 
     //按当前人员获取本人报告
     List<Map<String, Object>> getReportByDate(@Param("date") String date, @Param("id") String id);

+ 8 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/DepartmentService.java

@@ -50,4 +50,12 @@ public interface DepartmentService extends IService<Department> {
     public List<Integer> getAllManagedDeptIdList(User curUser, List<Department> allDepartmentList);
 
     HttpRespMsg exportCustomDataSum(String startDate, String endDate, HttpServletRequest request);
+
+    List<Integer> getBranchDepartment(Integer departmentId, List<Department> departmentList);
+
+    String getSupDepartment(Department department,List<Department> departmentList);
+
+    String getWxDepartment(Department department,List<Department> departmentList);
+
+    String exportWxDepartment(Department department,List<Department> departmentList);
 }

+ 58 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/DepartmentServiceImpl.java

@@ -1433,7 +1433,7 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
         });
     }
 
-    private List<Integer> getBranchDepartment(Integer departmentId, List<Department> departmentList) {
+    public List<Integer> getBranchDepartment(Integer departmentId, List<Department> departmentList) {
         List<Integer> list = new ArrayList<>();
         list.add(departmentId);
         //搜到子部门进行添加
@@ -1465,4 +1465,61 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
 //        }
 //        return list;
 //    }
+
+    //递归获取所有上级部门字符串,格式:"上级部门/上级部门/部门"
+    public String getSupDepartment(Department department,List<Department> departmentList) {
+        String depHierarchy = department.getDepartmentName();
+        //搜到父部门进行添加
+        if (department.getSuperiorId()==null) {
+            return depHierarchy;
+        } else {
+            Department supDept = null;
+            for (Department dept : departmentList) {
+                if (department.getSuperiorId().equals(dept.getDepartmentId())){
+                    supDept = dept;
+                    break;
+                }
+            }
+            return getSupDepartment(supDept,departmentList) + "/" + depHierarchy;
+        }
+    }
+
+    //用于报表展示:递归获取企业微信所有上级部门字符串,格式:"上级部门/上级部门/部门"
+    public String getWxDepartment(Department department,List<Department> departmentList) {
+        String depHierarchy = department.getCorpwxDeptid()+"";
+        //搜到父部门进行添加
+        if (department.getCorpwxDeptpid()==null || department.getCorpwxDeptpid()==1) {
+            return depHierarchy;
+        }else{
+            Department supDept = null;
+            for (Department dept : departmentList) {
+                if (department.getCorpwxDeptpid().equals(dept.getCorpwxDeptid())){
+                    supDept = dept;
+                    break;
+                }
+            }
+            return getWxDepartment(supDept,departmentList) + "/" + depHierarchy;
+        }
+    }
+
+    //用于导出:递归获取企业微信所有上级部门字符串,格式:"上级部门/上级部门/部门"
+    public String exportWxDepartment(Department department,List<Department> departmentList) {
+        if(department.getCorpwxDeptid() == null){
+            return "";
+        }
+        String depHierarchy = "$departmentName="+department.getCorpwxDeptid()+"$";
+        //搜到父部门进行添加
+        if (department.getCorpwxDeptpid()==null || department.getCorpwxDeptpid()==1) {
+            return depHierarchy;
+        }else{
+            Department supDept = null;
+            for (Department dept : departmentList) {
+                if (department.getCorpwxDeptpid().equals(dept.getCorpwxDeptid())){
+                    supDept = dept;
+                    break;
+                }
+            }
+            return exportWxDepartment(supDept,departmentList) + "/" + depHierarchy;
+        }
+    }
 }

+ 16 - 6
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ReportServiceImpl.java

@@ -3950,21 +3950,24 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
             int rowNum = 1;
             List<HashMap<String, Object>> allReportByDate = null;
             List<SysRichFunction> functionList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), "查看全公司工时");
+            //获取部门的所有子部门
+            List<Department> departments = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id",companyId));
+            List<Integer> branchDepartment = departmentService.getBranchDepartment(departmentId,departments);
             if (functionList.size() == 0) {
                 //检查是否是部门负责人
                 List<Integer> allVisibleDeptIdList = getAllVisibleDeptIdList(user, null);
                 if (allVisibleDeptIdList.size() > 0) {
-                    allReportByDate = reportMapper.getDeptMembReportByDate(startDate, null, allVisibleDeptIdList, endDate, projectId,stateKey,departmentId);
+                    allReportByDate = reportMapper.getDeptMembReportByDate(startDate, null, allVisibleDeptIdList, endDate, projectId,stateKey,branchDepartment);
                 }
 
                 List<HashMap<String, Object>> reportsFromProjects = null;
                 //检查是否是项目负责人
                 int cnt = projectMapper.selectCount(new QueryWrapper<Project>().eq("incharger_id", user.getId()));
                 if (cnt > 0) {
-                    reportsFromProjects = reportMapper.getProjectMembReportByDate(startDate, null, user.getId(), endDate, projectId,stateKey,departmentId);
+                    reportsFromProjects = reportMapper.getProjectMembReportByDate(startDate, null, user.getId(), endDate, projectId,stateKey,branchDepartment);
                 } else {
                     //普通员工只能看自己的
-                    reportsFromProjects = reportMapper.getAllReportByDate(startDate, null, user.getId(), endDate, projectId,stateKey,departmentId);
+                    reportsFromProjects = reportMapper.getAllReportByDate(startDate, null, user.getId(), endDate, projectId,stateKey,branchDepartment);
                 }
                 if (allReportByDate == null) {
                     allReportByDate = reportsFromProjects;
@@ -3984,7 +3987,7 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
 //            }
             else {
                 //看公司所有人的
-                allReportByDate = reportMapper.getAllReportByDate(startDate, user.getCompanyId(), null, endDate, projectId,stateKey,departmentId);
+                allReportByDate = reportMapper.getAllReportByDate(startDate, user.getCompanyId(), null, endDate, projectId,stateKey,branchDepartment);
             }
             //获取企业微信考勤数据
             List<UserCorpwxTime> userCorpwxTimeList = userCorpwxTimeMapper.selectList(new QueryWrapper<UserCorpwxTime>().eq("company_id", user.getCompanyId()).between("create_date", startDate, endDate));
@@ -4082,12 +4085,19 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
                     }
                     row.createCell(3+i).setCellValue(value);
                 }
+                Department dept = null;
+                for (Department department : departments) {
+                    if (department.getDepartmentId().toString().equals(map.get("departmentId").toString())){
+                        dept = department;
+                        break;
+                    }
+                }
                 if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
                     row.createCell(2).setCellValue("$userName="+(map.get("corpwxUserId")==null?"":map.get("corpwxUserId"))+"$");
-                    row.createCell(3+userCustomList.size()).setCellValue("$departmentName="+(map.get("corpwxDeptId")==null?"":map.get("corpwxDeptId"))+"$");
+                    row.createCell(3+userCustomList.size()).setCellValue(departmentService.exportWxDepartment(dept,departments));
                 }else {
                     row.createCell(2).setCellValue((String) map.get("name"));
-                    row.createCell(3+userCustomList.size()).setCellValue((String) map.get("departmentName"));
+                    row.createCell(3+userCustomList.size()).setCellValue(departmentService.getSupDepartment(dept,departments));
                 }
                 row.createCell(4+userCustomList.size()).setCellValue((String) map.get("projectCode"));
                 row.createCell(5+userCustomList.size()).setCellValue((String) map.get("project"));

+ 17 - 8
fhKeeper/formulahousekeeper/management-platform/src/main/resources/mapper/ReportMapper.xml

@@ -97,8 +97,11 @@
         <if test="userId != null">
             AND a.creator_id = #{userId}
         </if>
-        <if test="departmentId != null">
-            AND department.department_id = #{departmentId}
+        <if test="branchDepartment != null">
+            AND department.department_id in
+            <foreach collection="branchDepartment" item="deptId" separator="," close=")" open="(" index="index">
+                #{deptId}
+            </foreach>
         </if>
 
         ORDER BY a.creator_id, a.create_date desc
@@ -163,7 +166,7 @@
         a.custom_data as customData
         ,c.plate1 as plate1,c.plate2 as plate2,c.plate3 as plate3,c.plate4 as plate4,c.plate5 as plate5
         ,u.name as projectAuditorName, a.project_auditor_id as projectAuditorId, department.department_name as
-        departmentName, a.overtime_hours as overtimeHours, a.custom_text as customText, a.project_audit_time as
+        departmentName,department.department_id as departmentId, a.overtime_hours as overtimeHours, a.custom_text as customText, a.project_audit_time as
         projectAuditTime,project_main.name as projectMainName
         FROM report AS a
         JOIN project AS b ON a.project_id=b.id
@@ -199,8 +202,11 @@
         <if test="leaderId != null">
             AND (b.incharger_id = #{leaderId} or a.creator_id=#{leaderId})
         </if>
-        <if test="departmentId != null">
-            AND department.department_id = #{departmentId}
+        <if test="branchDepartment != null">
+            AND department.department_id in
+            <foreach collection="branchDepartment" item="deptId" separator="," close=")" open="(" index="index">
+                #{deptId}
+            </foreach>
         </if>
         ORDER BY a.creator_id, a.create_date desc
     </select>
@@ -212,7 +218,7 @@
         a.department_audit_state as departmentAuditState,a.stage, a.pic_str as picStr, multi_worktime as multiWorktime,a.is_dept_audit as isDeptAudit,a.group_audit_state as groupAuditState,task_group.incharger_id as inchargerId,a.project_audit_state as projectAuditState,a.audit_dept_managerid as deptAuditorName
         ,c.plate1 as plate1,c.plate2 as plate2,c.plate3 as plate3,c.plate4 as plate4,c.plate5 as plate5
         , reject_reason as rejectReason, reject_username as rejectUsername, reject_userid as rejectUserid, degree_id as degree_id,report_extra_degree.name as degreeName,task_group.name as groupName,a.group_id as groupId, a.custom_data as customData
-        ,u.name as projectAuditorName, a.project_auditor_id as projectAuditorId, department.department_name as departmentName, a.overtime_hours as overtimeHours, a.custom_text as customText, a.project_audit_time as projectAuditTime,project_main.name as projectMainName
+        ,u.name as projectAuditorName, a.project_auditor_id as projectAuditorId, department.department_name as departmentName,department.department_id as departmentId, a.overtime_hours as overtimeHours, a.custom_text as customText, a.project_audit_time as projectAuditTime,project_main.name as projectMainName
         FROM report AS a
         JOIN project AS b ON a.project_id=b.id
         LEFT JOIN user AS c ON a.creator_id=c.id
@@ -245,8 +251,11 @@
         <if test="projectId != null">
             AND a.project_id = #{projectId}
         </if>
-        <if test="departmentId != null">
-            AND department.department_id = #{departmentId}
+        <if test="branchDepartment != null">
+            AND department.department_id in
+            <foreach collection="branchDepartment" item="deptId" separator="," close=")" open="(" index="index">
+                #{deptId}
+            </foreach>
         </if>
         <if test="deptIds != null">
             AND c.department_id in