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 df111acf
authored
Apr 23, 2021
by
tyfanchz
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
用户设备管理功能开发
1 parent
7c5bbc22
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
435 additions
and
0 deletions
src/main/java/com/glsx/smart/controller/UserDeviceController.java
src/main/java/com/glsx/smart/dao/entity/SmartUserChannel.java
src/main/java/com/glsx/smart/dao/entity/SmartUserDevice.java
src/main/java/com/glsx/smart/dao/mapper/SmartUserChannelMapper.java
src/main/java/com/glsx/smart/dao/mapper/SmartUserDeviceMapper.java
src/main/java/com/glsx/smart/service/SmartUserChannelService.java
src/main/java/com/glsx/smart/service/SmartUserDeviceService.java
src/main/java/com/glsx/smart/service/impl/SmartUserChannelServiceImpl.java
src/main/java/com/glsx/smart/service/impl/SmartUserDeviceServiceImpl.java
src/main/resources/bootstrap.properties
src/main/resources/mapper/SmartUserChannelMapper.xml
src/main/resources/mapper/SmartUserDeviceMapper.xml
src/main/java/com/glsx/smart/controller/UserDeviceController.java
0 → 100644
View file @
df111ac
package
com
.
glsx
.
smart
.
controller
;
import
java.util.List
;
import
com.alibaba.fastjson.JSON
;
import
com.glsx.plat.core.web.R
;
import
com.glsx.smart.dao.entity.SmartUserDevice
;
import
com.glsx.smart.exception.BusinessException
;
import
com.glsx.smart.exception.ResultEnum
;
import
com.glsx.smart.service.SmartUserDeviceService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
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.RestController
;
/**
* <p>Description: 用户设备业务
* <p>Project: chejia-smart
*
* @author wbh
* @date 2021-04-23
*/
@Slf4j
@RestController
@RequestMapping
(
"/userDevice"
)
public
class
UserDeviceController
{
@Autowired
private
SmartUserDeviceService
userDeviceService
;
/**
* 获取用户设备
*
* @param userDevice 请求
* @return 结果
*/
@RequestMapping
(
value
=
"/getList"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
})
public
R
getList
(
SmartUserDevice
userDevice
)
{
log
.
info
(
"$$$$ /userDevice/getList param: {}"
,
JSON
.
toJSONString
(
userDevice
));
if
(
userDevice
.
getUserId
()
==
null
)
{
throw
BusinessException
.
create
(
ResultEnum
.
PARAM_ERROR
);
}
List
<
SmartUserDevice
>
userDeviceList
=
userDeviceService
.
getList
(
userDevice
);
return
R
.
ok
().
data
(
userDeviceList
);
}
/**
* 保存用户设备
*
* @param userDevice 请求
* @return 结果
*/
@RequestMapping
(
value
=
"/save"
,
method
=
{
RequestMethod
.
POST
})
public
R
save
(
@RequestBody
SmartUserDevice
userDevice
)
{
log
.
info
(
"$$$$ /userDevice/save param: {}"
,
JSON
.
toJSONString
(
userDevice
));
boolean
success
=
userDeviceService
.
save
(
userDevice
)
>
0
;
return
R
.
ok
().
data
(
success
);
}
/**
* 删除用户设备
*
* @param userDevice 请求
* @return 结果
*/
@RequestMapping
(
value
=
"/deleteDevice"
,
method
=
{
RequestMethod
.
POST
})
public
R
deleteDevice
(
@RequestBody
SmartUserDevice
userDevice
)
{
log
.
info
(
"$$$$ /userDevice/deleteDevice param: {}"
,
JSON
.
toJSONString
(
userDevice
));
if
(
userDevice
.
getId
()
==
null
&&
userDevice
.
getUserId
()
==
null
)
{
throw
BusinessException
.
create
(
ResultEnum
.
PARAM_ERROR
);
}
boolean
success
=
userDeviceService
.
deleteDevice
(
userDevice
)
>
0
;
return
R
.
ok
().
data
(
success
);
}
}
src/main/java/com/glsx/smart/dao/entity/SmartUserChannel.java
0 → 100644
View file @
df111ac
package
com
.
glsx
.
smart
.
dao
.
entity
;
import
javax.persistence.Column
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
import
java.util.Date
;
import
lombok.Data
;
/**
* <p>Description:
* <p>Project: chejia-smart
*
* @author wbh
* @date 2021-04-23
*/
/**
* 车家智能第三方用户关系表
*/
@Data
@Table
(
name
=
"smart_user_channel"
)
public
class
SmartUserChannel
{
/**
* 标识ID
*/
@Id
@Column
(
name
=
"id"
)
@GeneratedValue
(
generator
=
"JDBC"
)
private
Long
id
;
/**
* 用户ID 关联smart_user_relation中id
*/
@Column
(
name
=
"user_id"
)
private
Long
userId
;
/**
* 第三方平台标识 1涂鸦 2绿米
*/
@Column
(
name
=
"channel"
)
private
Byte
channel
;
/**
* 第三方平台用户id
*/
@Column
(
name
=
"third_id"
)
private
String
thirdId
;
/**
* 创建时间
*/
@Column
(
name
=
"create_time"
)
private
Date
createTime
;
}
src/main/java/com/glsx/smart/dao/entity/SmartUserDevice.java
0 → 100644
View file @
df111ac
package
com
.
glsx
.
smart
.
dao
.
entity
;
import
javax.persistence.Column
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
import
java.util.Date
;
import
lombok.Data
;
/**
* <p>Description:
* <p>Project: chejia-smart
*
* @author wbh
* @date 2021-04-23
*/
/**
* 车家智能用户设备表
*/
@Data
@Table
(
name
=
"smart_user_device"
)
public
class
SmartUserDevice
{
/**
* 标识ID
*/
@Id
@Column
(
name
=
"id"
)
@GeneratedValue
(
generator
=
"JDBC"
)
private
Long
id
;
/**
* 用户ID 关联smart_user_relation中id
*/
@Column
(
name
=
"user_id"
)
private
Long
userId
;
/**
* 设备id(或者网关设备)
*/
@Column
(
name
=
"device_id"
)
private
String
deviceId
;
/**
* 设备名称
*/
@Column
(
name
=
"device_name"
)
private
String
deviceName
;
/**
* 第三方平台标识 1涂鸦 2绿米
*/
@Column
(
name
=
"channel"
)
private
Byte
channel
;
/**
* 父设备id
*/
@Column
(
name
=
"parent_id"
)
private
String
parentId
;
/**
* 接入平台产品id
*/
@Column
(
name
=
"platform_product_id"
)
private
String
platformProductId
;
/**
* 创建时间
*/
@Column
(
name
=
"create_time"
)
private
Date
createTime
;
/**
* 更新时间
*/
@Column
(
name
=
"update_time"
)
private
Date
updateTime
;
}
src/main/java/com/glsx/smart/dao/mapper/SmartUserChannelMapper.java
0 → 100644
View file @
df111ac
package
com
.
glsx
.
smart
.
dao
.
mapper
;
import
com.glsx.smart.dao.entity.SmartUserChannel
;
import
org.apache.ibatis.annotations.Mapper
;
/**
* <p>Description:
* <p>Project: chejia-smart
*
* @author wbh
* @date 2021-04-23
*/
@Mapper
public
interface
SmartUserChannelMapper
extends
tk
.
mybatis
.
mapper
.
common
.
Mapper
<
SmartUserChannel
>
{
}
src/main/java/com/glsx/smart/dao/mapper/SmartUserDeviceMapper.java
0 → 100644
View file @
df111ac
package
com
.
glsx
.
smart
.
dao
.
mapper
;
import
java.util.List
;
import
com.glsx.smart.dao.entity.SmartUserDevice
;
import
org.apache.ibatis.annotations.Mapper
;
/**
* <p>Description:
* <p>Project: chejia-smart
*
* @author wbh
* @date 2021-04-23
*/
@Mapper
public
interface
SmartUserDeviceMapper
extends
tk
.
mybatis
.
mapper
.
common
.
Mapper
<
SmartUserDevice
>
{
List
<
SmartUserDevice
>
getList
(
SmartUserDevice
userDevice
);
int
deleteDevice
(
SmartUserDevice
userDevice
);
}
src/main/java/com/glsx/smart/service/SmartUserChannelService.java
0 → 100644
View file @
df111ac
package
com
.
glsx
.
smart
.
service
;
/**
* <p>Description:
* <p>Project: chejia-smart
*
* @author wbh
* @date 2021-04-23
*/
public
interface
SmartUserChannelService
{
}
src/main/java/com/glsx/smart/service/SmartUserDeviceService.java
0 → 100644
View file @
df111ac
package
com
.
glsx
.
smart
.
service
;
import
java.util.List
;
import
com.glsx.smart.dao.entity.SmartUserDevice
;
/**
* <p>Description:
* <p>Project: chejia-smart
*
* @author wbh
* @date 2021-04-23
*/
public
interface
SmartUserDeviceService
{
List
<
SmartUserDevice
>
getList
(
SmartUserDevice
userDevice
);
int
save
(
SmartUserDevice
userDevice
);
int
deleteDevice
(
SmartUserDevice
userDevice
);
}
src/main/java/com/glsx/smart/service/impl/SmartUserChannelServiceImpl.java
0 → 100644
View file @
df111ac
package
com
.
glsx
.
smart
.
service
.
impl
;
import
javax.annotation.Resource
;
import
com.glsx.smart.dao.mapper.SmartUserChannelMapper
;
import
com.glsx.smart.service.BaseService
;
import
com.glsx.smart.service.SmartUserChannelService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Service
;
/**
* <p>Description:
* <p>Project: chejia-smart
*
* @author wbh
* @date 2021-04-23
*/
@Slf4j
@Service
public
class
SmartUserChannelServiceImpl
extends
BaseService
implements
SmartUserChannelService
{
@Resource
private
SmartUserChannelMapper
userChannelMapper
;
}
src/main/java/com/glsx/smart/service/impl/SmartUserDeviceServiceImpl.java
0 → 100644
View file @
df111ac
package
com
.
glsx
.
smart
.
service
.
impl
;
import
javax.annotation.Resource
;
import
javax.transaction.Transactional
;
import
java.util.Date
;
import
java.util.List
;
import
com.glsx.plat.common.utils.StringUtils
;
import
com.glsx.smart.dao.entity.SmartUserDevice
;
import
com.glsx.smart.dao.mapper.SmartUserDeviceMapper
;
import
com.glsx.smart.exception.BusinessException
;
import
com.glsx.smart.exception.ResultEnum
;
import
com.glsx.smart.service.BaseService
;
import
com.glsx.smart.service.SmartUserDeviceService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Service
;
/**
* <p>Description: 用户设备业务
* <p>Project: chejia-smart
*
* @author wbh
* @date 2021-04-23
*/
@Slf4j
@Service
public
class
SmartUserDeviceServiceImpl
extends
BaseService
implements
SmartUserDeviceService
{
@Resource
private
SmartUserDeviceMapper
userDeviceMapper
;
@Override
public
List
<
SmartUserDevice
>
getList
(
SmartUserDevice
userDevice
)
{
return
userDeviceMapper
.
getList
(
userDevice
);
}
@Override
@Transactional
public
int
save
(
SmartUserDevice
userDevice
)
{
int
rows
;
Date
now
=
new
Date
();
if
(
userDevice
.
getId
()
==
null
)
{
userDevice
.
setCreateTime
(
now
);
userDevice
.
setUpdateTime
(
now
);
rows
=
userDeviceMapper
.
insertSelective
(
userDevice
);
}
else
{
if
(
StringUtils
.
isBlank
(
userDevice
.
getDeviceName
()))
{
throw
BusinessException
.
create
(
ResultEnum
.
PARAM_ERROR
);
}
SmartUserDevice
record
=
userDeviceMapper
.
selectByPrimaryKey
(
userDevice
.
getId
());
if
(
record
==
null
)
{
throw
BusinessException
.
create
(
ResultEnum
.
ID_NOT_FOUND
);
}
record
.
setDeviceName
(
userDevice
.
getDeviceName
());
record
.
setUpdateTime
(
now
);
rows
=
userDeviceMapper
.
updateByPrimaryKeySelective
(
record
);
}
return
rows
;
}
@Override
public
int
deleteDevice
(
SmartUserDevice
userDevice
)
{
int
rows
;
rows
=
userDeviceMapper
.
deleteDevice
(
userDevice
);
return
rows
;
}
}
src/main/resources/bootstrap.properties
View file @
df111ac
...
@@ -3,3 +3,5 @@ server.port=8209
...
@@ -3,3 +3,5 @@ server.port=8209
#nacos\u914D\u7F6E
#nacos\u914D\u7F6E
spring.cloud.nacos.config.group
=
DEFAULT_GROUP
spring.cloud.nacos.config.group
=
DEFAULT_GROUP
spring.cloud.nacos.config.server-
addr
=
192.168.0.63:8848
spring.cloud.nacos.config.server-
addr
=
192.168.0.63:8848
spring.cloud.nacos.config.prefix
=
${spring.application.name}
spring.cloud.nacos.config.file-
extension
=
properties
src/main/resources/mapper/SmartUserChannelMapper.xml
0 → 100644
View file @
df111ac
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.glsx.smart.dao.mapper.SmartUserChannelMapper"
>
<resultMap
id=
"BaseResultMap"
type=
"com.glsx.smart.dao.entity.SmartUserChannel"
>
<!--@mbg.generated generated on Fri Apr 23 15:24:29 CST 2021.-->
<!--@Table smart_user_channel-->
<id
column=
"id"
jdbcType=
"BIGINT"
property=
"id"
/>
<result
column=
"user_id"
jdbcType=
"BIGINT"
property=
"userId"
/>
<result
column=
"channel"
jdbcType=
"TINYINT"
property=
"channel"
/>
<result
column=
"third_id"
jdbcType=
"VARCHAR"
property=
"thirdId"
/>
<result
column=
"create_time"
jdbcType=
"TIMESTAMP"
property=
"createTime"
/>
</resultMap>
<sql
id=
"Base_Column_List"
>
<!--@mbg.generated generated on Fri Apr 23 15:24:29 CST 2021.-->
id, user_id, channel, third_id, create_time
</sql>
</mapper>
src/main/resources/mapper/SmartUserDeviceMapper.xml
0 → 100644
View file @
df111ac
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.glsx.smart.dao.mapper.SmartUserDeviceMapper"
>
<resultMap
id=
"BaseResultMap"
type=
"com.glsx.smart.dao.entity.SmartUserDevice"
>
<!--@mbg.generated generated on Fri Apr 23 15:24:29 CST 2021.-->
<!--@Table smart_user_device-->
<id
column=
"id"
jdbcType=
"BIGINT"
property=
"id"
/>
<result
column=
"user_id"
jdbcType=
"BIGINT"
property=
"userId"
/>
<result
column=
"device_id"
jdbcType=
"VARCHAR"
property=
"deviceId"
/>
<result
column=
"device_name"
jdbcType=
"VARCHAR"
property=
"deviceName"
/>
<result
column=
"channel"
jdbcType=
"TINYINT"
property=
"channel"
/>
<result
column=
"parent_id"
jdbcType=
"VARCHAR"
property=
"parentId"
/>
<result
column=
"platform_product_id"
jdbcType=
"VARCHAR"
property=
"platformProductId"
/>
<result
column=
"create_time"
jdbcType=
"TIMESTAMP"
property=
"createTime"
/>
<result
column=
"update_time"
jdbcType=
"TIMESTAMP"
property=
"updateTime"
/>
</resultMap>
<sql
id=
"Base_Column_List"
>
<!--@mbg.generated generated on Fri Apr 23 15:24:29 CST 2021.-->
id, user_id, device_id, device_name, channel, parent_id, platform_product_id, create_time,
update_time
</sql>
<select
id=
"getList"
resultMap=
"BaseResultMap"
>
select id, user_id, device_id, device_name, channel, parent_id, platform_product_id,
create_time, update_time
from smart_user_device
<where>
<if
test=
"userId != null"
>
and user_id = #{userId,jdbcType=BIGINT}
</if>
</where>
</select>
<delete
id=
"deleteDevice"
>
delete from smart_user_device
<where>
<if
test=
"id != null"
>
and id = #{id,jdbcType=BIGINT}
</if>
<if
test=
"userId != null"
>
and user_id = #{userId,jdbcType=BIGINT}
</if>
</where>
</delete>
</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