package com.dgtly.web.controller.system;

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.system.domain.SysMagnetLog;
import com.dgtly.system.service.ISysMagnetLogService;
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 2021-07-29
 */
@Controller
@RequestMapping("/system/magnetLog")
public class SysMagnetLogController extends BaseController
{
    private String prefix = "system/magnetLog";

    @Autowired
    private ISysMagnetLogService sysMagnetLogService;

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

    /**
     * 查询磁铁日志列表
     */
    @RequiresPermissions("system:magnetLog:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysMagnetLog sysMagnetLog)
    {
        startPage();
        List<SysMagnetLog> list = sysMagnetLogService.selectSysMagnetLogList(sysMagnetLog);
        return getDataTable(list);
    }

    /**
     * 导出磁铁日志列表
     */
    @RequiresPermissions("system:magnetLog:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysMagnetLog sysMagnetLog)
    {
        List<SysMagnetLog> list = sysMagnetLogService.selectSysMagnetLogList(sysMagnetLog);
        ExcelUtil<SysMagnetLog> util = new ExcelUtil<SysMagnetLog>(SysMagnetLog.class);
        return util.exportExcel(list, "magnetLog");
    }

    /**
     * 新增磁铁日志
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存磁铁日志
     */
    @Log(title = "磁铁日志", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysMagnetLog sysMagnetLog)
    {
        return toAjax(sysMagnetLogService.insertSysMagnetLog(sysMagnetLog));
    }

    /**
     * 修改磁铁日志
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysMagnetLog sysMagnetLog = sysMagnetLogService.selectSysMagnetLogById(id);
        mmap.put("sysMagnetLog", sysMagnetLog);
        return prefix + "/edit";
    }

    /**
     * 修改保存磁铁日志
     */
    @RequiresPermissions("system:magnetLog:edit")
    @Log(title = "磁铁日志", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysMagnetLog sysMagnetLog)
    {
        return toAjax(sysMagnetLogService.updateSysMagnetLog(sysMagnetLog));
    }

    /**
     * 删除磁铁日志
     */
    @RequiresPermissions("system:magnetLog:remove")
    @Log(title = "磁铁日志", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysMagnetLogService.deleteSysMagnetLogByIds(ids));
    }
}
