package com.sooka.sponest.monitor.feign;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.system.api.domain.SysFile;
import com.sooka.sponest.monitor.aidevicedept.domain.CenterdataTAidevicedept;
import com.sooka.sponest.monitor.aidevicedept.service.ICenterdataTAidevicedeptService;
import com.sooka.sponest.monitor.aideviceevent.domain.CenterdataTAideviceevent;
import com.sooka.sponest.monitor.aideviceevent.service.ICenterdataTAideviceeventService;
import com.sooka.sponest.monitor.camera.domain.CentermonitorTCamera;
import com.sooka.sponest.monitor.camera.service.ICentermonitorTCameraService;
import com.sooka.sponest.monitor.remoteapi.service.center.file.RemoteFileBaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 监控中心远程接口控制器
 */
@Api(tags = "监控中心远程接口控制器")
@RestController
@RequestMapping("/centerMonitorFeign")
public class CenterMonitorFeignController {
    private final ICenterdataTAidevicedeptService iCenterdataTAidevicedeptService;
    private final ICenterdataTAideviceeventService iCenterdataTAideviceeventService;
    private final ICentermonitorTCameraService centermonitorTCameraService;

    public CenterMonitorFeignController(ICenterdataTAidevicedeptService iCenterdataTAidevicedeptService, ICenterdataTAideviceeventService iCenterdataTAideviceeventService, ICentermonitorTCameraService centermonitorTCameraService) {
        this.iCenterdataTAidevicedeptService = iCenterdataTAidevicedeptService;
        this.iCenterdataTAideviceeventService = iCenterdataTAideviceeventService;
        this.centermonitorTCameraService = centermonitorTCameraService;
    }


    /**
     * 根据设备code查询部门
     */
    @Log(title = "监控中心", businessType = BusinessType.OTHER)
    @ApiOperation(value = "根据设备code查询部门", notes = "根据设备code查询部门")
    @ApiImplicitParam(name = "deviceCode", value = "设备编码", dataType = "String", paramType = "query")
    @RequestMapping(path = "/selectDeptByDeviceCode/{deviceCode}", method = RequestMethod.GET)
    public R<List<CenterdataTAidevicedept>> selectDeptByDeviceCode(@PathVariable("deviceCode") String deviceCode) {
        if (deviceCode == null || StringUtils.isEmpty(deviceCode)) {
            return R.fail(30001, "设备Code为空");
        }
        List<CenterdataTAidevicedept> list = iCenterdataTAidevicedeptService.selectDeptByDeviceCode(deviceCode);
        return R.ok(list);
    }

    /**
     * 根据设备code查询事件类型
     */
    @Log(title = "监控中心", businessType = BusinessType.OTHER)
    @ApiOperation(value = "根据设备code查询事件类型", notes = "根据设备code查询事件类型")
    @ApiImplicitParam(name = "deviceCode", value = "设备编码", dataType = "String", paramType = "query")
    @RequestMapping(path = "/selectEventTypeByDeviceCode/{deviceCode}", method = RequestMethod.GET)
    public R<List<CenterdataTAideviceevent>> selectEventTypeByDeviceCode(@PathVariable("deviceCode") String deviceCode) {
        if (deviceCode == null || StringUtils.isEmpty(deviceCode)) {
            return R.fail(30001, "设备Code为空");
        }
        List<CenterdataTAideviceevent> list = iCenterdataTAideviceeventService.selectEventTypeByDeviceCode(deviceCode);
        return R.ok(list);
    }

    /**
     * 根据摄像头id获取摄像头信息
     */
    @Log(title = "监控中心", businessType = BusinessType.OTHER)
    @ApiOperation(value = "根据摄像头id获取摄像头信息", notes = "根据摄像头id获取摄像头信息")
    @ApiImplicitParam(name = "id", value = "摄像头ID", dataType = "String", paramType = "query")
    @RequestMapping(path = "/selectByCameraId/{id}", method = RequestMethod.GET)
    public R<CentermonitorTCamera> selectByCameraId(@PathVariable("id") String id) {
        CentermonitorTCamera centermonitorTCamera = centermonitorTCameraService.selectCentermonitorTCameraById(id);
        return R.ok(centermonitorTCamera);
    }

    /**
     * 查询摄像头下拉
     */
    @Log(title = "监控中心", businessType = BusinessType.OTHER)
    @PostMapping ("/remoteList")
    public R<List<CentermonitorTCamera>> remoteList(@RequestBody CentermonitorTCamera centermonitorTCamera) {
        return R.ok(centermonitorTCameraService.selectCentermonitorTCameraList(centermonitorTCamera));

    }

    @Autowired
    private RemoteFileBaseService remoteFileBaseService;

    /**
     * 病虫害文件上传
     */
    @Log(title = "监控中心", businessType = BusinessType.OTHER)
    @PostMapping ("/upload")
    public R<SysFile> upload(MultipartFile file) {
        return remoteFileBaseService.upload(file);

    }
}
