package com.sptg.gateway.controller.iot;

import com.baomidou.mybatisplus.plugins.Page;
import com.sptg.common.core.beans.PageBean;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.security.annotation.Security;
import com.sptg.common.security.enums.DataFormatEnum;
import com.sptg.iot.api.constant.IotSecurityToken;
import com.sptg.iot.api.dto.IotAlarmWorkOrderDto;
import com.sptg.iot.api.dto.IotDeviceDto;
import com.sptg.iot.api.entity.IotAlarmWorkOrder;
import com.sptg.iot.api.entity.IotDevice;
import com.sptg.iot.api.feigns.IotAlarmWorkOrderFeign;
import com.sptg.iot.api.feigns.IotDeviceFeign;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author zwx
 * @create 2020/11/17 14:40
 */
@RestController
@RequestMapping(value = "/iot/alarmWorkOrder")
@RequiredArgsConstructor
public class IotAlarmWorkOrderController {

    private final IotAlarmWorkOrderFeign iotAlarmWorkOrderFeign;

    /**
     * 功能描述:iot设备告警工单列表初始化页面
     * @return ModelAndView
     */
    @GetMapping("/index")
    @Security(token = IotSecurityToken.IOT_ALARM_WORK_ORDER_MANAGE,format = DataFormatEnum.VIEW)
    public ModelAndView index(){
        return new ModelAndView("iot/iot-alarm-work-order-manage");
    }

    /**
     * 功能描述: 根据条件分页查询iot设备告警工单列表
     * @param pageBean 分页条件
     * @return ResultBean<Page>
     */
    @GetMapping(value = "/pagingQuery")
    @Security(token = IotSecurityToken.IOT_ALARM_WORK_ORDER_MANAGE,format = DataFormatEnum.JSON)
    public ResultBean<Page<IotAlarmWorkOrder>> pagingQuery(IotAlarmWorkOrderDto iotAlarmWorkOrderDto, PageBean<IotAlarmWorkOrder, IotAlarmWorkOrderDto> pageBean){
        // 暂时拿全部的数据
        iotAlarmWorkOrderDto.setPage(pageBean);
        return this.iotAlarmWorkOrderFeign.pagingQuery(iotAlarmWorkOrderDto);
    }

    /**
     * 功能描述: iot设备告警工单详情界面
     * @return ModelAndView
     */
    @GetMapping(value = "/detail/{id}")
    @Security(token = IotSecurityToken.IOT_ALARM_WORK_ORDER_MANAGE, format = DataFormatEnum.VIEW)
    public ModelAndView detail(@PathVariable(value = "id") Long id){
        IotAlarmWorkOrder iotAlarmWorkOrder = this.iotAlarmWorkOrderFeign.getIotAlarmWorkOrderById(id);
        if (iotAlarmWorkOrder == null){
            return new ModelAndView("common/404");
        }
        ModelAndView modelAndView = new ModelAndView("iot/iot-alarm-work-order-detail");
        modelAndView.addObject("iotAlarmWorkOrder",iotAlarmWorkOrder);
        return modelAndView;
    }
}
