package com.sooka.system.controller;

import com.sooka.common.annotation.Log;
import com.sooka.common.core.controller.BaseController;
import com.sooka.common.core.domain.AjaxResult;
import com.sooka.common.core.page.TableDataInfo;
import com.sooka.common.enums.BusinessType;
import com.sooka.common.utils.poi.ExcelUtil;
import com.sooka.system.domain.TUInterfaceCrashLog;
import com.sooka.system.service.ITUInterfaceCrashLogService;
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
 */
@Controller
@RequestMapping("/system/crashLog")
public class TUInterfaceCrashLogController extends BaseController
{
    private String prefix = "system/crashLog";

    @Autowired
    private ITUInterfaceCrashLogService tUInterfaceCrashLogService;

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

    /**
     * 查询接口崩溃日志列表
     */
    @RequiresPermissions("system:crashLog:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TUInterfaceCrashLog tUInterfaceCrashLog)
    {
        startPage();
        List<TUInterfaceCrashLog> list = tUInterfaceCrashLogService.selectTUInterfaceCrashLogList(tUInterfaceCrashLog);
        return getDataTable(list);
    }

    /**
     * 导出接口崩溃日志列表
     */
    @RequiresPermissions("system:crashLog:export")
    @Log(title = "接口崩溃日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TUInterfaceCrashLog tUInterfaceCrashLog)
    {
        List<TUInterfaceCrashLog> list = tUInterfaceCrashLogService.selectTUInterfaceCrashLogList(tUInterfaceCrashLog);
        ExcelUtil<TUInterfaceCrashLog> util = new ExcelUtil<TUInterfaceCrashLog>(TUInterfaceCrashLog.class);
        return util.exportExcel(list, "crashLog");
    }

    /**
     * 新增接口崩溃日志
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存接口崩溃日志
     */
    @RequiresPermissions("system:crashLog:add")
    @Log(title = "接口崩溃日志", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TUInterfaceCrashLog tUInterfaceCrashLog)
    {
        return toAjax(tUInterfaceCrashLogService.insertTUInterfaceCrashLog(tUInterfaceCrashLog));
    }

    /**
     * 修改接口崩溃日志
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        TUInterfaceCrashLog tUInterfaceCrashLog = tUInterfaceCrashLogService.selectTUInterfaceCrashLogById(id);
        mmap.put("crashLog", tUInterfaceCrashLog);
        return prefix + "/edit";
    }

    /**
     * 查看接口崩溃日志详情
     */
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") String id, ModelMap mmap) {
        TUInterfaceCrashLog tUInterfaceCrashLog = tUInterfaceCrashLogService.selectTUInterfaceCrashLogById(id);
        mmap.put("crashLog", tUInterfaceCrashLog);
        return prefix + "/detail";
    }

    /**
     * 修改保存接口崩溃日志
     */
    @RequiresPermissions("system:crashLog:edit")
    @Log(title = "接口崩溃日志", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TUInterfaceCrashLog tUInterfaceCrashLog)
    {
        return toAjax(tUInterfaceCrashLogService.updateTUInterfaceCrashLog(tUInterfaceCrashLog));
    }

    /**
     * 删除接口崩溃日志
     */
    @RequiresPermissions("system:crashLog:remove")
    @Log(title = "接口崩溃日志", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tUInterfaceCrashLogService.deleteTUInterfaceCrashLogByIds(ids));
    }
}
