package com.mortals.xhx.module.attendance.service.impl;
import com.mortals.framework.service.ICacheService;
import com.mortals.framework.util.DateUtils;
import com.mortals.framework.util.ThreadPool;
import com.mortals.xhx.common.utils.AttendSummaryThread;
import com.mortals.xhx.module.attendance.model.vo.AttendanceSummaryQuery;
import com.mortals.xhx.module.attendance.service.AttendanceStatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.xhx.module.attendance.dao.AttendanceLeaveRecordDao;
import com.mortals.xhx.module.attendance.model.AttendanceLeaveRecordEntity;
import com.mortals.xhx.module.attendance.service.AttendanceLeaveRecordService;

import static com.mortals.xhx.common.key.RedisKey.KEY_ATTENDANCE_STAT_CACHE;

/**
* AttendanceLeaveRecordService
* 请假记录信息 service实现
*
* @author zxfei
* @date 2023-04-07
*/
@Service("attendanceLeaveRecordService")
public class AttendanceLeaveRecordServiceImpl extends AbstractCRUDServiceImpl<AttendanceLeaveRecordDao, AttendanceLeaveRecordEntity, Long> implements AttendanceLeaveRecordService {

    @Autowired
    private AttendanceStatService attendanceStatService;
    @Autowired
    private ICacheService cacheService;

    @Override
    protected void updateAfter(AttendanceLeaveRecordEntity entity, Context context) throws AppException {
        super.updateAfter(entity,context);
        if(entity.getAuditResult()==1){
            AttendanceSummaryQuery query = new AttendanceSummaryQuery();
            query.setStaffId(entity.getLeavePersonId());
            query.setSummaryTimeStart(DateUtils.getStrDate(entity.getStartTime()));
            query.setSummaryTimeEnd(DateUtils.getStrDate(entity.getEndTime()));
            cacheService.lpush(KEY_ATTENDANCE_STAT_CACHE,query);
        }
    }

    @Override
    public AttendanceLeaveRecordEntity doUpdateRecord(String processInstanceId, AttendanceLeaveRecordEntity leaveRecordEntity) throws Exception {
        return dao.doUpdateRecord(processInstanceId,leaveRecordEntity);
    }
}