|
@@ -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;
|
|
|
}
|
|
|
|