package com.yuchen.saas.park.service.controller.device;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.park.api.entity.park.PmgBatDeviceData;
import com.yuchen.saas.park.service.service.ParkDeviceDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.nest.springwrap.core.mp.support.Condition;
import org.nest.springwrap.core.mp.support.Query;
import org.nest.springwrap.core.tool.api.R;
import org.nest.springwrap.core.tool.utils.Func;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@AllArgsConstructor
@RequestMapping("/device_data")
@Api(value = "单灯控制", tags = "单灯控制接口")
public class DeviceDataController {


    @Autowired
    private ParkDeviceDataService parkDeviceDataService;

    /**
     * 详情
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "详情", notes = "传入parkCompany")
    public R<PmgBatDeviceData> detail(PmgBatDeviceData pmgBatDeviceData) {
        PmgBatDeviceData detail = parkDeviceDataService.getOne(Condition.getQueryWrapper(pmgBatDeviceData));
        return R.data(detail);
    }


    /**
     * 分页 企业信息表
     */
    @GetMapping("/list")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "分页", notes = "传入parkCompany")
    public R<IPage<PmgBatDeviceData>> list(PmgBatDeviceData pmgBatParkCompany, Query query) {
        IPage<PmgBatDeviceData> pages = parkDeviceDataService.page(Condition.getPage(query),Condition.getQueryWrapper(pmgBatParkCompany));
        return  R.data(pages);
    }


    /**
     * 新增 企业信息
     */
    @PostMapping("/save")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "新增", notes = "传入parkCompany")
    public R save(@Valid @RequestBody PmgBatDeviceData pmgBatDeviceData) {
        return R.status(parkDeviceDataService.save(pmgBatDeviceData));
    }
    /**
     * 批量保存设备实时数据
     */
    @PostMapping("/saveList")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "新增", notes = "实时数据对象")
    public R saveList(@Valid @RequestBody List<PmgBatDeviceData> pmgBatDeviceDataList) {
        return R.status(parkDeviceDataService.saveBatch(pmgBatDeviceDataList));
    }
    /**
     * 修改
     */
    @PutMapping("/update")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "修改", notes = "传入parkCompany")
    public R update(@Valid @RequestBody PmgBatDeviceData pmgBatParkCompany) {
        return R.status(parkDeviceDataService.updateById(pmgBatParkCompany));
    }

    /**
     * 删除 车辆信息表
     */
    @DeleteMapping("/remove")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "逻辑删除", notes = "传入ids")
    public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        return R.status(parkDeviceDataService.deleteLogic(Func.toLongList(ids)));
    }


}
