package com.starry.admin.modules.play.service.impl;

import com.starry.common.utils.IdUtils;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.starry.admin.modules.play.mapper.PlayNoticeInfoMapper;
import com.starry.admin.modules.play.module.entity.PlayNoticeInfoEntity;
import com.starry.admin.modules.play.service.IPlayNoticeInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * 公告Service业务层处理
 *
 * @author admin
 * @since 2024-04-06
 */
@Service
public class PlayNoticeInfoServiceImpl extends ServiceImpl<PlayNoticeInfoMapper, PlayNoticeInfoEntity> implements IPlayNoticeInfoService {
    @Resource
    private PlayNoticeInfoMapper playNoticeInfoMapper;

    /**
     * 查询公告
     *
     * @param id 公告主键
     * @return 公告
     */
    @Override
    public PlayNoticeInfoEntity selectPlayNoticeInfoById(String id) {
        return this.baseMapper.selectById(id);
    }


    @Override
    public List<PlayNoticeInfoEntity> selectPlayNoticeInfo() {
        return this.baseMapper.selectList(new LambdaQueryWrapper<>());
    }

    /**
     * 查询公告列表
     *
     * @param playNoticeInfo 公告
     * @return 公告
     */
    @Override
    public IPage<PlayNoticeInfoEntity> selectPlayNoticeInfoByPage(PlayNoticeInfoEntity playNoticeInfo) {
        Page<PlayNoticeInfoEntity> page = new Page<>(1, 10);
        return this.baseMapper.selectPage(page, new LambdaQueryWrapper<>());
    }

    /**
     * 新增公告
     *
     * @param playNoticeInfo 公告
     * @return 结果
     */
    @Override
    public boolean create(PlayNoticeInfoEntity playNoticeInfo) {
        if (StrUtil.isBlankIfStr(playNoticeInfo.getId())) {
            playNoticeInfo.setId(IdUtils.getUuid());
        }
        return save(playNoticeInfo);
    }

    /**
     * 修改公告
     *
     * @param playNoticeInfo 公告
     * @return 结果
     */
    @Override
    public boolean update(PlayNoticeInfoEntity playNoticeInfo) {
        return updateById(playNoticeInfo);
    }

    /**
     * 批量删除公告
     *
     * @param ids 需要删除的公告主键
     * @return 结果
     */
    @Override
    public int deletePlayNoticeInfoByIds(String[] ids) {
        return playNoticeInfoMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除公告信息
     *
     * @param id 公告主键
     * @return 结果
     */
    @Override
    public int deletePlayNoticeInfoById(String id) {
        return playNoticeInfoMapper.deleteById(id);
    }
}
