package com.ruoyi.project.aerial.controller;

import java.io.IOException;
import java.util.List;

import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.framework.config.RuoYiConfig;
import com.ruoyi.project.common.domain.TCommonfile;
import com.ruoyi.project.common.service.ITCommonfileService;
import org.apache.commons.lang.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.aerial.domain.TAerialDevVideo;
import com.ruoyi.project.aerial.service.ITAerialDevVideoService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;
import sun.misc.ObjectInputFilter;

/**
 * 鸟瞰图设备视频Controller
 *
 * @author ssy
 * @date 2025-04-03
 */
@RestController
@RequestMapping("/aerial/devVideo")
public class TAerialDevVideoController extends BaseController
{
    @Autowired
    private ITAerialDevVideoService tAerialDevVideoService;

    @Autowired
    private ITCommonfileService tCommonfileService;

    /**
     * 获取鸟瞰图设备视频详细信息（根据区域名称和设备名称获取）
     */
    @PreAuthorize("@ss.hasPermi('aerial:devVideo:query')")
    @GetMapping(value = "/getDevVideoByAreaAndDev")
    public AjaxResult getInfoByAreaAndDev(TAerialDevVideo tAerialDevVideo)
    {
        List<TAerialDevVideo> list = tAerialDevVideoService.selectTAerialDevVideoList(tAerialDevVideo);//鸟瞰图设备视频对象列表
        if (list.size() == 1) {//最多一个对象
            TAerialDevVideo video = list.get(0);
            TCommonfile commonfile  = new TCommonfile();
            commonfile.setpType("devVideo");
            commonfile.setpId(video.getId());
            List<TCommonfile> tCommonfiles = tCommonfileService.selectAllFileList(commonfile);//文件列表
            if (tCommonfiles.size() == 1) {//最多一个文件
                TCommonfile file = tCommonfiles.get(0);
                file.setFileUrl(file.getFileUrl().replace("/profile", ""));
                return AjaxResult.success(file);
            } else {
                return AjaxResult.success();
            }
        } else {
            return AjaxResult.success();
        }
    }

    /**
     * 查询鸟瞰图设备视频列表
     */
    @PreAuthorize("@ss.hasPermi('aerial:devVideo:list')")
    @GetMapping("/list")
    public TableDataInfo list(TAerialDevVideo tAerialDevVideo)
    {
        startPage();
        List<TAerialDevVideo> list = tAerialDevVideoService.selectTAerialDevVideoList(tAerialDevVideo);
        return getDataTable(list);
    }

    /**
     * 导出鸟瞰图设备视频列表
     */
    @PreAuthorize("@ss.hasPermi('aerial:devVideo:export')")
    @Log(title = "鸟瞰图设备视频", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TAerialDevVideo tAerialDevVideo)
    {
        List<TAerialDevVideo> list = tAerialDevVideoService.selectTAerialDevVideoList(tAerialDevVideo);
        ExcelUtil<TAerialDevVideo> util = new ExcelUtil<TAerialDevVideo>(TAerialDevVideo.class);
        return util.exportExcel(list, "devVideo");
    }

    /**
     * 获取鸟瞰图设备视频详细信息
     */
    @PreAuthorize("@ss.hasPermi('aerial:devVideo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tAerialDevVideoService.selectTAerialDevVideoById(id));
    }

    /**
     * 新增鸟瞰图设备视频
     */
    @PreAuthorize("@ss.hasPermi('aerial:devVideo:add')")
    @Log(title = "鸟瞰图设备视频", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TAerialDevVideo tAerialDevVideo)
    {
        return toAjax(tAerialDevVideoService.insertTAerialDevVideo(tAerialDevVideo));
    }

    /**
     * 修改鸟瞰图设备视频
     */
    @PreAuthorize("@ss.hasPermi('aerial:devVideo:edit')")
    @Log(title = "鸟瞰图设备视频", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TAerialDevVideo tAerialDevVideo)
    {
        return toAjax(tAerialDevVideoService.updateTAerialDevVideo(tAerialDevVideo));
    }

    /**
     * 删除鸟瞰图设备视频
     */
    @PreAuthorize("@ss.hasPermi('aerial:devVideo:remove')")
    @Log(title = "鸟瞰图设备视频", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tAerialDevVideoService.deleteTAerialDevVideoByIds(ids));
    }
}
