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.LotPlatformDeviceQueryRequest;
import com.ruoyi.web.domain.dto.lotPlatformProducts.LotPlatformProductsAddRequest;
import com.ruoyi.web.domain.dto.lotPlatformProducts.LotPlatformProductsEditRequest;
import com.ruoyi.web.domain.dto.lotPlatformProducts.LotPlatformProductsQueryRequest;
import com.ruoyi.web.domain.entity.LotPlatformDevice;
import com.ruoyi.web.domain.entity.LotPlatformProducts;
import com.ruoyi.web.domain.vo.LotPlatformProductsVO;
import com.ruoyi.web.service.LotPlatformProductsService;
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/products")
public class LotPlatformProductsController {

    @Autowired
    private LotPlatformProductsService lotPlatformProductsService;

    /**
     * 添加物联网平台产品
     *
     * @param lotPlatformProductsAddRequest
     * @return
     */
    @ApiOperation("添加物联网平台产品")
    @PostMapping("/add")
    public AjaxResult addLotPlatformProducts(@RequestBody LotPlatformProductsAddRequest lotPlatformProductsAddRequest) {
        if (lotPlatformProductsAddRequest == null) {
            return error("请求参数为空");
        }
        Integer id = lotPlatformProductsService.addLotPlatformProducts(lotPlatformProductsAddRequest);
        return success(id);
    }

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


    /**
     * 编辑物联网平台产品
     *
     * @param lotPlatformProductsEditRequest
     * @return
     */
    @ApiOperation("编辑物联网平台产品")
    @PostMapping("/edit")
    public AjaxResult editLotPlatformProducts(@RequestBody LotPlatformProductsEditRequest lotPlatformProductsEditRequest) {
        if (lotPlatformProductsEditRequest == null) {
            return error("请求参数为空");
        }
        lotPlatformProductsService.editLotPlatformProducts(lotPlatformProductsEditRequest);
        return AjaxResult.success();
    }


    /**
     * 根据id获取物联网平台产品
     *
     * @param id
     * @return
     */
    @ApiOperation("根据id获取物联网平台产品")
    @GetMapping("/get")
    public AjaxResult getLotPlatformProductsById(@RequestParam int id) {
        if (ObjectUtil.isEmpty(id)) {
            return error("请求参数为空");
        }
        LotPlatformProductsVO lotPlatformProductsVO = lotPlatformProductsService.getLotPlatformProductsById(id);
        return success(lotPlatformProductsVO);
    }

    /**
     * 分页获取物联网平台产品列表
     *
     * @param lotPlatformProductsQueryRequest
     * @return
     */
    @ApiOperation("分页获取物联网平台产品列表")
    @PostMapping("/list/page")
    public AjaxResult listLotPlatformProductsByPage(@RequestBody LotPlatformProductsQueryRequest lotPlatformProductsQueryRequest) {
        if (lotPlatformProductsQueryRequest == null) {
            return error("请求参数为空");
        }
        Page<LotPlatformProductsVO> listLotPlatformProductsVOByPage = lotPlatformProductsService.getListLotPlatformProductsByPage(lotPlatformProductsQueryRequest);
        return success(listLotPlatformProductsVOByPage);
    }

    @ApiOperation("获取全部物联网平台设备列表")
    @PostMapping("/list/list")
    public AjaxResult listLotPlatformProducts(@RequestBody LotPlatformProductsQueryRequest lotPlatformProductsQueryRequest) {
        if (lotPlatformProductsQueryRequest == null) {
            return error("请求参数为空");
        }
        List<LotPlatformProducts> listLotPlatformProductsVOByPage = lotPlatformProductsService.listLotPlatformProducts(lotPlatformProductsQueryRequest);
        return success(listLotPlatformProductsVOByPage);
    }
}
