package com.muyu.enterprise.controller;


import com.muyu.common.core.domain.Result;
import com.muyu.enterprise.domain.FaultLog;
import com.muyu.enterprise.service.FaultLogService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 故障日志控制层
 * @author chenruijia
 * @Date 2024/9/28 11:58
 * @Description FaultLogController:故障日志控制层
 */
@RestController
@RequestMapping("/log")
@Tag(name = "故障日志",description = "对故障记录日志")
public class FaultLogController{
    @Autowired
    private FaultLogService faultLogService;

    /**
     * 查询车辆故障日志列表
     */
    @RequestMapping(value = "/faultLogList", method = RequestMethod.GET)
    public Result<List<FaultLog>> faultLogList(FaultLog faultLog){
        List<FaultLog> list = faultLogService.faultLogList(faultLog);
        return Result.success(list);
    }

    /**
     * 添加车辆故障日志
     * @param faultLog
     * @return
     */
    @RequestMapping(value = "/insertLog",method = RequestMethod.POST)
    public Result insertLog(@RequestBody FaultLog faultLog){
        return Result.success(faultLogService.save(faultLog));
    }

    /**
     * 修改车辆故障日志
     * @param faultLog
     * @return
     */
    @RequestMapping(value = "/updateLog",method = RequestMethod.PUT)
    public Result updateLog(@RequestBody FaultLog faultLog){
        return Result.success(faultLogService.updateById(faultLog));
    }

    /**
     *
     * 批量删除车辆故障日志
     * @param ids
     * @return
     */
    @RequestMapping(value = "/remove/{ids}",method = RequestMethod.DELETE)
    public Result remove(@PathVariable("ids") Long[] ids)
    {
        return Result.success(faultLogService.removeBatchByIds(Arrays.asList(ids)));
    }

    /**
     * 获取单条日志详细信息
     * @param faultLogId
     * @return
     */
    @RequestMapping(value = "/byidId/{faultLogId}",method = RequestMethod.GET)
    public Result byidId(@PathVariable Long faultLogId){
        FaultLog byid = faultLogService.byidId(faultLogId);
        return Result.success(byid);
    }


}
