package org.jeecg.modules.apiService.impl;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.apiBean.PageBean;
import org.jeecg.modules.apiService.NewsService;
import org.jeecg.modules.employBanner.entity.EmployBanner;
import org.jeecg.modules.employBanner.service.IEmployBannerService;
import org.jeecg.modules.employNews.entity.EmployNews;
import org.jeecg.modules.employNews.service.IEmployNewsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class NewsServiceImpl implements NewsService {
    /******************************************************************************************************************/
    //轮播图
    @Resource
    private IEmployNewsService employNewsService;
    /******************************************************************************************************************/

    //新闻资讯-获取新闻列表
    @Override
    public Result<?> queryNewsList(PageBean pageBean) {
        //返回信息
        String message = "获取新闻信息列表失败!";
        //工作信息列表
        Page<EmployNews> pageList = null;
        //分页信息
        Page<EmployNews> page = null;

        try{
            //分页
            page = new Page<EmployNews>(pageBean.getPageNo(), pageBean.getPageSize());
            LambdaQueryChainWrapper<EmployNews> query = employNewsService.lambdaQuery();

            //按时间倒序
            query.orderByDesc(EmployNews::getCreateTime);


            //获取工作信息列表
            pageList = query.page(page);

            //判断执行结果
            if(null != pageList){
                message = "新闻信息列表信息";
            }else {
                message = "新闻信息列表信息为空";
            }

            //返回执行结果
            return Result.OK(message, pageList);

        }catch (Exception e){
            //错误信息打印
            e.printStackTrace();
            return Result.error(message, pageList);
        }
    }

    //新闻资讯-根据id获取新闻详情
    @Override
    public Result<?> queryNewsById(String newsId) {
        //返回信息
        String message = "新闻详情查询失败!";
        //新闻详情
        EmployNews one = null;

        try{
            //获取新闻详情
            one = employNewsService.getById(newsId);

            //判断执行结果
            if(null != one){
                message = "新闻详情信息";
            }else {
                message = "新闻详情为空";
            }

            //返回执行结果
            return Result.OK(message, one);

        }catch (Exception e){
            //错误信息打印
            e.printStackTrace();
            return Result.error(message, one);
        }
    }
}
