|
|
@@ -5,7 +5,10 @@ import cn.hutool.json.JSONUtil;
|
|
|
import com.google.gson.JsonObject;
|
|
|
import com.zhongshu.card.client.model.mqtt.SendMessageModel;
|
|
|
import com.zhongshu.card.client.ret.ResultContent;
|
|
|
+import com.zhongshu.card.client.utils.type.ArtemisType;
|
|
|
+import com.zhongshu.card.server.core.dao.mqtt.ArtemisMessageDao;
|
|
|
import com.zhongshu.card.server.core.dao.org.UserCountDao;
|
|
|
+import com.zhongshu.card.server.core.domain.mqtt.ArtemisMessage;
|
|
|
import com.zhongshu.card.server.core.httpRequest.ApiRequestService;
|
|
|
import com.zhongshu.card.server.core.service.base.RedisService;
|
|
|
import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
@@ -43,6 +46,9 @@ public class MqttServiceImpl extends SuperService {
|
|
|
@Autowired
|
|
|
ApiRequestService apiRequestService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ ArtemisMessageDao artemisMessageDao;
|
|
|
+
|
|
|
/**
|
|
|
* 发送指令
|
|
|
*
|
|
|
@@ -52,12 +58,23 @@ public class MqttServiceImpl extends SuperService {
|
|
|
public ResultContent sendMessage(SendMessageModel param) {
|
|
|
String msg = "发送成功";
|
|
|
try {
|
|
|
+ String id = UUID.randomUUID().toString();
|
|
|
JsonObject jsonObject = new JsonObject();
|
|
|
- jsonObject.addProperty("id", UUID.randomUUID().toString());
|
|
|
+ jsonObject.addProperty("id", id);
|
|
|
jsonObject.addProperty("data", param.getMessage());
|
|
|
jsonObject.addProperty("time", DateUtils.paresTime(System.currentTimeMillis(), DateUtils.patternyyyySSS));
|
|
|
jsonObject.addProperty("ttl", 10 * 1000);
|
|
|
mqClient.sendObject(param.getTopic(), jsonObject.toString());
|
|
|
+
|
|
|
+ ArtemisMessage artemisMessage = new ArtemisMessage();
|
|
|
+ artemisMessage.setJsonObject(jsonObject);
|
|
|
+ artemisMessage.setTopIc(param.getTopic());
|
|
|
+ artemisMessage.setArtemisType(ArtemisType.Send);
|
|
|
+ artemisMessage.setMessageId(id);
|
|
|
+ artemisMessage.setTimeStr(DateUtils.paresTime(System.currentTimeMillis(),
|
|
|
+ DateUtils.patternyyyySSS));
|
|
|
+ artemisMessage.setUserId(param.getUserId());
|
|
|
+ artemisMessageDao.save(artemisMessage);
|
|
|
log.info("mqtt msg 发送成功");
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|