package com.ruoyi.hezhi.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.hezhi.domain.TbEvaluateAgency;
import com.ruoyi.hezhi.domain.vo.EvaluateAgencyVO;
import com.ruoyi.hezhi.service.ITbEvaluateAgencyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 评价机构Controller
 *
 * @author ruoyi
 * @date 2024-10-23
 */
@RestController
@RequestMapping("/hezhi/evaluateAgency")
public class TbEvaluateAgencyController extends BaseController
{
    @Autowired
    private ITbEvaluateAgencyService tbEvaluateAgencyService;

    /**
     * 查询评价机构列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:evaluateAgency:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbEvaluateAgency tbEvaluateAgency)
    {
        startPage();
        List<TbEvaluateAgency> list = tbEvaluateAgencyService.selectTbEvaluateAgencyList(tbEvaluateAgency);
        return getDataTable(list);
    }

    /**
     * 导出评价机构列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:evaluateAgency:export')")
    @Log(title = "评价机构", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbEvaluateAgency tbEvaluateAgency)
    {
        List<TbEvaluateAgency> list = tbEvaluateAgencyService.selectTbEvaluateAgencyList(tbEvaluateAgency);
        ExcelUtil<TbEvaluateAgency> util = new ExcelUtil<TbEvaluateAgency>(TbEvaluateAgency.class);
        util.exportExcel(response, list, "评价机构数据");
    }

    /**
     * 获取评价机构详细信息
     */
    @PreAuthorize("@ss.hasPermi('hezhi:evaluateAgency:query')")
    @GetMapping(value = "/{evaluateAgencyId}")
    public AjaxResult getInfo(@PathVariable("evaluateAgencyId") Long evaluateAgencyId)
    {
        return success(tbEvaluateAgencyService.selectTbEvaluateAgencyByEvaluateAgencyId(evaluateAgencyId));
    }

    /**
     * 新增评价机构
     */
    @PreAuthorize("@ss.hasPermi('hezhi:evaluateAgency:add')")
    @Log(title = "评价机构", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbEvaluateAgency tbEvaluateAgency)
    {
        return toAjax(tbEvaluateAgencyService.insertTbEvaluateAgency(tbEvaluateAgency));
    }

    /**
     * 修改评价机构
     */
    @PreAuthorize("@ss.hasPermi('hezhi:evaluateAgency:edit')")
    @Log(title = "评价机构", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbEvaluateAgency tbEvaluateAgency)
    {
        return toAjax(tbEvaluateAgencyService.updateTbEvaluateAgency(tbEvaluateAgency));
    }

    /**
     * 删除评价机构
     */
    @PreAuthorize("@ss.hasPermi('hezhi:evaluateAgency:remove')")
    @Log(title = "评价机构", businessType = BusinessType.DELETE)
	@DeleteMapping("/{evaluateAgencyIds}")
    public AjaxResult remove(@PathVariable Long[] evaluateAgencyIds)
    {
        return toAjax(tbEvaluateAgencyService.deleteTbEvaluateAgencyByEvaluateAgencyIds(evaluateAgencyIds));
    }

    /**
     * 获取筛选列表
     * @return 结果
     */
    @GetMapping("/getSelectList")
    public AjaxResult getSelectList(){
        List<EvaluateAgencyVO> selectList = tbEvaluateAgencyService.getSelectList();
        return AjaxResult.success(selectList);
    }
}
