LaserSceneGpsConsumer.java 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package com.fdkankan.manage_jp.mq.consumer;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.fdkankan.manage_jp.mq.vo.LaserSceneGpsVo;
  4. import com.fdkankan.manage_jp.mq.vo.LaserSceneTitleVo;
  5. import com.fdkankan.manage_jp.service.IProjectSceneGpsService;
  6. import com.rabbitmq.client.Channel;
  7. import lombok.extern.slf4j.Slf4j;
  8. import org.apache.commons.lang3.StringUtils;
  9. import org.springframework.amqp.core.Message;
  10. import org.springframework.amqp.rabbit.annotation.Queue;
  11. import org.springframework.amqp.rabbit.annotation.RabbitListener;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.stereotype.Component;
  14. import java.nio.charset.StandardCharsets;
  15. /**
  16. * 场景封存解封 mq
  17. */
  18. @Slf4j
  19. @Component
  20. public class LaserSceneGpsConsumer {
  21. @Autowired
  22. IProjectSceneGpsService projectSceneGpsService;
  23. @RabbitListener(
  24. queuesToDeclare = @Queue("${queue.laser.update-scene.location:save-scene-location}")
  25. )
  26. public void consumerQueue(Channel channel, Message message) {
  27. try {
  28. String messageId = message.getMessageProperties().getMessageId();
  29. String msg = new String(message.getBody(), StandardCharsets.UTF_8);
  30. log.info("laser-update-save-scene-location-mq--messageId:{},msg:{}",messageId,msg);
  31. channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
  32. LaserSceneGpsVo vo = JSONObject.parseObject(msg, LaserSceneGpsVo.class);
  33. if(vo != null && StringUtils.isNotBlank(vo.getNum()) && vo.getLocation() != null && vo.getLocation().length >0){
  34. String lat = String.valueOf(vo.getLocation()[1]);
  35. String lon = String.valueOf(vo.getLocation()[0]);
  36. projectSceneGpsService.updateGps(vo.getNum(),lat,lon,2);
  37. }
  38. }catch (Exception e){
  39. log.info("laser-save-scene-location------消费失败",e);
  40. }finally {
  41. }
  42. }
  43. }