Просмотр исходного кода

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

wutt 5 лет назад
Родитель
Сommit
d6a1ecd43c

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

@@ -37,6 +37,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
     public HttpRespMsg getProjectList(HttpServletRequest request) {
         HttpRespMsg httpRespMsg = new HttpRespMsg();
         try {
+            //通过公司id获取该公司所有的项目列表
             Integer companyId = userMapper.selectById(request.getHeader("Token")).getCompanyId();
             httpRespMsg.data = projectMapper.selectList(new QueryWrapper<Project>().eq("company_id", companyId));
         } catch (NullPointerException e) {

+ 13 - 9
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ReportServiceImpl.java

@@ -73,6 +73,7 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
         return httpRespMsg;
     }
 
+    //导出报告
     @Override
     public HttpRespMsg exportReport(String date, HttpServletRequest request) {
         HttpRespMsg httpRespMsg = new HttpRespMsg();
@@ -82,7 +83,7 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
             HSSFSheet sheet = workbook.createSheet(date + "日报");
             //创建表头
             HSSFRow headRow = sheet.createRow(0);
-            //设置列宽 setColumnWidth的第二个参数要乘以256这个参数的单位是1/256个字符宽度
+            //设置列宽 setColumnWidth的第二个参数要乘以256 这个参数的单位是1/256个字符宽度
             sheet.setColumnWidth(0, 5 * 256);
             sheet.setColumnWidth(1, 10 * 256);
             sheet.setColumnWidth(2, 20 * 256);
@@ -94,7 +95,7 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
             HSSFFont font = workbook.createFont();
             font.setBold(true);
             headStyle.setFont(font);
-
+            //表头
             HSSFCell headCell;
             headCell = headRow.createCell(0);
             headCell.setCellValue("序号");
@@ -114,11 +115,10 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
             headCell = headRow.createCell(5);
             headCell.setCellValue("提交时间");
             headCell.setCellStyle(headStyle);
-
             //设置日期格式
             HSSFCellStyle style = workbook.createCellStyle();
             style.setDataFormat(HSSFDataFormat.getBuiltinFormat("yy/mm/dd hh:mm"));
-            //新增数据行,并且设置单元格数据
+            //新增数据行 并且装填数据
             int rowNum = 1;
             for (Map<String, Object> map : reportMapper.getAllReportByDate(date)) {
                 HSSFRow row = sheet.createRow(rowNum);
@@ -133,13 +133,13 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
                 cell.setCellStyle(style);
                 rowNum++;
             }
-
             //生成Excel文件
             String fileUrlSuffix = date + "日报" + new SimpleDateFormat("hh-mm-ss").format(new Date()) + ".xls";
             FileOutputStream fos = new FileOutputStream(path + fileUrlSuffix);
             workbook.write(fos);
             fos.flush();
             fos.close();
+            //返回生成的文件地址/upload文件夹下
             httpRespMsg.data = "/upload/" + fileUrlSuffix;
         } catch (NullPointerException e) {
             httpRespMsg.setError("验证失败或缺少数据");
@@ -163,15 +163,19 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
                     .eq("creator_id", userId)
                     .eq("create_date", LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd")))));
             //顺便再获取一下可分配时间
-            Double totalWorkingTime = 0.0;
-            //此处认为0是工作时间
+            Integer totalWorkingTime = 0;
+            //以下区间被认为是工作时间
+            Integer[] workType = {-1, 0, 1, 2, 3, 4, 5};
+            //工作时间筛选
             for (TimeCalculation timeCalculation : timeCalculationMapper.selectList(new QueryWrapper<TimeCalculation>()
                     .eq("date", LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd")))
                     .eq("user_id", userId)
-                    .eq("action_type", 0))) {
+                    .in("action_type", workType))) {
                 totalWorkingTime += timeCalculation.getDuration();
             }
-            resultMap.put("time", new DecimalFormat("#.00").format(totalWorkingTime / 3600));
+            //把总秒数转为double后换算为小时并保留两位小数
+            resultMap.put("time", new DecimalFormat("#.00").format((double) totalWorkingTime / 3600));
+            //顺便返回该公司全部的计划
             resultMap.put("project", projectMapper.selectList(new QueryWrapper<Project>()
                     .eq("company_id", userMapper.selectById(userId).getCompanyId())));
             httpRespMsg.data = resultMap;

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

@@ -464,14 +464,14 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
             //单独记录当前的时间以便使用
             LocalTime currentTime = screenshot.getIndate().toLocalTime();
             if (latestRecord != null) {
-                //首先对比类型
+                //首先对比类型 同一种行为才有可能合并
                 if (latestRecord.getActionType().equals(screenshot.getPicType())) {
-                    //如果有记录的话 准备计算上次结束和新的开始的时间差
+                    //如果有记录的话 计算上次结束和新的开始的时间差
                     LocalTime estimatedTime = latestRecord.getEndTime();
                     Integer durationSecond = ((currentTime.getHour() - estimatedTime.getHour()) * 3600
                             + (currentTime.getMinute() - estimatedTime.getMinute()) * 60
                             + (currentTime.getSecond() - estimatedTime.getSecond()));
-                    //断层不大于600秒的话
+                    //断层不大于一定时间的话 这个定义目前为600秒
                     if (durationSecond <= DETECTION_INTERVAL) {
                         //确认连续 将状态改为连续
                         isConsecutive = true;
@@ -479,7 +479,7 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
                 }
             }
             if (isConsecutive) {
-                //如果是连续的话那就准备修改上一条记录的最后时间和持续时间
+                //如果是连续的话 修改上一条记录的最后时间和持续时间
                 LocalTime startTime = latestRecord.getStartTime();
                 //计算新的间隔
                 Integer duration = ((currentTime.getHour() - startTime.getHour()) * 3600
@@ -489,7 +489,7 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
                 latestRecord.setEndTime(currentTime).setDuration(duration);
                 timeCalculationMapper.updateById(latestRecord);
             } else {
-                //如果不是连续的话 那就准备新增一个记录
+                //如果不是连续的话 新增一个记录
                 TimeCalculation timeCalculation = new TimeCalculation();
                 timeCalculation
                         .setUserId(screenshot.getUid())

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

@@ -47,6 +47,7 @@ public class TimeCalculationServiceImpl extends ServiceImpl<TimeCalculationMappe
         resultMap.put("date", todayDate);
         //时间占比 预先定义好长度为9的数组再向里面添加
         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))) {
@@ -85,7 +86,7 @@ public class TimeCalculationServiceImpl extends ServiceImpl<TimeCalculationMappe
         try {
             List<Map<String, Object>> resultList = new ArrayList<>();
             Integer companyId = userMapper.selectById(request.getHeader("Token")).getCompanyId();
-            //首先获取某日期有截图的人
+            //首先获取某日期同一个公司下全部有记录的人
             for (Map<String, Object> userMap : timeCalculationMapper.getTodayStatisticsUser(date, companyId)) {
                 //对于每一个人 首先记录下姓名和电话号码
                 Map<String, Object> map = new HashMap<>();
@@ -105,6 +106,7 @@ public class TimeCalculationServiceImpl extends ServiceImpl<TimeCalculationMappe
                 resultArray[2] = timeArray[3] + timeArray[4];
                 resultArray[3] = timeArray[5];
                 resultArray[4] = timeArray[6] + timeArray[7] + timeArray[8];
+                //将后端的9中行为类型分门别类转换为前端的5种并转换为字符串格式
                 String[] stringArray = new String[5];
                 for (int i = 0; i < 5; i++) {
                     stringArray[i] = convertSecond(resultArray[i]);
@@ -133,27 +135,35 @@ public class TimeCalculationServiceImpl extends ServiceImpl<TimeCalculationMappe
         try {
             LocalDate start = LocalDate.parse(startDate, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
             LocalDate end = LocalDate.parse(endDate, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
-            //首先获取数据
+            //获取时间段内本人全部的工作记录 娱乐6 7 8不计入
+            Integer[] workType = {-1, 0, 1, 2, 3, 4, 5};
             List<TimeCalculation> dataList = timeCalculationMapper.selectList(new QueryWrapper<TimeCalculation>()
                     .eq("user_id", request.getHeader("Token"))
-                    .eq("action_type", 0)
+                    .in("action_type", workType)
                     .between("date", start, end)
                     .orderByAsc("start_time"));
             //先把所有的日期搞到一个list里面
             ArrayList<String> dateList = new ArrayList<>();
             LocalDate currentDate = start;
+            //从开始日期一直到结束日期的每一天 为了防止死循环最多100天 当然说不定可以再多一点
             for (int i = 0; !currentDate.equals(end.plusDays(1)) || ++i >= 100; currentDate = currentDate.plusDays(1)) {
+                //把这一天以字符串形式保存到list中
                 dateList.add(currentDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
             }
             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<>();
+                //遍历所有时间记录
                 for (TimeCalculation timeCalculation : dataList) {
+                    //如果这一天就是我们需要的那天的话
                     if (timeCalculation.getDate().toString().equals(date)) {
                         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")));
                         Integer todayTime = timeCalculation.getDuration();
@@ -161,9 +171,10 @@ public class TimeCalculationServiceImpl extends ServiceImpl<TimeCalculationMappe
                         total += todayTime;
                         list.add(map);
                     }
+                    /*这个时间复杂度巨几把高的for循环可以用某种算法优化 至少计算过的应该排除才对*/
                 }
                 dataMap.put("time", list);
-                //这里检查如果只有一天记录的话那就再多计算一个当天总工作时间
+                //这里检查如果只需要一天记录的话 说明是pc端界面那个地方 那就再多计算一个当天总工作时间
                 if (dateList.size() == 1) {
                     dataMap.put("total", total);
                 }
@@ -190,6 +201,7 @@ public class TimeCalculationServiceImpl extends ServiceImpl<TimeCalculationMappe
         return hour + "小时" + minute + "分" + second + "秒";
     }
 
+    //秒数转化为时间字符串 Long参数豪华限定版
     private static String convertSecond(Long time) {
         Long hour = 0L, minute = 0L, second = 0L;
         hour = time / 3600;

+ 1 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/UserServiceImpl.java

@@ -62,6 +62,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
             //检测密码正确时
             UserVO userVO = new UserVO();
             BeanUtils.copyProperties(userList.get(0), userVO);
+            //还要多返回一个公司名字
             userVO.setCompanyName(companyMapper.selectById(userVO.getCompanyId()).getCompanyName());
             httpRespMsg.data = userVO;
         } else {
@@ -324,7 +325,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
         try {
             User requester = userMapper.selectById(request.getHeader("Token")),
                     target = userMapper.selectById(id);
-            //管理员只能新增员工
             if (requester.getRole() != 1) {
                 httpRespMsg.setError("仅负责人有权限更改其他人员权限");
             } else if (!target.getCompanyId().equals(requester.getCompanyId())) {