CameraService.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package com.iden.bms.service;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.core.collection.CollUtil;
  4. import cn.hutool.core.util.StrUtil;
  5. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  6. import com.baomidou.mybatisplus.core.metadata.IPage;
  7. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  8. import com.iden.common.entity.IdenCamera;
  9. import com.iden.common.enums.CameraTypeEnum;
  10. import com.iden.common.enums.ConnectStatusEnum;
  11. import com.iden.common.service.IdenCameraService;
  12. import com.iden.common.util.MyBeanUtils;
  13. import com.iden.common.vo.CameraVO;
  14. import com.iden.common.vo.PageReqVO;
  15. import com.iden.common.vo.UserLoginedConvertVO;
  16. import org.springframework.beans.BeanUtils;
  17. import org.springframework.stereotype.Service;
  18. import org.springframework.transaction.annotation.Transactional;
  19. import javax.annotation.Resource;
  20. import java.util.ArrayList;
  21. import java.util.Date;
  22. import java.util.List;
  23. /**
  24. *
  25. * @author makejava
  26. * @since 2021-05-21 00:08:38
  27. */
  28. @Service
  29. public class CameraService {
  30. @Resource
  31. private IdenCameraService idenCameraService;
  32. public Integer countCamera(String type, String district, String subdistrict, Long communityId, String name, UserLoginedConvertVO loginUser) {
  33. QueryWrapper<IdenCamera> queryWrapper = new QueryWrapper<>();
  34. queryWrapper.lambda().like(StrUtil.isNotEmpty(name),IdenCamera::getName,name)
  35. .eq(StrUtil.isNotEmpty(district),IdenCamera::getDistrict,district)
  36. .eq(StrUtil.isNotEmpty(subdistrict),IdenCamera::getSubdistrict,subdistrict)
  37. .eq(communityId != null,IdenCamera::getCommunityId,communityId)
  38. .eq(StrUtil.isNotEmpty(type),IdenCamera::getType,type);
  39. return this.idenCameraService.count(queryWrapper);
  40. }
  41. /**
  42. * 查询摄像头列表
  43. * @return
  44. */
  45. public IPage<CameraVO> listCamera(String type, String district, String subdistrict, Long communityId, String name, UserLoginedConvertVO loginUser, PageReqVO pageReqVo) {
  46. IPage<IdenCamera> page = new Page<>(pageReqVo.getCurrent(), pageReqVo.getPageSize());
  47. QueryWrapper<IdenCamera> queryWrapper = new QueryWrapper<>();
  48. queryWrapper.lambda().like(StrUtil.isNotEmpty(name),IdenCamera::getName,name)
  49. .eq(StrUtil.isNotEmpty(district),IdenCamera::getDistrict,district)
  50. .eq(StrUtil.isNotEmpty(subdistrict),IdenCamera::getSubdistrict,subdistrict)
  51. .eq(communityId != null,IdenCamera::getCommunityId,communityId)
  52. .eq(StrUtil.isNotEmpty(type),IdenCamera::getType,type)
  53. .orderByAsc(IdenCamera::getCode);
  54. IPage<IdenCamera> pageRes = this.idenCameraService.page(page, queryWrapper);
  55. IPage<CameraVO> results = new Page<>(pageRes.getCurrent(),pageRes.getSize(),pageRes.getTotal());
  56. if(CollUtil.isNotEmpty(pageRes.getRecords())){
  57. List<CameraVO> list = new ArrayList<>();
  58. pageRes.getRecords().forEach(item -> {
  59. CameraVO resVO = new CameraVO();
  60. BeanUtils.copyProperties(item,resVO);
  61. resVO.setStatusName(ConnectStatusEnum.getValueToName(resVO.getCode()));
  62. resVO.setTypeName(CameraTypeEnum.getValueToName(resVO.getType()));
  63. list.add(resVO);
  64. });
  65. results.setRecords(list);
  66. }
  67. return results;
  68. }
  69. /**
  70. * 删除摄像头
  71. * @param id
  72. * @return
  73. */
  74. public boolean deleteById(Long id){
  75. return this.idenCameraService.removeById(id);
  76. }
  77. /**
  78. * 详情
  79. * @param id
  80. * @return
  81. */
  82. public CameraVO getCameraById(Long id){
  83. IdenCamera idenCamera = this.idenCameraService.getById(id);
  84. if (idenCamera!=null){
  85. CameraVO resVO = new CameraVO();
  86. BeanUtil.copyProperties(idenCamera,resVO);
  87. resVO.setStatusName(ConnectStatusEnum.getValueToName(resVO.getCode()));
  88. resVO.setTypeName(CameraTypeEnum.getValueToName(resVO.getType()));
  89. return resVO;
  90. }
  91. return null;
  92. }
  93. /**
  94. * 保存摄像头
  95. * @param vo
  96. */
  97. @Transactional(rollbackFor = Exception.class)
  98. public int createCamera(CameraVO vo, UserLoginedConvertVO loginUser){
  99. QueryWrapper<IdenCamera> queryWrapper = new QueryWrapper<>();
  100. queryWrapper.lambda().eq(IdenCamera::getName,vo.getName());
  101. if(idenCameraService.count(queryWrapper) > 0){
  102. return 1;
  103. }
  104. QueryWrapper<IdenCamera> queryWrapper2 = new QueryWrapper<>();
  105. queryWrapper2.lambda().eq(IdenCamera::getCode,vo.getCode());
  106. if(idenCameraService.count(queryWrapper2) > 0){
  107. return 2;
  108. }
  109. //保存摄像头
  110. IdenCamera idenCamera = new IdenCamera();
  111. BeanUtil.copyProperties(vo,idenCamera);
  112. idenCamera.setCreateTime(new Date());
  113. this.idenCameraService.save(idenCamera);
  114. return 0;
  115. }
  116. /**
  117. * 修改摄像头
  118. * @param vo
  119. */
  120. @Transactional(rollbackFor = Exception.class)
  121. public void updateCamera(CameraVO vo){
  122. //保存摄像头
  123. IdenCamera idenCamera = this.idenCameraService.getById(vo.getId());
  124. MyBeanUtils.copyProperties(vo,idenCamera);
  125. idenCamera.setModifyTime(new Date());
  126. this.idenCameraService.updateById(idenCamera);
  127. }
  128. }