/
productcreate.go
136 lines (122 loc) · 4.28 KB
/
productcreate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/**
* Created by GoLand.
* User: 姜伟
* Date: 2020/2/2 0002
* Time: 19:40
*/
package studio
import (
"strconv"
"github.com/a07061625/gompf/mpf/api/mpiot"
"github.com/a07061625/gompf/mpf/mpconstant/errorcode"
"github.com/a07061625/gompf/mpf/mperr"
"github.com/valyala/fasthttp"
)
// 新建产品
type productCreate struct {
mpiot.BaseTencent
productName string // 产品名称
productType int // 产品类型
productDesc string // 产品描述
categoryId int // 分组模板ID
encryptionType string // 加密类型
netType string // 连接类型
dataProtocol int // 数据协议
projectId int // 项目ID
}
func (pc *productCreate) SetProductName(productName string) {
if len(productName) > 0 {
pc.productName = productName
} else {
panic(mperr.NewIotTencent(errorcode.IotTencentParam, "产品名称不合法", nil))
}
}
func (pc *productCreate) SetProductType(productType int) {
if productType > 0 {
pc.productType = productType
} else {
panic(mperr.NewIotTencent(errorcode.IotTencentParam, "产品类型不合法", nil))
}
}
func (pc *productCreate) SetProductDesc(productDesc string) {
if len(productDesc) > 0 {
pc.productDesc = productDesc
} else {
panic(mperr.NewIotTencent(errorcode.IotTencentParam, "产品描述不合法", nil))
}
}
func (pc *productCreate) SetCategoryId(categoryId int) {
if categoryId > 0 {
pc.categoryId = categoryId
} else {
panic(mperr.NewIotTencent(errorcode.IotTencentParam, "分组模板ID不合法", nil))
}
}
func (pc *productCreate) SetEncryptionType(encryptionType string) {
if len(encryptionType) > 0 {
pc.encryptionType = encryptionType
} else {
panic(mperr.NewIotTencent(errorcode.IotTencentParam, "加密类型不合法", nil))
}
}
func (pc *productCreate) SetNetType(netType string) {
if len(netType) > 0 {
pc.netType = netType
} else {
panic(mperr.NewIotTencent(errorcode.IotTencentParam, "连接类型不合法", nil))
}
}
func (pc *productCreate) SetDataProtocol(dataProtocol int) {
if dataProtocol > 0 {
pc.dataProtocol = dataProtocol
} else {
panic(mperr.NewIotTencent(errorcode.IotTencentParam, "数据协议不合法", nil))
}
}
func (pc *productCreate) SetProjectId(projectId int) {
if projectId > 0 {
pc.projectId = projectId
} else {
panic(mperr.NewIotTencent(errorcode.IotTencentParam, "项目ID不合法", nil))
}
}
func (pc *productCreate) CheckData() (*fasthttp.Client, *fasthttp.Request) {
if len(pc.productName) == 0 {
panic(mperr.NewIotTencent(errorcode.IotTencentParam, "产品名称不能为空", nil))
}
if pc.productType <= 0 {
panic(mperr.NewIotTencent(errorcode.IotTencentParam, "产品类型不能为空", nil))
}
if len(pc.productDesc) == 0 {
panic(mperr.NewIotTencent(errorcode.IotTencentParam, "产品描述不能为空", nil))
}
if pc.categoryId <= 0 {
panic(mperr.NewIotTencent(errorcode.IotTencentParam, "分组模板ID不能为空", nil))
}
if len(pc.encryptionType) == 0 {
panic(mperr.NewIotTencent(errorcode.IotTencentParam, "加密类型不能为空", nil))
}
if len(pc.netType) == 0 {
panic(mperr.NewIotTencent(errorcode.IotTencentParam, "连接类型不能为空", nil))
}
if pc.dataProtocol <= 0 {
panic(mperr.NewIotTencent(errorcode.IotTencentParam, "数据协议不能为空", nil))
}
if pc.projectId <= 0 {
panic(mperr.NewIotTencent(errorcode.IotTencentParam, "项目ID不能为空", nil))
}
pc.ReqData["ProjectName"] = pc.productName
pc.ReqData["ProductType"] = strconv.Itoa(pc.productType)
pc.ReqData["ProductDesc"] = pc.productDesc
pc.ReqData["CategoryId"] = strconv.Itoa(pc.categoryId)
pc.ReqData["EncryptionType"] = pc.encryptionType
pc.ReqData["NetType"] = pc.netType
pc.ReqData["DataProtocol"] = strconv.Itoa(pc.dataProtocol)
pc.ReqData["ProjectId"] = strconv.Itoa(pc.projectId)
return pc.GetRequest()
}
func NewProductCreate() *productCreate {
pc := &productCreate{mpiot.NewBaseTencent(), "", 0, "", 0, "", "", 0, 0}
pc.ReqHeader["X-TC-Action"] = "CreateStudioProduct"
return pc
}