DeviceServiceImpl.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. @Override
  72. public List<Device> list(Integer userId,Integer siteId,Integer deviceStatus,Date startTime,Date endTime,String type) {
  73. return baseMapper.list(userId,siteId,deviceStatus,startTime,endTime,type);
  74. }
  75. /**
  76. * 汇总
  77. *
  78. * @param list
  79. * @param deviceStatus
  80. * @param type
  81. * @return
  82. */
  83. public Long getCount(List<Device> list, Integer deviceStatus, String type) {
  84. return list.stream()
  85. .filter(device -> Optional.ofNullable(deviceStatus).map(ds -> ds.equals(device.getDeviceStatus())).orElse(true))
  86. .filter(device -> Optional.ofNullable(type).map(ds -> ds.equals(device.getDeviceType())).orElse(true))
  87. .count();
  88. }
  89. @Override
  90. public List<DeviceList> deviceList(String siteId) {
  91. List<DeviceList> DeviceList = null;
  92. DeviceList = baseMapper.DeviceList(Integer.parseInt(siteId));
  93. return DeviceList;
  94. }
  95. @Override
  96. public List<Device> dataManagementDeviceList(int siteId, int deviceType) {
  97. LambdaQueryWrapper<Device> queryWrapper = Wrappers.lambdaQuery();
  98. queryWrapper.eq(Device::getEnable, 1).eq(Device::getSiteId, siteId);
  99. List<Device> deviceList = this.list(queryWrapper);
  100. return deviceList;
  101. }
  102. @Override
  103. public void correspondDeviceAdd(Device device) {
  104. SysUser user = SecurityUtils.getLoginUser().getUser();
  105. // Device device = correspondDeviceVOT.getDevice();
  106. device.setEnable(1);
  107. device.setInstallTime(new Date());
  108. device.setCreator(user.getUserName());
  109. // List<DeviceAnalogVariableList> DeviceAnalogVariableList = correspondDeviceVOT.getDeviceAnalogVariableList();
  110. this.save(device);
  111. String deviceCode = device.getDeviceCode();
  112. Integer siteId = device.getSiteId();
  113. DeviceStatus deviceStatus = new DeviceStatus();
  114. deviceStatus.setDeviceStatus(1);
  115. deviceStatus.setDeviceCode(deviceCode);
  116. deviceStatus.setStatusTime(new Date());
  117. deviceStatus.setSiteId(siteId);
  118. deviceStatusService.save(deviceStatus);
  119. // int ID = device.getId();
  120. // if (DeviceAnalogVariableList.size() > 0) {
  121. // for (int i = 0; i < DeviceAnalogVariableList.size(); i++) {
  122. // DeviceAnalogVariableList.get(i).setCommunicationEquipment(ID);
  123. // DeviceAnalogVariableList.get(i).setCreateTime(new Date());
  124. // DeviceAnalogVariableList.get(i).setCreator(user.getUserName());
  125. // DeviceAnalogVariableList.get(i).setStatus(1);
  126. // deviceAnalogVariableListService.save(DeviceAnalogVariableList.get(i));
  127. // }
  128. // }
  129. }
  130. @Override
  131. public void correspondDeviceUpdate(Device device) {
  132. SysUser user = SecurityUtils.getLoginUser().getUser();
  133. // List<DeviceAnalogVariableList> DeviceAnalogVariableList = correspondDeviceVOT.getDeviceAnalogVariableList();
  134. this.updateById(device);
  135. // int ID = correspondDeviceVOT.getDevice().getId();
  136. // if (DeviceAnalogVariableList.size() > 0) {
  137. // for (int i = 0; i < DeviceAnalogVariableList.size(); i++) {
  138. // DeviceAnalogVariableList.get(i).setCommunicationEquipment(ID);
  139. // DeviceAnalogVariableList.get(i).setCreateTime(new Date());
  140. // DeviceAnalogVariableList.get(i).setCreator(user.getUserName());
  141. // DeviceAnalogVariableList.get(i).setStatus(1);
  142. // deviceAnalogVariableListService.save(DeviceAnalogVariableList.get(i));
  143. // }
  144. // }
  145. }
  146. @Override
  147. public void correspondDeviceDel(int id) {
  148. Device device = new Device();
  149. device.setId(id);
  150. device.setEnable(0);
  151. this.updateById(device);
  152. }
  153. @Override
  154. public CommonPage<CorrespondDeviceVO> correspondDeviceList(String deviceName, int size, int current) {
  155. List<CorrespondDeviceVO> correspondDeviceListOne = baseMapper.CorrespondDeviceList(deviceName, null, null);
  156. int total = 0;
  157. if (correspondDeviceListOne.size() > 0) {
  158. total = correspondDeviceListOne.size();
  159. }
  160. int startCurrent = (size - 1) * current;
  161. List<CorrespondDeviceVO> correspondDeviceList = baseMapper.CorrespondDeviceList(deviceName, startCurrent, current);
  162. return new CommonPage<>(correspondDeviceList, total, current, size);
  163. }
  164. @Override
  165. public List<CorrespondDeviceListVO> correspondDeviceListEcho(int id) {
  166. LambdaQueryWrapper<Device> queryWrapper = Wrappers.lambdaQuery();
  167. queryWrapper.eq(Device::getEnable, 1).eq(Device::getId, id);
  168. List<Device> deviceList = this.list(queryWrapper);
  169. LambdaQueryWrapper<DeviceAnalogVariableList> queryWrapperOne = Wrappers.lambdaQuery();
  170. queryWrapperOne.eq(DeviceAnalogVariableList::getStatus, 1).eq(DeviceAnalogVariableList::getCommunicationEquipment, deviceList.get(0).getId());
  171. List<DeviceAnalogVariableList> deviceAnalogVariableList = deviceAnalogVariableListService.list(queryWrapperOne);
  172. List<CorrespondDeviceListVO> list = new ArrayList<>();
  173. list.add(CorrespondDeviceListVO.builder().deviceCode(deviceList.get(0).getDeviceCode()).deviceName(deviceList.get(0).getDeviceName())
  174. .deviceType(deviceList.get(0).getDeviceType()).deviceAddress(deviceList.get(0).getDeviceAddress())
  175. .creator(deviceList.get(0).getCreator()).enable(deviceList.get(0).getEnable()).floor(deviceList.get(0).getFloor())
  176. .id(deviceList.get(0).getId()).sim(deviceList.get(0).getSim()).siteId(deviceList.get(0).getSiteId())
  177. .installTime(deviceList.get(0).getInstallTime()).deviceAnalogVariableList(deviceAnalogVariableList).build());
  178. return list;
  179. }
  180. @Override
  181. public CommonPage<Device> videoMonitoringDeviceList(String deviceName, Integer deviceType, Integer siteId, Integer size, Integer current) {
  182. IPage<Device> page = new Page<Device>(size, current);
  183. LambdaQueryWrapper<Device> queryWrapper = Wrappers.lambdaQuery();
  184. queryWrapper.eq(Device::getSiteId, siteId).eq(Device::getEnable, 1);
  185. if (deviceType != null && deviceType != 0) {
  186. queryWrapper.eq(Device::getDeviceType, deviceType);
  187. }
  188. if (deviceName != null && !deviceName.equals("") && !deviceName.equals(null)) {
  189. queryWrapper.like(Device::getDeviceName, deviceName);
  190. }
  191. page = this.page(page, queryWrapper);
  192. this.ToCommonPage(page);
  193. return new CommonPage<>(page.getRecords(), page.getTotal(), page.getCurrent(), page.getSize());
  194. }
  195. }