package com.ff.common.controller;

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.ff.base.annotation.Log;
import com.ff.base.core.controller.BaseController;
import com.ff.base.core.domain.AjaxResult;
import com.ff.base.enums.BusinessType;
import com.ff.common.domain.Currency;
import com.ff.common.service.ICurrencyService;
import com.ff.base.utils.poi.ExcelUtil;
import com.ff.base.core.page.TableDataInfo;

/**
 * 币种Controller
 *
 * @author shi
 * @date 2025-02-10
 */
@RestController
@RequestMapping("/common/currency")
public class CurrencyController extends BaseController
{
    @Autowired
    private ICurrencyService currencyService;

    /**
     * 查询币种列表
     */
    @PreAuthorize("@ss.hasPermi('common:currency:list')")
    @GetMapping("/list")
    public TableDataInfo list(Currency currency)
    {
        startPage();
        List<Currency> list = currencyService.selectCurrencyList(currency);
        return getDataTable(list);
    }

    /**
     * 导出币种列表
     */
    @PreAuthorize("@ss.hasPermi('common:currency:export')")
    @Log(title = "币种", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Currency currency)
    {
        List<Currency> list = currencyService.selectCurrencyList(currency);
        ExcelUtil<Currency> util = new ExcelUtil<Currency>(Currency.class);
        util.exportExcel(response, list, "币种数据");
    }

    /**
     * 获取币种详细信息
     */
    @PreAuthorize("@ss.hasPermi('common:currency:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(currencyService.selectCurrencyById(id));
    }

    /**
     * 新增币种
     */
    @PreAuthorize("@ss.hasPermi('common:currency:add')")
    @Log(title = "币种", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Currency currency)
    {
        return toAjax(currencyService.insertCurrency(currency));
    }

    /**
     * 修改币种
     */
    @PreAuthorize("@ss.hasPermi('common:currency:edit')")
    @Log(title = "币种", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Currency currency)
    {
        return toAjax(currencyService.updateCurrency(currency));
    }

    /**
     * 删除币种
     */
    @PreAuthorize("@ss.hasPermi('common:currency:remove')")
    @Log(title = "币种", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(currencyService.deleteCurrencyByIds(ids));
    }
}
