package cn.iocoder.yudao.module.system.service.holiday.holidayworkingage;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.ListUtil;
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.holiday.holidayworkingage.vo.HolidayWorkingAgePageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.holiday.holidayworkingage.vo.HolidayWorkingAgeSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.holiday.holidayworkingage.HolidayWorkingAgeDO;
import cn.iocoder.yudao.module.system.dal.mysql.holiday.holidayworkingage.HolidayWorkingAgeMapper;
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.Collections;
import java.util.List;

/**
 * 假期额度工龄配置 Service 实现类
 *
 * @author 艾楷
 */
@Service
@Validated
public class HolidayWorkingAgeServiceImpl implements HolidayWorkingAgeService {

    @Resource
    private HolidayWorkingAgeMapper holidayWorkingAgeMapper;

    @Override
    public Long createHolidayWorkingAge(HolidayWorkingAgeSaveReqVO createReqVO) {
        // 插入
        HolidayWorkingAgeDO holidayWorkingAge = BeanUtils.toBean(createReqVO, HolidayWorkingAgeDO.class);
        holidayWorkingAgeMapper.insert(holidayWorkingAge);
        // 返回
        return holidayWorkingAge.getId();
    }

    @Override
    public void updateHolidayWorkingAge(HolidayWorkingAgeSaveReqVO updateReqVO) {
        // 更新
        HolidayWorkingAgeDO updateObj = BeanUtils.toBean(updateReqVO, HolidayWorkingAgeDO.class);
        holidayWorkingAgeMapper.updateById(updateObj);
    }

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

    @Override
    public HolidayWorkingAgeDO getHolidayWorkingAge(Long id) {
        return holidayWorkingAgeMapper.selectById(id);
    }

    @Override
    public PageResult<HolidayWorkingAgeDO> getHolidayWorkingAgePage(HolidayWorkingAgePageReqVO pageReqVO) {
        return holidayWorkingAgeMapper.selectPage(pageReqVO);
    }

    @Override
    public List<HolidayWorkingAgeDO> selectBySettingId(Long settingId) {
        return holidayWorkingAgeMapper.selectList(new LambdaQueryWrapper<HolidayWorkingAgeDO>()
                .eq(HolidayWorkingAgeDO::getHolidaySettingId, settingId));
    }

    @Override
    public List<HolidayWorkingAgeDO> selectBySettingIds(List<Long> holidaySettingIds) {
        if (CollectionUtil.isEmpty(holidaySettingIds)) {
            return Collections.emptyList();
        }
        return holidayWorkingAgeMapper.selectList(new LambdaQueryWrapper<HolidayWorkingAgeDO>()
                .in(HolidayWorkingAgeDO::getHolidaySettingId, holidaySettingIds));
    }

}
