package jnpf.personnels.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jnpf.model.personnels.po.FtbPersonnelsStaffArchivesHistory;
import jnpf.model.personnels.vo.roster.FtbPersonnelsStaffArchivesHistoryVo;
import jnpf.personnels.mapper.FtbPersonnelsStaffArchivesHistoryMapper;
import jnpf.personnels.service.FtbPersonnelsStaffArchivesHistoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class FtbPersonnelsStaffArchivesHistoryServiceImpl extends ServiceImpl<FtbPersonnelsStaffArchivesHistoryMapper, FtbPersonnelsStaffArchivesHistory> implements FtbPersonnelsStaffArchivesHistoryService {


    @Override
    public FtbPersonnelsStaffArchivesHistoryVo getInfo(String userId) {
        LambdaQueryWrapper<FtbPersonnelsStaffArchivesHistory> wrapper = new LambdaQueryWrapper<FtbPersonnelsStaffArchivesHistory>()
                .eq(FtbPersonnelsStaffArchivesHistory::getUserId, userId)
                .eq(FtbPersonnelsStaffArchivesHistory::getEnabledMark, 1);
        List<FtbPersonnelsStaffArchivesHistory> list = baseMapper.selectList(wrapper);
        if (CollectionUtil.isEmpty(list)) {
            return null;
        }
        return BeanUtil.copyProperties(list.get(0), FtbPersonnelsStaffArchivesHistoryVo.class);
    }


    @Override
    public void deleteForUserIds(List<String> userIds) {
        if (CollectionUtil.isEmpty(userIds)) {
            return;
        }
        LambdaUpdateWrapper<FtbPersonnelsStaffArchivesHistory> lambdaUpdate = Wrappers.lambdaUpdate();
        lambdaUpdate.in(FtbPersonnelsStaffArchivesHistory::getUserId, userIds);
        lambdaUpdate.set(FtbPersonnelsStaffArchivesHistory::getEnabledMark, 0);
        baseMapper.update(null, lambdaUpdate);
    }
}
