|
@@ -118,6 +118,7 @@ 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 {
|
|
|
|
+ //首先获取数据
|
|
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)
|
|
@@ -125,13 +126,28 @@ public class TimeCalculationServiceImpl extends ServiceImpl<TimeCalculationMappe
|
|
LocalDate.parse(startDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")),
|
|
LocalDate.parse(startDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")),
|
|
LocalDate.parse(endDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")))
|
|
LocalDate.parse(endDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")))
|
|
.orderByAsc("start_time"));
|
|
.orderByAsc("start_time"));
|
|
- List<Map<String, Object>> resultList = new ArrayList<>();
|
|
|
|
|
|
+ //先把所有的日期搞到一个set里面
|
|
|
|
+ Set<String> dateSet = new HashSet<>();
|
|
for (TimeCalculation timeCalculation : dataList) {
|
|
for (TimeCalculation timeCalculation : dataList) {
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
|
- map.put("startTime", LocalDateTime.of(timeCalculation.getDate(), timeCalculation.getStartTime()));
|
|
|
|
- map.put("endTime", LocalDateTime.of(timeCalculation.getDate(), timeCalculation.getEndTime()));
|
|
|
|
- map.put("duration", timeCalculation.getDuration());
|
|
|
|
- resultList.add(map);
|
|
|
|
|
|
+ dateSet.add(timeCalculation.getDate().toString());
|
|
|
|
+ }
|
|
|
|
+ List<Map<String, Object>> resultList = new ArrayList<>();
|
|
|
|
+ for (String date : dateSet) {
|
|
|
|
+ Map<String, Object> dataMap = new HashMap<>();
|
|
|
|
+ dataMap.put("date", date);
|
|
|
|
+ List<Map<String, Object>> list = new ArrayList<>();
|
|
|
|
+ for (TimeCalculation timeCalculation : dataList) {
|
|
|
|
+ if (timeCalculation.getDate().toString().equals(date)) {
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
+ map.put("startTime", timeCalculation.getStartTime().format(DateTimeFormatter.ofPattern("HH:mm")));
|
|
|
|
+ map.put("endTime", timeCalculation.getEndTime().format(DateTimeFormatter.ofPattern("HH:mm")));
|
|
|
|
+ map.put("duration", timeCalculation.getDuration());
|
|
|
|
+ resultList.add(map);
|
|
|
|
+ /*这里可以有个优化 remove已经读取过的内容 但是加强for好像获取不到索引的亚子*/
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ dataMap.put("time", list);
|
|
|
|
+ resultList.add(dataMap);
|
|
}
|
|
}
|
|
httpRespMsg.data = resultList;
|
|
httpRespMsg.data = resultList;
|
|
} catch (NullPointerException e) {
|
|
} catch (NullPointerException e) {
|