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 30f5fd5e
authored
Apr 25, 2021
by
tyfanchz
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
接口修改
1 parent
1224e427
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
135 additions
and
51 deletions
src/main/java/com/glsx/smart/controller/UserDeviceController.java
src/main/java/com/glsx/smart/dao/entity/SmartUserDevice.java
src/main/java/com/glsx/smart/dao/mapper/SmartUserDeviceMapper.java
src/main/java/com/glsx/smart/exception/BusinessException.java
src/main/java/com/glsx/smart/exception/ResultEnum.java
src/main/java/com/glsx/smart/service/SmartUserDeviceService.java
src/main/java/com/glsx/smart/service/impl/SmartUserDeviceServiceImpl.java
src/main/resources/mapper/SmartUserDeviceMapper.xml
src/main/java/com/glsx/smart/controller/UserDeviceController.java
View file @
30f5fd5
...
@@ -2,6 +2,7 @@ package com.glsx.smart.controller;
...
@@ -2,6 +2,7 @@ package com.glsx.smart.controller;
import
java.util.List
;
import
java.util.List
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.glsx.plat.common.utils.StringUtils
;
import
com.glsx.plat.core.web.R
;
import
com.glsx.plat.core.web.R
;
import
com.glsx.smart.dao.entity.SmartUserDevice
;
import
com.glsx.smart.dao.entity.SmartUserDevice
;
import
com.glsx.smart.exception.BusinessException
;
import
com.glsx.smart.exception.BusinessException
;
...
@@ -32,45 +33,64 @@ public class UserDeviceController {
...
@@ -32,45 +33,64 @@ public class UserDeviceController {
/**
/**
* 获取用户设备
* 获取用户设备
*
*
* @param
userDevice
请求
* @param
req
请求
* @return 结果
* @return 结果
*/
*/
@RequestMapping
(
value
=
"/getList"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
})
@RequestMapping
(
value
=
"/getList"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
})
public
R
getList
(
SmartUserDevice
userDevice
)
{
public
R
getList
(
SmartUserDevice
req
)
{
log
.
info
(
"$$$$ /userDevice/getList param: {}"
,
JSON
.
toJSONString
(
userDevice
));
log
.
info
(
"$$$$ /userDevice/getList param: {}"
,
JSON
.
toJSONString
(
req
));
if
(
userDevice
.
getUserId
()
==
null
)
{
if
(
req
.
getUserId
()
==
null
)
{
throw
BusinessException
.
create
(
ResultEnum
.
PARAM_ERROR
);
throw
BusinessException
.
create
(
ResultEnum
.
PARAM_ERROR
);
}
}
List
<
SmartUserDevice
>
userDeviceList
=
userDeviceService
.
getList
(
userDevice
);
List
<
SmartUserDevice
>
userDeviceList
=
userDeviceService
.
getList
(
req
);
return
R
.
ok
().
data
(
userDeviceList
);
return
R
.
ok
().
data
(
userDeviceList
);
}
}
/**
/**
* 根据 deviceId 查询设备详情
*
* @param req 请求
* @return 结果
*/
@RequestMapping
(
value
=
"/getByDeviceId"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
})
public
R
getByDeviceId
(
SmartUserDevice
req
)
{
log
.
info
(
"$$$$ /userDevice/getByDeviceId param: {}"
,
JSON
.
toJSONString
(
req
));
if
(
StringUtils
.
isBlank
(
req
.
getDeviceId
()))
{
throw
BusinessException
.
create
(
ResultEnum
.
PARAM_ERROR
);
}
SmartUserDevice
userDevice
=
userDeviceService
.
getByDeviceId
(
req
);
return
R
.
ok
().
data
(
userDevice
);
}
/**
* 保存用户设备
* 保存用户设备
*
*
* @param
userDevice
请求
* @param
req
请求
* @return 结果
* @return 结果
*/
*/
@RequestMapping
(
value
=
"/save"
,
method
=
{
RequestMethod
.
POST
})
@RequestMapping
(
value
=
"/save"
,
method
=
{
RequestMethod
.
POST
})
public
R
save
(
@RequestBody
SmartUserDevice
userDevice
)
{
public
R
save
(
@RequestBody
SmartUserDevice
req
)
{
log
.
info
(
"$$$$ /userDevice/save param: {}"
,
JSON
.
toJSONString
(
userDevice
));
log
.
info
(
"$$$$ /userDevice/save param: {}"
,
JSON
.
toJSONString
(
req
));
boolean
success
=
userDeviceService
.
save
(
userDevice
)
>
0
;
if
(
StringUtils
.
isBlank
(
req
.
getDeviceId
())
||
req
.
getChannel
()
==
null
)
{
throw
BusinessException
.
create
(
ResultEnum
.
PARAM_ERROR
);
}
boolean
success
=
userDeviceService
.
save
(
req
)
>
0
;
return
R
.
ok
().
data
(
success
);
return
R
.
ok
().
data
(
success
);
}
}
/**
/**
* 删除用户设备
* 删除用户设备
*
*
* @param
userDevice
请求
* @param
req
请求
* @return 结果
* @return 结果
*/
*/
@RequestMapping
(
value
=
"/deleteDevice"
,
method
=
{
RequestMethod
.
POST
})
@RequestMapping
(
value
=
"/deleteDevice"
,
method
=
{
RequestMethod
.
POST
})
public
R
deleteDevice
(
@RequestBody
SmartUserDevice
userDevice
)
{
public
R
deleteDevice
(
@RequestBody
SmartUserDevice
req
)
{
log
.
info
(
"$$$$ /userDevice/deleteDevice param: {}"
,
JSON
.
toJSONString
(
userDevice
));
log
.
info
(
"$$$$ /userDevice/deleteDevice param: {}"
,
JSON
.
toJSONString
(
req
));
if
(
userDevice
.
getId
()
==
null
&&
userDevice
.
getUserId
()
==
null
)
{
if
(
StringUtils
.
isBlank
(
req
.
getDeviceId
())
||
req
.
getChannel
()
==
null
)
{
throw
BusinessException
.
create
(
ResultEnum
.
PARAM_ERROR
);
throw
BusinessException
.
create
(
ResultEnum
.
PARAM_ERROR
);
}
}
boolean
success
=
userDeviceService
.
deleteDevice
(
userDevice
)
>
0
;
boolean
success
=
userDeviceService
.
deleteDevice
(
req
)
>
0
;
return
R
.
ok
().
data
(
success
);
return
R
.
ok
().
data
(
success
);
}
}
...
...
src/main/java/com/glsx/smart/dao/entity/SmartUserDevice.java
View file @
30f5fd5
...
@@ -4,25 +4,24 @@ import javax.persistence.Column;
...
@@ -4,25 +4,24 @@ import javax.persistence.Column;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
import
javax.persistence.Table
;
import
javax.persistence.Transient
;
import
java.util.Date
;
import
java.util.Date
;
import
lombok.Data
;
import
lombok.Data
;
/**
/**
* <p>Description:
* <p>Project: chejia-smart
*
* @author wbh
* @date 2021-04-23
*/
/**
* 车家智能用户设备表
* 车家智能用户设备表
*/
*/
@Data
@Data
@Table
(
name
=
"smart_user_device"
)
@Table
(
name
=
"smart_user_device"
)
public
class
SmartUserDevice
{
public
class
SmartUserDevice
{
/**
/**
* 第三方平台用户 ID
*/
@Transient
private
String
uid
;
/**
* 标识ID
* 标识ID
*/
*/
@Id
@Id
...
...
src/main/java/com/glsx/smart/dao/mapper/SmartUserDeviceMapper.java
View file @
30f5fd5
...
@@ -14,7 +14,7 @@ import org.apache.ibatis.annotations.Mapper;
...
@@ -14,7 +14,7 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
@Mapper
public
interface
SmartUserDeviceMapper
extends
tk
.
mybatis
.
mapper
.
common
.
Mapper
<
SmartUserDevice
>
{
public
interface
SmartUserDeviceMapper
extends
tk
.
mybatis
.
mapper
.
common
.
Mapper
<
SmartUserDevice
>
{
List
<
SmartUserDevice
>
getList
(
SmartUserDevice
userDevice
);
List
<
SmartUserDevice
>
getList
(
SmartUserDevice
req
);
int
deleteDevice
(
SmartUserDevice
userDevice
);
int
deleteDevice
(
SmartUserDevice
req
);
}
}
src/main/java/com/glsx/smart/exception/BusinessException.java
View file @
30f5fd5
...
@@ -45,4 +45,9 @@ public class BusinessException extends RuntimeException {
...
@@ -45,4 +45,9 @@ public class BusinessException extends RuntimeException {
public
static
BusinessException
create
(
ResultEnum
resultEnum
)
{
public
static
BusinessException
create
(
ResultEnum
resultEnum
)
{
return
create
(
resultEnum
.
getCode
(),
resultEnum
.
getMessage
());
return
create
(
resultEnum
.
getCode
(),
resultEnum
.
getMessage
());
}
}
public
static
BusinessException
create
(
ResultEnum
resultEnum
,
Object
...
args
)
{
String
message
=
String
.
format
(
resultEnum
.
getMessage
(),
args
);
return
create
(
resultEnum
.
getCode
(),
message
);
}
}
}
src/main/java/com/glsx/smart/exception/ResultEnum.java
View file @
30f5fd5
...
@@ -12,14 +12,18 @@ public enum ResultEnum {
...
@@ -12,14 +12,18 @@ public enum ResultEnum {
ERROR
(
500
,
"系统异常"
),
ERROR
(
500
,
"系统异常"
),
PARAM_ERROR
(
1001
,
"参数错误"
),
PARAM_ERROR
(
1001
,
"参数错误"
),
PARAM_ERROR_2
(
1001
,
"参数错误:%s"
),
ID_NOT_FOUND
(
1002
,
"ID不存在"
),
ID_NOT_FOUND
(
1002
,
"ID不存在"
),
PRODUCT_NOT_FOUND
(
2001
,
"产品ID
未找到
"
),
PRODUCT_NOT_FOUND
(
2001
,
"产品ID
不存在
"
),
PRODUCT_NAME_DUPLICATE
(
2002
,
"产品名称重复"
),
PRODUCT_NAME_DUPLICATE
(
2002
,
"产品名称重复"
),
PRODUCT_TYPE_NOT_FOUND
(
3001
,
"产品类型ID
未找到
"
),
PRODUCT_TYPE_NOT_FOUND
(
3001
,
"产品类型ID
不存在
"
),
PRODUCT_TYPE_NAME_DUPLICATE
(
3002
,
"产品类型名称重复"
),
PRODUCT_TYPE_NAME_DUPLICATE
(
3002
,
"产品类型名称重复"
),
DEVICE_NOT_FOUND
(
4001
,
"设备信息不存在"
),
USER_NOT_FOUND
(
5001
,
"用户信息不存在"
),
ENCRYPT_EXCEP_1
(
1101
,
"crep加密异常,无法插入"
),
ENCRYPT_EXCEP_1
(
1101
,
"crep加密异常,无法插入"
),
ENCRYPT_EXCEP_2
(
1102
,
"crep加密异常,无法返回钥匙信息"
),
ENCRYPT_EXCEP_2
(
1102
,
"crep加密异常,无法返回钥匙信息"
),
ENCRYPT_EXCEP_3
(
1103
,
"crep加密异常,无法更新"
),
ENCRYPT_EXCEP_3
(
1103
,
"crep加密异常,无法更新"
),
...
...
src/main/java/com/glsx/smart/service/SmartUserDeviceService.java
View file @
30f5fd5
...
@@ -12,11 +12,13 @@ import com.glsx.smart.dao.entity.SmartUserDevice;
...
@@ -12,11 +12,13 @@ import com.glsx.smart.dao.entity.SmartUserDevice;
*/
*/
public
interface
SmartUserDeviceService
{
public
interface
SmartUserDeviceService
{
List
<
SmartUserDevice
>
getList
(
SmartUserDevice
userDevice
);
List
<
SmartUserDevice
>
getList
(
SmartUserDevice
req
);
int
save
(
SmartUserDevice
userDevice
);
SmartUserDevice
getByDeviceId
(
SmartUserDevice
req
);
int
deleteDevice
(
SmartUserDevice
userDevice
);
int
save
(
SmartUserDevice
req
);
int
deleteDevice
(
SmartUserDevice
req
);
String
getUserBindKey
(
String
username
);
String
getUserBindKey
(
String
username
);
}
}
src/main/java/com/glsx/smart/service/impl/SmartUserDeviceServiceImpl.java
View file @
30f5fd5
...
@@ -8,7 +8,9 @@ import com.alibaba.fastjson.JSON;
...
@@ -8,7 +8,9 @@ import com.alibaba.fastjson.JSON;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.glsx.plat.common.utils.HttpUtils
;
import
com.glsx.plat.common.utils.HttpUtils
;
import
com.glsx.plat.common.utils.StringUtils
;
import
com.glsx.plat.common.utils.StringUtils
;
import
com.glsx.smart.dao.entity.SmartUserChannel
;
import
com.glsx.smart.dao.entity.SmartUserDevice
;
import
com.glsx.smart.dao.entity.SmartUserDevice
;
import
com.glsx.smart.dao.mapper.SmartUserChannelMapper
;
import
com.glsx.smart.dao.mapper.SmartUserDeviceMapper
;
import
com.glsx.smart.dao.mapper.SmartUserDeviceMapper
;
import
com.glsx.smart.exception.BusinessException
;
import
com.glsx.smart.exception.BusinessException
;
import
com.glsx.smart.exception.ResultEnum
;
import
com.glsx.smart.exception.ResultEnum
;
...
@@ -37,39 +39,91 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser
...
@@ -37,39 +39,91 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser
@Resource
@Resource
private
SmartUserDeviceMapper
userDeviceMapper
;
private
SmartUserDeviceMapper
userDeviceMapper
;
@Resource
private
SmartUserChannelMapper
userChannelMapper
;
@Override
public
List
<
SmartUserDevice
>
getList
(
SmartUserDevice
req
)
{
return
userDeviceMapper
.
getList
(
req
);
}
@Override
@Override
public
List
<
SmartUserDevice
>
getList
(
SmartUserDevice
userDevice
)
{
public
SmartUserDevice
getByDeviceId
(
SmartUserDevice
req
)
{
return
userDeviceMapper
.
getList
(
userDevice
);
List
<
SmartUserDevice
>
userDeviceList
=
userDeviceMapper
.
select
(
req
);
if
(
userDeviceList
.
isEmpty
())
{
throw
BusinessException
.
create
(
ResultEnum
.
DEVICE_NOT_FOUND
);
}
return
userDeviceList
.
get
(
0
);
}
}
@Override
@Override
@Transactional
@Transactional
public
int
save
(
SmartUserDevice
userDevice
)
{
public
int
save
(
SmartUserDevice
req
)
{
int
rows
;
int
rows
;
Date
now
=
new
Date
();
Date
now
=
new
Date
();
if
(
userDevice
.
getId
()
==
null
)
{
SmartUserDevice
record
=
new
SmartUserDevice
();
userDevice
.
setCreateTime
(
now
);
record
.
setDeviceId
(
req
.
getDeviceId
()
);
userDevice
.
setUpdateTime
(
now
);
record
.
setChannel
(
req
.
getChannel
()
);
rows
=
userDeviceMapper
.
insertSelective
(
userDevice
);
SmartUserDevice
savedUserDevice
=
userDeviceMapper
.
selectOne
(
record
);
}
else
{
if
(
savedUserDevice
==
null
)
{
if
(
StringUtils
.
isBlank
(
userDevice
.
getDeviceName
()))
{
if
(
StringUtils
.
isBlank
(
req
.
getUid
()))
{
throw
BusinessException
.
create
(
ResultEnum
.
PARAM_ERROR
);
throw
BusinessException
.
create
(
ResultEnum
.
PARAM_ERROR
);
}
}
SmartUserDevice
record
=
userDeviceMapper
.
selectByPrimaryKey
(
userDevice
.
getId
());
SmartUserChannel
ucRecord
=
new
SmartUserChannel
();
if
(
record
==
null
)
{
ucRecord
.
setThirdId
(
req
.
getUid
());
throw
BusinessException
.
create
(
ResultEnum
.
ID_NOT_FOUND
);
SmartUserChannel
savedUserChannel
=
userChannelMapper
.
selectOne
(
ucRecord
);
if
(
savedUserChannel
==
null
)
{
throw
BusinessException
.
create
(
ResultEnum
.
USER_NOT_FOUND
);
}
req
.
setUserId
(
savedUserChannel
.
getUserId
());
req
.
setCreateTime
(
now
);
req
.
setUpdateTime
(
now
);
rows
=
userDeviceMapper
.
insertSelective
(
req
);
}
else
{
if
(
StringUtils
.
isBlank
(
req
.
getDeviceName
()))
{
throw
BusinessException
.
create
(
ResultEnum
.
PARAM_ERROR
);
}
}
record
.
setDeviceName
(
userDevice
.
getDeviceName
());
savedUserDevice
.
setDeviceName
(
req
.
getDeviceName
());
record
.
setUpdateTime
(
now
);
savedUserDevice
.
setUpdateTime
(
now
);
rows
=
userDeviceMapper
.
updateByPrimaryKeySelective
(
record
);
rows
=
userDeviceMapper
.
updateByPrimaryKeySelective
(
savedUserDevice
);
}
}
//// 主键传空表示新增
//if (req.getId() == null) {
// if (StringUtils.isBlank(req.getUid())) {
// throw BusinessException.create(ResultEnum.PARAM_ERROR);
// }
// SmartUserChannel ucRecord = new SmartUserChannel();
// ucRecord.setThirdId(req.getUid());
// SmartUserChannel savedUserChannel = userChannelMapper.selectOne(ucRecord);
// if (savedUserChannel == null) {
// throw BusinessException.create(ResultEnum.USER_NOT_FOUND);
// }
// req.setUserId(savedUserChannel.getUserId());
// req.setCreateTime(now);
// req.setUpdateTime(now);
// rows = userDeviceMapper.insertSelective(req);
//} else {
// if (StringUtils.isBlank(req.getDeviceName())) {
// throw BusinessException.create(ResultEnum.PARAM_ERROR);
// }
// SmartUserDevice record = new SmartUserDevice();
// record.setDeviceId(req.getDeviceId());
// record.setChannel(req.getChannel());
// SmartUserDevice savedUserDevice = userDeviceMapper.selectOne(record);
// if (savedUserDevice == null) {
// throw BusinessException.create(ResultEnum.DEVICE_NOT_FOUND);
// }
// savedUserDevice.setDeviceName(req.getDeviceName());
// savedUserDevice.setUpdateTime(now);
// rows = userDeviceMapper.updateByPrimaryKeySelective(savedUserDevice);
//}
return
rows
;
return
rows
;
}
}
@Override
@Override
public
int
deleteDevice
(
SmartUserDevice
userDevice
)
{
public
int
deleteDevice
(
SmartUserDevice
req
)
{
int
rows
;
int
rows
;
rows
=
userDeviceMapper
.
deleteDevice
(
userDevice
);
rows
=
userDeviceMapper
.
deleteDevice
(
req
);
return
rows
;
return
rows
;
}
}
...
...
src/main/resources/mapper/SmartUserDeviceMapper.xml
View file @
30f5fd5
...
@@ -35,11 +35,11 @@
...
@@ -35,11 +35,11 @@
<delete
id=
"deleteDevice"
>
<delete
id=
"deleteDevice"
>
delete from smart_user_device
delete from smart_user_device
<where>
<where>
<if
test=
"
id != null
"
>
<if
test=
"
deviceId != null and deviceId != ''
"
>
and
id = #{id,jdbcType=BIGINT
}
and
device_id = #{deviceId,jdbcType=VARCHAR
}
</if>
</if>
<if
test=
"
userId
!= null"
>
<if
test=
"
channel
!= null"
>
and
user_id = #{userId,jdbcType=BIG
INT}
and
channel = #{channel,jdbcType=TINY
INT}
</if>
</if>
</where>
</where>
</delete>
</delete>
...
...
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