package com.ruoyi.post.service.impl;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.post.domain.PostNews;
import com.ruoyi.post.domain.PostPublisher;
import com.ruoyi.post.mapper.PostPublisherMapper;
import com.ruoyi.post.service.IPostPublisherService;
import org.springframework.stereotype.Service;

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

/**
 * @Author HuiANan
 * @Date 2023/1/25 20:18
 * @Exegesis:
 */
@Service
public class PostPublisherServiceImpl implements IPostPublisherService
{
    @Resource
    private PostPublisherMapper postPublisherMapper;

    /**
     * 查询邮贝发行方信息;
     *
     * @param publisherId 邮贝发行方信息;主键
     * @return 邮贝发行方信息;
     */
    @Override
    public PostPublisher selectPostPublisherByPublisherId(Long publisherId)
    {
        return postPublisherMapper.selectPostPublisherByPublisherId(publisherId);
    }

    /**
     * 查询邮贝发行方信息;列表
     *
     * @param postPublisher 邮贝发行方信息;
     * @return 邮贝发行方信息;
     */
    @Override
    public List<PostPublisher> selectPostPublisherList(PostPublisher postPublisher)
    {
        return postPublisherMapper.selectPostPublisherList(postPublisher);
    }

    /**
     * 新增邮贝发行方信息;
     *
     * @param postPublisher 邮贝发行方信息;
     * @return 结果
     */
    @Override
    public int insertPostPublisher(PostPublisher postPublisher)
    {
        postPublisher.setCreateTime(DateUtils.getNowDate());
        return postPublisherMapper.insertPostPublisher(postPublisher);
    }

    /**
     * 修改邮贝发行方信息;
     *
     * @param postPublisher 邮贝发行方信息;
     * @return 结果
     */
    @Override
    public int updatePostPublisher(PostPublisher postPublisher)
    {
        postPublisher.setUpdateTime(DateUtils.getNowDate());
        return postPublisherMapper.updatePostPublisher(postPublisher);
    }

    /**
     * 批量删除邮贝发行方信息;
     *
     * @param publisherIds 需要删除的邮贝发行方信息;主键
     * @return 结果
     */
    @Override
    public int deletePostPublisherByPublisherIds(Long[] publisherIds)
    {
        return postPublisherMapper.deletePostPublisherByPublisherIds(publisherIds);
    }

    /**
     * 删除邮贝发行方信息;信息
     *
     * @param publisherId 邮贝发行方信息;主键
     * @return 结果
     */
    @Override
    public int deletePostPublisherByPublisherId(Long publisherId)
    {
        return postPublisherMapper.deletePostPublisherByPublisherId(publisherId);
    }

    //检验发行方账号是否重复
    @Override
    public String checkPublisherName(PostPublisher postPublisher) {
        Long NewsId = StringUtils.isNull(postPublisher.getPublisherId()) ? -1l : postPublisher.getPublisherId();
        PostNews info = postPublisherMapper.checkPublisherNameUnique(postPublisher.getPublisherName());
        if (StringUtils.isNotNull(info) && info.getNewsId().longValue() != NewsId.longValue()) {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    //检验发行方头像是否重复
    @Override
    public String checkImage(PostPublisher postPublisher) {
        Long NewsId = StringUtils.isNull(postPublisher.getPublisherId()) ? -1l : postPublisher.getPublisherId();
        PostNews info = postPublisherMapper.checkImageUnique(postPublisher.getPublisherImage());
        if (StringUtils.isNotNull(info) && info.getNewsId().longValue() != NewsId.longValue()) {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }
}