package com.ruoyi.web.controller.ss;

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

import com.ruoyi.common.core.domain.ValidGroup;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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.apiPrice.domain.ApiPrice;
import com.ruoyi.ss.apiPrice.domain.ApiPriceVO;
import com.ruoyi.ss.apiPrice.domain.ApiPriceQuery;
import com.ruoyi.ss.apiPrice.service.ApiPriceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * API收费标准Controller
 *
 * @author ruoyi
 * @date 2024-08-08
 */
@RestController
@RequestMapping("/ss/apiPrice")
public class ApiPriceController extends BaseController
{
    @Autowired
    private ApiPriceService apiPriceService;

    /**
     * 查询API收费标准列表
     */
    @PreAuthorize("@ss.hasPermi('ss:apiPrice:list')")
    @GetMapping("/list")
    public TableDataInfo list(ApiPriceQuery query)
    {
        startPage();
        startOrderBy();
        List<ApiPriceVO> list = apiPriceService.selectApiPriceList(query);
        return getDataTable(list);
    }

    /**
     * 导出API收费标准列表
     */
    @PreAuthorize("@ss.hasPermi('ss:apiPrice:export')")
    @Log(title = "API收费标准", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ApiPriceQuery query)
    {
        List<ApiPriceVO> list = apiPriceService.selectApiPriceList(query);
        ExcelUtil<ApiPriceVO> util = new ExcelUtil<ApiPriceVO>(ApiPriceVO.class);
        util.exportExcel(response, list, "API收费标准数据");
    }

    /**
     * 获取API收费标准详细信息
     */
    @PreAuthorize("@ss.hasPermi('ss:apiPrice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(apiPriceService.selectApiPriceById(id));
    }

    /**
     * 新增API收费标准
     */
    @PreAuthorize("@ss.hasPermi('ss:apiPrice:add')")
    @Log(title = "API收费标准", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Validated(ValidGroup.Create.class) ApiPrice apiPrice)
    {
        apiPrice.setCreateBy(getUsername());
        return toAjax(apiPriceService.insertApiPrice(apiPrice));
    }

    /**
     * 修改API收费标准
     */
    @PreAuthorize("@ss.hasPermi('ss:apiPrice:edit')")
    @Log(title = "API收费标准", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody @Validated(ValidGroup.Update.class) ApiPrice apiPrice)
    {
        apiPrice.setUpdateBy(getUsername());
        return toAjax(apiPriceService.updateApiPrice(apiPrice));
    }

    /**
     * 删除API收费标准
     */
    @PreAuthorize("@ss.hasPermi('ss:apiPrice:remove')")
    @Log(title = "API收费标准", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(apiPriceService.logicDel(ids));
    }
}
