package com.njzscloud.supervisory.sys.bulletin.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njzscloud.common.mp.support.PageParam;
import com.njzscloud.common.mp.support.PageResult;
import com.njzscloud.supervisory.sys.bulletin.mapper.BulletinMapper;
import com.njzscloud.supervisory.sys.bulletin.pojo.BulletinEntity;
import com.njzscloud.supervisory.sys.bulletin.service.BulletinService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 公告表
 */
@Slf4j
@Service
public class BulletinServiceImpl extends ServiceImpl<BulletinMapper, BulletinEntity> implements BulletinService {

    /**
     * 新增
     */
    @Override
    public void add(BulletinEntity bulletinEntity) {
        this.save(bulletinEntity);
    }

    /**
     * 修改
     */
    @Override
    public void modify(BulletinEntity bulletinEntity) {
        this.updateById(bulletinEntity);
    }

    /**
     * 删除
     */
    @Override
    public void del(List<Long> ids) {
        this.removeBatchByIds(ids);
    }

    /**
     * 详情
     */
    @Override
    public BulletinEntity detail(Long id) {
        return this.getById(id);
    }

    /**
     * 分页查询
     */
    @Override
    public PageResult<BulletinEntity> paging(PageParam pageParam, BulletinEntity bulletinEntity) {
        return PageResult.of(this.page(pageParam.toPage(), Wrappers.<BulletinEntity>lambdaQuery()
                .like(StrUtil.isNotBlank(bulletinEntity.getTitle()), BulletinEntity::getTitle, bulletinEntity.getTitle())
                .eq(bulletinEntity.getDeleted() != null, BulletinEntity::getDeleted, Boolean.FALSE)
                .eq(bulletinEntity.getEnabled() != null, BulletinEntity::getEnabled, bulletinEntity.getEnabled())
                .orderByDesc(BulletinEntity::getCreateTime)));
    }

}
