package com.sptg.iot.biz.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.iot.api.dto.IotAlarmWorkOrderDto;
import com.sptg.iot.api.entity.IotAlarmWorkOrder;
import com.sptg.iot.api.feigns.IotAlarmWorkOrderFeign;
import com.sptg.iot.biz.service.IotAlarmWorkOrderServiceInterface;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author zwx
 * @create 2020/10/20 9:29
 */
@Slf4j
@RestController
@RequiredArgsConstructor
public class IotAlarmWorkOrderController implements IotAlarmWorkOrderFeign {

    private final IotAlarmWorkOrderServiceInterface iotDeviceWorkOrderServiceInterface;

    @Override
    @PostMapping(value = "/iot/alarmWorkOrder/list")
    public ResultBean<Page<IotAlarmWorkOrder>> showIotAlarmWorkOrderList(@RequestBody IotAlarmWorkOrderDto iotAlarmWorkOrderDto) {
        ResultBean<Page<IotAlarmWorkOrder>> pageResultBean = this.iotDeviceWorkOrderServiceInterface.showIotDeviceWorkOrderList(iotAlarmWorkOrderDto);
        return pageResultBean;
    }

    @Override
    @PostMapping(value = "/iot/alarmWorkOrder/sync/list")
    public ResultBean<String> syncIotAlarmWorkOrderList(@RequestBody IotAlarmWorkOrderDto iotAlarmWorkOrderDto) {
        ResultBean<String> resultBean = this.iotDeviceWorkOrderServiceInterface.syncIotDeviceWorkOrderList(iotAlarmWorkOrderDto);
        return resultBean;
    }

    @Override
    @PostMapping(value = "/iot/alarmWorkOrder/update")
    public ResultBean<String> updateIotAlarmWorkOrder(@RequestBody IotAlarmWorkOrderDto iotAlarmWorkOrderDto) {
        String orderId = iotAlarmWorkOrderDto.getOrder_id();
        Integer status = iotAlarmWorkOrderDto.getStatus();
        if(orderId == null){
            new ResultBean<>(ResultEnum.PARAMETER_ANOMALY, "工单id不能为空");
        }
        if(status == null){
            new ResultBean<>(ResultEnum.PARAMETER_ANOMALY, "工单更新状态不能为空");
        }
        ResultBean<String> resultBean = this.iotDeviceWorkOrderServiceInterface.updateIotDeviceWorkOrder(iotAlarmWorkOrderDto);
        return resultBean;
    }

    @Override
    @PostMapping(value = "/iot/iotAlarmWorkOrder/pagingQuery")
    public ResultBean<Page<IotAlarmWorkOrder>> pagingQuery(@RequestBody IotAlarmWorkOrderDto iotAlarmWorkOrderDto) {
        return this.iotDeviceWorkOrderServiceInterface.pagingQuery(iotAlarmWorkOrderDto);
    }

    @Override
    @GetMapping(value = "/iot/iotAlarmWorkOrder/getIotAlarmWorkOrderById/{id}")
    public IotAlarmWorkOrder getIotAlarmWorkOrderById(@PathVariable(value = "id") Long id) {
        return this.iotDeviceWorkOrderServiceInterface.getIotAlarmWorkOrderById(id);
    }
}
