Skip to content

Commit

Permalink
增加部分接口
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiahai committed Nov 28, 2023
1 parent 91bc5d2 commit f048cae
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 8 deletions.
9 changes: 9 additions & 0 deletions api/v1/product/tsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,12 @@ type DelTSLTagReq struct {
*model.DelTSLTagInput
}
type DelTSLTagRes struct{}

type AllTSLFunctionReq struct {
g.Meta `path:"/tsl/function/all" method:"get" summary:"所有功能列表" tags:"物模型"`
Key string `json:"key" dc:"产品标识" v:"required#产品标识不能为空"`
InputsValueTypes string `json:"inputsValueTypes" dc:"参数值类型"`
}
type AllTSLFunctionRes struct {
Data []model.TSLFunction
}
17 changes: 17 additions & 0 deletions api/v1/system/sys_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,20 @@ type EditUserAvatarReq struct {

type EditUserAvatarRes struct {
}

type EditUserInfoReq struct {
g.Meta `path:"/user/editUserInfo" tags:"用户管理" method:"put" summary:"修改用户个人资料"`
Id uint `json:"id" description:"Id" v:"required#ID不能为空"`
Mobile string `json:"mobile" description:"中国手机不带国家代码,国际手机号格式为:国家代码-手机号"`
UserNickname string `json:"userNickname" description:"用户昵称"`
Birthday string `json:"birthday" description:"生日"`
UserPassword string `json:"userPassword" description:"登录密码;cmf_password加密"`
UserEmail string `json:"userEmail" description:"用户登录邮箱"`
Sex int `json:"sex" description:"性别;0:保密,1:男,2:女"`
Avatar string `json:"avatar" description:"用户头像"`
Address string `json:"address" description:"联系地址"`
Describe string `json:"describe" description:"描述信息"`
}

type EditUserInfoRes struct {
}
8 changes: 8 additions & 0 deletions internal/controller/product/tsl_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ func (c *cTSLFunction) ListFunction(ctx context.Context, req *product.ListTSLFun
return
}

func (c *cTSLFunction) AllFunction(ctx context.Context, req *product.AllTSLFunctionReq) (res *product.AllTSLFunctionRes, err error) {
list, err := service.DevTSLFunction().AllFunction(ctx, req.Key, req.InputsValueTypes)
res = &product.AllTSLFunctionRes{
Data: list,
}
return
}

func (c *cTSLFunction) AddFunction(ctx context.Context, req *product.AddTSLFunctionReq) (res *product.AddTSLFunctionRes, err error) {
err = service.DevTSLFunction().AddFunction(ctx, req.TSLFunctionAddInput)
return
Expand Down
10 changes: 10 additions & 0 deletions internal/controller/system/sys_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,13 @@ func (u *cSysUser) EditUserAvatar(ctx context.Context, req *system.EditUserAvata
err = service.SysUser().EditUserAvatar(ctx, req.Id, req.Avatar)
return
}

// EditUserInfo 修改用户个人资料
func (c *cSysUser) EditUserInfo(ctx context.Context, req *system.EditUserInfoReq) (res *system.EditUserInfoRes, err error) {
var input *model.EditUserInfoInput
if err = gconv.Scan(req, &input); err != nil {
return
}
err = service.SysUser().EditUserInfo(ctx, input)
return
}
40 changes: 40 additions & 0 deletions internal/logic/product/dev_tsl_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/sagoo-cloud/sagooiot/internal/model/entity"
"github.com/sagoo-cloud/sagooiot/internal/service"
"math"
"strings"

"github.com/gogf/gf/v2/encoding/gjson"
"github.com/gogf/gf/v2/errors/gerror"
Expand Down Expand Up @@ -66,6 +67,45 @@ func (s *sDevTSLFunction) ListFunction(ctx context.Context, in *model.ListTSLFun
return
}

func (s *sDevTSLFunction) AllFunction(ctx context.Context, key string, inputsValueTypes string) (list []model.TSLFunction, err error) {
var p *entity.DevProduct

err = dao.DevProduct.Ctx(ctx).Where(dao.DevProduct.Columns().Key, key).Scan(&p)
if err != nil {
return
}
if p == nil {
return nil, gerror.New("产品不存在")
}

j, err := gjson.DecodeToJson(p.Metadata)
if err != nil {
return
}
tsl := new(model.TSL)
if err = j.Scan(tsl); err != nil {
return
}
if inputsValueTypes != "" {
for _, function := range tsl.Functions {
num := 0
flag := false
for _, input := range function.Inputs {
if strings.EqualFold(input.ValueType.Type, inputsValueTypes) {
flag = true
num++
}
}
if flag && num == 1 {
list = append(list, function)
}
}
} else {
list = tsl.Functions
}
return
}

func (s *sDevTSLFunction) AddFunction(ctx context.Context, in *model.TSLFunctionAddInput) (err error) {
var p *entity.DevProduct

Expand Down
52 changes: 47 additions & 5 deletions internal/logic/system/sys_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,15 @@ func (s *sSysUser) Edit(ctx context.Context, input *model.EditUserInput) (err er
sysUser.Status = input.Status
sysUser.Address = input.Address
sysUser.Avatar = input.Avatar
sysUser.Birthday = input.Birthday
sysUser.Birthday = gtime.NewFromStrFormat(input.Birthday, "Y-m-d")
sysUser.Describe = input.Describe
sysUser.UserTypes = input.UserTypes
sysUser.UserEmail = input.UserEmail
sysUser.Sex = input.Sex
sysUser.IsAdmin = input.IsAdmin
//获取当前登录用户ID
loginUserId := service.Context().GetUserId(ctx)
sysUser.UpdateBy = uint(loginUserId)
sysUser.UpdatedBy = uint(loginUserId)
//编辑用户信息
_, err = dao.SysUser.Ctx(ctx).Data(sysUser).Where(dao.SysUser.Columns().Id, input.Id).Update()
if err != nil {
Expand Down Expand Up @@ -454,7 +454,7 @@ func (s *sSysUser) ResetPassword(ctx context.Context, id uint, userPassword stri

sysUser.UserSalt = grand.S(10)
sysUser.UserPassword = utils.EncryptPassword(userPassword, sysUser.UserSalt)
sysUser.UpdateBy = uint(loginUserId)
sysUser.UpdatedBy = uint(loginUserId)
_, err = dao.SysUser.Ctx(ctx).Data(sysUser).Where(g.Map{
dao.SysUser.Columns().Id: id,
}).Update()
Expand All @@ -480,7 +480,7 @@ func (s *sSysUser) EditUserStatus(ctx context.Context, id uint, status uint) (er
//获取当前登录用户ID
loginUserId := service.Context().GetUserId(ctx)
sysUser.Status = status
sysUser.UpdateBy = uint(loginUserId)
sysUser.UpdatedBy = uint(loginUserId)
_, err = dao.SysUser.Ctx(ctx).Data(sysUser).Where(g.Map{
dao.SysUser.Columns().Id: id,
}).Update()
Expand Down Expand Up @@ -738,7 +738,7 @@ func (s *sSysUser) EditUserAvatar(ctx context.Context, id uint, avatar string) (
sysUser.Avatar = avatar
//获取当前登录用户ID
loginUserId := service.Context().GetUserId(ctx)
sysUser.UpdateBy = uint(loginUserId)
sysUser.UpdatedBy = uint(loginUserId)
_, err = dao.SysUser.Ctx(ctx).Data(sysUser).Where(g.Map{
dao.SysUser.Columns().Id: id,
}).Update()
Expand All @@ -747,3 +747,45 @@ func (s *sSysUser) EditUserAvatar(ctx context.Context, id uint, avatar string) (
}
return
}

// EditUserInfo 修改用户个人资料
func (s *sSysUser) EditUserInfo(ctx context.Context, input *model.EditUserInfoInput) (err error) {
var sysUser *entity.SysUser
err = dao.SysUser.Ctx(ctx).Where(g.Map{
dao.SysUser.Columns().Id: input.Id,
}).Scan(&sysUser)
if sysUser == nil {
err = gerror.New("ID错误")
return
}

//获取当前登录用户ID
loginUserId := service.Context().GetUserId(ctx)

//判断是否为当前用户
if input.Id != uint64(loginUserId) {
err = gerror.New("无法修改其他用户资料")
return
}
sysUser.Mobile = input.Mobile
sysUser.UserNickname = input.UserNickname
sysUser.Birthday = gtime.NewFromStrFormat(input.Birthday, "Y-m-d")
if input.UserPassword != "" {
sysUser.UserPassword = utils.EncryptPassword(input.UserPassword, sysUser.UserSalt)
}
sysUser.UserEmail = input.UserEmail
sysUser.Sex = input.Sex
sysUser.Avatar = input.Avatar
sysUser.Address = input.Address
sysUser.Describe = input.Describe
//获取当前登录用户ID
sysUser.UpdatedBy = uint(loginUserId)
sysUser.UpdatedAt = gtime.Now()
_, err = dao.SysUser.Ctx(ctx).Data(sysUser).Where(g.Map{
dao.SysUser.Columns().Id: input.Id,
}).Update()
if err != nil {
return gerror.New("修改个人资料失败")
}
return
}
4 changes: 2 additions & 2 deletions internal/model/entity/sys_user.go

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

15 changes: 14 additions & 1 deletion internal/model/sys_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ type EditUserInput struct {
UserTypes string `json:"userTypes" description:"系统 system 企业 company"`
Mobile string `json:"mobile" description:"中国手机不带国家代码,国际手机号格式为:国家代码-手机号" v:"required#手机号不能为空"`
UserNickname string `json:"userNickname" description:"用户昵称" v:"required#用户昵称不能为空"`
Birthday int `json:"birthday" description:"生日"`
Birthday string `json:"birthday" description:"生日"`
UserEmail string `json:"userEmail" description:"用户登录邮箱"`
Sex int `json:"sex" description:"性别;0:保密,1:男,2:女"`
Avatar string `json:"avatar" description:"用户头像"`
Expand Down Expand Up @@ -192,3 +192,16 @@ type UserInfoOut struct {
RoleIds []int `json:"roleIds" description:"角色ID数组" v:"required#角色不能为空"`
PostIds []int `json:"postIds" description:"岗位ID数组" v:"required#岗位不能为空"`
}

type EditUserInfoInput struct {
Id uint64 `json:"id" description:""`
Mobile string `json:"mobile" description:"中国手机不带国家代码,国际手机号格式为:国家代码-手机号"`
UserNickname string `json:"userNickname" description:"用户昵称"`
Birthday string `json:"birthday" description:"生日"`
UserPassword string `json:"userPassword" description:"登录密码;cmf_password加密"`
UserEmail string `json:"userEmail" description:"用户登录邮箱"`
Sex int `json:"sex" description:"性别;0:保密,1:男,2:女"`
Avatar string `json:"avatar" description:"用户头像"`
Address string `json:"address" description:"联系地址"`
Describe string `json:"describe" description:"描述信息"`
}
1 change: 1 addition & 0 deletions internal/service/product.go

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

1 change: 1 addition & 0 deletions internal/service/system.go

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

0 comments on commit f048cae

Please sign in to comment.