package com.ruoyi.web.controller.portal;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.system.domain.Introduction;
import com.ruoyi.system.domain.News;
import com.ruoyi.system.domain.Overview;
import com.ruoyi.system.domain.Value;
import com.ruoyi.system.service.IIntroductionService;
import com.ruoyi.system.service.INewsService;
import com.ruoyi.system.service.IOverviewService;
import com.ruoyi.system.service.IValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Anonymous
@RestController
@RequestMapping("/portal/home")
public class PortalHomeController extends BaseController {

    @Autowired
    private INewsService newsService;

    @Autowired
    private IOverviewService overviewService;

    @Autowired
    private IIntroductionService introductionService;

    @Autowired
    private IValueService valueService;

    @GetMapping("/data")
    public AjaxResult getHomeData() {
        Map<String, Object> data = new HashMap<>();
        
        Overview overview = overviewService.selectOverviewOne();
        data.put("overview", overview);
        
        Introduction introduction = introductionService.selectIntroductionOne();
        data.put("introduction", introduction);
        
        Value valueQuery = new Value();
        valueQuery.setStatus("0");
        List<Value> valueList = valueService.selectValueList(valueQuery);
        if (valueList != null && valueList.size() > 3) {
            data.put("valueList", valueList.subList(0, 3));
        } else {
            data.put("valueList", valueList);
        }
        
        data.put("introCards", new Object[]{});
        data.put("dataCards", new Object[]{});
        data.put("newsList", new Object[]{});
        data.put("coopCards", new Object[]{});
        return AjaxResult.success(data);
    }

    @GetMapping("/banner")
    public AjaxResult getBannerList() {
        News query = new News();
        query.setStatus("0");
        List<News> newsList = newsService.selectNewsList(query);
        return AjaxResult.success(newsList);
    }

    @GetMapping("/news")
    public AjaxResult getNewsList() {
        return AjaxResult.success(new Object[]{});
    }
}
