2 Star 0 Fork 0

广东宇凌网络科技有限公司/simple-iot-basic-rpc

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
create_device_prop_logic.go 1.17 KB
一键复制 编辑 原始数据 按行查看 历史
HienGee 提交于 2024-05-15 11:16 . 修复多语言
package device_prop
import (
"context"
"github.com/suyuan32/simple-admin-common/i18n"
"gitee.com/yuLingNet/simple-iot-basic-rpc/internal/svc"
"gitee.com/yuLingNet/simple-iot-basic-rpc/internal/utils/dberrorhandler"
"gitee.com/yuLingNet/simple-iot-basic-rpc/types/basic"
"github.com/suyuan32/simple-admin-common/utils/pointy"
"github.com/zeromicro/go-zero/core/logx"
)
type CreateDevicePropLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewCreateDevicePropLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateDevicePropLogic {
return &CreateDevicePropLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *CreateDevicePropLogic) CreateDeviceProp(in *basic.DevicePropInfo) (*basic.BaseIDResp, error) {
query := l.svcCtx.DB.DeviceProp.Create().
SetNotNilSort(in.Sort).
SetNotNilIotID(in.IotID).
SetNotNilProps(in.Props)
if in.Status != nil {
query.SetNotNilStatus(pointy.GetPointer(uint8(*in.Status)))
}
result, err := query.Save(l.ctx)
if err != nil {
return nil, dberrorhandler.DefaultEntError(l.Logger, err, in)
}
return &basic.BaseIDResp{Id: result.ID, Msg: i18n.CreateSuccess}, nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/yuLingNet/simple-iot-basic-rpc.git
git@gitee.com:yuLingNet/simple-iot-basic-rpc.git
yuLingNet
simple-iot-basic-rpc
simple-iot-basic-rpc
ca5a4cf0cee7

搜索帮助