package com.cmvr.web.controller.inspection;

import com.cmvr.common.core.controller.BaseController;
import com.cmvr.common.core.domain.AjaxResult;
import com.cmvr.common.core.page.TableDataInfo;
import com.cmvr.inspection.domain.InspectionTaskLog;
import com.cmvr.inspection.service.IInspectionTaskLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 巡检任务执行日志Controller
 * 
 * @author cmvr-iot
 * @since 2026-06-05
 */
@Api(tags = "巡检任务执行日志管理")
@RestController
@RequestMapping("/inspection/taskLog")
public class InspectionTaskLogController extends BaseController
{
    @Autowired
    private IInspectionTaskLogService inspectionTaskLogService;

    /**
     * 查询巡检任务执行日志列表
     */
    @ApiOperation("查询巡检任务执行日志列表")
    @GetMapping("/list")
    public TableDataInfo list(@ApiParam("任务实例ID") @RequestParam String taskInstanceId) {
        startPage();
        List<InspectionTaskLog> list = inspectionTaskLogService.selectInspectionTaskLogList(taskInstanceId);
        return getDataTable(list);
    }

    /**
     * 获取巡检任务执行日志详细信息
     */
    @ApiOperation("获取巡检任务执行日志详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@ApiParam("日志ID") @PathVariable("id") String id) {
        return success(inspectionTaskLogService.getById(id));
    }

    /**
     * 新增巡检任务执行日志
     */
    @ApiOperation("新增巡检任务执行日志")
    @PostMapping
    public AjaxResult add(@RequestBody InspectionTaskLog inspectionTaskLog) {
        return toAjax(inspectionTaskLogService.insertInspectionTaskLog(inspectionTaskLog));
    }

    /**
     * 批量新增巡检任务执行日志
     */
    @ApiOperation("批量新增巡检任务执行日志")
    @PostMapping("/batch")
    public AjaxResult batchAdd(@RequestBody List<InspectionTaskLog> logList) {
        return toAjax(inspectionTaskLogService.batchInsertInspectionTaskLog(logList));
    }

    /**
     * 修改巡检任务执行日志
     */
    @ApiOperation("修改巡检任务执行日志")
    @PutMapping
    public AjaxResult edit(@RequestBody InspectionTaskLog inspectionTaskLog) {
        return toAjax(inspectionTaskLogService.updateById(inspectionTaskLog));
    }

    /**
     * 删除巡检任务执行日志
     */
    @ApiOperation("删除巡检任务执行日志")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@ApiParam("日志ID数组") @PathVariable String[] ids) {
        return toAjax(inspectionTaskLogService.removeByIds(java.util.Arrays.asList(ids)));
    }
}
