package com.sooka.sponest.monitor.broadcast.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.domain.SysDept;
import com.ruoyi.system.api.domain.SysUser;
import com.sooka.sponest.monitor.aidevicedept.domain.CenterdataTAidevicedept;
import com.sooka.sponest.monitor.broadcast.domain.CentermonitorTCloudBroadcast;
import com.sooka.sponest.monitor.broadcast.service.ICentermonitorTCloudBroadcastService;
import com.sooka.sponest.monitor.device.domain.CentermonitorTMonitoringDevice;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.rmi.server.UID;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;

import static org.springframework.web.bind.annotation.RequestMethod.GET;

/**
 * 云广播设备Controller
 *
 * @author ruoyi
 * @date 2023-04-23
 */
@RestController
@RequestMapping("/broadcast")
public class CentermonitorTCloudBroadcastController extends BaseController
{
    @Autowired
    private ICentermonitorTCloudBroadcastService centermonitorTCloudBroadcastService;

    /**
     * 查询云广播设备列表
     */
    @Log(title = "云广播", businessType = BusinessType.OTHER)
    @RequiresPermissions("broadcast:broadcast:list")
    @GetMapping("/list")
    public TableDataInfo list(CentermonitorTCloudBroadcast centermonitorTCloudBroadcast)
    {
        startPage();
        List<CentermonitorTCloudBroadcast> list = centermonitorTCloudBroadcastService.selectCentermonitorTCloudBroadcastList(centermonitorTCloudBroadcast);
        return getDataTable(list);
    }

    /**
     * 查询云广播设备列表(所有)
     */
    @ApiOperation(value = "查询云广播设备列表远程调用", notes = "查询云广播设备列表远程调用")
    @GetMapping("/listBroadcastAll")
    @Log(title = "云广播", businessType = BusinessType.OTHER)
    public TableDataInfo listBroadcastAll( CentermonitorTCloudBroadcast centermonitorTCloudBroadcast) {
        startPage();
        List<CentermonitorTCloudBroadcast> list = centermonitorTCloudBroadcastService.selectCentermonitorTCloudBroadcastListAll(centermonitorTCloudBroadcast);
        return getDataTable(list);
    }

    /**
     * 查询部门管理列表
     * */
    @Log(title = "云广播", businessType = BusinessType.OTHER)
    @ApiOperation(value = "查询部门管理列表", notes = "查询部门管理列表")
    @GetMapping("/selectDeptBroadcastData")
    public TableDataInfo selectDeptBroadcastData( CenterdataTAidevicedept centerdataTAidevicedept) {
        startPage();
        List<CenterdataTAidevicedept> list  = centermonitorTCloudBroadcastService.selectDeptBroadcastData(centerdataTAidevicedept);
        return getDataTable(list);
    }

    /**
     * 根据部门id查询部门及部门以下的数据，没有则默认查询所有
     * @param centermonitorTCloudBroadcast
     * @param
     * @return
     */
    @Log(title = "云广播", businessType = BusinessType.OTHER)
    @GetMapping(value = "/getDlblistBydeptId")
    public R getListBydept(CentermonitorTCloudBroadcast centermonitorTCloudBroadcast)
    {
        List<CentermonitorTCloudBroadcast> list = centermonitorTCloudBroadcastService.selectCentermonitorTCloudBroadcastList(centermonitorTCloudBroadcast);
        return R.ok(list);
    }

    /**
     * 导出云广播设备列表
     */
    @RequiresPermissions("broadcast:broadcast:export")
    @Log(title = "云广播设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CentermonitorTCloudBroadcast centermonitorTCloudBroadcast)
    {
        List<CentermonitorTCloudBroadcast> list = centermonitorTCloudBroadcastService.selectCentermonitorTCloudBroadcastList(centermonitorTCloudBroadcast);
        ExcelUtil<CentermonitorTCloudBroadcast> util = new ExcelUtil<CentermonitorTCloudBroadcast>(CentermonitorTCloudBroadcast.class);
        util.exportExcel(response, list, "云广播设备数据");
    }

    /**
     * 根据ID查询云广播详细信息
     */
    @Log(title = "云广播", businessType = BusinessType.OTHER)
    @ApiOperation(value = "根据ID查询云广播详细信息", notes = "根据ID查询云广播详细信息")
    @RequestMapping(value = "/selectByBroadcastId/{id}", method = GET)
    @ApiImplicitParam(name = "id", value = "主键id", paramType = "query")
    public AjaxResult selectByBroadcastId(@PathVariable("id") String id) {
        return AjaxResult.success(centermonitorTCloudBroadcastService.selectCentermonitorTCloudBroadcastById(id));
    }

    /**
     * 获取云广播设备详细信息
     */
    @RequiresPermissions("broadcast:broadcast:query")
    @GetMapping(value = "/{id}")
    @Log(title = "云广播", businessType = BusinessType.OTHER)
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(centermonitorTCloudBroadcastService.selectCentermonitorTCloudBroadcastById(id));
    }

    /**
     * 新增云广播设备
     */
    @RequiresPermissions("broadcast:broadcast:add")
    @Log(title = "云广播设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CentermonitorTCloudBroadcast centermonitorTCloudBroadcast)
    {
        centermonitorTCloudBroadcast.setId(UUID.randomUUID().toString());
        return toAjax(centermonitorTCloudBroadcastService.insertCentermonitorTCloudBroadcast(centermonitorTCloudBroadcast));
    }

    /**
     * 修改云广播设备
     */
    @RequiresPermissions("broadcast:broadcast:edit")
    @Log(title = "云广播设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CentermonitorTCloudBroadcast centermonitorTCloudBroadcast)
    {
        return toAjax(centermonitorTCloudBroadcastService.updateCentermonitorTCloudBroadcast(centermonitorTCloudBroadcast));
    }

    /**
     * 删除云广播设备
     */
    @RequiresPermissions("broadcast:broadcast:remove")
    @Log(title = "云广播设备", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(centermonitorTCloudBroadcastService.deleteCentermonitorTCloudBroadcastByIds(ids));
    }

    /**
     * 查询附近云广播列表
     */
    @Log(title = "云广播", businessType = BusinessType.OTHER)
    @ApiOperation(value = "查询附近云广播列表", notes = "查询附近云广播列表")
    @GetMapping({"/selectNearHorn/{longitude}/{latitude}/{distance}/{type}", "/selectNearHorn/{longitude}/{latitude}/{distance}/{type}/{broadcastUse}"})
    public AjaxResult selectNearHorn(@PathVariable("longitude") String longitude, @PathVariable("latitude") String latitude,
                                     @PathVariable("distance") String distance,@PathVariable(value = "type") String type,
                                     @PathVariable(value = "broadcastUse", required = false) String broadcastUse) {
        return AjaxResult.success(centermonitorTCloudBroadcastService.selectNearHorn(longitude,latitude,broadcastUse,distance,type));
    }
}
