Jelajahi Sumber

工时成本统计按照部门查看时,点击部门可以看直属员工数据统计

seyason 10 bulan lalu
induk
melakukan
00579a3e82

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

@@ -21,6 +21,8 @@ public interface DepartmentMapper extends BaseMapper<Department> {
 
     List<Map<String, Object>> getCostByUser(@Param("departmentIds") List departmentIds, String startDate, String endDate, Integer companyId, List<String> userIds);
 
+    List<Map<String, Object>> getCostByUserSum(@Param("departmentIds") List departmentIds, String startDate, String endDate, Integer companyId);
+
     List<Map<String, Object>> getCustomDataByUser(@Param("departmentIds") List departmentIds, String startDate, String endDate, Integer companyId, List<String> userIds);
     @Update("update department set manager_id = null where department_id = #{departmentId}")
     void updateNullManager(Integer departmentId);

+ 86 - 75
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/DepartmentServiceImpl.java

@@ -452,90 +452,101 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
     @Override
     public HttpRespMsg getDepartmentStatistics(Integer parentDeptId, String startDate, String endDate, HttpServletRequest request) {
         HttpRespMsg httpRespMsg = new HttpRespMsg();
-        try {
-            User targetUser = userMapper.selectById(request.getHeader("Token"));
-            Integer companyId =targetUser.getCompanyId();
-            //当前用户管理部门
-            List<Integer> deptIds=null;
-            List<Department> departmentList = departmentMapper.selectList(new QueryWrapper<Department>().eq("manager_id", targetUser.getId()).eq("company_id", companyId));
-            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(), "查看成本统计");
-            //判断查看权限
-            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().map(dom -> dom.getDepartmentId()).distinct().collect(Collectors.toList());
-                        collect.addAll(otherCollect);
-                        deptIds.addAll(collect);
-                    }
+        User targetUser = userMapper.selectById(request.getHeader("Token"));
+        Integer companyId =targetUser.getCompanyId();
+        //当前用户管理部门
+        List<Integer> deptIds=null;
+        List<Department> departmentList = departmentMapper.selectList(new QueryWrapper<Department>().eq("manager_id", targetUser.getId()).eq("company_id", companyId));
+        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(), "查看成本统计");
+        //判断查看权限
+        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().map(dom -> dom.getDepartmentId()).distinct().collect(Collectors.toList());
+                    collect.addAll(otherCollect);
+                    deptIds.addAll(collect);
                 }
             }
-            QueryWrapper<Department> queryWrapper = new QueryWrapper<Department>()
-                    .eq("company_id", companyId);
-            if (parentDeptId == null) {
-                if (deptIds == null) {
-                    //查看全公司的
-                    queryWrapper.isNull("superior_id");
-                }else {
-                    queryWrapper.in("department_id",deptIds);
-                }
-            } else {
-                queryWrapper.eq("superior_id", parentDeptId);
+        }
+        QueryWrapper<Department> queryWrapper = new QueryWrapper<Department>()
+                .eq("company_id", companyId);
+        if (parentDeptId == null) {
+            if (deptIds == null) {
+                //查看全公司的
+                queryWrapper.isNull("superior_id");
+            }else {
+                queryWrapper.in("department_id",deptIds);
             }
-            //获取第一级部门
-            System.out.println(deptIds);
-            List<Department> masterList = departmentMapper.selectList(queryWrapper);
-            System.out.println(masterList);
-            Map<String, Object> resultMap = new HashMap<>();
-            List<DepartmentMasterVO> list = new ArrayList<>();
-            BigDecimal totalCostMoney = new BigDecimal(0);
-            List<Department> allDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", companyId));
-
-            for (Department department : masterList) {
+        } else {
+            queryWrapper.eq("superior_id", parentDeptId);
+        }
+        //获取第一级部门
+        System.out.println(deptIds);
+        List<Department> masterList = departmentMapper.selectList(queryWrapper);
+        Map<String, Object> resultMap = new HashMap<>();
+        List<DepartmentMasterVO> list = new ArrayList<>();
+        BigDecimal totalCostMoney = new BigDecimal(0);
+        List<Department> allDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", companyId));
+
+        for (Department department : masterList) {
+            DepartmentMasterVO departmentMasterVO = new DepartmentMasterVO();
+            BeanUtils.copyProperties(department, departmentMasterVO);
+            Map<String, Object> map = departmentMapper.getCostByDepartment(
+                    getBranchDepartment(department.getDepartmentId(), allDeptList), startDate, endDate);
+            Double time = map == null ? new Double(0) : (Double) map.get("time");
+            BigDecimal money = map == null ? new BigDecimal(0) : (BigDecimal) map.get("money");
+            totalCostMoney = totalCostMoney.add(money);
+            departmentMasterVO.setCostTime(time);
+            departmentMasterVO.setCostMoney(money);
+            departmentMasterVO.setType("departmentName");
+            //检查是否有子部门
+            if (allDeptList.stream().anyMatch(dept->department.getDepartmentId().equals(dept.getSuperiorId()))) {
+                departmentMasterVO.setHasSubDept(true);
+            }
+            list.add(departmentMasterVO);
+        }
+        //当前部门下的直属人员工时统计
+        if (parentDeptId != null) {
+            List<Integer> curDeptIds = new ArrayList<>();
+            curDeptIds.add(parentDeptId);
+            List<Map<String, Object>> userTimeList = departmentMapper.getCostByUserSum(curDeptIds, startDate, endDate, companyId);
+            for (Map<String, Object> map : userTimeList) {
                 DepartmentMasterVO departmentMasterVO = new DepartmentMasterVO();
-                BeanUtils.copyProperties(department, departmentMasterVO);
-                Map<String, Object> map = departmentMapper.getCostByDepartment(
-                        getBranchDepartment(department.getDepartmentId(), allDeptList), startDate, endDate);
-                Double time = map == null ? new Double(0) : (Double) map.get("time");
+                departmentMasterVO.setSeq(0);
+                departmentMasterVO.setDepartmentName((String)map.get("user"));
+                departmentMasterVO.setCostTime((Double)map.get("time"));
                 BigDecimal money = map == null ? new BigDecimal(0) : (BigDecimal) map.get("money");
-                totalCostMoney = totalCostMoney.add(money);
-                departmentMasterVO.setCostTime(time);
                 departmentMasterVO.setCostMoney(money);
-                departmentMasterVO.setType("departmentName");
-                //检查是否有子部门
-                if (allDeptList.stream().anyMatch(dept->department.getDepartmentId().equals(dept.getSuperiorId()))) {
-                    departmentMasterVO.setHasSubDept(true);
-                }
+                departmentMasterVO.setType("userName");
+                departmentMasterVO.setHasSubDept(false);
                 list.add(departmentMasterVO);
+                totalCostMoney = totalCostMoney.add(money);
             }
-            //对部门排序
-            list.sort(Comparator.comparing(l->l.getSeq()));
-            resultMap.put("totalCostMoney", totalCostMoney);
-            resultMap.put("costList", list);
-            if(functionCostList.size()==0){
-                resultMap.put("totalCostMoney",new BigDecimal(0));
-                list.forEach(li->{
-                    li.setCostMoney(new BigDecimal(0));
-                });
-            }
-            if(functionTimeList.size()==0){
-                list.forEach(li->{
-                    li.setCostTime(0.0);
-                });
-            }
-            httpRespMsg.data = resultMap;
-        } catch (NullPointerException e) {
-            //httpRespMsg.setError("验证失败");
-            httpRespMsg.setError(MessageUtils.message("access.verificationError"));
-            return httpRespMsg;
         }
+        //对部门排序
+        list.sort(Comparator.comparing(l->l.getSeq()));
+        resultMap.put("totalCostMoney", totalCostMoney);
+        resultMap.put("costList", list);
+        if(functionCostList.size()==0){
+            resultMap.put("totalCostMoney",new BigDecimal(0));
+            list.forEach(li->{
+                li.setCostMoney(new BigDecimal(0));
+            });
+        }
+        if(functionTimeList.size()==0){
+            list.forEach(li->{
+                li.setCostTime(0.0);
+            });
+        }
+        httpRespMsg.data = resultMap;
         return httpRespMsg;
     }
 

+ 22 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/resources/mapper/DepartmentMapper.xml

@@ -68,6 +68,28 @@
         GROUP BY b.project_id, a.id order by a.department_id
     </select>
 
+    <!--根据人员获取成本-->
+    <select id="getCostByUserSum" resultType="java.util.Map">
+        SELECT a.id as id, a.name AS user,a.corpwx_userid as corpwxUserId, a.job_number as jobNumber, ifnull(SUM(b.working_time),0) AS time, ifnull(SUM(b.cost),0) AS
+        money
+        FROM user AS a
+        LEFT JOIN report AS b ON a.id = b.creator_id
+        WHERE b.state = 1
+        <if test="departmentIds != null and departmentIds.size()>0">
+            AND b.dept_id IN
+            <foreach collection="departmentIds" item="departmentId" index="index" open="(" close=")" separator=",">
+                #{departmentId}
+            </foreach>
+        </if>
+        <if test="companyId != null">
+            AND a.company_id = #{companyId}
+        </if>
+        <if test="startDate != null and endDate != null">
+            AND b.create_date between #{startDate} and #{endDate}
+        </if>
+        GROUP BY a.id order by a.department_id
+    </select>
+
     <!-- 根据人员获取自定义的日报数值 -->
     <select id="getCustomDataByUser" resultType="java.util.Map">
         SELECT a.id as id, a.name AS user,a.corpwx_userid as corpwxUserid, a.job_number as jobNumber,c.project_name AS project, IFNULL(SUM(b.custom_data),0) AS cost

+ 16 - 13
fhKeeper/formulahousekeeper/timesheet/src/views/project/cost.vue

@@ -1082,7 +1082,8 @@
                                         // "value": this.yAxisValue==0 ? list[i].costMoney.toFixed(2) || list[i].costMoney: list[i].costTime.toFixed(1),
                                         "value": this.yAxisValue==0 ? (list[i].costMoney ? list[i].costMoney.toFixed(2) : 0) || list[i].costMoney: (list[i].costTime ? list[i].costTime.toFixed(1) : 0),
                                         "id": list[i].departmentId,
-                                        "hasSubDept": list[i].hasSubDept
+                                        "hasSubDept": list[i].hasSubDept,
+                                        "type": list[i].type
                                     }
                                     if(this.permissions.countCost){
                                         // item.money = list[i].costMoney.toFixed(2)
@@ -1313,19 +1314,21 @@
                                         _this.$router.push("/cost/" + _this.params[0].data.id + "/" + _this.params[0].name);
                                     }
                                 } else if (_this.radio==this.$t('lable.department')) {
-                                    if (_this.params[0].data.hasSubDept) {
-                                        if (_this.parentDeptId != _this.params[0].data.id) {
-                                            _this.parentDeptId = _this.params[0].data.id;
-                                            _this.parentDeptStack.push(_this.parentDeptId);
-                                            _this.jieliu();
-                                        }
-                                        // _this.jieliu();
-                                    } else {
-                                        if (_this.dateRange != null) {
-                                            _this.$router.push("/costDep/" + _this.params[0].data.id + "/" + _this.params[0].name
-                                                +"?startDate="+_this.dateRange[0]+"&endDate="+_this.dateRange[1]);
+                                    if (_this.params[0].data.type == 'departmentName') {
+                                        if (_this.params[0].data.hasSubDept) {
+                                            if (_this.parentDeptId != _this.params[0].data.id) {
+                                                _this.parentDeptId = _this.params[0].data.id;
+                                                _this.parentDeptStack.push(_this.parentDeptId);
+                                                _this.jieliu();
+                                            }
+                                            // _this.jieliu();
                                         } else {
-                                            _this.$router.push("/costDep/" + _this.params[0].data.id + "/" + _this.params[0].name);
+                                            if (_this.dateRange != null) {
+                                                _this.$router.push("/costDep/" + _this.params[0].data.id + "/" + _this.params[0].name
+                                                    +"?startDate="+_this.dateRange[0]+"&endDate="+_this.dateRange[1]);
+                                            } else {
+                                                _this.$router.push("/costDep/" + _this.params[0].data.id + "/" + _this.params[0].name);
+                                            }
                                         }
                                     }
                                 }