package com.ruoyi.web.controller.buyerapi;

import java.util.List;
import cn.hutool.core.util.IdUtil;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.buyerapi.domain.BuyerHelp;
import com.ruoyi.buyerapi.service.IBuyerHelpService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.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.common.core.page.TableDataInfo;

/**
 * 帮助中心Controller
 * 
 * @author ruoyi
 * @date 2022-10-12
 */
@Api(tags = "帮助中心")
@RestController
@RequestMapping("/buyer/help")
public class BuyerHelpController extends BaseController
{
    @Autowired
    private IBuyerHelpService buyerHelpService;

    /**
     * 查询帮助中心列表
     */
    @ApiOperation(value = "查询帮助中心列表")
    @GetMapping("/list")
    public TableDataInfo list(BuyerHelp buyerHelp)
    {
        startPage();
        List<BuyerHelp> list = buyerHelpService.selectBuyerHelpList(buyerHelp);
        return getDataTable(list);
    }

    /**
     * 导出帮助中心列表
     */
    @ApiOperation(value = "导出帮助中心列表")
    @Log(title = "帮助中心", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuyerHelp buyerHelp)
    {
        List<BuyerHelp> list = buyerHelpService.selectBuyerHelpList(buyerHelp);
        ExcelUtil<BuyerHelp> util = new ExcelUtil<BuyerHelp>(BuyerHelp.class);
        util.exportExcel(response, list, "帮助中心数据");
    }

    /**
     * 获取帮助中心详细信息
     */
    @ApiOperation(value = "获取帮助中心详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(buyerHelpService.selectBuyerHelpById(id));
    }

    /**
     * 新增帮助中心
     */
    @ApiOperation(value = "新增帮助中心")
    @Log(title = "帮助中心", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuyerHelp buyerHelp)
    {
        buyerHelp.setId(IdUtil.simpleUUID());
        buyerHelp.setCreateBy(getUsername());
        return toAjax(buyerHelpService.insertBuyerHelp(buyerHelp));
    }

    /**
     * 修改帮助中心
     */
    @ApiOperation(value = "修改帮助中心")
    @Log(title = "帮助中心", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuyerHelp buyerHelp)
    {
        buyerHelp.setUpdateBy(getUsername());
        return toAjax(buyerHelpService.updateBuyerHelp(buyerHelp));
    }

    /**
     * 删除帮助中心
     */
    @ApiOperation(value = "删除帮助中心")
    @Log(title = "帮助中心", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(buyerHelpService.deleteBuyerHelpByIds(ids));
    }
}
