package com.zhyc.module.app.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zhyc.module.app.domain.AppErrorLog;
import com.zhyc.module.app.service.IAppErrorLogService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhyc.common.annotation.Log;
import com.zhyc.common.core.controller.BaseController;
import com.zhyc.common.core.domain.AjaxResult;
import com.zhyc.common.enums.BusinessType;

import com.zhyc.common.utils.poi.ExcelUtil;
import com.zhyc.common.core.page.TableDataInfo;

/**
 * App错误日志Controller
 * 
 * @author ruoyi
 * @date 2026-01-19
 */
@RestController
@RequestMapping("/app/error")
public class AppErrorLogController extends BaseController
{
    @Autowired
    private IAppErrorLogService appErrorLogService;

    /**
     * 查询App错误日志列表
     */
//    @PreAuthorize("@ss.hasPermi('app:app:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppErrorLog appErrorLog)
    {
        startPage();
        List<AppErrorLog> list = appErrorLogService.selectAppErrorLogList(appErrorLog);
        return getDataTable(list);
    }

    /**
     * 导出App错误日志列表
     */
//    @PreAuthorize("@ss.hasPermi('app:app:export')")
    @Log(title = "App错误日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppErrorLog appErrorLog)
    {
        List<AppErrorLog> list = appErrorLogService.selectAppErrorLogList(appErrorLog);
        ExcelUtil<AppErrorLog> util = new ExcelUtil<AppErrorLog>(AppErrorLog.class);
        util.exportExcel(response, list, "App错误日志数据");
    }

    /**
     * 获取App错误日志详细信息
     */
//    @PreAuthorize("@ss.hasPermi('app:app:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(appErrorLogService.selectAppErrorLogById(id));
    }

    /**
     * 新增App错误日志
     */
//    @PreAuthorize("@ss.hasPermi('app:app:add')")
    @Log(title = "App错误日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppErrorLog appErrorLog)
    {
        return toAjax(appErrorLogService.insertAppErrorLog(appErrorLog));
    }

    /**
     * 修改App错误日志
     */
//    @PreAuthorize("@ss.hasPermi('app:app:edit')")
    @Log(title = "App错误日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppErrorLog appErrorLog)
    {
        return toAjax(appErrorLogService.updateAppErrorLog(appErrorLog));
    }

    /**
     * 删除App错误日志
     */
//    @PreAuthorize("@ss.hasPermi('app:app:remove')")
    @Log(title = "App错误日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(appErrorLogService.deleteAppErrorLogByIds(ids));
    }
}
