Просмотр исходного кода

add message print log

tags/B.2.2.0.6_20231012_base
yk 2 лет назад
Родитель
Сommit
ddf3b53e71
1 измененных файлов: 34 добавлений и 43 удалений
  1. +34
    -43
      xueyi-modules/xueyi-message/src/main/java/com/xueyi/message/transfer/controller/ApiController.java

+ 34
- 43
xueyi-modules/xueyi-message/src/main/java/com/xueyi/message/transfer/controller/ApiController.java Просмотреть файл

@@ -29,6 +29,8 @@ import com.xueyi.system.api.organize.domain.dto.SysEnterpriseDto;
import com.xueyi.system.api.resource.feign.RemoteH5ConfigService;
import com.xueyi.system.api.staff.domain.vo.DmStaffFeature;
import com.xueyi.system.api.staff.feign.RemoteStaffService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
@@ -49,6 +51,8 @@ import java.util.stream.Collectors;
@RequestMapping("api")
public class ApiController {

private static final Logger log = LoggerFactory.getLogger(ApiController.class);

@Autowired
RemoteStaffService remoteStaffService;

@@ -83,12 +87,11 @@ public class ApiController {
RemoteH5ConfigService remoteH5ConfigService;



@RequestMapping(value = "/heartbeat", method = {RequestMethod.POST})
@ResponseBody
public AjaxResult heartbeat(@RequestBody DmDeviceVo vo, HttpServletResponse response) {
Long sysTime = System.currentTimeMillis();
System.out.println("heartbeat: device: " + vo.getDevId() + " timestamp: " + sysTime);
log.info("heartbeat: device: {} timestamp: {} ",vo.getDevId(), sysTime);
Integer dex_res = 0;
// 根据设备id获取租户信息
R<DmManDeviceDto> manDeviceDtoR = manDeviceService.manDeviceInfoInner(vo.getDevId());
@@ -102,7 +105,7 @@ public class ApiController {
}

// 更新心跳
redisTemplate.opsForValue().set("group:dgman:" + vo.getDevId() + ":" + MessageConstants.HEART_BEAT_SYNC,String.valueOf(sysTime));
redisTemplate.opsForValue().set("group:dgman:" + vo.getDevId() + ":" + MessageConstants.HEART_BEAT_SYNC, String.valueOf(sysTime));

String timestamp = redisTemplate.opsForValue().get("group:dgman:" + manDeviceDtoR.getData().getTId() + ":" + MessageConstants.STAFF_SYNC);

@@ -147,15 +150,14 @@ public class ApiController {
@RequestMapping(value = "/update", method = {RequestMethod.POST})
@ResponseBody
public AjaxResult update(@RequestBody DmDeviceVo vo, HttpServletResponse response) {
System.out.println(vo.toString());
String timestamp = vo.getTimestamp();
// 根据设备id获取租户信息
R<DmManDeviceDto> manDeviceDtoR = manDeviceService.manDeviceInfoInner(vo.getDevId());
if (manDeviceDtoR.isFail() || manDeviceDtoR.getData() == null ) {
if (manDeviceDtoR.isFail() || manDeviceDtoR.getData() == null) {
return AjaxResult.warn("设备号获取失败,请检查");
}
Source source = SourceUtil.getSourceCache(manDeviceDtoR.getData().getStrategyId());
if (vo.getType() !=null) {
if (vo.getType() != null) {
switch (vo.getType()) {
// 人员信息
case 0:
@@ -176,7 +178,7 @@ public class ApiController {
});
return AjaxResult.success(staffFeatureList.getData()).put("timestamp", timestamp);
case 1:
System.out.println("=========租户号:" + manDeviceDtoR.getData().getTId() + ", 数据源: " + source.getMaster() + " 设备号:" + vo.getDevId());
log.info("=========租户号:{},数据源:{}, 设备号:{}",manDeviceDtoR.getData().getTId(), source.getMaster(), vo.getDevId());
R<List<DmSkillDto>> skillList = remoteSkillService.skilllistInner(vo.getDevId(), vo.getTimestamp(), manDeviceDtoR.getData().getTId(), source.getMaster(), SecurityConstants.INNER);
if (skillList.isFail())
return AjaxResult.warn("新增失败,请检查");
@@ -194,7 +196,7 @@ public class ApiController {
return AjaxResult.success(syncDmDto.getData()).put("timestamp", timestamp);
case 3:
R<DmReceptionVo> receptionVo = remoteReceptionService.getReceptionTaskInner(manDeviceDtoR.getData().getManCode(), manDeviceDtoR.getData().getTId(), source.getMaster(), SecurityConstants.INNER);
if (receptionVo.isFail()){
if (receptionVo.isFail()) {
return AjaxResult.warn("接待模式任务获取失败,请检查");
}

@@ -238,7 +240,7 @@ public class ApiController {
}

// 根据密钥获取账户信息
R<DeviceTenantSourceMergeVo> deviceTenantSourceMergeVoR = deviceTenantMergeServicel.selectDeviceSNTenantSourceMerge(vo.getSncode(),vo.getSecret());
R<DeviceTenantSourceMergeVo> deviceTenantSourceMergeVoR = deviceTenantMergeServicel.selectDeviceSNTenantSourceMerge(vo.getSncode(), vo.getSecret());
if (deviceTenantSourceMergeVoR.isFail()) {
return AjaxResult.warn(deviceTenantSourceMergeVoR.getMsg());
}
@@ -253,13 +255,13 @@ public class ApiController {
return AjaxResult.warn("更新设备信息失败,请查询log");
}
// 调用初始化处理(数字人,数字人设备,形象,技能)
R<Integer> initResult = remoteDigitalmanService.initInner(vo.getSecret(),deviceTenantSourceMergeVoR.getData().getTenantId(),deviceTenantSourceMergeVoR.getData().getSourceSlave(),SecurityConstants.INNER);
R<Integer> initResult = remoteDigitalmanService.initInner(vo.getSecret(), deviceTenantSourceMergeVoR.getData().getTenantId(), deviceTenantSourceMergeVoR.getData().getSourceSlave(), SecurityConstants.INNER);
// 根据状态返回结果
if (initResult.isFail()) {
return AjaxResult.warn("绑定数字人失败,请联系后台人员");
}
// 更新心跳状态
redisTemplate.opsForValue().set("group:dgman:" + vo.getSncode() + ":" + MessageConstants.HEART_BEAT_SYNC,String.valueOf(System.currentTimeMillis()));
redisTemplate.opsForValue().set("group:dgman:" + vo.getSncode() + ":" + MessageConstants.HEART_BEAT_SYNC, String.valueOf(System.currentTimeMillis()));
//redisTemplate.opsForHash().(MessageConstants.REDIS_GROUP_DEVICE_HEADER,devId,dto);
//redisTemplate.
return AjaxResult.success();
@@ -267,12 +269,10 @@ public class ApiController {

/**
* 获取设备在线状态
*
*
*/
@RequestMapping(value = "/device_online_status/{devId}", method = {RequestMethod.GET})
@ResponseBody
public AjaxResult getDeviceOnlineStatus(@RequestParam(value = "devId") String devId, HttpServletResponse response){
public AjaxResult getDeviceOnlineStatus(@RequestParam(value = "devId") String devId, HttpServletResponse response) {
// 获取设备心跳状态
String timestamp = redisTemplate.opsForValue().get("group:dgman:" + devId + ":" + MessageConstants.HEART_BEAT_SYNC);

@@ -286,53 +286,44 @@ public class ApiController {
return AjaxResult.success(InitConstants.DEVICE_ACTIVATE_STATUS_OFFLINE);
}
// 设备存在缓存时判断是否超过10min
return AjaxResult.success(System.currentTimeMillis() - Long.parseLong(timestamp) >10 * 60 * 1000 ? InitConstants.DEVICE_ACTIVATE_STATUS_OFFLINE : InitConstants.DEVICE_ACTIVATE_STATUS_ONLINE);
return AjaxResult.success(System.currentTimeMillis() - Long.parseLong(timestamp) > 10 * 60 * 1000 ? InitConstants.DEVICE_ACTIVATE_STATUS_OFFLINE : InitConstants.DEVICE_ACTIVATE_STATUS_ONLINE);
}

/**
* @Author yangkai
* @Description //TODO
* @Date 2023/8/11
* @Param
* @return
*
*
* manCount
* @return manCount
* serviceTimeCount
* chatTimes
* chatDurationCount
* skillExecuteTimes
*
* <p>
* recognizedPersonCount
* servicePerCount
*
* <p>
* receptionServiceCount
* meetingServiceCount
* visitServiceCount
* largeModelKnowledgeBaseGroupChangeNum
* largeModelKnowledgeBaseChangeNum
* @Author yangkai
* @Description //TODO
* @Date 2023/8/11
* @Param
**/
@RequestMapping(value = "/broadcast", method = {RequestMethod.GET})
@ResponseBody
public R broadcast(@RequestParam(value = "channel") String channel){
public R broadcast(@RequestParam(value = "channel") String channel) {
try {
JSONObject json = new JSONObject();
/*json.put("chatTimes", 865531);
json.put("chatDurationCount", 10068);
// json.put("skillExecuteTimes", 10);
json.put("recognizedPersonCount", 13899);
json.put("receptionServiceCount", 1824);
json.put("meetingServiceCount", 1762);
json.put("visitServiceCount", 523);*/

R<JSONObject> objectR = remoteDigitalmanService.mansInfo();
JSONObject jsonObj = objectR.getData();
jsonObj.keySet().forEach(key -> json.put(key, jsonObj.get(key)));
String str = json.toJSONString();

messageQueueService.broadcast(channel, str);
log.info("broadcast----exec");
JSONObject json = new JSONObject();
R<JSONObject> objectR = remoteDigitalmanService.mansInfo();
log.info("mansInfo:{}", objectR.getData());
JSONObject jsonObj = objectR.getData();
jsonObj.keySet().forEach(key -> json.put(key, jsonObj.get(key)));
String str = json.toJSONString();
log.info("broadcast:{}", str);
messageQueueService.broadcast(channel, str);
return R.ok(str);
}catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
return R.fail(e.getMessage());
}
@@ -346,7 +337,7 @@ public class ApiController {

return AjaxResult.success("false");
}
System.out.println(manDeviceDtR.getData().toString());
log.info(manDeviceDtR.getData().toString());
return AjaxResult.success("true");
}



Загрузка…
Отмена
Сохранить