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.IotAlarm;
import org.springblade.device.vo.IotAlarmVO;
import org.springblade.device.wrapper.IotAlarmWrapper;
import org.springblade.device.service.IIotAlarmService;
import org.springblade.core.boot.ctrl.BladeController;
import java.util.List;
/**
 * 设备告警 client
 *
 * @author lianghanqiang
 * @since 2021-04-19
 */

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

public class IotAlarmClient implements IIotAlarmClient {

    private final IIotAlarmService iotAlarmService;

        /**
     * 详情
     */
    @Override
    @GetMapping("/detail")
    public IotAlarmVO detail(@SpringQueryMap IotAlarm iotAlarm) {
        IotAlarm detail = iotAlarmService.getOne(Condition.getQueryWrapper(iotAlarm));
        return IotAlarmWrapper.build().entityVO(detail);
        }

    /**
     * 查询 设备告警
     */
    @Override
    @GetMapping("/list")
    public List<IotAlarmVO> list(@SpringQueryMap IotAlarm iotAlarm) {
        return IotAlarmWrapper.build().listVO(iotAlarmService.list(Condition.getQueryWrapper(iotAlarm).lambda().orderByDesc(IotAlarm::getRecordTime)));
        }



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

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

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


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


}
