2 Star 2 Fork 4

联犀/core

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
projectInfoUpdateLogic.go 3.20 KB
一键复制 编辑 原始数据 按行查看 历史
杨磊 提交于 2024-10-10 21:56 . feat: 更新mod
package projectmanagelogic
import (
"context"
"fmt"
"gitee.com/unitedrhino/core/service/syssvr/internal/logic"
"gitee.com/unitedrhino/core/service/syssvr/internal/repo/relationDB"
"gitee.com/unitedrhino/core/service/syssvr/pb/sys"
"gitee.com/unitedrhino/share/ctxs"
"gitee.com/unitedrhino/share/def"
"gitee.com/unitedrhino/share/errors"
"gitee.com/unitedrhino/share/oss"
"gitee.com/unitedrhino/share/oss/common"
"gitee.com/unitedrhino/core/service/syssvr/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type ProjectInfoUpdateLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
PiDB *relationDB.ProjectInfoRepo
}
func NewProjectInfoUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProjectInfoUpdateLogic {
return &ProjectInfoUpdateLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
PiDB: relationDB.NewProjectInfoRepo(ctx),
}
}
// 更新项目
func (l *ProjectInfoUpdateLogic) ProjectInfoUpdate(in *sys.ProjectInfo) (*sys.Empty, error) {
uc := ctxs.GetUserCtx(l.ctx)
uc.AllProject = true
defer func() {
uc.AllProject = false
}()
if in.ProjectID == 0 {
if uc.ProjectID <= def.NotClassified {
return nil, errors.Parameter
}
in.ProjectID = uc.ProjectID
}
po, err := checkProject(l.ctx, in.ProjectID)
if err != nil {
return nil, errors.Fmt(err).WithMsg("检查项目出错")
} else if po == nil {
return nil, errors.Parameter.AddDetail(in.ProjectID).WithMsg("检查项目不存在")
}
l.setPoByPb(po, in)
err = l.PiDB.Update(l.ctx, po)
if err != nil {
return nil, err
}
err = l.svcCtx.ProjectCache.SetData(l.ctx, in.ProjectID, nil)
if err != nil {
l.Error(err)
}
return &sys.Empty{}, nil
}
func (l *ProjectInfoUpdateLogic) setPoByPb(po *relationDB.SysProjectInfo, pb *sys.ProjectInfo) {
if pb.ProjectName != "" {
po.ProjectName = pb.ProjectName
}
//if pb.CompanyName != nil {
// po.CompanyName = pb.CompanyName.GetValue()
//}
uc := ctxs.GetUserCtxNoNil(l.ctx)
if uc.IsAdmin {
if pb.DeviceCount != nil {
po.DeviceCount = pb.DeviceCount.Value
}
}
if pb.AdminUserID != 0 && pb.AdminUserID != po.AdminUserID {
uc := ctxs.GetUserCtx(l.ctx)
if uc.UserID == po.AdminUserID { //只有项目的管理员才有权限更换
po.AdminUserID = pb.AdminUserID
}
}
if pb.Position != nil {
po.Position = logic.ToStorePoint(pb.Position)
}
if pb.Area != nil {
po.Area = pb.Area.GetValue()
}
if pb.Ppsm != 0 {
po.Ppsm = pb.Ppsm
}
//if pb.Region != nil {
// po.Region = pb.Region.GetValue()
//}
if pb.Address != nil {
po.Address = pb.Address.GetValue()
}
if pb.IsUpdateProjectImg && pb.ProjectImg != "" {
if po.ProjectImg != "" {
err := l.svcCtx.OssClient.PrivateBucket().Delete(l.ctx, po.ProjectImg, common.OptionKv{})
if err != nil {
l.Errorf("Delete file err path:%v,err:%v", po.ProjectImg, err)
}
}
nwePath := oss.GenFilePath(l.ctx, l.svcCtx.Config.Name, oss.BusinessProject, oss.SceneHeadIng,
fmt.Sprintf("%d/%s", pb.ProjectID, oss.GetFileNameWithPath(pb.ProjectImg)))
path, err := l.svcCtx.OssClient.PrivateBucket().CopyFromTempBucket(pb.ProjectImg, nwePath)
if err != nil {
l.Error(err)
} else {
po.ProjectImg = path
}
}
if pb.Desc != nil {
po.Desc = pb.Desc.GetValue()
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/unitedrhino/core.git
git@gitee.com:unitedrhino/core.git
unitedrhino
core
core
v1.0.1

搜索帮助

0d507c66 1850385 C8b1a773 1850385