|
@@ -81,6 +81,8 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|
@Resource
|
|
@Resource
|
|
StagesMapper stagesMapper;
|
|
StagesMapper stagesMapper;
|
|
@Resource
|
|
@Resource
|
|
|
|
+ FinanceMapper financeMapper;
|
|
|
|
+ @Resource
|
|
private HttpServletResponse response;
|
|
private HttpServletResponse response;
|
|
|
|
|
|
@Value(value = "${upload.path}")
|
|
@Value(value = "${upload.path}")
|
|
@@ -226,7 +228,6 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|
httpRespMsg.setError("操作失败");
|
|
httpRespMsg.setError("操作失败");
|
|
} else {
|
|
} else {
|
|
if (projectBaseCostData != null) {
|
|
if (projectBaseCostData != null) {
|
|
- System.out.println("projectBaseCostData===="+projectBaseCostData);
|
|
|
|
updateProjectBaseCostData(projectBaseCostData, project.getId());
|
|
updateProjectBaseCostData(projectBaseCostData, project.getId());
|
|
|
|
|
|
//创建项目涉及到基线成本数据,要填写到快照表中
|
|
//创建项目涉及到基线成本数据,要填写到快照表中
|
|
@@ -422,22 +423,90 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|
//根据系统配置的员工成本计算方式,按固定时薪还是固定月薪,分情况计算。
|
|
//根据系统配置的员工成本计算方式,按固定时薪还是固定月薪,分情况计算。
|
|
Integer companyId = userMapper.selectById(request.getHeader("Token")).getCompanyId();
|
|
Integer companyId = userMapper.selectById(request.getHeader("Token")).getCompanyId();
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
- //时薪固定计算
|
|
|
|
- List<Map<String, Object>> list = projectMapper.getTimeCost(companyId, startDate, endDate, null);
|
|
|
|
- BigDecimal totalMoneyCost = BigDecimal.valueOf(0);
|
|
|
|
- for (Map<String, Object> map : list) {
|
|
|
|
- if (!map.containsKey("cost")) {
|
|
|
|
- map.put("cost", 0);
|
|
|
|
|
|
+
|
|
|
|
+ TimeType timeType = timeTypeMapper.selectById(companyId);
|
|
|
|
+ if (timeType.getFixMonthcost() == 1) {
|
|
|
|
+ //每月固定月薪的方式计算,平摊到各个项目中
|
|
|
|
+ List<Map<String, Object>> list = projectMapper.getTimeCostReport(companyId, startDate+"-01", endDate+"-31", null);
|
|
|
|
+ //检查财务表中是否已经导入成本
|
|
|
|
+ List<Finance> financeList = financeMapper.selectList(new QueryWrapper<Finance>().eq("ymonth", startDate).eq("company_id", companyId));
|
|
|
|
+ List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", companyId));
|
|
|
|
+ //计算人员总工时
|
|
|
|
+ for (Map<String, Object> map : list) {
|
|
|
|
+ String creatorId = (String)map.get("creatorId");
|
|
|
|
+ double cost = (double)map.get("cost");
|
|
|
|
+ User user = userList.stream().filter(u -> u.getId().equals(creatorId)).findFirst().get();
|
|
|
|
+ user.setTotalHours(user.getTotalHours() + cost);
|
|
}
|
|
}
|
|
- if (!map.containsKey("costMoney")) {
|
|
|
|
- map.put("costMoney", 0);
|
|
|
|
- } else {
|
|
|
|
- totalMoneyCost = totalMoneyCost.add((BigDecimal)map.get("costMoney"));
|
|
|
|
|
|
+ //计算实际时薪
|
|
|
|
+ for (User user : userList) {
|
|
|
|
+ if (user.getTotalHours() != 0) {
|
|
|
|
+ Optional<Finance> first = financeList.stream().filter(f -> f.getUserId().equals(user.getId())).findFirst();
|
|
|
|
+ BigDecimal monthCost = null;
|
|
|
|
+ if (first.isPresent()) {
|
|
|
|
+ monthCost = first.get().getTotalCost();
|
|
|
|
+ } else {
|
|
|
|
+ monthCost = user.getMonthCost();
|
|
|
|
+ }
|
|
|
|
+ user.setCost(monthCost.divide(new BigDecimal(user.getTotalHours()), 6, BigDecimal.ROUND_HALF_UP));
|
|
|
|
+ } else {
|
|
|
|
+ user.setCost(new BigDecimal(0));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ BigDecimal totalMoneyCost = BigDecimal.valueOf(0);
|
|
|
|
+ List<Map<String, Object>> retList = new ArrayList<>();
|
|
|
|
+ List<Project> projectList = projectMapper.selectList(new QueryWrapper<Project>().eq("company_id", companyId).orderByAsc("id"));
|
|
|
|
+ for (Project p : projectList) {
|
|
|
|
+ Map<String, Object> projectMap = new HashMap<>();
|
|
|
|
+ projectMap.put("id", p.getId());
|
|
|
|
+ projectMap.put("name", p.getProjectName());
|
|
|
|
+ //按照项目汇总
|
|
|
|
+ double pTotalTime = 0;
|
|
|
|
+ BigDecimal pTotalMoney = new BigDecimal(0);
|
|
|
|
+ for (Map<String, Object> map : list) {
|
|
|
|
+ String creatorId = (String)map.get("creatorId");
|
|
|
|
+ int projectId = (int)map.get("projectId");
|
|
|
|
+ if (projectId == p.getId()) {
|
|
|
|
+ double costTime = (double)map.get("cost");
|
|
|
|
+ pTotalTime += costTime;
|
|
|
|
+ User curUser = userList.stream().filter(u->u.getId().equals(creatorId)).findFirst().get();
|
|
|
|
+ //该人员的成本
|
|
|
|
+ pTotalMoney = pTotalMoney.add(curUser.getCost().multiply(new BigDecimal(costTime)));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (pTotalTime > 0) {
|
|
|
|
+ projectMap.put("cost", pTotalTime);
|
|
|
|
+ projectMap.put("costMoney", pTotalMoney);
|
|
|
|
+ retList.add(projectMap);
|
|
|
|
+ totalMoneyCost = totalMoneyCost.add(pTotalMoney);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ resultMap.put("costList", retList);
|
|
|
|
+ resultMap.put("totalMoneyCost", totalMoneyCost);
|
|
|
|
+ httpRespMsg.data = resultMap;
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ List<Map<String, Object>> list = projectMapper.getTimeCost(companyId, startDate, endDate, 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"));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ resultMap.put("costList", list);
|
|
|
|
+ resultMap.put("totalMoneyCost", totalMoneyCost);
|
|
|
|
+ httpRespMsg.data = resultMap;
|
|
}
|
|
}
|
|
- resultMap.put("costList", list);
|
|
|
|
- resultMap.put("totalMoneyCost", totalMoneyCost);
|
|
|
|
- httpRespMsg.data = resultMap;
|
|
|
|
|
|
+
|
|
|
|
+
|
|
} catch (NullPointerException e) {
|
|
} catch (NullPointerException e) {
|
|
httpRespMsg.setError("验证失败");
|
|
httpRespMsg.setError("验证失败");
|
|
return httpRespMsg;
|
|
return httpRespMsg;
|
|
@@ -655,19 +724,72 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|
if (!projectMapper.selectById(projectId).getCompanyId().equals(companyId)) {
|
|
if (!projectMapper.selectById(projectId).getCompanyId().equals(companyId)) {
|
|
httpRespMsg.setError("无权查看其他公司的项目详情");
|
|
httpRespMsg.setError("无权查看其他公司的项目详情");
|
|
} else {
|
|
} else {
|
|
- Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
- List<Map<String, Object>> list = projectMapper.getProjectCost(startDate, endDate, projectId);
|
|
|
|
- BigDecimal totalMoneyCost = BigDecimal.valueOf(0);
|
|
|
|
- for (Map<String, Object> map : list) {
|
|
|
|
- if (!map.containsKey("costMoney")) {
|
|
|
|
- map.put("costMoney", 0);
|
|
|
|
- } else {
|
|
|
|
- totalMoneyCost = totalMoneyCost.add((BigDecimal)map.get("costMoney"));
|
|
|
|
|
|
+ TimeType timeType = timeTypeMapper.selectById(companyId);
|
|
|
|
+ if (timeType.getFixMonthcost() == 0) {
|
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
+ List<Map<String, Object>> list = projectMapper.getProjectCost(startDate, endDate, projectId);
|
|
|
|
+ BigDecimal totalMoneyCost = BigDecimal.valueOf(0);
|
|
|
|
+ for (Map<String, Object> map : list) {
|
|
|
|
+ if (!map.containsKey("costMoney")) {
|
|
|
|
+ map.put("costMoney", 0);
|
|
|
|
+ } else {
|
|
|
|
+ totalMoneyCost = totalMoneyCost.add((BigDecimal)map.get("costMoney"));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ resultMap.put("costList", list);
|
|
|
|
+ resultMap.put("totalMoneyCost", totalMoneyCost);
|
|
|
|
+ httpRespMsg.data = resultMap;
|
|
|
|
+ } else {
|
|
|
|
+ startDate = startDate + "-01";
|
|
|
|
+ endDate = endDate + "-31";
|
|
|
|
+ List<Map<String, Object>> userMonthTimeCostList = projectMapper.getUserMonthTimeCost(companyId, startDate+"-01", endDate+"-31");
|
|
|
|
+
|
|
|
|
+ List<Map<String, Object>> list = projectMapper.getProjectCost(startDate, endDate, projectId);
|
|
|
|
+
|
|
|
|
+ //检查财务表中是否已经导入成本
|
|
|
|
+ List<Finance> financeList = financeMapper.selectList(new QueryWrapper<Finance>().eq("ymonth", startDate).eq("company_id", companyId));
|
|
|
|
+ List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", companyId));
|
|
|
|
+
|
|
|
|
+ //计算实际时薪
|
|
|
|
+ for (User user : userList) {
|
|
|
|
+ double userTotalTime = 0;
|
|
|
|
+ for (int i=0;i<userMonthTimeCostList.size(); i++) {
|
|
|
|
+ Map map = userMonthTimeCostList.get(i);
|
|
|
|
+ if (map.get("creatorId").equals(user.getId())) {
|
|
|
|
+ userTotalTime = (double)map.get("cost");
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (userTotalTime != 0) {
|
|
|
|
+ Optional<Finance> first = financeList.stream().filter(f -> f.getUserId().equals(user.getId())).findFirst();
|
|
|
|
+ BigDecimal monthCost = null;
|
|
|
|
+ if (first.isPresent()) {
|
|
|
|
+ monthCost = first.get().getTotalCost();
|
|
|
|
+ } else {
|
|
|
|
+ monthCost = user.getMonthCost();
|
|
|
|
+ }
|
|
|
|
+ user.setCost(monthCost.divide(new BigDecimal(userTotalTime), 6, BigDecimal.ROUND_HALF_UP));
|
|
|
|
+ } else {
|
|
|
|
+ user.setCost(new BigDecimal(0));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
+ BigDecimal totalMoneyCost = BigDecimal.valueOf(0);
|
|
|
|
+
|
|
|
|
+ //计算人员在项目上的投入工时
|
|
|
|
+ for (Map<String, Object> map : list) {
|
|
|
|
+ String creatorId = (String)map.get("creatorId");
|
|
|
|
+ double cost = (double)map.get("cost");
|
|
|
|
+ User user = userList.stream().filter(u -> u.getId().equals(creatorId)).findFirst().get();
|
|
|
|
+ BigDecimal costMoney = user.getCost().multiply(new BigDecimal(cost));
|
|
|
|
+ map.put("costMoney", costMoney);
|
|
|
|
+ totalMoneyCost = totalMoneyCost.add(costMoney);
|
|
}
|
|
}
|
|
|
|
+ resultMap.put("costList", list);
|
|
|
|
+ resultMap.put("totalMoneyCost", totalMoneyCost);
|
|
|
|
+ httpRespMsg.data = resultMap;
|
|
}
|
|
}
|
|
- resultMap.put("costList", list);
|
|
|
|
- resultMap.put("totalMoneyCost", totalMoneyCost);
|
|
|
|
- httpRespMsg.data = resultMap;
|
|
|
|
}
|
|
}
|
|
} catch (NullPointerException e) {
|
|
} catch (NullPointerException e) {
|
|
httpRespMsg.setError("验证失败");
|
|
httpRespMsg.setError("验证失败");
|
|
@@ -1042,7 +1164,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|
List<String> userIds = new ArrayList<>();
|
|
List<String> userIds = new ArrayList<>();
|
|
if (user.getRole() == 0) {
|
|
if (user.getRole() == 0) {
|
|
//看看是部门经理还是项目负责人
|
|
//看看是部门经理还是项目负责人
|
|
- if (user.getManageDeptId() != null) {
|
|
|
|
|
|
+ if (user.getManageDeptId() != null && user.getManageDeptId() != 0) {
|
|
List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("department_id", user.getManageDeptId()));
|
|
List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("department_id", user.getManageDeptId()));
|
|
userIds = userList.stream().map(User::getId).collect(Collectors.toList());
|
|
userIds = userList.stream().map(User::getId).collect(Collectors.toList());
|
|
} else {
|
|
} else {
|
|
@@ -1053,6 +1175,10 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|
List<Participation> participationList = participationMapper.selectList(new QueryWrapper<Participation>().in("project_id", collect));
|
|
List<Participation> participationList = participationMapper.selectList(new QueryWrapper<Participation>().in("project_id", collect));
|
|
userIds = participationList.stream().map(Participation::getUserId).collect(Collectors.toList());
|
|
userIds = participationList.stream().map(Participation::getUserId).collect(Collectors.toList());
|
|
}
|
|
}
|
|
|
|
+ //把自己加进去
|
|
|
|
+ if (!userIds.contains(user.getId())) {
|
|
|
|
+ userIds.add(user.getId());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
//查看全部
|
|
//查看全部
|
|
@@ -1062,7 +1188,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
List<GanttDataItem> itemList = new ArrayList<>();
|
|
List<GanttDataItem> itemList = new ArrayList<>();
|
|
if (userIds.size() > 0) {
|
|
if (userIds.size() > 0) {
|
|
- List<Map> ganttData = projectMapper.getGanttData(userIds);
|
|
|
|
|
|
+ List<Map> ganttData = projectMapper.getGanttData(userIds, user.getCompanyId());
|
|
String lastUserId = null;
|
|
String lastUserId = null;
|
|
|
|
|
|
GanttDataItem lastUserItem = null;
|
|
GanttDataItem lastUserItem = null;
|