/*
 * Author: Zev
 * 生成controller
 */
package com.tofly.gpsboot.controller.plan.monitor;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.log.annotation.ToFlyAppLog;
import com.tofly.gpsboot.controller.BaseController;
import com.tofly.gpsboot.service.paln.PdamonitorService;
import com.tofly.pojo.plan.Pdamonitor;
import com.tofly.pojo.plan.dto.PdamonitorDto;
import com.tofly.pojo.plan.vo.PdamonitorVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

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

/**
 * 设备实时监控
 *
 * @author admin
 * @date Thu Mar 18 00:00:00 CST 2021
 */
@RestController
@RequestMapping("/pdamonitor")
@Api(tags="设备实时监控")
public class PdamonitorController extends BaseController<Pdamonitor, PdamonitorVo> {
    @Autowired
    public PdamonitorController(PdamonitorService service) {
        init(service);
    }

    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    @ToFlyAppLog(title = "分页查询设备实时监控")
    public ResultRespone<Page<PdamonitorVo>> getPdamonitorPage(Page page, @ModelAttribute PdamonitorDto parDto) {
        return super.getInfoPage(page, JSON.parseObject(JSON.toJSONString(parDto), Pdamonitor.class));
    }

    @ApiOperation(value = "新增基本信息对象")
    @PostMapping("/save")
    @ToFlyAppLog(title = "新增设备实时监控")
    public ResultRespone<Object> savePdamonitor(@Valid @RequestBody PdamonitorDto parDto, BindingResult result) {
        ResultRespone<Object> rest = new ResultRespone<>();
        // 数据校验 判空返回
        return Optional.ofNullable(super.validRest(rest, result)).orElseGet(() -> super.save(JSON.parseObject(JSON.toJSONString(parDto), Pdamonitor.class)));

    }

    @ApiOperation(value = "修改基本信息")
    @PutMapping("/updata")
    @ToFlyAppLog(title = "修改设备实时监控")
    public ResultRespone<Object> updateByIdPdamonitor(@Valid @RequestBody PdamonitorDto parDto, BindingResult result) {
        ResultRespone<Object> rest = new ResultRespone<>();
        // 数据校验 判空返回
        return Optional.ofNullable(super.validRest(rest, result)).orElseGet(() -> super.updateById(JSON.parseObject(JSON.toJSONString(parDto), Pdamonitor.class)));

    }

    @GetMapping("/{id}")
    @ApiOperation(value = "通过ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    @ToFlyAppLog(title = "通过ID查询设备实时监控")
    public ResultRespone<Pdamonitor> getByIdPdamonitor(@PathVariable Long id) {
        return super.getById(id);
    }


    @ApiOperation(value = "通过ID批量删除基本信息对象")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "批量删除，多个id以逗号隔开", required = true, dataType = "String")
    })
    @DeleteMapping("/deleteByIds")
    @ToFlyAppLog(title = "通过ID批量删除设备实时监控")
    public ResultRespone<Object> removeByIdListPdamonitor(String ids) {
        return super.removeByIdList(ids);
    }

}
