|
@@ -3,12 +3,14 @@ package com.management.platform.service.impl;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.github.pagehelper.util.StringUtil;
|
|
|
import com.management.platform.entity.*;
|
|
|
+import com.management.platform.entity.Task;
|
|
|
import com.management.platform.entity.vo.*;
|
|
|
import com.management.platform.mapper.*;
|
|
|
import com.management.platform.service.*;
|
|
@@ -53,10 +55,7 @@ import java.math.RoundingMode;
|
|
|
import java.sql.Array;
|
|
|
import java.sql.Timestamp;
|
|
|
import java.text.*;
|
|
|
-import java.time.Duration;
|
|
|
-import java.time.LocalDate;
|
|
|
-import java.time.LocalDateTime;
|
|
|
-import java.time.LocalTime;
|
|
|
+import java.time.*;
|
|
|
import java.time.chrono.ChronoLocalDate;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.time.temporal.TemporalAdjusters;
|
|
@@ -1249,6 +1248,9 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|
|
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<>();
|
|
@@ -1272,6 +1274,9 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|
|
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());
|
|
|
+ }
|
|
|
} else {
|
|
|
//担任项目经理的项目
|
|
|
List<Project> projectList = projectMapper.selectList(new QueryWrapper<Project>().select("id").eq("incharger_id", targetUser.getId()));
|
|
@@ -1289,7 +1294,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|
|
String[] split = userIds.split(",");
|
|
|
userIdList = Arrays.asList(split);
|
|
|
}
|
|
|
- List<Map<String, Object>> list = projectMapper.getTimeCost(companyId, startDate, endDate, projectId, userIdList,deptIds,null, deptRelatedProjectIds, projectIds);
|
|
|
+ List<Map<String, Object>> list = projectMapper.getTimeCost(companyId, startDate, endDate, projectId, userIdList,deptIds,null, deptRelatedProjectIds, projectIds, inchargeUserIds);
|
|
|
BigDecimal totalMoneyCost = BigDecimal.valueOf(0);
|
|
|
for (Map<String, Object> map : list) {
|
|
|
if (!map.containsKey("cost")) {
|
|
@@ -1355,6 +1360,9 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|
|
List<Integer> manProjectIds = null;
|
|
|
//判断查看权限
|
|
|
List<Integer> filterDeptIds=null;
|
|
|
+ //针对威派格,部门的主要和其他负责人需要查看部门下人员负责的项目或者项目下的任务分组的工时
|
|
|
+ boolean containDeptMembInchargeProjects = targetUser.getCompanyId() == 936;
|
|
|
+ List<String> inchargeUserIds = null;
|
|
|
if(deptId!=null){
|
|
|
filterDeptIds= getBranchDepartment(deptId, allDepartmentList);
|
|
|
}
|
|
@@ -1378,6 +1386,9 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|
|
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());
|
|
|
+ }
|
|
|
} else {
|
|
|
//担任项目经理的项目
|
|
|
List<Project> projectList = projectMapper.selectList(new QueryWrapper<Project>().select("id").eq("incharger_id", targetUser.getId()));
|
|
@@ -1407,7 +1418,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|
|
String[] split = userIds.split(",");
|
|
|
userIdList = Arrays.asList(split);
|
|
|
}
|
|
|
- List<Map<String, Object>> list = projectMapper.getTimeCost(companyId, startDate, endDate, projectId, userIdList,deptIds,filterDeptIds,deptRelatedProjectIds, manProjectIds);
|
|
|
+ List<Map<String, Object>> list = projectMapper.getTimeCost(companyId, startDate, endDate, projectId, userIdList,deptIds,filterDeptIds,deptRelatedProjectIds, manProjectIds, inchargeUserIds);
|
|
|
BigDecimal totalMoneyCost = BigDecimal.valueOf(0);
|
|
|
List<List<String>> allList=null ;
|
|
|
List<String> sumRow = null;
|
|
@@ -8207,14 +8218,64 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|
|
public HttpRespMsg getCostByGroup(String startDate, String endDate, Integer projectId, HttpServletRequest request) {
|
|
|
HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
try {
|
|
|
- Integer companyId = userMapper.selectById(request.getHeader("Token")).getCompanyId();
|
|
|
+ User targetUser = userMapper.selectById(request.getHeader("Token"));
|
|
|
+ Integer companyId = targetUser.getCompanyId();
|
|
|
//首先查看有无浏览权限
|
|
|
- if (!projectMapper.selectById(projectId).getCompanyId().equals(companyId)) {
|
|
|
+ Project project = projectMapper.selectById(projectId);
|
|
|
+ if (!project.getCompanyId().equals(companyId)) {
|
|
|
//httpRespMsg.setError("无权查看其他公司的项目详情");
|
|
|
httpRespMsg.setError(MessageUtils.message("access.otherCompanyProject"));
|
|
|
} else {
|
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
|
- List<Map<String, Object>> list = projectMapper.getCostByGroup(startDate, endDate, projectId);
|
|
|
+ List<Integer> gpIds = null;
|
|
|
+ if (companyId == 936) {
|
|
|
+ //威派格的工时查看可能是看分组负责人的分组工时,需要过滤筛选
|
|
|
+ //当前用户管理部门
|
|
|
+ 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(), "查看负责部门");
|
|
|
+ //无查看全公司的权限
|
|
|
+ if (functionAllList.size() == 0) {
|
|
|
+ deptIds = new ArrayList<>();
|
|
|
+ deptIds.add(-1);
|
|
|
+ //有查看负责部门的权限
|
|
|
+ if (functionDpartList.size() > 0) {
|
|
|
+ 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);
|
|
|
+ deptIds.addAll(branchDepartment);
|
|
|
+ }
|
|
|
+ //查找当前项目的负责人
|
|
|
+ if (project.getInchargerId() != null) {
|
|
|
+ Integer departmentId = userMapper.selectById(project.getInchargerId()).getDepartmentId();
|
|
|
+ if (deptIds.contains(departmentId)) {
|
|
|
+ //项目经理是管理的部门下面的人,查看全部分组
|
|
|
+ } else {
|
|
|
+ //检查是否是分组负责人,查看部分分组
|
|
|
+ List<Integer> fDeptIds = deptIds;
|
|
|
+ List<TaskGroup> groupList = taskGroupMapper.selectList(new QueryWrapper<TaskGroup>().eq("project_id", project.getId()));
|
|
|
+ gpIds = new ArrayList<>();
|
|
|
+ gpIds.add(-1);
|
|
|
+ for (TaskGroup g : groupList) {
|
|
|
+ if (g.getInchargerId() != null) {
|
|
|
+ Integer departmentId1 = userMapper.selectById(g.getInchargerId()).getDepartmentId();
|
|
|
+ if (fDeptIds.contains(departmentId1)) {
|
|
|
+ //是分组负责人,查看全部
|
|
|
+ gpIds.add(g.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Map<String, Object>> list = projectMapper.getCostByGroup(startDate, endDate, projectId, gpIds);
|
|
|
BigDecimal totalMoneyCost = BigDecimal.valueOf(0);
|
|
|
for (Map<String, Object> map : list) {
|
|
|
if (!map.containsKey("costMoney")) {
|
|
@@ -11199,6 +11260,81 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|
|
return msg;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg getEffectiveLaborHourRate(String startDate, String endDate) {
|
|
|
+ LambdaQueryWrapper<Department> lqw = new LambdaQueryWrapper<>();
|
|
|
+ lqw.in(Department::getDepartmentId,3759,3899,3900,3901,3902,3903,3904,3906,5719);
|
|
|
+ List<Department> departments = departmentMapper.selectList(lqw);
|
|
|
+
|
|
|
+ ArrayList<LaborHourRateVo> laborHourRateVos = new ArrayList<>();
|
|
|
+
|
|
|
+ int dayCount = WorkDayCalculateUtils.getWorkDaysCountInRange(startDate, endDate, 0);//应报工时天数
|
|
|
+
|
|
|
+ for (Department department : departments) {
|
|
|
+ LaborHourRateVo laborHourRateVo = new LaborHourRateVo();
|
|
|
+ laborHourRateVo.setRoot_id(department.getDepartmentId());
|
|
|
+ laborHourRateVo.setDepartment_name(department.getDepartmentName());
|
|
|
+ ArrayList<Integer> deptIds = new ArrayList<>();
|
|
|
+ setDeptIdList(department.getDepartmentId(),deptIds);
|
|
|
+ deptIds.add(department.getDepartmentId());
|
|
|
+ laborHourRateVo.setChild_ids(deptIds);
|
|
|
+ //查询该公司下某头部部门及子部门在四种项目下的工时之和,某个时间段内
|
|
|
+ List<Report> reportList= reportMapper.getSumWorkingTime(deptIds,startDate,endDate);
|
|
|
+ ArrayList<Report> reports = new ArrayList<>();//按时填报的report
|
|
|
+ for (Report report : reportList) {
|
|
|
+ LocalDate createDate = report.getCreateDate();
|
|
|
+ LocalDateTime createTime = report.getCreateTime();
|
|
|
+ LocalDate createTimeLocalDate = createTime.toLocalDate();
|
|
|
+ boolean b1 = WorkDayCalculateUtils.sameMonth(createDate, createTimeLocalDate);
|
|
|
+ boolean b2 = WorkDayCalculateUtils.sameWeek(createDate, createTimeLocalDate);
|
|
|
+ if (b1&&b2){
|
|
|
+ reports.add(report);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ double timeSum = reports.stream().mapToDouble(Report::getWorkingTime).sum();
|
|
|
+
|
|
|
+
|
|
|
+ int inActiveDays=0;
|
|
|
+ //查询 入职时间早于起始时间 但是员工在这段时间离职 的员工列表
|
|
|
+ List<User> inActiveList=userMapper.getInActiveList(deptIds,startDate,endDate);
|
|
|
+ //获取离职员工在此期间工作多少天
|
|
|
+ for (User user : inActiveList) {
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ String inactiveDate = user.getInactiveDate().format(formatter);
|
|
|
+ inActiveDays+=WorkDayCalculateUtils.getWorkDaysCountInRange(startDate,inactiveDate,0);
|
|
|
+ }
|
|
|
+ //-- 查询 有多少个 入职时间早于起始时间 并且是在职的员工
|
|
|
+ int isActiveCount=userMapper.getIsActiveCount(deptIds,startDate,endDate);
|
|
|
+
|
|
|
+ laborHourRateVo.setWorking_time(timeSum);
|
|
|
+ laborHourRateVo.setDate_count(dayCount);
|
|
|
+ laborHourRateVo.setCount(isActiveCount);
|
|
|
+ laborHourRateVo.setTotal_time((long) (inActiveList.size()*8*inActiveDays+isActiveCount*8*dayCount));//应报工时还少了在职的加上可能辞职的
|
|
|
+ System.out.println("============="+inActiveDays);
|
|
|
+ System.out.println("============="+isActiveCount);
|
|
|
+ laborHourRateVo.setDay_time(8);
|
|
|
+ laborHourRateVos.add(laborHourRateVo);
|
|
|
+ }
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ msg.setData(laborHourRateVos);
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void setDeptIdList(Integer departmentId,List<Integer> deptIds){
|
|
|
+ LambdaQueryWrapper<Department> lqw = new LambdaQueryWrapper<>();
|
|
|
+ lqw.eq(Department::getSuperiorId,departmentId);
|
|
|
+ List<Department> departmentList = departmentMapper.selectList(lqw);
|
|
|
+
|
|
|
+ if (departmentList!=null&&departmentList.size()>0){
|
|
|
+ List<Integer> collect = departmentList.stream().map(Department::getDepartmentId).collect(Collectors.toList());
|
|
|
+ deptIds.addAll(collect);
|
|
|
+ for (Integer id : collect) {
|
|
|
+ setDeptIdList(id,deptIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//同步SAP项目服务数据到工时管家
|
|
|
private void syncServiceData(String startDate, String endDate, Integer companyId) {
|
|
|
List<ReportExtraDegree> extraDegrees = reportExtraDegreeService.list(new QueryWrapper<ReportExtraDegree>().eq("company_id", companyId));
|