Ver Fonte

Merge branch 'master' of http://47.100.37.243:10080/wutt/manHourHousekeeper

ZhouRuiTing há 5 anos atrás
pai
commit
6888b1367b

+ 8 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/ScreenshotController.java

@@ -45,5 +45,13 @@ public class ScreenshotController {
         return screenshotService.getTodayScreenshotList(date, userId);
     }
 
+    /**
+     * 获取最近有截图的日期
+     * date 目标日期 格式yyyy-mm-dd
+     */
+    @RequestMapping("/getScreenshotDate")
+    public HttpRespMsg getScreenshotDate(@RequestParam String date) {
+        return screenshotService.getScreenshotDate(date);
+    }
 }
 

+ 3 - 3
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/TimeCalculationController.java

@@ -5,7 +5,6 @@ import com.management.platform.service.TimeCalculationService;
 import com.management.platform.util.HttpRespMsg;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestMapping;
-
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
@@ -31,10 +30,11 @@ public class TimeCalculationController {
     /**
      * 获取某人今日工作时间和其他信息
      * userId 用户id
+     * date 日期
      */
     @RequestMapping("/getTodayWorkingTime")
-    public HttpRespMsg getTodayWorkingTime(@RequestParam String userId) {
-        return timeCalculationService.getTodayWorkingTime(userId);
+    public HttpRespMsg getTodayWorkingTime(@RequestParam String userId, @RequestParam String date) {
+        return timeCalculationService.getTodayWorkingTime(userId, date);
     }
 
     /**

+ 2 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/ScreenshotService.java

@@ -20,6 +20,8 @@ public interface ScreenshotService extends IService<Screenshot> {
 
     HttpRespMsg getTodayScreenshotList(String userId, String date);
 
+    HttpRespMsg getScreenshotDate(String date);
+
     HttpRespMsg saveAndProcessImage(ScreenshotVO screenshotvo);
 
     HttpRespMsg reTestPicMatch(int id);

+ 2 - 2
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/TimeCalculationService.java

@@ -1,7 +1,7 @@
 package com.management.platform.service;
 
-import com.management.platform.entity.TimeCalculation;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.management.platform.entity.TimeCalculation;
 import com.management.platform.util.HttpRespMsg;
 
 import javax.servlet.http.HttpServletRequest;
@@ -15,7 +15,7 @@ import javax.servlet.http.HttpServletRequest;
  * @since 2020-01-09
  */
 public interface TimeCalculationService extends IService<TimeCalculation> {
-    HttpRespMsg getTodayWorkingTime(String userId);
+    HttpRespMsg getTodayWorkingTime(String userId, String date);
 
     HttpRespMsg getDevianceList(Integer pageIndex, Integer pageSize,
                                 String userId, Integer actionCode, String date, HttpServletRequest request);

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

@@ -25,8 +25,10 @@ import javax.servlet.http.HttpServletRequest;
 import java.awt.image.BufferedImage;
 import java.io.*;
 import java.text.SimpleDateFormat;
+import java.time.LocalDate;
 import java.time.LocalTime;
 import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
 import java.util.*;
 import java.util.regex.Pattern;
 
@@ -256,6 +258,46 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
         return httpRespMsg;
     }
 
+    @Override
+    public HttpRespMsg getScreenshotDate(String date) {
+        HttpRespMsg httpRespMsg = new HttpRespMsg();
+        if (screenshotMapper.selectCount(new QueryWrapper<Screenshot>().eq("date_str", date)) > 0) {
+            //当天有截图
+            httpRespMsg.data = date;
+        } else {
+            String futureDateString = screenshotMapper.selectOne(new QueryWrapper<Screenshot>()
+                    .gt("date_str", date)
+                    .orderByAsc("date_str")
+                    .last("LIMIT 1"))
+                    .getDateStr();
+            String historyDateString = screenshotMapper.selectOne(new QueryWrapper<Screenshot>()
+                    .lt("date_str", date)
+                    .orderByDesc("date_str")
+                    .last("LIMIT 1"))
+                    .getDateStr();
+            if (futureDateString == null && historyDateString == null) {
+                httpRespMsg = null;
+            } else if (futureDateString == null) {
+                httpRespMsg.data = historyDateString;
+            } else if (historyDateString == null) {
+                httpRespMsg.data = futureDateString;
+            } else {
+                DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+                LocalDate localDate = LocalDate.parse(date, dateTimeFormatter);
+                LocalDate futureDate = LocalDate.parse(futureDateString, dateTimeFormatter);
+                LocalDate historyDate = LocalDate.parse(historyDateString, dateTimeFormatter);
+                Long future = ChronoUnit.DAYS.between(localDate, futureDate);
+                Long history = ChronoUnit.DAYS.between(historyDate, localDate);
+                if (future >= history) {
+                    httpRespMsg.data = historyDateString;
+                } else {
+                    httpRespMsg.data = futureDateString;
+                }
+            }
+        }
+        return httpRespMsg;
+    }
+
     @Override
     public HttpRespMsg saveAndProcessImage(ScreenshotVO screenshotvo) {
         Map<String, Object> fileMap = UploadFileToFileNameUtil.uploadFile(screenshotvo.getFile(), path);

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

@@ -16,7 +16,6 @@ import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import java.text.DecimalFormat;
 import java.time.LocalDate;
-import java.time.ZoneOffset;
 import java.time.format.DateTimeFormatter;
 import java.time.format.DateTimeParseException;
 import java.util.ArrayList;
@@ -44,20 +43,20 @@ public class TimeCalculationServiceImpl extends ServiceImpl<TimeCalculationMappe
 
     //根据id获取用户名 日期 时间分布
     @Override
-    public HttpRespMsg getTodayWorkingTime(String userId) {
+    public HttpRespMsg getTodayWorkingTime(String userId, String date) {
         HttpRespMsg httpRespMsg = new HttpRespMsg();
         Map<String, Object> resultMap = new HashMap<>();
         //用户名
         resultMap.put("username", userMapper.selectById(userId).getName());
         //日期
-        LocalDate todayDate = LocalDate.now(ZoneOffset.of("+8"));
-        resultMap.put("date", todayDate);
+//        LocalDate todayDate = LocalDate.now(ZoneOffset.of("+8"));
+        resultMap.put("date", date);
         //时间占比 预先定义好长度为11的数组再向里面添加
         Integer[] timeArray = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
         //把当天所有行为分别加在一起装进数组
         List<TimeCalculation> list = timeCalculationMapper.selectList(new QueryWrapper<TimeCalculation>()
                 .eq("user_id", userId)
-                .eq("date", todayDate));
+                .eq("date", date));
         for (TimeCalculation timeCalculation : list) {
             timeArray[timeCalculation.getActionType() + 1] += timeCalculation.getDuration();
         }