package com.ruoyi.web.controller.business;

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.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.system.domain.SettledMerchants;
import com.ruoyi.system.service.ISettledMerchantsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 入驻商家Controller
 * 
 * @author boman
 * @date 2022-06-10
 */
@RestController
@RequestMapping("/system/merchants")
public class SettledMerchantsController extends BaseController
{
    @Autowired
    private ISettledMerchantsService settledMerchantsService;

    /**
     * 查询入驻商家列表
     */
    @PreAuthorize("@ss.hasPermi('system:merchants:list')")
    @GetMapping("/list")
    public TableDataInfo list(SettledMerchants settledMerchants)
    {
        List<SettledMerchants> list = settledMerchantsService.selectSettledMerchantsList(settledMerchants);
        return getDataTable(list);
    }

    /**
     * 查询入驻商家列表（不分页）
     */
    @PreAuthorize("@ss.hasPermi('system:merchants:list')")
    @GetMapping("/listAll")
    public TableDataInfo listAll(SettledMerchants settledMerchants)
    {
        List<SettledMerchants> list = settledMerchantsService.selectSettledMerchantsList(settledMerchants);
        return getDataTable(list);
    }

    /**
     * 导出入驻商家列表
     */
    @PreAuthorize("@ss.hasPermi('system:merchants:export')")
    @Log(title = "入驻商家", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SettledMerchants settledMerchants)
    {
        List<SettledMerchants> list = settledMerchantsService.selectSettledMerchantsList(settledMerchants);
        ExcelUtil<SettledMerchants> util = new ExcelUtil<SettledMerchants>(SettledMerchants.class);
        util.exportExcel(response, list, "入驻商家数据");
    }

    /**
     * 获取入驻商家详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:merchants:query')")
    @GetMapping(value = "/{businessId}")
    public AjaxResult getInfo(@PathVariable("businessId") Long businessId)
    {
        return AjaxResult.success(settledMerchantsService.selectSettledMerchantsByBusinessId(businessId));
    }

    /**
     * 根据政策类别获取入驻商家详细信息
     */
    @GetMapping(value = "/menu/{menuId}")
    public AjaxResult getInfoByMenuId(@PathVariable("menuId") Long menuId)
    {
        return AjaxResult.success(settledMerchantsService.selectSettledMerchantsByMenuId(menuId));
    }

    /**
     * 新增入驻商家
     */
    @PreAuthorize("@ss.hasPermi('system:merchants:add')")
    @Log(title = "入驻商家", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SettledMerchants settledMerchants)
    {
        return settledMerchantsService.insertSettledMerchants(settledMerchants);
    }

    /**
     * 修改入驻商家
     */
    @PreAuthorize("@ss.hasPermi('system:merchants:edit')")
    @Log(title = "入驻商家", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody SettledMerchants settledMerchants)
    {
        return toAjax(settledMerchantsService.updateSettledMerchants(settledMerchants));
    }

    /**
     * 删除入驻商家
     */
    @PreAuthorize("@ss.hasPermi('system:merchants:remove')")
    @Log(title = "入驻商家", businessType = BusinessType.DELETE)
	@DeleteMapping("/{businessIds}")
    public AjaxResult remove(@PathVariable Long[] businessIds)
    {
        return toAjax(settledMerchantsService.deleteSettledMerchantsByBusinessIds(businessIds));
    }
}
