Ver código fonte

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

wutt 5 anos atrás
pai
commit
9ee7debf3c

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

@@ -0,0 +1,21 @@
+package com.management.platform.controller;
+
+
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * <p>
+ *  前端控制器
+ * </p>
+ *
+ * @author 吴涛涛
+ * @since 2020-01-09
+ */
+@RestController
+@RequestMapping("/time-calculation")
+public class TimeCalculationController {
+
+}
+

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

@@ -0,0 +1,77 @@
+package com.management.platform.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import java.time.LocalDate;
+import com.baomidou.mybatisplus.annotation.TableId;
+import java.time.LocalTime;
+import com.baomidou.mybatisplus.annotation.TableField;
+import java.io.Serializable;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author 吴涛涛
+ * @since 2020-01-09
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+public class TimeCalculation extends Model<TimeCalculation> {
+
+    private static final long serialVersionUID=1L;
+
+    /**
+     * 时间记录表主键
+     */
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    /**
+     * 用户表主键
+     */
+    @TableField("user_id")
+    private String userId;
+
+    /**
+     * 行为代码 等价于screenshot表中的pic_type
+     */
+    @TableField("action_type")
+    private Integer actionType;
+
+    /**
+     * 日期
+     */
+    @TableField("date")
+    private LocalDate date;
+
+    /**
+     * 开始时间
+     */
+    @TableField("start_time")
+    private LocalTime startTime;
+
+    /**
+     * 结束时间
+     */
+    @TableField("end_time")
+    private LocalTime endTime;
+
+    /**
+     * 持续时间
+     */
+    @TableField("duration")
+    private Double duration;
+
+
+    @Override
+    protected Serializable pkVal() {
+        return this.id;
+    }
+
+}

+ 16 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/mapper/TimeCalculationMapper.java

@@ -0,0 +1,16 @@
+package com.management.platform.mapper;
+
+import com.management.platform.entity.TimeCalculation;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author 吴涛涛
+ * @since 2020-01-09
+ */
+public interface TimeCalculationMapper extends BaseMapper<TimeCalculation> {
+
+}

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

@@ -0,0 +1,16 @@
+package com.management.platform.service;
+
+import com.management.platform.entity.TimeCalculation;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author 吴涛涛
+ * @since 2020-01-09
+ */
+public interface TimeCalculationService extends IService<TimeCalculation> {
+
+}

+ 3 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ProjectServiceImpl.java

@@ -27,6 +27,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
     @Resource
     private ReportMapper reportMapper;
 
+    //获取项目列表
     @Override
     public HttpRespMsg getProjectList() {
         HttpRespMsg httpRespMsg = new HttpRespMsg();
@@ -34,6 +35,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
         return httpRespMsg;
     }
 
+    //添加或编辑项目
     @Override
     public HttpRespMsg editProject(Integer id, String name) {
         HttpRespMsg httpRespMsg = new HttpRespMsg();
@@ -55,6 +57,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
         return httpRespMsg;
     }
 
+    //删除项目
     @Override
     public HttpRespMsg deleteProject(Integer id) {
         HttpRespMsg httpRespMsg = new HttpRespMsg();

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

@@ -37,8 +37,10 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
     @Override
     public HttpRespMsg getReportList(String date) {
         HttpRespMsg httpRespMsg = new HttpRespMsg();
+        //首先根据日期获取当天所有提交过日志的人
         List<Map<String, Object>> nameList = reportMapper.getReportNameByDate(date);
         for (Map<String, Object> map : nameList) {
+            //再根据人分别获取当天的报告
             map.put("data", reportMapper.getReportByDate(date, (String) map.get("id")));
         }
         httpRespMsg.data = nameList;

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

@@ -7,9 +7,12 @@ import com.management.platform.constant.Constant;
 import com.management.platform.constant.Parameter;
 import com.management.platform.entity.PicContentKeywords;
 import com.management.platform.entity.Screenshot;
+import com.management.platform.entity.TimeCalculation;
 import com.management.platform.entity.vo.ScreenshotVO;
 import com.management.platform.mapper.PicContentKeywordsMapper;
+import com.management.platform.mapper.PicContentKeywordsMapper;
 import com.management.platform.mapper.ScreenshotMapper;
+import com.management.platform.mapper.TimeCalculationMapper;
 import com.management.platform.service.ScreenshotService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.management.platform.util.*;
@@ -21,9 +24,8 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
-import javax.annotation.Resources;
 import java.text.SimpleDateFormat;
-import java.time.LocalDateTime;
+import java.time.LocalTime;
 import java.time.format.DateTimeFormatter;
 import java.util.HashSet;
 import java.util.List;
@@ -44,6 +46,9 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
 
     public static Logger log = Logger.getLogger(ScreenshotServiceImpl.class);
 
+    //检测时间间隔秒数
+    private static Long DETECTION_INTERVAL = 600L;
+
     @Value(value = "${upload.path}")
     private String path;
 
@@ -56,12 +61,17 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
     @Resource
     private PicContentKeywordsMapper picContentKeywordsMapper;
 
+    @Resource
+    private TimeCalculationMapper timeCalculationMapper;
+
     //获取所有人最新的截图
     @Override
     public HttpRespMsg getLatestScreenshotList() {
         HttpRespMsg httpRespMsg = new HttpRespMsg();
+        //获取每一个人最后一张截图
         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.remove("indate");
         }
@@ -104,7 +114,7 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
             members = redisUtil.members(Constant.COMMON_SOFTWARE_KEYWORDS);
         }
         List<String> exeprocessList = ProcessUtil.getExeprocessListfromProcessStr(screenshotvo.getProcessList());
-        System.out.println("進程"+exeprocessList);
+        System.out.println("進程" + exeprocessList);
         boolean derail = false;//判断是否匹配的开关
         Integer lastType = null;
         for (String textContent : textContents) {
@@ -140,4 +150,58 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
         screenshotMapper.insert(screenshot);
         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("=====工作时长统计失败 缺少用户或时间数据=====");
+        }
+    }
 }

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

@@ -0,0 +1,20 @@
+package com.management.platform.service.impl;
+
+import com.management.platform.entity.TimeCalculation;
+import com.management.platform.mapper.TimeCalculationMapper;
+import com.management.platform.service.TimeCalculationService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author 吴涛涛
+ * @since 2020-01-09
+ */
+@Service
+public class TimeCalculationServiceImpl extends ServiceImpl<TimeCalculationMapper, TimeCalculation> implements TimeCalculationService {
+
+}

+ 1 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/util/CodeGenerator.java

@@ -204,7 +204,7 @@ public class CodeGenerator {
         //若想要生成的实体类继承某个Controller,则可打开下面注释。写上需要继承的Controller的位置即可
 //        strategy.setSuperControllerClass("com.baomidou.ant.common.BaseController");
         //此处user是表名,多个英文逗号分割
-//        strategy.setInclude("report");
+        strategy.setInclude("time_calculation");
 //        strategy.setExclude();//数据库表全生成
 //        strategy.setInclude(scanner("user").split(","));//表名,多个英文逗号分割
         strategy.setControllerMappingHyphenStyle(true);

+ 21 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/resources/mapper/TimeCalculationMapper.xml

@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.management.platform.mapper.TimeCalculationMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.management.platform.entity.TimeCalculation">
+        <id column="id" property="id" />
+        <result column="user_id" property="userId" />
+        <result column="action_type" property="actionType" />
+        <result column="date" property="date" />
+        <result column="start_time" property="startTime" />
+        <result column="end_time" property="endTime" />
+        <result column="duration" property="duration" />
+    </resultMap>
+
+    <!-- 通用查询结果列 -->
+    <sql id="Base_Column_List">
+        id, user_id, action_type, date, start_time, end_time, duration
+    </sql>
+
+</mapper>