package cn.com.ty.lift.business.emergency.service;

import cn.com.ty.lift.business.emergency.dto.CostRequest;
import cn.com.ty.lift.business.emergency.dto.CostResponse;
import cn.com.ty.lift.business.emergency.entity.ErRecordCost;
import cn.com.ty.lift.business.emergency.mapper.ErRecordCostMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wcz
 * @since 2019-12-04
 */
@Service
public class ErRecordCostService extends ServiceImpl<ErRecordCostMapper, ErRecordCost> {

    /**
     * 根据急修id查询急修收费项
     * @param erRecordId 急修id
     * @return List<ErRecordCost>
     */
    public List<ErRecordCost> listByErRecordId(Long erRecordId){
        LambdaQueryWrapper<ErRecordCost> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(ErRecordCost::getErRecordId, erRecordId);
        return list(lambdaQueryWrapper);
    }

    /**
     * 根据急修id和主键id查找急修收费项
     * @param erRecordId 急修id
     * @param id 主键id
     * @return ErRecordCost
     */
    public ErRecordCost findByRecordAndId(Long erRecordId, Long id){
        LambdaQueryWrapper<ErRecordCost> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(ErRecordCost::getErRecordId,erRecordId);
        lambdaQueryWrapper.eq(ErRecordCost::getId,id);
        lambdaQueryWrapper.last("LIMIT 1");
        return getOne(lambdaQueryWrapper);
    }

    public IPage<CostResponse> pageByCondition(CostRequest request) {
        return baseMapper.pageByCondition(request.getPage(), request);
    }

    public long countByCondition(CostRequest request) {
        return baseMapper.countByCondition(request);
    }
}
