package com.ruoyi.tuya.service.impl;

import java.util.List;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.tuya.domain.TuyaSitesInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.tuya.mapper.TuyaArticleInfoMapper;
import com.ruoyi.tuya.domain.TuyaArticleInfo;
import com.ruoyi.tuya.service.ITuyaArticleInfoService;

/**
 * 内容信息Service业务层处理
 *
 * @author ruoyi
 * @date 2022-07-14
 */
@Service
public class TuyaArticleInfoServiceImpl implements ITuyaArticleInfoService
{
    @Autowired
    private TuyaArticleInfoMapper tuyaArticleInfoMapper;

    /**
     * 校验内容标题是否唯一
     *
     * @param tuyaArticleInfo 内容信息
     * @return 结果
     */
    @Override
    public String checkArticleTitleUnique(TuyaArticleInfo tuyaArticleInfo)
    {
        Long articleId = StringUtils.isNull(tuyaArticleInfo.getArticleId()) ? -1L : tuyaArticleInfo.getArticleId();
        TuyaArticleInfo info = tuyaArticleInfoMapper.checkArticleTitleUnique(tuyaArticleInfo);
        if (StringUtils.isNotNull(info) && info.getArticleId() != articleId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    /**
     * 查询内容信息
     *
     * @param articleId 内容信息主键
     * @return 内容信息
     */
    @Override
    public TuyaArticleInfo selectTuyaArticleInfoByArticleId(Long articleId)
    {
        return tuyaArticleInfoMapper.selectTuyaArticleInfoByArticleId(articleId);
    }

    /**
     * 查询内容信息列表
     *
     * @param tuyaArticleInfo 内容信息
     * @return 内容信息
     */
    @Override
    public List<TuyaArticleInfo> selectTuyaArticleInfoList(TuyaArticleInfo tuyaArticleInfo)
    {
        return tuyaArticleInfoMapper.selectTuyaArticleInfoList(tuyaArticleInfo);
    }

    /**
     * 新增内容信息
     *
     * @param tuyaArticleInfo 内容信息
     * @return 结果
     */
    @Override
    public int insertTuyaArticleInfo(TuyaArticleInfo tuyaArticleInfo)
    {
        tuyaArticleInfo.setCreateTime(DateUtils.getNowDate());
        return tuyaArticleInfoMapper.insertTuyaArticleInfo(tuyaArticleInfo);
    }

    /**
     * 修改内容信息
     *
     * @param tuyaArticleInfo 内容信息
     * @return 结果
     */
    @Override
    public int updateTuyaArticleInfo(TuyaArticleInfo tuyaArticleInfo)
    {
        tuyaArticleInfo.setUpdateTime(DateUtils.getNowDate());
        return tuyaArticleInfoMapper.updateTuyaArticleInfo(tuyaArticleInfo);
    }

    /**
     * 批量删除内容信息
     *
     * @param articleIds 需要删除的内容信息主键
     * @return 结果
     */
    @Override
    public int deleteTuyaArticleInfoByArticleIds(Long[] articleIds)
    {
        return tuyaArticleInfoMapper.deleteTuyaArticleInfoByArticleIds(articleIds);
    }

    /**
     * 删除内容信息信息
     *
     * @param articleId 内容信息主键
     * @return 结果
     */
    @Override
    public int deleteTuyaArticleInfoByArticleId(Long articleId)
    {
        return tuyaArticleInfoMapper.deleteTuyaArticleInfoByArticleId(articleId);
    }
}
