materialsavelogic.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. imgByte, err := service.PersonImgSaveComposite(val, in.QrcodeUrl, v)
  58. if err != nil {
  59. return &pb.MaterialSaveResp{
  60. ErrorCode: -1,
  61. ErrorMsg: "",
  62. }, nil
  63. }
  64. up, err := entity.FileCenterRpc.Upload(l.ctx, &fpb.UploadReq{
  65. File: imgByte,
  66. OssBucketName: entity.OssBucketName,
  67. OssUrl: entity.OssUrl,
  68. Name: path.Base(in.FileUrl),
  69. NeedEncryption: false,
  70. })
  71. if up == nil || up.Url == "" {
  72. return &pb.MaterialSaveResp{
  73. ErrorCode: -1,
  74. ErrorMsg: "",
  75. }, nil
  76. }
  77. //key := up.Key
  78. //ossAddr = gconv.String(Ret["downUrl"])
  79. //log.Println("url", up.Url)
  80. //fileName := filepath.Base(up.Url)
  81. //downUrl := fmt.Sprintf("%s/jyoss/ml/attachment/%s", IC.IC.JyWebDomain, fileName)
  82. //log.Println("downUrl:", downUrl)
  83. ok := service.PersonImageSave(up.Url, msgId, gconv.Int64(positionArr[k]), mid)
  84. if !ok {
  85. return &pb.MaterialSaveResp{
  86. ErrorCode: -1,
  87. ErrorMsg: "",
  88. }, nil
  89. }
  90. }
  91. }
  92. return &pb.MaterialSaveResp{
  93. ErrorCode: 1,
  94. ErrorMsg: "",
  95. MsgId: msgId,
  96. MaterialId: mid,
  97. UserIdArr: userIdArr,
  98. }, nil
  99. }