|
@@ -821,12 +821,15 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|
headList.add(String.valueOf(pn)+"/工时");
|
|
headList.add(String.valueOf(pn)+"/工时");
|
|
headList.add(String.valueOf(pn)+"/成本");
|
|
headList.add(String.valueOf(pn)+"/成本");
|
|
});
|
|
});
|
|
|
|
+ headList.add("合计/工时");
|
|
|
|
+ headList.add("合计/成本");
|
|
allList=new ArrayList<>();
|
|
allList=new ArrayList<>();
|
|
allList.add(headList);
|
|
allList.add(headList);
|
|
//统计当前所有项目所有人的时间成本投入
|
|
//统计当前所有项目所有人的时间成本投入
|
|
List<Map<String, Object>> membList = projectMapper.getProjectCostGroupByProject(companyId,startDate, endDate, projectId);
|
|
List<Map<String, Object>> membList = projectMapper.getProjectCostGroupByProject(companyId,startDate, endDate, projectId);
|
|
for (User user : userList) {
|
|
for (User user : userList) {
|
|
- boolean flag=false;
|
|
|
|
|
|
+ BigDecimal moneyCost = BigDecimal.valueOf(0);
|
|
|
|
+ double costTime = 0;
|
|
List<Map<String, Object>> mapList = membList.stream().filter(mb -> mb.get("creatorId").equals(user.getId())).collect(Collectors.toList());
|
|
List<Map<String, Object>> mapList = membList.stream().filter(mb -> mb.get("creatorId").equals(user.getId())).collect(Collectors.toList());
|
|
List<String> membRowData=new ArrayList<>();
|
|
List<String> membRowData=new ArrayList<>();
|
|
membRowData.add(user.getName());
|
|
membRowData.add(user.getName());
|
|
@@ -835,11 +838,15 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|
if(resultList.size()>0){
|
|
if(resultList.size()>0){
|
|
membRowData.add(String.valueOf(resultList.get(0).get("cost")));
|
|
membRowData.add(String.valueOf(resultList.get(0).get("cost")));
|
|
membRowData.add(String.valueOf(resultList.get(0).get("costMoney")));
|
|
membRowData.add(String.valueOf(resultList.get(0).get("costMoney")));
|
|
|
|
+ costTime += (Double)resultList.get(0).get("cost");
|
|
|
|
+ moneyCost = totalMoneyCost.add((BigDecimal)resultList.get(0).get("costMoney"));
|
|
}else{
|
|
}else{
|
|
membRowData.add("");
|
|
membRowData.add("");
|
|
membRowData.add("");
|
|
membRowData.add("");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ membRowData.add(""+new BigDecimal(costTime).setScale(1, BigDecimal.ROUND_HALF_UP));
|
|
|
|
+ membRowData.add(moneyCost.toString());
|
|
if(mapList.size()>0){
|
|
if(mapList.size()>0){
|
|
allList.add(membRowData);
|
|
allList.add(membRowData);
|
|
}
|
|
}
|
|
@@ -2825,6 +2832,190 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|
return msg;
|
|
return msg;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg getTimeCostByCategory(String startDate, String endDate, String userId, HttpServletRequest request) {
|
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
|
+ try {
|
|
|
|
+ //根据系统配置的员工成本计算方式,按固定时薪还是固定月薪,分情况计算。
|
|
|
|
+ Integer companyId = userMapper.selectById(request.getHeader("Token")).getCompanyId();
|
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
+
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ //计算实际时薪
|
|
|
|
+ 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<ProjectCategory> projectCategoryList = projectCategoryMapper.selectList(new QueryWrapper<ProjectCategory>().eq("company_id", companyId).orderByAsc("id"));
|
|
|
|
+ for (ProjectCategory pc : projectCategoryList) {
|
|
|
|
+ Map<String, Object> projectCategoryMap = new HashMap<>();
|
|
|
|
+ projectCategoryMap.put("id", pc.getId());
|
|
|
|
+ projectCategoryMap.put("name", pc.getName());
|
|
|
|
+ //按照项目分类汇总
|
|
|
|
+ double pTotalTime = 0;
|
|
|
|
+ BigDecimal pTotalMoney = new BigDecimal(0);
|
|
|
|
+ for (Map<String, Object> map : list) {
|
|
|
|
+ String creatorId = (String)map.get("creatorId");
|
|
|
|
+ String projectCategoryName =StringUtils.isEmpty( (String) map.get("categoryName"))?"未分类": (String) map.get("categoryName");
|
|
|
|
+ if (projectCategoryName.equals(pc.getName())) {
|
|
|
|
+ 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) {
|
|
|
|
+ projectCategoryMap.put("cost", pTotalTime);
|
|
|
|
+ projectCategoryMap.put("costMoney", pTotalMoney);
|
|
|
|
+ retList.add(projectCategoryMap);
|
|
|
|
+ totalMoneyCost = totalMoneyCost.add(pTotalMoney);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ resultMap.put("costList", retList);
|
|
|
|
+ resultMap.put("totalMoneyCost", totalMoneyCost);
|
|
|
|
+ httpRespMsg.data = resultMap;
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ List<Map<String, Object>> list = projectMapper.getTimeCostByCategory(companyId, startDate, endDate, null, userId);
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ } catch (NullPointerException e) {
|
|
|
|
+ httpRespMsg.setError("验证失败");
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg exportTimeCostByCategory(String startDate, String endDate, Integer projectCategoryId, String userId, Boolean projectSum, Integer type, HttpServletRequest request) {
|
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
|
+ try {
|
|
|
|
+ Integer companyId = userMapper.selectById(request.getHeader("Token")).getCompanyId();
|
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
+ List<Map<String, Object>> list = projectMapper.getTimeCostByCategory(companyId, startDate, endDate, projectCategoryId, userId);
|
|
|
|
+ BigDecimal totalMoneyCost = BigDecimal.valueOf(0);
|
|
|
|
+ List<List<String>> allList=null ;
|
|
|
|
+ List<String> sumRow = null;
|
|
|
|
+ if(type==0){
|
|
|
|
+ List<String> headList = new ArrayList<String>();
|
|
|
|
+ headList.add("项目分类");
|
|
|
|
+ headList.add("工时(h)");
|
|
|
|
+ headList.add("成本(元)");
|
|
|
|
+ allList=new ArrayList<>();
|
|
|
|
+ allList.add(headList);
|
|
|
|
+ double totalCostTime = 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"));
|
|
|
|
+ }
|
|
|
|
+ totalCostTime += (Double)map.get("cost");
|
|
|
|
+ List<String> rowData = new ArrayList<String>();
|
|
|
|
+ rowData.add((String)map.get("categoryName"));
|
|
|
|
+ rowData.add(((Double)map.get("cost")).toString());
|
|
|
|
+ rowData.add(((BigDecimal)map.get("costMoney")).toString());
|
|
|
|
+ allList.add(rowData);
|
|
|
|
+ }
|
|
|
|
+ //合计
|
|
|
|
+ sumRow=new ArrayList<>();
|
|
|
|
+ sumRow.add("合计");
|
|
|
|
+ sumRow.add(""+new BigDecimal(totalCostTime).setScale(1, BigDecimal.ROUND_HALF_UP));
|
|
|
|
+ sumRow.add(totalMoneyCost.toString());
|
|
|
|
+ allList.add(sumRow);
|
|
|
|
+ }else{
|
|
|
|
+ List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", companyId).eq("is_active", 1));
|
|
|
|
+ List<Object> projectCategoryNameS = list.stream().map(mp -> mp.get("categoryName")).collect(Collectors.toList());
|
|
|
|
+ List<Object> projectCategorys = list.stream().map(mp -> mp.get("category")).collect(Collectors.toList());
|
|
|
|
+ List<String> headList = new ArrayList<String>();
|
|
|
|
+ headList.add("人员");
|
|
|
|
+ projectCategoryNameS.forEach(pc->{
|
|
|
|
+ headList.add(String.valueOf(pc)+"/工时");
|
|
|
|
+ headList.add(String.valueOf(pc)+"/成本");
|
|
|
|
+ });
|
|
|
|
+ allList=new ArrayList<>();
|
|
|
|
+ allList.add(headList);
|
|
|
|
+ //统计当前所有项目所有人的时间成本投入
|
|
|
|
+ List<Map<String, Object>> membList = projectMapper.getProjectCostGroupByCategory(companyId,startDate,endDate, projectCategoryId,userId);
|
|
|
|
+ for (User user : userList) {
|
|
|
|
+ boolean flag=false;
|
|
|
|
+ List<Map<String, Object>> mapList = membList.stream().filter(mb -> mb.get("creatorId").equals(user.getId())).collect(Collectors.toList());
|
|
|
|
+ List<String> membRowData=new ArrayList<>();
|
|
|
|
+ membRowData.add(user.getName());
|
|
|
|
+ for(Object i:projectCategorys){
|
|
|
|
+ List<Map<String, Object>> resultList = mapList.stream().filter(mp -> mp.get("category").equals(i)).collect(Collectors.toList());
|
|
|
|
+ if(resultList.size()>0){
|
|
|
|
+ membRowData.add(String.valueOf(resultList.get(0).get("cost")));
|
|
|
|
+ membRowData.add(String.valueOf(resultList.get(0).get("costMoney")));
|
|
|
|
+ }else{
|
|
|
|
+ membRowData.add("");
|
|
|
|
+ membRowData.add("");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(mapList.size()>0){
|
|
|
|
+ allList.add(membRowData);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //生成excel文件导出
|
|
|
|
+ String fileName = "项目成本工时统计_"+System.currentTimeMillis();
|
|
|
|
+ String resp = ExcelUtil.exportGeneralExcelByTitleAndList(fileName , allList, path);
|
|
|
|
+ httpRespMsg.data = resp;
|
|
|
|
+ } catch (NullPointerException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ httpRespMsg.setError("验证失败");
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
private List<Department> getSubDepts(Department dp, List<Department> list) {
|
|
private List<Department> getSubDepts(Department dp, List<Department> list) {
|
|
List<Department> collect = list.stream().filter(l -> dp.getDepartmentId().equals(l.getSuperiorId())).collect(Collectors.toList());;
|
|
List<Department> collect = list.stream().filter(l -> dp.getDepartmentId().equals(l.getSuperiorId())).collect(Collectors.toList());;
|