package cn.iocoder.yudao.module.system.service.attendance.factorypunchrecord;

import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils;
import cn.iocoder.yudao.module.system.controller.admin.attendance.vo.AttendanceFactoryPunchRecordPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.attendance.vo.AttendanceFactoryPunchRecordSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.attendance.factorypunchrecord.AttendanceFactoryPunchRecordDO;
import cn.iocoder.yudao.module.system.dal.mysql.attendance.factorypunchrecord.AttendanceFactoryPunchRecordMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;


import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;

/**
 * 工厂员工打卡记录 Service 实现类
 *
 * @author 艾楷
 */
@Service
@Validated
public class AttendanceFactoryPunchRecordServiceImpl implements AttendanceFactoryPunchRecordService {

    @Resource
    private AttendanceFactoryPunchRecordMapper attendanceFactoryPunchRecordMapper;

    @Override
    public Long createAttendanceFactoryPunchRecord(AttendanceFactoryPunchRecordSaveReqVO createReqVO) {
        // 插入
        AttendanceFactoryPunchRecordDO attendanceFactoryPunchRecord = BeanUtils.toBean(createReqVO, AttendanceFactoryPunchRecordDO.class);
        attendanceFactoryPunchRecordMapper.insert(attendanceFactoryPunchRecord);
        // 返回
        return attendanceFactoryPunchRecord.getId();
    }

    @Override
    public void updateAttendanceFactoryPunchRecord(AttendanceFactoryPunchRecordSaveReqVO updateReqVO) {
        // 更新
        AttendanceFactoryPunchRecordDO updateObj = BeanUtils.toBean(updateReqVO, AttendanceFactoryPunchRecordDO.class);
        attendanceFactoryPunchRecordMapper.updateById(updateObj);
    }

    @Override
    public void deleteAttendanceFactoryPunchRecord(Long id) {
        // 删除
        attendanceFactoryPunchRecordMapper.deleteById(id);
    }

    @Override
    public AttendanceFactoryPunchRecordDO getAttendanceFactoryPunchRecord(Long id) {
        return attendanceFactoryPunchRecordMapper.selectById(id);
    }

    @Override
    public PageResult<AttendanceFactoryPunchRecordDO> getAttendanceFactoryPunchRecordPage(AttendanceFactoryPunchRecordPageReqVO pageReqVO) {
        IPage<AttendanceFactoryPunchRecordDO> vos = attendanceFactoryPunchRecordMapper.getAttendanceFactoryPunchRecordPage(pageReqVO, MyBatisUtils.buildPage(pageReqVO));
        return new PageResult<>(vos.getRecords(), vos.getTotal());
    }

}
