package com.bonus.canteen.core.health.service.impl;

import java.util.List;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.bonus.canteen.core.health.mapper.HealthPopularArticleMapper;
import com.bonus.canteen.core.health.domain.HealthPopularArticle;
import com.bonus.canteen.core.health.service.IHealthPopularArticleService;

/**
 * 营养科普Service业务层处理
 *
 * @author xsheng
 * @date 2025-05-25
 */
@Service
public class HealthPopularArticleServiceImpl implements IHealthPopularArticleService {
    @Autowired
    private HealthPopularArticleMapper healthPopularArticleMapper;

    /**
     * 查询营养科普
     *
     * @param articleId 营养科普主键
     * @return 营养科普
     */
    @Override
    public HealthPopularArticle selectHealthPopularArticleByArticleId(Long articleId) {
        return healthPopularArticleMapper.selectHealthPopularArticleByArticleId(articleId);
    }

    /**
     * 查询营养科普列表
     *
     * @param healthPopularArticle 营养科普
     * @return 营养科普
     */
    @Override
    public List<HealthPopularArticle> selectHealthPopularArticleList(HealthPopularArticle healthPopularArticle) {
        return healthPopularArticleMapper.selectHealthPopularArticleList(healthPopularArticle);
    }

    /**
     * 新增营养科普
     *
     * @param healthPopularArticle 营养科普
     * @return 结果
     */
    @Override
    public int insertHealthPopularArticle(HealthPopularArticle healthPopularArticle) {
        healthPopularArticle.setCreateTime(DateUtils.getNowDate());
        try {
            return healthPopularArticleMapper.insertHealthPopularArticle(healthPopularArticle);
        } catch (Exception e) {
            throw new ServiceException(e.getMessage());
        }
    }

    /**
     * 修改营养科普
     *
     * @param healthPopularArticle 营养科普
     * @return 结果
     */
    @Override
    public int updateHealthPopularArticle(HealthPopularArticle healthPopularArticle) {
        healthPopularArticle.setUpdateTime(DateUtils.getNowDate());
        try {
            return healthPopularArticleMapper.updateHealthPopularArticle(healthPopularArticle);
        } catch (Exception e) {
            throw new ServiceException(e.getMessage());
        }
    }

    /**
     * 批量删除营养科普
     *
     * @param articleIds 需要删除的营养科普主键
     * @return 结果
     */
    @Override
    public int deleteHealthPopularArticleByArticleIds(Long[] articleIds) {
        return healthPopularArticleMapper.deleteHealthPopularArticleByArticleIds(articleIds);
    }

    /**
     * 删除营养科普信息
     *
     * @param articleId 营养科普主键
     * @return 结果
     */
    @Override
    public int deleteHealthPopularArticleByArticleId(Long articleId) {
        return healthPopularArticleMapper.deleteHealthPopularArticleByArticleId(articleId);
    }
}
