Newer
Older
huludao / src / main / java / com / newfiber / api / pc / controller / HkwsViewController.java
package com.newfiber.api.pc.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.github.pagehelper.PageInfo;
import com.newfiber.api.config.FileVisitProperty;
import com.newfiber.api.core.annotation.SysLog;
import com.newfiber.api.core.bean.ReqBodyObj;
import com.newfiber.api.core.bean.RespBodyObj;
import com.newfiber.api.core.commons.PageRequestObject;
import com.newfiber.api.core.commons.PageResultObject;
import com.newfiber.api.core.commons.ResultCode;
import com.newfiber.api.core.commons.ResultObj;
import com.newfiber.api.core.support.HttpCode;
import com.newfiber.api.pc.model.entity.CameraPic;
import com.newfiber.api.pc.model.entity.CameraResource;
import com.newfiber.api.pc.model.entity.CameraStat;
import com.newfiber.api.pc.model.hikvsion.RegionStation;
import com.newfiber.api.pc.service.CameraPicService;
import com.newfiber.api.pc.service.CameraResourceService;
import com.newfiber.api.pc.service.RegisionStationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sun.misc.BASE64Decoder;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.ParseException;
import java.util.Calendar;
import java.util.List;
import java.util.Map;

/**
 * @ClassName HkwsViewController  海康威视视频对接接口
 * @Description TODO
 * @Author 张鸿志
 * @Date 2021年3月4日13:14:02 13:14
 * Version 1.0
 **/
@Api(value = "HkwsViewController",tags = "海康威视视频功能接口")
@RestController
@RequestMapping("/hkview")
@Slf4j
public class HkwsViewController {

    @Autowired
    private CameraResourceService cameraResourceService;

    @Autowired
    private RegisionStationService stationService;



    @Autowired
    private CameraPicService cameraPicService;



    @Autowired
    private FileVisitProperty fileVisitProperty;


    @PostMapping("/queryAreaTree")
    @ApiOperation("查询区域的树列表")
    @SysLog(actionType = "4",value = "查询摄像头区域的树列表")
    public ResultObj<List<RegionStation>> queryTreePage(){
        return new ResultObj<>(ResultCode.OK,stationService.queryTreePage());
    }

    @PostMapping("/queryCameraResource")
    @ApiOperation("查询相机资源")
    @SysLog(actionType = "4",value = "查询相机资源")
    public ResultObj<List<CameraResource>> queryCameraResource(@RequestParam("indexCode")String indexCode){
        return new ResultObj<>(ResultCode.OK,stationService.queryCameraResource(indexCode));
    }

    @PostMapping("/queryPage")
    @ApiOperation("/分页查询视频设备管理")
    @SysLog(actionType = "4",value = "分页查询视频设备管理")
    public ResultObj<PageResultObject<CameraResource>> queryPage(@RequestBody PageRequestObject<String> pageRequestObject){
        return new ResultObj<>(ResultCode.OK,cameraResourceService.queryPage(pageRequestObject));
    }

    @PostMapping("/selectIsHighSpot")
    @ApiOperation("查询所有高点摄像机")
    @SysLog(actionType = "4",value = "查询所有高点摄像机")
    public ResultObj<List<CameraResource>> selectIsHighSpot(){
        EntityWrapper<CameraResource> wrapper = new EntityWrapper<>();
        wrapper.eq("is_high_spot",1);
        return new ResultObj<>(ResultCode.OK,cameraResourceService.selectList(wrapper));
    }


    @PostMapping("/updateistop")
    @ApiOperation("修改是否设置为置顶展示")
    @SysLog(actionType = "3",value = "修改是否设置为置顶展示")
    public ResultObj updateIsTop(@RequestParam("id")Integer id){
        cameraResourceService.updateIsTop(id);
        return ResultObj.ok();
    }
    @PostMapping("/updateisshow")
    @ApiOperation("更新资源是否展示")
    @SysLog(actionType = "3",value = "更新资源是否展示")
    public ResultObj updateIsShow(@RequestParam("id")Integer id){
        cameraResourceService.updateIsShow(id);
        return ResultObj.ok();
    }


    @PostMapping("/queryshowcamear")
    @ApiOperation("查询需要展示的摄像头数据")
    @SysLog(actionType = "4",value = "查询需要展示的摄像头数据")
    public ResultObj<List<CameraResource>> queryShowCamera(){
        return new ResultObj<List<CameraResource>>(ResultCode.OK,cameraResourceService.queryShowCamera());
    }

    @PostMapping("/queryAll")
    @ApiOperation("查询所有的摄像头数据")
    @SysLog(actionType = "4",value = "查询所有的摄像头数据")
    public ResultObj<List<CameraResource>> queryAll(@RequestParam(value = "cameraName",required = false)String cameraName,@RequestParam("type")Integer type){
        EntityWrapper<CameraResource> wrapper = new EntityWrapper<>();

        //如果是应急指挥
        if(type.equals(1)){
            wrapper.eq("is_show",1);
            wrapper.eq("status",1);
            return new ResultObj<>(ResultCode.OK,cameraResourceService.selectList(wrapper));
        }else{
            wrapper.like("name",cameraName);
            List<CameraResource> cameraResources = cameraResourceService.selectList(wrapper);
            return new ResultObj<>(ResultCode.OK,cameraResources);
        }
    }

    @PostMapping("/queryAllNew")
    @ApiOperation("查询所有的摄像头数据")
    @SysLog(actionType = "4",value = "查询所有的摄像头数据(新版)")
    public ResultObj<List<CameraResource>> queryAllNew(){
        EntityWrapper<CameraResource> wrapper = new EntityWrapper<>();
        wrapper.eq("is_show",1);
        return new ResultObj<>(ResultCode.OK,cameraResourceService.selectList(wrapper));
    }




    @GetMapping("/sync")
    @ApiOperation("同步资源操作")
    @SysLog(actionType = "3",value = "同步资源操作")
    public ResultObj sync(){
        try {
            cameraResourceService.sync();
        } catch (ParseException e) {
            return ResultObj.error("操作失败!");
        }
        return ResultObj.ok();
    }

    @PostMapping("/config_is_higt_spot")
    @ApiOperation("设置该摄像机为高点摄像机")
    @SysLog(actionType = "3",value = "设置该摄像机为高点摄像机")
    public ResultObj configIsHighSpot(@RequestParam("id")Integer id){
        cameraResourceService.configIsHighSpot(id);
        return ResultObj.ok();
    }


    @PostMapping("/download")
    @ApiOperation("下载插件")
    public ResultObj<String> downloadPlugins(){
        return new ResultObj<>(ResultCode.OK,fileVisitProperty.getWebExeFile() + "/xinyangfile/VideoWebPlugin.exe");
    }

    @PostMapping("/saveImage")
    @ApiOperation("保存摄像头抓拍图片")
    @SysLog(actionType = "1",value = "保存摄像头抓拍图片")
    public ResultObj saveImage(@RequestBody ReqBodyObj<CameraPic> pic){
        try {

            int i = cameraPicService.saveImage(pic.getData());
            if(i>0){
                return ResultObj.ok();
            }else{
                return ResultObj.error("操作失败!");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return ResultObj.error("操作失败!");
    }

    @PostMapping("/imageList")
    @ApiOperation("抓拍图片列表返回")
    @SysLog(actionType = "4",value = "抓拍图片列表返回")
    public RespBodyObj<PageInfo<CameraPic>> imageList(@RequestBody ReqBodyObj<Map<String, Object>> params){
        Integer current = params.getCurrent();
        Integer size = params.getSize();
        String indexCode = String.valueOf(params.getData().get("indexCode"));
        String startTime = String.valueOf(params.getData().get("startTime"));
        String endTime = String.valueOf(params.getData().get("endTime"));
        PageInfo<CameraPic> cameraPicPageInfo = cameraPicService.imageList(indexCode, startTime, endTime, current, size);
        return RespBodyObj.ok(cameraPicPageInfo);
    }

    /**
     * 雨量站关联的排口视频
     * @param siteNo
     * @return
     */
    @PostMapping("/getCameraCode")
    @ApiOperation("通过站点编号获取视频code")
    @SysLog(actionType = "4",value = "通过站点编号获取视频code")
    public RespBodyObj getCameraCode(@RequestParam("siteNo")String siteNo){
        List<String> result = cameraResourceService.getCameraCode(siteNo);
        return RespBodyObj.ok(result);
    }

    /**
     * 通过站点编号获取mongo中的历史数据
     * @param siteNo
     * @return
     */
    @PostMapping("/getBlackRiverWaterData")
    @ApiOperation("通过站点编号获取mongo中的历史数据")
    @SysLog(actionType = "4",value = "通过站点编号获取mongo中的历史数据")
    public RespBodyObj getBlackRiverWaterData(@RequestParam("siteNo")String siteNo){
        Map<String,Object> result = cameraResourceService.getBlackRiverWaterData(siteNo);
        return RespBodyObj.ok(result);
    }

    @PostMapping("/queryCameraStat")
    @ApiOperation("查询摄像资源的统计数据")
    @SysLog(actionType = "4",value = "查询摄像资源的统计数据")
    public RespBodyObj<CameraStat> queryCameraStat(){
        return new RespBodyObj<>(HttpCode.OK,cameraResourceService.queryCameraStat());
    }










    //base64字符串转化成图片
    public void GenerateImage(String imgStr) {


        BASE64Decoder decoder = new BASE64Decoder();
        //Base64解码
        byte[] b = new byte[0];
        try {
            b = decoder.decodeBuffer(imgStr);
            for (int i = 0; i < b.length; ++i) {
                if (b[i] < 0){
                    b[i] += 256;
                }
            }
            //生成jpeg图片
            StringBuffer sb = new StringBuffer();
            Calendar instance = Calendar.getInstance();
            sb.append(instance.get(Calendar.YEAR))
                    .append(File.separator)
                    .append(instance.get(Calendar.MARCH) + 1).
                    append(File.separator);
            String imgFilePath = "D:\\tupian\\new.jpg";//新生成的图片
            OutputStream out = new FileOutputStream(imgFilePath);
            out.write(b);
            out.flush();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }



    }

}