package com.dgtly.web.controller.system;

import com.dgtly.common.annotation.Log;
import com.dgtly.common.core.controller.BaseController;
import com.dgtly.common.core.domain.AjaxResult;
import com.dgtly.common.core.page.TableDataInfo;
import com.dgtly.common.enums.BusinessType;
import com.dgtly.common.utils.poi.ExcelUtil;
import com.dgtly.system.domain.SysRidingLantern;
import com.dgtly.system.service.ISysRidingLanternService;
import com.dgtly.wxportal.domain.WxMagnet;
import com.dgtly.wxportal.service.IWxMagnetService;
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.*;

import java.util.List;

/**
 * 走马灯提示语Controller
 * 
 * @author dgtly
 * @date 2022-11-22
 */
@Controller
@RequestMapping("/system/lantern")
public class SysRidingLanternController extends BaseController
{
    private String prefix = "system/lantern";

    @Autowired
    private ISysRidingLanternService sysRidingLanternService;

    @Autowired
    private IWxMagnetService wxMagnetService;

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

    /**
     * 查询走马灯提示语列表
     */
    @RequiresPermissions("system:lantern:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysRidingLantern sysRidingLantern)
    {
        startPage();
        List<SysRidingLantern> list = sysRidingLanternService.selectSysRidingLanternList(sysRidingLantern);
        return getDataTable(list);
    }

    @RequiresPermissions("system:lantern:tileList")
    @PostMapping("/tileList")
    @ResponseBody
    public List<WxMagnet> tileList(WxMagnet wxMagnet)
    {
        List<WxMagnet> menuList = wxMagnetService.selectTileMagnetList(wxMagnet);
        return menuList;
    }



    /**
     * 导出走马灯提示语列表
     */
    @RequiresPermissions("system:lantern:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysRidingLantern sysRidingLantern)
    {
        List<SysRidingLantern> list = sysRidingLanternService.selectSysRidingLanternList(sysRidingLantern);
        ExcelUtil<SysRidingLantern> util = new ExcelUtil<SysRidingLantern>(SysRidingLantern.class);
        return util.exportExcel(list, "lantern");
    }

    /**
     * 新增走马灯提示语
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存走马灯提示语
     */
    @RequiresPermissions("system:lantern:add")
    @Log(title = "走马灯提示语", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysRidingLantern sysRidingLantern)
    {
        return toAjax(sysRidingLanternService.insertSysRidingLantern(sysRidingLantern));
    }

    /**
     * 修改走马灯提示语
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysRidingLantern sysRidingLantern = sysRidingLanternService.selectSysRidingLanternById(id);
        mmap.put("sysRidingLantern", sysRidingLantern);
        return prefix + "/edit";
    }

    /**
     * 修改保存走马灯提示语
     */
    @RequiresPermissions("system:lantern:edit")
    @Log(title = "走马灯提示语", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysRidingLantern sysRidingLantern)
    {
        sysRidingLantern.getUserType();
        return toAjax(sysRidingLanternService.updateSysRidingLantern(sysRidingLantern));
    }

    /**
     * 删除走马灯提示语
     */
    @RequiresPermissions("system:lantern:remove")
    @Log(title = "走马灯提示语", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysRidingLanternService.deleteSysRidingLanternByIds(ids));
    }
}
