/*
*  Copyright 2019-2025 Tz
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.system.rest;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.system.domain.BusDeviceCommand;
import me.zhengjie.modules.system.domain.dto.BusCommandQueryCriteria;
import me.zhengjie.modules.system.service.BusCommandService;
import me.zhengjie.utils.PageResult;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* @author tz
* @date 2025-05-21
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "系统：设备指令")
@RequestMapping("/api/busDeviceCommand")
public class BusCommandController {

    private final BusCommandService busDeviceCommandService;

    @GetMapping
    @ApiOperation("查询busCommand")
    @PreAuthorize("@el.check('busDeviceCommand:list')")
    public ResponseEntity<PageResult<BusDeviceCommand>> queryBusDeviceCommand(BusCommandQueryCriteria criteria){
        Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
        return new ResponseEntity<>(busDeviceCommandService.queryAll(criteria,page),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增busCommand")
    @ApiOperation("新增busCommand")
    @PreAuthorize("@el.check('busDeviceCommand:add')")
    public ResponseEntity<Object> createBusDeviceCommand(@Validated @RequestBody BusDeviceCommand resources){
        busDeviceCommandService.create(resources);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改busCommand")
    @ApiOperation("修改busCommand")
    @PreAuthorize("@el.check('busDeviceCommand:edit')")
    public ResponseEntity<Object> updateBusDeviceCommand(@Validated @RequestBody BusDeviceCommand resources){
        busDeviceCommandService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除busCommand")
    @ApiOperation("删除busCommand")
    @PreAuthorize("@el.check('busDeviceCommand:del')")
    public ResponseEntity<Object> deleteBusDeviceCommand(@ApiParam(value = "传ID数组[]") @RequestBody List<Long> ids) {
        busDeviceCommandService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}