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 3f5f6d40
authored
Apr 27, 2021
by
tyfanchz
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge remote-tracking branch 'origin/dev' into dev
2 parents
c1e735c6
3a0501bf
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
66 additions
and
23 deletions
src/main/java/com/glsx/smart/controller/RemoteProductController.java
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/RemoteProductController.java
View file @
3f5f6d4
...
@@ -98,7 +98,7 @@ public class RemoteProductController {
...
@@ -98,7 +98,7 @@ public class RemoteProductController {
SmartUserDevice
record
=
new
SmartUserDevice
();
SmartUserDevice
record
=
new
SmartUserDevice
();
record
.
setUserId
(
userId
);
record
.
setUserId
(
userId
);
List
<
SmartUserDevice
>
list
=
userDeviceService
.
getList
(
record
);
List
<
SmartUserDevice
>
list
=
userDeviceService
.
getList
(
record
);
if
(
CollectionUtils
.
is
Not
Empty
(
list
)){
if
(
CollectionUtils
.
isEmpty
(
list
)){
return
deviceRespList
;
return
deviceRespList
;
}
}
return
productTypeService
.
remoteDeviceHandlerV2
(
list
,
status
);
return
productTypeService
.
remoteDeviceHandlerV2
(
list
,
status
);
...
...
src/main/java/com/glsx/smart/controller/UserDeviceController.java
View file @
3f5f6d4
...
@@ -115,4 +115,16 @@ public class UserDeviceController {
...
@@ -115,4 +115,16 @@ public class UserDeviceController {
log
.
info
(
"$$$$ /userDevice/sendCommand param: {}"
,
req
.
toJSONString
());
log
.
info
(
"$$$$ /userDevice/sendCommand param: {}"
,
req
.
toJSONString
());
return
userDeviceService
.
sendCommand
(
req
);
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 @
3f5f6d4
package
com
.
glsx
.
smart
.
pojo
;
package
com
.
glsx
.
smart
.
pojo
;
import
com.alibaba.nacos.common.utils.MD5Utils
;
import
lombok.Data
;
import
lombok.Data
;
import
sun.security.provider.MD5
;
/**
/**
* @author zhouhaibao
* @author zhouhaibao
...
@@ -16,4 +18,8 @@ public class ExecuteTaskVo {
...
@@ -16,4 +18,8 @@ public class ExecuteTaskVo {
private
String
value
;
private
String
value
;
private
String
deviceName
;
private
String
deviceName
;
private
String
msg
;
private
String
msg
;
private
String
phone
;
private
String
channel
=
"1"
;
}
}
src/main/java/com/glsx/smart/service/SmartUserDeviceService.java
View file @
3f5f6d4
...
@@ -24,4 +24,6 @@ public interface SmartUserDeviceService {
...
@@ -24,4 +24,6 @@ public interface SmartUserDeviceService {
String
getUserBindKey
(
String
token
);
String
getUserBindKey
(
String
token
);
String
sendCommand
(
JSONObject
req
);
String
sendCommand
(
JSONObject
req
);
String
unbind
(
JSONObject
req
);
}
}
src/main/java/com/glsx/smart/service/impl/SmartSceneServiceImpl.java
View file @
3f5f6d4
...
@@ -5,7 +5,7 @@ import cn.com.glsx.didicb.app.model.CarAssistantInfo;
...
@@ -5,7 +5,7 @@ import cn.com.glsx.didicb.app.model.CarAssistantInfo;
import
cn.com.glsx.didicb.app.remote.CarAssistantInfoRemote
;
import
cn.com.glsx.didicb.app.remote.CarAssistantInfoRemote
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
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.SmartDeviceStatus
;
import
com.glsx.smart.dao.entity.SmartScene
;
import
com.glsx.smart.dao.entity.SmartScene
;
import
com.glsx.smart.dao.entity.SmartSceneData
;
import
com.glsx.smart.dao.entity.SmartSceneData
;
...
@@ -190,10 +190,7 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
...
@@ -190,10 +190,7 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
try
{
try
{
for
(
int
i
=
0
;
i
<
orders
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
orders
.
size
();
i
++)
{
OrderResponse
orderResponse
=
new
OrderResponse
();
OrderResponse
orderResponse
=
new
OrderResponse
();
Map
<
String
,
List
<
Map
<
String
,
Object
>>>
ordermaps
=
new
HashMap
<>();
SmartSceneData
index
=
orders
.
get
(
i
);
SmartSceneData
index
=
orders
.
get
(
i
);
List
<
Map
<
String
,
Object
>>
maps
=
new
ArrayList
<>();
Map
<
String
,
Object
>
ordermap
=
new
HashMap
<>();
String
paramValue
=
index
.
getParamValue
();
String
paramValue
=
index
.
getParamValue
();
if
(
StringUtils
.
isEmpty
(
paramValue
))
{
if
(
StringUtils
.
isEmpty
(
paramValue
))
{
log
.
info
(
"参数异常{}"
,
index
.
getParamKey
());
log
.
info
(
"参数异常{}"
,
index
.
getParamKey
());
...
@@ -209,6 +206,7 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
...
@@ -209,6 +206,7 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
String
devideId
=
executeTaskVo
.
getSelect
();
String
devideId
=
executeTaskVo
.
getSelect
();
JSONObject
jsonObject
=
null
;
JSONObject
jsonObject
=
null
;
if
(
StringUtils
.
isBlank
(
remoteId
))
{
if
(
StringUtils
.
isBlank
(
remoteId
))
{
// 下发普通指令
// 如果设备状态已经是设置的,不重复下发
// 如果设备状态已经是设置的,不重复下发
String
order_value
=
executeTaskVo
.
getOrderVal
()
==
null
?
executeTaskVo
.
getValue
()
:
executeTaskVo
.
getOrderVal
();
String
order_value
=
executeTaskVo
.
getOrderVal
()
==
null
?
executeTaskVo
.
getValue
()
:
executeTaskVo
.
getOrderVal
();
SmartDeviceStatus
smartDevideStatus
=
smartDeviceStatusMapper
.
findDevStatusByIdAndCode
(
devideId
,
executeTaskVo
.
getOrder
());
SmartDeviceStatus
smartDevideStatus
=
smartDeviceStatusMapper
.
findDevStatusByIdAndCode
(
devideId
,
executeTaskVo
.
getOrder
());
...
@@ -216,17 +214,12 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
...
@@ -216,17 +214,12 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
log
.
info
(
"该设备已经设置成当前需要的状态,设备id{}"
,
devideId
);
log
.
info
(
"该设备已经设置成当前需要的状态,设备id{}"
,
devideId
);
continue
;
continue
;
}
}
String
valueType
=
executeTaskVo
.
getValType
();
Map
<
String
,
Object
>
objectMap
=
buildOrderIssueParam
(
executeTaskVo
,
order_value
);
ordermap
.
put
(
"code"
,
executeTaskVo
.
getOrder
());
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
<>());
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
<>());
}
else
{
}
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
<>());
jsonObject
=
HttpUtil
.
sendPost
(
instructionInfIssue
.
replace
(
"{remote_id}"
,
remoteId
).
replace
(
"{infrared_id}"
,
devideId
),
JSONObject
.
toJSONString
(
ordermap
),
new
HashMap
<>());
}
}
if
(
jsonObject
!=
null
)
{
if
(
jsonObject
!=
null
)
{
...
@@ -262,6 +255,28 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
...
@@ -262,6 +255,28 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
return
orderResponseList
;
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
...
@@ -346,7 +361,7 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
content
=
MessageFormat
.
format
(
"您配置的{0}场景未顺利执行,点击可查看详情。"
,
scene_name
);
content
=
MessageFormat
.
format
(
"您配置的{0}场景未顺利执行,点击可查看详情。"
,
scene_name
);
}
}
paramMap
.
put
(
"body"
,
content
);
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
);
paramMap
.
put
(
"msgBody"
,
context
);
saveMegInfo
(
user_id
,
title
,
context
);
saveMegInfo
(
user_id
,
title
,
context
);
if
(
StringUtils
.
isEmpty
(
source
)){
if
(
StringUtils
.
isEmpty
(
source
)){
...
@@ -384,13 +399,10 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
...
@@ -384,13 +399,10 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
/**
/**
* 消息推送到app端
* 消息推送到app端
*
*
* @param user_id 用户id
* @param title 标题
* @param orderResponseList 内容
* @param orderResponseList 内容
* @param id 场景id
* @param scene_name
* @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
=
""
;
String
context
=
""
;
if
(
CollectionUtils
.
isEmpty
(
orderResponseList
))
{
if
(
CollectionUtils
.
isEmpty
(
orderResponseList
))
{
context
=
MessageFormat
.
format
(
"您配置的{0}场景已在{1} 成功执行"
,
scene_name
,
new
Date
());
context
=
MessageFormat
.
format
(
"您配置的{0}场景已在{1} 成功执行"
,
scene_name
,
new
Date
());
...
@@ -407,8 +419,4 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
...
@@ -407,8 +419,4 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
return
context
;
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 @
3f5f6d4
...
@@ -48,6 +48,9 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser
...
@@ -48,6 +48,9 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser
@Value
(
"${user_send_command}"
)
@Value
(
"${user_send_command}"
)
private
String
userSendCommandApi
;
private
String
userSendCommandApi
;
@Value
(
"${unbindUrl}"
)
private
String
unbindUrl
;
@Value
(
"${user_device_subscribe}"
)
@Value
(
"${user_device_subscribe}"
)
private
String
userDeviceSubscribeApi
;
private
String
userDeviceSubscribeApi
;
...
@@ -151,6 +154,18 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser
...
@@ -151,6 +154,18 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser
return
result
;
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