package com.muyu.enterprise.controller;


import com.muyu.common.core.domain.Result;
import com.muyu.enterprise.domain.FaultrRule;
import com.muyu.enterprise.service.FaultrRuleService;
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 FaultrRuleController:故障的规则控制层
 */
@RestController
@RequestMapping("/rule")
@Tag(name = "故障的规则",description = "对故障数据规则的判断")
public class FaultrRuleController {
    @Autowired
    private FaultrRuleService faultrRuleService;
    /**
     * 查询车辆故障列表
     */
    @RequestMapping(value = "/faultRuleList", method = RequestMethod.GET)
    public Result<List<FaultrRule>> faultRuleList(FaultrRule faultrRule)
    {
        List<FaultrRule> list = faultrRuleService.faultRuleList(faultrRule);
        return Result.success(list);
    }

    /**
     * 添加车辆规则
     * @param faultrRule
     * @return
     */
    @RequestMapping(value = "/insertRule",method = RequestMethod.POST)
    public Result insertRule(@RequestBody FaultrRule faultrRule){
        return Result.success(faultrRuleService.save(faultrRule));
    }

    /**
     * 修改车辆规则
     * @param faultrRule
     * @return
     */
    @RequestMapping(value = "/updateRule",method = RequestMethod.POST)
    public Result updateRule(@RequestBody FaultrRule faultrRule){
        return Result.success(faultrRuleService.updateById(faultrRule));
    }

    /**
     * 获取单条故障规则详细信息
     * @param faultRuleId
     * @return
     */
    @RequestMapping(value = "/byidRuleId/{faultRuleId}",method = RequestMethod.GET)
    public Result byidRuleId(@PathVariable Long faultRuleId){
        FaultrRule byid = faultrRuleService.byidRuleId(faultRuleId);
        return Result.success(byid);
    }

    /**
     * 删除车辆故障
     */
    @RequestMapping(value = "/remove/{ids}",method = RequestMethod.DELETE)
    public Result<Integer> remove(@PathVariable("ids") Long[] ids)
    {
        faultrRuleService.removeBatchByIds(Arrays.asList(ids));
        return Result.success();
    }


}
