package com.ruoyi.frequency.agreement.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.frequency.agreement.entity.Agreement;
import com.ruoyi.frequency.agreement.service.AgreementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 协议Controller
 * 
 * @author liwenlong
 * @date 2023-10-26
 */
@RestController
@RequestMapping("/frequency/agreement")
public class AgreementController extends BaseController
{
    @Autowired
    private AgreementService agreementService;

    /**
     * 查询协议列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:agreement:list')")
    @PostMapping("/list")
    public TableDataInfo<Agreement> list(@RequestBody Agreement agreement)
    {
        startPage();
        List<Agreement> list = agreementService.selectAgreementList(agreement);
        return getDataTable(list);
    }

    /**
     * 导出协议列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:agreement:export')")
    @Log(title = "协议", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Agreement agreement)
    {
        List<Agreement> list = agreementService.selectAgreementList(agreement);
        ExcelUtil<Agreement> util = new ExcelUtil<Agreement>(Agreement.class);
        return util.exportExcel(list, "协议数据");
    }

    /**
     * 获取协议详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:agreement:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<Agreement> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(agreementService.selectAgreementById(id));
    }

    /**
     * 新增协议
     */
    @PreAuthorize("@ss.hasPermi('frequency:agreement:add')")
    @Log(title = "协议", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Agreement agreement)
    {
        return toAjax(agreementService.insertAgreement(agreement));
    }

    /**
     * 修改协议
     */
    @PreAuthorize("@ss.hasPermi('frequency:agreement:edit')")
    @Log(title = "协议", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Agreement agreement)
    {
        return toAjax(agreementService.updateAgreement(agreement));
    }

    /**
     * 删除协议
     */
    @PreAuthorize("@ss.hasPermi('frequency:agreement:remove')")
    @Log(title = "协议", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}/{delFlag}")
    public AjaxResult remove(@PathVariable("ids") Long[] ids,@PathVariable("delFlag") Integer delFalg)
    {
        return toAjax(agreementService.deleteAgreementByIds(ids,delFalg));
    }
}
