netty-修改请求框架,并且注册客户端信息落地,之后通过调用netty接口来进行后续操作。

This commit is contained in:
limqhz
2020-07-11 23:33:02 +08:00
parent 3703ee2844
commit 6f08b24538
29 changed files with 266 additions and 689 deletions

View File

@@ -62,4 +62,18 @@ public interface DeviceMapper {
List<DeviceDTO> findAllDTO();
Integer countByStream(@Param("stream") String stream,@Param("id") Integer id);
/**
* 更新设备状态为 0 - 未连接
*/
void offline(@Param("venueId") Integer venueId,@Param("deviceName") String deviceName);
/**
* 更新设备状态为 2 - 连接成功
*/
void online(@Param("venueId") Integer venueId,@Param("deviceName") String deviceName);
Integer checkDevice(@Param("deviceName") String deviceName,@Param("venueId") Integer venueId);
}

View File

@@ -20,6 +20,8 @@ import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;
/**
@@ -29,7 +31,6 @@ import java.util.List;
* @since 2018-08-09
*/
@Service
@Transactional(readOnly = true)
public class DeviceService extends BaseServiceImpl {
private final Logger logger = LoggerFactory.getLogger(DeviceService.class);
@@ -131,26 +132,30 @@ public class DeviceService extends BaseServiceImpl {
/**
* 设备连接断开
* @param deviceId
*/
@Transactional
public void offline(Integer deviceId){
Device device = new Device();
device.setId(deviceId);
device.setStatus(DeviceStatusEnum.OFFLINE.value);
deviceMapper.update(device);
public void offline(String deviceName, Integer venueId){
deviceMapper.offline(venueId,deviceName);
}
/**
* 设备连接成功
* @param deviceId
* 新的设备注册的逻辑
*/
@Transactional
public void online(Integer deviceId){
Device device = new Device();
device.setId(deviceId);
device.setStatus(DeviceStatusEnum.ONLINE.value);
deviceMapper.update(device);
public void online(String deviceName,Integer venueId,Integer venueType,String deviceIp){
Device device = new Device();
device.setVenueId(venueId);
device.setVenueType(venueType);
device.setName(deviceName);
device.setStatus(DeviceStatusEnum.ONLINE.value);
device.setStream(deviceIp);
if(deviceMapper.checkDevice(deviceName,venueId) > 0){
logger.info(deviceName + venueId + "设备已存在,该设备。");
deviceMapper.online(venueId, deviceName);
}else {
logger.info("落地客户端信息clientId = " + deviceIp + "&deviceName = " + deviceName + "&venueId = " + venueId);
deviceMapper.insert(device);
}
}
/**

View File

@@ -8,7 +8,7 @@
<result column="stream" property="stream"/>
<result column="venue_id" property="venueId"/>
<result column="venue_type" property="venueType"/>
<result column="status" property="status"></result>
<result column="status" property="status"/>
<result column="created_id" property="createdId"/>
<result column="modified_id" property="modifiedId"/>
<result column="created_time" property="createdTime"/>
@@ -63,7 +63,7 @@
</select>
<!-- 新增-->
<insert id="insert" parameterType="com.sv.entity.Device" useGeneratedKeys="true" keyProperty="id">
<insert id="insert" parameterType="com.sv.entity.Device">
INSERT INTO
<include refid="tableName"></include>
@@ -81,7 +81,10 @@
venue_id,
</if>
<if test="venueType != null">
venue_type
venue_type,
</if>
<if test="status != null">
status,
</if>
<if test="createdId != null">
created_id,
@@ -115,6 +118,9 @@
<if test="venueType != null">
#{venueType},
</if>
<if test="status != null">
#{status},
</if>
<if test="createdId != null">
#{createdId},
</if>
@@ -220,4 +226,20 @@
</if>
</select>
<update id="offline">
UPDATE sv_device set status = 0,modified_time = now()
WHERE name = #{deviceName} and venue_id=#{venueId}
</update>
<update id="online">
UPDATE sv_device set status = 2,modified_time = now()
WHERE name = #{deviceName} and venue_id=#{venueId}
</update>
<select id="checkDevice" resultType="java.lang.Integer">
SELECT count(1) FROM sv_device
WHERE name = #{deviceName} and venue_id=#{venueId} and deleted = 0
</select>
</mapper>