package logic import ( "app.yhyue.com/moapp/jybase/common" "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(), }, nil } //获取分发人的userid userIdArr, userIdMap := service.GetSendUserId(in.ReceiveUserId, in.EntId) positionArr := strings.Split(in.ReceiveUserId, ",") //userIdMap := service.GetUserIds(in.ReceiveUserId) //log.Println("userIdMap", userIdMap) for k, v := range strings.Split(in.ReceiveUserName, ",") { personCode := service.GetPersonCode(gconv.Int64(positionArr[k]), v, userIdMap[common.IntAll(positionArr[k])]) if len(strings.Split(in.FileUrl, ",")) == 0 { continue } if in.QrcodeUrl == "" { continue } qrcodeUrl := fmt.Sprintf("%s/material/%d/%s?tp=material", IC.IC.JyWebDomain, mid, personCode) //log.Println("二维码链接", qrcodeUrl) for _, val := range strings.Split(in.FileUrl, ",") { go func(fileUrl, name string, positionId int64) { err, imgByte := service.CompositeImage(fileUrl, qrcodeUrl) if err != nil { log.Println("合成图片出错:", positionId, fileUrl, err) return } up, err := entity.FileCenterRpc.Upload(context.Background(), &fpb.UploadReq{ File: imgByte, OssBucketName: entity.OssBucketName, OssUrl: entity.OssUrl, Name: path.Base(fileUrl), NeedEncryption: false, }) if up == nil || up.Url == "" { log.Println("上传合成图片失败:", positionId, err) return } ok := service.PersonImageSave(up.Url, msgId, positionId, mid) if !ok { log.Println("合成图片存库失败", positionId, mid) return } }(val, v, gconv.Int64(positionArr[k])) } } return &pb.MaterialSaveResp{ ErrorCode: 1, ErrorMsg: "", MsgId: msgId, MaterialId: mid, UserIdArr: userIdArr, }, nil }