|
@@ -2,14 +2,24 @@ package com.jpsoft.shinestar.modules.base.service.impl;
|
|
|
|
|
|
import com.github.pagehelper.Page;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
+import com.jpsoft.shinestar.modules.base.entity.PersonDeviceLog;
|
|
|
+import com.jpsoft.shinestar.modules.base.service.PersonDeviceLogService;
|
|
|
import com.jpsoft.shinestar.modules.base.service.WorkOverPersonService;
|
|
|
import com.jpsoft.shinestar.modules.base.dao.WorkOverPersonDAO;
|
|
|
import com.jpsoft.shinestar.modules.base.entity.WorkOverPerson;
|
|
|
+import com.jpsoft.shinestar.modules.base.service.WorkOverService;
|
|
|
import com.jpsoft.shinestar.modules.common.dto.Sort;
|
|
|
+import com.jpsoft.shinestar.modules.sys.entity.DataDictionary;
|
|
|
+import com.jpsoft.shinestar.modules.sys.service.DataDictionaryService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.joda.time.DateTime;
|
|
|
+import org.joda.time.Minutes;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -18,6 +28,7 @@ import java.util.Map;
|
|
|
* @author 墨鱼_mo
|
|
|
* @date 2021-5-21 9:21
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Transactional
|
|
|
@Component(value="workOverPersonService")
|
|
|
public class WorkOverPersonServiceImpl implements WorkOverPersonService {
|
|
@@ -25,6 +36,15 @@ public class WorkOverPersonServiceImpl implements WorkOverPersonService {
|
|
|
@Resource(name="workOverPersonDAO")
|
|
|
private WorkOverPersonDAO workOverPersonDAO;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private PersonDeviceLogService personDeviceLogService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DataDictionaryService dataDictionaryService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WorkOverService workOverService;
|
|
|
+
|
|
|
@Override
|
|
|
public WorkOverPerson get(String id) {
|
|
|
// TODO Auto-generated method stub
|
|
@@ -80,8 +100,8 @@ public class WorkOverPersonServiceImpl implements WorkOverPersonService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public WorkOverPerson findByPersonIdAndDate(Long personId, Date attendanceDate) {
|
|
|
- return workOverPersonDAO.findByPersonIdAndDate(personId,attendanceDate);
|
|
|
+ public WorkOverPerson findOneByPersonIdAndDate(Long personId, Date attendanceDate) {
|
|
|
+ return workOverPersonDAO.findOneByPersonIdAndDate(personId,attendanceDate);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -90,12 +110,96 @@ public class WorkOverPersonServiceImpl implements WorkOverPersonService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public WorkOverPerson findByPersonIdAndOffsetMinute(Long personId, Date recordTime, int earlyMinutes, int delayMinutes) {
|
|
|
- return workOverPersonDAO.findByPersonIdAndOffsetMinute(personId,recordTime,earlyMinutes,delayMinutes);
|
|
|
+ public WorkOverPerson findOneByPersonIdAndOffsetMinute(Long personId, Date recordTime, int earlyMinutes, int delayMinutes) {
|
|
|
+ return workOverPersonDAO.findOneByPersonIdAndOffsetMinute(personId,recordTime,earlyMinutes,delayMinutes);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<Map> findUnFinishByDate(Date startDate, Date endDate) {
|
|
|
return workOverPersonDAO.findUnFinishByDate(startDate, endDate);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int updateFinishTime(String day) {
|
|
|
+ int affectCount = 0;
|
|
|
+
|
|
|
+ try {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
|
|
+ Date startDate = sdf.parse(day + " 00:00");
|
|
|
+ Date endDate = sdf.parse(day + " 23:59");
|
|
|
+
|
|
|
+ List<DataDictionary> ddList = dataDictionaryService.findByCatalogName("设备用途");
|
|
|
+
|
|
|
+ String scene = "";
|
|
|
+
|
|
|
+ for (DataDictionary dd : ddList) {
|
|
|
+ if (dd.getName().indexOf("考勤") != -1) {
|
|
|
+ scene = dd.getValue();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询当天申请加班记录
|
|
|
+ List<Map> mapList = findUnFinishByDate(startDate, endDate);
|
|
|
+
|
|
|
+ for (Map map : mapList) {
|
|
|
+ String id = map.get("id_").toString();
|
|
|
+ Long personId = Long.valueOf(map.get("person_id").toString());
|
|
|
+ DateTime startTime = new DateTime((Date) map.get("start_time"));
|
|
|
+ DateTime endTime = new DateTime((Date) map.get("end_time"));
|
|
|
+
|
|
|
+ List<PersonDeviceLog> personDeviceLogs = personDeviceLogService.findByPersonAndDateAndScene(personId,
|
|
|
+ startTime.plusHours(-1).toDate(), endTime.plusHours(2).toDate(), scene);
|
|
|
+
|
|
|
+ boolean exist = false;
|
|
|
+
|
|
|
+ //取最后一条
|
|
|
+ if (personDeviceLogs.size() > 0) {
|
|
|
+ PersonDeviceLog personDeviceLog = personDeviceLogs.get(personDeviceLogs.size() - 1);
|
|
|
+
|
|
|
+ //最后一条打卡记录>加班开始时间+30分钟
|
|
|
+ if(personDeviceLog.getRecordTime().after(startTime.plusMinutes(30).toDate())){
|
|
|
+ exist = true;
|
|
|
+
|
|
|
+ boolean result = workOverService.punchIn(personDeviceLog.getDeviceNo(), personDeviceLog.getPersonId(), personDeviceLog.getRecordTime());
|
|
|
+
|
|
|
+ if (result) {
|
|
|
+ affectCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!exist){
|
|
|
+ //查询该员工半小时内是否还有加班,如果有则直接取计划结束时间作为实际完成时间
|
|
|
+ WorkOverPerson nextWorkOverPerson = findOneByPersonIdAndDate(personId, endTime.plusMinutes(30).toDate());
|
|
|
+
|
|
|
+ if (nextWorkOverPerson != null) {
|
|
|
+ WorkOverPerson workOverPerson = get(id);
|
|
|
+
|
|
|
+ if (workOverPerson.getBeginTime() == null) {
|
|
|
+ workOverPerson.setBeginTime(startTime.toDate());
|
|
|
+ }
|
|
|
+
|
|
|
+ workOverPerson.setFinishTime(endTime.toDate());
|
|
|
+
|
|
|
+ int minutes = (int) Minutes.minutesBetween(startTime, new DateTime(workOverPerson.getFinishTime())).getMinutes();
|
|
|
+ workOverPerson.setDuration(minutes);
|
|
|
+
|
|
|
+ int intHours = minutes / 60;
|
|
|
+ int intMinutes = minutes % 60;
|
|
|
+ workOverPerson.setDurationStr(intHours + "小时" + intMinutes + "分钟");
|
|
|
+
|
|
|
+ workOverPerson.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ update(workOverPerson);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex){
|
|
|
+ log.error(ex.getMessage(),ex);
|
|
|
+ }
|
|
|
+
|
|
|
+ return affectCount;
|
|
|
+ }
|
|
|
}
|