123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- package com.bizmatics.service.impl;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.baomidou.mybatisplus.core.toolkit.Wrappers;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.bizmatics.common.core.bean.CommonPage;
- import com.bizmatics.common.mvc.base.AbstractCrudService;
- import com.bizmatics.model.Device;
- import com.bizmatics.model.DeviceAnalogVariableList;
- import com.bizmatics.model.DeviceList;
- import com.bizmatics.model.DeviceStatus;
- import com.bizmatics.model.system.SysUser;
- import com.bizmatics.model.vo.CorrespondDeviceListVO;
- import com.bizmatics.model.vo.CorrespondDeviceVO;
- import com.bizmatics.persistence.mapper.DeviceMapper;
- import com.bizmatics.service.DeviceAnalogVariableListService;
- import com.bizmatics.service.DeviceService;
- import com.bizmatics.service.DeviceStatusService;
- import com.bizmatics.service.enums.DeviceStatusCode;
- import com.bizmatics.service.enums.DeviceType;
- import com.bizmatics.service.es.RtAnalogService;
- import com.bizmatics.service.util.SecurityUtils;
- import com.bizmatics.service.vo.CorrespondDeviceVOT;
- import com.bizmatics.service.vo.DeviceCountVO;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import java.util.Optional;
- /**
- * 设备
- *
- * @author ya
- * @since 2021-07-07
- */
- @Service
- public class DeviceServiceImpl extends AbstractCrudService<DeviceMapper, Device> implements DeviceService {
- @Autowired
- private DeviceAnalogVariableListService deviceAnalogVariableListService;
- @Autowired
- private DeviceStatusService deviceStatusService;
- @Override
- public DeviceCountVO selectDeviceCount(Date startTime, Date endTime) {
- Integer userId = SecurityUtils.getLoginUser().getUser().getUserId().intValue();
- DeviceCountVO deviceCountVo = new DeviceCountVO();
- deviceCountVo.setNormalCount(baseMapper
- .selectCount(userId, null, DeviceStatusCode.NORMAL.getValue(), startTime, endTime, null));
- deviceCountVo.setOffLineCount(baseMapper
- .selectCount(userId, null, DeviceStatusCode.OFFLINE.getValue(), startTime, endTime, null));
- deviceCountVo.setDeviceCount(baseMapper
- .selectCount(userId, null, DeviceStatusCode.DEVICE.getValue(), startTime, endTime, null));
- deviceCountVo.setFaultCount(baseMapper
- .selectCount(userId, null, DeviceStatusCode.FAULT.getValue(), startTime, endTime, null));
- deviceCountVo.setCount(baseMapper
- .selectCount(userId, null, null, startTime, endTime, null));
- return deviceCountVo;
- }
- @Override
- public DeviceCountVO selectDeviceCountByType(Integer site) {
- DeviceCountVO deviceCountVo = new DeviceCountVO();
- Integer userId = SecurityUtils.getLoginUser().getUser().getUserId().intValue();
- int oneEightThreeEp = baseMapper.selectCount(userId, site, null, null, null, DeviceType.ONE_EIGHT_THREE_EP.getValue());
- int oneSevenOneEp = baseMapper.selectCount(userId, site, null, null, null, DeviceType.ONE_SEVEN_ONE_EP.getValue());
- int oneSevenThreeEp = baseMapper.selectCount(userId, site, null, null, null, DeviceType.ONE_SEVEN_THREE_EP.getValue());
- int video = baseMapper.selectCount(userId, site, null, null, null, DeviceType.VODEO_MONITROING.getValue());
- deviceCountVo.setEpCount(oneEightThreeEp + oneSevenOneEp + oneSevenThreeEp);
- deviceCountVo.setVideoCount(video);
- return deviceCountVo;
- }
- @Override
- public List<Device> list(Integer userId,Integer siteId,Integer deviceStatus,Date startTime,Date endTime,String type) {
- return baseMapper.list(userId,siteId,deviceStatus,startTime,endTime,type);
- }
- /**
- * 汇总
- *
- * @param list
- * @param deviceStatus
- * @param type
- * @return
- */
- public Long getCount(List<Device> list, Integer deviceStatus, String type) {
- return list.stream()
- .filter(device -> Optional.ofNullable(deviceStatus).map(ds -> ds.equals(device.getDeviceStatus())).orElse(true))
- .filter(device -> Optional.ofNullable(type).map(ds -> ds.equals(device.getDeviceType())).orElse(true))
- .count();
- }
- @Override
- public List<DeviceList> deviceList(String siteId) {
- List<DeviceList> DeviceList = null;
- DeviceList = baseMapper.DeviceList(Integer.parseInt(siteId));
- return DeviceList;
- }
- @Override
- public List<Device> dataManagementDeviceList(int siteId, int deviceType) {
- LambdaQueryWrapper<Device> queryWrapper = Wrappers.lambdaQuery();
- queryWrapper.eq(Device::getEnable, 1).eq(Device::getSiteId, siteId);
- List<Device> deviceList = this.list(queryWrapper);
- return deviceList;
- }
- @Override
- public void correspondDeviceAdd(Device device) {
- SysUser user = SecurityUtils.getLoginUser().getUser();
- // Device device = correspondDeviceVOT.getDevice();
- device.setEnable(1);
- device.setInstallTime(new Date());
- device.setCreator(user.getUserName());
- // List<DeviceAnalogVariableList> DeviceAnalogVariableList = correspondDeviceVOT.getDeviceAnalogVariableList();
- this.save(device);
- String deviceCode = device.getDeviceCode();
- Integer siteId = device.getSiteId();
- DeviceStatus deviceStatus = new DeviceStatus();
- deviceStatus.setDeviceStatus(1);
- deviceStatus.setDeviceCode(deviceCode);
- deviceStatus.setStatusTime(new Date());
- deviceStatus.setSiteId(siteId);
- deviceStatusService.save(deviceStatus);
- // int ID = device.getId();
- // if (DeviceAnalogVariableList.size() > 0) {
- // for (int i = 0; i < DeviceAnalogVariableList.size(); i++) {
- // DeviceAnalogVariableList.get(i).setCommunicationEquipment(ID);
- // DeviceAnalogVariableList.get(i).setCreateTime(new Date());
- // DeviceAnalogVariableList.get(i).setCreator(user.getUserName());
- // DeviceAnalogVariableList.get(i).setStatus(1);
- // deviceAnalogVariableListService.save(DeviceAnalogVariableList.get(i));
- // }
- // }
- }
- @Override
- public void correspondDeviceUpdate(Device device) {
- SysUser user = SecurityUtils.getLoginUser().getUser();
- // List<DeviceAnalogVariableList> DeviceAnalogVariableList = correspondDeviceVOT.getDeviceAnalogVariableList();
- this.updateById(device);
- // int ID = correspondDeviceVOT.getDevice().getId();
- // if (DeviceAnalogVariableList.size() > 0) {
- // for (int i = 0; i < DeviceAnalogVariableList.size(); i++) {
- // DeviceAnalogVariableList.get(i).setCommunicationEquipment(ID);
- // DeviceAnalogVariableList.get(i).setCreateTime(new Date());
- // DeviceAnalogVariableList.get(i).setCreator(user.getUserName());
- // DeviceAnalogVariableList.get(i).setStatus(1);
- // deviceAnalogVariableListService.save(DeviceAnalogVariableList.get(i));
- // }
- // }
- }
- @Override
- public void correspondDeviceDel(int id) {
- Device device = new Device();
- device.setId(id);
- device.setEnable(0);
- this.updateById(device);
- }
- @Override
- public CommonPage<CorrespondDeviceVO> correspondDeviceList(String deviceName, int size, int current) {
- List<CorrespondDeviceVO> correspondDeviceListOne = baseMapper.CorrespondDeviceList(deviceName, null, null);
- int total = 0;
- if (correspondDeviceListOne.size() > 0) {
- total = correspondDeviceListOne.size();
- }
- int startCurrent = (size - 1) * current;
- List<CorrespondDeviceVO> correspondDeviceList = baseMapper.CorrespondDeviceList(deviceName, startCurrent, current);
- return new CommonPage<>(correspondDeviceList, total, current, size);
- }
- @Override
- public List<CorrespondDeviceListVO> correspondDeviceListEcho(int id) {
- LambdaQueryWrapper<Device> queryWrapper = Wrappers.lambdaQuery();
- queryWrapper.eq(Device::getEnable, 1).eq(Device::getId, id);
- List<Device> deviceList = this.list(queryWrapper);
- LambdaQueryWrapper<DeviceAnalogVariableList> queryWrapperOne = Wrappers.lambdaQuery();
- queryWrapperOne.eq(DeviceAnalogVariableList::getStatus, 1).eq(DeviceAnalogVariableList::getCommunicationEquipment, deviceList.get(0).getId());
- List<DeviceAnalogVariableList> deviceAnalogVariableList = deviceAnalogVariableListService.list(queryWrapperOne);
- List<CorrespondDeviceListVO> list = new ArrayList<>();
- list.add(CorrespondDeviceListVO.builder().deviceCode(deviceList.get(0).getDeviceCode()).deviceName(deviceList.get(0).getDeviceName())
- .deviceType(deviceList.get(0).getDeviceType()).deviceAddress(deviceList.get(0).getDeviceAddress())
- .creator(deviceList.get(0).getCreator()).enable(deviceList.get(0).getEnable()).floor(deviceList.get(0).getFloor())
- .id(deviceList.get(0).getId()).sim(deviceList.get(0).getSim()).siteId(deviceList.get(0).getSiteId())
- .installTime(deviceList.get(0).getInstallTime()).deviceAnalogVariableList(deviceAnalogVariableList).build());
- return list;
- }
- @Override
- public CommonPage<Device> videoMonitoringDeviceList(String deviceName, Integer deviceType, Integer siteId, Integer size, Integer current) {
- IPage<Device> page = new Page<Device>(size, current);
- LambdaQueryWrapper<Device> queryWrapper = Wrappers.lambdaQuery();
- queryWrapper.eq(Device::getSiteId, siteId).eq(Device::getEnable, 1);
- if (deviceType != null && deviceType != 0) {
- queryWrapper.eq(Device::getDeviceType, deviceType);
- }
- if (deviceName != null && !deviceName.equals("") && !deviceName.equals(null)) {
- queryWrapper.like(Device::getDeviceName, deviceName);
- }
- page = this.page(page, queryWrapper);
- this.ToCommonPage(page);
- return new CommonPage<>(page.getRecords(), page.getTotal(), page.getCurrent(), page.getSize());
- }
- }
|