package cn.iocoder.yudao.module.pms.controller.admin.yanfan.sip.device.channel;

import cn.iocoder.yudao.module.pms.controller.admin.TableDataInfo;
import cn.iocoder.yudao.module.pms.controller.admin.yanfan.sip.device.channel.vo.YfSipDeviceChannelPageReqVO;
import cn.iocoder.yudao.module.pms.controller.admin.yanfan.sip.device.channel.vo.YfSipDeviceChannelRespVO;
import cn.iocoder.yudao.module.pms.controller.admin.yanfan.sip.device.channel.vo.YfSipDeviceChannelSaveReqVO;
import cn.iocoder.yudao.module.pms.dal.dataobject.yanfan.sip.device.channel.YfSipDeviceChannelDO;
import cn.iocoder.yudao.module.pms.service.yanfan.sip.device.YfSipDeviceService;
import cn.iocoder.yudao.module.pms.service.yanfan.sip.device.channel.YfSipDeviceChannelService;
import cn.iocoder.yudao.module.pms.service.yanfan.sip.model.BaseTree;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;


@Tag(name = "管理后台 - yf监控设备通道信息")
@RestController
@RequestMapping("/rq/yf-sip-device-channel")
@Validated
public class YfSipDeviceChannelController {

    @Resource
    private YfSipDeviceChannelService yfSipDeviceChannelService;
    @Autowired
    private YfSipDeviceService yfSipDeviceService;

    @PostMapping("/create")
    @Operation(summary = "创建yf监控设备通道信息")
    @PreAuthorize("@ss.hasPermission('rq:yf-sip-device-channel:create')")
    public CommonResult<Long> createYfSipDeviceChannel(@Valid @RequestBody YfSipDeviceChannelSaveReqVO createReqVO) {
        return success(yfSipDeviceChannelService.createYfSipDeviceChannel(createReqVO));
    }

    @Operation(summary = "新增监控设备通道信息")
    @PostMapping(value = "/{createNum}")
    public CommonResult<String> add(@PathVariable("createNum") Long createNum, @RequestBody YfSipDeviceChannelSaveReqVO sipDeviceChannel) {
        return success(yfSipDeviceChannelService.insertSipDeviceChannelGen(createNum, sipDeviceChannel));
//        return AjaxResult.success(MessageUtils.message("operate.success"), );
    }

    @PutMapping("/update")
    @Operation(summary = "更新yf监控设备通道信息")
    @PreAuthorize("@ss.hasPermission('rq:yf-sip-device-channel:update')")
    public CommonResult<Boolean> updateYfSipDeviceChannel(@Valid @RequestBody YfSipDeviceChannelSaveReqVO updateReqVO) {
        yfSipDeviceChannelService.updateYfSipDeviceChannel(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除yf监控设备通道信息")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('rq:yf-sip-device-channel:delete')")
    public CommonResult<Boolean> deleteYfSipDeviceChannel(@RequestParam("id") Long id) {
        yfSipDeviceChannelService.deleteYfSipDeviceChannel(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得yf监控设备通道信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('rq:yf-sip-device-channel:query')")
    public CommonResult<YfSipDeviceChannelRespVO> getYfSipDeviceChannel(@RequestParam("id") Long id) {
        YfSipDeviceChannelDO yfSipDeviceChannel = yfSipDeviceChannelService.getYfSipDeviceChannel(id);
        return success(BeanUtils.toBean(yfSipDeviceChannel, YfSipDeviceChannelRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得yf监控设备通道信息分页")
    @PreAuthorize("@ss.hasPermission('rq:yf-sip-device-channel:query')")
    public CommonResult<PageResult<YfSipDeviceChannelRespVO>> getYfSipDeviceChannelPage(@Valid YfSipDeviceChannelPageReqVO pageReqVO) {
        PageResult<YfSipDeviceChannelDO> pageResult = yfSipDeviceChannelService.getYfSipDeviceChannelPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, YfSipDeviceChannelRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出yf监控设备通道信息 Excel")
    @PreAuthorize("@ss.hasPermission('rq:yf-sip-device-channel:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportYfSipDeviceChannelExcel(@Valid YfSipDeviceChannelPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<YfSipDeviceChannelDO> list = yfSipDeviceChannelService.getYfSipDeviceChannelPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "yf监控设备通道信息.xls", "数据", YfSipDeviceChannelRespVO.class,
                        BeanUtils.toBean(list, YfSipDeviceChannelRespVO.class));
    }


    /**
     * 查询监控设备通道信息列表
     */
    @Operation(summary = "查询监控设备通道信息列表")
    //@PreAuthorize("@ss.hasPermi('iot:video:list')")
    @GetMapping("/list")
    public CommonResult<List<YfSipDeviceChannelRespVO>> list(YfSipDeviceChannelDO sipDeviceChannelDO) {
        List<YfSipDeviceChannelRespVO> yfSipDeviceChannelDOS = yfSipDeviceChannelService.selectSipDeviceChannelList(sipDeviceChannelDO);
        return success(yfSipDeviceChannelDOS);
    }
}
