|
@@ -0,0 +1,55 @@
|
|
|
+package com.fdkankan.contro.mq.listener;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.fdkankan.fyun.face.FYunFileServiceInterface;
|
|
|
+import com.fdkankan.model.constants.UploadFilePath;
|
|
|
+import com.rabbitmq.client.Channel;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.amqp.core.Message;
|
|
|
+import org.springframework.amqp.rabbit.annotation.Queue;
|
|
|
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.util.HashMap;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+public class UpdateSceneStatusListener {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FYunFileServiceInterface fYunFileService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新场景status.json状态
|
|
|
+ * @param channel
|
|
|
+ * @param message
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @RabbitListener(
|
|
|
+ queuesToDeclare = @Queue("${queue.scene.update-scene-status}")
|
|
|
+ )
|
|
|
+ public void buildScenePreHandler(Channel channel, Message message) throws Exception {
|
|
|
+ String msg = new String(message.getBody(), StandardCharsets.UTF_8);
|
|
|
+ log.info("开始更新场景的的status.json状态,content:{}", msg);
|
|
|
+ HashMap<String, Object> map = JSON.parseObject(msg, HashMap.class);
|
|
|
+ String num = (String) map.get("num");
|
|
|
+ Integer status = (Integer)map.get("status");
|
|
|
+ String statusJsonPath = String.format(UploadFilePath.DATA_VIEW_PATH, num).concat("status.json");
|
|
|
+ try {
|
|
|
+
|
|
|
+ String fileContent = fYunFileService.getFileContent(statusJsonPath);
|
|
|
+ JSONObject jsonObject = JSON.parseObject(fileContent);
|
|
|
+ jsonObject.put("status", status);
|
|
|
+ fYunFileService.uploadFile(jsonObject.toJSONString().getBytes(), statusJsonPath);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("更新场景的的status.json状态, content:{}", msg, e);
|
|
|
+ }finally {
|
|
|
+ channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
|
|
+ }
|
|
|
+ log.info("结束更新场景的的status.json状态,content:{}", msg);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|