Skip to content

Commit

Permalink
feat: 新增产品配置项
Browse files Browse the repository at this point in the history
  • Loading branch information
godLei6 committed Dec 16, 2024
1 parent 93433cf commit 528de36
Show file tree
Hide file tree
Showing 10 changed files with 1,624 additions and 1,591 deletions.
10 changes: 9 additions & 1 deletion service/apisvr/http/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -11479,6 +11479,11 @@
"format": "int64",
"description": "产品状态 1:启用 2:禁用 3:开发中"
},
"isCanCoverBindDevice": {
"type": "integer",
"format": "int64",
"description": "是否可以覆盖绑定设备,默认为2"
},
"protocolConf": {
"type": "array",
"items": {
Expand All @@ -11497,7 +11502,10 @@
"description": "自定义ui,key是端的类型(web-client mini-client) value是以下类型的对象{version:123(版本号,只读),isUpdateUi:bool(是否更新ui),path:string(前端路径,如果需要修改,需要将isUpdateUi置为true并在这个参数中传入压缩包的filePath)}"
}
},
"title": "ProductInfo"
"title": "ProductInfo",
"required": [
"isCanCoverBindDevice"
]
},
"ProductInfoDeleteReq": {
"type": "object",
Expand Down
1 change: 1 addition & 0 deletions service/apisvr/http/things/product/info.api
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type (
Tags []*Tag `json:"tags,optional"` // 产品tag
SceneMode string `json:"sceneMode,optional"` //场景模式 读写类型: r(只读) rw(可读可写) none(不参与场景)
Status int64 `json:"status,optional"` //产品状态 1:启用 2:禁用 3:开发中
IsCanCoverBindDevice int64 `json:"isCanCoverBindDevice,optinal"` //是否可以覆盖绑定设备,默认为2
ProtocolConf []*Tag `json:"protocolConf,optional,omitempty"` //协议配置
// DevStatus *string `json:"devStatus,optional,omitempty"` // 产品状态
Protocol *ProtocolInfo `json:"protocol,omitempty"`
Expand Down
45 changes: 23 additions & 22 deletions service/apisvr/internal/types/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 11 additions & 10 deletions service/dmsvr/internal/logic/devicemanage/deviceInfoBindLogic.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ func (l *DeviceInfoBindLogic) DeviceInfoBind(in *dm.DeviceInfoBindReq) (*dm.Empt
return nil, errors.Permissions.AddMsg("无权限")
}
diDB := relationDB.NewDeviceInfoRepo(l.ctx)
pi, err := l.svcCtx.ProductCache.GetData(l.ctx, in.Device.ProductID)
if err != nil {
l.Error(err)
return nil, err
}
di, err := diDB.FindOneByFilter(ctxs.WithRoot(l.ctx), relationDB.DeviceFilter{
ProductID: in.Device.ProductID,
DeviceNames: []string{in.Device.DeviceName},
Expand All @@ -60,11 +65,7 @@ func (l *DeviceInfoBindLogic) DeviceInfoBind(in *dm.DeviceInfoBindReq) (*dm.Empt
if !errors.Cmp(err, errors.NotFind) {
return nil, err
}
pi, err := l.svcCtx.ProductCache.GetData(l.ctx, in.Device.ProductID)
if err != nil {
l.Error(err)
return nil, err
}

if !(pi.NetType == def.NetBle && pi.AutoRegister == def.AutoRegAuto) {
return nil, errors.NotFind
}
Expand All @@ -90,7 +91,7 @@ func (l *DeviceInfoBindLogic) DeviceInfoBind(in *dm.DeviceInfoBindReq) (*dm.Empt
}
//di.ProjectID=1 di.AreaID=2 dpi.ProjectID=0
if !((di.TenantCode == def.TenantCodeDefault && di.ProjectID < 3) || int64(di.ProjectID) == uc.ProjectID ||
int64(di.ProjectID) == dpi.DefaultProjectID) { //如果在其他租户下 则已经被绑定 或 在本租户下,但是不在一个项目下也不允许绑定
int64(di.ProjectID) == dpi.DefaultProjectID) && !(pi.IsCanCoverBindDevice == def.True) { //如果在其他租户下 则已经被绑定 或 在本租户下,但是不在一个项目下也不允许绑定
//只有归属于default租户和自己租户的才可以
l.Infof("DeviceCantBound di:%v uc:%v", utils.Fmt(di), utils.Fmt(uc))
return nil, errors.DeviceCantBound.WithMsg("设备已被其他用户绑定。如需解绑,请按照相关流程操作。")
Expand All @@ -117,18 +118,18 @@ func (l *DeviceInfoBindLogic) DeviceInfoBind(in *dm.DeviceInfoBindReq) (*dm.Empt
di.FirstBind = sql.NullTime{Time: time.Now(), Valid: true}
}
di.LastBind = sql.NullTime{Time: time.Now(), Valid: true}
pi, err := l.svcCtx.ProductCache.GetData(l.ctx, di.ProductID)
pc, err := l.svcCtx.ProductCache.GetData(l.ctx, di.ProductID)
if err != nil && !errors.Cmp(err, errors.NotFind) {
l.Error(err)
return nil, err
}
if pi.TrialTime.GetValue() != 0 && !di.ExpTime.Valid {
if pc.TrialTime.GetValue() != 0 && !di.ExpTime.Valid {
di.ExpTime = sql.NullTime{
Time: time.Now().Add(time.Hour * 24 * time.Duration(pi.TrialTime.GetValue())),
Time: time.Now().Add(time.Hour * 24 * time.Duration(pc.TrialTime.GetValue())),
Valid: true,
}
}
if pi.NetType == def.NetBle { //蓝牙绑定了就是上线
if pc.NetType == def.NetBle { //蓝牙绑定了就是上线
di.IsOnline = def.True
di.Status = def.DeviceStatusOnline
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ func (l *DeviceInfoCanBindLogic) DeviceInfoCanBind(in *dm.DeviceInfoCanBindReq)
if err != nil {
return nil, err
}
if !((di.TenantCode == def.TenantCodeDefault && di.ProjectID < 3) || int64(di.ProjectID) == uc.ProjectID || di.ProjectID == dpi.DefaultProjectID) { //如果在其他租户下 则已经被绑定 或 在本租户下,但是不在一个项目下也不允许绑定
pi, err := l.svcCtx.ProductCache.GetData(l.ctx, in.Device.ProductID)
if err != nil {
l.Error(err)
return nil, err
}
if !((di.TenantCode == def.TenantCodeDefault && di.ProjectID < 3) || int64(di.ProjectID) == uc.ProjectID || di.ProjectID == dpi.DefaultProjectID) && !(pi.IsCanCoverBindDevice == def.True) { //如果在其他租户下 则已经被绑定 或 在本租户下,但是不在一个项目下也不允许绑定
//只有归属于default租户和自己租户的才可以
return nil, errors.DeviceCantBound.WithMsg("设备已被其他用户绑定。如需解绑,请按照相关流程操作。")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,15 @@ func (l *ProductInfoCreateLogic) CheckProductID(in *dm.ProductInfo) (bool, error
*/
func (l *ProductInfoCreateLogic) ConvProductPbToPo(in *dm.ProductInfo) (*relationDB.DmProductInfo, error) {
pi := &relationDB.DmProductInfo{
ProductID: in.ProductID, // 产品id
ProductName: in.ProductName, // 产品名称
Desc: in.Desc.GetValue(),
Status: in.Status,
Secret: utils.GetRandomBase64(20),
TrialTime: in.TrialTime.GetValue(),
SceneMode: in.SceneMode,
DeviceSchemaMode: in.DeviceSchemaMode,
ProductID: in.ProductID, // 产品id
ProductName: in.ProductName, // 产品名称
Desc: in.Desc.GetValue(),
Status: in.Status,
Secret: utils.GetRandomBase64(20),
TrialTime: in.TrialTime.GetValue(),
SceneMode: in.SceneMode,
DeviceSchemaMode: in.DeviceSchemaMode,
IsCanCoverBindDevice: in.IsCanCoverBindDevice,
}
if in.AutoRegister != def.Unknown {
pi.AutoRegister = in.AutoRegister
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ func (l *ProductInfoUpdateLogic) setPoByPb(old *relationDB.DmProductInfo, data *
if data.DeviceSchemaMode != 0 {
old.DeviceSchemaMode = data.DeviceSchemaMode
}
if data.IsCanCoverBindDevice != 0 {
old.IsCanCoverBindDevice = data.IsCanCoverBindDevice
}
return nil
}

Expand Down
39 changes: 20 additions & 19 deletions service/dmsvr/internal/repo/relationDB/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,25 +145,26 @@ func (m *DmDeviceProfile) TableName() string {

// 产品信息表
type DmProductInfo struct {
ID int64 `gorm:"column:id;type:bigint;primary_key;AUTO_INCREMENT"`
ProductID string `gorm:"column:product_id;type:varchar(100);uniqueIndex:pd;NOT NULL"` // 产品id
ProductName string `gorm:"column:product_name;type:varchar(100);NOT NULL"` // 产品名称
ProductImg string `gorm:"column:product_img;type:varchar(200)"` // 产品图片
ProductType int64 `gorm:"column:product_type;type:smallint;default:1"` // 产品状态:1:开发中,2:审核中,3:已发布
AuthMode int64 `gorm:"column:auth_mode;type:smallint;default:1"` // 认证方式:1:账密认证,2:秘钥认证
DeviceType int64 `gorm:"column:device_type;index;type:smallint;default:1"` // 设备类型:1:设备,2:网关,3:子设备
CategoryID int64 `gorm:"column:category_id;type:integer;default:2"` // 产品品类 2:未分类
NetType int64 `gorm:"column:net_type;type:smallint;default:1"` // 通讯方式:1:其他,2:wi-fi,3:2G/3G/4G,4:5G,5:BLE,6:LoRaWAN
ProtocolCode string `gorm:"column:protocol_code;type:varchar(100);default:iThings"` // 协议code,默认iThings iThings,iThings-thingsboard,wumei,aliyun,huaweiyun,tuya
AutoRegister int64 `gorm:"column:auto_register;type:smallint;default:1"` // 动态注册:1:关闭,2:打开,3:打开并自动创建设备
DeviceSchemaMode int64 `gorm:"column:device_schema_mode;type:smallint;default:1"` // 设备物模型模式:1:关闭,2:设备自动创建3: 设备自动创建及上报无定义自动创建
Secret string `gorm:"column:secret;type:varchar(50)"` // 动态注册产品秘钥
Desc string `gorm:"column:desc;type:varchar(200)"` // 描述
TrialTime int64 `gorm:"column:trial_time"` //试用时间(单位为天,为0不限制)
Status devices.ProductStatus `gorm:"column:status;type:smallint;default:1"`
SceneMode string `gorm:"column:scene_mode;type:varchar(20);default:rw"` // 场景模式 读写类型: r(只读) rw(可读可写) none(不参与场景)
Tags map[string]string `gorm:"column:tags;type:json;serializer:json;NOT NULL;default:'{}'"` // 产品标签
ProtocolConf map[string]string `gorm:"column:protocol_conf;type:json;serializer:json;NOT NULL;default:'{}'"` // 自定义协议配置
ID int64 `gorm:"column:id;type:bigint;primary_key;AUTO_INCREMENT"`
ProductID string `gorm:"column:product_id;type:varchar(100);uniqueIndex:pd;NOT NULL"` // 产品id
ProductName string `gorm:"column:product_name;type:varchar(100);NOT NULL"` // 产品名称
ProductImg string `gorm:"column:product_img;type:varchar(200)"` // 产品图片
ProductType int64 `gorm:"column:product_type;type:smallint;default:1"` // 产品状态:1:开发中,2:审核中,3:已发布
AuthMode int64 `gorm:"column:auth_mode;type:smallint;default:1"` // 认证方式:1:账密认证,2:秘钥认证
DeviceType int64 `gorm:"column:device_type;index;type:smallint;default:1"` // 设备类型:1:设备,2:网关,3:子设备
CategoryID int64 `gorm:"column:category_id;type:integer;default:2"` // 产品品类 2:未分类
NetType int64 `gorm:"column:net_type;type:smallint;default:1"` // 通讯方式:1:其他,2:wi-fi,3:2G/3G/4G,4:5G,5:BLE,6:LoRaWAN
ProtocolCode string `gorm:"column:protocol_code;type:varchar(100);default:iThings"` // 协议code,默认iThings iThings,iThings-thingsboard,wumei,aliyun,huaweiyun,tuya
AutoRegister int64 `gorm:"column:auto_register;type:smallint;default:1"` // 动态注册:1:关闭,2:打开,3:打开并自动创建设备
DeviceSchemaMode int64 `gorm:"column:device_schema_mode;type:smallint;default:1"` // 设备物模型模式:1:关闭,2:设备自动创建3: 设备自动创建及上报无定义自动创建
IsCanCoverBindDevice int64 `gorm:"column:is_can_cover_bind_device;type:smallint;default:2"` // 是否可以覆盖绑定设备,默认为2
Secret string `gorm:"column:secret;type:varchar(50)"` // 动态注册产品秘钥
Desc string `gorm:"column:desc;type:varchar(200)"` // 描述
TrialTime int64 `gorm:"column:trial_time"` //试用时间(单位为天,为0不限制)
Status devices.ProductStatus `gorm:"column:status;type:smallint;default:1"`
SceneMode string `gorm:"column:scene_mode;type:varchar(20);default:rw"` // 场景模式 读写类型: r(只读) rw(可读可写) none(不参与场景)
Tags map[string]string `gorm:"column:tags;type:json;serializer:json;NOT NULL;default:'{}'"` // 产品标签
ProtocolConf map[string]string `gorm:"column:protocol_conf;type:json;serializer:json;NOT NULL;default:'{}'"` // 自定义协议配置
stores.NoDelTime
DeletedTime stores.DeletedTime `gorm:"column:deleted_time;uniqueIndex:pd"`
Category *DmProductCategory `gorm:"foreignKey:ID;references:CategoryID"` // 添加外键
Expand Down
Loading

0 comments on commit 528de36

Please sign in to comment.