2 Revize 8fd08ec365 ... 07f9aa22c6

Autor SHA1 Zpráva Datum
  fanghuisheng 8fd08ec365 调整domain相关逻辑、设备绑定相关方法 před 3 týdny
  fanghuisheng 5034326c78 新增门禁设备心跳数据接口 před 3 týdny

+ 0 - 41
service-eg/service-eg-biz/src/main/java/com/usky/eg/controller/web/EgDeviceHeartbeatController.java

@@ -1,41 +0,0 @@
-package com.usky.eg.controller.web;
-
-
-import com.usky.common.core.bean.ApiResult;
-import com.usky.eg.domain.EgDeviceHeartbeat;
-import com.usky.eg.service.EgDeviceHeartbeatService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * <p>
- * 门禁设备心跳表 前端控制器
- * </p>
- *
- * @author fhs
- * @since 2026-02-03
- */
-@RestController
-@RequestMapping("/egDeviceHeartbeat")
-public class EgDeviceHeartbeatController {
-    private static final Logger log = LoggerFactory.getLogger(EgDeviceHeartbeatController.class);
-    @Autowired
-    private EgDeviceHeartbeatService heartbeatService;
-
-    @PostMapping("/escalation")
-    public ApiResult<Void> heartbeatEscalation(@RequestBody EgDeviceHeartbeat heartbeat) {
-        try {
-            heartbeatService.heartbeatEscalation(heartbeat);
-        } catch (Exception e) {
-            log.error("设备心跳异常", e);
-            return ApiResult.error("设备心跳入库异常!");
-        }
-        return ApiResult.success();
-    }
-}

+ 0 - 8
service-eg/service-eg-biz/src/main/java/com/usky/eg/domain/EgDevice.java

@@ -134,14 +134,6 @@ public class EgDevice implements Serializable {
     private String workStatus;
 
     /**
-     * 设备code
-     */
-    private String deviceCode;
-
-    /**
-     * 设备状态;1:在线,0:离线
-     */
-    private Integer deviceStatus;
 
     /**
      * 用户人脸信息记录

+ 0 - 79
service-eg/service-eg-biz/src/main/java/com/usky/eg/domain/EgDeviceHeartbeat.java

@@ -1,79 +0,0 @@
-package com.usky.eg.domain;
-
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableId;
-
-import java.time.LocalDateTime;
-import java.io.Serializable;
-
-import com.fasterxml.jackson.annotation.JsonFormat;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-/**
- * <p>
- * 门禁设备心跳表
- * </p>
- *
- * @author fhs
- * @since 2026-02-03
- */
-@Data
-@EqualsAndHashCode(callSuper = false)
-public class EgDeviceHeartbeat implements Serializable {
-
-    private static final long serialVersionUID = 1L;
-
-    /**
-     * 门禁设备心跳表主键ID
-     */
-    @TableId(value = "id", type = IdType.AUTO)
-    private Integer id;
-
-    /**
-     * 设备code
-     */
-    private String deviceCode;
-
-    /**
-     * 设备ip地址
-     */
-    private String ipAddr;
-
-    /**
-     * 设备mac地址
-     */
-    private String macAddr;
-
-    /**
-     * 设备类型(1.会议屏 2.信息发布屏 3.综合屏)
-     */
-    private Boolean deviceType;
-
-    /**
-     * 创建日期
-     */
-    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
-    private LocalDateTime createTime;
-
-    /**
-     * 设备型号
-     */
-    private String model;
-
-    /**
-     *  设备厂商
-     */
-    private String manuFacturer;
-
-    /**
-     * 设备版本号
-     */
-    private String version;
-
-    /**
-     * 设备sdk
-     */
-    private String sdk;
-
-}

+ 0 - 18
service-eg/service-eg-biz/src/main/java/com/usky/eg/mapper/EgDeviceHeartbeatMapper.java

@@ -1,18 +0,0 @@
-package com.usky.eg.mapper;
-
-import com.usky.eg.domain.EgDeviceHeartbeat;
-import com.usky.common.mybatis.core.CrudMapper;
-import org.springframework.stereotype.Repository;
-
-/**
- * <p>
- * 门禁设备心跳表 Mapper 接口
- * </p>
- *
- * @author fhs
- * @since 2026-02-03
- */
-@Repository
-public interface EgDeviceHeartbeatMapper extends CrudMapper<EgDeviceHeartbeat> {
-
-}

+ 0 - 17
service-eg/service-eg-biz/src/main/java/com/usky/eg/service/EgDeviceHeartbeatService.java

@@ -1,17 +0,0 @@
-package com.usky.eg.service;
-
-import com.usky.eg.domain.EgDeviceHeartbeat;
-import com.usky.common.mybatis.core.CrudService;
-
-/**
- * <p>
- * 门禁设备心跳表 服务类
- * </p>
- *
- * @author fhs
- * @since 2026-02-03
- */
-public interface EgDeviceHeartbeatService extends CrudService<EgDeviceHeartbeat> {
-
-    void heartbeatEscalation(EgDeviceHeartbeat heartbeat);
-}

+ 0 - 50
service-eg/service-eg-biz/src/main/java/com/usky/eg/service/impl/EgDeviceHeartbeatServiceImpl.java

@@ -1,50 +0,0 @@
-package com.usky.eg.service.impl;
-
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
-import com.usky.common.core.exception.BusinessException;
-import com.usky.eg.domain.EgDeviceHeartbeat;
-import com.usky.eg.mapper.EgDeviceHeartbeatMapper;
-import com.usky.eg.service.EgDeviceHeartbeatService;
-import com.usky.common.mybatis.core.AbstractCrudService;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.time.LocalDateTime;
-
-/**
- * <p>
- * 门禁设备心跳表 服务实现类
- * </p>
- *
- * @author fhs
- * @since 2026-02-03
- */
-@Service
-public class EgDeviceHeartbeatServiceImpl extends AbstractCrudService<EgDeviceHeartbeatMapper, EgDeviceHeartbeat> implements EgDeviceHeartbeatService {
-
-    @Transactional(rollbackFor = Exception.class)
-    @Override
-    public void heartbeatEscalation(EgDeviceHeartbeat heartbeat) {
-        if (StringUtils.isBlank(heartbeat.getDeviceCode())) {
-            throw new BusinessException("设备编码不能为空!");
-        }
-        if (StringUtils.isBlank(heartbeat.getIpAddr())) {
-            throw new BusinessException("设备IP不能为空!");
-        }
-        if (heartbeat.getCreateTime() == null) {
-            heartbeat.setCreateTime(LocalDateTime.now());
-        }
-        if (heartbeat.getDeviceType() == null) {
-            throw new BusinessException("设备类型不能为空!");
-        }
-
-        // 删除旧数据
-        LambdaQueryWrapper<EgDeviceHeartbeat> deleteWrapper = Wrappers.lambdaQuery();
-        deleteWrapper.eq(EgDeviceHeartbeat::getDeviceCode, heartbeat.getDeviceCode());
-        baseMapper.delete(deleteWrapper);
-
-        baseMapper.insert(heartbeat);
-    }
-}

+ 38 - 195
service-eg/service-eg-biz/src/main/java/com/usky/eg/service/impl/EgDeviceServiceImpl.java

@@ -13,11 +13,9 @@ import com.usky.common.core.exception.BusinessException;
 import com.usky.common.core.util.UUIDUtils;
 import com.usky.common.security.utils.SecurityUtils;
 import com.usky.eg.domain.EgDevice;
-import com.usky.eg.domain.EgDeviceHeartbeat;
 import com.usky.eg.domain.MeetingFace;
 import com.usky.eg.domain.MeetingFaceDevice;
 import com.usky.eg.mapper.EgDeviceMapper;
-import com.usky.eg.mapper.EgDeviceHeartbeatMapper;
 import com.usky.eg.mapper.MeetingFaceDeviceMapper;
 import com.usky.eg.mapper.MeetingFaceMapper;
 import com.usky.eg.service.EgDeviceService;
@@ -49,8 +47,6 @@ public class EgDeviceServiceImpl extends AbstractCrudService<EgDeviceMapper, EgD
     @Autowired
     private EgDeviceMapper egDeviceMapper;
     @Autowired
-    private EgDeviceHeartbeatMapper egDeviceHeartbeatMapper;
-    @Autowired
     private RemoteIotTaskService remoteIotTaskService;
 
     @Autowired
@@ -59,17 +55,10 @@ public class EgDeviceServiceImpl extends AbstractCrudService<EgDeviceMapper, EgD
     @Override
     public CommonPage<EgDevice> page(EgDeviceRequestVO requestVO){
         IPage<EgDevice> page = new Page<>(requestVO.getCurrent(),requestVO.getSize());
-        Integer tenantId;
+        Integer tenantId ;
 
-        if(StringUtils.isNotBlank(requestVO.getDeviceCode())){
-            LambdaQueryWrapper<EgDevice> tempQueryWrapper = new LambdaQueryWrapper<>();
-            tempQueryWrapper.eq(EgDevice::getDeviceCode, requestVO.getDeviceCode());
-            EgDevice tempDevice = egDeviceMapper.selectOne(tempQueryWrapper);
-            if(tempDevice == null){
-                // 未查询到数据,返回空数组
-                return new CommonPage<>(new ArrayList<>(), 0L, requestVO.getSize(), requestVO.getCurrent());
-            }
-            tenantId = tempDevice.getTenantId();
+        if(StringUtils.isNotBlank(requestVO.getDomain())){
+            tenantId = egDeviceMapper.sysTenantId(requestVO.getDomain());
         }else{
             tenantId = SecurityUtils.getTenantId();
         }
@@ -80,61 +69,10 @@ public class EgDeviceServiceImpl extends AbstractCrudService<EgDeviceMapper, EgD
                 .eq(null != requestVO.getServiceStatus(),EgDevice::getServiceStatus,requestVO.getServiceStatus())
                 .eq(null != requestVO.getId(),EgDevice::getId,requestVO.getId())
                 .eq(null != requestVO.getDeviceUuid(),EgDevice::getDeviceUuid, requestVO.getDeviceUuid())
-                .eq(StringUtils.isNotBlank(requestVO.getDeviceCode()),EgDevice::getDeviceCode, requestVO.getDeviceCode())
                 .eq(EgDevice::getTenantId,tenantId)
                 .orderByDesc(EgDevice::getId);
         page = this.page(page,queryWrapper);
         if(!page.getRecords().isEmpty()){
-            // 检查设备心跳并更新serviceStatus
-            LocalDateTime now = LocalDateTime.now();
-            List<String> validDeviceCodes = new ArrayList<>();
-            for (EgDevice device : page.getRecords()) {
-                if (StringUtils.isNotBlank(device.getDeviceCode())) {
-                    validDeviceCodes.add(device.getDeviceCode());
-                }
-            }
-
-            // 批量查询心跳数据
-            Map<String, LocalDateTime> deviceHeartbeatMap = new HashMap<>();
-            if (!validDeviceCodes.isEmpty()) {
-                LambdaQueryWrapper<EgDeviceHeartbeat> heartbeatQueryWrapper = Wrappers.lambdaQuery();
-                heartbeatQueryWrapper.in(EgDeviceHeartbeat::getDeviceCode, validDeviceCodes)
-                        .orderByDesc(EgDeviceHeartbeat::getCreateTime);
-                List<EgDeviceHeartbeat> heartbeatList = egDeviceHeartbeatMapper.selectList(heartbeatQueryWrapper);
-                
-                // 构建deviceCode到最新心跳时间的映射
-                for (EgDeviceHeartbeat heartbeat : heartbeatList) {
-                    String deviceCode = heartbeat.getDeviceCode();
-                    if (StringUtils.isNotBlank(deviceCode) && heartbeat.getCreateTime() != null) {
-                        // 如果已存在,保留最新的(因为已按createTime降序排列)
-                        deviceHeartbeatMap.putIfAbsent(deviceCode, heartbeat.getCreateTime());
-                    }
-                }
-            }
-
-            // 更新每个设备的deviceStatus并保存到数据库
-            for (EgDevice device : page.getRecords()) {
-                String deviceCode = device.getDeviceCode();
-                Integer newDeviceStatus;
-                if (StringUtils.isNotBlank(deviceCode) && deviceHeartbeatMap.containsKey(deviceCode)) {
-                    LocalDateTime heartbeatTime = deviceHeartbeatMap.get(deviceCode);
-                    // 检查心跳时间是否在5分钟内
-                    if (heartbeatTime != null && heartbeatTime.isAfter(now.minusMinutes(5))) {
-                        newDeviceStatus = 1;
-                    } else {
-                        newDeviceStatus = 0;
-                    }
-                } else {
-                    // 没有心跳记录,设置为离线
-                    newDeviceStatus = 0;
-                }
-                device.setDeviceStatus(newDeviceStatus);
-                // 更新数据库中的deviceStatus
-                EgDevice updateDevice = new EgDevice();
-                updateDevice.setId(device.getId());
-                updateDevice.setDeviceStatus(newDeviceStatus);
-                this.updateById(updateDevice);
-            }
 
             LambdaQueryWrapper<MeetingFace> meetingFaceQuery = Wrappers.lambdaQuery();
             meetingFaceQuery.select(MeetingFace::getFid,MeetingFace::getCreateTime,MeetingFace::getVefNum,MeetingFace::getFaceName,MeetingFace::getRemark,MeetingFace::getFaceStatus,MeetingFace::getCardNum,MeetingFace::getBindDevice,MeetingFace::getDeptId,MeetingFace::getTenantId,MeetingFace::getUserId)
@@ -184,7 +122,7 @@ public class EgDeviceServiceImpl extends AbstractCrudService<EgDeviceMapper, EgD
                     .like(StringUtils.isNotBlank(requestVO.getInstallAddress()),EgDevice::getInstallAddress,requestVO.getInstallAddress())
                     .eq(null != requestVO.getServiceStatus(),EgDevice::getServiceStatus,requestVO.getServiceStatus())
                     .eq(null != requestVO.getId(),EgDevice::getId,requestVO.getId())
-                    .in(EgDevice::getId, (Object[]) deviceFid)
+                    .in(EgDevice::getId,deviceFid)
                     .eq(EgDevice::getTenantId,SecurityUtils.getTenantId())
                     .orderByDesc(EgDevice::getId);
             page = this.page(page,queryWrapper);
@@ -196,53 +134,17 @@ public class EgDeviceServiceImpl extends AbstractCrudService<EgDeviceMapper, EgD
 
     @Override
     public void add(EgDevice egDevice){
-
+        if(checkNameUnique(egDevice)){
+            throw new BusinessException("新增门禁门号设备'"+egDevice.getDeviceId()+","+egDevice.getEgNumber()+"'失败,设备已存在");
+        }
         if(checkDeviceNameUnique(egDevice)){
             throw new BusinessException("新增门禁设备'"+egDevice.getDeviceName()+"'失败,设备已存在");
         }
 
-        // 通过IP校验心跳表中的IP是否一致并且心跳时间必须在五分钟之内
-        if(StringUtils.isNotBlank(egDevice.getDeviceIp())){
-            LambdaQueryWrapper<EgDeviceHeartbeat> heartbeatQueryWrapper = Wrappers.lambdaQuery();
-            heartbeatQueryWrapper.eq(EgDeviceHeartbeat::getIpAddr, egDevice.getDeviceIp())
-                    .orderByDesc(EgDeviceHeartbeat::getCreateTime)
-                    .last("LIMIT 1");
-            EgDeviceHeartbeat heartbeat = egDeviceHeartbeatMapper.selectOne(heartbeatQueryWrapper);
-            
-            // 如果找不到心跳记录,抛出异常
-            if(heartbeat == null){
-                throw new BusinessException("设备不在线,请检查设备网络是否正常!");
-            }
-            
-            // 检查心跳时间是否在5分钟内
-            LocalDateTime now = LocalDateTime.now();
-            LocalDateTime heartbeatTime = heartbeat.getCreateTime();
-            if(heartbeatTime == null || !heartbeatTime.isAfter(now.minusMinutes(5))){
-                throw new BusinessException("设备不在线,请检查设备网络是否正常!");
-            }
-            
-            // 校验通过,设置device_code和device_status=1
-            egDevice.setDeviceCode(heartbeat.getDeviceCode());
-            egDevice.setDeviceStatus(1);
-            
-            // 校验DeviceCode是否已经被其他设备使用
-            if(StringUtils.isNotBlank(egDevice.getDeviceCode())){
-                LambdaQueryWrapper<EgDevice> deviceCodeCheckQueryWrapper = Wrappers.lambdaQuery();
-                deviceCodeCheckQueryWrapper.eq(EgDevice::getDeviceCode, egDevice.getDeviceCode())
-                        .eq(EgDevice::getTenantId, SecurityUtils.getTenantId());
-                EgDevice existingDevice = this.getOne(deviceCodeCheckQueryWrapper);
-                if(existingDevice != null){
-                    throw new BusinessException("设备已被设备'" + existingDevice.getDeviceName() + "'注册使用,请检查设备配置或更换设备IP!");
-                }
-            }
-        }
-
         egDevice.setDeviceUuid(UUIDUtils.uuid());
         egDevice.setCreateBy(SecurityUtils.getUsername());
         egDevice.setCreateTime(LocalDateTime.now());
         egDevice.setTenantId(SecurityUtils.getTenantId());
-        egDevice.setOpenMode("人脸");// 设置开门方式为人脸
-        egDevice.setWorkStatus("4");// 设置工作状态为4
 
         this.save(egDevice);
 
@@ -256,24 +158,7 @@ public class EgDeviceServiceImpl extends AbstractCrudService<EgDeviceMapper, EgD
             }
         }
 
-        // 调用远程服务添加设备信息,添加异常处理
-        try {
-            String deviceId = egDevice.getDeviceUuid();
-            if(StringUtils.isNotBlank(egDevice.getEgNumber())){
-                deviceId = egDevice.getDeviceUuid() + egDevice.getEgNumber();
-            }
-            // 确保必要参数不为空
-            if(StringUtils.isNotBlank(egDevice.getDeviceUuid()) && StringUtils.isNotBlank(deviceId) 
-                    && StringUtils.isNotBlank(egDevice.getDeviceName())){
-                remoteIotTaskService.addDeviceInfo("502_USKY", egDevice.getDeviceUuid(), deviceId, 
-                        egDevice.getDeviceName(), 
-                        egDevice.getInstallAddress() != null ? egDevice.getInstallAddress() : "", 
-                        egDevice.getServiceStatus() != null ? egDevice.getServiceStatus() : 1);
-            }
-        } catch (Exception e) {
-            // 远程服务调用失败,不抛出异常,允许设备保存成功
-            // 远程服务调用失败可以通过其他方式补偿
-        }
+        remoteIotTaskService.addDeviceInfo("502_USKY", egDevice.getDeviceUuid(),egDevice.getDeviceId()+egDevice.getEgNumber(),egDevice.getDeviceName(),egDevice.getInstallAddress(),egDevice.getServiceStatus());
     }
 
     @Override
@@ -294,47 +179,14 @@ public class EgDeviceServiceImpl extends AbstractCrudService<EgDeviceMapper, EgD
             }
         }
 
+
+        if(checkNameUnique(egDevice)){
+            throw new BusinessException("修改门禁门号设备'"+egDevice.getDeviceId()+","+egDevice.getEgNumber()+"'失败,设备已存在");
+        }
         if(checkDeviceNameUnique(egDevice)){
             throw new BusinessException("新增门禁设备'"+egDevice.getDeviceName()+"'失败,设备已存在");
         }
 
-        // 通过IP校验心跳表中的IP是否一致并且心跳时间必须在五分钟之内
-        if(StringUtils.isNotBlank(egDevice.getDeviceIp())){
-            LambdaQueryWrapper<EgDeviceHeartbeat> heartbeatQueryWrapper = Wrappers.lambdaQuery();
-            heartbeatQueryWrapper.eq(EgDeviceHeartbeat::getIpAddr, egDevice.getDeviceIp())
-                    .orderByDesc(EgDeviceHeartbeat::getCreateTime)
-                    .last("LIMIT 1");
-            EgDeviceHeartbeat heartbeat = egDeviceHeartbeatMapper.selectOne(heartbeatQueryWrapper);
-            
-            // 如果找不到心跳记录,抛出异常
-            if(heartbeat == null){
-                throw new BusinessException("设备不在线,请检查设备网络是否正常!");
-            }
-            
-            // 检查心跳时间是否在5分钟内
-            LocalDateTime now = LocalDateTime.now();
-            LocalDateTime heartbeatTime = heartbeat.getCreateTime();
-            if(heartbeatTime == null || !heartbeatTime.isAfter(now.minusMinutes(5))){
-                throw new BusinessException("设备不在线,请检查设备网络是否正常!");
-            }
-            
-            // 校验通过,设置device_code和device_status=1
-            egDevice.setDeviceCode(heartbeat.getDeviceCode());
-            egDevice.setDeviceStatus(1);
-            
-            // 校验DeviceCode是否已经被其他设备使用(排除当前设备自己)
-            if(StringUtils.isNotBlank(egDevice.getDeviceCode())){
-                LambdaQueryWrapper<EgDevice> deviceCodeCheckQueryWrapper = Wrappers.lambdaQuery();
-                deviceCodeCheckQueryWrapper.eq(EgDevice::getDeviceCode, egDevice.getDeviceCode())
-                        .eq(EgDevice::getTenantId, SecurityUtils.getTenantId())
-                        .ne(EgDevice::getId, egDevice.getId());
-                EgDevice existingDevice = this.getOne(deviceCodeCheckQueryWrapper);
-                if(existingDevice != null){
-                    throw new BusinessException("设备编码'" + egDevice.getDeviceCode() + "'已被设备'" + existingDevice.getDeviceName() + "'使用,请检查设备配置");
-                }
-            }
-        }
-
         egDevice.setUpdateBy(SecurityUtils.getUsername());
         egDevice.setUpdateTime(LocalDateTime.now());
 
@@ -347,7 +199,9 @@ public class EgDeviceServiceImpl extends AbstractCrudService<EgDeviceMapper, EgD
         EgDevice one = this.getById(egDevice.getId());
         egDevice.setBindFace(one.getBindFace());
 
-
+        if(checkNameUnique(egDevice)){
+            throw new BusinessException("更新门禁设备附加功能'"+egDevice.getDeviceId()+"'失败,设备已存在");
+        }
         if(checkDeviceNameUnique(egDevice)){
             throw new BusinessException("新增门禁设备'"+egDevice.getDeviceName()+"'失败,设备已存在");
         }
@@ -372,14 +226,7 @@ public class EgDeviceServiceImpl extends AbstractCrudService<EgDeviceMapper, EgD
 
         this.removeById(id);
 
-        // 调用远程服务删除设备信息,静默处理,失败不影响删除功能
-        try {
-            if(StringUtils.isNotBlank(egDevice.getDeviceUuid())){
-                remoteIotTaskService.deleteDeviceInfo(egDevice.getDeviceUuid());
-            }
-        } catch (Exception e) {
-            // 远程服务调用失败,静默处理,不影响设备删除
-        }
+        remoteIotTaskService.deleteDeviceInfo(egDevice.getDeviceUuid());
     }
 
     @Override
@@ -408,21 +255,10 @@ public class EgDeviceServiceImpl extends AbstractCrudService<EgDeviceMapper, EgD
         Integer tenantId;
         long commandUserId;
         String commandUserName;
-        EgDevice device = null;
-        
-        // 通过deviceUuid查询设备获取tenantId
-        if(StringUtils.isNotBlank(deviceUuid)){
-            LambdaQueryWrapper<EgDevice> deviceQueryWrapper = Wrappers.lambdaQuery();
-            deviceQueryWrapper.select(EgDevice::getId, EgDevice::getTenantId)
-                    .eq(EgDevice::getDeviceUuid, deviceUuid);
-            device = this.getOne(deviceQueryWrapper);
-            if(device != null){
-                tenantId = device.getTenantId();
-                commandUserId = userId;
-                commandUserName = userName;
-            }else{
-                throw new BusinessException("设备未注册,请先注册");
-            }
+        if(StringUtils.isNotBlank(domain)){
+            tenantId = baseMapper.sysTenantId(domain);
+            commandUserId = userId;
+            commandUserName = userName;
         }else{
             tenantId = SecurityUtils.getTenantId();
             commandUserId = SecurityUtils.getUserId();
@@ -430,22 +266,29 @@ public class EgDeviceServiceImpl extends AbstractCrudService<EgDeviceMapper, EgD
         }
 
         //人员设备权限校验,校验通过,可以下发命令控制设备
-        if(device != null){
-            Integer fid = baseMapper.getMeetingFaceData(commandUserId);
-            if(fid == null){
-                throw new BusinessException("人脸卡号信息未注册");
-            }
-            Integer[] deviceFid = baseMapper.getMeetingFaceDeviceList(fid);
-            if(deviceFid.length == 0){
-                throw new BusinessException("人员未绑定设备,请检查");
-            }
-            
-            boolean exist = Arrays.asList(deviceFid).contains(device.getId());
+        Integer fid = baseMapper.getMeetingFaceData(commandUserId);
+        if(fid == null){
+            throw new BusinessException("人脸卡号信息未注册");
+        }
+        Integer[] deviceFid = baseMapper.getMeetingFaceDeviceList(fid);
+        if(deviceFid.length == 0){
+            throw new BusinessException("人员未绑定设备,请检查");
+        }
+
+        LambdaQueryWrapper<EgDevice> queryWrapper = Wrappers.lambdaQuery();
+        queryWrapper.select(EgDevice::getId)
+                .eq(EgDevice::getDeviceUuid,deviceUuid);
+        EgDevice one = this.getOne(queryWrapper);
+        if(one != null){
+            boolean exist = Arrays.asList(deviceFid).contains(one.getId());
             if(!exist){
                 throw new BusinessException("暂无权限");
             }
+        }else{
+            throw new BusinessException("设备未注册,请先注册");
         }
 
+
         Map<String,Object> map = new HashMap<>();
         map.put("method","control");
         map.put("deviceUuid", deviceUuid);

+ 9 - 17
service-eg/service-eg-biz/src/main/java/com/usky/eg/service/impl/EgRecordServiceImpl.java

@@ -47,31 +47,23 @@ public class EgRecordServiceImpl extends AbstractCrudService<EgRecordMapper, EgR
     @Override
     public void add(EgRecord egRecord){
         Integer tenantId;
-        
-        // 通过deviceUuid查询设备获取tenantId
+        if(StringUtils.isNotBlank(egRecord.getDomain())){
+            tenantId = egDeviceMapper.sysTenantId(egRecord.getDomain());
+        }else{
+            tenantId = SecurityUtils.getTenantId();
+        }
+
         LambdaQueryWrapper<EgDevice> queryWrapper = Wrappers.lambdaQuery();
         if(StringUtils.isBlank(egRecord.getDeviceUuid())){
             throw new BusinessException("设备Uuid不能为空");
         }
-        queryWrapper.select(EgDevice::getId, EgDevice::getTenantId)
-                .eq(EgDevice::getDeviceUuid,egRecord.getDeviceUuid());
+        queryWrapper.eq(EgDevice::getDeviceUuid,egRecord.getDeviceUuid());
         EgDevice one = egDeviceService.getOne(queryWrapper);
-        if(one == null){
-            throw new BusinessException("设备未注册,请先注册");
-        }
-        tenantId = one.getTenantId();
         egRecord.setEgDeviceId(one.getId());
+
         egRecord.setCreateTime(LocalDateTime.now());
         egRecord.setTenantId(tenantId);
-        
-        // 安全获取部门ID
-        Integer deptId = null;
-        if(SecurityUtils.getLoginUser() != null 
-                && SecurityUtils.getLoginUser().getSysUser() != null 
-                && SecurityUtils.getLoginUser().getSysUser().getDeptId() != null){
-            deptId = SecurityUtils.getLoginUser().getSysUser().getDeptId().intValue();
-        }
-        egRecord.setDeptId(deptId);
+        egRecord.setDeptId(SecurityUtils.getLoginUser().getSysUser().getDeptId().intValue());
 
         this.save(egRecord);
     }

+ 0 - 5
service-eg/service-eg-biz/src/main/java/com/usky/eg/service/vo/EgDeviceRequestVO.java

@@ -45,9 +45,4 @@ public class EgDeviceRequestVO implements Serializable {
      * 设备uuid
      */
     private String deviceUuid;
-
-    /**
-     * 设备code
-     */
-    private String deviceCode;
 }

+ 0 - 19
service-eg/service-eg-biz/src/main/resources/mapper/eg/EgDeviceHeartbeatMapper.xml

@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.usky.eg.mapper.EgDeviceHeartbeatMapper">
-
-    <!-- 通用查询映射结果 -->
-    <resultMap id="BaseResultMap" type="com.usky.eg.domain.EgDeviceHeartbeat">
-        <id column="id" property="id"/>
-        <result column="device_code" property="deviceCode"/>
-        <result column="ip_addr" property="ipAddr"/>
-        <result column="mac_addr" property="macAddr"/>
-        <result column="device_type" property="deviceType"/>
-        <result column="create_time" property="createTime"/>
-        <result column="model" property="model"/>
-        <result column="manu_facturer"  property="manuFacturer"/>
-        <result column="version" property="version"/>
-        <result column="sdk" property="sdk"/>
-    </resultMap>
-
-</mapper>