Quellcode durchsuchen

持续时间单位修改为秒

Reiskuchen vor 5 Jahren
Ursprung
Commit
cc46bb763b

+ 3 - 3
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/entity/TimeCalculation.java

@@ -17,7 +17,7 @@ import lombok.experimental.Accessors;
  * </p>
  *
  * @author 吴涛涛
- * @since 2020-01-09
+ * @since 2020-01-16
  */
 @Data
 @EqualsAndHashCode(callSuper = false)
@@ -63,10 +63,10 @@ public class TimeCalculation extends Model<TimeCalculation> {
     private LocalTime endTime;
 
     /**
-     * 持续时间
+     * 持续时间
      */
     @TableField("duration")
-    private Double duration;
+    private Integer duration;
 
 
     @Override

+ 4 - 4
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ScreenshotServiceImpl.java

@@ -437,9 +437,9 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
                 //如果是连续的话那就准备修改上一条记录的最后时间和持续时间
                 LocalTime startTime = latestRecord.getStartTime();
                 //计算新的间隔
-                Double duration = (double) ((currentTime.getHour() - startTime.getHour()) * 3600
+                Integer duration = ((currentTime.getHour() - startTime.getHour()) * 3600
                         + (currentTime.getMinute() - startTime.getMinute()) * 60
-                        + (currentTime.getSecond() - startTime.getSecond())) / 3600;
+                        + (currentTime.getSecond() - startTime.getSecond()));
                 //设置新的结束时间和持续时间 保存记录
                 latestRecord.setEndTime(currentTime).setDuration(duration);
                 timeCalculationMapper.updateById(latestRecord);
@@ -454,8 +454,8 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
                         //设置开始时间和结束时间都为当前时间
                         .setStartTime(currentTime)
                         .setEndTime(currentTime)
-                        //第一次的持续时间默认为最短的一次间隔 以后为开始时间和结束时间只差 以防看一眼不计入时间的现象
-                        .setDuration(0.0);
+                        //第一次的持续时间默认为最少单位1秒 不然我看一眼就成了0秒了
+                        .setDuration(1);
                 timeCalculationMapper.insert(timeCalculation);
             }
             /*之后可能还需要处理跨越一天的情况*/

+ 8 - 8
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/TimeCalculationServiceImpl.java

@@ -47,13 +47,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;
     }
@@ -92,15 +92,15 @@ 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};
+                Integer[] timeArray = {0, 0, 0, 0, 0, 0, 0, 0, 0};
                 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")] += (int) dataMap.get("duration");
                 }
-                map.put("statistics", doubleArray);
+                map.put("statistics", timeArray);
                 //最后是数组的和
-                Double sum = 0.0;
-                for (Double singleNumber : doubleArray) {
+                Integer sum = 0;
+                for (Integer singleNumber : timeArray) {
                     sum += singleNumber;
                 }
                 map.put("sum", sum);