package com.muyu.enterprise.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.enterprise.domain.CarMessage;
import com.muyu.enterprise.service.CarMessageService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 车辆报文--控制层
 * @ClassName carMessageController
 * @Description 车辆类型 Controller 层
 * @author  MingWei.Zong
 * @Date 2024/9/28 16:52
 */
@RestController
@RequestMapping("/carMessage")
@Tag(name = "报文",description = "报文模块")
public class CarMessageController extends BaseController {
    @Autowired
    private CarMessageService sysCarMessageService;

    /**
     * 查询所有报文信息
     * @return
     */
    @PostMapping("selectMessageShow")
    public List<CarMessage> selectMessageShow(@RequestParam("templateId") Long templateId){
        return sysCarMessageService.selectMessageShow(templateId);
    }

    /**
     * 根据报文模板id查询报文
     * @param templateId
     * @return
     */
    @GetMapping("/selectByTemplateId")
    private Result<List<CarMessage>> selectByTemplateId(@RequestParam("templateId") Integer templateId) {
        return Result.success(sysCarMessageService.list
                (new LambdaQueryWrapper<CarMessage>().eq(CarMessage::getTemplateId, templateId)));
    }

    /**
     * 通过id查询报文信息
     * @return
     */
    @PostMapping("selectMessageByMessageId")
    public CarMessage selectMessageByMessageId(@RequestParam("messageId") Long messageId){
        return sysCarMessageService.selectMessageByMessageId(messageId);
    }

   /**
     * 添加报文信息
     * @return carMessage
     */
    @PostMapping("insertMessage")
    public Result insertMessage(@RequestBody CarMessage carMessage){
        sysCarMessageService.save(carMessage);
        return Result.success("添加成功");
    }
    /**
     * 修改报文信息
     * @return carMessage
     */
    @PostMapping("updataMessage")
    public Result updataMessage(@RequestBody CarMessage carMessage){
        sysCarMessageService.updateById(carMessage);
        return Result.success("修改成功");
    }
    /**
     * 删除报文信息
     * @return carMessage
     */
    @PostMapping("deleteMessage")
    public Result deleteMessage(@RequestParam("ids") List<Long> ids){
        sysCarMessageService.removeBatchByIds(ids);
        return Result.success("删除成功");
    }


}
