|
@@ -7,9 +7,12 @@ import com.management.platform.constant.Constant;
|
|
import com.management.platform.constant.Parameter;
|
|
import com.management.platform.constant.Parameter;
|
|
import com.management.platform.entity.PicContentKeywords;
|
|
import com.management.platform.entity.PicContentKeywords;
|
|
import com.management.platform.entity.Screenshot;
|
|
import com.management.platform.entity.Screenshot;
|
|
|
|
+import com.management.platform.entity.TimeCalculation;
|
|
import com.management.platform.entity.vo.ScreenshotVO;
|
|
import com.management.platform.entity.vo.ScreenshotVO;
|
|
import com.management.platform.mapper.PicContentKeywordsMapper;
|
|
import com.management.platform.mapper.PicContentKeywordsMapper;
|
|
|
|
+import com.management.platform.mapper.PicContentKeywordsMapper;
|
|
import com.management.platform.mapper.ScreenshotMapper;
|
|
import com.management.platform.mapper.ScreenshotMapper;
|
|
|
|
+import com.management.platform.mapper.TimeCalculationMapper;
|
|
import com.management.platform.service.ScreenshotService;
|
|
import com.management.platform.service.ScreenshotService;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.management.platform.util.*;
|
|
import com.management.platform.util.*;
|
|
@@ -21,9 +24,8 @@ import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
-import javax.annotation.Resources;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
-import java.time.LocalDateTime;
|
|
|
|
|
|
+import java.time.LocalTime;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.util.HashSet;
|
|
import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -44,6 +46,9 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
|
|
|
|
|
|
public static Logger log = Logger.getLogger(ScreenshotServiceImpl.class);
|
|
public static Logger log = Logger.getLogger(ScreenshotServiceImpl.class);
|
|
|
|
|
|
|
|
+ //检测时间间隔秒数
|
|
|
|
+ private static Long DETECTION_INTERVAL = 600L;
|
|
|
|
+
|
|
@Value(value = "${upload.path}")
|
|
@Value(value = "${upload.path}")
|
|
private String path;
|
|
private String path;
|
|
|
|
|
|
@@ -56,12 +61,17 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
|
|
@Resource
|
|
@Resource
|
|
private PicContentKeywordsMapper picContentKeywordsMapper;
|
|
private PicContentKeywordsMapper picContentKeywordsMapper;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private TimeCalculationMapper timeCalculationMapper;
|
|
|
|
+
|
|
//获取所有人最新的截图
|
|
//获取所有人最新的截图
|
|
@Override
|
|
@Override
|
|
public HttpRespMsg getLatestScreenshotList() {
|
|
public HttpRespMsg getLatestScreenshotList() {
|
|
HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
|
+ //获取每一个人最后一张截图
|
|
List<Map<String, Object>> resultMap = screenshotMapper.getLatestScreenshotList();
|
|
List<Map<String, Object>> resultMap = screenshotMapper.getLatestScreenshotList();
|
|
- for(Map<String, Object> map : resultMap){
|
|
|
|
|
|
+ for (Map<String, Object> map : resultMap) {
|
|
|
|
+ //对于每一张图 将时间戳转换为时间
|
|
map.put("time", new SimpleDateFormat("HH:mm:ss").format(map.get("indate")));
|
|
map.put("time", new SimpleDateFormat("HH:mm:ss").format(map.get("indate")));
|
|
map.remove("indate");
|
|
map.remove("indate");
|
|
}
|
|
}
|
|
@@ -104,7 +114,7 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
|
|
members = redisUtil.members(Constant.COMMON_SOFTWARE_KEYWORDS);
|
|
members = redisUtil.members(Constant.COMMON_SOFTWARE_KEYWORDS);
|
|
}
|
|
}
|
|
List<String> exeprocessList = ProcessUtil.getExeprocessListfromProcessStr(screenshotvo.getProcessList());
|
|
List<String> exeprocessList = ProcessUtil.getExeprocessListfromProcessStr(screenshotvo.getProcessList());
|
|
- System.out.println("進程"+exeprocessList);
|
|
|
|
|
|
+ System.out.println("進程" + exeprocessList);
|
|
boolean derail = false;//判断是否匹配的开关
|
|
boolean derail = false;//判断是否匹配的开关
|
|
Integer lastType = null;
|
|
Integer lastType = null;
|
|
for (String textContent : textContents) {
|
|
for (String textContent : textContents) {
|
|
@@ -140,4 +150,58 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
|
|
screenshotMapper.insert(screenshot);
|
|
screenshotMapper.insert(screenshot);
|
|
return new HttpRespMsg();
|
|
return new HttpRespMsg();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ //每次获取到截屏后计算并处理
|
|
|
|
+ private void calculateTime(Screenshot screenshot) {
|
|
|
|
+ try {
|
|
|
|
+ //默认状态为不连续 如果下面判断是连续才会修改为true
|
|
|
|
+ Boolean isConsecutive = false;
|
|
|
|
+ //获取本人当天结束时间为准的最后一条记录
|
|
|
|
+ TimeCalculation latestRecord = timeCalculationMapper.selectOne(new QueryWrapper<TimeCalculation>()
|
|
|
|
+ .eq("user_id", screenshot.getUid())
|
|
|
|
+ .eq("date", screenshot.getIndate().toLocalDate())
|
|
|
|
+ .orderByDesc("end_time")
|
|
|
|
+ .last("LIMIT 1"));
|
|
|
|
+ //单独记录当前的时间以便使用
|
|
|
|
+ LocalTime currentTime = screenshot.getIndate().toLocalTime();
|
|
|
|
+ if (latestRecord != null) {
|
|
|
|
+ //如果有记录的话 单独记录原来时间并加上间隔时间 准备进行对比
|
|
|
|
+ LocalTime estimatedTime = latestRecord.getEndTime().plusSeconds(DETECTION_INTERVAL);
|
|
|
|
+ //和当前时间进行对比 如果在小时和分数数相同则认为是连续的 秒和毫秒不考虑
|
|
|
|
+ if (estimatedTime.getHour() == currentTime.getHour()
|
|
|
|
+ && estimatedTime.getMinute() == currentTime.getMinute()) {
|
|
|
|
+ //确认连续 此时将状态改为连续
|
|
|
|
+ isConsecutive = true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (isConsecutive) {
|
|
|
|
+ //如果是连续的话那就准备修改上一条记录的最后时间和持续时间
|
|
|
|
+ LocalTime startTime = latestRecord.getStartTime();
|
|
|
|
+ //计算新的间隔
|
|
|
|
+ Double duration = (double) ((currentTime.getHour() - startTime.getHour()) * 3600
|
|
|
|
+ + (currentTime.getMinute() - startTime.getMinute()) * 60
|
|
|
|
+ + (currentTime.getSecond() - startTime.getSecond())) / 3600;
|
|
|
|
+ //设置新的结束时间和持续时间 保存记录
|
|
|
|
+ latestRecord.setEndTime(currentTime).setDuration(duration);
|
|
|
|
+ timeCalculationMapper.updateById(latestRecord);
|
|
|
|
+ } else {
|
|
|
|
+ //如果不是连续的话 那就准备新增一个记录
|
|
|
|
+ TimeCalculation timeCalculation = new TimeCalculation();
|
|
|
|
+ timeCalculation
|
|
|
|
+ .setUserId(screenshot.getUid())
|
|
|
|
+ //根据截图种类设置行为代号 如果为空则默认为正常 即0
|
|
|
|
+ .setActionType(screenshot.getPicType() != null ? screenshot.getPicType() : 0)
|
|
|
|
+ .setDate(screenshot.getIndate().toLocalDate())
|
|
|
|
+ //设置开始时间和结束时间都为当前时间
|
|
|
|
+ .setStartTime(currentTime)
|
|
|
|
+ .setEndTime(currentTime)
|
|
|
|
+ //第一次的持续时间默认为最短的一次间隔 以后为开始时间和结束时间只差 以防看一眼不计入时间的现象
|
|
|
|
+ .setDuration((double) DETECTION_INTERVAL / 3600);
|
|
|
|
+ timeCalculationMapper.insert(timeCalculation);
|
|
|
|
+ }
|
|
|
|
+ } catch (NullPointerException e) {
|
|
|
|
+ //凡是有空指针说明缺少用户id或者时间数据
|
|
|
|
+ log.info("=====工作时长统计失败 缺少用户或时间数据=====");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|