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 2faf6064
authored
Apr 11, 2021
by
111-PC\111
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]代码修改
1 parent
d1bd1c5c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
118 additions
and
13 deletions
pom.xml
src/main/java/com/glsx/smart/dao/mapper/SmartSceneMapper.java
src/main/java/com/glsx/smart/pojo/ExecuteTaskVo.java
src/main/java/com/glsx/smart/service/impl/SmartSceneServiceImpl.java
src/main/resources/mapper/SmartSceneMapper.xml
pom.xml
View file @
2faf606
...
@@ -27,6 +27,18 @@
...
@@ -27,6 +27,18 @@
<artifactId>
rest-admin-registry
</artifactId>
<artifactId>
rest-admin-registry
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
cn.com.glsx
</groupId>
<artifactId>
rpc-didicb-app-api
</artifactId>
<version>
0.0.1-SNAPSHOT
</version>
<exclusions>
<exclusion>
<groupId>
com.github.pagehelper
</groupId>
<artifactId>
pagehelper
</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--lombok-->
<!--lombok-->
<dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<groupId>
org.projectlombok
</groupId>
...
...
src/main/java/com/glsx/smart/dao/mapper/SmartSceneMapper.java
View file @
2faf606
...
@@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.Mapper;
...
@@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.Mapper;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
/**
/**
* <p>Description:
* <p>Description:
...
@@ -30,4 +31,5 @@ public interface SmartSceneMapper extends tk.mybatis.mapper.common.Mapper<SmartS
...
@@ -30,4 +31,5 @@ public interface SmartSceneMapper extends tk.mybatis.mapper.common.Mapper<SmartS
SmartScene
getById
(
Long
id
);
SmartScene
getById
(
Long
id
);
Map
<
String
,
Object
>
getBySourceAndUserId
(
Long
id
);
}
}
src/main/java/com/glsx/smart/pojo/ExecuteTaskVo.java
View file @
2faf606
...
@@ -14,4 +14,5 @@ public class ExecuteTaskVo {
...
@@ -14,4 +14,5 @@ public class ExecuteTaskVo {
private
String
valType
;
private
String
valType
;
private
String
remoteId
;
private
String
remoteId
;
private
String
value
;
private
String
value
;
private
String
deviceName
;
}
}
src/main/java/com/glsx/smart/service/impl/SmartSceneServiceImpl.java
View file @
2faf606
package
com
.
glsx
.
smart
.
service
.
impl
;
package
com
.
glsx
.
smart
.
service
.
impl
;
import
cn.com.glsx.didicb.app.enums.MessagePushResultEnum
;
import
cn.com.glsx.didicb.app.model.MessageBoxInfo
;
import
cn.com.glsx.didicb.app.remote.MessageBoxInfoRemote
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.glsx.plat.core.web.R
;
import
com.glsx.smart.dao.entity.SmartProduct
;
import
com.glsx.smart.dao.entity.SmartProduct
;
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
;
...
@@ -19,17 +21,19 @@ import com.glsx.smart.utils.HttpUtil;
...
@@ -19,17 +21,19 @@ import com.glsx.smart.utils.HttpUtil;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.dubbo.config.annotation.DubboReference
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.text.MessageFormat
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
/**
/**
...
@@ -51,12 +55,18 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
...
@@ -51,12 +55,18 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
@Resource
@Resource
private
SmartProductMapper
productMapper
;
private
SmartProductMapper
productMapper
;
@DubboReference
private
MessageBoxInfoRemote
messageBoxInfoRemote
;
@Value
(
"${orderIssueurl}"
)
@Value
(
"${orderIssueurl}"
)
private
String
orderIssueurl
;
private
String
orderIssueurl
;
@Value
(
"${instructionInfIssue}"
)
@Value
(
"${instructionInfIssue}"
)
private
String
instructionInfIssue
;
private
String
instructionInfIssue
;
@Value
(
"${infoUrl}"
)
private
String
infoUrl
;
@Override
@Override
public
List
<
SmartScene
>
getList
(
SmartScene
record
)
{
public
List
<
SmartScene
>
getList
(
SmartScene
record
)
{
return
sceneMapper
.
getList
(
record
);
return
sceneMapper
.
getList
(
record
);
...
@@ -151,12 +161,19 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
...
@@ -151,12 +161,19 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
return
orderValue
;
return
orderValue
;
}
}
/**
* 下发场景
*
* @param scene 场景
* @return
*/
@Override
@Override
public
List
<
OrderResponse
>
issueOrder
(
SmartScene
scene
)
{
public
List
<
OrderResponse
>
issueOrder
(
SmartScene
scene
)
{
List
<
OrderResponse
>
orderResponseList
=
new
ArrayList
<>();
List
<
OrderResponse
>
orderResponseList
=
new
ArrayList
<>();
List
<
SmartSceneData
>
smartTemplateParamList
=
sceneDataMapper
.
getBySceneId
(
scene
.
getId
());
List
<
SmartSceneData
>
smartTemplateParamList
=
sceneDataMapper
.
getBySceneId
(
scene
.
getId
());
if
(
CollectionUtils
.
isEmpty
(
smartTemplateParamList
))
{
if
(
CollectionUtils
.
isEmpty
(
smartTemplateParamList
))
{
log
.
info
(
"未查到该场景id的条件{}"
,
scene
.
getId
());
log
.
info
(
"未查到该场景id的条件{}"
,
scene
.
getId
());
return
orderResponseList
;
}
}
// 下发指令
// 下发指令
List
<
SmartSceneData
>
orders
=
smartTemplateParamList
.
stream
().
filter
(
index
->
index
.
getParamKey
().
equals
(
"scene_content_device"
)).
collect
(
Collectors
.
toList
());
List
<
SmartSceneData
>
orders
=
smartTemplateParamList
.
stream
().
filter
(
index
->
index
.
getParamKey
().
equals
(
"scene_content_device"
)).
collect
(
Collectors
.
toList
());
...
@@ -187,7 +204,7 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
...
@@ -187,7 +204,7 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
if
(
StringUtils
.
isBlank
(
remoteId
))
{
if
(
StringUtils
.
isBlank
(
remoteId
))
{
String
valueType
=
executeTaskVo
.
getValType
();
String
valueType
=
executeTaskVo
.
getValType
();
ordermap
.
put
(
"code"
,
executeTaskVo
.
getOrder
());
ordermap
.
put
(
"code"
,
executeTaskVo
.
getOrder
());
ordermap
.
put
(
"value"
,
revertType
(
valueType
,
executeTaskVo
.
getOrderVal
()
==
null
?
executeTaskVo
.
getValue
():
executeTaskVo
.
getOrderVal
()));
ordermap
.
put
(
"value"
,
revertType
(
valueType
,
executeTaskVo
.
getOrderVal
()
==
null
?
executeTaskVo
.
getValue
()
:
executeTaskVo
.
getOrderVal
()));
maps
.
add
(
ordermap
);
maps
.
add
(
ordermap
);
ordermaps
.
put
(
"commands"
,
maps
);
ordermaps
.
put
(
"commands"
,
maps
);
// 下发普通指令
// 下发普通指令
...
@@ -209,12 +226,7 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
...
@@ -209,12 +226,7 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
orderResponse
.
setMessage
(
responseVo
.
getMessage
());
orderResponse
.
setMessage
(
responseVo
.
getMessage
());
orderResponse
.
setCode
(
Integer
.
parseInt
(
responseVo
.
getCode
()));
orderResponse
.
setCode
(
Integer
.
parseInt
(
responseVo
.
getCode
()));
}
}
SmartProduct
smartProduct
=
new
SmartProduct
();
orderResponse
.
setDeviceName
(
executeTaskVo
.
getDeviceName
());
smartProduct
.
setPlatformProductId
(
devideId
);
List
<
SmartProduct
>
byCondition
=
productMapper
.
getByCondition
(
smartProduct
);
if
(
CollectionUtils
.
isNotEmpty
(
byCondition
))
{
orderResponse
.
setDeviceName
(
byCondition
.
get
(
0
).
getProductName
());
}
orderResponseList
.
add
(
orderResponse
);
orderResponseList
.
add
(
orderResponse
);
}
}
}
}
...
@@ -223,6 +235,77 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
...
@@ -223,6 +235,77 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
log
.
info
(
"下发异常,{}"
,
e
);
log
.
info
(
"下发异常,{}"
,
e
);
}
}
}
}
// 下发推送通知(Android设备和ios设备)
issueNotice
(
scene
,
orderResponseList
);
return
orderResponseList
;
return
orderResponseList
;
}
}
/**
* 推送通知
*
* @param scene 场景
* @param orderResponseList 下发场景返回的消息
*/
private
void
issueNotice
(
SmartScene
scene
,
List
<
OrderResponse
>
orderResponseList
)
{
if
(
CollectionUtils
.
isNotEmpty
(
orderResponseList
))
{
String
content
=
""
;
String
title
=
"收到一条智能消息"
;
Map
<
String
,
Object
>
map
=
sceneMapper
.
getBySourceAndUserId
(
scene
.
getId
());
String
user_id
=
map
.
get
(
"user_id"
)+
""
;
String
scene_name
=
map
.
get
(
"scene_name"
)+
""
;
Map
<
String
,
String
>
paramMap
=
new
HashMap
<>();
paramMap
.
put
(
"alias"
,
user_id
);
paramMap
.
put
(
"deviceType"
,
map
.
get
(
"source"
)+
""
);
paramMap
.
put
(
"title"
,
title
);
List
<
OrderResponse
>
collect
=
orderResponseList
.
stream
().
filter
(
index
->
!
index
.
isResult
()).
collect
(
Collectors
.
toList
());
if
(
CollectionUtils
.
isEmpty
(
collect
))
{
content
=
MessageFormat
.
format
(
"您配置的{0}场景已执行,点击可查看详情。"
,
scene_name
);
}
else
{
content
=
MessageFormat
.
format
(
"您配置的{0}场景未顺利执行,点击可查看详情。"
,
scene_name
);
}
paramMap
.
put
(
"body"
,
content
);
saveInfo
(
user_id
,
title
,
collect
,
scene
.
getId
(),
scene_name
);
try
{
JSONObject
jsonObject
=
HttpUtil
.
sendPost
(
infoUrl
,
JSONObject
.
toJSONString
(
paramMap
),
new
HashMap
<>());
if
(
jsonObject
!=
null
)
{
String
code
=
jsonObject
.
get
(
"code"
)
+
""
;
if
((
"200"
).
equals
(
code
))
{
log
.
info
(
"场景{}下发通知成功"
,
scene
.
getId
());
}
else
{
log
.
info
(
"场景{}下发通知失败"
,
jsonObject
.
get
(
"message"
));
}
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
/**
* 消息推送到app端
*
* @param user_id 用户id
* @param title 标题
* @param orderResponseList 内容
* @param id 场景id
* @param scene_name
*/
private
void
saveInfo
(
String
user_id
,
String
title
,
List
<
OrderResponse
>
orderResponseList
,
Long
id
,
String
scene_name
)
{
String
context
=
""
;
if
(
CollectionUtils
.
isEmpty
(
orderResponseList
))
{
context
=
MessageFormat
.
format
(
"您配置的{0}场景已在{1} 成功执行"
,
scene_name
,
new
Date
());
}
else
{
List
<
String
>
names
=
orderResponseList
.
stream
().
map
(
p
->
p
.
getDeviceName
()).
collect
(
Collectors
.
toList
());
context
=
MessageFormat
.
format
(
"您配置的{0}场景已在{1}触发执行,但因以下设备{2}未能执行成功,请关注以上设备状态"
,
scene_name
,
new
Date
(),
names
);
}
MessageBoxInfo
messageBoxInfo
=
new
MessageBoxInfo
();
messageBoxInfo
.
setAccountId
(
Integer
.
parseInt
(
user_id
));
messageBoxInfo
.
setSn
(
"88888888"
);
messageBoxInfo
.
setContent
(
context
);
messageBoxInfo
.
setTitle
(
title
);
messageBoxInfo
.
setExpandId
(
id
.
intValue
());
messageBoxInfo
.
setIsPushSuccess
(
MessagePushResultEnum
.
FAILURE
.
getValue
());
messageBoxInfoRemote
.
insert
(
messageBoxInfo
);
}
}
}
src/main/resources/mapper/SmartSceneMapper.xml
View file @
2faf606
...
@@ -24,7 +24,8 @@
...
@@ -24,7 +24,8 @@
<collection
property=
"iconUrl"
column=
"icon"
ofType=
"com.glsx.smart.dao.entity.SmartScene"
fetchType=
"eager"
<collection
property=
"iconUrl"
column=
"icon"
ofType=
"com.glsx.smart.dao.entity.SmartScene"
fetchType=
"eager"
select=
"com.glsx.smart.dao.mapper.SmartSysFileMapper.selectUrlById"
>
select=
"com.glsx.smart.dao.mapper.SmartSysFileMapper.selectUrlById"
>
</collection>
</collection>
<collection
property=
"backPicUrl"
column=
"back_pic"
ofType=
"com.glsx.smart.dao.entity.SmartScene"
fetchType=
"eager"
<collection
property=
"backPicUrl"
column=
"back_pic"
ofType=
"com.glsx.smart.dao.entity.SmartScene"
fetchType=
"eager"
select=
"com.glsx.smart.dao.mapper.SmartSysFileMapper.selectUrlById"
>
select=
"com.glsx.smart.dao.mapper.SmartSysFileMapper.selectUrlById"
>
</collection>
</collection>
</resultMap>
</resultMap>
...
@@ -436,7 +437,7 @@
...
@@ -436,7 +437,7 @@
</insert>
</insert>
<select
id=
"getList"
parameterType=
"com.glsx.smart.dao.entity.SmartScene"
resultMap=
"DetailResultMap"
>
<select
id=
"getList"
parameterType=
"com.glsx.smart.dao.entity.SmartScene"
resultMap=
"DetailResultMap"
>
select
select
<include
refid=
"Base_Column_List"
/>
<include
refid=
"Base_Column_List"
/>
from smart_scene t
from smart_scene t
<where>
<where>
<if
test=
"typeKey != null and typeKey != ''"
>
<if
test=
"typeKey != null and typeKey != ''"
>
...
@@ -453,8 +454,14 @@
...
@@ -453,8 +454,14 @@
</select>
</select>
<select
id=
"getById"
parameterType=
"java.lang.Long"
resultMap=
"DetailResultMap"
>
<select
id=
"getById"
parameterType=
"java.lang.Long"
resultMap=
"DetailResultMap"
>
select
select
<include
refid=
"Base_Column_List"
/>
<include
refid=
"Base_Column_List"
/>
from smart_scene
from smart_scene
where id = #{id,jdbcType=BIGINT}
where id = #{id,jdbcType=BIGINT}
</select>
<select
id=
"getBySourceAndUserId"
resultType=
"java.util.Map"
>
select
t2.user_id ,t2.source,t1.scene_name
from smart_scene t1 left join smart_user_relation t2 on t1.user_id=t2.id
where t1.id = #{id,jdbcType=BIGINT}
</select>
</select>
</mapper>
</mapper>
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