Ver código fonte

返回类型2

Reiskuchen 5 anos atrás
pai
commit
996b66d754

+ 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 = {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())) {