Jelajahi Sumber

部门负责人,查看自己负责的部门的所属项目时,可以看到全部项目参与人员的工时数据

seyason 2 tahun lalu
induk
melakukan
639662a5f5

+ 2 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/mapper/ProjectMapper.java

@@ -25,7 +25,8 @@ public interface ProjectMapper extends BaseMapper<Project> {
     List<Map<String, Object>> getOnlyJoinProjects(@Param("userId") String userId, @Param("companyId") Integer companyId);
 
     List<Map<String, Object>> getTimeCost(@Param("companyId") Integer companyId, @Param("startDate") String startDate, @Param("endDate") String endDate,
-        @Param("projectId") Integer projectId, @Param("userId") String userId,@Param("deptIds")List<Integer> deptIds,@Param("filterDeptIds")List<Integer> filterDeptIds);
+                                          @Param("projectId") Integer projectId, @Param("userId") String userId,
+                                          @Param("deptIds")List<Integer> deptIds,@Param("filterDeptIds")List<Integer> filterDeptIds, @Param("deptRelatedProjectIds") List<Integer> deptRelatedProjectIds);
 
     List<Map<String, Object>> getCustomDataSum(@Param("companyId") Integer companyId, @Param("startDate") String startDate, @Param("endDate") String endDate,
                                           @Param("projectId") Integer projectId, @Param("userId") String userId);

+ 5 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/FinanceServiceImpl.java

@@ -11,6 +11,7 @@ import com.management.platform.util.ExcelUtil;
 import com.management.platform.util.HttpRespMsg;
 import com.management.platform.util.MessageUtils;
 import com.management.platform.util.UserNotFoundException;
+import com.taobao.api.internal.util.StringUtils;
 import org.apache.commons.io.FileUtils;
 import org.apache.log4j.LogManager;
 import org.apache.log4j.Logger;
@@ -232,6 +233,10 @@ public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> impl
                 finance.setName(name);
                 if (includeJobNumber) {
                     finance.setJobNumber(jobNumberCell.getStringCellValue());
+                    if (StringUtils.isEmpty(finance.getJobNumber())) {
+                        msg.setError("工号不能为空");
+                        return msg;
+                    }
                 }
 
                 Optional<User> first = userList.stream().filter(u -> includeJobNumber?

+ 42 - 20
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ProjectServiceImpl.java

@@ -1029,24 +1029,35 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
             List<SysRichFunction> functionDpartList = sysFunctionMapper.getRoleFunctions(targetUser.getRoleId(), "查看负责部门");
             List<SysRichFunction> functionTimeList = sysFunctionMapper.getRoleFunctions(targetUser.getRoleId(), "查看工时统计");
             List<SysRichFunction> functionCostList = sysFunctionMapper.getRoleFunctions(targetUser.getRoleId(), "查看成本统计");
+            List<Integer> deptRelatedProjectIds = new ArrayList<>();
             //判断查看权限
             if(functionAllList.size()==0){
                 deptIds=new ArrayList<>();
                 deptIds.add(-1);
+
+                //获取负责的部门的相关的项目,对于这些项目是有查看全部参与人的权限的
+                List<Integer> allMyManagedDeptIds = new ArrayList<>();
+                List<Integer> collect = departmentList.stream().distinct().map(dm -> dm.getDepartmentId()).collect(Collectors.toList());
+                List<Integer> otherCollect = departmentOtherManagerList.stream().distinct().map(dom -> dom.getDepartmentId()).collect(Collectors.toList());
+                collect.addAll(otherCollect);
+                for (Integer integer : collect) {
+                    List<Integer> branchDepartment = getBranchDepartment(integer, allDepartmentList);
+                    allMyManagedDeptIds.addAll(branchDepartment);
+                }
+                if (allMyManagedDeptIds.size() > 0) {
+                    List<Project> projectList = projectMapper.selectList(new QueryWrapper<Project>().select("id").in("dept_id", allMyManagedDeptIds));
+                    deptRelatedProjectIds = projectList.stream().map(Project::getId).collect(Collectors.toList());
+                }
+
                 if(functionDpartList.size()>0){
                     if(functionTimeList.size()>0||functionCostList.size()>0){
-                        List<Integer> collect = departmentList.stream().distinct().map(dm -> dm.getDepartmentId()).collect(Collectors.toList());
-                        List<Integer> otherCollect = departmentOtherManagerList.stream().distinct().map(dom -> dom.getDepartmentId()).collect(Collectors.toList());
-                        collect.addAll(otherCollect);
-                        for (Integer integer : collect) {
-                            List<Integer> branchDepartment = getBranchDepartment(integer, allDepartmentList);
-                            deptIds.addAll(branchDepartment);
-                        }
+                        deptIds.addAll(allMyManagedDeptIds);
                     }
                 }
+
             }
 
-            List<Map<String, Object>> list = projectMapper.getTimeCost(companyId, startDate, endDate, null, userId,deptIds,null);
+            List<Map<String, Object>> list = projectMapper.getTimeCost(companyId, startDate, endDate, null, userId,deptIds,null, deptRelatedProjectIds);
             BigDecimal totalMoneyCost = BigDecimal.valueOf(0);
             for (Map<String, Object> map : list) {
                 if (!map.containsKey("cost")) {
@@ -1100,6 +1111,8 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
             List<SysRichFunction> functionDpartList = sysFunctionMapper.getRoleFunctions(targetUser.getRoleId(), "查看负责部门");
             List<SysRichFunction> functionTimeList = sysFunctionMapper.getRoleFunctions(targetUser.getRoleId(), "查看工时统计");
             List<SysRichFunction> functionCostList = sysFunctionMapper.getRoleFunctions(targetUser.getRoleId(), "查看成本统计");
+            List<Integer> deptRelatedProjectIds = new ArrayList<>();
+
             //判断查看权限
             List<Integer> filterDeptIds=null;
             if(deptId!=null){
@@ -1108,16 +1121,18 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
             if(functionAllList.size()==0){
                 deptIds=new ArrayList<>();
                 deptIds.add(-1);
-                if(functionDpartList.size()>0){
-                    if(functionTimeList.size()>0||functionCostList.size()>0){
-                        List<Integer> collect = departmentList.stream().map(dp -> dp.getDepartmentId()).distinct().collect(Collectors.toList());
-                        List<Integer> otherCollect = departmentOtherManagerList.stream().distinct().map(dom -> dom.getDepartmentId()).collect(Collectors.toList());
-                        collect.addAll(otherCollect);
-                        for (Integer integer : collect) {
-                            List<Integer> branchDepartment = getBranchDepartment(integer, allDepartmentList);
-                            deptIds.addAll(branchDepartment);
-                        }
-                    }
+                //获取负责的部门的相关的项目,对于这些项目是有查看全部参与人的权限的
+                List<Integer> allMyManagedDeptIds = new ArrayList<>();
+                List<Integer> collect = departmentList.stream().distinct().map(dm -> dm.getDepartmentId()).collect(Collectors.toList());
+                List<Integer> otherCollect = departmentOtherManagerList.stream().distinct().map(dom -> dom.getDepartmentId()).collect(Collectors.toList());
+                collect.addAll(otherCollect);
+                for (Integer integer : collect) {
+                    List<Integer> branchDepartment = getBranchDepartment(integer, allDepartmentList);
+                    allMyManagedDeptIds.addAll(branchDepartment);
+                }
+                if (allMyManagedDeptIds.size() > 0) {
+                    List<Project> projectList = projectMapper.selectList(new QueryWrapper<Project>().select("id").in("dept_id", allMyManagedDeptIds));
+                    deptRelatedProjectIds = projectList.stream().map(Project::getId).collect(Collectors.toList());
                 }
                 //没有查看全公司的权限 只能先判断当前部门/父级别是否在负责部门才能获取数据
                 if(deptId!=null){
@@ -1133,7 +1148,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                 }
             }
             System.out.println(filterDeptIds);
-            List<Map<String, Object>> list = projectMapper.getTimeCost(companyId, startDate, endDate, projectId, userId,deptIds,filterDeptIds);
+            List<Map<String, Object>> list = projectMapper.getTimeCost(companyId, startDate, endDate, projectId, userId,deptIds,filterDeptIds,deptRelatedProjectIds);
             BigDecimal totalMoneyCost = BigDecimal.valueOf(0);
             List<List<String>> allList=null ;
             List<String> sumRow = null;
@@ -1180,7 +1195,14 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                     }
                     //统计每个项目中的人员时间成本投入
                     int curProjectId = (Integer)map.get("id");
-                    List<Map<String, Object>> membList = projectMapper.getProjectCost(companyId,startDate, endDate, curProjectId,stateKey, userId,deptIds,filterDeptIds);
+                    //判断是否是当前项目的所属部门的主要或者其他负责人
+                    List<Integer> finalDeptIds = null;
+                    if (deptRelatedProjectIds.contains(curProjectId)) {
+                        //有权限看该项目的全部参与人员,不需要按照部门过滤了
+                    } else {
+                        finalDeptIds = deptIds;
+                    }
+                    List<Map<String, Object>> membList = projectMapper.getProjectCost(companyId,startDate, endDate, curProjectId,stateKey, userId,finalDeptIds,filterDeptIds);
                     map.put("membList", membList);
                     for (Map<String, Object> membMap : membList) {
                         double pTotalTime = 0;

+ 8 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/resources/mapper/ProjectMapper.xml

@@ -145,10 +145,17 @@
             </when>
             <otherwise>
                 <if test="deptIds!=null and deptIds.size()>0">
-                    and b.dept_id in
+                    and (b.dept_id in
                     <foreach collection="deptIds" open="(" item="item" separator="," close=")">
                         #{item}
                     </foreach>
+                    <if test="deptRelatedProjectIds.size() > 0">
+                        or a.id in
+                        <foreach collection="deptRelatedProjectIds" open="(" item="pid" separator="," close=")">
+                            #{pid}
+                        </foreach>
+                    </if>
+                    )
                 </if>
             </otherwise>
         </choose>