123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- package com.iden.bms.controller;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.iden.bms.service.CameraService;
- import com.iden.common.annotation.Permission;
- import com.iden.common.exception.BDException;
- import com.iden.common.logaspect.LogAnnotation;
- import com.iden.common.logaspect.OperateType;
- import com.iden.common.util.PageResult;
- import com.iden.common.util.Result;
- import com.iden.common.util.WebPageUtils;
- import com.iden.common.vo.CameraVO;
- import com.iden.common.vo.PageReqVO;
- import com.iden.common.vo.UserLoginedConvertVO;
- import io.micrometer.core.instrument.util.StringUtils;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiImplicitParam;
- import io.swagger.annotations.ApiImplicitParams;
- import io.swagger.annotations.ApiOperation;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.multipart.MultipartFile;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import java.util.List;
- /**
- * @Author: lilt
- * @Date: 2021/5/26
- * @Desc:
- */
- @RestController
- @Api(value = "CameraController", tags = { "摄像头管理" })
- @Slf4j
- @RequestMapping("/bms/camera")
- @Permission
- public class CameraController {
- @Autowired
- private CameraService cameraService;
- @GetMapping("/countCamera")
- @ApiOperation(value = "当前摄像头个数查询")
- @ApiImplicitParams(value = {
- @ApiImplicitParam(paramType = "query", name = "type", value = "摄像头类型,1摄像机,2抓拍设备",required = true),
- @ApiImplicitParam(paramType = "query", name = "district", value = "所属区域"),
- @ApiImplicitParam(paramType = "query", name = "subdistrict", value = "所属街道"),
- @ApiImplicitParam(paramType = "query", name = "cameraId", value = "摄像头ID"),
- @ApiImplicitParam(paramType = "query", name = "name", value = "摄像头名称")
- })
- public Result<Integer> countCamera(HttpServletRequest request, @RequestHeader(value = "token") String token,
- @RequestParam(value = "type", required = true) String type,
- @RequestParam(value = "district", required = false) String district,
- @RequestParam(value = "subdistrict", required = false) String subdistrict,
- @RequestParam(value = "cameraId", required = false) Long cameraId,
- @RequestParam(value = "name", required = false) String name
- ){
- try {
- UserLoginedConvertVO loginUser = WebPageUtils.getCurrentLoginedUser(request);
- Integer count = this.cameraService.countCamera(type,district,subdistrict,cameraId,name,loginUser );
- return Result.success("查询成功!",count);
- }catch (BDException e) {
- log.error("当前摄像头个数查询-出现异常",e);
- return PageResult.error(e.getMessage());
- } catch (Exception e) {
- log.error("摄像头管理: 当前摄像头个数出现异常",e);
- return PageResult.error( "获取数据失败");
- }
- }
- @GetMapping("/listCamera")
- @ApiOperation(value = "摄像头列表分页 ")
- @ApiImplicitParams(value = {
- @ApiImplicitParam(paramType = "query", name = "type", value = "摄像头类型,1摄像机,2抓拍设备",required = true),
- @ApiImplicitParam(paramType = "query", name = "district", value = "所属区域"),
- @ApiImplicitParam(paramType = "query", name = "subdistrict", value = "所属街道"),
- @ApiImplicitParam(paramType = "query", name = "cameraId", value = "摄像头ID"),
- @ApiImplicitParam(paramType = "query", name = "name", value = "摄像头名称")
- })
- public PageResult<List<CameraVO>> listCamera(HttpServletRequest request, @RequestHeader(value = "token") String token,
- @RequestParam(value = "type", required = true) String type,
- @RequestParam(value = "district", required = false) String district,
- @RequestParam(value = "subdistrict", required = false) String subdistrict,
- @RequestParam(value = "cameraId", required = false) Long cameraId,
- @RequestParam(value = "name", required = false) String name,
- PageReqVO pageReqVo){
- try {
- UserLoginedConvertVO loginUser = WebPageUtils.getCurrentLoginedUser(request);
- IPage<CameraVO> pageResponse = this.cameraService.listCamera(type,district,subdistrict,cameraId,name,loginUser ,pageReqVo);
- return PageResult.success(pageResponse.getRecords(),pageResponse.getCurrent(),pageResponse.getSize(),pageResponse.getTotal());
- }catch (BDException e) {
- log.error("摄像头列表查询-分页列表出现异常",e);
- return PageResult.error(e.getMessage());
- } catch (Exception e) {
- log.error("摄像头管理: 摄像头列表查询出现异常",e);
- return PageResult.error( "获取列表失败");
- }
- }
- @PostMapping("/addCamera")
- @ApiOperation(value = "新增摄像头")
- @LogAnnotation(
- type = OperateType.ADD,
- moduleName = "新增摄像头",
- description = "新增摄像头"
- )
- public Result<Object> addCamera(HttpServletRequest request,@RequestHeader("token") String token,
- @RequestBody CameraVO vo){
- try {
- if(StringUtils.isEmpty(vo.getType())){
- return Result.error("类型不能为空!");
- }
- UserLoginedConvertVO loginUser = WebPageUtils.getCurrentLoginedUser(request);
- int flag = this.cameraService.createCamera(vo,loginUser);
- if (flag == 1) {
- return Result.error("名称已存在!");
- } if (flag == 2) {
- return Result.error("编码已存在!");
- } else if (flag == 0) {
- return Result.success("新增成功!");
- } else {
- return Result.error("新增失败!");
- }
- }catch (BDException e) {
- log.error("新增摄像头-出现异常",e);
- return Result.error(e.getMessage());
- } catch (Exception e) {
- log.error("摄像头管理: 新增摄像头出现异常",e);
- return Result.error("新增失败!");
- }
- }
- @PostMapping("/updateCamera")
- @ApiOperation(value = "修改摄像头")
- @LogAnnotation(
- type = OperateType.MODIFY,
- moduleName = "修改摄像头",
- description = "修改摄像头"
- )
- public Result<Object> updateCamera(HttpServletRequest request,@RequestHeader("token") String token,
- @RequestBody CameraVO vo){
- try {
- this.cameraService.updateCamera(vo);
- return Result.success("修改成功!");
- }catch (BDException e) {
- log.error("修改摄像头-出现异常",e);
- return Result.error(e.getMessage());
- } catch (Exception e) {
- log.error("摄像头管理: 修改摄像头出现异常",e);
- return Result.error("修改失败!");
- }
- }
- /**
- * 导出列表
- * @param
- * @return
- */
- @ApiOperation(value = "导出Excel")
- @ApiImplicitParams(value = {
- @ApiImplicitParam(paramType = "query", name = "type", value = "摄像头类型,1摄像机,2抓拍设备",required = true),
- @ApiImplicitParam(paramType = "query", name = "district", value = "所属区域"),
- @ApiImplicitParam(paramType = "query", name = "subdistrict", value = "所属街道"),
- @ApiImplicitParam(paramType = "query", name = "cameraId", value = "摄像头ID"),
- @ApiImplicitParam(paramType = "query", name = "name", value = "摄像头名称")
- })
- @GetMapping({"/exportToExcel"})
- @LogAnnotation(
- type = OperateType.EXPORT,
- moduleName = "导出摄像头列表",
- description = "导出摄像头列表"
- )
- public void exportToExcel(HttpServletRequest request,@RequestHeader(name = "token", required = true) String token,
- @RequestParam(value = "type", required = true) String type,
- @RequestParam(value = "district", required = false) String district,
- @RequestParam(value = "subdistrict", required = false) String subdistrict,
- @RequestParam(value = "cameraId", required = false) Long cameraId,
- @RequestParam(value = "name", required = false) String name,
- HttpServletResponse response) {
- try {
- UserLoginedConvertVO loginUser = WebPageUtils.getCurrentLoginedUser(request);
- this.cameraService.exportToExcel(type,district,subdistrict,cameraId,name,loginUser,response);
- } catch (BDException e) {
- log.error("导出摄像头列表出现异常",e);
- } catch (Exception e) {
- log.error("摄像头管理: 导出摄像头列表出现异常",e);
- }
- }
- /**
- * 下载模板
- * @param
- * @return
- */
- @ApiOperation(value = "下载模板")
- @GetMapping({"/downloadFormwork"})
- @LogAnnotation(
- type = OperateType.EXPORT,
- moduleName = "下载模板",
- description = "下载模板"
- )
- public void downloadFormwork(HttpServletRequest request,@RequestHeader(name = "token", required = true) String token,
- HttpServletResponse response) {
- try {
- UserLoginedConvertVO loginUser = WebPageUtils.getCurrentLoginedUser(request);
- this.cameraService.downloadFormwork(loginUser,response);
- } catch (BDException e) {
- log.error("下载模板出现异常",e);
- } catch (Exception e) {
- log.error("小区管理: 下载模板出现异常",e);
- }
- }
- @ApiOperation(value = "导入Excel")
- @ApiImplicitParams(value = {
- @ApiImplicitParam(paramType = "query", name = "type", value = "摄像头类型,1摄像机,2抓拍设备"),
- })
- @PostMapping(value = "/importWithExcel", headers = "content-type=multipart/form-data")
- public Result<Object> importWithExcel( HttpServletRequest request, @RequestHeader(value = "token") String token,
- @RequestParam(value = "type", required = true) String type,
- @RequestParam(value = "file") MultipartFile multipartFile) {
- try {
- boolean flag = cameraService.importWithExcel(type,multipartFile);
- if(flag){
- return Result.success("导入成功!");
- } else {
- return Result.error("导入失败");
- }
- } catch (BDException e) {
- log.error("导入摄像头列表出现异常",e);
- return Result.error(e.getMessage());
- } catch (Exception e) {
- log.error("摄像头管理: 导入摄像头列表出现异常",e);
- return Result.error("导入摄像头失败!");
- }
- }
- @GetMapping("/getCameraInfo/{id}")
- @ApiOperation(value = "摄像头详情")
- public Result<CameraVO> getCameraInfo(HttpServletRequest request, @RequestHeader("token") String token, @PathVariable("id") Long id){
- CameraVO info = this.cameraService.getCameraById(id);
- return Result.success("查询成功!",info);
- }
- @PostMapping("/deleteCamera/{id}")
- @ApiOperation(value = "删除摄像头")
- @LogAnnotation(
- type = OperateType.REMOVE,
- moduleName = "删除摄像头",
- description = "删除摄像头"
- )
- public Result<Object> deleteCamera(HttpServletRequest request,@RequestHeader("token") String token,
- @PathVariable("id") Long id){
- try {
- if( this.cameraService.deleteById(id)){
- return Result.success("删除成功!");
- } else {
- return Result.error("摄像头被引用,不能删除!");
- }
- } catch (Exception e) {
- log.error("摄像头管理: 删除出现异常",e);
- return Result.error("删除失败!");
- }
- }
- }
|