package com.ruoyi.web.controller.ss;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ss.apiBill.domain.ApiBill;
import com.ruoyi.ss.apiBill.domain.ApiBillVO;
import com.ruoyi.ss.apiBill.domain.ApiBillQuery;
import com.ruoyi.ss.apiBill.service.ApiBillService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * API收费订单Controller
 *
 * @author ruoyi
 * @date 2024-08-09
 */
@RestController
@RequestMapping("/ss/apiBill")
public class ApiBillController extends BaseController
{
    @Autowired
    private ApiBillService apiBillService;

    /**
     * 查询API收费订单列表
     */
    @PreAuthorize("@ss.hasPermi('ss:apiBill:list')")
    @GetMapping("/list")
    public TableDataInfo list(ApiBillQuery query)
    {
        startPage();
        startOrderBy();
        List<ApiBillVO> list = apiBillService.selectApiBillList(query);
        return getDataTable(list);
    }

    /**
     * 导出API收费订单列表
     */
    @PreAuthorize("@ss.hasPermi('ss:apiBill:export')")
    @Log(title = "API收费订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ApiBillQuery query)
    {
        List<ApiBillVO> list = apiBillService.selectApiBillList(query);
        ExcelUtil<ApiBillVO> util = new ExcelUtil<ApiBillVO>(ApiBillVO.class);
        util.exportExcel(response, list, "API收费订单数据");
    }

    /**
     * 获取API收费订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('ss:apiBill:query')")
    @GetMapping(value = "/{billId}")
    public AjaxResult getInfo(@PathVariable("billId") Long billId)
    {
        return success(apiBillService.selectApiBillByBillId(billId));
    }

    /**
     * 新增API收费订单
     */
    @PreAuthorize("@ss.hasPermi('ss:apiBill:add')")
    @Log(title = "API收费订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ApiBill apiBill)
    {
        return toAjax(apiBillService.insertApiBill(apiBill));
    }

    /**
     * 修改API收费订单
     */
    @PreAuthorize("@ss.hasPermi('ss:apiBill:edit')")
    @Log(title = "API收费订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ApiBill apiBill)
    {
        return toAjax(apiBillService.updateApiBill(apiBill));
    }

    /**
     * 删除API收费订单
     */
    @PreAuthorize("@ss.hasPermi('ss:apiBill:remove')")
    @Log(title = "API收费订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{billIds}")
    public AjaxResult remove(@PathVariable Long[] billIds)
    {
        return toAjax(apiBillService.deleteApiBillByBillIds(billIds));
    }
}
