package com.zd.forward.controller;


import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.zd.common.core.domain.R;
import com.zd.common.core.exception.ServiceException;
import com.zd.common.swagger.config.Knife4jConfiguration;
import com.zd.forward.serivce.ImageService;
import com.zd.system.api.domain.SysFile;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * 报警拍照服务
 */
@Api(tags = {"报警拍照服务"})
@ApiSupport(author = Knife4jConfiguration.Author.ZP)
@RestController
@RequestMapping("/alarm")
public class AlarmController {

    @Resource
    private ImageService imageService;

    @ApiOperation(value = "拍照")
    @GetMapping("/photograph")
    public R<SysFile> photograph(@RequestParam("streamUrl") String streamUrl) {
        try {
            SysFile sysFile = imageService.photograph(streamUrl);
            if (sysFile!=null){
                return R.ok(sysFile);
            }
            return R.fail("图片抓拍失败");
        } catch (IOException|ServiceException e) {
            throw new ServiceException(e.getMessage());
        }
    }
}
