DeviceServiceImpl.java 9.6 KB

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