Commit 3f5f6d40 by tyfanchz

Merge remote-tracking branch 'origin/dev' into dev

2 parents c1e735c6 3a0501bf
......@@ -98,7 +98,7 @@ public class RemoteProductController {
SmartUserDevice record = new SmartUserDevice();
record.setUserId(userId);
List<SmartUserDevice> list = userDeviceService.getList(record);
if(CollectionUtils.isNotEmpty(list)){
if(CollectionUtils.isEmpty(list)){
return deviceRespList;
}
return productTypeService.remoteDeviceHandlerV2(list, status);
......
......@@ -115,4 +115,16 @@ public class UserDeviceController {
log.info("$$$$ /userDevice/sendCommand param: {}", req.toJSONString());
return userDeviceService.sendCommand(req);
}
/**
* 设备解绑
*
* @param req 请求
* @return 结果
*/
@RequestMapping(value = "/unbind", method = {RequestMethod.POST})
public String unbind(@RequestBody JSONObject req) {
log.info("$$$$ /userDevice/unbind param: {}", req.toJSONString());
return userDeviceService.unbind(req);
}
}
package com.glsx.smart.pojo;
import com.alibaba.nacos.common.utils.MD5Utils;
import lombok.Data;
import sun.security.provider.MD5;
/**
* @author zhouhaibao
......@@ -16,4 +18,8 @@ public class ExecuteTaskVo {
private String value;
private String deviceName;
private String msg;
private String phone;
private String channel="1";
}
......@@ -24,4 +24,6 @@ public interface SmartUserDeviceService {
String getUserBindKey(String token);
String sendCommand(JSONObject req);
String unbind(JSONObject req);
}
......@@ -5,7 +5,7 @@ import cn.com.glsx.didicb.app.model.CarAssistantInfo;
import cn.com.glsx.didicb.app.remote.CarAssistantInfoRemote;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.common.utils.MD5Utils;
import com.glsx.smart.constant.Constants;
import com.glsx.smart.dao.entity.SmartDeviceStatus;
import com.glsx.smart.dao.entity.SmartScene;
import com.glsx.smart.dao.entity.SmartSceneData;
......@@ -190,10 +190,7 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
try {
for (int i = 0; i < orders.size(); i++) {
OrderResponse orderResponse = new OrderResponse();
Map<String, List<Map<String, Object>>> ordermaps = new HashMap<>();
SmartSceneData index = orders.get(i);
List<Map<String, Object>> maps = new ArrayList<>();
Map<String, Object> ordermap = new HashMap<>();
String paramValue = index.getParamValue();
if (StringUtils.isEmpty(paramValue)) {
log.info("参数异常{}", index.getParamKey());
......@@ -209,6 +206,7 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
String devideId = executeTaskVo.getSelect();
JSONObject jsonObject = null;
if (StringUtils.isBlank(remoteId)) {
// 下发普通指令
// 如果设备状态已经是设置的,不重复下发
String order_value = executeTaskVo.getOrderVal() == null ? executeTaskVo.getValue() : executeTaskVo.getOrderVal();
SmartDeviceStatus smartDevideStatus = smartDeviceStatusMapper.findDevStatusByIdAndCode(devideId, executeTaskVo.getOrder());
......@@ -216,17 +214,12 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
log.info("该设备已经设置成当前需要的状态,设备id{}", devideId);
continue;
}
String valueType = executeTaskVo.getValType();
ordermap.put("code", executeTaskVo.getOrder());
ordermap.put("value", revertType(valueType, order_value));
maps.add(ordermap);
ordermaps.put("commands", maps);
log.info("发送的指令{}", JSON.toJSONString(maps));
// 下发普通指令
jsonObject = HttpUtil.sendPost(orderIssueurl.replace("{device_id}", devideId), JSONObject.toJSONString(ordermaps), new HashMap<>());
Map<String, Object> objectMap = buildOrderIssueParam(executeTaskVo, order_value);
jsonObject = HttpUtil.sendPost(orderIssueurl.replace("{device_id}", executeTaskVo.getChannel().equals(Constants.USER_CHANNEL_TUYA)?devideId:executeTaskVo.getPhone()).replace("{resource}",executeTaskVo.getChannel()), JSONObject.toJSONString(objectMap), new HashMap<>());
} else {
ordermap.put("key", executeTaskVo.getOrderVal());
// 下发红外遥控指令
Map<String, Object> ordermap = new HashMap<>();
ordermap.put("key", executeTaskVo.getOrderVal());
jsonObject = HttpUtil.sendPost(instructionInfIssue.replace("{remote_id}", remoteId).replace("{infrared_id}", devideId), JSONObject.toJSONString(ordermap), new HashMap<>());
}
if (jsonObject != null) {
......@@ -262,6 +255,28 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
return orderResponseList;
}
private Map<String, Object> buildOrderIssueParam(ExecuteTaskVo executeTaskVo, String order_value) {
String channel = executeTaskVo.getChannel();
String valueType = executeTaskVo.getValue();
Map<String, Object> ordermaps = new HashMap<>();
List<Map<String, Object>> maps = new ArrayList<>();
Map<String, Object> ordermap = new HashMap<>();
if(channel.equals(Constants.USER_CHANNEL_TUYA)) {
ordermap.put("code", executeTaskVo.getOrder());
ordermap.put("value", revertType(valueType, order_value));
maps.add(ordermap);
ordermaps.put("commands", maps);
log.info("涂鸦发送的指令{}", JSON.toJSONString(maps));
}else if(channel.equals(Constants.USER_CHANNEL_AQARA)){
ordermap.put(executeTaskVo.getOrder(),revertType(valueType, order_value));
maps.add(ordermap);
ordermaps.put("attrs", maps);
ordermaps.put("did", executeTaskVo.getSelect());
log.info("aqara发送的指令{}", JSON.toJSONString(ordermaps));
}
return ordermaps;
}
/**
* 下发系统通知
*
......@@ -346,7 +361,7 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
content = MessageFormat.format("您配置的{0}场景未顺利执行,点击可查看详情。", scene_name);
}
paramMap.put("body", content);
String context = buildBody(user_id, title, collect, scene.getId(), scene_name);
String context = buildBody(collect,scene_name);
paramMap.put("msgBody", context);
saveMegInfo(user_id, title, context);
if(StringUtils.isEmpty(source)){
......@@ -384,13 +399,10 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
/**
* 消息推送到app端
*
* @param user_id 用户id
* @param title 标题
* @param orderResponseList 内容
* @param id 场景id
* @param scene_name
*/
private String buildBody(String user_id, String title, List<OrderResponse> orderResponseList, Long id, String scene_name) {
private String buildBody(List<OrderResponse> orderResponseList, String scene_name) {
String context = "";
if (CollectionUtils.isEmpty(orderResponseList)) {
context = MessageFormat.format("您配置的{0}场景已在{1} 成功执行", scene_name, new Date());
......@@ -407,8 +419,4 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
return context;
}
public static void main(String[] args) {
System.out.println(MD5Utils.md5Hex("13450798972","utf-8"));
}
}
......@@ -48,6 +48,9 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser
@Value("${user_send_command}")
private String userSendCommandApi;
@Value("${unbindUrl}")
private String unbindUrl;
@Value("${user_device_subscribe}")
private String userDeviceSubscribeApi;
......@@ -151,6 +154,18 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser
return result;
}
@Override
public String unbind(JSONObject req) {
String url = remoteUrl + unbindUrl;
log.info("$$$$ unbind url = {}, param: {}", url, req.toJSONString());
String respJson = HttpUtils.get(url, req);
log.info("$$$$ unbind resp = {}", respJson);
JSONObject respObj = JSON.parseObject(respJson);
String result = "200".equals(respObj.getString("code"))
? "true" : "false";
return result;
}
/**
* 订阅用户设备
*
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!