|
@@ -26,6 +26,7 @@ import org.joda.time.format.DateTimeFormat;
|
|
|
import org.joda.time.format.DateTimeFormatter;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.data.redis.core.ValueOperations;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -51,6 +52,9 @@ public class WorkScheduleAttendanceServiceImpl implements WorkScheduleAttendance
|
|
|
@Autowired
|
|
|
private ValueOperations<String, Object> valueOperations;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RedisTemplate<String, Object> redisTemplate;
|
|
|
+
|
|
|
@Autowired
|
|
|
private DeviceInfoService deviceInfoService;
|
|
|
|
|
@@ -628,89 +632,89 @@ public class WorkScheduleAttendanceServiceImpl implements WorkScheduleAttendance
|
|
|
int workMinutes = 0;
|
|
|
|
|
|
try {
|
|
|
- WorkShiftInfo workShiftInfo = workShiftInfoService.get(workShiftId);
|
|
|
+ String key = "wsa_" + personScheduleId + "_" + workShiftId + "_" + classify;
|
|
|
|
|
|
- if (workShiftInfo != null) {
|
|
|
- DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm");
|
|
|
+ boolean absent = valueOperations.setIfAbsent(key,true,1,TimeUnit.MINUTES);
|
|
|
|
|
|
- if ("1".equals(classify)) {
|
|
|
- //上班
|
|
|
- DateTime workTime = DateTime.parse(attendanceDate + " " + workShiftInfo.getWorkTime(), formatter);
|
|
|
- workTime = workTime.plusDays(workShiftInfo.getWorkDayType());
|
|
|
+ if(absent) {
|
|
|
+ WorkShiftInfo workShiftInfo = workShiftInfoService.get(workShiftId);
|
|
|
|
|
|
- offsetMinute = Minutes.minutesBetween(new DateTime(recordTime), workTime).getMinutes();
|
|
|
- } else {
|
|
|
- //下班
|
|
|
- DateTime closingTime = DateTime.parse(attendanceDate + " " + workShiftInfo.getClosingTime(), formatter);
|
|
|
- closingTime = closingTime.plusDays(workShiftInfo.getClosingDayType());
|
|
|
+ if (workShiftInfo != null) {
|
|
|
+ DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm");
|
|
|
|
|
|
- offsetMinute = Minutes.minutesBetween(new DateTime(recordTime), closingTime).getMinutes();
|
|
|
+ if ("1".equals(classify)) {
|
|
|
+ //上班
|
|
|
+ DateTime workTime = DateTime.parse(attendanceDate + " " + workShiftInfo.getWorkTime(), formatter);
|
|
|
+ workTime = workTime.plusDays(workShiftInfo.getWorkDayType());
|
|
|
+
|
|
|
+ offsetMinute = Minutes.minutesBetween(new DateTime(recordTime), workTime).getMinutes();
|
|
|
+ } else {
|
|
|
+ //下班
|
|
|
+ DateTime closingTime = DateTime.parse(attendanceDate + " " + workShiftInfo.getClosingTime(), formatter);
|
|
|
+ closingTime = closingTime.plusDays(workShiftInfo.getClosingDayType());
|
|
|
|
|
|
- //计算本班次上班时长(下班时间-上班时间)
|
|
|
- List<WorkScheduleAttendance> onWorkList = workScheduleAttendanceDAO.findByPersonScheduleIdAndClassify(personScheduleId, workShiftId, "1");
|
|
|
+ offsetMinute = Minutes.minutesBetween(new DateTime(recordTime), closingTime).getMinutes();
|
|
|
|
|
|
- if(onWorkList.size()>0){
|
|
|
- WorkScheduleAttendance workStartAttendance = onWorkList.get(0);
|
|
|
+ //计算本班次上班时长(下班时间-上班时间)
|
|
|
+ List<WorkScheduleAttendance> onWorkList = workScheduleAttendanceDAO.findByPersonScheduleIdAndClassify(personScheduleId, workShiftId, "1");
|
|
|
|
|
|
- if(StringUtils.isNotEmpty(workStartAttendance.getResult()) &&
|
|
|
- !"0".equals(workStartAttendance.getResult())){
|
|
|
- workMinutes = Minutes.minutesBetween(
|
|
|
- new DateTime(workStartAttendance.getRecordTime()),
|
|
|
- new DateTime(recordTime))
|
|
|
- .getMinutes();
|
|
|
+ if (onWorkList.size() > 0) {
|
|
|
+ WorkScheduleAttendance workStartAttendance = onWorkList.get(0);
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(workStartAttendance.getResult()) &&
|
|
|
+ !"0".equals(workStartAttendance.getResult())) {
|
|
|
+ workMinutes = Minutes.minutesBetween(
|
|
|
+ new DateTime(workStartAttendance.getRecordTime()),
|
|
|
+ new DateTime(recordTime))
|
|
|
+ .getMinutes();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex){
|
|
|
- log.error(ex.getMessage(),ex);
|
|
|
- }
|
|
|
|
|
|
- WorkScheduleAttendance workEndAttendance = new WorkScheduleAttendance();
|
|
|
+ WorkScheduleAttendance workEndAttendance = new WorkScheduleAttendance();
|
|
|
|
|
|
- List<WorkScheduleAttendance> attendanceList = workScheduleAttendanceDAO.findByPersonScheduleIdAndClassify(personScheduleId, workShiftId, classify);
|
|
|
+ List<WorkScheduleAttendance> attendanceList = workScheduleAttendanceDAO.findByPersonScheduleIdAndClassify(personScheduleId, workShiftId, classify);
|
|
|
|
|
|
- if (attendanceList.size() == 0) {
|
|
|
- workEndAttendance.setId(UUID.randomUUID().toString());
|
|
|
- workEndAttendance.setPersonScheduleId(personScheduleId);
|
|
|
- workEndAttendance.setWorkShiftId(workShiftId);
|
|
|
- workEndAttendance.setAttendanceDate(attendanceDate);
|
|
|
- workEndAttendance.setClassify(classify);
|
|
|
- workEndAttendance.setResult(result);
|
|
|
- workEndAttendance.setLateLeaveMinute(new BigDecimal(minutes));
|
|
|
- workEndAttendance.setWorkStatus(workStatus);
|
|
|
- workEndAttendance.setPersonId(personId);
|
|
|
- workEndAttendance.setDelFlag(false);
|
|
|
- workEndAttendance.setTemperature(temperature);
|
|
|
- workEndAttendance.setRecordTime(recordTime);
|
|
|
- workEndAttendance.setCreateTime(new Date());
|
|
|
- workEndAttendance.setOffsetMinute(new BigDecimal(offsetMinute));
|
|
|
- workEndAttendance.setWorkMinute(new BigDecimal(workMinutes));
|
|
|
-
|
|
|
- if(workOverPerson!=null){
|
|
|
- workEndAttendance.setWorkOverPersonId(workOverPerson.getId());
|
|
|
- }
|
|
|
+ if (attendanceList.size() > 0) {
|
|
|
+ for (WorkScheduleAttendance workScheduleAttendance : attendanceList) {
|
|
|
+ workScheduleAttendance.setDelFlag(true);
|
|
|
+ workScheduleAttendance.setUpdateTime(new Date());
|
|
|
|
|
|
- workScheduleAttendanceDAO.insert(workEndAttendance);
|
|
|
- } else {
|
|
|
- workEndAttendance = attendanceList.get(0);
|
|
|
-
|
|
|
- workEndAttendance.setAttendanceDate(attendanceDate);
|
|
|
- workEndAttendance.setResult(result);
|
|
|
- workEndAttendance.setWorkStatus(workStatus);
|
|
|
- workEndAttendance.setDelFlag(false);
|
|
|
- workEndAttendance.setTemperature(temperature);
|
|
|
- workEndAttendance.setRecordTime(recordTime);
|
|
|
- workEndAttendance.setUpdateTime(new Date());
|
|
|
- workEndAttendance.setOffsetMinute(new BigDecimal(offsetMinute));
|
|
|
- workEndAttendance.setWorkMinute(new BigDecimal(workMinutes));
|
|
|
-
|
|
|
- if(workOverPerson!=null){
|
|
|
- workEndAttendance.setWorkOverPersonId(workOverPerson.getId());
|
|
|
- }
|
|
|
+ workScheduleAttendanceDAO.update(workScheduleAttendance);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- workScheduleAttendanceDAO.update(workEndAttendance);
|
|
|
+ workEndAttendance.setId(UUID.randomUUID().toString());
|
|
|
+ workEndAttendance.setPersonScheduleId(personScheduleId);
|
|
|
+ workEndAttendance.setWorkShiftId(workShiftId);
|
|
|
+ workEndAttendance.setAttendanceDate(attendanceDate);
|
|
|
+ workEndAttendance.setClassify(classify);
|
|
|
+ workEndAttendance.setResult(result);
|
|
|
+ workEndAttendance.setLateLeaveMinute(new BigDecimal(minutes));
|
|
|
+ workEndAttendance.setWorkStatus(workStatus);
|
|
|
+ workEndAttendance.setPersonId(personId);
|
|
|
+ workEndAttendance.setDelFlag(false);
|
|
|
+ workEndAttendance.setTemperature(temperature);
|
|
|
+ workEndAttendance.setRecordTime(recordTime);
|
|
|
+ workEndAttendance.setCreateTime(new Date());
|
|
|
+ workEndAttendance.setOffsetMinute(new BigDecimal(offsetMinute));
|
|
|
+ workEndAttendance.setWorkMinute(new BigDecimal(workMinutes));
|
|
|
+
|
|
|
+ if (workOverPerson != null) {
|
|
|
+ workEndAttendance.setWorkOverPersonId(workOverPerson.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ workScheduleAttendanceDAO.insert(workEndAttendance);
|
|
|
+
|
|
|
+ redisTemplate.delete(key);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ log.warn(key + "正在处理中");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex){
|
|
|
+ log.error(ex.getMessage(),ex);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1288,4 +1292,9 @@ public class WorkScheduleAttendanceServiceImpl implements WorkScheduleAttendance
|
|
|
double workMinute = workScheduleAttendanceDAO.findSumWorkMinuteByParams(personId, startDate, endDate, searchParams);
|
|
|
return new BigDecimal(workMinute);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Map> queryDuplicateRecord(Date startDate, int limit) {
|
|
|
+ return workScheduleAttendanceDAO.queryDuplicateRecord(startDate,limit);
|
|
|
+ }
|
|
|
}
|