|
@@ -0,0 +1,143 @@
|
|
|
|
+package com.hfln.portal.infrastructure.gateway.impl;
|
|
|
|
+
|
|
|
|
+import cn.hfln.framework.extension.BizException;
|
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
+import com.hfln.portal.common.dto.DevInfoImportDto;
|
|
|
|
+import com.hfln.portal.common.dto.data.device.DeviceDTO;
|
|
|
|
+import com.hfln.portal.common.request.device.DeviceListQueryReq;
|
|
|
|
+import com.hfln.portal.common.vo.PageRecord;
|
|
|
|
+import com.hfln.portal.common.vo.UploadRes;
|
|
|
|
+import com.hfln.portal.domain.customer.util.CopyUtils;
|
|
|
|
+import com.hfln.portal.domain.exception.ErrorEnum;
|
|
|
|
+import com.hfln.portal.domain.gateway.AdminGateway;
|
|
|
|
+import com.hfln.portal.infrastructure.mqtt.MqttClient;
|
|
|
|
+import com.hfln.portal.infrastructure.oss.OssClient;
|
|
|
|
+import com.hfln.portal.infrastructure.po.BasePO;
|
|
|
|
+import com.hfln.portal.infrastructure.po.DevInfo;
|
|
|
|
+import com.hfln.portal.infrastructure.service.*;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
+
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+@Slf4j
|
|
|
|
+@Service
|
|
|
|
+public class AdminGatewayImpl implements AdminGateway {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private DevShareService devShareService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private DevInfoService devInfoService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private GroupShareService groupShareService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private DevGroupService devGroupService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private EventService eventService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private OssFileService ossFileService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private DevRoomService devRoomService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private UserService userService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private MqttClient mqttClient;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private OssClient ossClient;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private AlarmEventService alarmEventService;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public UploadRes uploadDev(MultipartFile file) throws IOException {
|
|
|
|
+
|
|
|
|
+ // 校验文件非空
|
|
|
|
+ if (file.isEmpty()) {
|
|
|
|
+ throw new BizException(ErrorEnum.FILE_IS_EMPTY.getErrorCode(), ErrorEnum.FILE_IS_EMPTY.getErrorMessage());
|
|
|
|
+ }
|
|
|
|
+ List<DevInfoImportDto> devInfoImportVoList = EasyExcel.read(file.getInputStream(), DevInfoImportDto.class, null).sheet(0).doReadSync();
|
|
|
|
+ if (CollectionUtils.isEmpty(devInfoImportVoList)) {
|
|
|
|
+ throw new BizException(ErrorEnum.FILE_IS_EMPTY.getErrorCode(), ErrorEnum.FILE_IS_EMPTY.getErrorMessage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<String> devIds = devInfoImportVoList.stream()
|
|
|
|
+ .map(DevInfoImportDto::getDevId)
|
|
|
|
+ .distinct()
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ List<String> existClientIds = devInfoService.queryClientIdListByClientIds(devIds);
|
|
|
|
+ if (!CollectionUtils.isEmpty(existClientIds)) {
|
|
|
|
+ devInfoImportVoList = devInfoImportVoList.stream().filter(item -> !existClientIds.contains(item.getDevId())).collect(Collectors.toList());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ devInfoService.saveOrUpdateBatch(devInfoImportVoList.stream().map(item -> {
|
|
|
|
+ DevInfo devInfo = new DevInfo();
|
|
|
|
+ devInfo.setClientId(item.getDevId());
|
|
|
|
+ devInfo.setDevType(item.getDevType());
|
|
|
|
+ devInfo.setSoftware(item.getSoftware());
|
|
|
|
+ devInfo.setStatusLight(1);
|
|
|
|
+ devInfo.setOnline(0);
|
|
|
|
+ devInfo.setIsDeleted(BasePO.DeleteFlag.NOT_DELETED);
|
|
|
|
+ devInfo.setX(BigDecimal.ZERO);
|
|
|
|
+ devInfo.setY(BigDecimal.ZERO);
|
|
|
|
+ devInfo.setNorthAngle(BigDecimal.ZERO);
|
|
|
|
+ return devInfo;
|
|
|
|
+ }).collect(Collectors.toList()));
|
|
|
|
+
|
|
|
|
+ UploadRes uploadRes = new UploadRes();
|
|
|
|
+ if (!CollectionUtils.isEmpty(existClientIds)) {
|
|
|
|
+ uploadRes.setSuc(false);
|
|
|
|
+ uploadRes.setMsgList(existClientIds);
|
|
|
|
+ }
|
|
|
|
+ uploadRes.setMsg("上传重复");
|
|
|
|
+ return uploadRes;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public PageRecord<DeviceDTO> queryDevList(DeviceListQueryReq queryReq) {
|
|
|
|
+
|
|
|
|
+ // 执行分页查询
|
|
|
|
+ Page<DevInfo> devInfoPage = devInfoService.queryDevList(queryReq);
|
|
|
|
+ // 换为目标VO
|
|
|
|
+ List<DeviceDTO> targets = CopyUtils.copyList(devInfoPage.getRecords(), DeviceDTO.class);
|
|
|
|
+ return CopyUtils.copyPage(devInfoPage, targets);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void addOneDevice(DeviceDTO deviceDTO) {
|
|
|
|
+
|
|
|
|
+ DevInfo devInfo = devInfoService.queryOneByClientId(deviceDTO.getClientId());
|
|
|
|
+ if (devInfo != null) {
|
|
|
|
+ throw new BizException(ErrorEnum.DEVICE_IS_EXIST.getErrorCode(), ErrorEnum.DEVICE_IS_EXIST.getErrorMessage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DevInfo saveInfo = new DevInfo();
|
|
|
|
+ saveInfo.setClientId(deviceDTO.getClientId());
|
|
|
|
+ saveInfo.setDevType(deviceDTO.getDevType());
|
|
|
|
+ saveInfo.setSoftware(deviceDTO.getSoftware());
|
|
|
|
+ saveInfo.setStatusLight(1);
|
|
|
|
+ saveInfo.setOnline(0);
|
|
|
|
+ saveInfo.setIsDeleted(BasePO.DeleteFlag.NOT_DELETED);
|
|
|
|
+ saveInfo.setX(BigDecimal.ZERO);
|
|
|
|
+ saveInfo.setY(BigDecimal.ZERO);
|
|
|
|
+ saveInfo.setNorthAngle(BigDecimal.ZERO);
|
|
|
|
+ devInfoService.save(saveInfo);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+}
|