
package com.tmerclub.cloud.user.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.tmerclub.cloud.user.mapper.PopupRelateMapper;
import com.tmerclub.cloud.user.model.PopupRelate;
import com.tmerclub.cloud.user.service.PopupRelateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 弹窗广告关联
 * @author TRACK
 */
@Service
public class PopupRelateServiceImpl implements PopupRelateService {

    @Autowired
    private PopupRelateMapper popupRelateMapper;

    @Override
    public List<PopupRelate> getByPopupId(Long popupId) {
        return popupRelateMapper.getByPopupId(popupId);
    }

    @Override
    public void saveBatch(List<PopupRelate> popupRelates) {
        popupRelateMapper.saveBatch(popupRelates);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateBatch(Long popupId, List<PopupRelate> popupRelates) {
        // 先删除后新增
        popupRelateMapper.deleteById(popupId);
        if (CollUtil.isEmpty(popupRelates)) {
            return;
        }
        popupRelateMapper.saveBatch(popupRelates);
    }

    @Override
    public void deleteById(Long popupId) {
        popupRelateMapper.deleteById(popupId);
    }

    @Override
    public void deleteByRelateIds(List<Long> relateIds) {
        popupRelateMapper.deleteByRelateIds(relateIds);
    }
}
