package com.qmth.sop.server.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.boot.api.annotation.Aac;
import com.qmth.sop.business.bean.result.EditResult;
import com.qmth.sop.business.entity.SysDeviceModel;
import com.qmth.sop.business.service.SysDeviceModelService;
import com.qmth.sop.common.annotation.OperationLog;
import com.qmth.sop.common.contant.SystemConstant;
import com.qmth.sop.common.enums.LogTypeEnum;
import com.qmth.sop.common.util.Result;
import com.qmth.sop.common.util.ResultUtil;
import io.swagger.annotations.*;
import org.springframework.util.CollectionUtils; 
import org.springframework.validation.BindingResult; 
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.util.List;
import java.util.Objects;

/**
 * 设备品牌型号表 控制器
 * 
 * @author: shudonghui
 * @date: 2023-08-25 10:29:08
 * @version: 1.0
 * @email: shudonghui@qmth.com.cn
 * @Company: www.qmth.com.cn
 */
@Api(tags = "设备品牌型号表 Controller")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX+"/sys/device/model")
public class SysDeviceModelController {


    @Resource
    SysDeviceModelService sysDeviceModelService;

    
    @ApiOperation(value = "设备品牌型号表查询接口")
    @RequestMapping(value = "/query", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "设备品牌型号表查询结果", response = SysDeviceModel.class)})
    public Result query(
                @ApiParam(value = "模糊查询条件", required = false) @RequestParam(required = false) String query,
                @ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
                @ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
        IPage<SysDeviceModel> resultIPage = sysDeviceModelService.query(new Page<>(pageNumber, pageSize),query);

        return ResultUtil.ok(resultIPage);
    }

    
    @ApiOperation(value = "设备品牌型号表新增修改接口")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = Object.class)})
    @OperationLog(logType = LogTypeEnum.EDIT)
    public Result save(@Valid @ApiParam(value = "设备品牌型号表信息", required = true) @RequestBody(required = true) SysDeviceModel sysDeviceModel, BindingResult bindingResult) throws InterruptedException {
        if (bindingResult.hasErrors()) {
            return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
        }
        return ResultUtil.ok(sysDeviceModelService.saveSysDeviceModel(sysDeviceModel));
    }


    
    @ApiOperation(value = "设备品牌型号表删除接口")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = Object.class)})
    @OperationLog(logType = LogTypeEnum.DELETE)
    public Result delete(@ApiParam(value = "设备品牌型号表id", required = true) @RequestParam(required = true) long id) {
        return ResultUtil.ok(sysDeviceModelService.delete(id));
    }


    
    @ApiOperation(value = "设备品牌型号表获取单个接口")
    @RequestMapping(value = "/get", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "设备品牌型号表信息", response = SysDeviceModel.class)})
    public Result get(@ApiParam(value = "设备品牌型号表id", required = true) @RequestParam long id) {
        return ResultUtil.ok(sysDeviceModelService.getById(id));
    }


}