Commit 6fcd2444 by huangjy

fix:声网token区分rtm和rtc

parent d72bd5bd
...@@ -68,15 +68,16 @@ public class PlatAlarmRecordController { ...@@ -68,15 +68,16 @@ public class PlatAlarmRecordController {
@ApiOperation("呼叫设备") @ApiOperation("呼叫设备")
@PostMapping("callingDevice") @PostMapping("callingDevice")
public ApiResponseEntity<PlatAlarmCallDeviceVO> callingDevice() { public ApiResponseEntity<PlatAlarmCallDeviceVO> callingDevice(@RequestBody PlatCallingDeviceDTO dto) {
return ApiResponseUtils.success(platAlarmRecordService.callingDevice()); return ApiResponseUtils.success(platAlarmRecordService.callingDevice(dto));
} }
@ApiOperation("呼叫设备") @ApiOperation("呼叫设备")
@PostMapping("callingDeviceAuthIgnore") @PostMapping("callingDeviceAuthIgnore")
@AuthIgnore @AuthIgnore
public ApiResponseEntity<PlatAlarmCallDeviceVO> callingDeviceAuthIgnore() { @TenantIdIgnore
return ApiResponseUtils.success(platAlarmRecordService.callingDevice()); public ApiResponseEntity<PlatAlarmCallDeviceVO> callingDeviceAuthIgnore(@RequestBody PlatCallingDeviceDTO dto) {
return ApiResponseUtils.success(platAlarmRecordService.callingDevice(dto));
} }
@ApiOperation("呼叫设备rtm") @ApiOperation("呼叫设备rtm")
......
...@@ -70,7 +70,7 @@ public interface PlatAlarmRecordService extends IService<PlatAlarmRecord> { ...@@ -70,7 +70,7 @@ public interface PlatAlarmRecordService extends IService<PlatAlarmRecord> {
void misinformation(String id); void misinformation(String id);
PlatAlarmCallDeviceVO callingDevice(); PlatAlarmCallDeviceVO callingDevice(PlatCallingDeviceDTO dto);
PlatAlarmCallDeviceVO callingDeviceAuthIgnoreRtm(PlatCallingDeviceDTO id); PlatAlarmCallDeviceVO callingDeviceAuthIgnoreRtm(PlatCallingDeviceDTO id);
} }
...@@ -61,7 +61,6 @@ import lombok.extern.slf4j.Slf4j; ...@@ -61,7 +61,6 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -586,44 +585,38 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe ...@@ -586,44 +585,38 @@ public class PlatAlarmRecordServiceImpl extends ServiceImpl<PlatAlarmRecordMappe
} }
@Override @Override
public PlatAlarmCallDeviceVO callingDevice() { public PlatAlarmCallDeviceVO callingDevice(PlatCallingDeviceDTO dto) {
PlatAlarmCallDeviceVO platAlarmCallDeviceVO = new PlatAlarmCallDeviceVO();
PlatAlarmRecord platAlarmRecord = getById(dto.getId());
if (platAlarmRecord == null) {
throw new RuntimeException("告警记录为空:" + dto.getId());
}
String deviceId = platAlarmRecord.getDeviceId();
PlatDevice platDevice = platDeviceService.getById(deviceId);
platAlarmCallDeviceVO.setDeviceId(platDevice.getOriDeviceId());
platAlarmCallDeviceVO.setUserId(dto.getUserId());
platAlarmCallDeviceVO.setAppId(shengwangProperties.getAppId());
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
String format = now.format(dateTimeFormatter); String channelName = String.format("%s:%s","RTC",now.format(dateTimeFormatter));
RtcTokenBuilder2 token = new RtcTokenBuilder2(); RtcTokenBuilder2 token = new RtcTokenBuilder2();
String result = token.buildTokenWithUid(shengwangProperties.getAppId(), shengwangProperties.getAppCertificate(), format, 0, RtcTokenBuilder2.Role.ROLE_SUBSCRIBER, String result = token.buildTokenWithUid(shengwangProperties.getAppId(), shengwangProperties.getAppCertificate(), channelName, 0, RtcTokenBuilder2.Role.ROLE_SUBSCRIBER,
shengwangProperties.getTokenExpirationInSeconds(), shengwangProperties.getPrivilegeExpirationInSeconds()); shengwangProperties.getTokenExpirationInSeconds(), shengwangProperties.getPrivilegeExpirationInSeconds());
PlatAlarmCallDeviceVO platAlarmCallDeviceVO = new PlatAlarmCallDeviceVO();
platAlarmCallDeviceVO.setAccessToken(result); platAlarmCallDeviceVO.setAccessToken(result);
platAlarmCallDeviceVO.setChannelName(format); platAlarmCallDeviceVO.setChannelName(channelName);
return platAlarmCallDeviceVO; return platAlarmCallDeviceVO;
} }
@Override @Override
public PlatAlarmCallDeviceVO callingDeviceAuthIgnoreRtm(PlatCallingDeviceDTO dto) { public PlatAlarmCallDeviceVO callingDeviceAuthIgnoreRtm(PlatCallingDeviceDTO dto) {
String redisResult = redisTemplate.opsForValue().get(REDIS_DEVICE_CALL + dto.getUserId());
if (StringUtils.isNotEmpty(redisResult)) {
return JSON.parseObject(redisResult,PlatAlarmCallDeviceVO.class);
}
PlatAlarmCallDeviceVO platAlarmCallDeviceVO = new PlatAlarmCallDeviceVO(); PlatAlarmCallDeviceVO platAlarmCallDeviceVO = new PlatAlarmCallDeviceVO();
PlatAlarmRecord platAlarmRecord = getById(dto.getId());
if (platAlarmRecord == null) {
throw new RuntimeException("告警记录为空:" + dto.getId());
}
String deviceId = platAlarmRecord.getDeviceId();
PlatDevice platDevice = platDeviceService.getById(deviceId);
platAlarmCallDeviceVO.setDeviceId(platDevice.getOriDeviceId());
platAlarmCallDeviceVO.setUserId(dto.getUserId());
RtmTokenBuilder2 token = new RtmTokenBuilder2(); RtmTokenBuilder2 token = new RtmTokenBuilder2();
String result = token.buildToken(shengwangProperties.getAppId(), shengwangProperties.getAppCertificate(), dto.getUserId(), shengwangProperties.getTokenExpirationInSeconds()); String result = token.buildToken(shengwangProperties.getAppId(), shengwangProperties.getAppCertificate(), dto.getUserId(), shengwangProperties.getTokenExpirationInSeconds());
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
String format = now.format(dateTimeFormatter); String format = String.format("%s:%s","RTM",now.format(dateTimeFormatter));
platAlarmCallDeviceVO.setAccessToken(result); platAlarmCallDeviceVO.setAccessToken(result);
platAlarmCallDeviceVO.setChannelName(format); platAlarmCallDeviceVO.setChannelName(format);
platAlarmCallDeviceVO.setChannelName(shengwangProperties.getAppId());
redisTemplate.opsForValue().set(REDIS_DEVICE_CALL + dto.getUserId(),JSON.toJSONString(platAlarmCallDeviceVO),
shengwangProperties.getTokenExpirationInSeconds(),TimeUnit.SECONDS);
return platAlarmCallDeviceVO; return platAlarmCallDeviceVO;
} }
} }
...@@ -72,6 +72,7 @@ public class PlatElderChildrenInfoServiceImpl extends ServiceImpl<PlatElderChild ...@@ -72,6 +72,7 @@ public class PlatElderChildrenInfoServiceImpl extends ServiceImpl<PlatElderChild
.like(StringUtils.isNotBlank(dto.getPhone()), PlatElderChildrenInfo::getPhone, dto.getPhone()) .like(StringUtils.isNotBlank(dto.getPhone()), PlatElderChildrenInfo::getPhone, dto.getPhone())
.eq(StringUtils.isNotBlank(dto.getElderId()), PlatElderChildrenInfo::getElderId, dto.getElderId()) .eq(StringUtils.isNotBlank(dto.getElderId()), PlatElderChildrenInfo::getElderId, dto.getElderId())
.eq(StringUtils.isNotBlank(dto.getTenantId()), PlatElderChildrenInfo::getTenantId, dto.getTenantId()) .eq(StringUtils.isNotBlank(dto.getTenantId()), PlatElderChildrenInfo::getTenantId, dto.getTenantId())
.in(CollectionUtils.isNotEmpty(dto.getOrgIdList()),PlatElderChildrenInfo::getOrgId,dto.getOrgIdList())
.apply(StringUtils.isNotBlank(dto.getOrgId()), "find_in_set('" + dto.getOrgId() + "',org_path)"); .apply(StringUtils.isNotBlank(dto.getOrgId()), "find_in_set('" + dto.getOrgId() + "',org_path)");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment