cs 2 лет назад
Родитель
Сommit
40e69eeb14

+ 3 - 3
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/ProjectController.java

@@ -1223,13 +1223,13 @@ public class ProjectController {
     //FTE报表
     @RequestMapping("/getFTEData")
     public HttpRespMsg getFTEData(@RequestParam Integer pageIndex, @RequestParam Integer pageSize,String month,String area,HttpServletRequest request){
-        return projectService.getFTEData(pageIndex,pageSize,month,request);
+        return projectService.getFTEData(pageIndex,pageSize,month,area,request);
     }
 
     //导出FTE报表
     @RequestMapping("/exportFTEData")
-    public HttpRespMsg exportFTEData(String month,HttpServletRequest request){
-        return projectService.exportFTEData(month,request);
+    public HttpRespMsg exportFTEData(String month,String area,HttpServletRequest request){
+        return projectService.exportFTEData(month,area,request);
     }
 }
 

+ 12 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/UserController.java

@@ -1,6 +1,7 @@
 package com.management.platform.controller;
 
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.management.platform.entity.FeishuInfo;
 import com.management.platform.entity.User;
 import com.management.platform.service.FeishuInfoService;
@@ -266,5 +267,16 @@ public class UserController {
         return httpRespMsg;
     }
 
+    /**
+     * 返回用户自定义的地区信息
+     * @return
+     */
+    @RequestMapping("/areaData")
+    public HttpRespMsg areaData(HttpServletRequest request){
+        HttpRespMsg httpRespMsg=new HttpRespMsg();
+        String token = request.getHeader("token");
+        return userService.areaData(token);
+    }
+
 }
 

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

@@ -153,4 +153,6 @@ public interface ProjectMapper extends BaseMapper<Project> {
     List<Map<String, Object>> getDegreeDetailCost(Integer companyId, String startDate, String endDate, Integer projectId,int curProjectId, List<Integer> finalDeptIds, List<Integer> filterDeptIds, List<Integer> deptIds);
 
     List<Project> selectNearProject(String userId);
+
+    List<Map<String, Object>> getFTEData(Integer companyId, String startDate, String endDate, Integer start, Integer size, String area, List<Integer> branchDepartment, List<Integer> deptIds);
 }

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

@@ -239,7 +239,7 @@ public interface ProjectService extends IService<Project> {
 
     HttpRespMsg nearProject(HttpServletRequest request);
 
-    HttpRespMsg getFTEData(Integer pageIndex, Integer pageSize, String month, HttpServletRequest request);
+    HttpRespMsg getFTEData(Integer pageIndex, Integer pageSize, String month, String area, HttpServletRequest request);
 
-    HttpRespMsg exportFTEData(String month, HttpServletRequest request);
+    HttpRespMsg exportFTEData(String month, String area, HttpServletRequest request);
 }

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

@@ -83,4 +83,6 @@ public interface UserService extends IService<User> {
     HttpRespMsg mobSkipGuidance(HttpServletRequest request);
 
     HttpRespMsg moveUserData(String sourceId, String targetId, HttpServletRequest request);
+
+    HttpRespMsg areaData(String token);
 }

+ 269 - 43
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ProjectServiceImpl.java

@@ -9692,62 +9692,288 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
 
     //获取FTE报表数据
     @Override
-    public HttpRespMsg getFTEData(Integer pageIndex, Integer pageSize, String month, HttpServletRequest request) {
+    public HttpRespMsg getFTEData(Integer pageIndex, Integer pageSize, String month, String area, HttpServletRequest request) {
+        HttpRespMsg httpRespMsg =new HttpRespMsg();
+        User targetUser = userMapper.selectById(request.getHeader("token"));
+        List<SysRichFunction> functionAllList = sysFunctionMapper.getRoleFunctions(targetUser.getRoleId(), "全部部门FTE报表");
+        List<SysRichFunction> functionDeptList = sysFunctionMapper.getRoleFunctions(targetUser.getRoleId(), "负责部门FTE报表");
+        List<Integer> deptIds=null;
+        List<Department> allDepartmentList=departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id",targetUser.getCompanyId()));
+        List<Department> userDepartmentList = departmentMapper.selectList(new QueryWrapper<Department>().eq("manager_id", targetUser.getId()).eq("company_id",targetUser.getCompanyId()));
+        List<DepartmentOtherManager> departmentOtherManagerList = departmentOtherManagerMapper.selectList(new QueryWrapper<DepartmentOtherManager>().eq("other_manager_id", targetUser.getId()));
+        //判断查看权限
+        if(functionAllList.size()==0){
+            deptIds=new ArrayList<>();
+            deptIds.add(-1);
+            if(functionDeptList.size()>0){
+                List<Integer> collect = userDepartmentList.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);
+                //将该用户管理的所有部门以及部门的子部门id添加到deptIds集合中
+                for (Integer integer : collect) {
+                    List<Integer> branchDepartment = getBranchDepartment(integer, allDepartmentList);
+                    deptIds.addAll(branchDepartment);
+                }
+            }
+        }
+        long total  = 0;
+        List<Map<String,Object>> resultList = null;
+        List<Integer> branchDepartment =null;
+        //若用户传入departmentId参数,则查询该部门所有子部门,添加到branchDepartment集合中
+//        if(departmentId!=null){
+//            branchDepartment = getBranchDepartment(departmentId, allDepartmentList);
+//        }
+        String startDate = null;
+        String endDate = null;
+        LocalDate time = LocalDate.parse(month, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+        startDate = time.with(TemporalAdjusters.firstDayOfMonth()).toString();
+        endDate = time.with(TemporalAdjusters.lastDayOfMonth()).toString();
+        int days = WorkDayCalculateUtils.getWorkDaysListInRange(startDate, endDate, 0).size();
+        TimeType allDay = timeTypeMapper.selectOne(new QueryWrapper<TimeType>().eq("company_id", targetUser.getCompanyId()));
+        Float monthTime = days * allDay.getAllday();
 
-        return null;
+        if(pageIndex!=null&&pageSize!=null){
+            Integer size=pageSize;
+            Integer start=(pageIndex-1)*size;
+            resultList=projectMapper.getFTEData(targetUser.getCompanyId(),startDate,endDate,start,size,area,branchDepartment,deptIds);
+            total=projectMapper.getFTEData(targetUser.getCompanyId(),startDate,endDate,null,null,area,branchDepartment,deptIds).size();
+        }else{
+            resultList=projectMapper.getFTEData(targetUser.getCompanyId(),startDate,endDate,null,null,area,branchDepartment,deptIds);
+        }
+        for (Map<String, Object> map : resultList) {
+            map.put("FTE",Float.parseFloat(map.get("workTime").toString())/monthTime);
+        }
+        WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", targetUser.getCompanyId()));
+        if (wxCorpInfo != null && wxCorpInfo.getSaasSyncContact().equals(1)){
+            for (Map<String, Object> map : resultList) {
+                map.put("userName",map.get("wxUserId"));
+                map.put("corpwx_userid","$userName=" + map.get("wxUserId") + "$");
+            }
+        }
+        HashMap<String, Object> map = new HashMap<>();
+        map.put("resultList",resultList);
+        map.put("total",total);
+        map.put("monthTime",monthTime);
+        httpRespMsg.data = map;
+        return httpRespMsg;
     }
 
     //导出FTE报表数据
     @Override
-    public HttpRespMsg exportFTEData(String month, HttpServletRequest request) {
-        HttpRespMsg msg=new HttpRespMsg();
-//        User user = userMapper.selectById(request.getHeader("token"));
-//        Integer companyId = userMapper.selectById(request.getHeader("token")).getCompanyId();
-//        List<Project> projectList = projectMapper.selectList(new QueryWrapper<Project>().eq("company_id", user.getCompanyId()));
-//        List<SysRichFunction> functionAllList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), "全部子项目工时成本");
-//        List<SysRichFunction> functionInchargeList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), "负责项目子项目工时成本");
-//        //判断查看权限
-//        List<Integer> inchagerIds=null;
-//        if(functionAllList.size()==0){
-//            inchagerIds=new ArrayList<>();
-//            if(functionInchargeList.size()>0){
-//                List<Project> list = projectList.stream().filter(pl -> (pl.getInchargerId()==null?0:pl.getInchargerId()).equals(user.getId())).collect(Collectors.toList());
-//                if(list!=null){
-//                    List<Integer> collect = list.stream().map(li -> li.getId()).collect(Collectors.toList());
-//                    inchagerIds.addAll(collect);
-//                }
-//            }else {
-//                inchagerIds.add(-1);
-//            }
-//        }
-
+    public HttpRespMsg exportFTEData(String month, String area,HttpServletRequest request) {
+        HttpRespMsg httpRespMsg = new HttpRespMsg();
+        User user = userMapper.selectById(request.getHeader("token"));
+        WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", user.getCompanyId()));
+        HttpRespMsg fteData = getFTEData(null, null, month, area, request);
+        Map<String, Object> data = (Map<String, Object>) (Map<String, Object>) fteData.data;
+        List<Map<String, Object>> resultList = (List<Map<String, Object>>) data.get("resultList");
+        Float monthTime = (Float) data.get("monthTime");
         List<List<String>> dataList=new ArrayList<>();
         List<String> titleList=new ArrayList<>();
-        List<List<Integer>> mergeCellList = new ArrayList<>();
+        List<String> subtitle=new ArrayList<>();
+        Integer no = 0;
         titleList.add("地区");
         titleList.add("序号");
         titleList.add("CRC姓名");
         titleList.add("项目号");
         titleList.add("项目名称");
-        titleList.add("子项目成本/元");
+        titleList.add("工时(H)");
+        titleList.add("FTE(工时/当月工时基数)");
+        titleList.add("非项目工时(H)(当月工时基数-项目工时合计工时数)");
         dataList.add(titleList);
-        ArrayList<Integer> cell = new ArrayList<>();
-        cell.add(0);
-        cell.add(2);
-        cell.add(0);
-        cell.add(0);
-        mergeCellList.add(cell);
-
-        ArrayList<Integer> cell1 = new ArrayList<>();
-        cell1.add(0);
-        cell1.add(2);
-        cell1.add(1);
-        cell1.add(1);
-
-        mergeCellList.add(cell1);
+        subtitle.add("");
+        subtitle.add("");
+        subtitle.add("");
+        subtitle.add("");
+        subtitle.add("");
+        subtitle.add("");
+        subtitle.add("当月工时:" + monthTime);
+        dataList.add(subtitle);
+        Float pTimeSum = 0.0F;
+        Float pFteSum = 0.0F;
+        Float aTimeSum = 0.0F;
+        Float aFteSum = 0.0F;
+        for (int i = 0; i < resultList.size(); i++) {
+            ArrayList<String> row = new ArrayList<>();
+            if (i == 0){
+                no += 1;
+                row.add(resultList.get(i).get("area")==null?"无":resultList.get(i).get("area").toString());
+                row.add(no + "");
+                if (wxCorpInfo != null && wxCorpInfo.getSaasSyncContact().equals(1)){
+                    row.add(resultList.get(i).get("corpwx_userid") + "");
+                }else {
+                    row.add(resultList.get(i).get("userName") + "");
+                }
+                row.add(resultList.get(i).get("projectCode") + "");
+                row.add(resultList.get(i).get("projectName") + "");
+
+                Float workTime = Float.valueOf(resultList.get(i).get("workTime").toString());
+                row.add(workTime + "");
+                pTimeSum += workTime;
+                aTimeSum += workTime;
+
+                Float FTE = Float.valueOf(resultList.get(i).get("workTime").toString()) / monthTime;
+                row.add(new BigDecimal(FTE).setScale(2, RoundingMode.HALF_UP) + "");
+                pFteSum += FTE;
+                aFteSum += FTE;
+
+                row.add("");
+
+                dataList.add(row);
+            }else if(resultList.get(i).get("area").equals(resultList.get(i - 1).get("area"))){
+                if (resultList.get(i).get("id").equals(resultList.get(i - 1).get("id"))){
+                    row.add("");
+                    row.add("");
+                    row.add("");
+                    row.add(resultList.get(i).get("projectCode") + "");
+                    row.add(resultList.get(i).get("projectName") + "");
+
+                    Float workTime = Float.valueOf(resultList.get(i).get("workTime").toString());
+                    row.add(workTime + "");
+                    pTimeSum += workTime;
+                    aTimeSum += workTime;
+
+                    Float FTE = Float.valueOf(resultList.get(i).get("workTime").toString()) / monthTime;
+                    row.add(new BigDecimal(FTE).setScale(2, RoundingMode.HALF_UP) + "");
+                    pFteSum += FTE;
+                    aFteSum += FTE;
+
+                    row.add("");
+
+                    dataList.add(row);
+                }else {
+                    ArrayList<String> sum = new ArrayList<>();
+                    sum.add("");
+                    sum.add("");
+                    sum.add("合计");
+                    sum.add("");
+                    sum.add("");
+                    sum.add(pTimeSum.toString());
+                    sum.add(new BigDecimal(pFteSum).setScale(2, RoundingMode.HALF_UP) + "");
+                    sum.add((monthTime - pTimeSum) + "");
+                    pTimeSum = 0.0F;
+                    pFteSum = 0.0F;
+                    dataList.add(sum);
+
+                    no += 1;
+                    row.add("");
+                    row.add(no + "");
+                    if (wxCorpInfo != null && wxCorpInfo.getSaasSyncContact().equals(1)){
+                        row.add(resultList.get(i).get("corpwx_userid") + "");
+                    }else {
+                        row.add(resultList.get(i).get("userName") + "");
+                    }
+                    row.add(resultList.get(i).get("projectCode") + "");
+                    row.add(resultList.get(i).get("projectName") + "");
+
+                    Float workTime = Float.valueOf(resultList.get(i).get("workTime").toString());
+                    row.add(workTime + "");
+                    pTimeSum += workTime;
+                    aTimeSum += workTime;
+
+                    Float FTE = Float.valueOf(resultList.get(i).get("workTime").toString()) / monthTime;
+                    row.add(new BigDecimal(FTE).setScale(2, RoundingMode.HALF_UP) + "");
+                    pFteSum += FTE;
+                    aFteSum += FTE;
+
+                    row.add("");
+
+                    dataList.add(row);
+                }
+
+            }else {
+                ArrayList<String> pSum = new ArrayList<>();
+                pSum.add("");
+                pSum.add("");
+                pSum.add("合计");
+                pSum.add("");
+                pSum.add("");
+                pSum.add(pTimeSum.toString());
+                pSum.add(new BigDecimal(pFteSum).setScale(2, RoundingMode.HALF_UP) + "");
+                pSum.add((monthTime - pTimeSum) + "");
+                pTimeSum = 0.0F;
+                pFteSum = 0.0F;
+
+                dataList.add(pSum);
+
+                ArrayList<String> sum = new ArrayList<>();
+                sum.add("");
+                sum.add("");
+                sum.add("地区合计");
+                sum.add("");
+                sum.add("");
+                sum.add(aTimeSum.toString());
+                //sum.add(new BigDecimal(aFteSum).setScale(2, RoundingMode.HALF_UP) + "");
+                sum.add("");
+                sum.add((monthTime - aTimeSum) + "");
+                pTimeSum = 0.0F;
+                pFteSum = 0.0F;
+                aTimeSum = 0.0F;
+                aFteSum = 0.0F;
+                dataList.add(sum);
+
+                ArrayList<String> n = new ArrayList<>();
+                n.add("");
+                dataList.add(n);
+
+                no += 1;
+                row.add(resultList.get(i).get("area")==null?"无":resultList.get(i).get("area").toString());
+                row.add(no + "");
+                if (wxCorpInfo != null && wxCorpInfo.getSaasSyncContact().equals(1)){
+                    row.add(resultList.get(i).get("corpwx_userid") + "");
+                }else {
+                    row.add(resultList.get(i).get("userName") + "");
+                }
+                row.add(resultList.get(i).get("projectCode") + "");
+                row.add(resultList.get(i).get("projectName") + "");
+
+                Float workTime = Float.valueOf(resultList.get(i).get("workTime").toString());
+                row.add(workTime + "");
+                pTimeSum += workTime;
+                aTimeSum += workTime;
+
+                Float FTE = Float.valueOf(resultList.get(i).get("workTime").toString()) / monthTime;
+                row.add(new BigDecimal(FTE).setScale(2, RoundingMode.HALF_UP) + "");
+                pFteSum += FTE;
+                aFteSum += FTE;
+
+                row.add("");
+
+                dataList.add(row);
+            }
+
+            if (i == resultList.size()-1){
+                ArrayList<String> pSum = new ArrayList<>();
+                pSum.add("");
+                pSum.add("");
+                pSum.add("合计");
+                pSum.add("");
+                pSum.add("");
+                pSum.add(pTimeSum.toString());
+                pSum.add(new BigDecimal(pFteSum).setScale(2, RoundingMode.HALF_UP) + "");
+                pSum.add((monthTime - pTimeSum) + "");
+                dataList.add(pSum);
+
+                ArrayList<String> sum = new ArrayList<>();
+                sum.add("");
+                sum.add("");
+                sum.add("地区合计");
+                sum.add("");
+                sum.add("");
+                sum.add(aTimeSum.toString());
+                //sum.add(new BigDecimal(aFteSum).setScale(2, RoundingMode.HALF_UP) + "");
+                sum.add("");
+                sum.add((monthTime - aTimeSum) + "");
+                dataList.add(sum);
+            }
+        }
         String fileName = "FTE报表"+System.currentTimeMillis();
-        String resp = ExcelUtil.exportGeneralExcelByTitleAndList(fileName, dataList, path,mergeCellList);
-        msg.data=resp;
-        return msg;
+        try {
+            return excelExportService.exportGeneralExcelByTitleAndList(wxCorpInfo,fileName, dataList, path);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        httpRespMsg.data =  pathPrefix + fileName+".xlsx";
+        return httpRespMsg;
     }
 }

+ 13 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/UserServiceImpl.java

@@ -2702,4 +2702,17 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
         }
         return httpRespMsg;
     }
+
+    @Override
+    public HttpRespMsg areaData(String token) {
+        HttpRespMsg httpRespMsg = new HttpRespMsg();
+        User user = userMapper.selectById(token);
+        List<User> items = userMapper.selectList(new QueryWrapper<User>().select("DISTINCT plate1").eq("company_id", user.getCompanyId()));
+        ArrayList<String> areas = new ArrayList<String>();
+        for (User item : items) {
+            areas.add(item.getPlate1());
+        }
+        httpRespMsg.data = areas;
+        return httpRespMsg;
+    }
 }

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

@@ -1600,4 +1600,37 @@
             ) p2
         )
     </select>
+
+    <select id="getFTEData" resultType="java.util.Map">
+        SELECT u.id,u.name userName,u.corpwx_userid wxUserId,u.plate1 area,SUM(r.working_time) workTime,p.project_name projectName,p.project_code projectCode
+        FROM `user` u
+        LEFT JOIN report r
+        ON u.id = r.creator_id
+        LEFT JOIN project p
+        ON r.project_id = p.id
+        WHERE r.state = 1
+        AND p.is_public = 0
+        AND u.company_id=#{companyId}
+        AND r.create_date BETWEEN #{startDate} AND #{endDate}
+        <if test="area!=null and area != '' ">
+            and u.plate1 = #{area}
+        </if>
+        <if test="branchDepartment!=null and branchDepartment.size()>0">
+            and us.department_id in
+            <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
+                #{item}
+            </foreach>
+        </if>
+        <if test="deptIds!=null and deptIds.size()>0">
+            and us.department_id in
+            <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
+                #{item}
+            </foreach>
+        </if>
+        GROUP BY u.id,p.id,u.plate1,p.project_name,u.name,u.corpwx_userid,p.project_code
+        order by area,id
+        <if test="start!=null and size!=null">
+            limit #{start},#{size}
+        </if>
+    </select>
 </mapper>