package com.ruoyi.web.controller.system;

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.system.domain.Issuer;
import com.ruoyi.system.service.IIssuerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 发行方Controller
 *
 * @author ruoyi
 * @date 2023-02-14
 */
@Api(tags = "IssuerController",description = "发行方")
@RestController
@RequestMapping("/system/issuer")
public class IssuerController extends BaseController
{
    @Autowired
    private IIssuerService issuerService;

    /**
     * 查询发行方列表
     */
    @ApiOperation("查询发行方列表")
    @PreAuthorize("@ss.hasPermi('system:issuer:list')")
    @GetMapping("/list")
    public TableDataInfo list(Issuer issuer)
    {
        startPage();
        List<Issuer> list = issuerService.selectIssuerList(issuer);
        return getDataTable(list);
    }

    /**
     * 导出发行方列表
     */
    @ApiOperation("导出发行方列表")
    @PreAuthorize("@ss.hasPermi('system:issuer:export')")
    @Log(title = "发行方", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Issuer issuer)
    {
        List<Issuer> list = issuerService.selectIssuerList(issuer);
        ExcelUtil<Issuer> util = new ExcelUtil<Issuer>(Issuer.class);
        util.exportExcel(response, list, "发行方数据");
    }

    /**
     * 获取发行方详细信息
     */
    @ApiOperation("获取发行方详细信息")
    @PreAuthorize("@ss.hasPermi('system:issuer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(issuerService.selectIssuerById(id));
    }

    /**
     * 新增发行方
     */
    @ApiOperation("新增发行方")
    @PreAuthorize("@ss.hasPermi('system:issuer:add')")
    @Log(title = "发行方", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Issuer issuer)
    {
        return toAjax(issuerService.insertIssuer(issuer));
    }

    /**
     * 修改发行方
     */
    @ApiOperation("修改发行方")
    @PreAuthorize("@ss.hasPermi('system:issuer:edit')")
    @Log(title = "发行方", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Issuer issuer)
    {
        return toAjax(issuerService.updateIssuer(issuer));
    }

    /**
     * 删除发行方
     */
    @ApiOperation("删除发行方")
    @PreAuthorize("@ss.hasPermi('system:issuer:remove')")
    @Log(title = "发行方", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(issuerService.deleteIssuerByIds(ids));
    }
    /**
     * 根据发行方名字搜索发行方列表
     */
    @ApiOperation("根据发行方名字搜索发行方列表")
    @PreAuthorize("@ss.hasPermi('system:issuer:searchIssuer')")
    @GetMapping("/searchIssuer")
    public AjaxResult searchIssuer(@RequestParam(required = false) String issuerName){
        startPage();
        List<Issuer> list= issuerService.selectByIssuerName(issuerName);
        return AjaxResult.success(list);
    }
}
