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

import cn.com.ty.lift.business.evaluation.dao.entity.Evaluation;
import cn.com.ty.lift.business.evaluation.dao.mapper.EvaluationMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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 huangyuan
 * @since 2019-12-31
 */
@Service
public class EvaluationService extends ServiceImpl<EvaluationMapper, Evaluation> {

    /**
     * 根据记录id和来源分类查询评价记录
     * @param recordId 急修or维保id
     * @param source 急修or维保
     */
    public Evaluation findByRecord(Long recordId, int source){
        LambdaQueryWrapper<Evaluation> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(Evaluation::getRecordId, recordId);
        lambdaQueryWrapper.eq(Evaluation::getSource, source);
        lambdaQueryWrapper.last("LIMIT 1");
        return getOne(lambdaQueryWrapper);
    }
    /**
     * 根据记录id和来源分类查询评价记录条数
     * @param recordId 急修or维保id
     * @param source 急修or维保
     */
    public int countByRecord(Long recordId, int source) {
        LambdaQueryWrapper<Evaluation> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(Evaluation::getRecordId, recordId);
        lambdaQueryWrapper.eq(Evaluation::getSource, source);
        return count(lambdaQueryWrapper);
    }

    public List<Evaluation> listDuplicateForSameRecord(){
        return baseMapper.listDuplicateForSameRecord();
    }

    public List<Long> listToDelete(Long recordId, int source){
        return baseMapper.listToDelete(recordId, source);
    }

    public Long findOneToDelete(Long recordId, int source){
        return baseMapper.findOneToDelete(recordId, source);
    }
}
