123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- package com.care.bigscreen.service.impl;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.care.bigscreen.entity.StOrganization;
- import com.care.bigscreen.entity.StStation;
- import com.care.bigscreen.mapper.BigSreenMapper;
- import com.care.bigscreen.mapper.StOrganizationMapper;
- import com.care.bigscreen.mapper.StStationMapper;
- import com.care.bigscreen.service.BigScreenService;
- import com.care.bigscreen.vo.*;
- import com.care.bigscreen.websocket.BigScreenWebSocketEndpoint;
- import com.care.common.service.CareStationService;
- import com.care.common.util.DomainEquals;
- import com.care.common.vo.PageResVO;
- import com.care.common.util.PageUtil;
- import org.apache.logging.log4j.LogManager;
- import org.apache.logging.log4j.Logger;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.Date;
- import java.util.List;
- /**
- * @author stw
- * @version 1.0
- * @description 站点统计表接口实现类
- * @date 2021/05/20/19:41
- */
- @Service
- public class BigScreenServiceImpl implements BigScreenService {
- private static final Logger logger = LogManager.getLogger(BigScreenServiceImpl.class);
- @Autowired
- private BigSreenMapper bigSreenMapper;
- @Autowired
- private CareStationService careStationService;
- @Autowired
- private StStationMapper stStationMapper;
- @Autowired
- private StOrganizationMapper stOrganizationMapper;
- /**
- * 运营商大屏统计查询
- * @return 搜索符合条件的大屏统计数据
- */
- @Override
- public OpBigScreenStatisticsVO selectBigScreenStatisticsByOp(Long stationId){
- OpBigScreenStatisticsVO opBigScreenStatisticsVO = bigSreenMapper.selectBigScreenStatisticsByOp(stationId);
- BigScreenOrgVO bigScreenOrgVO = null;
- if(stationId == null){ //运营商大屏
- bigScreenOrgVO = bigSreenMapper.selectBigScreenOrgStatistics(null);
- } else { //站点查询
- bigScreenOrgVO = bigSreenMapper.selectBigScreenOrgStatistics(careStationService.getById(stationId).getOrgId());
- }
- opBigScreenStatisticsVO.setSeatsAmount(bigScreenOrgVO.getSeatsAmount());
- opBigScreenStatisticsVO.setSeatsOnlineDuration(bigScreenOrgVO.getSeatsOnlineDuration());
- return opBigScreenStatisticsVO;
- }
- /**
- * 运营商大屏统计查询
- * @return 根据经纬度范围搜索符合条件的大屏统计数据
- */
- @Override
- public OpBigScreenStatisticsVO selectOpBigScreenStatisticsByLongitudeLatitude(String longitudeLeftUp, String latitudeLeftUp, String longitudeRightDown, String latitudeRightDown) {
- return bigSreenMapper.selectOpBigScreenStatisticsByLongitudeLatitude(longitudeLeftUp,latitudeLeftUp,longitudeRightDown,latitudeRightDown);
- }
- /**
- * 机构大屏统计查询
- * @return 搜索符合条件的大屏统计数据
- */
- @Override
- public OrgBigScreenStatisticsVO selectBigScreenStatisticsByOrg(Long stationId, Long orgId){
- OrgBigScreenStatisticsVO orgBigScreenStatisticsVO = bigSreenMapper.selectBigScreenStatisticsByOrg(stationId,orgId);
- BigScreenOrgVO bigScreenOrgVO = null;
- if(stationId == null){ //机构大屏
- bigScreenOrgVO = bigSreenMapper.selectBigScreenOrgStatistics(orgId);
- } else { //站点查询
- bigScreenOrgVO = bigSreenMapper.selectBigScreenOrgStatistics(careStationService.getById(stationId).getOrgId());
- }
- orgBigScreenStatisticsVO.setStationAmount(bigScreenOrgVO.getStationAmount());
- return orgBigScreenStatisticsVO;
- }
- /**
- * 机构大屏统计查询
- * @return 根据经纬度范围搜索符合条件的大屏统计数据
- */
- @Override
- public OrgBigScreenStatisticsVO selectOrgBigScreenStatisticsByLongitudeLatitude(String longitudeLeftUp, String latitudeLeftUp, String longitudeRightDown, String latitudeRightDown, Long orgId) {
- return bigSreenMapper.selectOrgBigScreenStatisticsByLongitudeLatitude(longitudeLeftUp,latitudeLeftUp,longitudeRightDown,latitudeRightDown,orgId);
- }
- /**
- * 站点列表查询
- */
- @Override
- public List<BigScreenStationVO> selectBigScreenStationList(Long orgId) {
- return bigSreenMapper.selectBigScreenStationList(orgId);
- }
- /**
- * 服务站大屏的站点统计查询
- * @return 搜索符合条件的大屏统计数据
- */
- @Override
- public StationBigScreenStatisticsVO selectStationBigScreenStatisticsByStation(Long stationId){
- return bigSreenMapper.selectStationBigScreenStatisticsByStation(stationId);
- }
- /**
- * 告警用户列表查询
- */
- @Override
- public List<BigScreenAlarmOlderVO> selectBigScreenAlarmOlderList(Long stationId, String olderName){
- return bigSreenMapper.selectBigScreenAlarmOlderList(stationId, olderName);
- }
- /**
- * 服务站大屏的被监控人详细查询
- */
- @Override
- public BigScreenOlderDetailVO selectStationBigScreenOlderDetail(Long olderId) {
- return bigSreenMapper.selectStationBigScreenOlderDetail(olderId);
- }
- /**
- * 服务站大屏的安全事件总计查询
- * @return 搜索符合条件的大屏统计数据
- */
- @Override
- public BigScreenEventTotalVO selectStationBigScreenEventTotal(Long stationId){
- return bigSreenMapper.selectStationBigScreenEventTotal(stationId);
- }
- /**
- * 机构大屏或服务站大屏的实时安全事件列表查询
- */
- @Override
- public List<BigScreenEventVO> selectBigScreenRtEventList(Long orgId ,Long stationId) {
- return bigSreenMapper.selectBigScreenRtEventList(orgId, stationId);
- }
- /**
- * 机构大屏的设备列表查询
- */
- @Override
- public List<BigScreenDeviceVO> selectOrgBigScreenDeviceList(Long orgId, Long stationId,String status) {
- return bigSreenMapper.selectOrgBigScreenDeviceList(orgId, stationId,status);
- }
- /**
- * 服务站大屏的已完成安全事件列表分页查询
- */
- @Override
- public PageUtil<BigScreenEventVO> selectBigScreenHisEventListByPage(Long stationId, PageResVO page) {
- //1、创建一个分页工具对象(然后对分页数据进行整理)
- PageUtil<BigScreenEventVO> pageUtil = new PageUtil<>();
- //2、更新当前页面大小
- pageUtil.setPageSize(page.getPageSize());
- //3、获取多条件查询总记录数
- pageUtil.setTotal(bigSreenMapper.selectBigScreenHisEventListByCount(stationId));
- //4、更新当前页码(此时页码将不会再发生越界问题)
- pageUtil.setCurrent(page.getCurrent());
- List<BigScreenEventVO> bigScreenEventVOList = bigSreenMapper.selectBigScreenHisEventListByPage(stationId, pageUtil);
- pageUtil.setListT(bigScreenEventVOList);
- return pageUtil;
- }
- /**
- * 服务站大屏的用户卡片总计查询
- * @return 搜索符合条件的大屏统计数据
- */
- @Override
- public BigScreenOlderCardTotalVO selectStationBigScreenOlderCardTotal(Long stationId,String olderName){
- return bigSreenMapper.selectStationBigScreenOlderCardTotal(stationId,olderName);
- }
- /**
- * 服务站大屏的用户卡片列表分页查询
- */
- @Override
- public PageUtil<BigScreenOlderDetailVO> selectBigScreenOlderCardListByPage(Long stationId, String olderName,String isAlarm, PageResVO page) {
- //1、创建一个分页工具对象(然后对分页数据进行整理)
- PageUtil<BigScreenOlderDetailVO> pageUtil = new PageUtil<>();
- //2、更新当前页面大小
- pageUtil.setPageSize(page.getPageSize());
- //3、获取多条件查询总记录数
- pageUtil.setTotal(bigSreenMapper.selectBigScreenOlderCardListByCount(stationId,olderName,isAlarm));
- //4、更新当前页码(此时页码将不会再发生越界问题)
- pageUtil.setCurrent(page.getCurrent());
- List<BigScreenOlderDetailVO> bigScreenOlderDetailVOList = bigSreenMapper.selectBigScreenOlderCardListByPage(stationId,olderName,isAlarm, pageUtil);
- pageUtil.setListT(bigScreenOlderDetailVOList);
- return pageUtil;
- }
- /**
- * 调用websocket推送实时事件标识给前端
- */
- @Override
- public void pushRtEventFlag(String stationId) {
- //触发统计
- exeStatistics();
- BigScreenWebSocketEndpoint.sendMsgToFront(stationId,"rt_event_happen");
- }
- /**
- * 进行统计
- */
- @Override
- public void exeStatistics(){
- try {
- List<StStation> stStationList = stStationMapper.selectStStationList();
- for(StStation stStation : stStationList) {
- QueryWrapper<StStation> queryWrapper = new QueryWrapper<>();
- //查询表中是否存在
- queryWrapper.lambda().eq(StStation::getStationId, stStation.getStationId());
- StStation stStationDb = stStationMapper.selectOne(queryWrapper);
- if (stStationDb == null) { //插入
- Date now = new Date();
- stStation.setCreateTime(now);
- stStation.setModifyTime(now);
- stStationMapper.insert(stStation);
- } else { //更新
- stStation.setCreateTime(stStationDb.getCreateTime());
- stStation.setModifyTime(stStationDb.getModifyTime());
- stStation.setId(stStationDb.getId());
- //其余属性不一样的就更新
- if (!DomainEquals.domainEquals(stStation,stStationDb)){
- Date now = new Date();
- stStation.setModifyTime(now);
- stStationMapper.updateById(stStation);
- }
- }
- }
- List<StOrganization> stOrganizationList = stOrganizationMapper.selectStOrganizationList();
- for(StOrganization stOrganization : stOrganizationList) {
- QueryWrapper<StOrganization> queryWrapper = new QueryWrapper<>();
- //查询表中是否存在
- queryWrapper.lambda().eq(StOrganization::getOrgId, stOrganization.getOrgId());
- StOrganization stOrganizationDb = stOrganizationMapper.selectOne(queryWrapper);
- if (stOrganizationDb == null) { //插入
- Date now = new Date();
- stOrganization.setCreateTime(now);
- stOrganization.setModifyTime(now);
- stOrganizationMapper.insert(stOrganization);
- } else { //更新
- stOrganization.setCreateTime(stOrganizationDb.getCreateTime());
- stOrganization.setModifyTime(stOrganizationDb.getModifyTime());
- stOrganization.setId(stOrganizationDb.getId());
- //其余属性不一样的就更新
- if (!DomainEquals.domainEquals(stOrganization,stOrganizationDb)) {
- Date now = new Date();
- stOrganization.setModifyTime(now);
- stOrganizationMapper.updateById(stOrganization);
- }
- }
- }
- } catch (Exception e) {
- logger.error("统计计算出错:{}", e.getMessage());
- }
- }
- }
|