package com.yiqi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.yiqi.common.constant.UrlConstants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yiqi.common.annotation.Log;
import com.yiqi.common.core.controller.BaseController;
import com.yiqi.common.core.domain.AjaxResult;
import com.yiqi.common.enums.BusinessType;
import com.yiqi.system.domain.SysSettlementRate;
import com.yiqi.system.service.ISysSettlementRateService;
import com.yiqi.common.utils.poi.ExcelUtil;
import com.yiqi.common.core.page.TableDataInfo;

/**
 * 结算费率Controller
 *
 * @author ruoyi
 * @date 2023-10-17
 */
@Api(tags = "管理后台 - 结算费率")
@RestController
@RequestMapping(UrlConstants.managerApi + "/settlement/rate")
public class SysSettlementRateController extends BaseController {
    @Autowired
    private ISysSettlementRateService sysSettlementRateService;

    /**
     * 查询结算费率列表
     */
    @PreAuthorize("@ss.hasPermi('settlement:rate:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询结算费率列表")
    public TableDataInfo list(SysSettlementRate sysSettlementRate) {
        startPage();
        List<SysSettlementRate> list = sysSettlementRateService.selectSysSettlementRateList(sysSettlementRate);
        return getDataTable(list);
    }

    /**
     * 导出结算费率列表
     */
    @PreAuthorize("@ss.hasPermi('settlement:rate:export')")
    @Log(title = "结算费率", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出结算费率列表")
    public void export(HttpServletResponse response, SysSettlementRate sysSettlementRate) {
        List<SysSettlementRate> list = sysSettlementRateService.selectSysSettlementRateList(sysSettlementRate);
        ExcelUtil<SysSettlementRate> util = new ExcelUtil<SysSettlementRate>(SysSettlementRate. class);
        util.exportExcel(response, list, "结算费率数据");
    }

    /**
     * 获取结算费率详细信息
     */
    @PreAuthorize("@ss.hasPermi('settlement:rate:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取结算费率详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysSettlementRateService.selectSysSettlementRateById(id));
    }

    /**
     * 新增结算费率
     */
    @PreAuthorize("@ss.hasPermi('settlement:rate:add')")
    @Log(title = "结算费率", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增结算费率")
    public AjaxResult add(@RequestBody SysSettlementRate sysSettlementRate) {
        return toAjax(sysSettlementRateService.insertSysSettlementRate(sysSettlementRate));
    }

    /**
     * 修改结算费率
     */
    @PreAuthorize("@ss.hasPermi('settlement:rate:edit')")
    @Log(title = "结算费率", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改结算费率")
    public AjaxResult edit(@RequestBody SysSettlementRate sysSettlementRate) {
        return toAjax(sysSettlementRateService.updateSysSettlementRate(sysSettlementRate));
    }

    /**
     * 删除结算费率
     */
    @PreAuthorize("@ss.hasPermi('settlement:rate:remove')")
    @Log(title = "结算费率", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除结算费率")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysSettlementRateService.deleteSysSettlementRateByIds(ids));
    }

    @GetMapping ("/insertAllRate")
    @ApiOperation(value = "新增全部结算费率")
    public AjaxResult insertAllRate() {
        return toAjax(true);
    }

}

