package com.dgtly.wxportal.controller;

import java.util.List;

import com.dgtly.wxportal.service.IHelpCenterService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
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.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.dgtly.common.annotation.Log;
import com.dgtly.common.enums.BusinessType;
import com.dgtly.wxportal.domain.HelpCenter;
import com.dgtly.common.core.controller.BaseController;
import com.dgtly.common.core.domain.AjaxResult;
import com.dgtly.common.utils.poi.ExcelUtil;
import com.dgtly.common.core.page.TableDataInfo;

/**
 * 帮助中心Controller
 * 
 * @author dgtly
 * @date 2020-12-09
 */
@Controller
@RequestMapping("/helpCenter/center")
public class HelpCenterController extends BaseController
{
    private String prefix = "wxportal/helpCenter";

    @Autowired
    private IHelpCenterService helpCenterService;

    @RequiresPermissions("helpCenter:center:view")
    @GetMapping()
    public String center()
    {
        return prefix + "/center";
    }

    /**
     * 查询帮助中心列表
     */
    @RequiresPermissions("helpCenter:center:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HelpCenter helpCenter)
    {
        startPage();
        List<HelpCenter> list = helpCenterService.selectHelpCenterList(helpCenter);
        return getDataTable(list);
    }

    /**
     * 导出帮助中心列表
     */
    @RequiresPermissions("helpCenter:center:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HelpCenter helpCenter)
    {
        List<HelpCenter> list = helpCenterService.selectHelpCenterList(helpCenter);
        ExcelUtil<HelpCenter> util = new ExcelUtil<HelpCenter>(HelpCenter.class);
        return util.exportExcel(list, "center");
    }

    /**
     * 新增帮助中心
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存帮助中心
     */
    @RequiresPermissions("helpCenter:center:add")
    @Log(title = "帮助中心", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HelpCenter helpCenter)
    {
        return toAjax(helpCenterService.insertHelpCenter(helpCenter));
    }

    /**
     * 修改帮助中心
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        HelpCenter helpCenter = helpCenterService.selectHelpCenterById(id);
        mmap.put("helpCenter", helpCenter);
        return prefix + "/edit";
    }

    /**
     * 修改保存帮助中心
     */
    @RequiresPermissions("helpCenter:center:edit")
    @Log(title = "帮助中心", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HelpCenter helpCenter)
    {
        return toAjax(helpCenterService.updateHelpCenter(helpCenter));
    }

    /**
     * 删除帮助中心
     */
    @RequiresPermissions("helpCenter:center:remove")
    @Log(title = "帮助中心", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(helpCenterService.deleteHelpCenterByIds(ids));
    }
}
