materialsavelogic.go 2.8 KB

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