java110 5 éve%!(EXTRA string=óta)
szülő
commit
d0869e61b6

+ 9 - 0
java110-bean/src/main/java/com/java110/dto/machine/MachineDto.java

@@ -54,6 +54,7 @@ public class MachineDto extends PageDto implements Serializable {
     private String createTime;
 
     private String statusCd = "0";
+    private String heartbeatTime;
 
 
     public String getMachineMac() {
@@ -296,4 +297,12 @@ public class MachineDto extends PageDto implements Serializable {
     public void setMachineAttrs(List<MachineAttrDto> machineAttrs) {
         this.machineAttrs = machineAttrs;
     }
+
+    public String getHeartbeatTime() {
+        return heartbeatTime;
+    }
+
+    public void setHeartbeatTime(String heartbeatTime) {
+        this.heartbeatTime = heartbeatTime;
+    }
 }

+ 9 - 6
java110-db/src/main/resources/mapper/common/MachineServiceDaoImplMapper.xml

@@ -8,11 +8,11 @@
     <insert id="saveBusinessMachineInfo" parameterType="Map">
         insert into business_machine(
         machine_mac,machine_id,machine_code,auth_code,operate,machine_version,community_id,b_id,
-        machine_name,machine_type_cd,machine_ip,location_type_cd,location_obj_id,state,direction
+        machine_name,machine_type_cd,machine_ip,location_type_cd,location_obj_id,state,direction,heartbeat_time
         ) values (
         #{machineMac},#{machineId},#{machineCode},#{authCode},#{operate},#{machineVersion},
         #{communityId},#{bId},#{machineName},#{machineTypeCd},#{machineIp},
-        #{locationTypeCd},#{locationObjId},#{state},#{direction}
+        #{locationTypeCd},#{locationObjId},#{state},#{direction},#{heartbeatTime}
         )
     </insert>
 
@@ -24,7 +24,7 @@
         machineVersion,t.community_id,t.community_id communityId,t.b_id,t.b_id bId,t.machine_name,t.machine_name
         machineName,t.machine_type_cd,t.machine_type_cd machineTypeCd,t.machine_ip,t.machine_ip machineIp,
         t.location_type_cd,t.location_obj_id,t.state,t.location_type_cd,t.location_obj_id,t.location_type_cd
-        locationTypeCd,t.location_obj_id locationObjId,t.direction
+        locationTypeCd,t.location_obj_id locationObjId,t.direction,t.heartbeat_time,t.heartbeat_time heartbeatTime
         from business_machine t
         where 1 =1
         <if test="machineMac !=null and machineMac != ''">
@@ -83,11 +83,11 @@
         insert into machine(
         machine_mac,machine_id,machine_code,auth_code,machine_version,status_cd,
         community_id,b_id,machine_name,machine_type_cd,machine_ip,
-        location_type_cd,location_obj_id,state,direction
+        location_type_cd,location_obj_id,state,direction,heartbeat_time
         ) select
         t.machine_mac,t.machine_id,t.machine_code,t.auth_code,t.machine_version,'0',t.community_id,t.b_id,
         t.machine_name,t.machine_type_cd,t.machine_ip,
-        t.location_type_cd,t.location_obj_id,t.state,t.direction
+        t.location_type_cd,t.location_obj_id,t.state,t.direction,t.heartbeat_time
         from business_machine t where 1=1
         <if test="machineMac !=null and machineMac != ''">
             and t.machine_mac= #{machineMac}
@@ -145,7 +145,7 @@
         bId,t.machine_name,t.machine_name machineName,t.machine_type_cd,t.machine_type_cd
         machineTypeCd,t.machine_ip,t.machine_ip machineIp,td.name machineTypeCdName,
         t.state,c.location_id locationTypeCd, c.location_name locationTypeName, t.location_obj_id locationObjId,
-        t.location_type_cd,t.location_obj_id,
+        t.location_type_cd,t.location_obj_id,t.heartbeat_time,t.heartbeat_time heartbeatTime
         td1.name stateName,t.create_time createTime,t.direction,td3.name directionName
         from machine t
         left join t_dict td on t.machine_type_cd=td.status_cd and td.table_name='machine' and td.table_columns='machine_type_cd'
@@ -254,6 +254,9 @@
         <if test="direction !=null and direction != ''">
             , t.direction = #{direction}
         </if>
+        <if test="heartbeatTime !=null and heartbeatTime != ''">
+            , t.heartbeat_time = #{heartbeatTime}
+        </if>
         where 1=1
         <if test="machineId !=null and machineId != ''">
             and t.machine_id= #{machineId}

+ 27 - 0
service-common/src/main/java/com/java110/common/api/MachineApi.java

@@ -1,10 +1,12 @@
 package com.java110.common.api;
 
 import com.alibaba.fastjson.JSONObject;
+import com.java110.common.bmo.machine.IMachineHeartbeatBMO;
 import com.java110.common.bmo.machine.IMachineOpenDoorBMO;
 import com.java110.common.bmo.machine.ISaveMachineRecordBMO;
 import com.java110.common.bmo.machine.IUpdateMachineTransactionStateBMO;
 import com.java110.common.bmo.machineTranslateError.IGetMachineTranslateErrorBMO;
+import com.java110.dto.machine.MachineDto;
 import com.java110.dto.machine.MachineRecordDto;
 import com.java110.dto.machine.MachineTranslateDto;
 import com.java110.dto.machineTranslateError.MachineTranslateErrorDto;
@@ -36,6 +38,9 @@ public class MachineApi {
     @Autowired
     private IUpdateMachineTransactionStateBMO updateMachineTransactionStateBMOImpl;
 
+    @Autowired
+    private IMachineHeartbeatBMO machineHeartbeatBMOImpl;
+
     /**
      * 设备开门功能
      *
@@ -163,4 +168,26 @@ public class MachineApi {
         return updateMachineTransactionStateBMOImpl.update(machineRecordDto);
     }
 
+    /**
+     * 物联网系统设备心跳
+     *
+     * @param reqJson
+     * @return
+     * @serviceCode /machine/heartbeat
+     * @path /app/machine/heartbeat
+     */
+    @RequestMapping(value = "/heartbeat", method = RequestMethod.POST)
+    public ResponseEntity<String> heartbeat(@RequestBody JSONObject reqJson) {
+        Assert.hasKeyAndValue(reqJson, "taskId", "未包含任务信息");
+        Assert.hasKeyAndValue(reqJson, "machineCode", "未包含设备编码");
+        Assert.hasKeyAndValue(reqJson, "heartbeatTime", "未包含心跳时间");
+        Assert.hasKeyAndValue(reqJson, "extCommunityId", "未包含小区ID");
+        MachineDto machineDto = new MachineDto();
+        machineDto.setMachineCode(reqJson.getString("machineCode"));
+        machineDto.setCommunityId(reqJson.getString("extCommunityId"));
+        machineDto.setHeartbeatTime(reqJson.getString("heartbeatTime"));
+
+        return machineHeartbeatBMOImpl.heartbeat(machineDto);
+    }
+
 }

+ 37 - 0
service-common/src/main/java/com/java110/common/bmo/machine/IMachineHeartbeatBMO.java

@@ -0,0 +1,37 @@
+/*
+ * Copyright 2017-2020 吴学文 and java110 team.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.java110.common.bmo.machine;
+
+import com.java110.dto.machine.MachineDto;
+import org.springframework.http.ResponseEntity;
+
+/**
+ * 设备心跳
+ * <p>
+ * add by wuxw 2020-12-27
+ * <p>
+ * 协议:https://gitee.com/java110/MicroCommunityThings/blob/master/back/docs/api.md
+ */
+public interface IMachineHeartbeatBMO {
+
+    /**
+     * 设备心跳
+     *
+     * @param machineDto
+     * @return
+     */
+    ResponseEntity<String> heartbeat(MachineDto machineDto);
+}

+ 59 - 0
service-common/src/main/java/com/java110/common/bmo/machine/impl/MachineHeartbeatBMOImpl.java

@@ -0,0 +1,59 @@
+/*
+ * Copyright 2017-2020 吴学文 and java110 team.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.java110.common.bmo.machine.impl;
+
+import com.java110.common.bmo.machine.IMachineHeartbeatBMO;
+import com.java110.dto.machine.MachineDto;
+import com.java110.intf.common.IMachineInnerServiceSMO;
+import com.java110.utils.util.Assert;
+import com.java110.vo.ResultVo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * 设备心跳实现类
+ *
+ * @desc add by 吴学文 17:37
+ */
+@Service
+public class MachineHeartbeatBMOImpl implements IMachineHeartbeatBMO {
+
+
+    @Autowired
+    private IMachineInnerServiceSMO machineInnerServiceSMO;
+
+    @Override
+    public ResponseEntity<String> heartbeat(MachineDto machineDto) {
+
+        MachineDto tmpMachineDto = new MachineDto();
+        tmpMachineDto.setMachineCode(machineDto.getMachineCode());
+        tmpMachineDto.setCommunityId(machineDto.getCommunityId());
+        List<MachineDto> machineDtos = machineInnerServiceSMO.queryMachines(tmpMachineDto);
+
+        Assert.listOnlyOne(machineDtos, "设备不存在");
+
+        machineDto.setMachineId(machineDto.getMachineId());
+
+        int count = machineInnerServiceSMO.updateMachineState(machineDto);
+        if (count > 0) {
+            return ResultVo.success();
+        }
+        return ResultVo.error("上传记录失败");
+    }
+}

+ 4 - 0
service-common/src/main/java/com/java110/common/listener/machine/AbstractMachineBusinessServiceDataFlowListener.java

@@ -7,6 +7,7 @@ import com.java110.core.event.service.AbstractBusinessServiceDataFlowListener;
 import com.java110.utils.constant.ResponseConstant;
 import com.java110.utils.constant.StatusConstant;
 import com.java110.utils.exception.ListenerExecuteException;
+import com.java110.utils.util.DateUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -49,6 +50,7 @@ public abstract class AbstractMachineBusinessServiceDataFlowListener extends Abs
         businessMachineInfo.put("machineIp", businessMachineInfo.get("machine_ip"));
         businessMachineInfo.put("locationTypeCd", businessMachineInfo.get("location_type_cd"));
         businessMachineInfo.put("locationObjId", businessMachineInfo.get("location_obj_id"));
+        businessMachineInfo.put("heartbeatTime", businessMachineInfo.get("heartbeat_time"));
         businessMachineInfo.put("state", businessMachineInfo.get("state"));
 
         businessMachineInfo.remove("bId");
@@ -88,6 +90,8 @@ public abstract class AbstractMachineBusinessServiceDataFlowListener extends Abs
         currentMachineInfo.put("locationTypeCd", currentMachineInfo.get("location_type_cd"));
         currentMachineInfo.put("locationObjId", currentMachineInfo.get("location_obj_id"));
         currentMachineInfo.put("state", currentMachineInfo.get("state"));
+        currentMachineInfo.put("heartbeatTime", currentMachineInfo.get("heartbeat_time"));
+
 
 
         currentMachineInfo.put("operate", StatusConstant.OPERATE_DEL);

+ 3 - 0
service-common/src/main/java/com/java110/common/listener/machine/SaveMachineInfoListener.java

@@ -11,6 +11,7 @@ import com.java110.po.machine.MachinePo;
 import com.java110.utils.constant.BusinessTypeConstant;
 import com.java110.utils.constant.StatusConstant;
 import com.java110.utils.util.Assert;
+import com.java110.utils.util.DateUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -163,6 +164,8 @@ public class SaveMachineInfoListener extends AbstractMachineBusinessServiceDataF
 
         }
 
+        businessMachine.put("heartbeatTime", DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A));
+
         businessMachine.put("bId", business.getbId());
         businessMachine.put("operate", StatusConstant.OPERATE_ADD);
         //保存设备信息