Newer
Older
huludao / src / main / java / com / newfiber / api / pc / camera / Controller / CameraInfoController.java
package com.newfiber.api.pc.camera.Controller;


import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.newfiber.api.core.bean.ReqBodyObj;
import com.newfiber.api.core.commons.ResultCode;
import com.newfiber.api.core.commons.ResultObj;
import com.newfiber.api.pc.camera.dto.CameraInfo;
import com.newfiber.api.pc.camera.service.CameraInfoService;
import com.newfiber.xfsk.core.util.InstanceUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 摄像头表 Controller
 *
 * @author xiebinbin
 * @date 2020-12-12 16:49:48
 */
@RestController
@RequestMapping("/camerainfo")
@Api(tags = "摄像头管理")
public class CameraInfoController{
    @Autowired
    private CameraInfoService cameraInfoService;

    /**
     * 获取摄像头表列表
     */
    @PostMapping("/queryPage")
//	@RequiresPermissions("camerainfo:list")
//	@SysLog(value="查询列表",actionType=Constant.ActionType.SELECT)
    public ResultObj<Page<CameraInfo>> list(@RequestBody ReqBodyObj<CameraInfo> params) {
        Page<CameraInfo> page = new Page<>(params.getCurrent(),params.getSize());
        Map<String, Object> map = InstanceUtil.transBean2Map(params.getData());
        List<CameraInfo> cameraInfoList = cameraInfoService.queryList(map, page);
        page.setRecords(cameraInfoList);
        page.setTotal(cameraInfoService.selectCount(new EntityWrapper<CameraInfo>().eq("del_flag",0)));
        return new ResultObj<>(ResultCode.OK,page);
    }

    /**
     * 获取摄像头表列表
     */
    @PostMapping("/queryList")
//	@RequiresPermissions("camerainfo:list")
//	@SysLog(value="查询列表",actionType=Constant.ActionType.SELECT)
    public ResultObj<Map<String,Object>> queryList(@RequestBody ReqBodyObj<CameraInfo> params) {
        Map<String,Object> result=new HashMap<>();
        Map<String, Object> map = InstanceUtil.transBean2Map(params.getData());
        List<CameraInfo> cameraInfoList = cameraInfoService.queryList(map);
        Long online=0l;
        Long offline=0l;
        int all=0;
        if(CollectionUtil.isNotEmpty(cameraInfoList)){
           online= cameraInfoList.stream().filter(s->s.getStatusOnline()==1).count();
           offline= cameraInfoList.stream().filter(s->s.getStatusOnline()==1).count();
           all= cameraInfoList.size();
        }
        result.put("online",online);
        result.put("offline",offline);
        result.put("all",all);
        result.put("cameraInfoList",cameraInfoList);
        return new ResultObj<>(ResultCode.OK,result);
    }

    /**
     * 获取摄像头表详细信息
     */
    @PostMapping("/queryById")
//	@RequiresPermissions("camerainfo:info")
//    @SysLog(value = "查询", actionType = "4")
    public ResultObj<CameraInfo> info(@RequestBody ReqBodyObj<CameraInfo> param) {
        if (param == null) {
            return ResultObj.error();
        }
        CameraInfo cameraInfo = cameraInfoService.selectById(param.getData().getId());
        return new ResultObj<>(ResultCode.OK,cameraInfo);
    }

    /**
     * 获取摄像头表详细信息
     */
    @PostMapping("/playByid")
//	@RequiresPermissions("camerainfo:info")
//    @SysLog(value = "根据设备id播放视频", actionType = "4")
    @ApiOperation(value = "根据设备id播放视频", notes = "根据设备id播放视频")
    public ResultObj<String> play(@RequestBody ReqBodyObj<CameraInfo> param) {
        if (param == null) {
            return ResultObj.error();
        }
        return new ResultObj<>(ResultCode.OK,cameraInfoService.playCameraByCameraId(param.getData().getId()));
    }

    /**
     * 获取摄像头表详细信息
     */
    @PostMapping("/playSiteId")
//	@RequiresPermissions("camerainfo:info")
//    @SysLog(value = "根据站点id播放视频", actionType = "4")
    @ApiOperation(value = "根据站点id播放视频", notes = "根据站点id播放视频")
    public ResultObj<String> playBySiteId(@RequestBody ReqBodyObj<CameraInfo> param) {
        if (param == null) {
            return ResultObj.error();
        }
        return new ResultObj<>(ResultCode.OK,cameraInfoService.playCameraBySiteId(param.getData().getSiteId()));
    }

    /**
     * 保存摄像头表
     */
    //@SysLog("保存摄像头表")
    @PostMapping("/save")
//    @RequiresPermissions("camerainfo:save")
    public ResultObj<CameraInfo> save(@RequestBody ReqBodyObj<CameraInfo> param) {
        ///ValidatorUtils.validateEntity(param, AddGroup.class);

        cameraInfoService.insert(param.getData());

        return ResultObj.ok();
    }

    /**
     * 修改摄像头表
     */
    @PostMapping("/update")
//    @RequiresPermissions("camerainfo:update")
    public ResultObj<CameraInfo> update(@RequestBody ReqBodyObj<CameraInfo> param) {
       // ValidatorUtils.validateEntity(param, UpdateGroup.class);

        cameraInfoService.updateById(param.getData());

        return ResultObj.ok();
    }

    /**
     * 删除摄像头表
     */
//    @SysLog(value = "删除", actionType = "2")
    //@SysLog("删除摄像头表")
    @PostMapping("/delete")
//    @RequiresPermissions("camerainfo:delete")
    public ResultObj<CameraInfo> delete(@RequestBody List<Integer> param) {
        if (param == null) {
            return ResultObj.error();
        }

        cameraInfoService.deleteBatchIds(param);

        return ResultObj.ok();
    }

//    @SysLog(value = "绑定站点", actionType = "2")
    //@SysLog("删除摄像头表")
    @PostMapping("/bindSite")
//	@RequiresPermissions("camerainfo:delete")
    @ApiOperation(value = "绑定站点", notes = "绑定站点")
    public ResultObj<CameraInfo> bind(@RequestBody ReqBodyObj<CameraInfo> param) {
        if (param == null) {
            return ResultObj.error();
        }

        cameraInfoService.bindSite(param.getData().getId(), param.getData().getSiteId());

        return ResultObj.ok();
    }

//    @SysLog(value = "解绑定站点", actionType = "2")
    //@SysLog("删除摄像头表")
    @PostMapping("/unbindSite")
//	@RequiresPermissions("camerainfo:delete")
    @ApiOperation(value = "解绑定站点", notes = "解绑定站点")
    public ResultObj<CameraInfo> unbind(@RequestBody ReqBodyObj<CameraInfo> param) {
        if (param == null) {
            return ResultObj.error();
        }
        cameraInfoService.unBindSite(param.getData().getId());
        return ResultObj.ok();
    }

//    @SysLog(value = "首页摄像头在线统计", actionType = "2")
    //@SysLog("删除摄像头表")
    @PostMapping("/indexCameraCount")
//	@RequiresPermissions("camerainfo:delete")
    @ApiOperation(value = "首页摄像头在线统计", notes = "首页摄像头在线统计")
    public ResultObj<Map> cameraCount() {
        return new ResultObj<>(ResultCode.OK,cameraInfoService.indexCameraStatistics());
    }
    /** 批量删除摄像头表 */
	/*@SysLog("批量删除摄像头表")
	@PostMapping(BaseUrl.DELETE_BATCH_URL)
	@RequiresPermissions("camerainfo:delete")
	public RespBodyObj<CameraInfo> deleteBatch(@RequestBody List<Integer> param){
		if( param == null ){
			return RespBodyObj.error(HttpCode.BAD_REQUEST);
		}
		
		cameraInfoService.deleteBatchIds(param);
		
		return RespBodyObj.ok();
	}*/
}