|
@@ -8580,4 +8580,84 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
|
msg.setData(actualEmployeeTimes);
|
|
|
return msg;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg getCustomDataWithDate(String startDate, String endDate, HttpServletRequest request) {
|
|
|
+ HttpRespMsg httpRespMsg=new HttpRespMsg();
|
|
|
+ Integer companyId = userMapper.selectById(request.getHeader("token")).getCompanyId();
|
|
|
+ DateTimeFormatter df=DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ List<LocalDate> dateList = getDays(LocalDate.parse(startDate,df), LocalDate.parse(endDate,df));
|
|
|
+ //检查是否有查看全公司数值的权限
|
|
|
+ User curUser = userMapper.selectById(request.getHeader("TOKEN"));
|
|
|
+ List<SysRichFunction> functionList = sysFunctionMapper.getRoleFunctions(curUser.getRoleId(), "查看全公司数值");
|
|
|
+ List<Map<String,Object>> mapList=reportMapper.getCustomDataWithDate(startDate,endDate,companyId);
|
|
|
+ if(functionList==null){
|
|
|
+ mapList=new ArrayList<>();
|
|
|
+ }
|
|
|
+ Map<String, List<Map<String, Object>>> tempMap = new HashMap<>();
|
|
|
+ List<Map<String,Object>> createDateList = new ArrayList<>();
|
|
|
+ Double totalCost = 0.0;
|
|
|
+ //结果集中默认加上不存在的日期数据
|
|
|
+ for (LocalDate date : dateList) {
|
|
|
+ String dateString = df.format(date);
|
|
|
+ Optional<Map<String, Object>> first = mapList.stream().filter(m -> String.valueOf(m.get("createDate")).equals(dateString)).findFirst();
|
|
|
+ if(!first.isPresent()){
|
|
|
+ Map<String,Object> map=new HashMap<>();
|
|
|
+ map.put("createDate",dateString);
|
|
|
+ map.put("project","");
|
|
|
+ map.put("cost",Double.valueOf(0));
|
|
|
+ mapList.add(map);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ mapList = mapList.stream().sorted(Comparator.comparing(m->LocalDate.parse(String.valueOf(m.get("createDate")),df))).collect(Collectors.toList());
|
|
|
+ for (Map<String, Object> map : mapList) {
|
|
|
+ if (tempMap.containsKey(map.get("createDate"))) {
|
|
|
+ //这个名字已经装进数组中了
|
|
|
+ List<Map<String, Object>> tempList = tempMap.get(map.get("createDate"));
|
|
|
+ Map<String, Object> dataMap = new HashMap<>();
|
|
|
+ dataMap.put("project", map.get("project"));
|
|
|
+ Double cost = (Double) map.getOrDefault("cost", 0);
|
|
|
+ totalCost = totalCost + cost;
|
|
|
+ dataMap.put("cost", cost);
|
|
|
+ tempList.add(dataMap);
|
|
|
+ } else {
|
|
|
+ Map<String,Object> createMap=new HashMap<>();
|
|
|
+ createMap.put("createDate",(String)map.get("createDate"));
|
|
|
+ createDateList.add(createMap);
|
|
|
+ //这个名字尚未装进数组中
|
|
|
+ List<Map<String, Object>> tempList = new ArrayList<>();
|
|
|
+ if (map.containsKey("project")) {
|
|
|
+ Map<String, Object> dataMap = new HashMap<>();
|
|
|
+ dataMap.put("project", map.get("project"));
|
|
|
+ Double cost = (Double) map.getOrDefault("cost", 0);
|
|
|
+ totalCost = totalCost + cost;
|
|
|
+ dataMap.put("cost", cost);
|
|
|
+ tempList.add(dataMap);
|
|
|
+ }
|
|
|
+ tempMap.put((String) map.get("createDate"), tempList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Map<String, Object> finalMap = new HashMap<>();
|
|
|
+ List<Map<String, Object>> finalList = new ArrayList<>();
|
|
|
+ for (String key : tempMap.keySet()) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("name", key);
|
|
|
+ List<Map<String, Object>> userProjectTime = tempMap.get(key);
|
|
|
+ map.put("project", userProjectTime);
|
|
|
+ //计算总时间
|
|
|
+ double userTotalTime = 0;
|
|
|
+ for (Map<String, Object> timeItem: userProjectTime) {
|
|
|
+ double t = (double)timeItem.get("cost");
|
|
|
+ userTotalTime += t;
|
|
|
+ }
|
|
|
+ map.put("cost", userTotalTime);
|
|
|
+ finalList.add(map);
|
|
|
+ }
|
|
|
+ finalList=finalList.stream().sorted(Comparator.comparing(m->LocalDate.parse(String.valueOf(m.get("name")),df))).collect(Collectors.toList());
|
|
|
+ finalMap.put("totalCost", totalCost);
|
|
|
+ finalMap.put("list", finalList);
|
|
|
+ finalMap.put("createDateList",createDateList);
|
|
|
+ httpRespMsg.data = finalMap;
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
}
|