package jnpf.personnels.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jnpf.base.entity.SuperBaseEntity;
import jnpf.model.personnels.dto.recruitmentchannels.PersonnelsRecruitmentChannelsAddDTO;
import jnpf.model.personnels.po.FtbPersonnelsRecruitmentChannels;
import jnpf.personnels.mapper.FtbPersonnelsRecruitmentChannelsMapper;
import jnpf.personnels.service.FtbPersonnelsRecruitmentChannelsService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class FtbPersonnelsRecruitmentChannelsServiceImpl extends ServiceImpl<FtbPersonnelsRecruitmentChannelsMapper, FtbPersonnelsRecruitmentChannels> implements FtbPersonnelsRecruitmentChannelsService {

    @Override
    @Transactional
    public void add(PersonnelsRecruitmentChannelsAddDTO personnelsRecruitmentChannelsAddDTO) {
        List<FtbPersonnelsRecruitmentChannels> ftbPersonnelsRecruitmentChannels = personnelsRecruitmentChannelsAddDTO.convert(personnelsRecruitmentChannelsAddDTO);
        LambdaQueryWrapper<FtbPersonnelsRecruitmentChannels> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.ne(FtbPersonnelsRecruitmentChannels::getInternalStatus, 0);
        baseMapper.delete(queryWrapper);
        saveBatch(ftbPersonnelsRecruitmentChannels);
    }

    @Override
    public List<FtbPersonnelsRecruitmentChannels> queryRecruitmentChannels() {
        LambdaQueryWrapper<FtbPersonnelsRecruitmentChannels> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.select(SuperBaseEntity.SuperIBaseEntity::getId,
                FtbPersonnelsRecruitmentChannels::getRegularName,
                FtbPersonnelsRecruitmentChannels::getInternalStatus);
        queryWrapper.eq(FtbPersonnelsRecruitmentChannels::getEnableMark, 0);
        queryWrapper.orderByAsc(FtbPersonnelsRecruitmentChannels::getInternalStatus);
        return baseMapper.selectList(queryWrapper);
    }
}
