package com.cmvr.web.controller.aima;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.cmvr.common.annotation.Log;
import com.cmvr.common.core.controller.BaseController;
import com.cmvr.common.core.domain.AjaxResult;
import com.cmvr.common.enums.BusinessType;
import com.cmvr.aima.domain.AimaTestLog;
import com.cmvr.aima.service.IAimaTestLogService;
import com.cmvr.common.utils.poi.ExcelUtil;
import com.cmvr.common.core.page.TableDataInfo;

@RestController
@RequestMapping("/aima/testlog")
@Api(tags = "爱玛电动车--测试日志管理")
public class AimaTestLogController extends BaseController {
    @Autowired
    private IAimaTestLogService aimaTestLogService;

    @ApiOperation("查询测试日志列表")
    @PreAuthorize("@ss.hasPermi('aima:testlog:list')")
    @GetMapping("/list")
    public TableDataInfo list(AimaTestLog aimaTestLog) {
        startPage();
        List<AimaTestLog> list = aimaTestLogService.selectAimaTestLogList(aimaTestLog);
        return getDataTable(list);
    }

    @ApiOperation("导出测试日志列表")
    @PreAuthorize("@ss.hasPermi('aima:testlog:export')")
    @Log(title = "测试日志管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AimaTestLog aimaTestLog) {
        List<AimaTestLog> list = aimaTestLogService.selectAimaTestLogList(aimaTestLog);
        ExcelUtil<AimaTestLog> util = new ExcelUtil<>(AimaTestLog.class);
        util.exportExcel(response, list, "测试日志数据");
    }

    @ApiOperation("获取测试日志详细信息")
    @PreAuthorize("@ss.hasPermi('aima:testlog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(aimaTestLogService.selectAimaTestLogById(id));
    }

    @ApiOperation("新增测试日志")
    @PreAuthorize("@ss.hasPermi('aima:testlog:add')")
    @Log(title = "测试日志管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AimaTestLog aimaTestLog) {
        return toAjax(aimaTestLogService.insertAimaTestLog(aimaTestLog));
    }

    @ApiOperation("修改测试日志")
    @PreAuthorize("@ss.hasPermi('aima:testlog:edit')")
    @Log(title = "测试日志管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AimaTestLog aimaTestLog) {
        return toAjax(aimaTestLogService.updateAimaTestLog(aimaTestLog));
    }

    @ApiOperation("删除测试日志")
    @PreAuthorize("@ss.hasPermi('aima:testlog:remove')")
    @Log(title = "测试日志管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(aimaTestLogService.deleteAimaTestLogByIds(ids));
    }
}
