|
@@ -3,18 +3,24 @@ package com.qmth.sop.business.service.impl;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.qmth.sop.business.bean.dto.DateFormDto;
|
|
|
import com.qmth.sop.business.bean.result.*;
|
|
|
import com.qmth.sop.business.entity.TBDing;
|
|
|
+import com.qmth.sop.business.entity.TFFlowApprove;
|
|
|
import com.qmth.sop.business.mapper.TBDingMapper;
|
|
|
import com.qmth.sop.business.service.TBDingService;
|
|
|
-import com.qmth.sop.common.enums.DingResultEnum;
|
|
|
-import com.qmth.sop.common.enums.InOutTypeEnum;
|
|
|
+import com.qmth.sop.common.contant.SystemConstant;
|
|
|
+import com.qmth.sop.common.enums.*;
|
|
|
+import com.qmth.sop.common.util.DateDisposeUtils;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.lang3.time.DateFormatUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 考勤打卡表 服务实现.
|
|
@@ -28,71 +34,153 @@ import java.util.Objects;
|
|
|
@Service
|
|
|
public class TBDingServiceImpl extends ServiceImpl<TBDingMapper, TBDing> implements TBDingService {
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
- public Object findDingElements() {
|
|
|
- return null;
|
|
|
+ public DingElementResult findDingElements(String sopNo, Long userId) {
|
|
|
+ DingElementResult dingElementResult = this.baseMapper.findDingResultByUserId(userId);
|
|
|
+ Long userArchivesId = dingElementResult.getUserArchivesId();
|
|
|
+ String currentDayStr = DateFormatUtils.format(System.currentTimeMillis(), SystemConstant.DEFAULT_DATE_DAY_PATTERN);
|
|
|
+ List<TBDing> tbDingList = this.list(new QueryWrapper<TBDing>()
|
|
|
+ .lambda()
|
|
|
+ .eq(TBDing::getSopNo, sopNo)
|
|
|
+ .eq(TBDing::getUserArchivesId, userArchivesId)
|
|
|
+ .eq(TBDing::getSignDate, currentDayStr));
|
|
|
+ if (CollectionUtils.isNotEmpty(tbDingList)) {
|
|
|
+ // 有考勤记录
|
|
|
+ if (tbDingList.size() > 1) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("考勤记录异常");
|
|
|
+ }
|
|
|
+ TBDing tbDing = tbDingList.get(0);
|
|
|
+ Long signInTime = tbDing.getSignInTime();
|
|
|
+ String singInAddress = tbDing.getSignInAddress();
|
|
|
+ Long signOutTime = tbDing.getSignOutTime();
|
|
|
+ String signOutAddress = tbDing.getSignOutAddress();
|
|
|
+
|
|
|
+ dingElementResult.setSignInTime(signInTime);
|
|
|
+ dingElementResult.setSignInAddress(singInAddress);
|
|
|
+ dingElementResult.setSignOutAddress(signOutAddress);
|
|
|
+ dingElementResult.setSignOutTime(signOutTime);
|
|
|
+ }
|
|
|
+ return dingElementResult;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public DingStatisticResult findDingStatistic(Long serviceUnitId, String sopNo, Long userArchivesId) {
|
|
|
- List<TBDing> tbDingList = this.list(new QueryWrapper<TBDing>().lambda()
|
|
|
- .eq(TBDing::getServiceId, serviceUnitId)
|
|
|
- .eq(TBDing::getSopNo, sopNo)
|
|
|
- .eq(TBDing::getUserArchivesId, userArchivesId)
|
|
|
- .orderByAsc(TBDing::getId));
|
|
|
+ // 根据sopNo查询日期表单
|
|
|
+ DateFormDto dateFormDto = this.buildSignDateFormBySop(sopNo);
|
|
|
+
|
|
|
+ List<String> dateFormList = dateFormDto.getDateFormList();
|
|
|
+
|
|
|
+ int workCount = 0;
|
|
|
+ int exceptionCount = 0;
|
|
|
List<DingFormResult> formList = new ArrayList<>();
|
|
|
- int exceptionDays = 0;
|
|
|
- for (TBDing tbDing : tbDingList) {
|
|
|
- String signDate = tbDing.getSignDate();
|
|
|
- Long signInTime = tbDing.getSignInTime();
|
|
|
- String signInAddress = tbDing.getSignInAddress();
|
|
|
- String axisInX = tbDing.getAxisInX();
|
|
|
- String axisInY = tbDing.getAxisInY();
|
|
|
-
|
|
|
- DingInfoResult signInInfo = new DingInfoResult();
|
|
|
- if (signInTime == null || signInTime == 0) {
|
|
|
- signInInfo.setStatus(false);
|
|
|
- } else {
|
|
|
- signInInfo.setStatus(true);
|
|
|
- signInInfo.setInOutType(InOutTypeEnum.IN);
|
|
|
- signInInfo.setSignTime(signInTime);
|
|
|
- signInInfo.setSignAddress(signInAddress);
|
|
|
- signInInfo.setAxisX(axisInX);
|
|
|
- signInInfo.setAxisY(axisInY);
|
|
|
+ if (CollectionUtils.isNotEmpty(dateFormList)) {
|
|
|
+ Boolean sopIsEnd = dateFormDto.getSopIsEnd();
|
|
|
+
|
|
|
+ List<TBDing> tbDingList = this.list(new QueryWrapper<TBDing>().lambda()
|
|
|
+ .eq(TBDing::getServiceId, serviceUnitId)
|
|
|
+ .eq(TBDing::getSopNo, sopNo)
|
|
|
+ .eq(TBDing::getUserArchivesId, userArchivesId)
|
|
|
+ .orderByAsc(TBDing::getId));
|
|
|
+
|
|
|
+ // 签到表
|
|
|
+ List<DingFormResult> formDingList = new ArrayList<>();
|
|
|
+ for (TBDing tbDing : tbDingList) {
|
|
|
+ String signDate = tbDing.getSignDate();
|
|
|
+ Long signInTime = tbDing.getSignInTime();
|
|
|
+ String signInAddress = tbDing.getSignInAddress();
|
|
|
+ String axisInX = tbDing.getAxisInX();
|
|
|
+ String axisInY = tbDing.getAxisInY();
|
|
|
+ String dingSopNo = tbDing.getDingSopNo();
|
|
|
+
|
|
|
+ DingInfoResult signInInfo = new DingInfoResult();
|
|
|
+ if (signInTime == null || signInTime == 0) {
|
|
|
+ if (sopIsEnd) {
|
|
|
+ signInInfo.setStatus(DingStatusEnum.RE_SIGN);
|
|
|
+ } else {
|
|
|
+ signInInfo.setStatus(DingStatusEnum.NO_SIGN);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (sopNo.equals(dingSopNo)) {
|
|
|
+ signInInfo.setStatus(DingStatusEnum.SIGN);
|
|
|
+ } else {
|
|
|
+ signInInfo.setStatus(DingStatusEnum.OTHER);
|
|
|
+ }
|
|
|
+ signInInfo.setInOutType(InOutTypeEnum.IN);
|
|
|
+ signInInfo.setSignTime(signInTime);
|
|
|
+ signInInfo.setSignAddress(signInAddress);
|
|
|
+ signInInfo.setAxisX(axisInX);
|
|
|
+ signInInfo.setAxisY(axisInY);
|
|
|
+ }
|
|
|
+
|
|
|
+ Long signOutTime = tbDing.getSignOutTime();
|
|
|
+ String signOutAddress = tbDing.getSignInAddress();
|
|
|
+ String axisOutX = tbDing.getAxisInX();
|
|
|
+ String axisOutY = tbDing.getAxisInY();
|
|
|
+
|
|
|
+ DingInfoResult signOutInfo = new DingInfoResult();
|
|
|
+ if (signOutTime == null || signOutTime == 0) {
|
|
|
+ if (sopIsEnd) {
|
|
|
+ signOutInfo.setStatus(DingStatusEnum.RE_SIGN);
|
|
|
+ } else {
|
|
|
+ signOutInfo.setStatus(DingStatusEnum.NO_SIGN);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (sopNo.equals(dingSopNo)) {
|
|
|
+ signOutInfo.setStatus(DingStatusEnum.SIGN);
|
|
|
+ } else {
|
|
|
+ signOutInfo.setStatus(DingStatusEnum.OTHER);
|
|
|
+ }
|
|
|
+ signOutInfo.setInOutType(InOutTypeEnum.OUT);
|
|
|
+ signOutInfo.setSignTime(signOutTime);
|
|
|
+ signOutInfo.setSignAddress(signOutAddress);
|
|
|
+ signOutInfo.setAxisX(axisOutX);
|
|
|
+ signOutInfo.setAxisY(axisOutY);
|
|
|
+ }
|
|
|
+ DingFormResult formResult = new DingFormResult();
|
|
|
+ formResult.setDingId(tbDing.getId());
|
|
|
+ formResult.setSignDate(signDate);
|
|
|
+ formResult.setSignInInfo(signInInfo);
|
|
|
+ formResult.setSignOutInfo(signOutInfo);
|
|
|
+ formDingList.add(formResult);
|
|
|
}
|
|
|
|
|
|
- Long signOutTime = tbDing.getSignOutTime();
|
|
|
- String signOutAddress = tbDing.getSignInAddress();
|
|
|
- String axisOutX = tbDing.getAxisInX();
|
|
|
- String axisOutY = tbDing.getAxisInY();
|
|
|
-
|
|
|
- DingInfoResult signOutInfo = new DingInfoResult();
|
|
|
- if (signOutTime == null || signOutTime == 0) {
|
|
|
- signOutInfo.setStatus(false);
|
|
|
- } else {
|
|
|
- signOutInfo.setStatus(true);
|
|
|
- signOutInfo.setInOutType(InOutTypeEnum.OUT);
|
|
|
- signOutInfo.setSignTime(signOutTime);
|
|
|
- signOutInfo.setSignAddress(signOutAddress);
|
|
|
- signOutInfo.setAxisX(axisOutX);
|
|
|
- signOutInfo.setAxisY(axisOutY);
|
|
|
- }
|
|
|
- DingFormResult formResult = new DingFormResult();
|
|
|
- formResult.setDingId(tbDing.getId());
|
|
|
- formResult.setSignDate(signDate);
|
|
|
- formResult.setSignInInfo(signInInfo);
|
|
|
- formResult.setSignOutInfo(signOutInfo);
|
|
|
- formList.add(formResult);
|
|
|
-
|
|
|
- if (!signInInfo.getStatus() || !signOutInfo.getStatus()) {
|
|
|
- exceptionDays++;
|
|
|
+
|
|
|
+ for (String date : dateFormList) {
|
|
|
+ List<DingFormResult> dingFormResultList = formDingList.stream()
|
|
|
+ .filter(e -> date.equals(e.getSignDate()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ DingFormResult dingFormResult = new DingFormResult();
|
|
|
+ dingFormResult.setSignDate(date);
|
|
|
+ if (CollectionUtils.isNotEmpty(dingFormResultList)) {
|
|
|
+ // 有这一天的打卡记录
|
|
|
+
|
|
|
+ dingFormResult = dingFormResultList.get(0);
|
|
|
+ // 考勤异常天数增加
|
|
|
+ if (dingFormResult.getSignInInfo().getStatus().equals(DingStatusEnum.RE_SIGN) || dingFormResult.getSignOutInfo().getStatus().equals(DingStatusEnum.RE_SIGN)) {
|
|
|
+ exceptionCount++;
|
|
|
+ }
|
|
|
+ // 出勤天数增加
|
|
|
+ if ((dingFormResult.getSignInInfo().getStatus().equals(DingStatusEnum.SIGN) && dingFormResult.getSignOutInfo().getStatus().equals(DingStatusEnum.SIGN)) ||
|
|
|
+ (dingFormResult.getSignInInfo().getStatus().equals(DingStatusEnum.OTHER) && dingFormResult.getSignOutInfo().getStatus().equals(DingStatusEnum.OTHER))) {
|
|
|
+ workCount++;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 完全没有这天的打卡记录
|
|
|
+ DingInfoResult in = new DingInfoResult();
|
|
|
+ in.setStatus(DingStatusEnum.NO_SIGN);
|
|
|
+ DingInfoResult out = new DingInfoResult();
|
|
|
+ out.setStatus(DingStatusEnum.NO_SIGN);
|
|
|
+ dingFormResult.setSignInInfo(in);
|
|
|
+ dingFormResult.setSignOutInfo(out);
|
|
|
+ exceptionCount++;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
DingStatisticResult dingStatisticResult = new DingStatisticResult();
|
|
|
dingStatisticResult.setDingFormList(formList);
|
|
|
- dingStatisticResult.setWorkDays(formList.size());
|
|
|
- dingStatisticResult.setExceptionCount(exceptionDays);
|
|
|
+ dingStatisticResult.setWorkDays(workCount);
|
|
|
+ dingStatisticResult.setExceptionCount(exceptionCount);
|
|
|
return dingStatisticResult;
|
|
|
}
|
|
|
|
|
@@ -132,4 +220,33 @@ public class TBDingServiceImpl extends ServiceImpl<TBDingMapper, TBDing> impleme
|
|
|
public List<TBDingAttendanceResult> attendanceQuery(Long serviceId, String userName, Long startTime, Long endTime, Long supplierId, String custom, String sopNo, InOutTypeEnum type, DingResultEnum status) {
|
|
|
return this.baseMapper.attendanceQuery(serviceId, userName, startTime, endTime, supplierId, custom, sopNo, Objects.nonNull(type) ? type.name() : null, Objects.nonNull(status) ? status.name() : null);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public DateFormDto buildSignDateFormBySop(String sopNo) {
|
|
|
+ DateFormDto result = new DateFormDto();
|
|
|
+ List<String> dateList;
|
|
|
+ if (sopNo != null && sopNo.length() > 0) {
|
|
|
+ List<TFFlowApprove> tfFlowApproves = this.baseMapper.findDateAndStatusBySopNo(sopNo);
|
|
|
+ if (CollectionUtils.isNotEmpty(tfFlowApproves)) {
|
|
|
+ if (tfFlowApproves.size() > 1) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(String.format("sop编号为[%s]的有多条流程审核记录", sopNo));
|
|
|
+ }
|
|
|
+ TFFlowApprove tfFlowApprove = tfFlowApproves.get(0);
|
|
|
+ FlowStatusEnum flowStatusEnum = tfFlowApprove.getStatus();
|
|
|
+ Long createTime = tfFlowApprove.getCreateTime();
|
|
|
+ Long updateTime = tfFlowApprove.getUpdateTime();
|
|
|
+ Long currentTime = System.currentTimeMillis();
|
|
|
+
|
|
|
+ if (FlowStatusEnum.FINISH.equals(flowStatusEnum)) {
|
|
|
+ dateList = DateDisposeUtils.getDaysBetween(createTime, updateTime, SystemConstant.DEFAULT_DATE_DAY_PATTERN);
|
|
|
+ result.setSopIsEnd(true);
|
|
|
+ } else {
|
|
|
+ dateList = DateDisposeUtils.getDaysBetween(createTime, currentTime, SystemConstant.DEFAULT_DATE_DAY_PATTERN);
|
|
|
+ result.setSopIsEnd(false);
|
|
|
+ }
|
|
|
+ result.setDateFormList(dateList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|