Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
open-source
/
chejia-smart-service
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 3708582a
authored
Apr 25, 2021
by
tyfanchz
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
下发指令接口
1 parent
30f5fd5e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
31 deletions
src/main/java/com/glsx/smart/controller/UserDeviceController.java
src/main/java/com/glsx/smart/service/SmartUserDeviceService.java
src/main/java/com/glsx/smart/service/impl/SmartUserDeviceServiceImpl.java
src/main/java/com/glsx/smart/controller/UserDeviceController.java
View file @
3708582
...
@@ -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
);
}
}
}
src/main/java/com/glsx/smart/service/SmartUserDeviceService.java
View file @
3708582
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
);
}
}
src/main/java/com/glsx/smart/service/impl/SmartUserDeviceServiceImpl.java
View file @
3708582
...
@@ -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"
);
}
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment