|
@@ -13,7 +13,6 @@ import org.springframework.stereotype.Service;
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.time.LocalDate;
|
|
|
-import java.time.LocalDateTime;
|
|
|
import java.time.ZoneOffset;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.time.format.DateTimeParseException;
|
|
@@ -47,13 +46,13 @@ public class TimeCalculationServiceImpl extends ServiceImpl<TimeCalculationMappe
|
|
|
LocalDate todayDate = LocalDate.now(ZoneOffset.of("+8"));
|
|
|
resultMap.put("date", todayDate);
|
|
|
//时间占比 预先定义好长度为9的数组再向里面添加
|
|
|
- Double[] doubleArray = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
|
|
|
+ Integer[] timeArray = {0, 0, 0, 0, 0, 0, 0, 0, 0};
|
|
|
for (TimeCalculation timeCalculation : timeCalculationMapper.selectList(new QueryWrapper<TimeCalculation>()
|
|
|
.eq("user_id", userId)
|
|
|
.eq("date", todayDate))) {
|
|
|
- doubleArray[timeCalculation.getActionType()] += timeCalculation.getDuration();
|
|
|
+ timeArray[timeCalculation.getActionType()] += timeCalculation.getDuration();
|
|
|
}
|
|
|
- resultMap.put("timeDistribution", doubleArray);
|
|
|
+ resultMap.put("timeDistribution", timeArray);
|
|
|
httpRespMsg.data = resultMap;
|
|
|
return httpRespMsg;
|
|
|
}
|
|
@@ -74,6 +73,7 @@ public class TimeCalculationServiceImpl extends ServiceImpl<TimeCalculationMappe
|
|
|
httpRespMsg.data = resultMap;
|
|
|
} catch (NullPointerException e) {
|
|
|
httpRespMsg.setError("验证失败");
|
|
|
+ return httpRespMsg;
|
|
|
}
|
|
|
return httpRespMsg;
|
|
|
}
|
|
@@ -92,23 +92,28 @@ public class TimeCalculationServiceImpl extends ServiceImpl<TimeCalculationMappe
|
|
|
map.put("name", userMap.get("name"));
|
|
|
map.put("phone", userMap.get("phone"));
|
|
|
//然后根据日期和用户id获取到所有的记录 然后手动累加在一起
|
|
|
- Double[] doubleArray = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
|
|
|
+ Long[] timeArray = {0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L};
|
|
|
+ String[] stringArray = new String[9];
|
|
|
for (Map<String, Object> dataMap : timeCalculationMapper
|
|
|
.getTodayStatistics((String) userMap.get("id"), date, companyId)) {
|
|
|
- doubleArray[(int) dataMap.get("type")] += (Double) dataMap.get("duration");
|
|
|
+ timeArray[(int) dataMap.get("type")] += (Long) dataMap.get("duration");
|
|
|
}
|
|
|
- map.put("statistics", doubleArray);
|
|
|
+ for (int i = 0; i < 9; i++) {
|
|
|
+ stringArray[i] = convertSecond(timeArray[i]);
|
|
|
+ }
|
|
|
+ map.put("statistics", stringArray);
|
|
|
//最后是数组的和
|
|
|
- Double sum = 0.0;
|
|
|
- for (Double singleNumber : doubleArray) {
|
|
|
+ Long sum = 0L;
|
|
|
+ for (Long singleNumber : timeArray) {
|
|
|
sum += singleNumber;
|
|
|
}
|
|
|
- map.put("sum", sum);
|
|
|
+ map.put("sum", convertSecond(sum));
|
|
|
resultList.add(map);
|
|
|
}
|
|
|
httpRespMsg.data = resultList;
|
|
|
} catch (NullPointerException e) {
|
|
|
httpRespMsg.setError("验证失败");
|
|
|
+ return httpRespMsg;
|
|
|
}
|
|
|
return httpRespMsg;
|
|
|
}
|
|
@@ -134,6 +139,7 @@ public class TimeCalculationServiceImpl extends ServiceImpl<TimeCalculationMappe
|
|
|
}
|
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
|
|
for (String date : dateList) {
|
|
|
+ Integer total = 0;
|
|
|
Map<String, Object> dataMap = new HashMap<>();
|
|
|
dataMap.put("date", date);
|
|
|
List<Map<String, Object>> list = new ArrayList<>();
|
|
@@ -142,19 +148,46 @@ public class TimeCalculationServiceImpl extends ServiceImpl<TimeCalculationMappe
|
|
|
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());
|
|
|
+ Integer todayTime = timeCalculation.getDuration();
|
|
|
+ map.put("duration", convertSecond(todayTime));
|
|
|
+ total += todayTime;
|
|
|
list.add(map);
|
|
|
}
|
|
|
}
|
|
|
dataMap.put("time", list);
|
|
|
+ //这里检查如果只有一天记录的话那就再多计算一个当天总工作时间
|
|
|
+ if (dateList.size() == 1) {
|
|
|
+ dataMap.put("total", total);
|
|
|
+ }
|
|
|
resultList.add(dataMap);
|
|
|
}
|
|
|
httpRespMsg.data = resultList;
|
|
|
- } catch (NullPointerException e) {
|
|
|
- httpRespMsg.setError("验证失败");
|
|
|
} catch (DateTimeParseException e) {
|
|
|
httpRespMsg.setError("日期格式有误");
|
|
|
+ return httpRespMsg;
|
|
|
+ } catch (NullPointerException e) {
|
|
|
+ httpRespMsg.setError("验证失败");
|
|
|
+ return httpRespMsg;
|
|
|
}
|
|
|
return httpRespMsg;
|
|
|
}
|
|
|
+
|
|
|
+ //秒数转化为时间字符串
|
|
|
+ private static String convertSecond(Integer time) {
|
|
|
+ Integer hour = 0, minute = 0, second = 0;
|
|
|
+ hour = time / 3600;
|
|
|
+ time = time % 3600;
|
|
|
+ minute = time / 60;
|
|
|
+ second = minute % 60;
|
|
|
+ return hour + "小时" + minute + "分" + second + "秒";
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String convertSecond(Long time) {
|
|
|
+ Long hour = 0L, minute = 0L, second = 0L;
|
|
|
+ hour = time / 3600;
|
|
|
+ time = time % 3600;
|
|
|
+ minute = time / 60;
|
|
|
+ second = minute % 60;
|
|
|
+ return hour + "小时" + minute + "分" + second + "秒";
|
|
|
+ }
|
|
|
}
|