|
@@ -1,10 +1,24 @@
|
|
package com.jpsoft.smart.modules.business.service.impl;
|
|
package com.jpsoft.smart.modules.business.service.impl;
|
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.UUID;
|
|
import java.util.UUID;
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+
|
|
|
|
+import com.jpsoft.smart.modules.base.dao.AlarmConfigDAO;
|
|
|
|
+import com.jpsoft.smart.modules.base.dao.CompanyInfoDAO;
|
|
|
|
+import com.jpsoft.smart.modules.base.dao.PersonInfoDAO;
|
|
|
|
+import com.jpsoft.smart.modules.base.entity.AlarmConfig;
|
|
|
|
+import com.jpsoft.smart.modules.base.entity.CompanyInfo;
|
|
|
|
+import com.jpsoft.smart.modules.base.entity.PersonInfo;
|
|
|
|
+import com.jpsoft.smart.modules.common.utils.StringUtils;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.aspectj.weaver.patterns.PerSingleton;
|
|
|
|
+import org.joda.time.DateTime;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import com.jpsoft.smart.modules.business.dao.WorkAttendanceDAO;
|
|
import com.jpsoft.smart.modules.business.dao.WorkAttendanceDAO;
|
|
@@ -14,12 +28,22 @@ import com.github.pagehelper.Page;
|
|
import com.jpsoft.smart.modules.common.dto.Sort;
|
|
import com.jpsoft.smart.modules.common.dto.Sort;
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageHelper;
|
|
|
|
|
|
|
|
+@Slf4j
|
|
@Transactional
|
|
@Transactional
|
|
@Component(value="workAttendanceService")
|
|
@Component(value="workAttendanceService")
|
|
public class WorkAttendanceServiceImpl implements WorkAttendanceService {
|
|
public class WorkAttendanceServiceImpl implements WorkAttendanceService {
|
|
@Resource(name="workAttendanceDAO")
|
|
@Resource(name="workAttendanceDAO")
|
|
private WorkAttendanceDAO workAttendanceDAO;
|
|
private WorkAttendanceDAO workAttendanceDAO;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private PersonInfoDAO personInfoDAO;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private CompanyInfoDAO companyInfoDAO;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private AlarmConfigDAO alarmConfigDAO;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public WorkAttendance get(String id) {
|
|
public WorkAttendance get(String id) {
|
|
// TODO Auto-generated method stub
|
|
// TODO Auto-generated method stub
|
|
@@ -78,4 +102,108 @@ public class WorkAttendanceServiceImpl implements WorkAttendanceService {
|
|
public int deleteByCompanyCodeAndDate(String companyCode, Date startDate, Date endDate) {
|
|
public int deleteByCompanyCodeAndDate(String companyCode, Date startDate, Date endDate) {
|
|
return workAttendanceDAO.deleteByCompanyCodeAndDate(companyCode,startDate,endDate);
|
|
return workAttendanceDAO.deleteByCompanyCodeAndDate(companyCode,startDate,endDate);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean punchIn(Long personId, BigDecimal temperature, Date recordDate) {
|
|
|
|
+ boolean result = false;
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ PersonInfo personInfo = personInfoDAO.get(personId);
|
|
|
|
+ CompanyInfo companyInfo = companyInfoDAO.get(personInfo.getCompanyId());
|
|
|
|
+
|
|
|
|
+ String[] arr = companyInfo.getCode().split(",");
|
|
|
|
+
|
|
|
|
+ List<AlarmConfig> configList = null;
|
|
|
|
+
|
|
|
|
+ for (int i = arr.length - 1; i >= 0; i--) {
|
|
|
|
+ configList = alarmConfigDAO.findByCompanyId(arr[i]);
|
|
|
|
+
|
|
|
|
+ if (configList != null && configList.size() > 0) {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DateTime recordTime = new DateTime(recordDate);
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
|
|
|
+ String date = recordTime.toString("yyyy-MM-dd");
|
|
|
|
+
|
|
|
|
+ if (configList != null) {
|
|
|
|
+ for (AlarmConfig alarmConfig : configList) {
|
|
|
|
+ //是否工作日
|
|
|
|
+ if (alarmConfig.getWeekdays().indexOf(String.valueOf(recordTime.getDayOfWeek())) == -1) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DateTime startTime = new DateTime(sdf.parse(date + " " + alarmConfig.getStartTime()));
|
|
|
|
+ DateTime attendanceTime = new DateTime(sdf.parse(date + " " + alarmConfig.getAttendanceTime()));
|
|
|
|
+ DateTime endTime = new DateTime(sdf.parse(date + " " + alarmConfig.getEndTime()));
|
|
|
|
+
|
|
|
|
+ String attendanceResult = "";
|
|
|
|
+
|
|
|
|
+ if (alarmConfig.getClassifier().equals(1)) {
|
|
|
|
+ //todo 上班考勤
|
|
|
|
+
|
|
|
|
+ //准时上班
|
|
|
|
+ if (recordTime.compareTo(startTime)>0 && recordTime.compareTo(attendanceTime)<=0){
|
|
|
|
+ attendanceResult = WorkAttendance.SUCCESS;
|
|
|
|
+ }
|
|
|
|
+ else if(recordTime.compareTo(attendanceTime)>0 && recordTime.compareTo(endTime)<=0){
|
|
|
|
+ attendanceResult = WorkAttendance.LATE;
|
|
|
|
+
|
|
|
|
+ //当天是否已经有该时段正常上班打卡记录,如果有则不记录
|
|
|
|
+ List<WorkAttendance> workAttendances = workAttendanceDAO.findByPeriod(personId,alarmConfig.getId(),recordTime.toDate());
|
|
|
|
+
|
|
|
|
+ if (workAttendances.size()>0){
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ //todo 下班考勤
|
|
|
|
+ //早退
|
|
|
|
+ if (recordTime.compareTo(startTime)>0 && recordTime.compareTo(attendanceTime)<=0){
|
|
|
|
+ attendanceResult = WorkAttendance.LEAVE_EARLY;
|
|
|
|
+ }
|
|
|
|
+ else if(recordTime.compareTo(attendanceTime)>0 && recordTime.compareTo(endTime)<=0){
|
|
|
|
+ attendanceResult = WorkAttendance.SUCCESS;
|
|
|
|
+
|
|
|
|
+ //当天是否已经有该时段早退记录则删除,只保留最后一次正常下班打卡记录
|
|
|
|
+ List<WorkAttendance> workAttendances = workAttendanceDAO.findByPeriod(personId,alarmConfig.getId(),recordTime.toDate());
|
|
|
|
+
|
|
|
|
+ for (WorkAttendance workAttendance : workAttendances) {
|
|
|
|
+ workAttendance.setDelFlag(true);
|
|
|
|
+ workAttendance.setUpdateTime(new Date());
|
|
|
|
+
|
|
|
|
+ workAttendanceDAO.update(workAttendance);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isNotEmpty(attendanceResult)) {
|
|
|
|
+ WorkAttendance workAttendance = new WorkAttendance();
|
|
|
|
+ workAttendance.setId(UUID.randomUUID().toString());
|
|
|
|
+ workAttendance.setPersonId(personInfo.getId());
|
|
|
|
+ workAttendance.setAlarmConfigId(alarmConfig.getId());
|
|
|
|
+ workAttendance.setCreateTime(new Date());
|
|
|
|
+ workAttendance.setDelFlag(false);
|
|
|
|
+
|
|
|
|
+ workAttendance.setTemperature(temperature);
|
|
|
|
+ workAttendance.setResult(attendanceResult);
|
|
|
|
+ workAttendance.setRecordTime(recordDate);
|
|
|
|
+
|
|
|
|
+ int affectCount = workAttendanceDAO.insert(workAttendance);
|
|
|
|
+
|
|
|
|
+ result = affectCount > 0;
|
|
|
|
+
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch (Exception ex){
|
|
|
|
+ result = false;
|
|
|
|
+ log.error(ex.getMessage(),ex);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
}
|
|
}
|