materialsavelogic.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. MsgId: msgId,
  38. }, nil
  39. }
  40. //获取分发人的userid
  41. userIdArr := service.GetSendUserId(in.ReceiveUserId, in.EntId)
  42. log.Println("分发给:", userIdArr)
  43. if len(strings.Split(in.FileUrl, ",")) > 0 {
  44. positionArr := strings.Split(in.ReceiveUserId, ",")
  45. for k, v := range strings.Split(in.ReceiveUserName, ",") {
  46. for _, val := range strings.Split(in.FileUrl, ",") {
  47. imgByte, err := service.PersonImgSaveComposite(val, in.QrcodeUrl, v)
  48. if err != nil {
  49. return &pb.MaterialSaveResp{
  50. ErrorCode: -1,
  51. ErrorMsg: "",
  52. }, nil
  53. }
  54. up, err := entity.FileCenterRpc.Upload(l.ctx, &fpb.UploadReq{
  55. File: imgByte,
  56. OssBucketName: entity.OssBucketName,
  57. OssUrl: entity.OssUrl,
  58. Name: path.Base(in.FileUrl),
  59. NeedEncryption: false,
  60. })
  61. if up == nil || up.Url == "" {
  62. return &pb.MaterialSaveResp{
  63. ErrorCode: -1,
  64. ErrorMsg: "",
  65. }, nil
  66. }
  67. //key := up.Key
  68. ok := service.PersonImageSave(fmt.Sprintf("%s/%s", entity.OssUrl, up.Url), msgId, gconv.Int64(positionArr[k]), mid)
  69. if !ok {
  70. return &pb.MaterialSaveResp{
  71. ErrorCode: -1,
  72. ErrorMsg: "",
  73. }, nil
  74. }
  75. }
  76. }
  77. }
  78. return &pb.MaterialSaveResp{
  79. ErrorCode: 1,
  80. ErrorMsg: "",
  81. MsgId: msgId,
  82. MaterialId: mid,
  83. UserIdArr: userIdArr,
  84. }, nil
  85. }