Jelajahi Sumber

修改任务分组导出后缀

yurk 2 tahun lalu
induk
melakukan
bbf4a2a75f

+ 195 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ProjectServiceImpl.java

@@ -9035,6 +9035,201 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
         return msg;
     }
 
+    /**
+     * 按维度导出工时和成本
+     * @param startDate
+     * @param endDate
+     * @param projectId
+     * @param request
+     * @return
+     */
+    @Override
+    public HttpRespMsg exportDegreeCost(String startDate, String endDate, Integer projectId, Integer deptId, HttpServletRequest request) {
+        HttpRespMsg httpRespMsg = new HttpRespMsg();
+        try {
+            User targetUser = userMapper.selectById(request.getHeader("Token"));
+            Integer companyId =targetUser.getCompanyId();
+            WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", companyId));
+            Map<String, Object> resultMap = new HashMap<>();
+            //当前用户管理部门
+            List<Integer> deptIds=null;
+            List<Department> departmentList = departmentMapper.selectList(new QueryWrapper<Department>().eq("manager_id", targetUser.getId()).eq("company_id", companyId));
+            List<Department> allDepartmentList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", targetUser.getCompanyId()));
+            List<DepartmentOtherManager> departmentOtherManagerList = departmentOtherManagerMapper.selectList(new QueryWrapper<DepartmentOtherManager>().eq("other_manager_id", targetUser.getId()));
+            List<SysRichFunction> functionAllList = sysFunctionMapper.getRoleFunctions(targetUser.getRoleId(), "查看全公司");
+            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){
+                filterDeptIds= getBranchDepartment(deptId, allDepartmentList);
+            }
+            //若没有查看全部部门的权限
+            if(functionAllList.size()==0){
+                deptIds=new ArrayList<>();
+                deptIds.add(-1);
+                //获取负责的部门的相关的项目,对于这些项目是有查看全部参与人的权限的
+                List<Integer> allMyManagedDeptIds = new ArrayList<>();
+                List<Integer> collect = departmentList.stream().map(dm -> dm.getDepartmentId()).distinct().collect(Collectors.toList());
+                List<Integer> otherCollect = departmentOtherManagerList.stream().map(dom -> dom.getDepartmentId()).distinct().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){
+                        deptIds.addAll(allMyManagedDeptIds);
+                    }
+                }
+                //没有查看全公司的权限 只能先判断当前部门/父级别是否在负责部门才能获取数据
+                if(deptId!=null){
+                    Optional<Department> first = allDepartmentList.stream().filter(ad -> ad.getDepartmentId().equals(deptId)).findFirst();
+                    if(first.isPresent()){
+                        if(deptIds.contains(first.get().getSuperiorId())||deptIds.contains(deptId)){
+                            filterDeptIds= getBranchDepartment(deptId,allDepartmentList);
+                        }else {
+                            filterDeptIds=new ArrayList<>();
+                            filterDeptIds.add(-1);
+                        }
+                    }
+                }
+            }
+            //deptIds:管理的部门;filterDeptIds:筛选的部门;deptRelatedProjectIds:负责部门相关联的项目
+            List<Map<String, Object>> list = projectMapper.getExportDegreeCost(companyId, startDate, endDate,projectId,deptIds,filterDeptIds,deptRelatedProjectIds);
+            TimeType timeType = timeTypeMapper.selectById(companyId);
+            List<List<String>> allList=null ;
+            List<String> sumRow = null;
+            List<String> headList = new ArrayList<String>();
+            //headList.add("项目编号");
+            headList.add(MessageUtils.message("entry.projectId"));
+            //headList.add("项目名称");
+            headList.add(MessageUtils.message("entry.projectName"));
+            //headList.add("项目分类");
+            headList.add(MessageUtils.message("entry.projectType"));
+            //headList.add("人员");
+            headList.add(MessageUtils.message("entry.personnel"));
+            //headList.add("部门");
+//            headList.add(MessageUtils.message("excel.department"));
+            headList.add(timeType.getCustomDegreeName());
+            if(functionTimeList.size()>0){
+                //headList.add("工时(h)");
+                headList.add(MessageUtils.message("entry.workHours")+"(h)");
+            }
+            if(functionCostList.size()>0){
+                //headList.add("成本(元)");
+                headList.add(MessageUtils.message("entry.cost")+"(元)");
+            }
+
+            allList=new ArrayList<>();
+            allList.add(headList);
+            BigDecimal totalMoneyCost = BigDecimal.valueOf(0);
+            double totalCostTime = 0;
+            for (Map<String, Object> map : list) {
+                if (!map.containsKey("cost")) {
+                    map.put("cost", 0);
+                }
+                if (!map.containsKey("costMoney")) {
+                    map.put("costMoney", 0);
+                } else {
+                    totalMoneyCost = totalMoneyCost.add((BigDecimal)map.get("costMoney"));
+                }
+                totalCostTime += (Double)map.get("cost");
+                List<String> rowData = new ArrayList<String>();
+                rowData.add(map.get("projectCode")==null?"":map.get("projectCode").toString());
+                rowData.add(map.get("projectName")==null?"":map.get("projectName").toString());
+                rowData.add(map.get("categoryName")==null?"":map.get("categoryName").toString());
+                rowData.add("");
+                rowData.add("");
+//                rowData.add("");
+
+                if(functionTimeList.size()>0){
+                    rowData.add(((Double)map.get("cost")).toString());
+                }
+                if (functionCostList.size()>0){
+                    rowData.add(((BigDecimal)map.get("costMoney")).toString());
+                }
+                allList.add(rowData);
+
+                //统计每个项目中的人员时间成本投入
+                int curProjectId = (Integer)map.get("id");
+                //判断是否是当前项目的所属部门的主要或者其他负责人
+                List<Integer> finalDeptIds = null;
+                if (deptRelatedProjectIds.contains(curProjectId)) {
+                    //有权限看该项目的全部参与人员,不需要按照部门过滤了
+                } else {
+                    finalDeptIds = deptIds;
+                }
+                List<Map<String, Object>> membList = projectMapper.getDegreeDetailCost(companyId,startDate, endDate,projectId,curProjectId,finalDeptIds,filterDeptIds,deptIds);
+                map.put("membList", membList);
+                for (Map<String, Object> membMap : membList) {
+                    List<String> membRowData = new ArrayList<String>();
+                    membRowData.add("");
+                    membRowData.add("");
+                    membRowData.add("");
+                    if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
+                        membRowData.add(("$userName="+membMap.get("corpwxUserId")+"$"));
+//                        if(membMap.get("departmentName").equals("未分配")){
+//                            membRowData.add("未分配");
+//                        }else {
+//                            membRowData.add((String)("$departmentName="+membMap.get("corpwxDeptId")+"$"));
+//                        }
+                    }else {
+                        membRowData.add((String)membMap.get("name"));
+//                        membRowData.add((String)membMap.get("departmentName"));
+                    }
+                    membRowData.add(membMap.get("degreeName")==null?"未分配":(String)membMap.get("degreeName"));
+                    if(functionTimeList.size()>0){
+                        membRowData.add(((Double)membMap.get("cost")).toString());
+                    }
+                    if (functionCostList.size()>0){
+                        membRowData.add(((BigDecimal)membMap.get("costMoney")).toString());
+                    }
+                    allList.add(membRowData);
+                }
+            }
+            //合计
+            sumRow=new ArrayList<>();
+            //sumRow.add("合计");
+            sumRow.add(MessageUtils.message("entry.total"));
+            //sumRow.add("");
+            sumRow.add("");
+            sumRow.add("");
+            sumRow.add("");
+            sumRow.add("");
+            if(functionTimeList.size()>0){
+                sumRow.add(""+new BigDecimal(totalCostTime).setScale(1, BigDecimal.ROUND_HALF_UP));
+            }
+            if (functionCostList.size()>0){
+                sumRow.add(totalMoneyCost.toString());
+            }
+            allList.add(sumRow);
+            //生成excel文件导出
+            //String fileName = "维度成本工时统计_"+System.currentTimeMillis();
+            String fileName = timeType.getCustomDegreeName() + MessageUtils.message("fileName.degreeCost")+System.currentTimeMillis();
+            return excelExportService.exportGeneralExcelByTitleAndList(wxCorpInfo,fileName , allList, path);
+        } catch (NullPointerException e) {
+            e.printStackTrace();
+            //httpRespMsg.setError("验证失败");
+            httpRespMsg.setError(MessageUtils.message("access.verificationError"));
+            return httpRespMsg;
+        } catch (Exception exception) {
+            exception.printStackTrace();
+            httpRespMsg.setError(exception.getMessage());
+        }
+        return httpRespMsg;
+    }
+
     private List<GanttDataItem> getUserGanttDataItemList(GanttDataItem userGantt, List<GanttDataItem> itemList) {
         if(itemList==null){
             itemList=new ArrayList<>();