|
@@ -2684,6 +2684,111 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|
|
return httpRespMsg;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg getTimeCostByStatus(String startDate, String endDate, String userIds,Integer status, Integer type,HttpServletRequest request) {
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
+ try {
|
|
|
+ //根据系统配置的员工成本计算方式,按固定时薪还是固定月薪,分情况计算。
|
|
|
+ User targetUser = userMapper.selectById(request.getHeader("Token"));
|
|
|
+ Integer companyId = targetUser.getCompanyId();
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
+ //当前用户管理部门
|
|
|
+ List<Integer> deptIds=null;
|
|
|
+ List<Department> allDepartmentList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id",companyId));
|
|
|
+ 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(), "查看成本统计");
|
|
|
+ List<Integer> deptRelatedProjectIds = new ArrayList<>();
|
|
|
+ List<Integer> projectIds = null;
|
|
|
+ //针对威派格,部门的主要和其他负责人需要查看部门下人员负责的项目或者项目下的任务分组的工时
|
|
|
+ boolean containDeptMembInchargeProjects = targetUser.getCompanyId() == 936;
|
|
|
+ List<String> inchargeUserIds = null;
|
|
|
+ //判断查看权限
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+
|
|
|
+ //有限匹配项目经理的数据视角
|
|
|
+ List<Project> projectList = projectMapper.selectList(new QueryWrapper<Project>().select("id").eq("incharger_id", targetUser.getId()));
|
|
|
+ if (projectList.size() > 0) {
|
|
|
+ projectIds = projectList.stream().map(Project::getId).collect(Collectors.toList());
|
|
|
+ deptIds = null;
|
|
|
+ } else {
|
|
|
+ if(functionDpartList.size()>0){
|
|
|
+ if(functionTimeList.size()>0||functionCostList.size()>0){
|
|
|
+ deptIds.addAll(allMyManagedDeptIds);
|
|
|
+ }
|
|
|
+ if (containDeptMembInchargeProjects && deptIds.size() > 1) {
|
|
|
+ inchargeUserIds = userMapper.selectList(new QueryWrapper<User>().select("id").in("department_id", deptIds)).stream().map(User::getId).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<String> userIdList=new ArrayList<>();
|
|
|
+ if(userIds!=null&&userIds.length()>0){
|
|
|
+ String[] split = userIds.split(",");
|
|
|
+ userIdList = Arrays.asList(split);
|
|
|
+ }
|
|
|
+ List<Map<String, Object>> list = projectMapper.getTimeCostByStatus(companyId, startDate, endDate, status, userIdList,deptIds,null, deptRelatedProjectIds, projectIds, inchargeUserIds,null);
|
|
|
+ BigDecimal totalMoneyCost = BigDecimal.valueOf(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"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (type.equals(0)){
|
|
|
+ list = list.stream().sorted(Comparator.comparing(l -> -Double.parseDouble(l.get("costMoney").toString()))).collect(Collectors.toList());
|
|
|
+ }else {
|
|
|
+ list = list.stream().sorted(Comparator.comparing(l -> -Double.parseDouble(l.get("cost").toString()))).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ resultMap.put("costList", list);
|
|
|
+ resultMap.put("totalMoneyCost", totalMoneyCost);
|
|
|
+ if(functionCostList.size()==0){
|
|
|
+ resultMap.put("totalCostMoney",new BigDecimal(0));
|
|
|
+ list.forEach(li->{
|
|
|
+ li.put("costMoney",new BigDecimal(0));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if(functionTimeList.size()==0){
|
|
|
+ list.forEach(li->{
|
|
|
+ li.put("cost",0.0);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ httpRespMsg.data = resultMap;
|
|
|
+ } catch (NullPointerException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ //httpRespMsg.setError("验证失败");
|
|
|
+ httpRespMsg.setError(MessageUtils.message("access.verificationError"));
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private HashMap fillMainProjectRowData(Integer projectMainId, Integer companyId, String startDate, String endDate, Integer stateKey, List<String> userIdList, List<Map<String, Object>> list,
|
|
|
List<UserCustom> userCustoms, List<SysRichFunction> functionTimeList, List<SysRichFunction> functionCostList,
|
|
|
String exportContent, List<User> userList, List<Integer> deptIds, List<Integer> deptRelatedProjectIds,
|