materialsavelogic.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. log.Println("物料分发给:", userIdArr)
  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. for k, v := range strings.Split(in.ReceiveUserName, ",") {
  53. if len(strings.Split(in.FileUrl, ",")) == 0 {
  54. break
  55. }
  56. for _, val := range strings.Split(in.FileUrl, ",") {
  57. go func(fileUrl, name string, positionId int64) {
  58. imgByte, err := service.PersonImgSaveComposite(fileUrl, in.QrcodeUrl, name, positionId)
  59. if err != nil {
  60. log.Println("合成图片出错:", err)
  61. return
  62. }
  63. up, err := entity.FileCenterRpc.Upload(l.ctx, &fpb.UploadReq{
  64. File: imgByte,
  65. OssBucketName: entity.OssBucketName,
  66. OssUrl: entity.OssUrl,
  67. Name: path.Base(in.FileUrl),
  68. NeedEncryption: false,
  69. })
  70. if up == nil || up.Url == "" {
  71. log.Println("上传合成图片失败:", err)
  72. return
  73. }
  74. //key := up.Key
  75. //ossAddr = gconv.String(Ret["downUrl"])
  76. /*log.Println("url", up.Url)
  77. fileName := filepath.Base(up.Url)
  78. downUrl := fmt.Sprintf("%s/jyoss/ml/attachment/%s", IC.IC.JyWebDomain, fileName)
  79. log.Println("downUrl:", downUrl)*/
  80. ok := service.PersonImageSave(up.Url, msgId, positionId, mid)
  81. if !ok {
  82. log.Println("合成图片存库失败")
  83. return
  84. }
  85. }(val, v, gconv.Int64(positionArr[k]))
  86. }
  87. }
  88. return &pb.MaterialSaveResp{
  89. ErrorCode: 1,
  90. ErrorMsg: "",
  91. MsgId: msgId,
  92. MaterialId: mid,
  93. UserIdArr: userIdArr,
  94. }, nil
  95. }