 package com.huatek.busi.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import com.huatek.busi.constant.ApiConstant.Tags;
import com.huatek.busi.dto.BusiVideoDto;
import com.huatek.busi.entity.BusiVideo;
import com.huatek.busi.service.BusiVideoService;
import com.huatek.busi.vo.BusiVideoVo;
import com.huatek.torch.frame.log.KerLog;
import com.huatek.torch.frame.permission.KerPermission;
import com.huatek.torch.frame.tools.ConstantUtil;
import com.huatek.torch.frame.tools.ResultUtil;
import com.huatek.torch.util.uuid.Uuid;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

@Api(tags = {Tags.BUSI_VIDEO})
 @Slf4j
 @RestController
 @RequestMapping("/api/busiVideo")
 public class BusiVideoController {
    
    @Reference(check = false)
    private BusiVideoService busiVideoService;
    
    @ApiOperation(value = "列表分页查询", response = BusiVideoVo.class)
    @PostMapping(value = "/queryList", produces = { "application/json;charset=utf-8" })
    public Map<String, Object> queryList(@RequestBody BusiVideoDto busiVideoDto) {
        PageInfo<BusiVideoVo> busiVideoVo = busiVideoService.page(busiVideoDto);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, busiVideoVo.getTotal(), "",
            busiVideoVo.getList());
    }
    
    @ApiOperation(value = "根据Id查询视频", response = BusiVideoVo.class)
    @GetMapping(value = "/queryBusiVideoById", produces = { "application/json;charset=utf-8" })
    public Map<String, Object> queryBusiVideoById(@RequestParam("id") String id) {
        BusiVideoVo busiVideoVo = busiVideoService.queryBusiVideoById(id);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", busiVideoVo);
    }
    
    
    /**
     * 添加视频流
     * @param busiVideo
     * @return
     */
    @ApiOperation(value = "添加视频流")
    @KerLog(projectName = "PROJECTNAME", modelName = "BUSISITE.MODELNAME", methodName = "BUSISITE.METHODNAME.ADDBUSITEMPERPOINT")
    @PostMapping(value = "/addBusiVideo", produces = { "application/json;charset=utf-8" })
    public Map<String, Object> addBusiVideo(String token,@RequestBody BusiVideo busiVideo) {
        busiVideo.setId(Uuid.getUUID());
        int count = busiVideoService.add(token,busiVideo);
        log.debug("addBusiVideo: {}", count);
        Map<String, Object> map = ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
        return map;
    }

    /**
     * 修改视频流
     * @param busiTemperPointDto
     * @return
     */
    @ApiOperation(value = "修改视频流")
    @KerLog(projectName = "PROJECTNAME", modelName = "BUSISITE.MODELNAME", methodName = "BUSISITE.METHODNAME.UPDATEBUSITEMPERPOINT")
    @PostMapping(value = "/updateBusiVideo", produces = { "application/json;charset=utf-8" })
    public Map<String, Object> updateBusiVideo(@RequestBody BusiVideo busiVideo) {
        int count = busiVideoService.update(busiVideo);
        log.debug("updateBusiVideo: {}", count);
        Map<String, Object> map = ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
        return map;
    }

    /**
     * 删除视频流
     * @param temperPointId
     * @return
     */
    @ApiOperation(value = "删除视频流")
    @KerLog(projectName = "PROJECTNAME", modelName = "BUSISITE.MODELNAME", methodName = "BUSISITE.METHODNAME.DELETEBUSISITE")
    @PostMapping(value = "/deleteBusiVideo", produces = { "application/json;charset=utf-8" })
    @KerPermission("")                     
    public Map<String, Object> deleteBusiVideo(String token,@RequestBody String[] ids) {
        int count = busiVideoService.delete(Arrays.asList(ids));
        log.debug("deleteBusiVideo: {}", count);
        Map<String, Object> map = ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
        return map;
    }
    
}
