package com.ruoyi.ehsRescueTeamWorker.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.ruoyi.common.utils.StringUtils;

import java.util.List;
import java.util.Map;

import com.ruoyi.ehsRescueTeamWorker.mapper.EhsRescueTeamWorkerMapper;
import com.ruoyi.ehsRescueTeamWorker.domain.EhsRescueTeamWorker;
import com.ruoyi.ehsRescueTeamWorker.service.IEhsRescueTeamWorkerService;

/**
 * 应急救援队人员信息Service业务层处理
 *
 * @author ruoyi
 * @date 2023-12-11
 */
@Service
public class EhsRescueTeamWorkerServiceImpl extends ServiceImpl<EhsRescueTeamWorkerMapper, EhsRescueTeamWorker> implements IEhsRescueTeamWorkerService {

    @Autowired
    private EhsRescueTeamWorkerMapper ehsRescueTeamWorkerMapper;

    /**
     * 查询应急救援队人员信息
     *
     * @param id 应急救援队人员信息主键
     * @return 应急救援队人员信息
     */
    @Override
    public EhsRescueTeamWorker selectEhsRescueTeamWorkerById(Long id) {
        return ehsRescueTeamWorkerMapper.selectEhsRescueTeamWorkerById(id);
    }

    /**
     * 查询应急救援队人员信息列表
     *
     * @param ehsRescueTeamWorker 应急救援队人员信息
     * @return 应急救援队人员信息
     */
    @Override
    public List<EhsRescueTeamWorker> selectEhsRescueTeamWorkerList(EhsRescueTeamWorker ehsRescueTeamWorker) {
        return ehsRescueTeamWorkerMapper.selectEhsRescueTeamWorkerList(ehsRescueTeamWorker);
    }

    // 根据队伍ids删除队伍中的队员
    @Override
    public boolean removeWorkerByTeamIds(List<Long> teamIds) {
        return ehsRescueTeamWorkerMapper.removeWorkerByTeamIds(teamIds);
    }


    private LambdaQueryWrapper<EhsRescueTeamWorker> buildQueryWrapper(EhsRescueTeamWorker query) {
        Map<String, Object> params = query.getParams();
        LambdaQueryWrapper<EhsRescueTeamWorker> lqw = Wrappers.lambdaQuery();
        lqw.eq(query.getRescueTeamId() != null, EhsRescueTeamWorker::getRescueTeamId, query.getRescueTeamId());
        lqw.like(StringUtils.isNotBlank(query.getRescueTeamName()), EhsRescueTeamWorker::getRescueTeamName, query.getRescueTeamName());
        lqw.like(StringUtils.isNotBlank(query.getWorkerName()), EhsRescueTeamWorker::getWorkerName, query.getWorkerName());
        lqw.eq(query.getGender() != null, EhsRescueTeamWorker::getGender, query.getGender());
        lqw.eq(query.getBirthday() != null, EhsRescueTeamWorker::getBirthday, query.getBirthday());
        lqw.eq(StringUtils.isNotBlank(query.getIdCard()), EhsRescueTeamWorker::getIdCard, query.getIdCard());
        lqw.eq(StringUtils.isNotBlank(query.getPhone()), EhsRescueTeamWorker::getPhone, query.getPhone());
        lqw.eq(StringUtils.isNotBlank(query.getWorkYear()), EhsRescueTeamWorker::getWorkYear, query.getWorkYear());
        lqw.eq(StringUtils.isNotBlank(query.getSpeciality()), EhsRescueTeamWorker::getSpeciality, query.getSpeciality());
        lqw.orderByDesc(EhsRescueTeamWorker::getCreateTime);
        return lqw;
    }

}
