package com.muyu.breakdown.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.muyu.breakdown.domain.SysCarFaultMessage;
import com.muyu.breakdown.service.SysCarFaultMessageService;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.web.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @ClassDescription:
 * @JdkVersion: 1.8
 * @Author: YZL
 * @Created: 2024/9/22 14:39
 */
@RestController
@RequestMapping("/message")
public class SysCarFaultMessageController extends BaseController {
    @Autowired
    private SysCarFaultMessageService service;

    /**
     * 查询所有故障信息
     * @return
     */
    @GetMapping("/list")
    public Result<TableDataInfo<SysCarFaultMessage>> list(){
        startPage();
        List<SysCarFaultMessage> list = service.list();
        return getDataTable(list);
    }

    /**
     * 查询状态为1的故障信息
     * @return
     */

    @GetMapping("/listStatusOne")
    public Result<TableDataInfo<SysCarFaultMessage>>listStatusOne(){
        startPage();
        List<SysCarFaultMessage> list = service.listStatusOnt();
        return getDataTable(list);
    }

    /**
     * 查询状态为2的故障信息
     * @return
     */
    @GetMapping("/listStatusTwo")
    public Result<TableDataInfo<SysCarFaultMessage>>listStatusTwo(){
        startPage();
        List<SysCarFaultMessage> list = service.listStatusTwo();
        return getDataTable(list);
    }
    /**
     * 修改未读站内信息为已读
     * @param id
     * @return
     */
    @PutMapping("/updateStatusById/{id}")
    public Result updateStatusById(@PathVariable("id")Long id){
        UpdateWrapper<SysCarFaultMessage> wrapper = new UpdateWrapper<>();
        wrapper.eq("id",id);
        wrapper.set("status",1);
        boolean update = service.update(wrapper);
        return Result.success(update);
    }
}
