From f048cae2c9d46e6092474610e5871691e1272de0 Mon Sep 17 00:00:00 2001 From: Xiahai Date: Tue, 28 Nov 2023 08:53:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=83=A8=E5=88=86=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/v1/product/tsl.go | 9 ++++ api/v1/system/sys_user.go | 17 +++++++ internal/controller/product/tsl_function.go | 8 ++++ internal/controller/system/sys_user.go | 10 ++++ internal/logic/product/dev_tsl_function.go | 40 ++++++++++++++++ internal/logic/system/sys_user.go | 52 +++++++++++++++++++-- internal/model/entity/sys_user.go | 4 +- internal/model/sys_user.go | 15 +++++- internal/service/product.go | 1 + internal/service/system.go | 1 + 10 files changed, 149 insertions(+), 8 deletions(-) diff --git a/api/v1/product/tsl.go b/api/v1/product/tsl.go index 268202d..696418b 100644 --- a/api/v1/product/tsl.go +++ b/api/v1/product/tsl.go @@ -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 +} diff --git a/api/v1/system/sys_user.go b/api/v1/system/sys_user.go index b154d6d..47680e5 100644 --- a/api/v1/system/sys_user.go +++ b/api/v1/system/sys_user.go @@ -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 { +} diff --git a/internal/controller/product/tsl_function.go b/internal/controller/product/tsl_function.go index fbdb879..40bd2f1 100644 --- a/internal/controller/product/tsl_function.go +++ b/internal/controller/product/tsl_function.go @@ -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 diff --git a/internal/controller/system/sys_user.go b/internal/controller/system/sys_user.go index 9174df4..9968597 100644 --- a/internal/controller/system/sys_user.go +++ b/internal/controller/system/sys_user.go @@ -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 +} diff --git a/internal/logic/product/dev_tsl_function.go b/internal/logic/product/dev_tsl_function.go index 37af010..2360885 100644 --- a/internal/logic/product/dev_tsl_function.go +++ b/internal/logic/product/dev_tsl_function.go @@ -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" @@ -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 diff --git a/internal/logic/system/sys_user.go b/internal/logic/system/sys_user.go index a7da2ef..5422f3b 100644 --- a/internal/logic/system/sys_user.go +++ b/internal/logic/system/sys_user.go @@ -254,7 +254,7 @@ 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 @@ -262,7 +262,7 @@ func (s *sSysUser) Edit(ctx context.Context, input *model.EditUserInput) (err er 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 { @@ -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() @@ -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() @@ -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() @@ -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 +} diff --git a/internal/model/entity/sys_user.go b/internal/model/entity/sys_user.go index ce3c249..ba42662 100644 --- a/internal/model/entity/sys_user.go +++ b/internal/model/entity/sys_user.go @@ -15,7 +15,7 @@ type SysUser struct { UserTypes string `json:"userTypes" description:"系统 system 企业 company"` Mobile string `json:"mobile" description:"中国手机不带国家代码,国际手机号格式为:国家代码-手机号"` UserNickname string `json:"userNickname" description:"用户昵称"` - Birthday int `json:"birthday" description:"生日"` + Birthday *gtime.Time `json:"birthday" description:"生日"` UserPassword string `json:"userPassword" description:"登录密码;cmf_password加密"` UserSalt string `json:"userSalt" description:"加密盐"` UserEmail string `json:"userEmail" description:"用户登录邮箱"` @@ -32,7 +32,7 @@ type SysUser struct { IsDeleted int `json:"isDeleted" description:"是否删除 0未删除 1已删除"` CreateBy uint `json:"createBy" description:"创建者"` CreatedAt *gtime.Time `json:"createdAt" description:"创建日期"` - UpdateBy uint `json:"updateBy" description:"更新者"` + UpdatedBy uint `json:"updatedBy" description:"更新者"` UpdatedAt *gtime.Time `json:"updatedAt" description:"修改日期"` DeletedBy int `json:"deletedBy" description:"删除人"` DeletedAt *gtime.Time `json:"deletedAt" description:"删除时间"` diff --git a/internal/model/sys_user.go b/internal/model/sys_user.go index 5a4327c..5a321bb 100644 --- a/internal/model/sys_user.go +++ b/internal/model/sys_user.go @@ -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:"用户头像"` @@ -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:"描述信息"` +} diff --git a/internal/service/product.go b/internal/service/product.go index 4d6abe2..4fd6af9 100644 --- a/internal/service/product.go +++ b/internal/service/product.go @@ -63,6 +63,7 @@ type ( } IDevTSLFunction interface { ListFunction(ctx context.Context, in *model.ListTSLFunctionInput) (out *model.ListTSLFunctionOutput, err error) + AllFunction(ctx context.Context, key string, inputsValueTypes string) (list []model.TSLFunction, err error) AddFunction(ctx context.Context, in *model.TSLFunctionAddInput) (err error) EditFunction(ctx context.Context, in *model.TSLFunctionAddInput) (err error) DelFunction(ctx context.Context, in *model.DelTSLFunctionInput) (err error) diff --git a/internal/service/system.go b/internal/service/system.go index 6610378..0a33660 100644 --- a/internal/service/system.go +++ b/internal/service/system.go @@ -164,6 +164,7 @@ type ( GetAll(ctx context.Context) (data []*entity.SysUser, err error) CurrentUser(ctx context.Context) (userInfoOut *model.UserInfoOut, menuTreeOut []*model.UserMenuTreeOut, err error) EditUserAvatar(ctx context.Context, id uint, avatar string) (err error) + EditUserInfo(ctx context.Context, input *model.EditUserInfoInput) (err error) } ISysAuthorize interface { AuthorizeQuery(ctx context.Context, itemsType string, menuIds []int) (out []*model.AuthorizeQueryTreeOut, err error)