materialsavelogic.go 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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, userIdMap := service.GetSendUserId(in.ReceiveUserId, in.EntId)
  42. positionArr := strings.Split(in.ReceiveUserId, ",")
  43. //userIdMap := service.GetUserIds(in.ReceiveUserId)
  44. //log.Println("userIdMap", userIdMap)
  45. for k, v := range strings.Split(in.ReceiveUserName, ",") {
  46. personCode := service.GetPersonCode(gconv.Int64(positionArr[k]), v, userIdMap[common.IntAll(positionArr[k])])
  47. if len(strings.Split(in.FileUrl, ",")) == 0 {
  48. continue
  49. }
  50. if in.QrcodeUrl == "" {
  51. continue
  52. }
  53. qrcodeUrl := fmt.Sprintf("%s/material/%d/%s?tp=material", IC.IC.JyWebDomain, mid, personCode)
  54. //log.Println("二维码链接", qrcodeUrl)
  55. for _, val := range strings.Split(in.FileUrl, ",") {
  56. go func(fileUrl, name string, positionId int64) {
  57. err, imgByte := service.CompositeImage(fileUrl, qrcodeUrl)
  58. if err != nil {
  59. log.Println("合成图片出错:", positionId, fileUrl, err)
  60. return
  61. }
  62. up, err := entity.FileCenterRpc.Upload(context.Background(), &fpb.UploadReq{
  63. File: imgByte,
  64. OssBucketName: entity.OssBucketName,
  65. OssUrl: entity.OssUrl,
  66. Name: path.Base(fileUrl),
  67. NeedEncryption: false,
  68. })
  69. if up == nil || up.Url == "" {
  70. log.Println("上传合成图片失败:", positionId, err)
  71. return
  72. }
  73. ok := service.PersonImageSave(up.Url, msgId, positionId, mid)
  74. if !ok {
  75. log.Println("合成图片存库失败", positionId, mid)
  76. return
  77. }
  78. }(val, v, gconv.Int64(positionArr[k]))
  79. }
  80. }
  81. return &pb.MaterialSaveResp{
  82. ErrorCode: 1,
  83. ErrorMsg: "",
  84. MsgId: msgId,
  85. MaterialId: mid,
  86. UserIdArr: userIdArr,
  87. }, nil
  88. }