2023-07-19 15:26:36 优化完善获取可控设备列表接口!

master
魔神煜修罗皇 2 years ago
parent 3bc8c681a9
commit f5277d61f8
  1. 3
      psdc-business/src/main/java/com/psdc/entity/vo/ModelVo.java
  2. 57
      psdc-business/src/main/java/com/psdc/service/impl/PsdcDeviceServiceImpl.java
  3. 2
      psdc-business/src/main/java/com/psdc/service/impl/PsdcSceneServiceImpl.java
  4. 3
      psdc-business/src/main/resources/mapper/business/PsdcModelMapper.xml
  5. 5
      psdc-business/src/main/resources/mapper/business/PsdcStrategyMapper.xml
  6. 2
      psdc-business/src/main/resources/mapper/business/PsdcThermometerHtdataMapper.xml

@ -26,5 +26,6 @@ public class ModelVo implements Serializable,Cloneable{
private String ioDesc ;
/** io类型【serve服务;event事件,attribute属性】 */
private String ioType ;
/** io描述 */
private String ioRemark ;
}

@ -135,6 +135,7 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService {
Double tempValue = 0.0;
map.put("controlElement", mv.getRelationField());
map.put("controlRemark", mv.getIoDesc());
map.put("nowTempRemark", mv.getIoRemark());
if (null != thermometerDataRes) {
switch (mv.getRelationField()) {
case "intemp":
@ -276,15 +277,23 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService {
@Override
public int controlDeviceStartAndStop(Integer deviceId, Integer runStatus, String controlBy, Integer controlMethod) {
List<HashMap> data = new ArrayList<>();
String value = "";
if (runStatus == 1) {
value = "启动";
HashMap<String, Object> map = new HashMap<>();
map.put("Open", "1");
data.add(map);
} else if (runStatus == 2) {
value = "停止";
HashMap<String, Object> map = new HashMap<>();
map.put("Close", "0");
data.add(map);
}
log.info("设备id:{}", deviceId);
PsdcDevice psdcDevice = psdcDeviceMapper.queryById(deviceId);
if (psdcDevice == null) {
psdcControlLogMapper.insert(new PsdcControlLog(deviceId, null, null, "设备启停", value, controlMethod, 3, "未找到该设备", controlBy));
@ -296,6 +305,16 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService {
// TODO 发送MQTT指令
MyMQTTClient myMQTTClient = new MyMQTTClient();
// 封装控制策略Json
JSONObject jsonObject = new JSONObject();
jsonObject.put("mid",MID);
jsonObject.put("timestamp",sdf2.format(new Date()));
jsonObject.put("deviceId",deviceId);
jsonObject.put("data",data);
MID = MID + 1;
myMQTTClient.publish(jsonObject.toJSONString(), "/hwj1/dntd/request/action/command", 2, false);
// psdcControlLogMapper.insert(new PsdcControlLog(deviceId,psdcDevice.getDeviceName(),psdcDevice.getDeviceSn(),"设备启停",value,controlMethod,3,"手动控制,等待终端响应超时",controlBy));
// 发送成功
@ -322,33 +341,36 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService {
}
AtomicInteger atomicInteger = new AtomicInteger(0);
List<HashMap> ary = new ArrayList<>();
for (HashMap map : data) {
// 模式策略下属各场景步骤控制指令下发执行日志
String controlKey = map.get("controlKey").toString();
String controlValue = map.get("controlValue").toString();
HashMap<String, Object> map2 = new HashMap<>();
map2.put(coverKey(controlKey), controlValue);
ary.add(map2);
if (controlValue.equals("1") || controlValue.equals("2")) {
controlValue = coverStr("r", Integer.parseInt(controlValue));
}
String controlContext = ControlKeyEnum.getControlContext(controlKey);
// TODO 发送MQTT指令
MyMQTTClient myMQTTClient = new MyMQTTClient();
// 封装控制策略Json
JSONObject jsonObject = new JSONObject();
jsonObject.put("mid",MID);
jsonObject.put("timestamp",sdf2.format(new Date()));
jsonObject.put("deviceId",deviceId);
jsonObject.put("data",data);
MID = MID + 1;
myMQTTClient.publish(jsonObject.toJSONString(), "/hwj1/dntd/request/action/command", 2, false);
// psdcControlLogMapper.insert(new PsdcControlLog(deviceId,psdcDevice.getDeviceName(),psdcDevice.getDeviceSn(),controlContext,controlValue,controlMethod,2,"控制成功",controlBy));
// psdcControlLogMapper.insert(new PsdcControlLog(deviceId,psdcDevice.getDeviceName(),psdcDevice.getDeviceSn(),controlContext,controlValue,controlMethod,3,"等待终端响应超时",controlBy));
// 发送成功
psdcControlLogMapper.insert(new PsdcControlLog(deviceId, psdcDevice.getDeviceName(), psdcDevice.getDeviceSn(), controlContext, controlValue, controlMethod, 2, "控制成功", controlBy));
atomicInteger.incrementAndGet();
}
// TODO 发送MQTT指令
MyMQTTClient myMQTTClient = new MyMQTTClient();
// 封装控制策略Json
JSONObject jsonObject = new JSONObject();
jsonObject.put("mid",MID);
jsonObject.put("timestamp",sdf2.format(new Date()));
jsonObject.put("deviceId",deviceId);
jsonObject.put("data", ary);
MID = MID + 1;
myMQTTClient.publish(jsonObject.toJSONString(), "/hwj1/dntd/request/action/command", 2, false);
// psdcControlLogMapper.insert(new PsdcControlLog(deviceId,psdcDevice.getDeviceName(),psdcDevice.getDeviceSn(),controlContext,controlValue,controlMethod,2,"控制成功",controlBy));
// psdcControlLogMapper.insert(new PsdcControlLog(deviceId,psdcDevice.getDeviceName(),psdcDevice.getDeviceSn(),controlContext,controlValue,controlMethod,3,"等待终端响应超时",controlBy));
// 发送成功
atomicInteger.incrementAndGet();
return atomicInteger.get();
}
@ -670,4 +692,5 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService {
return s;
}
}
}

@ -409,7 +409,7 @@ public class PsdcSceneServiceImpl implements IPsdcSceneService {
switch (value){
case "1":
return "open";
case "2":
case "0":
return "close";
default:
return "Start-End";

@ -7,6 +7,7 @@
<result property="relationField" column="relation_field" />
<result property="ioDesc" column="io_desc" />
<result property="ioType" column="io_type" />
<result property="ioRemark" column="io_remark" />
</resultMap>
<!--新增数据-->
@ -66,7 +67,7 @@
<!-- 通过model_name查询数据 -->
<select id="selDevIsControlByModelName" resultMap="PsdcModelMap">
Select
model_id,model_name,relation_field,io_desc,io_type
model_id,model_name,relation_field,io_desc,io_type,io_remark
From psdc_model
Where model_name = #{modelName} And io_type = "serve"
</select>

@ -16,8 +16,8 @@
<select id="queryByUser" resultMap="PsdcStrategyMap">
Select
strategy_id,user_id,strategy_name,strategy_code,scenes,strategy_info,create_by,create_time,update_by,update_time
From psdc_strategy
DISTINCT strategy_code,strategy_id,user_id,strategy_name,scenes,strategy_info,create_by,create_time,update_by,update_time
From psdc_strategy
<where>
<if test="userId != null and userId != ''">
And user_id = #{userId}
@ -26,7 +26,6 @@
And strategy_code = #{sceneCode}
</if>
</where>
Group By strategy_code
</select>
<!--新增数据-->

@ -51,7 +51,7 @@
And date_format(pth.update_time,'%Y-%m-%d %H:%i:%S') &lt;= date_format(#{endTime},'%Y-%m-%d %H:%i:%S')
</if>
</where>
GROUP BY PTH.update_time
GROUP BY pth.update_time
ORDER BY pth.update_time
</select>

Loading…
Cancel
Save