package com.muyu.server.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.domain.SysCarFaultMessage;
import com.muyu.server.service.SysCarFaultMessageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 站内信 接口控制层
 * @author 袁子龙
 * @package: com.muyu.breakdown.controller
 * @name: SysCarFaultMessageController
 * @date: 2024/9/22 14:39
 */
@RestController
@RequestMapping("/message")
@Log4j2
@Tag(name = "站内信",description = "站内信管理")
public class SysCarFaultMessageController extends BaseController {
    @Autowired
    private SysCarFaultMessageService service;

    /**
     * 查询所有站内信信息
     * @return
     */
    @GetMapping("/list")
    @Operation(summary = "查询所有站内信信息",description = "查询所有站内信信息")
    public Result<TableDataInfo<SysCarFaultMessage>> list(){
        startPage();
        List<SysCarFaultMessage> list = service.list();
        return getDataTable(list);
    }

    /**
     * 查询状态为已读的信息
     * @return
     */

    @GetMapping("/listStatusOne")
    @Operation(summary ="查询状态为以解决的故障信息",description = "查询状态为已解决的故障信息")
    public Result<TableDataInfo<SysCarFaultMessage>>listStatusOne(){
        startPage();
        List<SysCarFaultMessage> list = service.listStatusOnt();
        return getDataTable(list);
    }

    /**
     * 查询状态为未读的信息
     * @return
     */
    @GetMapping("/listStatusTwo")
    @Operation(summary = "查询状态为未读的信息",description = "查询状态为未读的信息")
    public Result<TableDataInfo<SysCarFaultMessage>>listStatusTwo(){
        startPage();
        List<SysCarFaultMessage> list = service.listStatusTwo();
        return getDataTable(list);
    }
    /**
     * 修改未读站内信息为已读
     * @param id
     * @return
     */
    @PutMapping("/updateStatusById/{id}")
    @Operation(summary = "修改未读站内信息为已读",description = "修改未读站内信息为已读")
    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);
    }
}
