Commit e685d3a1 by wnb0128

Merge branch 'dev' of 192.168.3.233:open-source/chejia-smart-service into dev

2 parents ef2c2dc0 3708582a
...@@ -2,6 +2,7 @@ package com.glsx.smart.controller; ...@@ -2,6 +2,7 @@ package com.glsx.smart.controller;
import java.util.List; import java.util.List;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.glsx.plat.common.utils.StringUtils; import com.glsx.plat.common.utils.StringUtils;
import com.glsx.plat.core.web.R; import com.glsx.plat.core.web.R;
import com.glsx.smart.dao.entity.SmartUserDevice; import com.glsx.smart.dao.entity.SmartUserDevice;
...@@ -106,4 +107,17 @@ public class UserDeviceController { ...@@ -106,4 +107,17 @@ public class UserDeviceController {
String userBindKey = userDeviceService.getUserBindKey(username); String userBindKey = userDeviceService.getUserBindKey(username);
return R.ok().data(userBindKey); return R.ok().data(userBindKey);
} }
/**
* 下发指令
*
* @param req 请求
* @return 结果
*/
@RequestMapping(value = "/sendCommand", method = {RequestMethod.POST})
public R sendCommand(JSONObject req) {
log.info("$$$$ /userDevice/sendCommand param: {}", req.toJSONString());
String result = userDeviceService.sendCommand(req);
return R.ok().data(result);
}
} }
package com.glsx.smart.service; package com.glsx.smart.service;
import java.util.List; import java.util.List;
import com.alibaba.fastjson.JSONObject;
import com.glsx.smart.dao.entity.SmartUserDevice; import com.glsx.smart.dao.entity.SmartUserDevice;
/** /**
...@@ -21,4 +22,6 @@ public interface SmartUserDeviceService { ...@@ -21,4 +22,6 @@ public interface SmartUserDeviceService {
int deleteDevice(SmartUserDevice req); int deleteDevice(SmartUserDevice req);
String getUserBindKey(String username); String getUserBindKey(String username);
String sendCommand(JSONObject req);
} }
...@@ -36,6 +36,9 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser ...@@ -36,6 +36,9 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser
@Value("${user_bind_key}") @Value("${user_bind_key}")
private String userBindKeyApi; private String userBindKeyApi;
@Value("${user_send_command}")
private String userSendCommandApi;
@Resource @Resource
private SmartUserDeviceMapper userDeviceMapper; private SmartUserDeviceMapper userDeviceMapper;
...@@ -87,36 +90,6 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser ...@@ -87,36 +90,6 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser
savedUserDevice.setUpdateTime(now); savedUserDevice.setUpdateTime(now);
rows = userDeviceMapper.updateByPrimaryKeySelective(savedUserDevice); rows = userDeviceMapper.updateByPrimaryKeySelective(savedUserDevice);
} }
//// 主键传空表示新增
//if (req.getId() == null) {
// if (StringUtils.isBlank(req.getUid())) {
// throw BusinessException.create(ResultEnum.PARAM_ERROR);
// }
// SmartUserChannel ucRecord = new SmartUserChannel();
// ucRecord.setThirdId(req.getUid());
// SmartUserChannel savedUserChannel = userChannelMapper.selectOne(ucRecord);
// if (savedUserChannel == null) {
// throw BusinessException.create(ResultEnum.USER_NOT_FOUND);
// }
// req.setUserId(savedUserChannel.getUserId());
// req.setCreateTime(now);
// req.setUpdateTime(now);
// rows = userDeviceMapper.insertSelective(req);
//} else {
// if (StringUtils.isBlank(req.getDeviceName())) {
// throw BusinessException.create(ResultEnum.PARAM_ERROR);
// }
// SmartUserDevice record = new SmartUserDevice();
// record.setDeviceId(req.getDeviceId());
// record.setChannel(req.getChannel());
// SmartUserDevice savedUserDevice = userDeviceMapper.selectOne(record);
// if (savedUserDevice == null) {
// throw BusinessException.create(ResultEnum.DEVICE_NOT_FOUND);
// }
// savedUserDevice.setDeviceName(req.getDeviceName());
// savedUserDevice.setUpdateTime(now);
// rows = userDeviceMapper.updateByPrimaryKeySelective(savedUserDevice);
//}
return rows; return rows;
} }
...@@ -132,7 +105,7 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser ...@@ -132,7 +105,7 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser
JSONObject reqObj = new JSONObject(); JSONObject reqObj = new JSONObject();
reqObj.put("username", username); reqObj.put("username", username);
String url = remoteUrl + userBindKeyApi; String url = remoteUrl + userBindKeyApi;
log.info("$$$$ getUserBindKey url = {}, req = {}", url, JSON.toJSONString(reqObj)); log.info("$$$$ getUserBindKey url = {}, req = {}", url, reqObj.toJSONString());
String respJson = HttpUtils.get(url, reqObj); String respJson = HttpUtils.get(url, reqObj);
log.info("$$$$ getUserBindKey resp = {}", respJson); log.info("$$$$ getUserBindKey resp = {}", respJson);
JSONObject respObj = JSON.parseObject(respJson); JSONObject respObj = JSON.parseObject(respJson);
...@@ -140,4 +113,14 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser ...@@ -140,4 +113,14 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser
? respObj.getJSONObject("message").getString("bindKey") : null; ? respObj.getJSONObject("message").getString("bindKey") : null;
return bindKey; return bindKey;
} }
@Override
public String sendCommand(JSONObject req) {
String url = remoteUrl + userSendCommandApi;
log.info("$$$$ sendCommand url = {}, param: {}", url, req.toJSONString());
String respJson = HttpUtils.post(url, req.toJSONString());
log.info("$$$$ sendCommand resp = {}", respJson);
JSONObject respObj = JSON.parseObject(respJson);
return respObj.getString("result");
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!