package com.dgtly.wxportal.controller;

import java.util.List;
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.WxBanner;
import com.dgtly.wxportal.service.IWxBannerService;
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;

/**
 * 企业微信门户首页banner图Controller
 * 
 * @author qxp
 * @date 2020-06-23
 */
@Controller
@RequestMapping("/wxportal/banner")
public class WxBannerController extends BaseController
{
    private String prefix = "wxportal/banner";

    @Autowired
    private IWxBannerService wxBannerService;

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

    /**
     * 查询企业微信门户首页banner图列表
     */
    @RequiresPermissions("wxportal:banner:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WxBanner wxBanner)
    {
        startPage();
        List<WxBanner> list = wxBannerService.selectWxBannerList(wxBanner);
        return getDataTable(list);
    }

    /**
     * 导出企业微信门户首页banner图列表
     */
    @RequiresPermissions("wxportal:banner:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WxBanner wxBanner)
    {
        List<WxBanner> list = wxBannerService.selectWxBannerList(wxBanner);
        ExcelUtil<WxBanner> util = new ExcelUtil<WxBanner>(WxBanner.class);
        return util.exportExcel(list, "banner");
    }

    /**
     * 新增企业微信门户首页banner图
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存企业微信门户首页banner图
     */
    @RequiresPermissions("wxportal:banner:add")
    @Log(title = "企业微信门户首页banner图", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WxBanner wxBanner)
    {
        return toAjax(wxBannerService.insertWxBanner(wxBanner));
    }

    /**
     * 修改企业微信门户首页banner图
     */
    @GetMapping("/edit/{bannerId}")
    public String edit(@PathVariable("bannerId") Long bannerId, ModelMap mmap)
    {
        WxBanner wxBanner = wxBannerService.selectWxBannerById(bannerId);
        mmap.put("wxBanner", wxBanner);
        return prefix + "/edit";
    }

    /**
     * 修改保存企业微信门户首页banner图
     */
    @RequiresPermissions("wxportal:banner:edit")
    @Log(title = "企业微信门户首页banner图", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WxBanner wxBanner)
    {
        return toAjax(wxBannerService.updateWxBanner(wxBanner));
    }

    /**
     * 删除企业微信门户首页banner图
     */
    @RequiresPermissions("wxportal:banner:remove")
    @Log(title = "企业微信门户首页banner图", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wxBannerService.deleteWxBannerByIds(ids));
    }


    /**
     * 上传图片
     */
    @GetMapping("/imgUpload")
    public String imgUpload(String imgUrl,ModelMap mmap)
    {
        mmap.addAttribute("imgUrl",imgUrl);
        return prefix + "/uploadImg";
    }
}
