DeviceServiceImpl.java 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. package com.bizmatics.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.metadata.IPage;
  4. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. import com.bizmatics.common.core.bean.CommonPage;
  7. import com.bizmatics.common.mvc.base.AbstractCrudService;
  8. import com.bizmatics.model.Device;
  9. import com.bizmatics.model.DeviceAnalogVariableList;
  10. import com.bizmatics.model.DeviceList;
  11. import com.bizmatics.model.DeviceStatus;
  12. import com.bizmatics.model.system.SysUser;
  13. import com.bizmatics.model.vo.CorrespondDeviceListVO;
  14. import com.bizmatics.model.vo.CorrespondDeviceVO;
  15. import com.bizmatics.persistence.mapper.DeviceMapper;
  16. import com.bizmatics.service.DeviceAnalogVariableListService;
  17. import com.bizmatics.service.DeviceService;
  18. import com.bizmatics.service.DeviceStatusService;
  19. import com.bizmatics.service.enums.DeviceStatusCode;
  20. import com.bizmatics.service.enums.DeviceType;
  21. import com.bizmatics.service.es.RtAnalogService;
  22. import com.bizmatics.service.util.SecurityUtils;
  23. import com.bizmatics.service.vo.CorrespondDeviceVOT;
  24. import com.bizmatics.service.vo.DeviceCountVO;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import org.springframework.stereotype.Service;
  27. import java.util.ArrayList;
  28. import java.util.Date;
  29. import java.util.List;
  30. import java.util.Optional;
  31. /**
  32. * 设备
  33. *
  34. * @author ya
  35. * @since 2021-07-07
  36. */
  37. @Service
  38. public class DeviceServiceImpl extends AbstractCrudService<DeviceMapper, Device> implements DeviceService {
  39. @Autowired
  40. private DeviceAnalogVariableListService deviceAnalogVariableListService;
  41. @Autowired
  42. private DeviceStatusService deviceStatusService;
  43. @Override
  44. public DeviceCountVO selectDeviceCount(Date startTime, Date endTime) {
  45. Integer userId = SecurityUtils.getLoginUser().getUser().getUserId().intValue();
  46. DeviceCountVO deviceCountVo = new DeviceCountVO();
  47. deviceCountVo.setNormalCount(baseMapper
  48. .selectCount(userId, null, DeviceStatusCode.NORMAL.getValue(), startTime, endTime, null));
  49. deviceCountVo.setOffLineCount(baseMapper
  50. .selectCount(userId, null, DeviceStatusCode.OFFLINE.getValue(), startTime, endTime, null));
  51. deviceCountVo.setDeviceCount(baseMapper
  52. .selectCount(userId, null, DeviceStatusCode.DEVICE.getValue(), startTime, endTime, null));
  53. deviceCountVo.setFaultCount(baseMapper
  54. .selectCount(userId, null, DeviceStatusCode.FAULT.getValue(), startTime, endTime, null));
  55. deviceCountVo.setCount(baseMapper
  56. .selectCount(userId, null, null, startTime, endTime, null));
  57. return deviceCountVo;
  58. }
  59. @Override
  60. public DeviceCountVO selectDeviceCountByType(Integer site) {
  61. DeviceCountVO deviceCountVo = new DeviceCountVO();
  62. Integer userId = SecurityUtils.getLoginUser().getUser().getUserId().intValue();
  63. int oneEightThreeEp = baseMapper.selectCount(userId, site, null, null, null, DeviceType.ONE_EIGHT_THREE_EP.getValue());
  64. int oneSevenOneEp = baseMapper.selectCount(userId, site, null, null, null, DeviceType.ONE_SEVEN_ONE_EP.getValue());
  65. int oneSevenThreeEp = baseMapper.selectCount(userId, site, null, null, null, DeviceType.ONE_SEVEN_THREE_EP.getValue());
  66. int video = baseMapper.selectCount(userId, site, null, null, null, DeviceType.VODEO_MONITROING.getValue());
  67. deviceCountVo.setEpCount(oneEightThreeEp + oneSevenOneEp + oneSevenThreeEp);
  68. deviceCountVo.setVideoCount(video);
  69. return deviceCountVo;
  70. }
  71. /**
  72. * 汇总
  73. *
  74. * @param list
  75. * @param deviceStatus
  76. * @param type
  77. * @return
  78. */
  79. public Long getCount(List<Device> list, Integer deviceStatus, String type) {
  80. return list.stream()
  81. .filter(device -> Optional.ofNullable(deviceStatus).map(ds -> ds.equals(device.getDeviceStatus())).orElse(true))
  82. .filter(device -> Optional.ofNullable(type).map(ds -> ds.equals(device.getDeviceType())).orElse(true))
  83. .count();
  84. }
  85. @Override
  86. public List<DeviceList> deviceList(String siteId) {
  87. List<DeviceList> DeviceList = null;
  88. DeviceList = baseMapper.DeviceList(Integer.parseInt(siteId));
  89. return DeviceList;
  90. }
  91. @Override
  92. public List<Device> dataManagementDeviceList(int siteId, int deviceType) {
  93. LambdaQueryWrapper<Device> queryWrapper = Wrappers.lambdaQuery();
  94. queryWrapper.eq(Device::getEnable, 1).eq(Device::getSiteId, siteId);
  95. List<Device> deviceList = this.list(queryWrapper);
  96. return deviceList;
  97. }
  98. @Override
  99. public void correspondDeviceAdd(Device device) {
  100. SysUser user = SecurityUtils.getLoginUser().getUser();
  101. // Device device = correspondDeviceVOT.getDevice();
  102. device.setEnable(1);
  103. device.setInstallTime(new Date());
  104. device.setCreator(user.getUserName());
  105. // List<DeviceAnalogVariableList> DeviceAnalogVariableList = correspondDeviceVOT.getDeviceAnalogVariableList();
  106. this.save(device);
  107. String deviceCode = device.getDeviceCode();
  108. Integer siteId = device.getSiteId();
  109. DeviceStatus deviceStatus = new DeviceStatus();
  110. deviceStatus.setDeviceStatus(1);
  111. deviceStatus.setDeviceCode(deviceCode);
  112. deviceStatus.setStatusTime(new Date());
  113. deviceStatus.setSiteId(siteId);
  114. deviceStatusService.save(deviceStatus);
  115. // int ID = device.getId();
  116. // if (DeviceAnalogVariableList.size() > 0) {
  117. // for (int i = 0; i < DeviceAnalogVariableList.size(); i++) {
  118. // DeviceAnalogVariableList.get(i).setCommunicationEquipment(ID);
  119. // DeviceAnalogVariableList.get(i).setCreateTime(new Date());
  120. // DeviceAnalogVariableList.get(i).setCreator(user.getUserName());
  121. // DeviceAnalogVariableList.get(i).setStatus(1);
  122. // deviceAnalogVariableListService.save(DeviceAnalogVariableList.get(i));
  123. // }
  124. // }
  125. }
  126. @Override
  127. public void correspondDeviceUpdate(Device device) {
  128. SysUser user = SecurityUtils.getLoginUser().getUser();
  129. // List<DeviceAnalogVariableList> DeviceAnalogVariableList = correspondDeviceVOT.getDeviceAnalogVariableList();
  130. this.updateById(device);
  131. // int ID = correspondDeviceVOT.getDevice().getId();
  132. // if (DeviceAnalogVariableList.size() > 0) {
  133. // for (int i = 0; i < DeviceAnalogVariableList.size(); i++) {
  134. // DeviceAnalogVariableList.get(i).setCommunicationEquipment(ID);
  135. // DeviceAnalogVariableList.get(i).setCreateTime(new Date());
  136. // DeviceAnalogVariableList.get(i).setCreator(user.getUserName());
  137. // DeviceAnalogVariableList.get(i).setStatus(1);
  138. // deviceAnalogVariableListService.save(DeviceAnalogVariableList.get(i));
  139. // }
  140. // }
  141. }
  142. @Override
  143. public void correspondDeviceDel(int id) {
  144. Device device = new Device();
  145. device.setId(id);
  146. device.setEnable(0);
  147. this.updateById(device);
  148. }
  149. @Override
  150. public CommonPage<CorrespondDeviceVO> correspondDeviceList(String deviceName, int size, int current) {
  151. List<CorrespondDeviceVO> correspondDeviceListOne = baseMapper.CorrespondDeviceList(deviceName, null, null);
  152. int total = 0;
  153. if (correspondDeviceListOne.size() > 0) {
  154. total = correspondDeviceListOne.size();
  155. }
  156. int startCurrent = (size - 1) * current;
  157. List<CorrespondDeviceVO> correspondDeviceList = baseMapper.CorrespondDeviceList(deviceName, startCurrent, current);
  158. return new CommonPage<>(correspondDeviceList, total, current, size);
  159. }
  160. @Override
  161. public List<CorrespondDeviceListVO> correspondDeviceListEcho(int id) {
  162. LambdaQueryWrapper<Device> queryWrapper = Wrappers.lambdaQuery();
  163. queryWrapper.eq(Device::getEnable, 1).eq(Device::getId, id);
  164. List<Device> deviceList = this.list(queryWrapper);
  165. LambdaQueryWrapper<DeviceAnalogVariableList> queryWrapperOne = Wrappers.lambdaQuery();
  166. queryWrapperOne.eq(DeviceAnalogVariableList::getStatus, 1).eq(DeviceAnalogVariableList::getCommunicationEquipment, deviceList.get(0).getId());
  167. List<DeviceAnalogVariableList> deviceAnalogVariableList = deviceAnalogVariableListService.list(queryWrapperOne);
  168. List<CorrespondDeviceListVO> list = new ArrayList<>();
  169. list.add(CorrespondDeviceListVO.builder().deviceCode(deviceList.get(0).getDeviceCode()).deviceName(deviceList.get(0).getDeviceName())
  170. .deviceType(deviceList.get(0).getDeviceType()).deviceAddress(deviceList.get(0).getDeviceAddress())
  171. .creator(deviceList.get(0).getCreator()).enable(deviceList.get(0).getEnable()).floor(deviceList.get(0).getFloor())
  172. .id(deviceList.get(0).getId()).sim(deviceList.get(0).getSim()).siteId(deviceList.get(0).getSiteId())
  173. .installTime(deviceList.get(0).getInstallTime()).deviceAnalogVariableList(deviceAnalogVariableList).build());
  174. return list;
  175. }
  176. @Override
  177. public CommonPage<Device> videoMonitoringDeviceList(String deviceName, Integer deviceType, Integer siteId, Integer size, Integer current) {
  178. IPage<Device> page = new Page<Device>(size, current);
  179. LambdaQueryWrapper<Device> queryWrapper = Wrappers.lambdaQuery();
  180. queryWrapper.eq(Device::getSiteId, siteId).eq(Device::getEnable, 1);
  181. if (deviceType != null && deviceType != 0) {
  182. queryWrapper.eq(Device::getDeviceType, deviceType);
  183. }
  184. if (deviceName != null && !deviceName.equals("") && !deviceName.equals(null)) {
  185. queryWrapper.like(Device::getDeviceName, deviceName);
  186. }
  187. page = this.page(page, queryWrapper);
  188. this.ToCommonPage(page);
  189. return new CommonPage<>(page.getRecords(), page.getTotal(), page.getCurrent(), page.getSize());
  190. }
  191. }