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 3023a4ae
authored
Mar 25, 2021
by
111-PC\111
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]文件列表展示
1 parent
92c0c6cc
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
152 additions
and
4 deletions
src/main/java/com/glsx/smart/controller/SceneController.java
src/main/java/com/glsx/smart/pojo/ExecuteTaskVo.java
src/main/java/com/glsx/smart/pojo/ResponseVo.java
src/main/java/com/glsx/smart/service/SmartSceneService.java
src/main/java/com/glsx/smart/service/impl/SmartSceneServiceImpl.java
src/main/java/com/glsx/smart/utils/HttpUtil.java
src/main/java/com/glsx/smart/controller/SceneController.java
View file @
3023a4a
...
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
...
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
import
com.glsx.smart.dao.entity.SmartScene
;
import
com.glsx.smart.dao.entity.SmartScene
;
import
com.glsx.smart.service.SmartSceneDataService
;
import
com.glsx.smart.service.SmartSceneDataService
;
import
com.glsx.smart.service.SmartSceneService
;
import
com.glsx.smart.service.SmartSceneService
;
import
io.swagger.annotations.Api
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestBody
;
...
@@ -24,6 +25,7 @@ import java.util.List;
...
@@ -24,6 +25,7 @@ import java.util.List;
@Slf4j
@Slf4j
@RestController
@RestController
@RequestMapping
(
"/scene"
)
@RequestMapping
(
"/scene"
)
@Api
(
value
=
"场景管理"
,
tags
=
{
"场景管理"
})
public
class
SceneController
{
public
class
SceneController
{
@Autowired
@Autowired
...
@@ -68,4 +70,9 @@ public class SceneController {
...
@@ -68,4 +70,9 @@ public class SceneController {
log
.
info
(
"用户更新调用/scene/updateStatus param: {}"
,
JSON
.
toJSONString
(
scene
));
log
.
info
(
"用户更新调用/scene/updateStatus param: {}"
,
JSON
.
toJSONString
(
scene
));
return
sceneService
.
updateByPrimaryKeySelective
(
scene
)
>
0
?
true
:
false
;
return
sceneService
.
updateByPrimaryKeySelective
(
scene
)
>
0
?
true
:
false
;
}
}
@RequestMapping
(
value
=
"/issueOrder"
,
method
=
{
RequestMethod
.
POST
})
public
boolean
issueOrder
(
@RequestBody
SmartScene
scene
)
{
return
sceneService
.
issueOrder
(
scene
);
}
}
}
src/main/java/com/glsx/smart/pojo/ExecuteTaskVo.java
0 → 100644
View file @
3023a4a
package
com
.
glsx
.
smart
.
pojo
;
import
lombok.Data
;
/**
* @author zhouhaibao
* @date 2021/3/22 15:52
*/
@Data
public
class
ExecuteTaskVo
{
private
String
deviceId
;
private
String
orderCode
;
private
String
orderValue
;
private
String
orderValueType
;
private
String
remoteId
;
}
src/main/java/com/glsx/smart/pojo/ResponseVo.java
0 → 100644
View file @
3023a4a
package
com
.
glsx
.
smart
.
pojo
;
import
lombok.Data
;
/**
* @author zhouhaibao
* @date 2021/3/22 16:18
*/
@Data
public
class
ResponseVo
{
private
String
code
;
private
String
message
;
private
String
msg
;
}
src/main/java/com/glsx/smart/service/SmartSceneService.java
View file @
3023a4a
...
@@ -2,6 +2,7 @@ package com.glsx.smart.service;
...
@@ -2,6 +2,7 @@ package com.glsx.smart.service;
import
com.glsx.smart.dao.entity.SmartScene
;
import
com.glsx.smart.dao.entity.SmartScene
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -30,4 +31,5 @@ public interface SmartSceneService {
...
@@ -30,4 +31,5 @@ public interface SmartSceneService {
int
updateByPrimaryKeySelective
(
SmartScene
record
);
int
updateByPrimaryKeySelective
(
SmartScene
record
);
boolean
issueOrder
(
SmartScene
scene
);
}
}
src/main/java/com/glsx/smart/service/impl/SmartSceneServiceImpl.java
View file @
3023a4a
package
com
.
glsx
.
smart
.
service
.
impl
;
package
com
.
glsx
.
smart
.
service
.
impl
;
import
com.alibaba.fastjson.JSONObject
;
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
;
import
com.glsx.smart.dao.mapper.SmartSceneDataMapper
;
import
com.glsx.smart.dao.mapper.SmartSceneDataMapper
;
import
com.glsx.smart.dao.mapper.SmartSceneMapper
;
import
com.glsx.smart.dao.mapper.SmartSceneMapper
;
import
com.glsx.smart.exception.BusinessException
;
import
com.glsx.smart.exception.BusinessException
;
import
com.glsx.smart.exception.ResultEnum
;
import
com.glsx.smart.exception.ResultEnum
;
import
com.glsx.smart.pojo.ExecuteTaskVo
;
import
com.glsx.smart.pojo.ResponseVo
;
import
com.glsx.smart.service.BaseService
;
import
com.glsx.smart.service.BaseService
;
import
com.glsx.smart.service.SmartSceneService
;
import
com.glsx.smart.service.SmartSceneService
;
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.lang.StringUtils
;
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.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
java.util.stream.Collectors
;
/**
/**
* <p>Description:
* <p>Description:
...
@@ -32,6 +45,12 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
...
@@ -32,6 +45,12 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
@Resource
@Resource
private
SmartSceneDataMapper
sceneDataMapper
;
private
SmartSceneDataMapper
sceneDataMapper
;
@Value
(
"${orderIssueurl}"
)
private
String
orderIssueurl
;
@Value
(
"${instructionInfIssue}"
)
private
String
instructionInfIssue
;
@Override
@Override
public
List
<
SmartScene
>
getList
(
SmartScene
record
)
{
public
List
<
SmartScene
>
getList
(
SmartScene
record
)
{
return
sceneMapper
.
getList
(
record
);
return
sceneMapper
.
getList
(
record
);
...
@@ -67,9 +86,9 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
...
@@ -67,9 +86,9 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
int
i
=
sceneMapper
.
insertSelective
(
record
);
int
i
=
sceneMapper
.
insertSelective
(
record
);
Long
id
=
record
.
getId
();
Long
id
=
record
.
getId
();
log
.
info
(
"保存用户场景数据生成id:{}"
,
record
.
getId
());
log
.
info
(
"保存用户场景数据生成id:{}"
,
record
.
getId
());
if
(
i
>
0
)
{
if
(
i
>
0
)
{
List
<
SmartSceneData
>
list
=
record
.
getDataList
();
List
<
SmartSceneData
>
list
=
record
.
getDataList
();
if
(!
list
.
isEmpty
())
{
if
(!
list
.
isEmpty
())
{
for
(
SmartSceneData
data
:
list
)
{
for
(
SmartSceneData
data
:
list
)
{
data
.
setSceneId
(
id
);
data
.
setSceneId
(
id
);
}
}
...
@@ -84,10 +103,10 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
...
@@ -84,10 +103,10 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
public
int
update
(
SmartScene
record
)
{
public
int
update
(
SmartScene
record
)
{
Long
id
=
record
.
getId
();
Long
id
=
record
.
getId
();
int
i
=
sceneMapper
.
updateByPrimaryKeySelective
(
record
);
int
i
=
sceneMapper
.
updateByPrimaryKeySelective
(
record
);
if
(
i
>
0
)
{
if
(
i
>
0
)
{
sceneDataMapper
.
deleteBySceneId
(
id
);
sceneDataMapper
.
deleteBySceneId
(
id
);
List
<
SmartSceneData
>
list
=
record
.
getDataList
();
List
<
SmartSceneData
>
list
=
record
.
getDataList
();
if
(!
list
.
isEmpty
())
{
if
(!
list
.
isEmpty
())
{
for
(
SmartSceneData
data
:
list
)
{
for
(
SmartSceneData
data
:
list
)
{
data
.
setSceneId
(
id
);
data
.
setSceneId
(
id
);
}
}
...
@@ -107,4 +126,91 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
...
@@ -107,4 +126,91 @@ public class SmartSceneServiceImpl extends BaseService implements SmartSceneServ
return
sceneMapper
.
updateByPrimaryKeySelective
(
record
);
return
sceneMapper
.
updateByPrimaryKeySelective
(
record
);
}
}
private
Object
revertType
(
String
valueType
,
String
object
)
{
Object
orderValue
=
null
;
switch
(
valueType
)
{
case
"1"
:
orderValue
=
object
;
break
;
case
"2"
:
orderValue
=
Integer
.
parseInt
(
object
);
break
;
case
"3"
:
orderValue
=
Boolean
.
valueOf
(
object
);
break
;
default
:
orderValue
=
object
;
break
;
}
return
orderValue
;
}
@Override
public
boolean
issueOrder
(
SmartScene
scene
)
{
boolean
flag
=
false
;
List
<
SmartSceneData
>
smartTemplateParamList
=
sceneDataMapper
.
getBySceneId
(
scene
.
getId
());
if
(
CollectionUtils
.
isEmpty
(
smartTemplateParamList
))
{
log
.
info
(
"未查到该场景id的条件{}"
,
scene
.
getId
());
}
// 下发指令
List
<
SmartSceneData
>
orders
=
smartTemplateParamList
.
stream
().
filter
(
index
->
index
.
getParamKey
().
equals
(
"scene_content_device"
)).
collect
(
Collectors
.
toList
());
if
(
CollectionUtils
.
isEmpty
(
orders
))
{
log
.
info
(
"未查到该场景id的指令{}"
,
scene
.
getId
());
}
else
{
int
count
=
0
;
try
{
for
(
int
i
=
0
;
i
<
orders
.
size
();
i
++)
{
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
());
continue
;
}
ExecuteTaskVo
executeTaskVo
=
JSONObject
.
parseObject
(
paramValue
,
ExecuteTaskVo
.
class
);
if
(
StringUtils
.
isEmpty
(
executeTaskVo
.
getOrderCode
())
||
StringUtils
.
isEmpty
(
executeTaskVo
.
getDeviceId
()))
{
log
.
info
(
"参数异常{}"
,
index
.
getParamKey
());
continue
;
}
// 根据遥控器id下发普通指令还是红外遥控指令
String
remoteId
=
executeTaskVo
.
getRemoteId
();
String
devideId
=
executeTaskVo
.
getDeviceId
();
JSONObject
jsonObject
=
null
;
if
(
StringUtils
.
isBlank
(
remoteId
))
{
String
valueType
=
executeTaskVo
.
getOrderValueType
();
ordermap
.
put
(
"code"
,
executeTaskVo
.
getOrderCode
());
ordermap
.
put
(
"value"
,
revertType
(
valueType
,
executeTaskVo
.
getOrderValue
()));
maps
.
add
(
ordermap
);
ordermaps
.
put
(
"commands"
,
maps
);
// 下发普通指令
jsonObject
=
HttpUtil
.
sendPost
(
orderIssueurl
.
replace
(
"{device_id}"
,
devideId
),
JSONObject
.
toJSONString
(
ordermaps
),
new
HashMap
<>());
}
else
{
ordermap
.
put
(
"key"
,
executeTaskVo
.
getOrderCode
());
// 下发红外遥控指令
jsonObject
=
HttpUtil
.
sendPost
(
instructionInfIssue
.
replace
(
"{remote_id}"
,
remoteId
).
replace
(
"{infrared_id}"
,
devideId
),
JSONObject
.
toJSONString
(
ordermap
),
new
HashMap
<>());
}
if
(
jsonObject
!=
null
)
{
ResponseVo
responseVo
=
JSONObject
.
toJavaObject
(
jsonObject
,
ResponseVo
.
class
);
if
(
responseVo
.
getCode
().
equals
(
"200"
))
{
log
.
info
(
"设备{}下发成功"
,
devideId
);
count
++;
}
else
{
log
.
info
(
"设备{}下发失败,错误信息为{}"
,
devideId
,
responseVo
.
getMessage
());
}
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
log
.
info
(
"下发异常,{}"
,
e
);
return
flag
;
}
if
(
count
==
orders
.
size
())
{
flag
=
true
;
}
}
return
flag
;
}
}
}
src/main/java/com/glsx/smart/utils/HttpUtil.java
0 → 100644
View file @
3023a4a
This diff is collapsed.
Click to expand it.
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