Kaynağa Gözat

Merge remote-tracking branch 'origin/V0.1.1' into V0.1.1

jingyuanchao 1 yıl önce
ebeveyn
işleme
d147043320

+ 3 - 0
soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/dao/HostInfoDao.java

@@ -6,6 +6,7 @@ import com.xunmei.deploy.domain.AppInfo;
 import com.xunmei.deploy.domain.HostInfo;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.xunmei.deploy.vo.HostInfoVo;
+import com.xunmei.deploy.vo.IotServerInfoVo;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
@@ -35,4 +36,6 @@ public interface HostInfoDao extends BaseMapper<HostInfo> {
 
     //白令海版本升级-列表
     IPage<HostInfoVo> selectPage(Page<HostInfo> page, @Param("info") HostInfoVo hostInfoVo);
+
+    IotServerInfoVo getIoTServerInfoByIotCode(@Param("iotCode") String iotCode);
 }

+ 8 - 15
soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/service/impl/BeringServiceImpl.java

@@ -15,10 +15,7 @@ import com.xunmei.deploy.service.FrontTaskService;
 import com.xunmei.deploy.util.RedisPrefix;
 import com.xunmei.deploy.util.RedisTemplateUtil;
 import com.xunmei.deploy.util.UTCTimeUtils;
-import com.xunmei.deploy.vo.MachineInfo;
-import com.xunmei.deploy.vo.OrgVo;
-import com.xunmei.deploy.vo.TokenCache;
-import com.xunmei.deploy.vo.TokenVo;
+import com.xunmei.deploy.vo.*;
 import com.xunmei.deploy.vo.heart.AppRunningInfo;
 import com.xunmei.deploy.vo.heart.HeartBeat;
 import com.xunmei.deploy.vo.heart.HeartResponse;
@@ -99,22 +96,18 @@ public class BeringServiceImpl  extends ServiceImpl<HostInfoDao, HostInfo> imple
             throw new ServerException("主机获取令牌失败:请求参数认证类型错误!");
         }
 
-        //验证秘钥是否合法
         List<String> macs = machineInfo.getMacs();
-        if (null == macs || macs.size() <= 0){
+        if (null == macs || macs.size() == 0){
             logger.error("主机获取令牌失败:传入machineInfo内macs数组为空!");
             throw new ServerException("主机获取令牌失败:计算机macs信息不能为空!");
         }
-
         Collections.sort(macs);
-        String macsStr = StringUtils.join(macs.toArray(), "");
-        String str = macsStr + "zmoon";
 
-        //md5加密--->按照生成规则生成后的秘钥
-        String code = DigestUtils.md5DigestAsHex(str.getBytes());
+        //验证秘钥在iot_server_info表中对应iot_code是否存在
         String clientSecret = tokenVo.getClient_secret();
-        if(!code.equals(clientSecret)){
-            logger.error("主机获取令牌失败:client_secret={}与machineInfo内macs数组解析算法不一致!",clientSecret);
+        IotServerInfoVo iotServerInfoVo = baseMapper.getIoTServerInfoByIotCode(clientSecret);
+        if (iotServerInfoVo == null){
+            logger.error("主机获取令牌失败:client_secret={}在iot_server_info表中对应iot_code不存在!",clientSecret);
             throw new ServerException("主机获取令牌失败:主机秘钥认证失败!");
         }
 
@@ -135,7 +128,7 @@ public class BeringServiceImpl  extends ServiceImpl<HostInfoDao, HostInfo> imple
             if ("1".equals(sysConf.getConfigValue())){
                 logger.info("主机获取令牌:程序允许主机重新注册,开始注册\n{}",clientSecret,JSON.toJSONString(machineInfo));
                 hostInfo = new HostInfo();
-                hostInfo.setId(code);
+                hostInfo.setId(clientSecret);
                 hostInfo.setHostName(machineInfo.getMachineName());
                 hostInfo.setHostIp(StringUtils.join(machineInfo.getIpAddresses().toArray(),","));
                 hostInfo.setHostSystem(machineInfo.getOsPlatform());
@@ -148,7 +141,7 @@ public class BeringServiceImpl  extends ServiceImpl<HostInfoDao, HostInfo> imple
 
                 //删除frontTask中数据
                 QueryWrapper<FrontTask> wrapper = new QueryWrapper<>();
-                wrapper.eq("host_id",code);
+                wrapper.eq("host_id",clientSecret);
                 frontTaskDao.delete(wrapper);
 
                 //添加缓存信息

+ 6 - 10
soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/service/impl/HostInfoServiceImpl.java

@@ -36,7 +36,6 @@ public class HostInfoServiceImpl extends ServiceImpl<HostInfoDao, HostInfo> impl
     private UpgradeBatchInfoDao upgradeBatchInfoDao;
     @Autowired
     private OperationLogDao operationLogDao;
-
     @Resource
     private RedisTemplateUtil redisTemplateUtil;
 
@@ -76,19 +75,16 @@ public class HostInfoServiceImpl extends ServiceImpl<HostInfoDao, HostInfo> impl
                 logger.error("主机节点注册:删除主机相关表出错:{}",e);
             }
         }
-        //3.不存在,验证注册码是否合法
-        //排序mac
-        Collections.sort(macs);
-        String macsStr = StringUtils.join(macs.toArray(), "");
-        String str = macsStr + "zmoon";
-        String code = DigestUtils.md5DigestAsHex(str.getBytes());
-        if(!code.equals(registerCode)){
-            logger.error("主机节点注册失败:code={}与machineInfo内macs数组解析算法不一致!",registerCode);
+        //3.不存在,验证注册码是否合法(判断在iotServer那个表里有没有唯一标识)
+        IotServerInfoVo iotServerInfoVo = baseMapper.getIoTServerInfoByIotCode(registerCode);
+        if (iotServerInfoVo == null){
+            logger.error("主机节点注册失败:registerCode={}在iot_server_info表中对应iot_code不存在!",registerCode);
             throw new RuntimeException("主机节点注册失败:无效的注册码!");
         }
+
         // 4. 注册码合法,合法后保存数据库,且更新缓存数据
         hostInfo = new HostInfo();
-        hostInfo.setId(code);
+        hostInfo.setId(registerCode);
         hostInfo.setHostName(machineInfo.getMachineName());
         hostInfo.setHostIp(StringUtils.join(machineInfo.getIpAddresses().toArray(),","));
         hostInfo.setHostSystem(machineInfo.getOsPlatform());

+ 82 - 0
soc-modules/soc-modules-deploy/src/main/java/com/xunmei/deploy/vo/IotServerInfoVo.java

@@ -0,0 +1,82 @@
+package com.xunmei.deploy.vo;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.xunmei.common.core.constant.Constants;
+import com.xunmei.common.core.enums.iot.IotServerConnectStatus;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+/**
+ * <p>
+ * iot客户端信息
+ * </p>
+ *
+ * @author
+ * @since 2024-07-18
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@TableName("iot_server_info")
+@ApiModel(value="IotServerInfo对象", description="iot客户端信息")
+public class IotServerInfoVo implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty(value = "主键")
+    private Long id;
+
+    @ApiModelProperty(value = "名称")
+    private String iotName;
+
+    @ApiModelProperty(value = "服务编码(全局唯一)")
+    private String iotCode;
+
+    @ApiModelProperty(value = "组织机构id")
+    private Long orgId;
+
+    @ApiModelProperty(value = "组织机构名称")
+    private String orgName;
+
+    @ApiModelProperty(value = "组织机构路径")
+    private String orgPath;
+
+    /**
+     * @see IotServerConnectStatus
+     */
+    @ApiModelProperty(value = "链接状态:0:未知(未启用),1:在线,2:离线")
+    private int iotStatus;
+
+    @JsonFormat(pattern = Constants.HMS_FORMAT)
+    @ApiModelProperty(value = "最近一次链接时间")
+    private LocalDateTime lastConnectTime;
+
+    @ApiModelProperty(value = "ip地址")
+    private String iotIp;
+
+    @ApiModelProperty(value = "临时注册码")
+    private String registerCode;
+
+    @ApiModelProperty(value = "临时注册码状态",notes = "0:未使用,1:已使用")
+    private Integer registerCodeStatus;
+
+    @ApiModelProperty(value = "创建人")
+    private String createBy;
+
+    @ApiModelProperty(value = "创建时间")
+    private LocalDateTime createTime;
+
+    @ApiModelProperty(value = "修改人")
+    private String updateBy;
+
+    @ApiModelProperty(value = "修改时间")
+    private LocalDateTime updateTime;
+
+
+}

+ 3 - 0
soc-modules/soc-modules-deploy/src/main/resources/mapper/HostInfoDao.xml

@@ -184,5 +184,8 @@
             </if>
         </where>
     </select>
+    <select id="getIoTServerInfoByIotCode" resultType="com.xunmei.deploy.vo.IotServerInfoVo">
+        select * from iot_server_info where iot_code = #{iotCode}
+    </select>
 
 </mapper>