|
@@ -5,13 +5,15 @@ import cn.easyes.core.conditions.LambdaEsQueryWrapper;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.github.yitter.idgen.YitIdHelper;
|
|
|
+import com.xy.collections.map.JConcurrentHashMap;
|
|
|
+import com.xy.collections.map.JMap;
|
|
|
+import com.xy.config.ThreadPoolConfig;
|
|
|
import com.xy.dto.BackMqttDto;
|
|
|
import com.xy.dto.MqttDto;
|
|
|
import com.xy.dto.PaterDto;
|
|
|
import com.xy.entity.MqttCommand;
|
|
|
import com.xy.mapper.MqttCommandMapper;
|
|
|
import com.xy.producer.MqttProducer;
|
|
|
-import com.xy.service.MqttService;
|
|
|
import com.xy.utils.*;
|
|
|
import com.xy.utils.enums.MqttCommandStatusEnum;
|
|
|
import io.swagger.annotations.Api;
|
|
@@ -23,8 +25,8 @@ import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
import static com.xy.utils.EsBeans.toPageBean;
|
|
|
|
|
@@ -40,9 +42,10 @@ public class MqttServiceImpl implements MqttService {
|
|
|
|
|
|
@Override
|
|
|
@ApiOperation("指令发布")
|
|
|
- public List<MqttDto.Vo> sendMqtt(List<MqttDto> mqttDtos) {
|
|
|
- List<MqttDto.Vo> list = new ArrayList<>(mqttDtos.size());
|
|
|
- mqttDtos.forEach(mqttDto -> {
|
|
|
+ public Map<String, Boolean> sendMqtt(List<MqttDto> mqttDtos) {
|
|
|
+ JMap<String, Boolean> map = new JConcurrentHashMap<>(mqttDtos.size());
|
|
|
+ ThreadPoolUtils.Execute execute = ThreadPoolUtils.excPoll(ThreadPoolConfig.SEND_MQTT_POLL, mqttDtos.size());
|
|
|
+ mqttDtos.forEach(mqttDto -> execute.execute(() -> {
|
|
|
//给予默认值
|
|
|
PaterDto pater = mqttDto.getPater()
|
|
|
.setSn(String.valueOf(YitIdHelper.nextId()))
|
|
@@ -68,14 +71,15 @@ public class MqttServiceImpl implements MqttService {
|
|
|
mqttProducer.sendToMqtt(value.toString(), topic, mqttDto.getLevel());
|
|
|
//指令记录
|
|
|
saveMqttCommand(mqttDto, value, pater.getAck() ? MqttCommandStatusEnum.COMMAND_SEND : MqttCommandStatusEnum.COMMAND_SUCCESS, null);
|
|
|
- list.add(new MqttDto.Vo().setWkSn(wkSn).setResult(true));
|
|
|
+ map.put(wkSn, true);
|
|
|
} catch (Exception e) {
|
|
|
//指令记录
|
|
|
saveMqttCommand(mqttDto, value, MqttCommandStatusEnum.COMMAND_SEND_FAIL, e.getMessage());
|
|
|
- list.add(new MqttDto.Vo().setWkSn(wkSn).setResult(false));
|
|
|
+ map.put(wkSn, false);
|
|
|
}
|
|
|
- });
|
|
|
- return list;
|
|
|
+ }));
|
|
|
+ execute.end();
|
|
|
+ return map;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -115,7 +119,7 @@ public class MqttServiceImpl implements MqttService {
|
|
|
EsPageInfo<MqttCommand> mqttCommandEsPageInfo = mqttCommandMapper.pageQuery(lambdaEsQueryWrapper, (int) pageBean.getCurrent(), (int) pageBean.getSize());
|
|
|
return R.ok(toPageBean(MqttDto.Vo2.class, mqttCommandEsPageInfo));
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 新增指令记录
|