Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
open-source
/
smartDevices-platform-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 e0d685f1
authored
Mar 09, 2021
by
111-PC\111
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'dev' of
http://192.168.3.233:8090/open-source/smartDevices-platform-service
into dev
2 parents
8debd16e
4e26bfc5
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
145 additions
and
303 deletions
src/main/java/cn/com/glsx/modules/factory/PlatForm.java
src/main/java/cn/com/glsx/modules/factory/PlatformConstants.java
src/main/java/cn/com/glsx/modules/factory/PlatformFactory.java
src/main/java/cn/com/glsx/modules/factory/PlatformStrategy.java
src/main/java/cn/com/glsx/modules/factory/strategy/TuyaStrategy.java
src/main/java/cn/com/glsx/modules/model/param/Action.java
src/main/java/cn/com/glsx/modules/model/param/Automation.java
src/main/java/cn/com/glsx/modules/model/param/Condition.java
src/main/java/cn/com/glsx/modules/model/param/Display.java
src/main/java/cn/com/glsx/modules/model/param/Precondition.java
src/main/java/cn/com/glsx/modules/model/param/PreconditionDisplay.java
src/main/java/cn/com/glsx/modules/model/param/TimeDisplay.java
src/main/java/cn/com/glsx/modules/service/HomeService.java
src/main/java/cn/com/glsx/modules/service/ScenesService.java
src/main/java/cn/com/glsx/modules/factory/PlatForm.java
0 → 100644
View file @
e0d685f
package
cn
.
com
.
glsx
.
modules
.
factory
;
/**
* @author fengzhi
* @date 2021/3/9 17:05
* @description 平台信息枚举
*/
public
enum
PlatForm
implements
PlatformConstants
{
TUYA
{
@Override
public
Integer
getCode
()
{
return
0
;
}
@Override
public
String
getValue
()
{
return
"涂鸦"
;
}
@Override
public
String
getBeanName
(){
return
"oneselfStrategy"
;
}
},
XIAOMI
{
@Override
public
Integer
getCode
()
{
return
1
;
}
@Override
public
String
getValue
()
{
return
"小米"
;
}
@Override
public
String
getBeanName
(){
return
"oneselfStrategy"
;
}
},;
public
static
String
getValueByCode
(
Integer
code
)
{
for
(
PlatForm
platForm
:
PlatForm
.
values
())
{
if
(
platForm
.
getCode
().
equals
(
code
))
{
return
platForm
.
getValue
();
}
}
return
null
;
}
public
static
String
getBeanNameByCode
(
Integer
code
)
{
for
(
PlatForm
platForm
:
PlatForm
.
values
())
{
if
(
platForm
.
getCode
().
equals
(
code
))
{
return
platForm
.
getBeanName
();
}
}
return
null
;
}
}
src/main/java/cn/com/glsx/modules/factory/PlatformConstants.java
0 → 100644
View file @
e0d685f
package
cn
.
com
.
glsx
.
modules
.
factory
;
/**
* @author fengzhi
* @date 2021/3/9 17:05
* @description 平台信息接口
*/
public
interface
PlatformConstants
{
Integer
getCode
();
String
getValue
();
String
getBeanName
();
}
src/main/java/cn/com/glsx/modules/factory/PlatformFactory.java
0 → 100644
View file @
e0d685f
package
cn
.
com
.
glsx
.
modules
.
factory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
/**
* @author fengzhi
* @date 2021/3/9 17:05
* @description 平台接口工厂类
*/
@Service
public
class
PlatformFactory
{
@Autowired
Map
<
String
,
PlatformStrategy
>
strategys
=
new
ConcurrentHashMap
<>(
3
);
public
PlatformStrategy
getStrategy
(
Integer
platformCode
)
throws
Exception
{
PlatformStrategy
strategy
=
strategys
.
get
(
PlatForm
.
getBeanNameByCode
(
platformCode
));
if
(
strategy
==
null
)
{
throw
new
RuntimeException
(
"no strategy defined"
);
}
return
strategy
;
}
}
src/main/java/cn/com/glsx/modules/factory/PlatformStrategy.java
0 → 100644
View file @
e0d685f
package
cn
.
com
.
glsx
.
modules
.
factory
;
/**
* @author fengzhi
* @date 2021/3/9 17:05
* @description 平台统一对外接口
*/
public
interface
PlatformStrategy
{
}
src/main/java/cn/com/glsx/modules/factory/strategy/TuyaStrategy.java
0 → 100644
View file @
e0d685f
package
cn
.
com
.
glsx
.
modules
.
factory
.
strategy
;
import
cn.com.glsx.modules.factory.PlatformStrategy
;
import
org.springframework.stereotype.Service
;
@Service
public
class
TuyaStrategy
implements
PlatformStrategy
{
}
src/main/java/cn/com/glsx/modules/model/param/Action.java
deleted
100644 → 0
View file @
8debd16
package
cn
.
com
.
glsx
.
modules
.
model
.
param
;
import
lombok.Data
;
@Data
public
class
Action
{
/*目标 ID*/
private
String
entity_id
;
/*设备动作
entity_id:设备 ID
action_executor :dpIssue
executor_property:标准指令
禁用自动化,
entity_id:自动化id
action_executor:ruleDisable
executor_property:不填
启用自动化
entity_id:自动化id
action_executor:ruleEnable
executor_property:不填
触发自动化或场景
entity_id :自动化 ID 或场景 ID
action_executo:ruleTrigger
executor_property:不填
*/
private
String
executor_property
;
/*执行动作类别*/
private
String
action_executor
;
}
src/main/java/cn/com/glsx/modules/model/param/Automation.java
deleted
100644 → 0
View file @
8debd16
package
cn
.
com
.
glsx
.
modules
.
model
.
param
;
import
lombok.Data
;
import
java.util.List
;
@Data
public
class
Automation
{
/*背景图片*/
private
String
background
;
/*匹配类型*/
private
Integer
match_type
;
/*自动化名称*/
private
String
name
;
/*条件列表*/
private
List
<
Condition
>
conditions
;
/*动作列表*/
private
List
<
Action
>
actions
;
/*自定义条件规则*/
private
String
condition_rule
;
/*前置条件,优先级最高*/
private
List
<
Precondition
>
preconditions
;
}
src/main/java/cn/com/glsx/modules/model/param/Condition.java
deleted
100644 → 0
View file @
8debd16
package
cn
.
com
.
glsx
.
modules
.
model
.
param
;
import
lombok.Data
;
@Data
public
class
Condition
{
/*条件类型。目前支持以下类型:
设备状态条件: entity_type=1
外部条件: entity_type=15
天气条件:entityType=3
定时条件: entity_type=6*/
private
Integer
entity_type
;
/*条件排序,从 1 开始*/
private
Integer
order_num
;
/* 非必填==执行动作实体:
entity_type=1 :取值为设备 ID,必填。
entity_type=15:取值由系统自动生成。
entit_type=3:取值为对应城市的 ID。
entity_type=6:取值固定为 timer*/
private
String
entity_id
;
private
Display
display
;
}
src/main/java/cn/com/glsx/modules/model/param/Display.java
deleted
100644 → 0
View file @
8debd16
package
cn
.
com
.
glsx
.
modules
.
model
.
param
;
import
lombok.Data
;
/*设备,外部,天气条件实体类*/
@Data
public
class
Display
{
/*设备的 statusCode*/
private
String
code
;
/*操作符
type operator
Boolean “==”
Integer “>”,“==”,“<”
Enum “==”
* */
private
String
operator
;
/*Code 的取值*/
private
String
value
;
}
src/main/java/cn/com/glsx/modules/model/param/Precondition.java
deleted
100644 → 0
View file @
8debd16
package
cn
.
com
.
glsx
.
modules
.
model
.
param
;
import
lombok.Data
;
@Data
public
class
Precondition
{
/*当前仅支持时间段限制,固定为timeCheck*/
private
String
cond_type
;
/*条件展示*/
private
PreconditionDisplay
display
;
}
src/main/java/cn/com/glsx/modules/model/param/PreconditionDisplay.java
deleted
100644 → 0
View file @
8debd16
package
cn
.
com
.
glsx
.
modules
.
model
.
param
;
import
lombok.Data
;
@Data
public
class
PreconditionDisplay
{
/*开始时间,默认为当天的某个时间点,24小时制。示例:10:00*/
private
String
start
;
/*结束时间,24小时制。示例:22:00*/
private
String
end
;
/*由 0 和 1 组成的 7 位数字。
0 表示不执行,1 表示执行。
第 1 位为周日,依次表示周一至周六。
例如,0011000表示每周二,周三执行*/
private
String
loops
;
/*时区 ID,示例:Asia/Shanghai*/
private
String
timezone_id
;
}
src/main/java/cn/com/glsx/modules/model/param/TimeDisplay.java
deleted
100644 → 0
View file @
8debd16
package
cn
.
com
.
glsx
.
modules
.
model
.
param
;
import
lombok.Data
;
@Data
public
class
TimeDisplay
{
/*触发日期,格式为yyyyMMdd,例如20191125*/
private
String
date
;
/*触发时间,24 小时制,示例:14:00*/
private
String
time
;
/*由 0 和 1 组成的 7 位数字。
0 表示不执行,1 表示执行。
第 1 位为周日,依次表示周一至周六。
例如,0011000表示每周二,周三执行*/
private
String
loops
;
/*时区 ID,示例:Asia/Shanghai*/
private
String
timezone_id
;
}
src/main/java/cn/com/glsx/modules/service/HomeService.java
View file @
e0d685f
...
@@ -4,6 +4,7 @@ import cn.com.glsx.modules.model.param.HomeInfo;
...
@@ -4,6 +4,7 @@ import cn.com.glsx.modules.model.param.HomeInfo;
import
cn.com.glsx.modules.model.param.ResponseBody
;
import
cn.com.glsx.modules.model.param.ResponseBody
;
import
cn.com.glsx.modules.model.param.memberInfo
;
import
cn.com.glsx.modules.model.param.memberInfo
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.glsx.plat.core.web.R
;
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.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
...
@@ -15,23 +16,11 @@ import java.util.List;
...
@@ -15,23 +16,11 @@ import java.util.List;
/**
/**
* @author fengzhi
* @author fengzhi
* @date 2021/3/5 09:26
* @date 2021/3/5 09:26
* @description 全屋管理
* @description
涂鸦api,
全屋管理
*/
*/
@Service
@Service
@Slf4j
@Slf4j
public
class
HomeService
{
public
class
HomeService
{
/*
PUT /v1.0/homes/{home_id} 修改家庭
DELETE /v1.0/homes/{home_id}/members/{uid} 删除家庭成员
GET /v1.0/homes/{home_id}/members 查询家庭成员
GET /v1.0/users/{uid}/homes 查询⽤户所在的家庭列表
PUT /v1.0/homes/{home_id}/rooms/{room_id}/devices 修改家庭下房间内的设备
DELETE /v1.0/homes/{home_id}/rooms/{room_id}/devices 删除家庭下房间内的设备
DELETE /v1.0/homes/{home_id} 删除家庭
GET /v1.0/homes/{home_id}/rooms 查询家庭下的房间列表
GET /v1.0/homes/{home_id}/rooms/{room_id}/devices 查询家庭房间设备*/
/********************************创建默认家庭,默认成员,设置成员权限********************************/
/********************************创建默认家庭,默认成员,设置成员权限********************************/
@Value
(
"${tuya.baseUrl}"
)
@Value
(
"${tuya.baseUrl}"
)
...
@@ -48,15 +37,22 @@ public class HomeService {
...
@@ -48,15 +37,22 @@ public class HomeService {
* @param uid 涂鸦用户
* @param uid 涂鸦用户
* @param home 家庭
* @param home 家庭
* @param rooms 房间
* @param rooms 房间
*
* @return 家庭 ID,即 home_id
*/
*/
public
void
addHome
(
String
uid
,
HomeInfo
home
,
List
<
String
>
rooms
)
{
public
R
addHome
(
String
uid
,
HomeInfo
home
,
List
<
String
>
rooms
)
{
HashMap
<
String
,
Object
>
params
=
new
HashMap
<>();
HashMap
<
String
,
Object
>
params
=
new
HashMap
<>();
params
.
put
(
"uid"
,
uid
);
params
.
put
(
"uid"
,
uid
);
params
.
put
(
"home"
,
home
);
params
.
put
(
"home"
,
home
);
params
.
put
(
"rooms"
,
rooms
);
params
.
put
(
"rooms"
,
null
==
rooms
?
""
:
rooms
);
ResponseBody
responseBody
=
requestService
.
sendRequestPost
(
baseUrl
+
"/home/create-home"
,
JSONObject
.
toJSONString
(
params
));
ResponseBody
responseBody
=
requestService
.
sendRequestPost
(
baseUrl
+
"/home/create-home"
,
JSONObject
.
toJSONString
(
params
));
log
.
info
(
"回调:"
+
responseBody
);
if
(
responseBody
.
isSuccess
()){
return
R
.
ok
().
data
(
Long
.
valueOf
(
responseBody
.
getResult
()))
;
}
else
{
return
R
.
error
(
responseBody
.
getCode
(),
responseBody
.
getMessage
());
}
}
}
/**
/**
...
@@ -67,13 +63,20 @@ public class HomeService {
...
@@ -67,13 +63,20 @@ public class HomeService {
* @param home_id 家庭 ID
* @param home_id 家庭 ID
* @param app_schema 账号标识
* @param app_schema 账号标识
* @param member 成员对象
* @param member 成员对象
*
*
*/
*/
public
void
addHomeMember
(
String
home_id
,
String
app_schema
,
memberInfo
member
)
{
public
R
addHomeMember
(
String
home_id
,
String
app_schema
,
memberInfo
member
)
{
HashMap
<
String
,
Object
>
params
=
new
HashMap
<>();
HashMap
<
String
,
Object
>
params
=
new
HashMap
<>();
params
.
put
(
"app_schema"
,
app_schema
);
params
.
put
(
"app_schema"
,
app_schema
);
params
.
put
(
"member"
,
member
);
params
.
put
(
"member"
,
member
);
ResponseBody
responseBody
=
requestService
.
sendRequestPost
(
baseUrl
+
"/homes/"
+
home_id
+
"/members"
,
JSONObject
.
toJSONString
(
params
));
ResponseBody
responseBody
=
requestService
.
sendRequestPost
(
baseUrl
+
"/homes/"
+
home_id
+
"/members"
,
JSONObject
.
toJSONString
(
params
));
log
.
info
(
"回调:"
+
responseBody
);
if
(
responseBody
.
isSuccess
()){
return
R
.
ok
().
data
(
Boolean
.
parseBoolean
(
responseBody
.
getResult
()))
;
}
else
{
return
R
.
error
(
responseBody
.
getCode
(),
responseBody
.
getMessage
());
}
}
}
/**
/**
...
@@ -87,53 +90,14 @@ public class HomeService {
...
@@ -87,53 +90,14 @@ public class HomeService {
* true:管理员
* true:管理员
* false:非管理员
* false:非管理员
*/
*/
public
void
editMemberPermission
(
String
home_id
,
String
uid
,
boolean
admin
)
{
public
R
editMemberPermission
(
String
home_id
,
String
uid
,
boolean
admin
)
{
HashMap
<
String
,
Object
>
params
=
new
HashMap
<>();
HashMap
<
String
,
Object
>
params
=
new
HashMap
<>();
params
.
put
(
"admin"
,
admin
);
params
.
put
(
"admin"
,
admin
);
ResponseBody
responseBody
=
requestService
.
sendRequestPut
(
baseUrl
+
"/homes/"
+
home_id
+
"/members/"
+
uid
,
JSONObject
.
toJSONString
(
params
));
ResponseBody
responseBody
=
requestService
.
sendRequestPut
(
baseUrl
+
"/homes/"
+
home_id
+
"/members/"
+
uid
,
JSONObject
.
toJSONString
(
params
));
log
.
info
(
"回调:"
+
responseBody
);
if
(
responseBody
.
isSuccess
()){
}
return
R
.
ok
().
data
(
Boolean
.
parseBoolean
(
responseBody
.
getResult
()))
;
}
else
{
return
R
.
error
(
responseBody
.
getCode
(),
responseBody
.
getMessage
());
/********************************其他接口暂未使用********************************/
}
/**
* POST /v1.0/homes/{home_id}/rooms/{room_id}/devices
* 说明:新增家庭下房间内的设备
*
* @param home_id 家庭 ID
* @param room_id 房间 ID
* @param device_ids 新增的设备 ID
*/
public
void
addHomeRoomDevices
(
Long
home_id
,
Long
room_id
,
List
<
String
>
device_ids
)
{
HashMap
<
String
,
Object
>
params
=
new
HashMap
<>();
params
.
put
(
"device_ids"
,
device_ids
);
ResponseBody
responseBody
=
requestService
.
sendRequestPost
(
baseUrl
+
"/homes/"
+
home_id
+
"/rooms/"
+
room_id
+
"/devices"
,
JSONObject
.
toJSONString
(
params
));
log
.
info
(
"回调:"
+
responseBody
);
}
/**
* GET /v1.0/homes/{home_id}
* 查询家庭
* 根据家庭 ID查询家庭信息
*
* @param home_id 家庭 ID
*/
public
void
queryHome
(
Long
home_id
)
{
ResponseBody
responseBody
=
requestService
.
sendRequestGet
(
baseUrl
+
"/homes/"
+
home_id
);
log
.
info
(
"回调:"
+
responseBody
);
}
/**
* GET /v1.0/homes/{home_id}/devices
* 查询家庭下的设备列表
* 根据家庭 ID查询家庭下的设备列表
*
* @param home_id 家庭 ID
*/
public
void
queryHomeDevices
(
Long
home_id
)
{
ResponseBody
responseBody
=
requestService
.
sendRequestGet
(
baseUrl
+
"/homes/"
+
home_id
+
"/devices"
);
log
.
info
(
"回调:"
+
responseBody
);
}
}
}
}
src/main/java/cn/com/glsx/modules/service/ScenesService.java
deleted
100644 → 0
View file @
8debd16
package
cn
.
com
.
glsx
.
modules
.
service
;
import
cn.com.glsx.modules.model.param.Automation
;
import
cn.com.glsx.modules.model.param.ResponseBody
;
import
com.alibaba.fastjson.JSONObject
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
/**
* @author fengzhi
* @date 2021/3/5 17:26
* @description 场景自动化
*/
@Service
@Slf4j
public
class
ScenesService
{
/*
GET /v1.0/homes/{home_id}/scenes 查询家庭下的场景列表
GET /v1.0/scenes/default-pictures 查询默认场景图片列表
POST /v1.0/homes/{home_id}/scenes/{scene_id}/trigger 触发场景
POST /v1.0/homes/{home_id}/scenes 添加场景
DELETE /v1.0/homes/{home_id}/scenes/{scene_id} 删除场景
PUT /v1.0/homes/{home_id}/scenes/{scene_id} 修改场景
GET /v1.0/homes/{home_id}/scene/devices 查询家庭下支持场景的设备列表
POST /v1.0/devices/{device_id}/scenes/{scene_id} 场景绑定
DELETE /v1.0/devices/{device_id}/scenes/{scene_id} 场景解绑
GET /v1.0/devices/{device_id}/scenes 查询设备已绑定的场景列表
DELETE /v1.0/homes/{home_id}/automations
/{automation_id} 删除自动化
GET /v1.0/homes/{home_id}/automations 查询自动化列表
GET /v1.0/homes/{home_id}/automations
/{automation_id} 查询家庭下的某个自动化
POST /v1.0/homes/{home_id}/automations
/{automation_id}/conditions/trigger 触发家庭下某个自动化的外部条件
GET /v1.0/homes/{home_id}/automation
/devices 查询家庭下支持自动化的设备列表
GET /v1.0/homes/automation/weather/conditions 查询自动化支持的天气条件
GET /v1.0/homes/{home_id}/enable-linkage/codes 查询家庭下支持的动作列表
PUT /v1.0/homes/{home_id}/automations
/{automation_id}/actions/enable 启用自动化
PUT /v1.0/homes/{home_id}/automations
/{automation_id}/actions/disable 停用自动化*/
/********************************创建,修改自动化********************************/
@Value
(
"${tuya.baseUrl}"
)
private
String
baseUrl
;
@Autowired
private
SendRequestService
requestService
;
/**
* POST /v1.0/homes/{home_id}/automations
* 添加自动化
* 说明:为家庭添加自动化功能。
*
* @param home_id 用户家庭 ID
* @param automation 自动化对象参数
*/
public
void
addAutomations
(
String
home_id
,
Automation
automation
)
{
ResponseBody
responseBody
=
requestService
.
sendRequestPost
(
baseUrl
+
"/homes/"
+
home_id
+
"/automations"
,
JSONObject
.
toJSONString
(
automation
));
log
.
info
(
"回调:"
+
responseBody
);
}
/**
* PUT /v1.0/homes/{home_id}/automations/{automation_id}
* 修改自动化
* 说明:修改家庭的自动化配置。
*
* @param home_id 用户家庭 ID
* @param automation_id 自动化 ID
* @param automation 自动化对象参数
*/
public
void
editAutomations
(
String
home_id
,
String
automation_id
,
Automation
automation
)
{
ResponseBody
responseBody
=
requestService
.
sendRequestPut
(
baseUrl
+
"/homes/"
+
home_id
+
"/automations/"
+
automation_id
,
JSONObject
.
toJSONString
(
automation
));
log
.
info
(
"回调:"
+
responseBody
);
}
}
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