|
@@ -1,19 +1,19 @@
|
|
package com.usky.transfer.service.impl;
|
|
package com.usky.transfer.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.sun.media.jfxmedia.logging.Logger;
|
|
import com.sun.media.jfxmedia.logging.Logger;
|
|
import com.usky.common.core.util.UUIDUtils;
|
|
import com.usky.common.core.util.UUIDUtils;
|
|
import com.usky.common.security.utils.SecurityUtils;
|
|
import com.usky.common.security.utils.SecurityUtils;
|
|
import com.usky.transfer.domain.*;
|
|
import com.usky.transfer.domain.*;
|
|
import com.usky.transfer.mapper.QueryInfluxdbDataMapper;
|
|
import com.usky.transfer.mapper.QueryInfluxdbDataMapper;
|
|
-import com.usky.transfer.service.DmpDeviceService;
|
|
|
|
-import com.usky.transfer.service.DmpDeviceStatusService;
|
|
|
|
-import com.usky.transfer.service.DmpProductService;
|
|
|
|
-import com.usky.transfer.service.QueryInfluxdbDataService;
|
|
|
|
|
|
+import com.usky.transfer.service.*;
|
|
import com.usky.common.mybatis.core.AbstractCrudService;
|
|
import com.usky.common.mybatis.core.AbstractCrudService;
|
|
|
|
+import com.usky.transfer.service.config.mqtt.MqttOutConfig;
|
|
import com.usky.transfer.service.rocketmq.MyProducer;
|
|
import com.usky.transfer.service.rocketmq.MyProducer;
|
|
import com.usky.transfer.service.utils.TsdbUtils;
|
|
import com.usky.transfer.service.utils.TsdbUtils;
|
|
import com.usky.transfer.service.vo.DeviceMapVO;
|
|
import com.usky.transfer.service.vo.DeviceMapVO;
|
|
@@ -26,10 +26,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
@@ -50,11 +47,51 @@ public class QueryInfluxdbDataServiceImpl extends AbstractCrudService<QueryInflu
|
|
private DmpDeviceService dmpDeviceService;
|
|
private DmpDeviceService dmpDeviceService;
|
|
@Autowired
|
|
@Autowired
|
|
private DmpDeviceStatusService dmpDeviceStatusService;
|
|
private DmpDeviceStatusService dmpDeviceStatusService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private DmpDeviceCommandService dmpDeviceCommandService;
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
private MyProducer myProducer;
|
|
private MyProducer myProducer;
|
|
|
|
+ @Resource
|
|
|
|
+ private MqttOutConfig.MqttGateway mqttGateway;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Map<String,Object> deviceControl(String topic,String dataStr){
|
|
|
|
+ Map<String,Object> rec_map = new HashMap<>();
|
|
|
|
+ String[] str = topic.split("/");
|
|
|
|
+
|
|
|
|
+ //存储下发设备控制命令到数据库表中
|
|
|
|
+ DmpDeviceCommand command = new DmpDeviceCommand();
|
|
|
|
+ command.setProductCode(str[1]);
|
|
|
|
+ command.setDeviceId(str[2]);
|
|
|
|
+ command.setCommandContent(dataStr);
|
|
|
|
+ command.setCreatedBy(SecurityUtils.getUsername());
|
|
|
|
+ command.setCreatedTime(LocalDateTime.now());
|
|
|
|
+// if (Objects.nonNull(SecurityUtils.getLoginUser().getSysUser().getDeptId())){
|
|
|
|
+// command.setDeptId(SecurityUtils.getLoginUser().getSysUser().getDeptId().intValue());
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+ command.setTenantId(SecurityUtils.getTenantId());
|
|
|
|
+ dmpDeviceCommandService.save(command);
|
|
|
|
+ int commandId = command.getId();
|
|
|
|
+
|
|
|
|
+ JSONObject dataJson = JSONObject.parseObject(dataStr);
|
|
|
|
+ dataJson.put("id",commandId);
|
|
|
|
+
|
|
|
|
+ command.setCommandContent(dataJson.toJSONString());
|
|
|
|
+ dmpDeviceCommandService.updateById(command);
|
|
|
|
+ //推送下发设备控制mqtt
|
|
|
|
+ if(StringUtils.isNotBlank(dataStr)){
|
|
|
|
+ mqttGateway.sendToMqtt(topic,dataJson.toJSONString());
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
+ rec_map.put("code",200);
|
|
|
|
+ rec_map.put("message","操作成功");
|
|
|
|
+
|
|
|
|
+ return rec_map;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public Map<String,Object> sendDeviceDataToMQ(DeviceDataWriteVO writeVO){
|
|
public Map<String,Object> sendDeviceDataToMQ(DeviceDataWriteVO writeVO){
|
|
Map<String,Object> rec_map = new HashMap<>();
|
|
Map<String,Object> rec_map = new HashMap<>();
|