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 6e967f50
authored
May 10, 2021
by
tyfanchz
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
代码修改
1 parent
140aaf97
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
484 additions
and
214 deletions
src/main/java/cn/com/glsx/smart/modules/controller/ProductController.java
src/main/java/cn/com/glsx/smart/modules/controller/ProductTypeController.java
src/main/java/cn/com/glsx/smart/modules/controller/RemoteProductController.java
src/main/java/cn/com/glsx/smart/modules/controller/UserDeviceController.java
src/main/java/cn/com/glsx/smart/modules/mapper/SmartUserDeviceMapper.java
src/main/java/cn/com/glsx/smart/modules/model/request/SmartUserDeviceDeleteReq.java
src/main/java/cn/com/glsx/smart/modules/model/request/SmartUserDeviceQueryReq.java
src/main/java/cn/com/glsx/smart/modules/model/request/SmartUserDeviceSaveReq.java
src/main/java/cn/com/glsx/smart/modules/model/response/SmartUserDeviceResp.java
src/main/java/cn/com/glsx/smart/modules/service/SmartProductService.java
src/main/java/cn/com/glsx/smart/modules/service/SmartProductTypeService.java
src/main/java/cn/com/glsx/smart/modules/service/SmartUserDeviceService.java
src/main/java/cn/com/glsx/smart/modules/service/impl/SmartProductServiceImpl.java
src/main/java/cn/com/glsx/smart/modules/service/impl/SmartProductTypeServiceImpl.java
src/main/java/cn/com/glsx/smart/modules/service/impl/SmartUserDeviceServiceImpl.java
src/main/java/cn/com/glsx/smart/modules/controller/ProductController.java
View file @
6e967f5
...
...
@@ -7,7 +7,6 @@ import cn.com.glsx.smart.modules.model.ValidateGroups;
import
cn.com.glsx.smart.modules.model.request.SmartProductQueryReq
;
import
cn.com.glsx.smart.modules.model.request.SmartProductSaveReq
;
import
cn.com.glsx.smart.modules.service.SmartProductService
;
import
cn.hutool.core.bean.BeanUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.github.pagehelper.PageInfo
;
...
...
@@ -45,8 +44,7 @@ public class ProductController {
@GetMapping
(
"/getPageList"
)
public
R
getPageList
(
SmartProductQueryReq
req
)
{
log
.
info
(
"$$$$ /product/getPageList param: {}"
,
JSON
.
toJSONString
(
req
));
SmartProduct
product
=
BeanUtil
.
toBean
(
req
,
SmartProduct
.
class
);
PageInfo
<
SmartProduct
>
pageInfo
=
productService
.
getPageList
(
product
);
PageInfo
<
SmartProduct
>
pageInfo
=
productService
.
getPageList
(
req
);
return
R
.
ok
().
putPageData
(
pageInfo
);
}
...
...
@@ -59,8 +57,7 @@ public class ProductController {
@GetMapping
(
"/getList"
)
public
R
getList
(
SmartProductQueryReq
req
)
{
log
.
info
(
"$$$$ /product/getList param: {}"
,
JSON
.
toJSONString
(
req
));
SmartProduct
product
=
BeanUtil
.
toBean
(
req
,
SmartProduct
.
class
);
List
<
SmartProduct
>
productList
=
productService
.
getList
(
product
);
List
<
SmartProduct
>
productList
=
productService
.
getList
(
req
);
return
R
.
ok
().
data
(
productList
);
}
...
...
@@ -96,8 +93,8 @@ public class ProductController {
* @return 结果
*/
@GetMapping
(
"/getProductAndCategory"
)
public
R
getProduct
AndCategory
()
{
log
.
info
(
"$$$$ /product/getProduct
AndCategory
..."
);
public
R
getProduct
Tree
()
{
log
.
info
(
"$$$$ /product/getProduct
Tree
..."
);
JSONArray
productTree
=
productService
.
getProductTree
();
return
R
.
ok
().
data
(
productTree
);
}
...
...
@@ -111,9 +108,8 @@ public class ProductController {
@PostMapping
(
"/save"
)
public
R
save
(
@RequestBody
@Validated
(
ValidateGroups
.
Insert
.
class
)
SmartProductSaveReq
req
)
{
log
.
info
(
"$$$$ /product/save param: {}"
,
JSON
.
toJSONString
(
req
));
SmartProduct
product
=
BeanUtil
.
toBean
(
req
,
SmartProduct
.
class
);
Boolean
success
=
productService
.
save
(
product
);
return
R
.
ok
().
data
(
success
);
int
rows
=
productService
.
save
(
req
);
return
R
.
ok
().
data
(
rows
>
0
);
}
/**
...
...
@@ -150,7 +146,7 @@ public class ProductController {
@PostMapping
(
"/putOnOff"
)
public
R
putOnOff
(
@RequestParam
Long
id
)
{
log
.
info
(
"$$$$ /product/putOnOff param: {}"
,
id
);
Boolean
succes
s
=
productService
.
putOnOff
(
id
);
return
R
.
ok
().
data
(
success
);
int
row
s
=
productService
.
putOnOff
(
id
);
return
R
.
ok
().
data
(
rows
>
0
);
}
}
src/main/java/cn/com/glsx/smart/modules/controller/ProductTypeController.java
View file @
6e967f5
...
...
@@ -6,7 +6,6 @@ import cn.com.glsx.smart.modules.model.ValidateGroups;
import
cn.com.glsx.smart.modules.model.request.SmartProductTypeQueryReq
;
import
cn.com.glsx.smart.modules.model.request.SmartProductTypeSaveReq
;
import
cn.com.glsx.smart.modules.service.SmartProductTypeService
;
import
cn.hutool.core.bean.BeanUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.github.pagehelper.PageInfo
;
import
com.glsx.plat.core.web.R
;
...
...
@@ -43,8 +42,7 @@ public class ProductTypeController {
@GetMapping
(
"/getPageList"
)
public
R
getPageList
(
SmartProductTypeQueryReq
req
)
{
log
.
info
(
"$$$$ /productType/getPageList param: {}"
,
JSON
.
toJSONString
(
req
));
SmartProductType
productType
=
BeanUtil
.
toBean
(
req
,
SmartProductType
.
class
);
PageInfo
<
SmartProductType
>
pageInfo
=
productTypeService
.
getPageList
(
productType
);
PageInfo
<
SmartProductType
>
pageInfo
=
productTypeService
.
getPageList
(
req
);
return
R
.
ok
().
putPageData
(
pageInfo
);
}
...
...
@@ -57,8 +55,7 @@ public class ProductTypeController {
@GetMapping
(
"/getList"
)
public
R
getList
(
SmartProductTypeQueryReq
req
)
{
log
.
info
(
"$$$$ /productType/getList param: {}"
,
JSON
.
toJSONString
(
req
));
SmartProductType
productType
=
BeanUtil
.
toBean
(
req
,
SmartProductType
.
class
);
List
<
SmartProductType
>
productTypeList
=
productTypeService
.
getList
(
productType
);
List
<
SmartProductType
>
productTypeList
=
productTypeService
.
getList
(
req
);
return
R
.
ok
().
data
(
productTypeList
);
}
...
...
@@ -83,9 +80,8 @@ public class ProductTypeController {
@PostMapping
(
"/save"
)
public
R
save
(
@RequestBody
@Validated
(
ValidateGroups
.
Insert
.
class
)
SmartProductTypeSaveReq
req
)
{
log
.
info
(
"$$$$ /productType/save param: {}"
,
JSON
.
toJSONString
(
req
));
SmartProductType
productType
=
BeanUtil
.
toBean
(
req
,
SmartProductType
.
class
);
Boolean
success
=
productTypeService
.
save
(
productType
);
return
R
.
ok
().
data
(
success
);
int
rows
=
productTypeService
.
save
(
req
);
return
R
.
ok
().
data
(
rows
>
0
);
}
/**
...
...
src/main/java/cn/com/glsx/smart/modules/controller/RemoteProductController.java
View file @
6e967f5
package
cn
.
com
.
glsx
.
smart
.
modules
.
controller
;
import
java.util.ArrayList
;
import
java.util.List
;
import
cn.com.glsx.smart.modules.entity.SmartUserDevice
;
import
cn.com.glsx.smart.modules.entity.SmartUserRelation
;
import
cn.com.glsx.smart.modules.model.request.SmartUserDeviceQueryReq
;
import
cn.com.glsx.smart.modules.model.response.RemoteDeviceResp
;
import
cn.com.glsx.smart.modules.service.SmartProductTypeService
;
import
cn.com.glsx.smart.modules.service.SmartUserDeviceService
;
...
...
@@ -17,10 +20,12 @@ import lombok.extern.slf4j.Slf4j;
import
org.apache.commons.collections.CollectionUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* 远程产品服务controller
...
...
@@ -95,10 +100,10 @@ public class RemoteProductController {
*/
private
List
<
RemoteDeviceResp
>
getRemoteDeviceV2
(
Long
userId
,
Byte
status
)
{
List
<
RemoteDeviceResp
>
deviceRespList
=
new
ArrayList
<>();
SmartUserDevice
record
=
new
SmartUserDevice
();
re
cord
.
setUserId
(
userId
);
re
cord
.
setType
((
byte
)
1
);
List
<
SmartUserDevice
>
list
=
userDeviceService
.
getList
(
re
cord
);
SmartUserDevice
QueryReq
req
=
new
SmartUserDeviceQueryReq
();
re
q
.
setUserId
(
userId
);
re
q
.
setType
((
byte
)
1
);
List
<
SmartUserDevice
>
list
=
userDeviceService
.
getList
(
re
q
);
if
(
CollectionUtils
.
isEmpty
(
list
)){
return
deviceRespList
;
}
...
...
src/main/java/cn/com/glsx/smart/modules/controller/UserDeviceController.java
View file @
6e967f5
package
cn
.
com
.
glsx
.
smart
.
modules
.
controller
;
import
java.util.List
;
import
cn.com.glsx.smart.common.exception.ChejiaBusinessException
;
import
cn.com.glsx.smart.common.exception.ResultEnum
;
import
cn.com.glsx.smart.modules.entity.SmartUserDevice
;
import
cn.com.glsx.smart.modules.model.ValidateGroups
;
import
cn.com.glsx.smart.modules.model.request.SmartUserDeviceDeleteReq
;
import
cn.com.glsx.smart.modules.model.request.SmartUserDeviceQueryReq
;
import
cn.com.glsx.smart.modules.model.request.SmartUserDeviceSaveReq
;
import
cn.com.glsx.smart.modules.service.SmartUserDeviceService
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
...
...
@@ -10,9 +15,13 @@ import com.glsx.plat.common.utils.StringUtils;
import
com.glsx.plat.core.web.R
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* <p>Description: 用户设备业务
...
...
@@ -35,7 +44,7 @@ public class UserDeviceController {
* @return 结果
*/
@GetMapping
(
"/getList"
)
public
R
getList
(
SmartUserDevice
req
)
{
public
R
getList
(
SmartUserDevice
QueryReq
req
)
{
log
.
info
(
"$$$$ /userDevice/getList param: {}"
,
JSON
.
toJSONString
(
req
));
if
(
req
.
getUserId
()
==
null
)
{
throw
ChejiaBusinessException
.
create
(
ResultEnum
.
PARAM_EMPTY
,
"userId"
);
...
...
@@ -51,7 +60,7 @@ public class UserDeviceController {
* @return 结果
*/
@GetMapping
(
"/getByDeviceId"
)
public
R
getByDeviceId
(
SmartUserDevice
req
)
{
public
R
getByDeviceId
(
SmartUserDevice
QueryReq
req
)
{
log
.
info
(
"$$$$ /userDevice/getByDeviceId param: {}"
,
JSON
.
toJSONString
(
req
));
if
(
StringUtils
.
isBlank
(
req
.
getDeviceId
()))
{
throw
ChejiaBusinessException
.
create
(
ResultEnum
.
PARAM_EMPTY
,
"deviceId"
);
...
...
@@ -67,11 +76,12 @@ public class UserDeviceController {
* @return 结果
*/
@PostMapping
(
"/save"
)
public
R
save
(
@RequestBody
SmartUserDevice
req
)
{
public
R
save
(
@RequestBody
@Validated
(
ValidateGroups
.
Insert
.
class
)
SmartUserDeviceSaveReq
req
)
{
log
.
info
(
"$$$$ /userDevice/save param: {}"
,
JSON
.
toJSONString
(
req
));
if
(
StringUtils
.
isBlank
(
req
.
getDeviceId
())
||
req
.
getChannel
()
==
null
)
{
throw
ChejiaBusinessException
.
create
(
ResultEnum
.
PARAM_EMPTY
,
"deviceId, channel"
);
}
//
if (StringUtils.isBlank(req.getDeviceId()) || req.getChannel() == null) {
//
throw ChejiaBusinessException.create(ResultEnum.PARAM_EMPTY, "deviceId, channel");
//
}
int
rows
=
userDeviceService
.
save
(
req
);
return
R
.
ok
().
data
(
rows
>
0
);
}
...
...
@@ -83,11 +93,12 @@ public class UserDeviceController {
* @return 结果
*/
@PostMapping
(
"/deleteDevice"
)
public
R
deleteDevice
(
@RequestBody
SmartUserDevice
req
)
{
public
R
deleteDevice
(
@RequestBody
@Validated
(
ValidateGroups
.
Delete
.
class
)
SmartUserDeviceDeleteReq
req
)
{
log
.
info
(
"$$$$ /userDevice/deleteDevice param: {}"
,
JSON
.
toJSONString
(
req
));
if
(
StringUtils
.
isBlank
(
req
.
getDeviceId
())
||
req
.
getChannel
()
==
null
)
{
throw
ChejiaBusinessException
.
create
(
ResultEnum
.
PARAM_EMPTY
,
"deviceId, channel"
);
}
//
if (StringUtils.isBlank(req.getDeviceId()) || req.getChannel() == null) {
//
throw ChejiaBusinessException.create(ResultEnum.PARAM_EMPTY, "deviceId, channel");
//
}
int
rows
=
userDeviceService
.
deleteDevice
(
req
);
return
R
.
ok
().
data
(
rows
>
0
);
}
...
...
src/main/java/cn/com/glsx/smart/modules/mapper/SmartUserDeviceMapper.java
View file @
6e967f5
package
cn
.
com
.
glsx
.
smart
.
modules
.
mapper
;
import
java.util.List
;
import
cn.com.glsx.smart.modules.entity.SmartUserDevice
;
import
org.apache.ibatis.annotations.Mapper
;
import
java.util.List
;
/**
* <p>Description:
* <p>Project: chejia-smart
...
...
@@ -16,11 +15,11 @@ import java.util.List;
@Mapper
public
interface
SmartUserDeviceMapper
extends
tk
.
mybatis
.
mapper
.
common
.
Mapper
<
SmartUserDevice
>
{
List
<
SmartUserDevice
>
getList
(
SmartUserDevice
req
);
List
<
SmartUserDevice
>
getList
(
SmartUserDevice
userDevice
);
SmartUserDevice
getByDeviceId
(
SmartUserDevice
req
);
SmartUserDevice
getByDeviceId
(
SmartUserDevice
userDevice
);
int
deleteDevice
(
SmartUserDevice
req
);
int
deleteDevice
(
SmartUserDevice
userDevice
);
List
<
SmartUserDevice
>
findByParentId
(
String
infrared_id
);
}
src/main/java/cn/com/glsx/smart/modules/model/request/SmartUserDeviceDeleteReq.java
0 → 100644
View file @
6e967f5
package
cn
.
com
.
glsx
.
smart
.
modules
.
model
.
request
;
import
javax.validation.constraints.NotBlank
;
import
javax.validation.constraints.NotNull
;
import
java.util.Date
;
import
cn.com.glsx.smart.modules.model.ValidateGroups
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
lombok.Data
;
/**
* 车家智能用户设备表
*/
@Data
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
SmartUserDeviceDeleteReq
{
/**
* 第三方平台用户 ID
*/
private
String
uid
;
/**
* 产品图标
*/
private
String
icon
;
/**
* 标识ID
*/
private
Long
id
;
/**
* 用户ID 关联smart_user_relation中id
*/
private
Long
userId
;
/**
* 设备id(或者网关设备)
*/
@NotBlank
(
message
=
"deviceId不能为空"
,
groups
=
ValidateGroups
.
Delete
.
class
)
private
String
deviceId
;
/**
* 设备名称
*/
private
String
deviceName
;
/**
* 类型:1实体设备 2虚拟红外设备
*/
private
Byte
type
;
/**
* 第三方平台标识 1涂鸦 2绿米
*/
@NotNull
(
message
=
"channel不能为空"
,
groups
=
ValidateGroups
.
Delete
.
class
)
private
Byte
channel
;
/**
* 父设备id
*/
private
String
parentId
;
/**
* 接入平台产品id
*/
private
String
platformProductId
;
/**
* 创建时间
*/
private
Date
createTime
;
/**
* 更新时间
*/
private
Date
updateTime
;
private
String
typeId
;
}
src/main/java/cn/com/glsx/smart/modules/model/request/SmartUserDeviceQueryReq.java
0 → 100644
View file @
6e967f5
package
cn
.
com
.
glsx
.
smart
.
modules
.
model
.
request
;
import
java.io.Serializable
;
import
java.util.Date
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
lombok.Data
;
/**
* 车家智能用户设备表
*/
@Data
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
SmartUserDeviceQueryReq
implements
Serializable
{
/**
* 第三方平台用户 ID
*/
private
String
uid
;
/**
* 产品图标
*/
private
String
icon
;
/**
* 标识ID
*/
private
Long
id
;
/**
* 用户ID 关联smart_user_relation中id
*/
private
Long
userId
;
/**
* 设备id(或者网关设备)
*/
private
String
deviceId
;
/**
* 设备名称
*/
private
String
deviceName
;
/**
* 类型:1实体设备 2虚拟红外设备
*/
private
Byte
type
;
/**
* 第三方平台标识 1涂鸦 2绿米
*/
private
Byte
channel
;
/**
* 父设备id
*/
private
String
parentId
;
/**
* 接入平台产品id
*/
private
String
platformProductId
;
/**
* 创建时间
*/
private
Date
createTime
;
/**
* 更新时间
*/
private
Date
updateTime
;
private
String
typeId
;
}
src/main/java/cn/com/glsx/smart/modules/model/request/SmartUserDeviceSaveReq.java
0 → 100644
View file @
6e967f5
package
cn
.
com
.
glsx
.
smart
.
modules
.
model
.
request
;
import
javax.validation.constraints.NotBlank
;
import
javax.validation.constraints.NotNull
;
import
java.util.Date
;
import
cn.com.glsx.smart.modules.model.ValidateGroups
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
lombok.Data
;
/**
* 车家智能用户设备表
*/
@Data
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
SmartUserDeviceSaveReq
{
/**
* 第三方平台用户 ID
*/
private
String
uid
;
/**
* 产品图标
*/
private
String
icon
;
/**
* 标识ID
*/
private
Long
id
;
/**
* 用户ID 关联smart_user_relation中id
*/
private
Long
userId
;
/**
* 设备id(或者网关设备)
*/
@NotBlank
(
message
=
"deviceId不能为空"
,
groups
=
ValidateGroups
.
Insert
.
class
)
private
String
deviceId
;
/**
* 设备名称
*/
private
String
deviceName
;
/**
* 类型:1实体设备 2虚拟红外设备
*/
private
Byte
type
;
/**
* 第三方平台标识 1涂鸦 2绿米
*/
@NotNull
(
message
=
"channel不能为空"
,
groups
=
ValidateGroups
.
Insert
.
class
)
private
Byte
channel
;
/**
* 父设备id
*/
private
String
parentId
;
/**
* 接入平台产品id
*/
private
String
platformProductId
;
/**
* 创建时间
*/
private
Date
createTime
;
/**
* 更新时间
*/
private
Date
updateTime
;
private
String
typeId
;
}
src/main/java/cn/com/glsx/smart/modules/model/response/SmartUserDeviceResp.java
0 → 100644
View file @
6e967f5
package
cn
.
com
.
glsx
.
smart
.
modules
.
model
.
response
;
import
java.util.Date
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
lombok.Data
;
/**
* 车家智能用户设备表
*/
@Data
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
SmartUserDeviceResp
{
/**
* 第三方平台用户 ID
*/
private
String
uid
;
/**
* 产品图标
*/
private
String
icon
;
/**
* 标识ID
*/
private
Long
id
;
/**
* 用户ID 关联smart_user_relation中id
*/
private
Long
userId
;
/**
* 设备id(或者网关设备)
*/
private
String
deviceId
;
/**
* 设备名称
*/
private
String
deviceName
;
/**
* 类型:1实体设备 2虚拟红外设备
*/
private
Byte
type
;
/**
* 第三方平台标识 1涂鸦 2绿米
*/
private
Byte
channel
;
/**
* 父设备id
*/
private
String
parentId
;
/**
* 接入平台产品id
*/
private
String
platformProductId
;
/**
* 创建时间
*/
private
Date
createTime
;
/**
* 更新时间
*/
private
Date
updateTime
;
private
String
typeId
;
}
src/main/java/cn/com/glsx/smart/modules/service/SmartProductService.java
View file @
6e967f5
package
cn
.
com
.
glsx
.
smart
.
modules
.
service
;
import
java.util.List
;
import
cn.com.glsx.smart.modules.entity.SmartDeviceOrder
;
import
cn.com.glsx.smart.modules.entity.SmartProduct
;
import
cn.com.glsx.smart.modules.model.request.SmartProductQueryReq
;
import
cn.com.glsx.smart.modules.model.request.SmartProductSaveReq
;
import
com.alibaba.fastjson.JSONArray
;
import
com.github.pagehelper.PageInfo
;
import
java.util.List
;
/**
* <p>Description:
* <p>Project: chejia-smart
...
...
@@ -16,25 +17,21 @@ import java.util.List;
*/
public
interface
SmartProductService
{
PageInfo
<
SmartProduct
>
getPageList
(
SmartProduct
product
);
PageInfo
<
SmartProduct
>
getPageList
(
SmartProduct
QueryReq
req
);
List
<
SmartProduct
>
getList
(
SmartProduct
product
);
List
<
SmartProduct
>
getByPlatProductIdList
(
List
<
String
>
list
);
List
<
SmartProduct
>
getList
(
SmartProductQueryReq
req
);
List
<
SmartProduct
>
getListByCondition
(
SmartProduct
product
);
SmartProduct
getById
(
Long
id
);
JSONArray
getProductAndCategory
();
JSONArray
getProductTree
();
Boolean
save
(
SmartProduct
product
);
int
save
(
SmartProductSaveReq
req
);
List
<
SmartDeviceOrder
>
getCommandSetById
(
Long
id
);
List
<
String
>
getSupportedCommands
(
String
platformProductId
);
Boolean
putOnOff
(
Long
id
);
int
putOnOff
(
Long
id
);
}
src/main/java/cn/com/glsx/smart/modules/service/SmartProductTypeService.java
View file @
6e967f5
package
cn
.
com
.
glsx
.
smart
.
modules
.
service
;
import
java.util.List
;
import
cn.com.glsx.smart.modules.entity.SmartProductType
;
import
cn.com.glsx.smart.modules.entity.SmartUserDevice
;
import
cn.com.glsx.smart.modules.model.request.SmartProductTypeQueryReq
;
import
cn.com.glsx.smart.modules.model.request.SmartProductTypeSaveReq
;
import
cn.com.glsx.smart.modules.model.response.RemoteDeviceResp
;
import
com.alibaba.fastjson.JSONArray
;
import
com.github.pagehelper.PageInfo
;
import
java.util.List
;
/**
* <p>Description:
* <p>Project: chejia-smart
...
...
@@ -17,15 +18,13 @@ import java.util.List;
*/
public
interface
SmartProductTypeService
{
PageInfo
<
SmartProductType
>
getPageList
(
SmartProductType
productType
);
List
<
SmartProductType
>
getList
(
SmartProductType
productType
);
PageInfo
<
SmartProductType
>
getPageList
(
SmartProductTypeQueryReq
req
);
List
<
SmartProductType
>
get
ByIdList
(
List
<
Long
>
list
);
List
<
SmartProductType
>
get
List
(
SmartProductTypeQueryReq
req
);
SmartProductType
getById
(
Long
id
);
Boolean
save
(
SmartProductType
productType
);
int
save
(
SmartProductTypeSaveReq
req
);
List
<
SmartProductType
>
getListAndContent
(
List
<
Long
>
list
);
...
...
src/main/java/cn/com/glsx/smart/modules/service/SmartUserDeviceService.java
View file @
6e967f5
package
cn
.
com
.
glsx
.
smart
.
modules
.
service
;
import
java.util.List
;
import
cn.com.glsx.smart.modules.entity.SmartUserDevice
;
import
cn.com.glsx.smart.modules.model.request.SmartUserDeviceDeleteReq
;
import
cn.com.glsx.smart.modules.model.request.SmartUserDeviceQueryReq
;
import
cn.com.glsx.smart.modules.model.request.SmartUserDeviceSaveReq
;
import
com.alibaba.fastjson.JSONObject
;
import
java.util.List
;
/**
* <p>Description:
* <p>Project: chejia-smart
...
...
@@ -14,13 +16,13 @@ import java.util.List;
*/
public
interface
SmartUserDeviceService
{
List
<
SmartUserDevice
>
getList
(
SmartUserDevice
req
);
List
<
SmartUserDevice
>
getList
(
SmartUserDevice
QueryReq
req
);
SmartUserDevice
getByDeviceId
(
SmartUserDevice
req
);
SmartUserDevice
getByDeviceId
(
SmartUserDevice
QueryReq
req
);
int
save
(
SmartUserDevice
req
);
int
save
(
SmartUserDevice
SaveReq
req
);
int
deleteDevice
(
SmartUserDevice
req
);
int
deleteDevice
(
SmartUserDevice
DeleteReq
req
);
String
getUserBindKey
(
String
token
);
...
...
src/main/java/cn/com/glsx/smart/modules/service/impl/SmartProductServiceImpl.java
View file @
6e967f5
package
cn
.
com
.
glsx
.
smart
.
modules
.
service
.
impl
;
import
javax.annotation.Resource
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
cn.com.glsx.smart.common.constant.Constants
;
import
cn.com.glsx.smart.common.enums.DeviceChannelEnum
;
import
cn.com.glsx.smart.common.exception.ChejiaBusinessException
;
...
...
@@ -10,8 +14,11 @@ import cn.com.glsx.smart.modules.entity.SmartSysCode;
import
cn.com.glsx.smart.modules.mapper.SmartDeviceOrderMapper
;
import
cn.com.glsx.smart.modules.mapper.SmartProductMapper
;
import
cn.com.glsx.smart.modules.mapper.SmartSysCodeMapper
;
import
cn.com.glsx.smart.modules.model.request.SmartProductQueryReq
;
import
cn.com.glsx.smart.modules.model.request.SmartProductSaveReq
;
import
cn.com.glsx.smart.modules.service.BaseService
;
import
cn.com.glsx.smart.modules.service.SmartProductService
;
import
cn.hutool.core.bean.BeanUtil
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.github.pagehelper.PageInfo
;
...
...
@@ -21,12 +28,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
* <p>Description: 产品列表业务
* <p>Project: chejia-smart
...
...
@@ -49,13 +50,13 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
/**
* 获取产品列表。
*
* @param
product
请求体
* @param
req
请求体
* @return 结果
*/
@Override
public
PageInfo
<
SmartProduct
>
getPageList
(
SmartProduct
product
)
{
super
.
startPagination
(
product
);
return
PageInfo
.
of
(
this
.
getList
(
product
));
public
PageInfo
<
SmartProduct
>
getPageList
(
SmartProduct
QueryReq
req
)
{
super
.
startPagination
(
req
);
return
PageInfo
.
of
(
this
.
getList
(
req
));
}
@Override
...
...
@@ -64,16 +65,12 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
}
@Override
public
List
<
SmartProduct
>
getList
(
SmartProduct
product
)
{
public
List
<
SmartProduct
>
getList
(
SmartProductQueryReq
req
)
{
SmartProduct
product
=
BeanUtil
.
toBean
(
req
,
SmartProduct
.
class
);
List
<
SmartProduct
>
productList
=
productMapper
.
getList
(
product
);
return
productList
;
}
@Override
public
List
<
SmartProduct
>
getByPlatProductIdList
(
List
<
String
>
list
)
{
return
productMapper
.
getByPlatProductIdList
(
list
);
}
/**
* 根据 id 查询产品详情。
*
...
...
@@ -95,62 +92,6 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
* @return 结果
*/
@Override
public
JSONArray
getProductAndCategory
()
{
SmartSysCode
example
=
new
SmartSysCode
();
example
.
setDictType
(
"smart_device"
);
List
<
SmartSysCode
>
categoryList
=
sysCodeMapper
.
getList
(
example
);
List
<
SmartProduct
>
allProductList
=
productMapper
.
getAllProductList
();
JSONArray
resultList
=
new
JSONArray
();
if
(
CollectionUtils
.
isNotEmpty
(
categoryList
))
{
// 筛选一级分类
List
<
SmartSysCode
>
firstCategoryList
=
categoryList
.
stream
()
.
filter
(
index
->
index
.
getLevel
()
==
0
).
collect
(
Collectors
.
toList
());
// 筛选二级分类
List
<
SmartSysCode
>
secondCategoryList
=
categoryList
.
stream
()
.
filter
(
index
->
index
.
getLevel
()
==
1
).
collect
(
Collectors
.
toList
());
// 一级分类数据
firstCategoryList
.
forEach
(
firstCategory
->
{
JSONObject
firstObj
=
new
JSONObject
();
firstObj
.
put
(
"title"
,
firstCategory
.
getDictValue
());
List
<
JSONObject
>
firstItemList
=
new
ArrayList
<>();
// 获取此分类下的子分类
List
<
SmartSysCode
>
subCategoryList
=
secondCategoryList
.
stream
()
.
filter
(
inx
->
inx
.
getParentKey
().
equals
(
firstCategory
.
getDictKey
()))
.
collect
(
Collectors
.
toList
());
// 子分类数据
subCategoryList
.
forEach
(
subCategory
->
{
JSONObject
subObj
=
new
JSONObject
();
subObj
.
put
(
"title"
,
subCategory
.
getDictValue
());
// 获取此分类下的产品
List
<
SmartProduct
>
productList
=
allProductList
.
stream
()
.
filter
(
pro
->
pro
.
getCategoryKey
().
equals
(
subCategory
.
getDictKey
()))
.
collect
(
Collectors
.
toList
());
// 映射产品信息
List
<
JSONObject
>
productInfoList
=
productList
.
stream
()
.
map
(
product
->
{
JSONObject
productObj
=
new
JSONObject
();
productObj
.
put
(
"name"
,
product
.
getProductName
());
productObj
.
put
(
"iconUrl"
,
product
.
getIconUrl
());
productObj
.
put
(
"typeId"
,
product
.
getTypeId
());
productObj
.
put
(
"shopProductId"
,
product
.
getShopProductId
());
return
productObj
;
}).
collect
(
Collectors
.
toList
());
subObj
.
put
(
"list"
,
productInfoList
);
firstItemList
.
add
(
subObj
);
});
firstObj
.
put
(
"list"
,
firstItemList
);
resultList
.
add
(
firstObj
);
});
}
return
resultList
;
}
/**
* <p>获取树状的产品数据。
*
* @return 结果
*/
@Override
public
JSONArray
getProductTree
()
{
SmartSysCode
example
=
new
SmartSysCode
();
example
.
setDictType
(
"smart_device"
);
...
...
@@ -163,17 +104,17 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
/**
* 保存产品。无则插入,有则更新。
*
* @param
product
产品
* @param
req
产品
* @return 是否成功
*/
@Override
@Transactional
public
Boolean
save
(
SmartProduct
product
)
{
boolean
succes
s
;
public
int
save
(
SmartProductSaveReq
req
)
{
int
row
s
;
Date
now
=
new
Date
();
SmartProduct
product
=
BeanUtil
.
toBean
(
req
,
SmartProduct
.
class
);
product
.
setUpdateTime
(
now
);
product
.
setUpdateBy
(
0L
);
if
(
product
.
getId
()
==
null
)
{
int
nameCount
=
productMapper
.
countByProductName
(
product
.
getProductName
());
if
(
nameCount
>
0
)
{
...
...
@@ -181,17 +122,17 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
}
product
.
setCreateTime
(
now
);
product
.
setCreateBy
(
0L
);
success
=
productMapper
.
insertSelective
(
product
)
>
0
;
rows
=
productMapper
.
insertSelective
(
product
)
;
}
else
{
SmartProduct
record
=
productMapper
.
selectByPrimaryKey
(
product
.
getId
());
if
(
record
!=
null
)
{
success
=
productMapper
.
updateByPrimaryKeySelective
(
product
)
>
0
;
rows
=
productMapper
.
updateByPrimaryKeySelective
(
product
)
;
}
else
{
throw
ChejiaBusinessException
.
create
(
ResultEnum
.
PRODUCT_NOT_FOUND
);
}
}
return
succes
s
;
return
row
s
;
}
/**
...
...
@@ -220,15 +161,15 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
*/
@Override
@Transactional
public
Boolean
putOnOff
(
Long
id
)
{
boolean
succes
s
;
public
int
putOnOff
(
Long
id
)
{
int
row
s
;
SmartProduct
product
=
productMapper
.
selectByPrimaryKey
(
id
);
if
(
product
==
null
)
{
throw
ChejiaBusinessException
.
create
(
ResultEnum
.
PRODUCT_NOT_FOUND
);
}
product
.
setStatus
((
byte
)
(
product
.
getStatus
()
^
0b00000001
));
success
=
productMapper
.
updateByPrimaryKeySelective
(
product
)
>
0
;
return
succes
s
;
rows
=
productMapper
.
updateByPrimaryKeySelective
(
product
)
;
return
row
s
;
}
/**
...
...
src/main/java/cn/com/glsx/smart/modules/service/impl/SmartProductTypeServiceImpl.java
View file @
6e967f5
package
cn
.
com
.
glsx
.
smart
.
modules
.
service
.
impl
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.Comparator
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
import
cn.com.glsx.smart.common.constant.Constants
;
import
cn.com.glsx.smart.common.exception.ChejiaBusinessException
;
import
cn.com.glsx.smart.common.exception.ResultEnum
;
...
...
@@ -9,9 +17,12 @@ import cn.com.glsx.smart.modules.entity.SmartUserDevice;
import
cn.com.glsx.smart.modules.mapper.SmartProductMapper
;
import
cn.com.glsx.smart.modules.mapper.SmartProductTypeMapper
;
import
cn.com.glsx.smart.modules.mapper.SmartUserDeviceMapper
;
import
cn.com.glsx.smart.modules.model.request.SmartProductTypeQueryReq
;
import
cn.com.glsx.smart.modules.model.request.SmartProductTypeSaveReq
;
import
cn.com.glsx.smart.modules.model.response.RemoteDeviceResp
;
import
cn.com.glsx.smart.modules.service.BaseService
;
import
cn.com.glsx.smart.modules.service.SmartProductTypeService
;
import
cn.hutool.core.bean.BeanUtil
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.github.pagehelper.PageInfo
;
...
...
@@ -21,10 +32,6 @@ import org.springframework.beans.factory.annotation.Value;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.annotation.Resource
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
* <p>Description: 产品类型业务
* <p>Project: chejia-smart
...
...
@@ -51,31 +58,27 @@ public class SmartProductTypeServiceImpl extends BaseService implements SmartPro
/**
* 分页获取产品类型列表。
*
* @param
productType
请求
* @param
req
请求
* @return 结果
*/
@Override
public
PageInfo
<
SmartProductType
>
getPageList
(
SmartProductType
productType
)
{
super
.
startPagination
(
productType
);
return
PageInfo
.
of
(
this
.
getList
(
productType
));
public
PageInfo
<
SmartProductType
>
getPageList
(
SmartProductType
QueryReq
req
)
{
super
.
startPagination
(
req
);
return
PageInfo
.
of
(
this
.
getList
(
req
));
}
/**
* 获取产品类型列表,不分页。
*
* @param
productType
请求
* @param
req
请求
* @return 结果
*/
@Override
public
List
<
SmartProductType
>
getList
(
SmartProductType
productType
)
{
public
List
<
SmartProductType
>
getList
(
SmartProductTypeQueryReq
req
)
{
SmartProductType
productType
=
BeanUtil
.
toBean
(
req
,
SmartProductType
.
class
);
return
productTypeMapper
.
getList
(
productType
);
}
@Override
public
List
<
SmartProductType
>
getByIdList
(
List
<
Long
>
list
)
{
return
productTypeMapper
.
getByIdList
(
list
);
}
/**
* 根据 id 获取产品类型。
*
...
...
@@ -94,17 +97,17 @@ public class SmartProductTypeServiceImpl extends BaseService implements SmartPro
/**
* 保存产品类型。
*
* @param
productType
产品类型
* @param
req
产品类型
* @return 是否成功
*/
@Override
@Transactional
public
Boolean
save
(
SmartProductType
productType
)
{
boolean
succes
s
;
public
int
save
(
SmartProductTypeSaveReq
req
)
{
int
row
s
;
Date
now
=
new
Date
();
SmartProductType
productType
=
BeanUtil
.
toBean
(
req
,
SmartProductType
.
class
);
productType
.
setUpdateTime
(
now
);
productType
.
setUpdateBy
(
0L
);
if
(
productType
.
getId
()
==
null
)
{
int
nameCount
=
productTypeMapper
.
countByProductTypeName
(
productType
.
getTypeName
());
if
(
nameCount
>
0
)
{
...
...
@@ -112,17 +115,17 @@ public class SmartProductTypeServiceImpl extends BaseService implements SmartPro
}
productType
.
setCreateTime
(
now
);
productType
.
setCreateBy
(
0L
);
success
=
productTypeMapper
.
insertSelective
(
productType
)
>
0
;
rows
=
productTypeMapper
.
insertSelective
(
productType
)
;
}
else
{
SmartProductType
record
=
productTypeMapper
.
selectByPrimaryKey
(
productType
.
getId
());
if
(
record
!=
null
)
{
success
=
productTypeMapper
.
updateByPrimaryKeySelective
(
productType
)
>
0
;
rows
=
productTypeMapper
.
updateByPrimaryKeySelective
(
productType
)
;
}
else
{
throw
ChejiaBusinessException
.
create
(
ResultEnum
.
PRODUCT_TYPE_NOT_FOUND
);
}
}
return
succes
s
;
return
row
s
;
}
@Override
...
...
src/main/java/cn/com/glsx/smart/modules/service/impl/SmartUserDeviceServiceImpl.java
View file @
6e967f5
package
cn
.
com
.
glsx
.
smart
.
modules
.
service
.
impl
;
import
javax.annotation.Resource
;
import
javax.transaction.Transactional
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
cn.com.glsx.smart.common.constant.Constants
;
import
cn.com.glsx.smart.common.exception.ChejiaBusinessException
;
import
cn.com.glsx.smart.common.exception.ResultEnum
;
...
...
@@ -11,8 +18,12 @@ import cn.com.glsx.smart.modules.mapper.SmartProductMapper;
import
cn.com.glsx.smart.modules.mapper.SmartUserChannelMapper
;
import
cn.com.glsx.smart.modules.mapper.SmartUserDeviceMapper
;
import
cn.com.glsx.smart.modules.mapper.SmartUserRelationMapper
;
import
cn.com.glsx.smart.modules.model.request.SmartUserDeviceDeleteReq
;
import
cn.com.glsx.smart.modules.model.request.SmartUserDeviceQueryReq
;
import
cn.com.glsx.smart.modules.model.request.SmartUserDeviceSaveReq
;
import
cn.com.glsx.smart.modules.service.BaseService
;
import
cn.com.glsx.smart.modules.service.SmartUserDeviceService
;
import
cn.hutool.core.bean.BeanUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.glsx.plat.common.utils.HttpUtils
;
...
...
@@ -22,14 +33,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
javax.transaction.Transactional
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* <p>Description: 用户设备业务
* <p>Project: chejia-smart
...
...
@@ -71,51 +74,54 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser
private
RedisService
redisService
;
@Override
public
List
<
SmartUserDevice
>
getList
(
SmartUserDevice
req
)
{
return
userDeviceMapper
.
getList
(
req
);
public
List
<
SmartUserDevice
>
getList
(
SmartUserDeviceQueryReq
req
)
{
SmartUserDevice
userDevice
=
BeanUtil
.
toBean
(
req
,
SmartUserDevice
.
class
);
return
userDeviceMapper
.
getList
(
userDevice
);
}
@Override
public
SmartUserDevice
getByDeviceId
(
SmartUserDevice
req
)
{
SmartUserDevice
userDevice
=
userDeviceMapper
.
getByDeviceId
(
req
);
if
(
userDevice
==
null
)
{
public
SmartUserDevice
getByDeviceId
(
SmartUserDeviceQueryReq
req
)
{
SmartUserDevice
userDevice
=
BeanUtil
.
toBean
(
req
,
SmartUserDevice
.
class
);
SmartUserDevice
savedUserDevice
=
userDeviceMapper
.
getByDeviceId
(
userDevice
);
if
(
savedUserDevice
==
null
)
{
throw
ChejiaBusinessException
.
create
(
ResultEnum
.
DEVICE_NOT_FOUND
);
}
return
u
serDevice
;
return
savedU
serDevice
;
}
@Override
@Transactional
public
int
save
(
SmartUserDevice
req
)
{
public
int
save
(
SmartUserDevice
SaveReq
req
)
{
int
rows
;
Date
now
=
new
Date
();
SmartUserDevice
record
=
new
SmartUserDevice
();
record
.
setDeviceId
(
req
.
getDeviceId
());
record
.
setChannel
(
req
.
getChannel
());
SmartUserDevice
savedUserDevice
=
userDeviceMapper
.
selectOne
(
record
);
SmartUserDevice
userDevice
=
BeanUtil
.
toBean
(
req
,
SmartUserDevice
.
class
);
SmartUserDevice
example
=
new
SmartUserDevice
();
example
.
setDeviceId
(
userDevice
.
getDeviceId
());
example
.
setChannel
(
userDevice
.
getChannel
());
SmartUserDevice
savedUserDevice
=
userDeviceMapper
.
selectOne
(
example
);
if
(
savedUserDevice
==
null
)
{
if
(
StringUtils
.
isBlank
(
req
.
getUid
()))
{
if
(
StringUtils
.
isBlank
(
userDevice
.
getUid
()))
{
throw
ChejiaBusinessException
.
create
(
ResultEnum
.
PARAM_EMPTY
,
"uid"
);
}
// 根据第三方用户 id 查询用户绑定信息
SmartUserChannel
uc
Record
=
new
SmartUserChannel
();
uc
Record
.
setThirdId
(
req
.
getUid
());
SmartUserChannel
savedUserChannel
=
userChannelMapper
.
selectOne
(
uc
Record
);
SmartUserChannel
uc
Example
=
new
SmartUserChannel
();
uc
Example
.
setThirdId
(
userDevice
.
getUid
());
SmartUserChannel
savedUserChannel
=
userChannelMapper
.
selectOne
(
uc
Example
);
if
(
savedUserChannel
==
null
)
{
throw
ChejiaBusinessException
.
create
(
ResultEnum
.
USER_NOT_FOUND
);
}
// 插入用户信息
req
.
setUserId
(
savedUserChannel
.
getUserId
());
req
.
setCreateTime
(
now
);
req
.
setUpdateTime
(
now
);
rows
=
userDeviceMapper
.
insertSelective
(
req
);
userDevice
.
setUserId
(
savedUserChannel
.
getUserId
());
userDevice
.
setCreateTime
(
now
);
userDevice
.
setUpdateTime
(
now
);
rows
=
userDeviceMapper
.
insertSelective
(
userDevice
);
// 订阅用户设备
this
.
subscribeDevice
(
req
);
this
.
subscribeDevice
(
userDevice
);
}
else
{
if
(
StringUtils
.
isBlank
(
req
.
getDeviceName
()))
{
if
(
StringUtils
.
isBlank
(
userDevice
.
getDeviceName
()))
{
throw
ChejiaBusinessException
.
create
(
ResultEnum
.
PARAM_EMPTY
,
"deviceName"
);
}
savedUserDevice
.
setDeviceName
(
req
.
getDeviceName
());
savedUserDevice
.
setDeviceName
(
userDevice
.
getDeviceName
());
savedUserDevice
.
setUpdateTime
(
now
);
rows
=
userDeviceMapper
.
updateByPrimaryKeySelective
(
savedUserDevice
);
}
...
...
@@ -123,9 +129,10 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser
}
@Override
public
int
deleteDevice
(
SmartUserDevice
req
)
{
public
int
deleteDevice
(
SmartUserDevice
DeleteReq
req
)
{
int
rows
;
rows
=
userDeviceMapper
.
deleteDevice
(
req
);
SmartUserDevice
userDevice
=
BeanUtil
.
toBean
(
req
,
SmartUserDevice
.
class
);
rows
=
userDeviceMapper
.
deleteDevice
(
userDevice
);
return
rows
;
}
...
...
@@ -170,19 +177,22 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser
/**
* 订阅用户设备
*
* @param
req
请求
* @param
userDevice
请求
*/
private
void
subscribeDevice
(
SmartUserDevice
req
)
{
if
(
Constants
.
USER_CHANNEL_AQARA
.
equals
(
req
.
getChannel
()))
{
private
void
subscribeDevice
(
SmartUserDevice
userDevice
)
{
if
(
Constants
.
USER_CHANNEL_AQARA
.
equals
(
userDevice
.
getChannel
()))
{
// 只有绿米的设备需要订阅
if
(
StringUtils
.
isBlank
(
req
.
getPlatformProductId
()))
{
throw
ChejiaBusinessException
.
create
(
ResultEnum
.
PARAM_EMPTY
,
"platformProductId"
);
if
(
StringUtils
.
isBlank
(
userDevice
.
getPlatformProductId
()))
{
throw
ChejiaBusinessException
.
create
(
ResultEnum
.
PARAM_EMPTY
,
"platformProductId"
);
}
// 通过用户手机号获取用户 token
SmartUserRelation
userRelation
=
userRelationMapper
.
selectByPrimaryKey
(
req
.
getUserId
());
SmartUserRelation
userRelation
=
userRelationMapper
.
selectByPrimaryKey
(
userDevice
.
getUserId
());
String
token
=
(
String
)
redisService
.
get
(
userRelation
.
getPhone
()
+
"_aqara"
);
// 查询支持的指令集
List
<
String
>
commands
=
productMapper
.
getSupportedCommands
(
req
.
getPlatformProductId
());
List
<
String
>
commands
=
productMapper
.
getSupportedCommands
(
userDevice
.
getPlatformProductId
());
log
.
info
(
"$$$$ subscribeDevice commands = {}"
,
JSON
.
toJSONString
(
commands
));
if
(!
commands
.
isEmpty
())
{
// 指令集不为空才订阅
...
...
@@ -191,7 +201,7 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser
reqParam
.
put
(
"token"
,
token
);
// 请求 body
JSONObject
reqData
=
new
JSONObject
();
reqData
.
put
(
"did"
,
req
.
getDeviceId
());
reqData
.
put
(
"did"
,
userDevice
.
getDeviceId
());
reqData
.
put
(
"attrs"
,
commands
);
JSONObject
reqObj
=
new
JSONObject
();
reqObj
.
put
(
"data"
,
reqData
);
...
...
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