package com.ruoyi.web.controller.system;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.domain.dto.lotPlatFormDevice.LotPlatformDeviceAddRequest;
import com.ruoyi.web.domain.dto.lotPlatFormDevice.LotPlatformDeviceEditRequest;
import com.ruoyi.web.domain.dto.lotPlatFormDevice.LotPlatformDeviceQueryRequest;
import com.ruoyi.web.domain.entity.LotPlatformDevice;
import com.ruoyi.web.domain.vo.LotPlatformDeviceVO;
import com.ruoyi.web.service.LotPlatformDeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

import static com.ruoyi.common.core.domain.AjaxResult.error;
import static com.ruoyi.common.core.domain.AjaxResult.success;

@Api(tags = "物联网平台设备")
@RestController
@RequestMapping("/system/lot/platform/device")
public class LotPlatformDeviceController {

    @Autowired
    private LotPlatformDeviceService lotPlatformDeviceService;

    /**
     * 添加物联网平台设备
     *
     * @param lotPlatformDeviceAddRequest
     * @return
     */
    @ApiOperation("添加物联网平台设备")
    @PostMapping("/add")
    public AjaxResult addLotPlatformDevice(@RequestBody LotPlatformDeviceAddRequest lotPlatformDeviceAddRequest) {
        if (lotPlatformDeviceAddRequest == null) {
            return error("请求参数为空");
        }
        Integer id = lotPlatformDeviceService.addLotPlatformDevice(lotPlatformDeviceAddRequest);
        return success(id);
    }

    /**
     * 删除物联网平台设备
     *
     * @param paramsMap
     * @return
     */
    @ApiOperation("删除物联网平台设备")
    @PostMapping("/delete")
    public AjaxResult deleteLotPlatformDevice(@RequestBody Map<String, String> paramsMap) {
        String ids = paramsMap.get("ids");
        if (StrUtil.isBlank(ids)) {
            return error("请求参数为空");
        }
        boolean b = lotPlatformDeviceService.deleteLotPlatformDevice(ids);
        if (b) {
            return success("删除成功");
        }
        return error("删除失败");
    }


    /**
     * 编辑物联网平台设备
     *
     * @param lotPlatformDeviceEditRequest
     * @return
     */
    @ApiOperation("编辑物联网平台设备")
    @PostMapping("/edit")
    public AjaxResult editLotPlatformDevice(@RequestBody LotPlatformDeviceEditRequest lotPlatformDeviceEditRequest) {
        if (lotPlatformDeviceEditRequest == null) {
            return error("请求参数为空");
        }
        lotPlatformDeviceService.editLotPlatformDevice(lotPlatformDeviceEditRequest);
        return AjaxResult.success();
    }


    /**
     * 根据id获取物联网平台设备
     *
     * @param id
     * @return
     */
    @ApiOperation("根据id获取物联网平台设备")
    @GetMapping("/get")
    public AjaxResult getLotPlatformDeviceById(@RequestParam int id) {
        if (ObjectUtil.isEmpty(id)) {
            return error("请求参数为空");
        }
        LotPlatformDeviceVO lotPlatformDeviceVO = lotPlatformDeviceService.getLotPlatformDeviceById(id);
        return success(lotPlatformDeviceVO);
    }

    /**
     * 分页获取物联网平台设备列表
     *
     * @param lotPlatformDeviceQueryRequest
     * @return
     */
    @ApiOperation("分页获取物联网平台设备列表")
    @PostMapping("/list/page")
    public AjaxResult listLotPlatformDeviceByPage(@RequestBody LotPlatformDeviceQueryRequest lotPlatformDeviceQueryRequest) {
        if (lotPlatformDeviceQueryRequest == null) {
            return error("请求参数为空");
        }
        Page<LotPlatformDeviceVO> listLotPlatformDeviceVOByPage = lotPlatformDeviceService.getListLotPlatformDeviceByPage(lotPlatformDeviceQueryRequest);
        return success(listLotPlatformDeviceVOByPage);
    }
    @ApiOperation("获取全部物联网平台设备列表")
    @PostMapping("/list/ ")
    public AjaxResult listLotPlatformDevice(@RequestBody LotPlatformDeviceQueryRequest lotPlatformDeviceQueryRequest) {
        if (lotPlatformDeviceQueryRequest == null) {
            return error("请求参数为空");
        }
        List<LotPlatformDevice> listLotPlatformDeviceVO = lotPlatformDeviceService.listLotPlatformDevice(lotPlatformDeviceQueryRequest);
        return success(listLotPlatformDeviceVO);
    }

}
