package com.ruoyi.web.controller.dxp.customer;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.dxp.constant.DxpConstants;
import com.ruoyi.dxp.domain.*;
import com.ruoyi.dxp.dto.customer.IndexStatisticsDto;
import com.ruoyi.dxp.mapper.IndexStaticsMapper;
import com.ruoyi.dxp.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 首页
 */
@RestController
@RequestMapping("/customer/index")
public class IndexCustomerController extends BaseController {

    @Autowired
    private ITopicService topicService;

    @Autowired
    private ICatalogueService catalogueService;

    @Autowired
    private IDataShareService dataShareService;

    @Autowired
    private IServiceShareService serviceShareService;

    @Autowired
    private ILiteratureService literatureService;

    @Autowired
    private IndexStaticsMapper indexStaticsMapper;

    /**
     * 查询热门目录列表
     */
//    @Anonymous
    @GetMapping("/hotcatalogue")
    public TableDataInfo hotCatalogueList(Catalogue catalogue) {
        startPage();
        catalogue.setCatalogueType(DxpConstants.DATA_TYPE_SHARE);
        List<Catalogue> list = catalogueService.selectCatalogueList(catalogue);
        return getDataTable(list);
    }

    /**
     * 首页统计
     */
//    @Anonymous
    @GetMapping("/statis")
    public AjaxResult indexStatistics() {
        IndexStatisticsDto dto = new IndexStatisticsDto();

        // 查询表数量
        dto.setTableCount(indexStaticsMapper.selectTableCount());

        // 查询数据项
        dto.setTableItemCount(indexStaticsMapper.selectDataItemCount());

        // 查询应用数
        dto.setAppCount(indexStaticsMapper.selectAppCount());

        dto.setDataCount(0);
        return success(dto);
    }

    /**
     * 热点数据
     */
//    @Anonymous
    @GetMapping("/hotdatalist")
    public TableDataInfo list(DataShare dataShare) {
        startPage();
        dataShare.setStatus(DxpConstants.STATUS_VALID);
        List<DataShare> list = dataShareService.selectHotDataShareList(dataShare);
        return getDataTable(list);
    }

    /**
     * 热点服务
     */
//    @Anonymous
    @GetMapping("/hotservicelist")
    public TableDataInfo list(ServiceShare serviceShare)
    {
        startPage();
        serviceShare.setStatus(DxpConstants.STATUS_VALID);
        List<ServiceShare> list = serviceShareService.selectHotServiceShareList(serviceShare);
        return getDataTable(list);
    }

    /**
     * 热点文献
     */
//    @Anonymous
    @GetMapping("/hotliteratur")
    public TableDataInfo literaturLlist(Literature literature)
    {
        startPage();
        List<Literature> list = literatureService.selectHotLiteratureList(literature);
        // 用户查询不返回地址
        if (list != null && list.size() > 0) {
            for (Literature item : list) {
                item.setFileUrl("");
            }
        }
        return getDataTable(list);
    }

    /**
     * 首页专题
     */
//    @Anonymous
    @GetMapping("/topiclist")
    public TableDataInfo topicList(Topic topic)
    {
        startPage();
        topic.setStatus(DxpConstants.STATUS_VALID);
        List<Topic> list = topicService.selectTopicList(topic);
        return getDataTable(list);
    }
}
