package com.jpsoft.shinestar.mq.listener;

import com.jpsoft.shinestar.modules.business.dto.UpdatePersonAttendanceDTO;
import com.jpsoft.shinestar.modules.business.service.WorkScheduleAttendanceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RabbitListener(queues = "updatePersonAttendanceQueue",concurrency = "5")
public class UpdatePersonAttendanceListener {
    @Autowired
    private WorkScheduleAttendanceService workScheduleAttendanceService;

    @RabbitHandler
    public void process(UpdatePersonAttendanceDTO dto) {
        try {
            log.warn("更新考勤记录:{}", dto.toString());

            workScheduleAttendanceService.updatePersonAttendance(dto.getPersonId(), dto.getStartTime(), dto.getEndTime());
        }
        catch (Exception ex){
            log.error(ex.getMessage(),ex);
        }
    }
}
