BigScreenServiceImpl.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. package com.care.bigscreen.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.care.bigscreen.entity.StOrganization;
  4. import com.care.bigscreen.entity.StStation;
  5. import com.care.bigscreen.mapper.BigSreenMapper;
  6. import com.care.bigscreen.mapper.StOrganizationMapper;
  7. import com.care.bigscreen.mapper.StStationMapper;
  8. import com.care.bigscreen.service.BigScreenService;
  9. import com.care.bigscreen.vo.*;
  10. import com.care.bigscreen.websocket.BigScreenWebSocketEndpoint;
  11. import com.care.common.service.CareStationService;
  12. import com.care.common.util.DomainEquals;
  13. import com.care.common.vo.PageResVO;
  14. import com.care.common.util.PageUtil;
  15. import org.apache.logging.log4j.LogManager;
  16. import org.apache.logging.log4j.Logger;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.stereotype.Service;
  19. import java.util.Date;
  20. import java.util.List;
  21. /**
  22. * @author stw
  23. * @version 1.0
  24. * @description 站点统计表接口实现类
  25. * @date 2021/05/20/19:41
  26. */
  27. @Service
  28. public class BigScreenServiceImpl implements BigScreenService {
  29. private static final Logger logger = LogManager.getLogger(BigScreenServiceImpl.class);
  30. @Autowired
  31. private BigSreenMapper bigSreenMapper;
  32. @Autowired
  33. private CareStationService careStationService;
  34. @Autowired
  35. private StStationMapper stStationMapper;
  36. @Autowired
  37. private StOrganizationMapper stOrganizationMapper;
  38. /**
  39. * 运营商大屏统计查询
  40. * @return 搜索符合条件的大屏统计数据
  41. */
  42. @Override
  43. public OpBigScreenStatisticsVO selectBigScreenStatisticsByOp(Long stationId){
  44. OpBigScreenStatisticsVO opBigScreenStatisticsVO = bigSreenMapper.selectBigScreenStatisticsByOp(stationId);
  45. BigScreenOrgVO bigScreenOrgVO = null;
  46. if(stationId == null){ //运营商大屏
  47. bigScreenOrgVO = bigSreenMapper.selectBigScreenOrgStatistics(null);
  48. } else { //站点查询
  49. bigScreenOrgVO = bigSreenMapper.selectBigScreenOrgStatistics(careStationService.getById(stationId).getOrgId());
  50. }
  51. opBigScreenStatisticsVO.setSeatsAmount(bigScreenOrgVO.getSeatsAmount());
  52. opBigScreenStatisticsVO.setSeatsOnlineDuration(bigScreenOrgVO.getSeatsOnlineDuration());
  53. return opBigScreenStatisticsVO;
  54. }
  55. /**
  56. * 运营商大屏统计查询
  57. * @return 根据经纬度范围搜索符合条件的大屏统计数据
  58. */
  59. @Override
  60. public OpBigScreenStatisticsVO selectOpBigScreenStatisticsByLongitudeLatitude(String longitudeLeftUp, String latitudeLeftUp, String longitudeRightDown, String latitudeRightDown) {
  61. return bigSreenMapper.selectOpBigScreenStatisticsByLongitudeLatitude(longitudeLeftUp,latitudeLeftUp,longitudeRightDown,latitudeRightDown);
  62. }
  63. /**
  64. * 机构大屏统计查询
  65. * @return 搜索符合条件的大屏统计数据
  66. */
  67. @Override
  68. public OrgBigScreenStatisticsVO selectBigScreenStatisticsByOrg(Long stationId, Long orgId){
  69. OrgBigScreenStatisticsVO orgBigScreenStatisticsVO = bigSreenMapper.selectBigScreenStatisticsByOrg(stationId,orgId);
  70. BigScreenOrgVO bigScreenOrgVO = null;
  71. if(stationId == null){ //机构大屏
  72. bigScreenOrgVO = bigSreenMapper.selectBigScreenOrgStatistics(orgId);
  73. } else { //站点查询
  74. bigScreenOrgVO = bigSreenMapper.selectBigScreenOrgStatistics(careStationService.getById(stationId).getOrgId());
  75. }
  76. orgBigScreenStatisticsVO.setStationAmount(bigScreenOrgVO.getStationAmount());
  77. return orgBigScreenStatisticsVO;
  78. }
  79. /**
  80. * 机构大屏统计查询
  81. * @return 根据经纬度范围搜索符合条件的大屏统计数据
  82. */
  83. @Override
  84. public OrgBigScreenStatisticsVO selectOrgBigScreenStatisticsByLongitudeLatitude(String longitudeLeftUp, String latitudeLeftUp, String longitudeRightDown, String latitudeRightDown, Long orgId) {
  85. return bigSreenMapper.selectOrgBigScreenStatisticsByLongitudeLatitude(longitudeLeftUp,latitudeLeftUp,longitudeRightDown,latitudeRightDown,orgId);
  86. }
  87. /**
  88. * 站点列表查询
  89. */
  90. @Override
  91. public List<BigScreenStationVO> selectBigScreenStationList(Long orgId) {
  92. return bigSreenMapper.selectBigScreenStationList(orgId);
  93. }
  94. /**
  95. * 服务站大屏的站点统计查询
  96. * @return 搜索符合条件的大屏统计数据
  97. */
  98. @Override
  99. public StationBigScreenStatisticsVO selectStationBigScreenStatisticsByStation(Long stationId){
  100. return bigSreenMapper.selectStationBigScreenStatisticsByStation(stationId);
  101. }
  102. /**
  103. * 告警用户列表查询
  104. */
  105. @Override
  106. public List<BigScreenAlarmOlderVO> selectBigScreenAlarmOlderList(Long stationId, String olderName){
  107. return bigSreenMapper.selectBigScreenAlarmOlderList(stationId, olderName);
  108. }
  109. /**
  110. * 服务站大屏的被监控人详细查询
  111. */
  112. @Override
  113. public BigScreenOlderDetailVO selectStationBigScreenOlderDetail(Long olderId) {
  114. return bigSreenMapper.selectStationBigScreenOlderDetail(olderId);
  115. }
  116. /**
  117. * 服务站大屏的安全事件总计查询
  118. * @return 搜索符合条件的大屏统计数据
  119. */
  120. @Override
  121. public BigScreenEventTotalVO selectStationBigScreenEventTotal(Long stationId){
  122. return bigSreenMapper.selectStationBigScreenEventTotal(stationId);
  123. }
  124. /**
  125. * 机构大屏或服务站大屏的实时安全事件列表查询
  126. */
  127. @Override
  128. public List<BigScreenEventVO> selectBigScreenRtEventList(Long orgId ,Long stationId) {
  129. return bigSreenMapper.selectBigScreenRtEventList(orgId, stationId);
  130. }
  131. /**
  132. * 机构大屏的设备列表查询
  133. */
  134. @Override
  135. public List<BigScreenDeviceVO> selectOrgBigScreenDeviceList(Long orgId, Long stationId,String status) {
  136. return bigSreenMapper.selectOrgBigScreenDeviceList(orgId, stationId,status);
  137. }
  138. /**
  139. * 服务站大屏的已完成安全事件列表分页查询
  140. */
  141. @Override
  142. public PageUtil<BigScreenEventVO> selectBigScreenHisEventListByPage(Long stationId, PageResVO page) {
  143. //1、创建一个分页工具对象(然后对分页数据进行整理)
  144. PageUtil<BigScreenEventVO> pageUtil = new PageUtil<>();
  145. //2、更新当前页面大小
  146. pageUtil.setPageSize(page.getPageSize());
  147. //3、获取多条件查询总记录数
  148. pageUtil.setTotal(bigSreenMapper.selectBigScreenHisEventListByCount(stationId));
  149. //4、更新当前页码(此时页码将不会再发生越界问题)
  150. pageUtil.setCurrent(page.getCurrent());
  151. List<BigScreenEventVO> bigScreenEventVOList = bigSreenMapper.selectBigScreenHisEventListByPage(stationId, pageUtil);
  152. pageUtil.setListT(bigScreenEventVOList);
  153. return pageUtil;
  154. }
  155. /**
  156. * 服务站大屏的用户卡片总计查询
  157. * @return 搜索符合条件的大屏统计数据
  158. */
  159. @Override
  160. public BigScreenOlderCardTotalVO selectStationBigScreenOlderCardTotal(Long stationId,String olderName){
  161. return bigSreenMapper.selectStationBigScreenOlderCardTotal(stationId,olderName);
  162. }
  163. /**
  164. * 服务站大屏的用户卡片列表分页查询
  165. */
  166. @Override
  167. public PageUtil<BigScreenOlderDetailVO> selectBigScreenOlderCardListByPage(Long stationId, String olderName,String isAlarm, PageResVO page) {
  168. //1、创建一个分页工具对象(然后对分页数据进行整理)
  169. PageUtil<BigScreenOlderDetailVO> pageUtil = new PageUtil<>();
  170. //2、更新当前页面大小
  171. pageUtil.setPageSize(page.getPageSize());
  172. //3、获取多条件查询总记录数
  173. pageUtil.setTotal(bigSreenMapper.selectBigScreenOlderCardListByCount(stationId,olderName,isAlarm));
  174. //4、更新当前页码(此时页码将不会再发生越界问题)
  175. pageUtil.setCurrent(page.getCurrent());
  176. List<BigScreenOlderDetailVO> bigScreenOlderDetailVOList = bigSreenMapper.selectBigScreenOlderCardListByPage(stationId,olderName,isAlarm, pageUtil);
  177. pageUtil.setListT(bigScreenOlderDetailVOList);
  178. return pageUtil;
  179. }
  180. /**
  181. * 调用websocket推送实时事件标识给前端
  182. */
  183. @Override
  184. public void pushRtEventFlag(String stationId) {
  185. //触发统计
  186. exeStatistics();
  187. BigScreenWebSocketEndpoint.sendMsgToFront(stationId,"rt_event_happen");
  188. }
  189. /**
  190. * 进行统计
  191. */
  192. @Override
  193. public void exeStatistics(){
  194. try {
  195. List<StStation> stStationList = stStationMapper.selectStStationList();
  196. for(StStation stStation : stStationList) {
  197. QueryWrapper<StStation> queryWrapper = new QueryWrapper<>();
  198. //查询表中是否存在
  199. queryWrapper.lambda().eq(StStation::getStationId, stStation.getStationId());
  200. StStation stStationDb = stStationMapper.selectOne(queryWrapper);
  201. if (stStationDb == null) { //插入
  202. Date now = new Date();
  203. stStation.setCreateTime(now);
  204. stStation.setModifyTime(now);
  205. stStationMapper.insert(stStation);
  206. } else { //更新
  207. stStation.setCreateTime(stStationDb.getCreateTime());
  208. stStation.setModifyTime(stStationDb.getModifyTime());
  209. stStation.setId(stStationDb.getId());
  210. //其余属性不一样的就更新
  211. if (!DomainEquals.domainEquals(stStation,stStationDb)){
  212. Date now = new Date();
  213. stStation.setModifyTime(now);
  214. stStationMapper.updateById(stStation);
  215. }
  216. }
  217. }
  218. List<StOrganization> stOrganizationList = stOrganizationMapper.selectStOrganizationList();
  219. for(StOrganization stOrganization : stOrganizationList) {
  220. QueryWrapper<StOrganization> queryWrapper = new QueryWrapper<>();
  221. //查询表中是否存在
  222. queryWrapper.lambda().eq(StOrganization::getOrgId, stOrganization.getOrgId());
  223. StOrganization stOrganizationDb = stOrganizationMapper.selectOne(queryWrapper);
  224. if (stOrganizationDb == null) { //插入
  225. Date now = new Date();
  226. stOrganization.setCreateTime(now);
  227. stOrganization.setModifyTime(now);
  228. stOrganizationMapper.insert(stOrganization);
  229. } else { //更新
  230. stOrganization.setCreateTime(stOrganizationDb.getCreateTime());
  231. stOrganization.setModifyTime(stOrganizationDb.getModifyTime());
  232. stOrganization.setId(stOrganizationDb.getId());
  233. //其余属性不一样的就更新
  234. if (!DomainEquals.domainEquals(stOrganization,stOrganizationDb)) {
  235. Date now = new Date();
  236. stOrganization.setModifyTime(now);
  237. stOrganizationMapper.updateById(stOrganization);
  238. }
  239. }
  240. }
  241. } catch (Exception e) {
  242. logger.error("统计计算出错:{}", e.getMessage());
  243. }
  244. }
  245. }