package cn.iocoder.yudao.module.rescue.service.impl;

import cn.iocoder.yudao.module.rescue.domain.RescueCustomerInfo;
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
import cn.iocoder.yudao.module.rescue.service.IRescueCustomerInfoService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.iocoder.yudao.module.rescue.mapper.RescueCustomerInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 救援的客户信息Service业务层处理
 *
 * @author zcy
 * @date 2023-09-14
 */
@Service
public class RescueCustomerInfoServiceImpl extends ServiceImpl<RescueCustomerInfoMapper, RescueCustomerInfo> implements IRescueCustomerInfoService {
    @Autowired
    private DeptApi deptService;

    /**
     * 查询救援的客户信息
     *
     * @param id 救援的客户信息主键
     * @return 救援的客户信息
     */
    @Override
    public RescueCustomerInfo selectRescueCustomerInfoById(Long id) {
        RescueCustomerInfo rescueCustomerInfo = baseMapper.selectRescueCustomerInfoById(id);
        DeptRespDTO sysDept = deptService.getDept(rescueCustomerInfo.getCustomerDeptId());
        rescueCustomerInfo.setDeptName(sysDept.getName());
        return rescueCustomerInfo;
    }

    /**
     * 查询救援的客户信息列表
     *
     * @param rescueCustomerInfo 救援的客户信息
     * @return 救援的客户信息
     */
    @Override
    public IPage<RescueCustomerInfo> selectRescueCustomerInfoList(RescueCustomerInfo rescueCustomerInfo, Page<RescueCustomerInfo> page) {
        return baseMapper.selectRescueCustomerInfoList(rescueCustomerInfo, page);
    }

    /**
     * 新增救援的客户信息
     *
     * @param rescueCustomerInfo 救援的客户信息
     * @return 结果
     */
    @Override
    public int insertRescueCustomerInfo(RescueCustomerInfo rescueCustomerInfo) {
        return baseMapper.insertRescueCustomerInfo(rescueCustomerInfo);
    }

    /**
     * 修改救援的客户信息
     *
     * @param rescueCustomerInfo 救援的客户信息
     * @return 结果
     */
    @Override
    public int updateRescueCustomerInfo(RescueCustomerInfo rescueCustomerInfo) {
        return baseMapper.updateRescueCustomerInfo(rescueCustomerInfo);
    }

    /**
     * 批量删除救援的客户信息
     *
     * @param ids 需要删除的救援的客户信息主键
     * @return 结果
     */
    @Override
    public int deleteRescueCustomerInfoByIds(Long[] ids) {
        return baseMapper.deleteByIds(Arrays.asList(ids));
    }

    /**
     * 删除救援的客户信息信息
     *
     * @param id 救援的客户信息主键
     * @return 结果
     */
    @Override
    public int deleteRescueCustomerInfoById(Long id) {
        return baseMapper.deleteById(id);
    }
}
