package com.ruoyi.web.modules.news.service.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.web.modules.news.domain.FarmingNewsListVo;
import com.ruoyi.web.modules.news.domain.FarmingNewsQuery;
import com.ruoyi.web.modules.news.domain.FarmingNewsRow;
import com.ruoyi.web.modules.news.mapper.FarmingNewsMapper;
import com.ruoyi.web.modules.news.service.IFarmingNewsService;
import com.ruoyi.web.modules.news.support.FarmingNewsQuerySupport;

@Service
public class FarmingNewsServiceImpl implements IFarmingNewsService
{
    @Autowired
    private FarmingNewsMapper farmingNewsMapper;

    @Override
    public List<FarmingNewsListVo> selectFarmingNewsList(FarmingNewsQuery query)
    {
        FarmingNewsQuery effective = FarmingNewsQuerySupport.normalize(query);
        List<FarmingNewsRow> rows = farmingNewsMapper.selectFarmingNewsList(effective);
        if (rows == null || rows.isEmpty())
        {
            return Collections.emptyList();
        }
        List<FarmingNewsListVo> result = new ArrayList<>(rows.size());
        for (FarmingNewsRow row : rows)
        {
            result.add(toListVo(row));
        }
        return result;
    }

    private static FarmingNewsListVo toListVo(FarmingNewsRow row)
    {
        FarmingNewsListVo vo = new FarmingNewsListVo();
        vo.setTitle(row.getTitle());
        vo.setIntroduction(row.getIntroduction());
        vo.setType(row.getType());
        vo.setCoverFileUrl(row.getCoverFileUrl());
        vo.setContentFileUrl(row.getContentFileUrl());
        vo.setPublishTime(row.getPublishTime());
        return vo;
    }
}
