|
|
@@ -0,0 +1,178 @@
|
|
|
+package com.xunmei.mediator.api.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.xunmei.common.core.constant.CacheConstants;
|
|
|
+import com.xunmei.common.core.domain.iot.domain.IotDevice;
|
|
|
+import com.xunmei.common.core.domain.iot.domain.IotDvrDisk;
|
|
|
+import com.xunmei.common.core.enums.CategoryDataEnum;
|
|
|
+import com.xunmei.common.core.utils.IDHelper;
|
|
|
+import com.xunmei.common.redis.utils.RedisUtils;
|
|
|
+import com.xunmei.mediator.api.mapper.IotDvrDiskMapper;
|
|
|
+import com.xunmei.mediator.api.service.IIotDeviceService;
|
|
|
+import com.xunmei.mediator.api.service.IotDvrDiskService;
|
|
|
+import com.xunmei.mediator.api.service.NorthErrorService;
|
|
|
+import com.xunmei.mediator.api.service.NorthStatisticsSyncService;
|
|
|
+import com.xunmei.mediator.util.CheckDataUtil;
|
|
|
+import com.xunmei.mediator.util.RedisCheckRepeatDataUtil;
|
|
|
+import com.xunmei.system.api.RemoteOrgService;
|
|
|
+import com.xunmei.system.api.domain.SysOrg;
|
|
|
+import com.xunmei.system.api.domain.north.NorthError;
|
|
|
+import com.xunmei.system.api.dto.DataPageDto;
|
|
|
+import com.xunmei.system.api.dto.DvrDiskPageDto;
|
|
|
+import com.xunmei.system.api.dto.DvrdiskDto;
|
|
|
+import com.xunmei.system.api.dto.protection.ReceiveErrorDto;
|
|
|
+import com.xunmei.system.api.enums.DataType;
|
|
|
+import com.xunmei.system.api.util.LogUtils;
|
|
|
+import com.xunmei.system.api.vo.SysOrgVO;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author oygj
|
|
|
+ * @since 2024-02-21
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class IotDvrDiskServiceImpl extends ServiceImpl<IotDvrDiskMapper, IotDvrDisk> implements IotDvrDiskService {
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private NorthStatisticsSyncService northStatisticsSyncService;
|
|
|
+ @Autowired
|
|
|
+ private NorthErrorService northErrorService;
|
|
|
+ @Autowired
|
|
|
+ private IIotDeviceService iotDeviceService;
|
|
|
+ @Autowired
|
|
|
+ private RedisCheckRepeatDataUtil redisCheckRepeatDataUtil;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ReceiveErrorDto saveData(DataPageDto<DvrDiskPageDto> request, String msgId, String branchId) throws Exception {
|
|
|
+ //验证基础分页信息
|
|
|
+ ReceiveErrorDto dto = CheckDataUtil.checkObjFieldIsNull(request);
|
|
|
+ if (dto.getSuccess()) {
|
|
|
+ //分页数据的存取
|
|
|
+ List<DvrDiskPageDto> dvrdiskPageLists = redisCheckRepeatDataUtil.isCompleted(request, DvrDiskPageDto.class);
|
|
|
+
|
|
|
+ log.info("判断是否获取DVR硬盘空间全部信息分页数据:{}", dvrdiskPageLists.size() > 0 ? true : false);
|
|
|
+ if (dvrdiskPageLists.size() > 0) {
|
|
|
+ Map<String, Object> map = this.cheakDvrdiskPageDto(dvrdiskPageLists, branchId, msgId);
|
|
|
+ this.saveAll(map);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return dto;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void saveAll(Map<String, Object> map) throws Exception {
|
|
|
+
|
|
|
+ List<NorthError> errors = (List<NorthError>) map.get("errors");
|
|
|
+
|
|
|
+ List<IotDvrDisk> dvrdisks = (List<IotDvrDisk>) map.get("dvrdisks");
|
|
|
+
|
|
|
+ this.northStatisticsSyncService.saveOrUpdateBaseCountByDataType(DataType.dvrdiskCount.getIndex(), dvrdisks.size(), false);
|
|
|
+
|
|
|
+ if (ObjectUtil.isNotEmpty(errors)) {
|
|
|
+ northErrorService.saveErrorData(errors);
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotEmpty(dvrdisks)) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ baseMapper.delete(null);
|
|
|
+ this.saveBatch(dvrdisks);
|
|
|
+ } catch (Exception e) {
|
|
|
+ LogUtils.STATUS_INFO_DISKS_SPACE.error("批量保存dvrdisk失败,失败原因:{}", e.getMessage());
|
|
|
+ throw new RuntimeException(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Object> cheakDvrdiskPageDto(List<DvrDiskPageDto> dvrdiskPageLists, String branchId, String msgId) throws IllegalAccessException {
|
|
|
+ //获取所有的监控主机
|
|
|
+ final List<IotDevice> deviceListAll = iotDeviceService.findByCategory(CategoryDataEnum.MONITOR_HOST_DEVICE.getId());
|
|
|
+
|
|
|
+ List<SysOrgVO> orgList = RedisUtils.getCacheList(CacheConstants.ORG_CACHE_LIST_KEY);
|
|
|
+
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+
|
|
|
+ List<NorthError> errors = new ArrayList<>();
|
|
|
+
|
|
|
+ List<IotDvrDisk> dvrdisks = new ArrayList<>();
|
|
|
+
|
|
|
+ for (DvrDiskPageDto pageDto : dvrdiskPageLists) {
|
|
|
+ NorthError error = null;
|
|
|
+ SysOrgVO org = null;
|
|
|
+ IotDevice device = null;
|
|
|
+ //验证DvrdiskPageDto对象中是否有参数为null
|
|
|
+ error = CheckDataUtil.checkObjFieldIsNull(pageDto, branchId, msgId, "/api/data/dvrDiskList", null);
|
|
|
+ if (error != null) {
|
|
|
+ errors.add(error);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //验证机构是否存在
|
|
|
+ final Optional<SysOrgVO> optional = orgList.stream().filter(r -> r.getCode().equals(pageDto.getOrganizationGuid())).findFirst();
|
|
|
+ if (!optional.isPresent()) {
|
|
|
+ error = new NorthError(msgId, branchId, "/api/data/dvrDiskList"
|
|
|
+ , pageDto, "OrganizationGuid:" + pageDto.getOrganizationGuid() + "不正确");
|
|
|
+ errors.add(error);
|
|
|
+ continue;
|
|
|
+ } else {
|
|
|
+ org = optional.get();
|
|
|
+ }
|
|
|
+ //验证监控主机是否存在
|
|
|
+ SysOrgVO finalOrg = org;
|
|
|
+ List<IotDevice> deviceList = deviceListAll.stream().filter(r -> r.getEquipmentCode().equals(pageDto.getEquipmentCode())
|
|
|
+ && r.getOrgId().equals(finalOrg.getId())).collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (deviceList.size() == 0) {
|
|
|
+ error = new NorthError(msgId, branchId, "/api/data/dvrDiskList"
|
|
|
+ , pageDto, "EquipmentCode:" + pageDto.getEquipmentCode() + "不正确");
|
|
|
+ errors.add(error);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<DvrdiskDto> diskSpaces = pageDto.getDiskSpace();
|
|
|
+
|
|
|
+ if (ObjectUtil.isEmpty(diskSpaces)) {
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ for (DvrdiskDto dto : diskSpaces) {
|
|
|
+ //验证DvrdiskDto是否有字段为null
|
|
|
+ List<String> fields = new ArrayList<>();
|
|
|
+ fields.add("name");
|
|
|
+ error = CheckDataUtil.checkObjFieldIsNull(dto, branchId, msgId, "/api/data/dvrDiskList", fields);
|
|
|
+ if (error != null) {
|
|
|
+ errors.add(error);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ IotDvrDisk dvrdisk = IotDvrDisk.builder()
|
|
|
+ .available(dto.getAvailable().substring(0, dto.getAvailable().length() - 2))
|
|
|
+ .diskIndex(dto.getDiskSerialNum())
|
|
|
+ .equipmentCode(pageDto.getEquipmentCode())
|
|
|
+ .diskName(dto.getName())
|
|
|
+ .id(IDHelper.id())
|
|
|
+ .total(dto.getTotal().substring(0, dto.getTotal().length() - 2))
|
|
|
+ .orgId(org.getId()).build();
|
|
|
+
|
|
|
+ dvrdisks.add(dvrdisk);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ map.put("errors", errors);
|
|
|
+ map.put("dvrdisks", dvrdisks);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+}
|