Browse Source

完善一体化登录物联网平台

hym 3 years ago
parent
commit
d88b60af95

+ 1 - 0
user_auth/src/main/java/com/huaxu/service/impl/UserServiceImpl.java

@@ -236,6 +236,7 @@ public class UserServiceImpl implements UserService {
         String key = null;
         try {
             // 验证加密的内容是否正确
+            encryptValue=encryptValue.replaceAll(" ","+");
             key = DESUtil.decrypt(encryptValue,appSecret);
             // 截取里面的时间
             String date = key.substring(key.lastIndexOf("_") + 1, key.length());

+ 4 - 0
user_center/src/main/java/com/huaxu/entity/UserEntity.java

@@ -111,6 +111,9 @@ public class UserEntity implements Serializable {
     /** 备注 */
     @ApiModelProperty(value = "备注")
     private String remark;
+    /** 备注 */
+    @ApiModelProperty(value = "平台用户唯一id")
+    private String uniqId;
 
     /** 用户角色 */
     @ApiModelProperty(value = "用户角色")
@@ -133,4 +136,5 @@ public class UserEntity implements Serializable {
     @ApiModelProperty(value="用户权限类型")
     @TableField(exist = false)
     private Integer permissonType;
+
 }

+ 31 - 0
user_center/src/main/java/com/huaxu/service/UserService.java

@@ -1,6 +1,7 @@
 package com.huaxu.service;
 
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.huaxu.common.ToolUtil;
 import com.huaxu.dao.OrgMapper;
@@ -16,12 +17,18 @@ import com.huaxu.util.ByteArrayUtils;
 import com.huaxu.util.RedisUtil;
 import com.huaxu.util.UserUtil;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import javax.annotation.Resource;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.client.RestTemplate;
 
 import java.util.*;
 import java.util.stream.Collectors;
@@ -45,6 +52,8 @@ public class UserService extends ServiceImpl<UserMapper,UserEntity> {
 	private OrgMapper orgMapper;
 	@Autowired
 	private RedisUtil redisUtil;
+	@Value("${add_iot_user_url}")
+	private String addIotUserUrl;
 
 	/**
 	 * 自定义分页查询,含关联实体对像
@@ -135,6 +144,7 @@ public class UserService extends ServiceImpl<UserMapper,UserEntity> {
 	 * 保存
 	 */
 	public boolean addUser(UserEntity user) {
+		user.setUniqId(UUID.randomUUID().toString());
 		if (this.save(user)) {
 			Long pkId = user.getId();
 			//添加用户标签
@@ -163,9 +173,30 @@ public class UserService extends ServiceImpl<UserMapper,UserEntity> {
 				userRoleEntity.setUserId(pkId);
 				userRoleService.addUserRole(userRoleEntity);
 			}
+			addIotUser(user);
 			return true;
 		}
 		return false;
+	}
+	private void addIotUser(UserEntity userEntity){
+		try {
+			HttpHeaders headers = new HttpHeaders();
+			JSONObject args=new JSONObject();
+			args.put("username",userEntity.getUsername());
+			args.put("mobilePhone",userEntity.getPhone());
+			args.put("tenantId",userEntity.getTenantId());
+			args.put("uniqId",userEntity.getUniqId());
+			headers.setContentType(MediaType.APPLICATION_JSON);
+			HttpEntity<String> formEntity = new HttpEntity<>(args.toJSONString(), headers);
+
+			RestTemplate restTemplate=new RestTemplate();
+			restTemplate.postForEntity(addIotUserUrl, formEntity,String.class);
+		 }catch (Exception e){
+			log.error("添加物联网用户失败",e);
+		}
+
+
+
 	}
 
 	/**

+ 3 - 4
user_center/src/main/resources/application-dev.properties

@@ -84,13 +84,12 @@ dispath.routing.key=dipathKey
 ribbon.OkToRetryOnAllOperations=false
 ribbon.ReadTimeout=5000:
 ribbon.ConnectTimeout=3000
-
-
-
 # 设置 feign 客户端超时时间(OpenFeign 默认支持 ribbon)
 # 值的是建立连接所用的时间,使用与网络状态正常的情况,两端连接所用的时间
-ribbon.ReadTimeout=5000
+
 # 指的是建立连接后从服务器读取到可用资源所用的时间
 ribbon.ConnectionTimeout=5000
+add_iot_user_url=http://localhost:8090/api/integration/user/savePlatformUser
+
 
 

+ 1 - 1
user_center/src/main/resources/application-sit.properties

@@ -79,7 +79,7 @@ spring.rabbitmq.template.mandatory=true
 receive.exchange.name=messageExchangeTest
 dispath.routing.key=dipathKeyTest1
 dispath.queue=dispathTest1
-
+add_iot_user_url=http://114.135.61.188:58080/api/integration/user/savePlatformUser