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 3a0501bf
authored
Apr 27, 2021
by
111-PC\111
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]aqara需求
1 parent
ac785e82
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
65 additions
and
22 deletions
src/main/java/com/glsx/smart/controller/UserDeviceController.java
src/main/java/com/glsx/smart/pojo/ExecuteTaskVo.java
src/main/java/com/glsx/smart/service/SmartUserDeviceService.java
src/main/java/com/glsx/smart/service/impl/SmartSceneServiceImpl.java
src/main/java/com/glsx/smart/service/impl/SmartUserDeviceServiceImpl.java
src/main/java/com/glsx/smart/controller/UserDeviceController.java
View file @
3a0501b
...
...
@@ -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
);
}
}
src/main/java/com/glsx/smart/pojo/ExecuteTaskVo.java
View file @
3a0501b
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"
;
}
src/main/java/com/glsx/smart/service/SmartUserDeviceService.java
View file @
3a0501b
...
...
@@ -24,4 +24,6 @@ public interface SmartUserDeviceService {
String
getUserBindKey
(
String
token
);
String
sendCommand
(
JSONObject
req
);
String
unbind
(
JSONObject
req
);
}
src/main/java/com/glsx/smart/service/impl/SmartSceneServiceImpl.java
View file @
3a0501b
...
...
@@ -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.MD5Util
s
;
import
com.
glsx.smart.constant.Constant
s
;
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"
));
}
}
src/main/java/com/glsx/smart/service/impl/SmartUserDeviceServiceImpl.java
View file @
3a0501b
...
...
@@ -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
;
}
/**
* 订阅用户设备
*
...
...
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