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

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.addressgroup.vo.AttendanceAddressGroupItemPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.addressgroup.vo.AttendanceAddressGroupItemSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.attendance.addressgroup.AttendanceAddressGroupItemDO;
import cn.iocoder.yudao.module.system.dal.mysql.attendance.addressgroup.AttendanceAddressGroupItemMapper;
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 AttendanceAddressGroupItemServiceImpl implements AttendanceAddressGroupItemService {

    @Resource
    private AttendanceAddressGroupItemMapper attendanceAddressGroupItemMapper;

    @Override
    public Long createAttendanceAddressGroupItem(AttendanceAddressGroupItemSaveReqVO createReqVO) {
        // 插入
        AttendanceAddressGroupItemDO attendanceAddressGroupItem = BeanUtils.toBean(createReqVO, AttendanceAddressGroupItemDO.class);
        attendanceAddressGroupItemMapper.insert(attendanceAddressGroupItem);
        // 返回
        return attendanceAddressGroupItem.getId();
    }

    @Override
    public void updateAttendanceAddressGroupItem(AttendanceAddressGroupItemSaveReqVO updateReqVO) {
        // 更新
        AttendanceAddressGroupItemDO updateObj = BeanUtils.toBean(updateReqVO, AttendanceAddressGroupItemDO.class);
        attendanceAddressGroupItemMapper.updateById(updateObj);
    }

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

    @Override
    public AttendanceAddressGroupItemDO getAttendanceAddressGroupItem(Long id) {
        return attendanceAddressGroupItemMapper.selectById(id);
    }

    @Override
    public PageResult<AttendanceAddressGroupItemDO> getAttendanceAddressGroupItemPage(AttendanceAddressGroupItemPageReqVO pageReqVO) {
        return attendanceAddressGroupItemMapper.selectPage(pageReqVO);
    }

    @Override
    public List<AttendanceAddressGroupItemDO> getListByAddressGroupIds(List<Long> addressGroupIdList) {
        return attendanceAddressGroupItemMapper.selectList(new LambdaQueryWrapper<AttendanceAddressGroupItemDO>()
                .in(AttendanceAddressGroupItemDO::getAddressGroupId, addressGroupIdList));
    }

}
