materialsavelogic.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. "bp.jydev.jianyu360.cn/BaseService/biService/entity"
  5. IC "bp.jydev.jianyu360.cn/BaseService/biService/rpc/internal/config"
  6. "bp.jydev.jianyu360.cn/BaseService/biService/rpc/internal/svc"
  7. "bp.jydev.jianyu360.cn/BaseService/biService/rpc/pb"
  8. "bp.jydev.jianyu360.cn/BaseService/biService/service"
  9. fpb "bp.jydev.jianyu360.cn/BaseService/fileCenter/rpc/pb"
  10. "context"
  11. "fmt"
  12. "github.com/gogf/gf/v2/util/gconv"
  13. "github.com/zeromicro/go-zero/core/logx"
  14. "log"
  15. "path"
  16. "strings"
  17. )
  18. type MaterialSaveLogic struct {
  19. ctx context.Context
  20. svcCtx *svc.ServiceContext
  21. logx.Logger
  22. }
  23. func NewMaterialSaveLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MaterialSaveLogic {
  24. return &MaterialSaveLogic{
  25. ctx: ctx,
  26. svcCtx: svcCtx,
  27. Logger: logx.WithContext(ctx),
  28. }
  29. }
  30. func (l *MaterialSaveLogic) MaterialSave(in *pb.MaterialSaveReq) (*pb.MaterialSaveResp, error) {
  31. // todo: add your logic here and delete this line
  32. //先插入消息记录表
  33. msgId, mid, err := service.MaterialSave(in, IC.IC.MaterialMsg.Title, fmt.Sprintf(IC.IC.MaterialMsg.Content, in.CreateUser))
  34. if msgId == 0 || err != nil {
  35. return &pb.MaterialSaveResp{
  36. ErrorCode: -1,
  37. ErrorMsg: err.Error(),
  38. }, nil
  39. }
  40. //获取分发人的userid
  41. userIdArr := service.GetSendUserId(in.ReceiveUserId, in.EntId)
  42. if in.QrcodeUrl == "" {
  43. return &pb.MaterialSaveResp{
  44. ErrorCode: 1,
  45. ErrorMsg: "",
  46. MsgId: msgId,
  47. MaterialId: mid,
  48. UserIdArr: userIdArr,
  49. }, nil
  50. }
  51. positionArr := strings.Split(in.ReceiveUserId, ",")
  52. userIdMap := service.GetUserIds(in.ReceiveUserId)
  53. for k, v := range strings.Split(in.ReceiveUserName, ",") {
  54. if len(strings.Split(in.FileUrl, ",")) == 0 {
  55. break
  56. }
  57. personCode := service.GetPersonCode(gconv.Int64(positionArr[k]), v, userIdMap[common.IntAll(positionArr[k])])
  58. qrcodeUrl := fmt.Sprintf("%s/material/%d/%s?tp=material", IC.IC.JyWebDomain, mid, personCode)
  59. //log.Println("二维码链接", qrcodeUrl)
  60. for _, val := range strings.Split(in.FileUrl, ",") {
  61. go func(fileUrl, name string, positionId int64) {
  62. err, imgByte := service.CompositeImage(fileUrl, qrcodeUrl)
  63. if err != nil {
  64. log.Println("合成图片出错:", positionId, fileUrl, err)
  65. return
  66. }
  67. up, err := entity.FileCenterRpc.Upload(context.Background(), &fpb.UploadReq{
  68. File: imgByte,
  69. OssBucketName: entity.OssBucketName,
  70. OssUrl: entity.OssUrl,
  71. Name: path.Base(fileUrl),
  72. NeedEncryption: false,
  73. })
  74. if up == nil || up.Url == "" {
  75. log.Println("上传合成图片失败:", positionId, err)
  76. return
  77. }
  78. ok := service.PersonImageSave(up.Url, msgId, positionId, mid)
  79. if !ok {
  80. log.Println("合成图片存库失败", positionId, mid)
  81. return
  82. }
  83. }(val, v, gconv.Int64(positionArr[k]))
  84. }
  85. }
  86. return &pb.MaterialSaveResp{
  87. ErrorCode: 1,
  88. ErrorMsg: "",
  89. MsgId: msgId,
  90. MaterialId: mid,
  91. UserIdArr: userIdArr,
  92. }, nil
  93. }