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.TbCooperatePartner;
import com.ruoyi.hezhi.service.ITbCooperatePartnerService;
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-16
 */
@RestController
@RequestMapping("/hezhi/cooperatePartner")
public class TbCooperatePartnerController extends BaseController
{
    @Autowired
    private ITbCooperatePartnerService tbCooperatePartnerService;

    /**
     * 查询合作伙伴列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:cooperatePartner:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbCooperatePartner tbCooperatePartner)
    {
        startPage();
        List<TbCooperatePartner> list = tbCooperatePartnerService.selectTbCooperatePartnerList(tbCooperatePartner);
        return getDataTable(list);
    }

    /**
     * 导出合作伙伴列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:cooperatePartner:export')")
    @Log(title = "合作伙伴", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbCooperatePartner tbCooperatePartner)
    {
        List<TbCooperatePartner> list = tbCooperatePartnerService.selectTbCooperatePartnerList(tbCooperatePartner);
        ExcelUtil<TbCooperatePartner> util = new ExcelUtil<TbCooperatePartner>(TbCooperatePartner.class);
        util.exportExcel(response, list, "合作伙伴数据");
    }

    /**
     * 获取合作伙伴详细信息
     */
    @PreAuthorize("@ss.hasPermi('hezhi:cooperatePartner:query')")
    @GetMapping(value = "/{cooperatePartnerId}")
    public AjaxResult getInfo(@PathVariable("cooperatePartnerId") Long cooperatePartnerId)
    {
        return success(tbCooperatePartnerService.selectTbCooperatePartnerByCooperatePartnerId(cooperatePartnerId));
    }

    /**
     * 新增合作伙伴
     */
    @PreAuthorize("@ss.hasPermi('hezhi:cooperatePartner:add')")
    @Log(title = "合作伙伴", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbCooperatePartner tbCooperatePartner)
    {
        return toAjax(tbCooperatePartnerService.insertTbCooperatePartner(tbCooperatePartner));
    }

    /**
     * 修改合作伙伴
     */
    @PreAuthorize("@ss.hasPermi('hezhi:cooperatePartner:edit')")
    @Log(title = "合作伙伴", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbCooperatePartner tbCooperatePartner)
    {
        return toAjax(tbCooperatePartnerService.updateTbCooperatePartner(tbCooperatePartner));
    }

    /**
     * 删除合作伙伴
     */
    @PreAuthorize("@ss.hasPermi('hezhi:cooperatePartner:remove')")
    @Log(title = "合作伙伴", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cooperatePartnerIds}")
    public AjaxResult remove(@PathVariable Long[] cooperatePartnerIds)
    {
        return toAjax(tbCooperatePartnerService.deleteTbCooperatePartnerByCooperatePartnerIds(cooperatePartnerIds));
    }
}
