materialsavelogic.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. personCode := service.GetPersonCode(gconv.Int64(positionArr[k]))
  57. for _, val := range strings.Split(in.FileUrl, ",") {
  58. go func(fileUrl, name string, positionId int64) {
  59. imgByte, err := service.PersonImgSaveComposite(fileUrl, in.QrcodeUrl, name, personCode, positionId)
  60. log.Println(imgByte)
  61. if err != nil {
  62. log.Println("合成图片出错:", err)
  63. return
  64. }
  65. log.Println("图片名称", path.Base(fileUrl))
  66. up, err := entity.FileCenterRpc.Upload(context.Background(), &fpb.UploadReq{
  67. File: imgByte,
  68. OssBucketName: entity.OssBucketName,
  69. OssUrl: entity.OssUrl,
  70. Name: path.Base(fileUrl),
  71. NeedEncryption: false,
  72. })
  73. //log.Println(err)
  74. if up == nil || up.Url == "" {
  75. log.Println("上传合成图片失败:", err)
  76. return
  77. }
  78. ok := service.PersonImageSave(up.Url, msgId, positionId, mid)
  79. if !ok {
  80. log.Println("合成图片存库失败")
  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. }