package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.vo.AttendanceTimeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.AttendanceTimeMapper;
import com.ruoyi.system.domain.AttendanceTime;
import com.ruoyi.system.service.IAttendanceTimeService;

/**
 * 考勤时间设置Service业务层处理
 *
 * @author ruoyi
 * @date 2025-06-25
 */
@Service
public class AttendanceTimeServiceImpl implements IAttendanceTimeService {
    @Autowired
    private AttendanceTimeMapper attendanceTimeMapper;

    /**
     * 查询考勤时间设置
     *
     * @param id 考勤时间设置主键
     * @return 考勤时间设置
     */
    @Override
    public AttendanceTime selectAttendanceTimeById(Long id) {
        return attendanceTimeMapper.selectAttendanceTimeById(id);
    }

    /**
     * 查询考勤时间设置列表
     *
     * @param attendanceTime 考勤时间设置
     * @return 考勤时间设置
     */
    @Override
    public List<AttendanceTime> selectAttendanceTimeList(AttendanceTime attendanceTime) {
        return attendanceTimeMapper.selectAttendanceTimeList(attendanceTime);
    }

    /**
     * 新增考勤时间设置
     *
     * @param attendanceTimeVo 考勤时间设置
     * @return 结果
     */
    @Override
    public int insertAttendanceTime(AttendanceTimeVo attendanceTimeVo) {
        int i = 0;
        List<AttendanceTime> attendanceTimeList = attendanceTimeVo.getAttendanceTimeList();
        for (AttendanceTime attendanceTime : attendanceTimeList) {
            attendanceTime.setSubmitTime(DateUtils.getNowDate());
            i = i + attendanceTimeMapper.insertAttendanceTime(attendanceTime);
        }
        return i;
    }

    /**
     * 修改考勤时间设置
     *
     * @param attendanceTimeVo 考勤时间设置
     * @return 结果
     */
    @Override
    public int updateAttendanceTime(AttendanceTimeVo attendanceTimeVo) {
        int i = 0;
        List<AttendanceTime> attendanceTimeList = attendanceTimeVo.getAttendanceTimeList();
        for (AttendanceTime attendanceTime : attendanceTimeList) {
            if (attendanceTime.getId() != null && attendanceTime.getId() != 0L) {
                attendanceTime.setSubmitTime(DateUtils.getNowDate());
                i = i + attendanceTimeMapper.updateAttendanceTime(attendanceTime);
            } else {
                i = i + attendanceTimeMapper.insertAttendanceTime(attendanceTime);
            }

        }
        return i;
    }

    /**
     * 批量删除考勤时间设置
     *
     * @param ids 需要删除的考勤时间设置主键
     * @return 结果
     */
    @Override
    public int deleteAttendanceTimeByIds(Long[] ids) {
        return attendanceTimeMapper.deleteAttendanceTimeByIds(ids);
    }

    /**
     * 删除考勤时间设置信息
     *
     * @param id 考勤时间设置主键
     * @return 结果
     */
    @Override
    public int deleteAttendanceTimeById(Long id) {
        return attendanceTimeMapper.deleteAttendanceTimeById(id);
    }
}
