package com.zhiqiyun.open.core.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhiqiyun.open.core.mapper.bz.BzMediaMapper;
import com.zhiqiyun.open.core.models.bz.BzMedia;
import com.zhiqiyun.open.core.service.BzService;
import com.zhiqiyun.open.core.service.SequenceService;
import com.zhiqiyun.open.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BzServiceImpl implements BzService {

    @Autowired
    private BzMediaMapper bzMediaMapper;

    @Autowired
    private SequenceService sequenceService;

    @Override
    public Page<BzMedia> findMediaPage(Page<BzMedia> page, QueryWrapper<BzMedia> wrapper) {
        return this.bzMediaMapper.selectPage(page, wrapper);
    }

    @Override
    public void insertOrUpdateMedia(BzMedia media) {
        if (media.getId() == null) {
            media.setCreatedTime(DateUtil.current());
            media.setId(this.sequenceService.nextId());
            this.bzMediaMapper.insert(media);
        } else {
            media.setUpdatedTime(DateUtil.current());
            this.bzMediaMapper.updateById(media);
        }
    }

    @Override
    public void deleteMediaByIds(List<Long> ids) {
        this.bzMediaMapper.deleteBatchIds(ids);
    }
}
