package logic import ( "bp.jydev.jianyu360.cn/BaseService/biService/entity" IC "bp.jydev.jianyu360.cn/BaseService/biService/rpc/internal/config" "bp.jydev.jianyu360.cn/BaseService/biService/rpc/internal/svc" "bp.jydev.jianyu360.cn/BaseService/biService/rpc/pb" "bp.jydev.jianyu360.cn/BaseService/biService/service" fpb "bp.jydev.jianyu360.cn/BaseService/fileCenter/rpc/pb" "context" "fmt" "github.com/gogf/gf/v2/util/gconv" "github.com/zeromicro/go-zero/core/logx" "log" "path" "strings" ) type MaterialSaveLogic struct { ctx context.Context svcCtx *svc.ServiceContext logx.Logger } func NewMaterialSaveLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MaterialSaveLogic { return &MaterialSaveLogic{ ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx), } } func (l *MaterialSaveLogic) MaterialSave(in *pb.MaterialSaveReq) (*pb.MaterialSaveResp, error) { // todo: add your logic here and delete this line //先插入消息记录表 msgId, mid, err := service.MaterialSave(in, IC.IC.MaterialMsg.Title, fmt.Sprintf(IC.IC.MaterialMsg.Content, in.CreateUser)) if msgId == 0 || err != nil { return &pb.MaterialSaveResp{ ErrorCode: -1, ErrorMsg: err.Error(), MsgId: msgId, }, nil } //获取分发人的userid userIdArr := service.GetSendUserId(in.ReceiveUserId, in.EntId) log.Println("分发给:", userIdArr) if len(strings.Split(in.FileUrl, ",")) > 0 { positionArr := strings.Split(in.ReceiveUserId, ",") for k, v := range strings.Split(in.ReceiveUserName, ",") { for _, val := range strings.Split(in.FileUrl, ",") { imgByte, err := service.PersonImgSaveComposite(val, in.QrcodeUrl, v) if err != nil { return &pb.MaterialSaveResp{ ErrorCode: -1, ErrorMsg: "", }, nil } up, err := entity.FileCenterRpc.Upload(l.ctx, &fpb.UploadReq{ File: imgByte, OssBucketName: entity.OssBucketName, OssUrl: entity.OssUrl, Name: path.Base(in.FileUrl), NeedEncryption: false, }) if up == nil || up.Url == "" { return &pb.MaterialSaveResp{ ErrorCode: -1, ErrorMsg: "", }, nil } //key := up.Key ok := service.PersonImageSave(fmt.Sprintf("%s/%s", entity.OssUrl, up.Url), msgId, gconv.Int64(positionArr[k]), mid) if !ok { return &pb.MaterialSaveResp{ ErrorCode: -1, ErrorMsg: "", }, nil } } } } return &pb.MaterialSaveResp{ ErrorCode: 1, ErrorMsg: "", MsgId: msgId, MaterialId: mid, UserIdArr: userIdArr, }, nil }