Commit c8583e92 authored by 赵啸非's avatar 赵啸非

整理代码

parent 0b5188d1
...@@ -28,6 +28,7 @@ import com.mortals.framework.service.impl.AbstractCRUDServiceImpl; ...@@ -28,6 +28,7 @@ import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.xhx.module.attendance.dao.AttendanceRecordHikDao; import com.mortals.xhx.module.attendance.dao.AttendanceRecordHikDao;
import com.mortals.framework.model.Context; import com.mortals.framework.model.Context;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StopWatch;
import java.util.*; import java.util.*;
...@@ -101,6 +102,9 @@ public class AttendanceRecordHikServiceImpl extends AbstractCRUDServiceImpl<Atte ...@@ -101,6 +102,9 @@ public class AttendanceRecordHikServiceImpl extends AbstractCRUDServiceImpl<Atte
public void addAttendanceOtherRecordList(List<AttendanceRecordHikEntity> hikEntityList, AttendanceRecordHikEntity attendanceRecordHikQuery, Context context) throws Exception { public void addAttendanceOtherRecordList(List<AttendanceRecordHikEntity> hikEntityList, AttendanceRecordHikEntity attendanceRecordHikQuery, Context context) throws Exception {
StopWatch stopWatch = new StopWatch("stopwatch stat attendance");//耗时计算
stopWatch.start("数据获取");
List<AttendanceRecordHikEntity> collect = hikEntityList.stream().sorted(Comparator.comparing(AttendanceRecordHikEntity::getAttendanceDate)).collect(Collectors.toList()); List<AttendanceRecordHikEntity> collect = hikEntityList.stream().sorted(Comparator.comparing(AttendanceRecordHikEntity::getAttendanceDate)).collect(Collectors.toList());
Map<Long, List<AttendanceRecordHikEntity>> listMap = collect.stream().collect(Collectors.groupingBy(AttendanceRecordHikEntity::getStaffId)); Map<Long, List<AttendanceRecordHikEntity>> listMap = collect.stream().collect(Collectors.groupingBy(AttendanceRecordHikEntity::getStaffId));
Map<Long, List<AttendanceGroupStaffEntity>> groupStaffMap = attendanceGroupStaffService.find(new AttendanceGroupStaffQuery()).parallelStream().collect(Collectors.groupingBy(x -> x.getStaffId())); Map<Long, List<AttendanceGroupStaffEntity>> groupStaffMap = attendanceGroupStaffService.find(new AttendanceGroupStaffQuery()).parallelStream().collect(Collectors.groupingBy(x -> x.getStaffId()));
...@@ -116,11 +120,14 @@ public class AttendanceRecordHikServiceImpl extends AbstractCRUDServiceImpl<Atte ...@@ -116,11 +120,14 @@ public class AttendanceRecordHikServiceImpl extends AbstractCRUDServiceImpl<Atte
query.setAttendanceDateStart(attendanceDateStart); query.setAttendanceDateStart(attendanceDateStart);
query.setAttendanceDateEnd(attendanceDateEnd); query.setAttendanceDateEnd(attendanceDateEnd);
Map<Long, AttendanceRecordEntity> staffRecordMap = attendanceRecordService.find(query).parallelStream().collect(Collectors.toMap(x -> x.getStaffId(), y -> y, (o, n) -> n)); Map<Long, AttendanceRecordEntity> staffRecordMap = attendanceRecordService.find(query).parallelStream().collect(Collectors.toMap(x -> x.getStaffId(), y -> y, (o, n) -> n));
stopWatch.stop();
log.info("考勤数据获取耗时:{}ms", stopWatch.getLastTaskTimeMillis());
//获取日期 //获取日期
List<AttendanceRecordEntity> saveList = new ArrayList<>(); List<AttendanceRecordEntity> saveList = new ArrayList<>();
List<AttendanceRecordEntity> updateList = new ArrayList<>(); List<AttendanceRecordEntity> updateList = new ArrayList<>();
listMap.entrySet().stream().forEach(itemEntry -> { listMap.entrySet().stream().forEach(itemEntry -> {
//按人员 todo 改为多线程并行计算 //按人员 todo 改为多线程并行计算
stopWatch.start("人员计算耗时");
Long staffId = itemEntry.getKey(); Long staffId = itemEntry.getKey();
List<AttendanceRecordHikEntity> recordHikEntityList = itemEntry.getValue(); List<AttendanceRecordHikEntity> recordHikEntityList = itemEntry.getValue();
Map<String, List<AttendanceRecordHikEntity>> dateRecordMap = recordHikEntityList.stream().collect(Collectors.groupingBy(hikEntity -> DateUtil.formatDate(hikEntity.getAttendanceDate()))); Map<String, List<AttendanceRecordHikEntity>> dateRecordMap = recordHikEntityList.stream().collect(Collectors.groupingBy(hikEntity -> DateUtil.formatDate(hikEntity.getAttendanceDate())));
...@@ -242,9 +249,11 @@ public class AttendanceRecordHikServiceImpl extends AbstractCRUDServiceImpl<Atte ...@@ -242,9 +249,11 @@ public class AttendanceRecordHikServiceImpl extends AbstractCRUDServiceImpl<Atte
saveList.add(attendanceRecordEntity); saveList.add(attendanceRecordEntity);
} }
} }
stopWatch.stop();
log.info("考勤数据计算耗时:{}ms", stopWatch.getLastTaskTimeMillis());
} }
}); });
// } stopWatch.start("考勤新增与更新耗时");
if (!ObjectUtils.isEmpty(saveList)) { if (!ObjectUtils.isEmpty(saveList)) {
log.info("新增考勤记录数:" + saveList.size()); log.info("新增考勤记录数:" + saveList.size());
attendanceRecordService.save(saveList); attendanceRecordService.save(saveList);
...@@ -254,6 +263,8 @@ public class AttendanceRecordHikServiceImpl extends AbstractCRUDServiceImpl<Atte ...@@ -254,6 +263,8 @@ public class AttendanceRecordHikServiceImpl extends AbstractCRUDServiceImpl<Atte
log.info("更新考勤记录数:" + updateList.size()); log.info("更新考勤记录数:" + updateList.size());
attendanceRecordService.update(updateList); attendanceRecordService.update(updateList);
} }
stopWatch.stop();
log.info("考勤数据新增与更新耗时:{}ms", stopWatch.getLastTaskTimeMillis());
} }
public void addAttendanceRecordList(List<AttendanceRecordHikEntity> hikEntityList, Context context) throws Exception { public void addAttendanceRecordList(List<AttendanceRecordHikEntity> hikEntityList, Context context) throws Exception {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment