package com.dcsoft.system.consume.controller;

import com.dcsoft.common.core.utils.poi.ExcelUtil;
import com.dcsoft.common.core.web.controller.BaseController;
import com.dcsoft.common.core.web.domain.AjaxResult;
import com.dcsoft.common.core.web.page.TableDataInfo;
import com.dcsoft.common.log.annotation.Log;
import com.dcsoft.common.log.enums.BusinessType;
import com.dcsoft.common.security.annotation.RequiresPermissions;
import com.dcsoft.system.consume.domain.ConsumeTenant;
import com.dcsoft.system.consume.service.IConsumeTenantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 商户信息Controller
 *
 * @author nichun
 * @date 2023-09-15
 */
@RestController
@RequestMapping("/consumeTenant")
public class ConsumeTenantController extends BaseController
{
    @Autowired
    private IConsumeTenantService consumeTenantService;

    /**
     * 查询商户信息列表
     */
    @RequiresPermissions("consume:consumeTenant:list")
    @GetMapping("/list")
    public TableDataInfo list(ConsumeTenant consumeTenant)
    {
        startPage();
        List<ConsumeTenant> list = consumeTenantService.selectConsumeTenantList(consumeTenant);
        return getDataTable(list);
    }

    /**
     * 导出商户信息列表
     */
    @RequiresPermissions("consume:consumeTenant:export")
    @Log(title = "商户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ConsumeTenant consumeTenant)
    {
        List<ConsumeTenant> list = consumeTenantService.selectConsumeTenantList(consumeTenant);
        ExcelUtil<ConsumeTenant> util = new ExcelUtil<ConsumeTenant>(ConsumeTenant.class);
        util.exportExcel(response, list, "商户信息数据");
    }

    /**
     * 获取商户信息详细信息
     */
    @RequiresPermissions("consume:consumeTenant:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(consumeTenantService.selectConsumeTenantById(id));
    }

    /**
     * 新增商户信息
     */
    @RequiresPermissions("consume:consumeTenant:add")
    @Log(title = "商户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ConsumeTenant consumeTenant)
    {
        return toAjax(consumeTenantService.insertConsumeTenant(consumeTenant));
    }

    /**
     * 修改商户信息
     */
    @RequiresPermissions("consume:consumeTenant:edit")
    @Log(title = "商户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ConsumeTenant consumeTenant)
    {
        return toAjax(consumeTenantService.updateConsumeTenant(consumeTenant));
    }

    /**
     * 删除商户信息
     */
    @RequiresPermissions("consume:consumeTenant:remove")
    @Log(title = "商户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(consumeTenantService.deleteConsumeTenantByIds(ids));
    }
}
