package com.yida.data.device.telephone.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yida.data.common.core.entity.telephone.EduTelephoneCard;
import com.yida.data.common.core.entity.telephone.EduTelephonePrice;
import com.yida.data.common.core.utils.Asserts;
import com.yida.data.device.telephone.mapper.EduTelephoneCardMapper;
import com.yida.data.device.telephone.mapper.EduTelephonePriceMapper;
import com.yida.data.device.telephone.service.EduTelephonePriceService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 亲情电话-套餐费率 Service实现
 *
 * @author zhanghaijun
 * @date 2021-08-10 17:01:27
 */
@Service
@RequiredArgsConstructor
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class EduTelephonePriceServiceImpl extends ServiceImpl
        <EduTelephonePriceMapper, EduTelephonePrice> implements EduTelephonePriceService {

    private final EduTelephoneCardMapper eduTelephoneCardMapper;

    @Override
    public void delPriceBatch(List<Long> ids) {
        Asserts.isFalse(eduTelephoneCardMapper.selectCount(Wrappers.lambdaQuery(new EduTelephoneCard())
                .in(EduTelephoneCard::getPriceId, ids)) > 0, "费率正在使用中，请调整相关学生费率后重试");
        removeByIds(ids);
    }
}
