|
@@ -118,21 +118,24 @@ public class TimeCalculationServiceImpl extends ServiceImpl<TimeCalculationMappe
|
|
public HttpRespMsg getDuration(String startDate, String endDate, HttpServletRequest request) {
|
|
public HttpRespMsg getDuration(String startDate, String endDate, HttpServletRequest request) {
|
|
HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
try {
|
|
try {
|
|
|
|
+ LocalDate start = LocalDate.parse(startDate, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
|
+ LocalDate end = LocalDate.parse(endDate, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
//首先获取数据
|
|
//首先获取数据
|
|
List<TimeCalculation> dataList = timeCalculationMapper.selectList(new QueryWrapper<TimeCalculation>()
|
|
List<TimeCalculation> dataList = timeCalculationMapper.selectList(new QueryWrapper<TimeCalculation>()
|
|
.eq("user_id", request.getHeader("Token"))
|
|
.eq("user_id", request.getHeader("Token"))
|
|
.eq("action_type", 0)
|
|
.eq("action_type", 0)
|
|
- .between("date",
|
|
|
|
- LocalDate.parse(startDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")),
|
|
|
|
- LocalDate.parse(endDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")))
|
|
|
|
|
|
+ .between("date", start, end)
|
|
.orderByAsc("start_time"));
|
|
.orderByAsc("start_time"));
|
|
- //先把所有的日期搞到一个set里面
|
|
|
|
- Set<String> dateSet = new HashSet<>();
|
|
|
|
- for (TimeCalculation timeCalculation : dataList) {
|
|
|
|
- dateSet.add(timeCalculation.getDate().toString());
|
|
|
|
|
|
+ //先把所有的日期搞到一个list里面
|
|
|
|
+ ArrayList<String> dateList = new ArrayList<>();
|
|
|
|
+ LocalDate currentDate = start;
|
|
|
|
+ int i = 0;/*防止死循环的机制*/
|
|
|
|
+ while (currentDate == end.plusDays(1) && ++i < 1000) {
|
|
|
|
+ dateList.add(currentDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
|
|
|
+ currentDate = currentDate.plusDays(1);
|
|
}
|
|
}
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
|
- for (String date : dateSet) {
|
|
|
|
|
|
+ for (String date : dateList) {
|
|
Map<String, Object> dataMap = new HashMap<>();
|
|
Map<String, Object> dataMap = new HashMap<>();
|
|
dataMap.put("date", date);
|
|
dataMap.put("date", date);
|
|
List<Map<String, Object>> list = new ArrayList<>();
|
|
List<Map<String, Object>> list = new ArrayList<>();
|
|
@@ -143,7 +146,7 @@ public class TimeCalculationServiceImpl extends ServiceImpl<TimeCalculationMappe
|
|
map.put("endTime", timeCalculation.getEndTime().format(DateTimeFormatter.ofPattern("HH:mm")));
|
|
map.put("endTime", timeCalculation.getEndTime().format(DateTimeFormatter.ofPattern("HH:mm")));
|
|
map.put("duration", timeCalculation.getDuration());
|
|
map.put("duration", timeCalculation.getDuration());
|
|
list.add(map);
|
|
list.add(map);
|
|
- /*这里可以有个优化 remove已经读取过的内容 但是加强for好像获取不到索引的亚子*/
|
|
|
|
|
|
+ dataList.remove(timeCalculation);/*这个remove不知道会不会出问题*/
|
|
}
|
|
}
|
|
}
|
|
}
|
|
dataMap.put("time", list);
|
|
dataMap.put("time", list);
|