CameraController.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. package com.iden.bms.controller;
  2. import com.baomidou.mybatisplus.core.metadata.IPage;
  3. import com.iden.bms.service.CameraService;
  4. import com.iden.common.annotation.Permission;
  5. import com.iden.common.exception.BDException;
  6. import com.iden.common.logaspect.LogAnnotation;
  7. import com.iden.common.logaspect.OperateType;
  8. import com.iden.common.util.PageResult;
  9. import com.iden.common.util.Result;
  10. import com.iden.common.util.WebPageUtils;
  11. import com.iden.common.vo.CameraVO;
  12. import com.iden.common.vo.PageReqVO;
  13. import com.iden.common.vo.UserLoginedConvertVO;
  14. import io.micrometer.core.instrument.util.StringUtils;
  15. import io.swagger.annotations.Api;
  16. import io.swagger.annotations.ApiImplicitParam;
  17. import io.swagger.annotations.ApiImplicitParams;
  18. import io.swagger.annotations.ApiOperation;
  19. import lombok.extern.slf4j.Slf4j;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.web.bind.annotation.*;
  22. import org.springframework.web.multipart.MultipartFile;
  23. import javax.servlet.http.HttpServletRequest;
  24. import javax.servlet.http.HttpServletResponse;
  25. import java.util.List;
  26. /**
  27. * @Author: lilt
  28. * @Date: 2021/5/26
  29. * @Desc:
  30. */
  31. @RestController
  32. @Api(value = "CameraController", tags = { "摄像头管理" })
  33. @Slf4j
  34. @RequestMapping("/bms/camera")
  35. @Permission
  36. public class CameraController {
  37. @Autowired
  38. private CameraService cameraService;
  39. @GetMapping("/countCamera")
  40. @ApiOperation(value = "当前摄像头个数查询")
  41. @ApiImplicitParams(value = {
  42. @ApiImplicitParam(paramType = "query", name = "type", value = "摄像头类型,1摄像机,2抓拍设备",required = true),
  43. @ApiImplicitParam(paramType = "query", name = "district", value = "所属区域"),
  44. @ApiImplicitParam(paramType = "query", name = "subdistrict", value = "所属街道"),
  45. @ApiImplicitParam(paramType = "query", name = "cameraId", value = "摄像头ID"),
  46. @ApiImplicitParam(paramType = "query", name = "name", value = "摄像头名称")
  47. })
  48. public Result<Integer> countCamera(HttpServletRequest request, @RequestHeader(value = "token") String token,
  49. @RequestParam(value = "type", required = true) String type,
  50. @RequestParam(value = "district", required = false) String district,
  51. @RequestParam(value = "subdistrict", required = false) String subdistrict,
  52. @RequestParam(value = "cameraId", required = false) Long cameraId,
  53. @RequestParam(value = "name", required = false) String name
  54. ){
  55. try {
  56. UserLoginedConvertVO loginUser = WebPageUtils.getCurrentLoginedUser(request);
  57. Integer count = this.cameraService.countCamera(type,district,subdistrict,cameraId,name,loginUser );
  58. return Result.success("查询成功!",count);
  59. }catch (BDException e) {
  60. log.error("当前摄像头个数查询-出现异常",e);
  61. return PageResult.error(e.getMessage());
  62. } catch (Exception e) {
  63. log.error("摄像头管理: 当前摄像头个数出现异常",e);
  64. return PageResult.error( "获取数据失败");
  65. }
  66. }
  67. @GetMapping("/listCamera")
  68. @ApiOperation(value = "摄像头列表分页 ")
  69. @ApiImplicitParams(value = {
  70. @ApiImplicitParam(paramType = "query", name = "type", value = "摄像头类型,1摄像机,2抓拍设备",required = true),
  71. @ApiImplicitParam(paramType = "query", name = "district", value = "所属区域"),
  72. @ApiImplicitParam(paramType = "query", name = "subdistrict", value = "所属街道"),
  73. @ApiImplicitParam(paramType = "query", name = "cameraId", value = "摄像头ID"),
  74. @ApiImplicitParam(paramType = "query", name = "name", value = "摄像头名称")
  75. })
  76. public PageResult<List<CameraVO>> listCamera(HttpServletRequest request, @RequestHeader(value = "token") String token,
  77. @RequestParam(value = "type", required = true) String type,
  78. @RequestParam(value = "district", required = false) String district,
  79. @RequestParam(value = "subdistrict", required = false) String subdistrict,
  80. @RequestParam(value = "cameraId", required = false) Long cameraId,
  81. @RequestParam(value = "name", required = false) String name,
  82. PageReqVO pageReqVo){
  83. try {
  84. UserLoginedConvertVO loginUser = WebPageUtils.getCurrentLoginedUser(request);
  85. IPage<CameraVO> pageResponse = this.cameraService.listCamera(type,district,subdistrict,cameraId,name,loginUser ,pageReqVo);
  86. return PageResult.success(pageResponse.getRecords(),pageResponse.getCurrent(),pageResponse.getSize(),pageResponse.getTotal());
  87. }catch (BDException e) {
  88. log.error("摄像头列表查询-分页列表出现异常",e);
  89. return PageResult.error(e.getMessage());
  90. } catch (Exception e) {
  91. log.error("摄像头管理: 摄像头列表查询出现异常",e);
  92. return PageResult.error( "获取列表失败");
  93. }
  94. }
  95. @PostMapping("/addCamera")
  96. @ApiOperation(value = "新增摄像头")
  97. @LogAnnotation(
  98. type = OperateType.ADD,
  99. moduleName = "新增摄像头",
  100. description = "新增摄像头"
  101. )
  102. public Result<Object> addCamera(HttpServletRequest request,@RequestHeader("token") String token,
  103. @RequestBody CameraVO vo){
  104. try {
  105. if(StringUtils.isEmpty(vo.getType())){
  106. return Result.error("类型不能为空!");
  107. }
  108. UserLoginedConvertVO loginUser = WebPageUtils.getCurrentLoginedUser(request);
  109. int flag = this.cameraService.createCamera(vo,loginUser);
  110. if (flag == 1) {
  111. return Result.error("名称已存在!");
  112. } if (flag == 2) {
  113. return Result.error("编码已存在!");
  114. } else if (flag == 0) {
  115. return Result.success("新增成功!");
  116. } else {
  117. return Result.error("新增失败!");
  118. }
  119. }catch (BDException e) {
  120. log.error("新增摄像头-出现异常",e);
  121. return Result.error(e.getMessage());
  122. } catch (Exception e) {
  123. log.error("摄像头管理: 新增摄像头出现异常",e);
  124. return Result.error("新增失败!");
  125. }
  126. }
  127. @PostMapping("/updateCamera")
  128. @ApiOperation(value = "修改摄像头")
  129. @LogAnnotation(
  130. type = OperateType.MODIFY,
  131. moduleName = "修改摄像头",
  132. description = "修改摄像头"
  133. )
  134. public Result<Object> updateCamera(HttpServletRequest request,@RequestHeader("token") String token,
  135. @RequestBody CameraVO vo){
  136. try {
  137. this.cameraService.updateCamera(vo);
  138. return Result.success("修改成功!");
  139. }catch (BDException e) {
  140. log.error("修改摄像头-出现异常",e);
  141. return Result.error(e.getMessage());
  142. } catch (Exception e) {
  143. log.error("摄像头管理: 修改摄像头出现异常",e);
  144. return Result.error("修改失败!");
  145. }
  146. }
  147. /**
  148. * 导出列表
  149. * @param
  150. * @return
  151. */
  152. @ApiOperation(value = "导出Excel")
  153. @ApiImplicitParams(value = {
  154. @ApiImplicitParam(paramType = "query", name = "type", value = "摄像头类型,1摄像机,2抓拍设备",required = true),
  155. @ApiImplicitParam(paramType = "query", name = "district", value = "所属区域"),
  156. @ApiImplicitParam(paramType = "query", name = "subdistrict", value = "所属街道"),
  157. @ApiImplicitParam(paramType = "query", name = "cameraId", value = "摄像头ID"),
  158. @ApiImplicitParam(paramType = "query", name = "name", value = "摄像头名称")
  159. })
  160. @GetMapping({"/exportToExcel"})
  161. @LogAnnotation(
  162. type = OperateType.EXPORT,
  163. moduleName = "导出摄像头列表",
  164. description = "导出摄像头列表"
  165. )
  166. public void exportToExcel(HttpServletRequest request,@RequestHeader(name = "token", required = true) String token,
  167. @RequestParam(value = "type", required = true) String type,
  168. @RequestParam(value = "district", required = false) String district,
  169. @RequestParam(value = "subdistrict", required = false) String subdistrict,
  170. @RequestParam(value = "cameraId", required = false) Long cameraId,
  171. @RequestParam(value = "name", required = false) String name,
  172. HttpServletResponse response) {
  173. try {
  174. UserLoginedConvertVO loginUser = WebPageUtils.getCurrentLoginedUser(request);
  175. this.cameraService.exportToExcel(type,district,subdistrict,cameraId,name,loginUser,response);
  176. } catch (BDException e) {
  177. log.error("导出摄像头列表出现异常",e);
  178. } catch (Exception e) {
  179. log.error("摄像头管理: 导出摄像头列表出现异常",e);
  180. }
  181. }
  182. /**
  183. * 下载模板
  184. * @param
  185. * @return
  186. */
  187. @ApiOperation(value = "下载模板")
  188. @GetMapping({"/downloadFormwork"})
  189. @LogAnnotation(
  190. type = OperateType.EXPORT,
  191. moduleName = "下载模板",
  192. description = "下载模板"
  193. )
  194. public void downloadFormwork(HttpServletRequest request,@RequestHeader(name = "token", required = true) String token,
  195. HttpServletResponse response) {
  196. try {
  197. UserLoginedConvertVO loginUser = WebPageUtils.getCurrentLoginedUser(request);
  198. this.cameraService.downloadFormwork(loginUser,response);
  199. } catch (BDException e) {
  200. log.error("下载模板出现异常",e);
  201. } catch (Exception e) {
  202. log.error("小区管理: 下载模板出现异常",e);
  203. }
  204. }
  205. @ApiOperation(value = "导入Excel")
  206. @ApiImplicitParams(value = {
  207. @ApiImplicitParam(paramType = "query", name = "type", value = "摄像头类型,1摄像机,2抓拍设备"),
  208. })
  209. @PostMapping(value = "/importWithExcel", headers = "content-type=multipart/form-data")
  210. public Result<Object> importWithExcel( HttpServletRequest request, @RequestHeader(value = "token") String token,
  211. @RequestParam(value = "type", required = true) String type,
  212. @RequestParam(value = "file") MultipartFile multipartFile) {
  213. try {
  214. boolean flag = cameraService.importWithExcel(type,multipartFile);
  215. if(flag){
  216. return Result.success("导入成功!");
  217. } else {
  218. return Result.error("导入失败");
  219. }
  220. } catch (BDException e) {
  221. log.error("导入摄像头列表出现异常",e);
  222. return Result.error(e.getMessage());
  223. } catch (Exception e) {
  224. log.error("摄像头管理: 导入摄像头列表出现异常",e);
  225. return Result.error("导入摄像头失败!");
  226. }
  227. }
  228. @GetMapping("/getCameraInfo/{id}")
  229. @ApiOperation(value = "摄像头详情")
  230. public Result<CameraVO> getCameraInfo(HttpServletRequest request, @RequestHeader("token") String token, @PathVariable("id") Long id){
  231. CameraVO info = this.cameraService.getCameraById(id);
  232. return Result.success("查询成功!",info);
  233. }
  234. @PostMapping("/deleteCamera/{id}")
  235. @ApiOperation(value = "删除摄像头")
  236. @LogAnnotation(
  237. type = OperateType.REMOVE,
  238. moduleName = "删除摄像头",
  239. description = "删除摄像头"
  240. )
  241. public Result<Object> deleteCamera(HttpServletRequest request,@RequestHeader("token") String token,
  242. @PathVariable("id") Long id){
  243. try {
  244. if( this.cameraService.deleteById(id)){
  245. return Result.success("删除成功!");
  246. } else {
  247. return Result.error("摄像头被引用,不能删除!");
  248. }
  249. } catch (Exception e) {
  250. log.error("摄像头管理: 删除出现异常",e);
  251. return Result.error("删除失败!");
  252. }
  253. }
  254. }