package com.zehong.web.controller.evaluate;

import com.zehong.common.annotation.Log;
import com.zehong.common.core.controller.BaseController;
import com.zehong.common.core.domain.AjaxResult;
import com.zehong.common.core.page.TableDataInfo;
import com.zehong.common.enums.BusinessType;
import com.zehong.common.utils.poi.ExcelUtil;
import com.zehong.system.domain.TEnterpriseRanking;
import com.zehong.system.service.ITEnterpriseRankingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 企业评价Controller
 * 
 * @author zehong
 * @date 2026-03-17
 */
@RestController
@RequestMapping("/system/ranking")
public class TEnterpriseRankingController extends BaseController
{
    @Autowired
    private ITEnterpriseRankingService tEnterpriseRankingService;

    /**
     * 查询企业评价列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TEnterpriseRanking tEnterpriseRanking)
    {
        startPage();
        List<TEnterpriseRanking> list = tEnterpriseRankingService.selectTEnterpriseRankingList(tEnterpriseRanking);
        return getDataTable(list);
    }

    /**
     * 导出企业评价列表
     */
    @Log(title = "企业评价", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TEnterpriseRanking tEnterpriseRanking)
    {
        List<TEnterpriseRanking> list = tEnterpriseRankingService.selectTEnterpriseRankingList(tEnterpriseRanking);
        ExcelUtil<TEnterpriseRanking> util = new ExcelUtil<TEnterpriseRanking>(TEnterpriseRanking.class);
        return util.exportExcel(list, "企业评价数据");
    }

    /**
     * 获取企业评价详细信息
     */
    @GetMapping(value = "/{rankingId}")
    public AjaxResult getInfo(@PathVariable("rankingId") Long rankingId)
    {
        return AjaxResult.success(tEnterpriseRankingService.selectTEnterpriseRankingById(rankingId));
    }

    /**
     * 新增企业评价
     */
    @Log(title = "企业评价", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TEnterpriseRanking tEnterpriseRanking)
    {
        return toAjax(tEnterpriseRankingService.insertTEnterpriseRanking(tEnterpriseRanking));
    }

    /**
     * 修改企业评价
     */
    @Log(title = "企业评价", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TEnterpriseRanking tEnterpriseRanking)
    {
        return toAjax(tEnterpriseRankingService.updateTEnterpriseRanking(tEnterpriseRanking));
    }

    /**
     * 删除企业评价
     */
    @Log(title = "企业评价", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rankingIds}")
    public AjaxResult remove(@PathVariable Long[] rankingIds)
    {
        return toAjax(tEnterpriseRankingService.deleteTEnterpriseRankingByIds(rankingIds));
    }

    /**
     * 根据年份获取企业评价评分
     */
    @GetMapping(value = "/byyear")
    public AjaxResult getInfo(Integer yearNum)
    {
        return AjaxResult.success(tEnterpriseRankingService.selectFractionByYear(yearNum));
    }

}
