wulianwei 1 tahun lalu
induk
melakukan
f13f73c4e5

+ 10 - 1
src/main/java/com/tuoren/forward/config/amqp/AmqpClient1.java

@@ -217,6 +217,13 @@ public class AmqpClient1 {
             JSONObject localJson = null;
      
             String hospitalCode = !items.containsKey("userId") ? "" : items.getString("userId");
+            String alias = "";
+            JSONObject remoteHospital = remoteUtil.getHospitalInfo(deviceName);
+            if(remoteHospital != null) {
+        		hospitalCode = remoteHospital.getString("hospitalCode");
+        		alias = remoteHospital.getString("alias");
+        		items.put("alias", alias);
+        	}
             String tenentId = "";
             User owner = null;
             if(!StringUtils.isEmpty(hospitalCode)) {
@@ -248,6 +255,7 @@ public class AmqpClient1 {
     			record.setMac(deviceName);
     			record.setProductId(productKey);
     			record.setTenantId(tenentId);
+    			record.setAlias(alias);
     			if(localJson != null) {
     				record.setLat(localJson.getString("lat"));
     				record.setLng(localJson.getString("lng"));
@@ -263,6 +271,7 @@ public class AmqpClient1 {
     			record.setModifytime(date);
     			record.setProductId(productKey);
     			record.setTenantId(tenentId);
+    			record.setAlias(alias);
     			if(localJson != null) {
     				record.setLat(localJson.getString("lat"));
     				record.setLng(localJson.getString("lng"));
@@ -309,7 +318,7 @@ public class AmqpClient1 {
     			log.info("mqtt publish1:"+  mqttJson.toString());
     			if(owner != null) {
     				DevConfig config = devConfigMapper.selectByPrimaryKey(owner.getId());
-    				if(!StringUtils.isEmpty(config.getMqttTopic())) {
+    				if(config!=null && !StringUtils.isEmpty(config.getMqttTopic())) {
     					String[] topics = config.getMqttTopic().split(",");
     					for(String t : topics) {
 //    						MqTick mt = mqTickMapper.selectOnlineByTopic(t);

+ 10 - 2
src/main/java/com/tuoren/forward/config/amqp/AmqpClient2.java

@@ -217,8 +217,14 @@ public class AmqpClient2 {
             JSONObject localJson = null;
      
             String hospitalCode = !items.containsKey("userId") ? "" : items.getString("userId");
+            String alias = "";
+            JSONObject remoteHospital = remoteUtil.getHospitalInfo(deviceName);
+            if(remoteHospital != null) {
+        		hospitalCode = remoteHospital.getString("hospitalCode");
+        		alias = remoteHospital.getString("alias");
+        		items.put("alias", alias);
+        	}
             if(StringUtils.isEmpty(hospitalCode)) {
-            	hospitalCode = remoteUtil.getHospitalCode(deviceName);
             	if(StringUtils.isEmpty(hospitalCode)) {
   				  log.info("设备没有对应医院:"+deviceName);
   				 // return;
@@ -256,6 +262,7 @@ public class AmqpClient2 {
     			record.setMac(deviceName);
     			record.setProductId(productKey);
     			record.setTenantId(tenentId);
+    			record.setAlias(alias);
     			if(localJson != null) {
     				record.setLat(localJson.getString("lat"));
     				record.setLng(localJson.getString("lng"));
@@ -271,6 +278,7 @@ public class AmqpClient2 {
     			record.setModifytime(date);
     			record.setProductId(productKey);
     			record.setTenantId(tenentId);
+    			record.setAlias(alias);
     			if(localJson != null) {
     				record.setLat(localJson.getString("lat"));
     				record.setLng(localJson.getString("lng"));
@@ -317,7 +325,7 @@ public class AmqpClient2 {
     			log.info("mqtt publish2:"+  mqttJson.toString());
     			if(owner != null) {
     				DevConfig config = devConfigMapper.selectByPrimaryKey(owner.getId());
-    				if(!StringUtils.isEmpty(config.getMqttTopic())) {
+    				if(config!=null && !StringUtils.isEmpty(config.getMqttTopic())) {
     					String[] topics = config.getMqttTopic().split(",");
     					for(String t : topics) {
 //    						MqTick mt = mqTickMapper.selectOnlineByTopic(t);

+ 3 - 0
src/main/java/com/tuoren/forward/entity/Device.java

@@ -15,6 +15,9 @@ public class Device {
 
     @Schema(description = "设备名称")
     private String name;
+    
+    @Schema(description = "设备别名")
+    private String alias;
 
     @Schema(description = "是否删除:, '0':未删除.’'1' 删除")
     private String isDelete;

+ 4 - 3
src/main/java/com/tuoren/forward/util/RemoteUtil.java

@@ -10,6 +10,7 @@ import org.springframework.util.LinkedMultiValueMap;
 import org.springframework.util.MultiValueMap;
 import org.springframework.web.client.RestTemplate;
 
+import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
 
@@ -89,16 +90,16 @@ public class RemoteUtil {
 	}
 
 	
-	public String getHospitalCode(String mac) {
+	public JSONObject getHospitalInfo(String mac) {
 
 	    HttpEntity<String> request = new HttpEntity<String>(mac);
 		String result = restTemplate.postForObject(hospitalCodeAddress, request, String.class);
 		System.out.println("result========="+result);
 		JSONObject json = JSONObject.parseObject(result);
 		if(json.containsKey("data")) {
-			return json.getString("data");
+			return json.getJSONObject("data");
 		}
-		return "";
+		return null;
 	}
 
 }

+ 9 - 9
src/main/resources/application.yml

@@ -95,18 +95,18 @@ mqtt:
 #阿里云配置
 aliyun1: 
   enable: true
-  accessKey: LTAI5tRaK95AqvWiQ9LspZ3q
-  accessSecret: wZUpYGeztNcV4tGbBLfK2OvxnZzZF3
-  consumerGroupId: 0na0olXpWEmWgMucxIH1000100
-  iotInstanceId: iot-06z00hi2guq5qi3
+  accessKey: LTAI4G7FA9ytMc76oNkJ45YJ
+  accessSecret: R7hOvMfiHb0PYroDqUDXAYgB9htQss
+  consumerGroupId: u3mShumaQA0Yyk3gfQM5000100
+  iotInstanceId: iot-060a0bgd
   clientId: fe80aba1dfd66b3576ce
-  amqpHost: iot-06z00hi2guq5qi3.amqp.iothub.aliyuncs.com
+  amqpHost: iot-060a0bgd.amqp.iothub.aliyuncs.com
   
 aliyun2: 
   enable: true
   accessKey: LTAI4G7FA9ytMc76oNkJ45YJ
   accessSecret: R7hOvMfiHb0PYroDqUDXAYgB9htQss
-  consumerGroupId: AQ2Lk4saOGHYWBzJa39c000100
+  consumerGroupId: RJeEjZ6TroTZ5TDrdRYP000100
   iotInstanceId: iot-060a0bgd
   clientId: fe80aba1dfd66b3576ce
   amqpHost: iot-060a0bgd.amqp.iothub.aliyuncs.com
@@ -121,7 +121,7 @@ handleLog:
   enable: true   #是否记录请求操作
 #pca获取医院编码地址
 remote:
-  hospitalCodeAddress: https://pca.tuoren.com:9090/api/bus/device/info/hospitalCode
+  hospitalCodeAddress: https://pca.tuoren.com:9090/api/bus/device/info/hospitalCodeAndAlias
   h5Address: https://iot.tuoren.com/wap
 
 #测试环境
@@ -210,7 +210,7 @@ handleLog:
   enable: true   #是否记录请求操作
 #pca获取医院编码地址
 remote:
-  hospitalCodeAddress: https://pca.tuoren.com:9090/api/bus/device/info/hospitalCode
+  hospitalCodeAddress: https://pca.tuoren.com:9090/api/bus/device/info/hospitalCodeAndAlias
   h5Address: https://iot.tuoren.com/wap
 
   
@@ -304,5 +304,5 @@ handleLog:
 
 #pca获取医院编码地址
 remote:
-  hospitalCodeAddress: https://pca.tuoren.com:9090/api/bus/device/info/hospitalCode
+  hospitalCodeAddress: https://pca.tuoren.com:9090/api/bus/device/info/hospitalCodeAndAlias
   h5Address: https://iot.tuoren.com/wap

+ 4 - 0
src/main/resources/db/migration/V1.0.1__dev_config.sql

@@ -20,3 +20,7 @@ CREATE TABLE `mq_tick` (
   PRIMARY KEY (`id`),
   UNIQUE KEY `topic_UNIQUE` (`topic`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='消息队列主题心跳'
+
+
+ALTER TABLE `forward`.`device` 
+CHANGE COLUMN `` `alias` VARCHAR(45) NULL COMMENT '设备别名' ;

+ 18 - 3
src/main/resources/mapper/DeviceMapper.xml

@@ -5,6 +5,7 @@
     <id column="id" jdbcType="VARCHAR" property="id" />
     <result column="mac" jdbcType="VARCHAR" property="mac" />
     <result column="name" jdbcType="VARCHAR" property="name" />
+    <result column="alias" jdbcType="VARCHAR" property="alias" />
     <result column="is_delete" jdbcType="CHAR" property="isDelete" />
     <result column="product_id" jdbcType="VARCHAR" property="productId" />
     <result column="description" jdbcType="VARCHAR" property="description" />
@@ -27,7 +28,7 @@
     data
   </sql>
   <sql id="Base_Column_Relation">
-    d.id, d.mac, d.name, d.is_delete isDelete, d.product_id productId, d.description, d.createtime, d.modifytime, 
+    d.id, d.mac, d.name, d.alias,d.is_delete isDelete, d.product_id productId, d.description, d.createtime, d.modifytime, 
     d.tenant_id tenantId, d.data
   </sql>
   <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="ResultMapWithBLOBs">
@@ -99,12 +100,12 @@
     where id = #{id,jdbcType=VARCHAR}
   </delete>
   <insert id="insert" parameterType="com.tuoren.forward.entity.Device">
-    insert into device (id, mac, name, 
+    insert into device (id, mac, name, alias,
       is_delete, product_id, description, 
       createtime, modifytime, tenant_id, 
       lat,lng,address,radius,
       data)
-    values (#{id,jdbcType=VARCHAR}, #{mac,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, 
+    values (#{id,jdbcType=VARCHAR}, #{mac,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{alias,jdbcType=VARCHAR} ,
       #{isDelete,jdbcType=CHAR}, #{productId,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, 
       #{createtime,jdbcType=TIMESTAMP}, #{modifytime,jdbcType=TIMESTAMP}, #{tenantId,jdbcType=VARCHAR}, 
       #{lat,jdbcType=VARCHAR},#{lng,jdbcType=VARCHAR},#{address,jdbcType=VARCHAR},
@@ -122,6 +123,9 @@
       <if test="name != null">
         name,
       </if>
+      <if test="alias != null">
+        alias,
+      </if>
       <if test="isDelete != null">
         is_delete,
       </if>
@@ -166,6 +170,9 @@
       <if test="name != null">
         #{name,jdbcType=VARCHAR},
       </if>
+      <if test="alias != null">
+        #{alias,jdbcType=VARCHAR},
+      </if>
       <if test="isDelete != null">
         #{isDelete,jdbcType=CHAR},
       </if>
@@ -210,6 +217,9 @@
       <if test="name != null">
         name = #{name,jdbcType=VARCHAR},
       </if>
+      <if test="alias != null">
+        alias = #{alias,jdbcType=VARCHAR},
+      </if>
       <if test="isDelete != null">
         is_delete = #{isDelete,jdbcType=CHAR},
       </if>
@@ -255,6 +265,9 @@
       <if test="name != null">
         name = #{name,jdbcType=VARCHAR},
       </if>
+      <if test="alias != null">
+        alias = #{alias,jdbcType=VARCHAR},
+      </if>
       <if test="isDelete != null">
         is_delete = #{isDelete,jdbcType=CHAR},
       </if>
@@ -295,6 +308,7 @@
     update device
     set mac = #{mac,jdbcType=VARCHAR},
       name = #{name,jdbcType=VARCHAR},
+      alias = #{alias,jdbcType=VARCHAR},
       is_delete = #{isDelete,jdbcType=CHAR},
       product_id = #{productId,jdbcType=VARCHAR},
       description = #{description,jdbcType=VARCHAR},
@@ -312,6 +326,7 @@
     update device
     set mac = #{mac,jdbcType=VARCHAR},
       name = #{name,jdbcType=VARCHAR},
+      alias = #{alias,jdbcType=VARCHAR},
       is_delete = #{isDelete,jdbcType=CHAR},
       product_id = #{productId,jdbcType=VARCHAR},
       description = #{description,jdbcType=VARCHAR},