package com.ruoyi.web.modules.trading.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
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.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.modules.trading.domain.BizDistributor;
import com.ruoyi.web.modules.trading.service.IBizDistributorService;

/**
 * 承销商管理
 */
@RestController
@RequestMapping("/tradeMarket/distributor")
public class BizDistributorController extends BaseController
{
    @Autowired
    private IBizDistributorService bizDistributorService;

    @PreAuthorize("@ss.hasPermi('tradeMarket:distributor:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizDistributor query)
    {
        startPage();
        List<BizDistributor> list = bizDistributorService.selectBizDistributorList(query);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('tradeMarket:distributor:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizDistributorService.selectBizDistributorById(id));
    }

    @PreAuthorize("@ss.hasPermi('tradeMarket:distributor:add')")
    @Log(title = "承销商管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody BizDistributor row)
    {
        row.setCreateBy(getUsername());
        return toAjax(bizDistributorService.insertBizDistributor(row));
    }

    @PreAuthorize("@ss.hasPermi('tradeMarket:distributor:edit')")
    @Log(title = "承销商管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody BizDistributor row)
    {
        row.setUpdateBy(getUsername());
        return toAjax(bizDistributorService.updateBizDistributor(row));
    }

    @PreAuthorize("@ss.hasPermi('tradeMarket:distributor:remove')")
    @Log(title = "承销商管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizDistributorService.deleteBizDistributorByIds(ids, getUsername()));
    }

    @PreAuthorize("@ss.hasPermi('tradeMarket:distributor:assignAccount')")
    @Log(title = "承销商分配账号", businessType = BusinessType.INSERT)
    @PostMapping("/assignAccount/{id}")
    public AjaxResult assignAccount(@PathVariable Long id)
    {
        return toAjax(bizDistributorService.assignAccount(id, getUsername()));
    }
}
