1078-增加位置信息并发处理能力

This commit is contained in:
panlinlin
2024-06-16 06:41:57 +08:00
parent 93532a6b3b
commit 36e15c80b0
6 changed files with 51 additions and 11 deletions

View File

@@ -181,6 +181,7 @@ public class VideoManagerConstants {
//************************** 1078 ****************************************
public static final String INVITE_INFO_1078_POSITION = "INVITE_INFO_1078_POSITION:";
public static final String INVITE_INFO_1078_PLAY = "INVITE_INFO_1078_PLAY:";
public static final String INVITE_INFO_1078_PLAYBACK = "INVITE_INFO_1078_PLAYBACK:";
public static final String INVITE_INFO_1078_TALK = "INVITE_INFO_1078_TALK:";

View File

@@ -103,4 +103,16 @@ public interface JTTerminalMapper {
@Select("SELECT * FROM wvp_jt_terminal where id=#{deviceId}")
JTDevice getDeviceById(@Param("deviceId") Integer deviceId);
@Update({"<script>" +
"<foreach collection='devices' item='item' separator=';'>" +
" UPDATE" +
" wvp_jt_terminal" +
" SET update_time=#{item.updateTime}" +
"<if test='item.longitude != null'>, longitude=#{item.longitude}</if>" +
"<if test='item.latitude != null'>, latitude=#{item.latitude}</if>" +
"<if test='item.id > 0'>WHERE id=#{item.id}</if>" +
"<if test='item.id == 0 and item.phoneNumber != null '>WHERE phone_number=#{item.phoneNumber}</if>" +
"</foreach>" +
"</script>"})
void batchUpdateDevicePosition(List<JTDevice> devices);
}

View File

@@ -89,19 +89,11 @@ public class J0200 extends Re {
@Override
protected Rs handler(Header header, Session session, Ijt1078Service service) {
JTDevice deviceInDb = service.getDevice(header.getPhoneNumber());
J8001 j8001 = new J8001();
j8001.setRespNo(header.getSn());
j8001.setRespId(header.getMsgId());
if (deviceInDb == null) {
j8001.setResult(J8001.FAIL);
}else {
// TODO 优化为发送异步事件,定时读取队列写入数据库
deviceInDb.setLongitude(positionInfo.getLongitude());
deviceInDb.setLatitude(positionInfo.getLatitude());
service.updateDevice(deviceInDb);
j8001.setResult(J8001.SUCCESS);
}
j8001.setResult(J8001.SUCCESS);
service.updateDevicePosition(header.getPhoneNumber(), positionInfo.getLongitude(), positionInfo.getLatitude());
return j8001;
}

View File

@@ -132,4 +132,5 @@ public interface Ijt1078Service {
JTDevice getDeviceById(Integer deviceId);
void updateDevicePosition(String phoneNumber, Double longitude, Double latitude);
}

View File

@@ -43,7 +43,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.CrossOrigin;
import java.lang.reflect.Field;
import java.util.*;
@@ -1158,4 +1160,32 @@ public class jt1078ServiceImpl implements Ijt1078Service {
public JTDevice getDeviceById(Integer deviceId) {
return jtDeviceMapper.getDeviceById(deviceId);
}
@Override
public void updateDevicePosition(String phoneNumber, Double longitude, Double latitude) {
JTDevice device = new JTDevice();
device.setPhoneNumber(phoneNumber);
device.setLongitude(longitude);
device.setLatitude(latitude);
device.setUpdateTime(DateUtil.getNow());
String key = VideoManagerConstants.INVITE_INFO_1078_POSITION + userSetting.getServerId();
redisTemplate.opsForList().leftPush(key, device);
}
@Scheduled(fixedDelay = 1000)
public void positionTask(){
String key = VideoManagerConstants.INVITE_INFO_1078_POSITION + userSetting.getServerId();
int count = 1000;
List<JTDevice> devices = new ArrayList<>(count);
Long size = redisTemplate.opsForList().size(key);
if (size == null || size == 0) {
return;
}
long readCount = Math.min(count, size);
for (long i = 0L; i < readCount; i++) {
devices.add((JTDevice)redisTemplate.opsForList().rightPop(key));
}
jtDeviceMapper.batchUpdateDevicePosition(devices);
}
}