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

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.controller.admin.groupshiftitem.vo.AttendanceGroupShiftItemPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.groupshiftitem.vo.AttendanceGroupShiftItemSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.attendance.groupshiftitem.AttendanceGroupShiftItemDO;
import cn.iocoder.yudao.module.system.dal.mysql.attendance.groupshiftitem.AttendanceGroupShiftItemMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.List;

/**
 * 考勤组班次子表 Service 实现类
 *
 * @author 艾楷
 */
@Service
@Validated
public class AttendanceGroupShiftItemServiceImpl implements AttendanceGroupShiftItemService {

    @Resource
    private AttendanceGroupShiftItemMapper attendanceGroupShiftItemMapper;

    @Override
    public Long createAttendanceGroupShiftItem(AttendanceGroupShiftItemSaveReqVO createReqVO) {
        // 插入
        AttendanceGroupShiftItemDO attendanceGroupShiftItem = BeanUtils.toBean(createReqVO, AttendanceGroupShiftItemDO.class);
        attendanceGroupShiftItemMapper.insert(attendanceGroupShiftItem);
        // 返回
        return attendanceGroupShiftItem.getId();
    }

    @Override
    public void updateAttendanceGroupShiftItem(AttendanceGroupShiftItemSaveReqVO updateReqVO) {
        // 更新
        AttendanceGroupShiftItemDO updateObj = BeanUtils.toBean(updateReqVO, AttendanceGroupShiftItemDO.class);
        attendanceGroupShiftItemMapper.updateById(updateObj);
    }

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


    @Override
    public AttendanceGroupShiftItemDO getAttendanceGroupShiftItem(Long id) {
        return attendanceGroupShiftItemMapper.selectById(id);
    }

    @Override
    public PageResult<AttendanceGroupShiftItemDO> getAttendanceGroupShiftItemPage(AttendanceGroupShiftItemPageReqVO pageReqVO) {
        return attendanceGroupShiftItemMapper.selectPage(pageReqVO);
    }

    @Override
    public List<AttendanceGroupShiftItemDO> getGroupShiftItemListByShiftId(Long attendanceGroupShiftId) {
        return attendanceGroupShiftItemMapper.selectList(new LambdaQueryWrapper<AttendanceGroupShiftItemDO>()
                .eq(AttendanceGroupShiftItemDO::getKqAttendanceGroupShiftId, attendanceGroupShiftId)
                .orderByAsc(AttendanceGroupShiftItemDO::getLevel));
    }

}