package com.muyu.enterprise.controller;

import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.annotation.RequiresPermissions;

import com.muyu.domain.*;
import com.muyu.domain.vo.RuleVo;
import com.muyu.enterprise.service.RuleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * @Author：ChenYan
 * @Project：2112-car-cloud-server
 * @Package：com.muyu.fault.controller
 * @Filename：RuleController
 * @Description TODO
 * @Date：2024/9/21 18:42
 */
@Log4j2
@RestController
@Tag(name = "规则", description = "故障管理列")
@RequestMapping("/rules")
public class RuleController extends BaseController {

    @Autowired
    private RuleService ruleService;


    /**
     * 查询车辆故障管理列表
     */
    @GetMapping("/list")
    @RequiresPermissions("fault:rules:list")
    @Operation(summary = "查询集合", description = "查询车辆故障管理列表")
    public Result<TableDataInfo<RuleVo>> list(RuleVo fault) {
        startPage();
        List<RuleVo> list = ruleService.pageQueryRule(fault);
        return getDataTable(list);
    }

    /**
     * 导出车辆故障管理列表
     */
    @Log(title = "车辆故障管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @RequiresPermissions("fault:rules:export")
    public void export(HttpServletResponse response, Rule fault) {
        List<Rule> list = ruleService.pageQuery(fault);
        ExcelUtil<Rule> util = new ExcelUtil<Rule>(Rule.class);
        util.exportExcel(response, list, "车辆故障管理数据");
    }


    /**
     * 获取车辆故障管理详细信息
     */
    @GetMapping(value = "/{id}")
    public Result<String> getConfigKey(@PathVariable("id") String id) {
        return success(ruleService.getById(id));
    }


    /**
     * 新增车辆故障管理
     */
    @Log(title = "车辆故障管理", businessType = BusinessType.INSERT)
    @PostMapping
    @RequiresPermissions("fault:rules:add")
    public Result add(@RequestBody Rule fault) {
        return Result.success(ruleService.insertFault(fault), "成功");
    }


    /**
     * 修改车故障管理
     */
    @Log(title = "车辆故障管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @RequiresPermissions("fault:rules:edit")
    public Result edit(@RequestBody Rule fault) {
        return Result.success(ruleService.updateFault(fault), "成功");
    }


    /**
     * 删除车辆故障管理
     */
    @Log(title = "车辆故障管理删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    @RequiresPermissions("fault:rules:remove")
    public Result remove(@PathVariable("id") Long[] id) {
        return Result.success(ruleService.removeBatchByIds(Arrays.asList(id)), "成功");
    }


    /**
     * 查询车辆故障管理列表
     */
    @GetMapping("/custom")
    @Operation(summary = "查询集合", description = "查询车辆故障管理列表")
    public Result<List<Custom>> custom(Custom fault) {
        return ruleService.pageQueryList(fault);
    }


    /**
     * 查询车辆故障管理列表
     */
    @GetMapping("/car")
    @Operation(summary = "查询集合", description = "查询车辆故障管理列表")
    public Result<List<Vehicle>> car(Vehicle fault) {
        return ruleService.pageQueryCar(fault);
    }


    /**
     * 查询车辆故障管理列表
     */
    @GetMapping("/type")
    @Operation(summary = "查询集合", description = "查询车辆故障管理列表")
    public Result<List<Type>> type(Type fault) {
        return ruleService.pageQueryType(fault);
    }

    /**
     * 查询车辆故障管理列表
     */
    @GetMapping("/MessageValue")
    @Operation(summary = "查询集合", description = "查询车辆故障管理列表")
    public Result<List<MessageValue>> MessageValue(MessageValue fault) {
        return ruleService.pageQueryMessageValue(fault);
    }

}
