package org.springblade.device.feign;

import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import javax.validation.Valid;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.tool.utils.Func;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import org.springblade.device.entity.IotDeviceHeartbeat;
import org.springblade.device.vo.IotDeviceHeartbeatVO;
import org.springblade.device.wrapper.IotDeviceHeartbeatWrapper;
import org.springblade.device.service.IIotDeviceHeartbeatService;
import org.springblade.core.boot.ctrl.BladeController;
import java.util.List;
/**
 * 设备告警 client
 *
 * @author lianghanqiang
 * @since 2021-05-27
 */

@AllArgsConstructor
@RestController
@RequestMapping("/feign/iotdeviceheartbeat")

public class IotDeviceHeartbeatClient implements IIotDeviceHeartbeatClient {

    private final IIotDeviceHeartbeatService iotDeviceHeartbeatService;

        /**
     * 详情
     */
    @Override
    @GetMapping("/detail")
    public IotDeviceHeartbeatVO detail(@SpringQueryMap IotDeviceHeartbeat iotDeviceHeartbeat) {
        IotDeviceHeartbeat detail = iotDeviceHeartbeatService.getOne(Condition.getQueryWrapper(iotDeviceHeartbeat));
        return IotDeviceHeartbeatWrapper.build().entityVO(detail);
        }

    /**
     * 查询 设备告警
     */
    @Override
    @GetMapping("/list")
    public List<IotDeviceHeartbeatVO> list(@SpringQueryMap IotDeviceHeartbeat iotDeviceHeartbeat) {
        return IotDeviceHeartbeatWrapper.build().listVO(iotDeviceHeartbeatService.list(Condition.getQueryWrapper(iotDeviceHeartbeat)));
        }



    /**
     * 新增 设备告警
     */
    @Override
    @PostMapping("/save")
    public boolean save(@Valid @RequestBody IotDeviceHeartbeat iotDeviceHeartbeat) {
        return iotDeviceHeartbeatService.save(iotDeviceHeartbeat);
        }

    /**
     * 修改 设备告警
     */
    @Override
    @PostMapping("/update")
    public boolean update(@Valid @RequestBody IotDeviceHeartbeat iotDeviceHeartbeat) {
        return iotDeviceHeartbeatService.updateById(iotDeviceHeartbeat);
        }

    /**
     * 新增或修改 设备告警
     */
    @Override
    @PostMapping("/submit")
    public boolean submit(@Valid @RequestBody IotDeviceHeartbeat iotDeviceHeartbeat) {
        return iotDeviceHeartbeatService.saveOrUpdate(iotDeviceHeartbeat);
        }


    /**
     * 删除 设备告警
     */
    @Override
    @PostMapping("/remove")
    public boolean remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        return iotDeviceHeartbeatService.deleteLogic(Func.toLongList(ids));
        }


}
