package com.microservices.dms.resourceLibrary.controller;

import com.microservices.common.core.utils.poi.ExcelUtil;
import com.microservices.common.core.web.controller.BaseController;
import com.microservices.common.core.web.domain.AjaxResult;
import com.microservices.common.core.web.page.TableDataInfo;
import com.microservices.common.log.annotation.Log;
import com.microservices.common.log.enums.BusinessType;
import com.microservices.dms.resourceLibrary.domain.ExpertResourceLibrary;
import com.microservices.dms.resourceLibrary.service.IExpertResourceLibraryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 专家资源库Controller
 * 
 * @author microservices
 * @date 2025-04-11
 */
@Api(tags = "数据管理体系-优质专家库")
@RestController
@RequestMapping("/expertResourceLibrary")
public class ExpertResourceLibraryController extends BaseController
{
    @Autowired
    private IExpertResourceLibraryService expertResourceLibraryService;

    /**
     * 查询专家资源库列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ExpertResourceLibrary expertResourceLibrary)
    {
        startPage();
        List<ExpertResourceLibrary> list = expertResourceLibraryService.selectExpertResourceLibraryList(expertResourceLibrary);
        return getDataTable(list);
    }


    /**
     * 查询专家资源库列表
     */
    @GetMapping("/listFront")
    public TableDataInfo listFront(ExpertResourceLibrary expertResourceLibrary)
    {
        startPage();
        List<ExpertResourceLibrary> list = expertResourceLibraryService.selectExpertResourceLibraryList2(expertResourceLibrary);
        return getDataTable(list);
    }

    /**
     * 导出专家资源库列表
     */
    @Log(title = "专家资源库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExpertResourceLibrary expertResourceLibrary)
    {
        List<ExpertResourceLibrary> list = expertResourceLibraryService.selectExpertResourceLibraryList(expertResourceLibrary);
        ExcelUtil<ExpertResourceLibrary> util = new ExcelUtil<ExpertResourceLibrary>(ExpertResourceLibrary.class);
        util.exportExcel(response, list, "专家资源库数据");
    }

    /**
     * 获取专家资源库详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(expertResourceLibraryService.selectExpertResourceLibraryById(id));
    }

    /**
     * 新增专家资源库
     */
    @Log(title = "专家资源库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExpertResourceLibrary expertResourceLibrary)
    {
        return toAjax(expertResourceLibraryService.insertExpertResourceLibrary(expertResourceLibrary));
    }

    /**
     * 修改专家资源库
     */
    @Log(title = "专家资源库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExpertResourceLibrary expertResourceLibrary)
    {
        return toAjax(expertResourceLibraryService.updateExpertResourceLibrary(expertResourceLibrary));
    }

    /**
     * 删除专家资源库
     */
    @Log(title = "专家资源库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(expertResourceLibraryService.deleteExpertResourceLibraryByIds(ids));
    }

    @ApiOperation(value = "评审专家数")
	@GetMapping("/auditExpertCount")
    public AjaxResult auditExpertCount()
    {
        return AjaxResult.success(expertResourceLibraryService.auditExpertCount());
    }

    @ApiOperation(value = "竞赛评审数")
	@GetMapping("/competitionAuditCount")
    public AjaxResult competitionAuditCount()
    {
        return AjaxResult.success(expertResourceLibraryService.competitionAuditCount());
    }

    @ApiOperation(value = "任务评审数")
	@GetMapping("/taskAuditCount")
    public AjaxResult taskAuditCount()
    {
        return AjaxResult.success(expertResourceLibraryService.taskAuditCount());
    }


    @ApiOperation("根据当前用户以及专家ID,获取当前专家的 是否收藏与关注状态")
    @GetMapping("/getWatchFavoriteStatusById")
    public AjaxResult getWatchFavoriteStatusById(Long id, Long userId) {
        return success(expertResourceLibraryService.getWatchFavoriteStatusById(id, userId));
    }


    @ApiOperation("根据成果ID,获取专家的相关行为数据统计（点击量、搜索量、附件下载量、收藏、关注）")
    @GetMapping("/getActDataStatisticById")
    public AjaxResult getActDataStatisticById(Long id) {
        return success(expertResourceLibraryService.getActDataStatisticById(id));
    }
}
