link.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package service
  2. import (
  3. "context"
  4. "fmt"
  5. "strings"
  6. "youngee_b_api/db"
  7. "youngee_b_api/model/gorm_model"
  8. "youngee_b_api/model/http_model"
  9. "github.com/sirupsen/logrus"
  10. )
  11. var Link *link
  12. type link struct {
  13. }
  14. // LinkOpinion 在上传脚本表上提交修改意见
  15. func (*link) LinkOpinion(ctx context.Context, request http_model.LinkOpinionRequest) (*http_model.LinkOpinionData, error) {
  16. Link := gorm_model.YounggeeLinkInfo{
  17. TaskID: request.TaskID,
  18. ReviseOpinion: request.LinkOpinion,
  19. }
  20. err := db.LinkOpinion(ctx, Link.TaskID, Link.ReviseOpinion)
  21. if err != nil {
  22. logrus.WithContext(ctx).Errorf("[Link service] call CreateLink error,err:%+v", err)
  23. return nil, err
  24. }
  25. // 记录任务日志
  26. err = db.CreateTaskLog(ctx, Link.TaskID, "链接驳回")
  27. if err != nil {
  28. logrus.WithContext(ctx).Errorf("[Link service] call CreateTaskLog error,err:%+v", err)
  29. return nil, err
  30. }
  31. err = db.CreateMessageByTaskId(ctx, 18, 3, Link.TaskID)
  32. if err != nil {
  33. logrus.WithContext(ctx).Errorf("[Link service] call CreateMessageByTaskId error,err:%+v", err)
  34. return nil, err
  35. }
  36. res := &http_model.LinkOpinionData{
  37. TaskID: Link.TaskID,
  38. }
  39. return res, nil
  40. }
  41. // AcceptLink
  42. func (*link) AcceptLink(ctx context.Context, request http_model.AcceptLinkRequest) (*http_model.AcceptLinkData, error) {
  43. var TaskIDList []string
  44. TaskIDs := strings.Split(request.TaskIds, ",")
  45. for _, taskId := range TaskIDs {
  46. TaskIDList = append(TaskIDList, taskId)
  47. }
  48. fmt.Printf("acc request %+v", TaskIDList)
  49. err := db.AcceptLink(ctx, TaskIDList)
  50. if err != nil {
  51. logrus.WithContext(ctx).Errorf("[Link service] call CreateLink error,err:%+v", err)
  52. return nil, err
  53. }
  54. // 记录任务日志
  55. for _, taskId := range TaskIDList {
  56. err = db.CreateTaskLog(ctx, taskId, "链接通过")
  57. if err != nil {
  58. logrus.WithContext(ctx).Errorf("[Link service] call CreateTaskLog error,err:%+v", err)
  59. return nil, err
  60. }
  61. err = db.CreateMessageByTaskId(ctx, 4, 1, taskId)
  62. if err != nil {
  63. logrus.WithContext(ctx).Errorf("[Script service] call CreateTaskLog error,err:%+v", err)
  64. return nil, err
  65. }
  66. }
  67. res := &http_model.AcceptLinkData{
  68. TaskIds: TaskIDList,
  69. }
  70. return res, nil
  71. }
  72. // RejectLink
  73. func (*link) RejectLink(ctx context.Context, request http_model.RejectLinkRequest) (*http_model.RejectLinkData, error) {
  74. var TaskIDList []string
  75. TaskIDs := strings.Split(request.TaskIds, ",")
  76. for _, taskId := range TaskIDs {
  77. TaskIDList = append(TaskIDList, taskId)
  78. }
  79. fmt.Printf("acc request %+v", TaskIDList)
  80. err := db.RejectLink(ctx, TaskIDList)
  81. if err != nil {
  82. logrus.WithContext(ctx).Errorf("[Link service] call CreateLink error,err:%+v", err)
  83. return nil, err
  84. }
  85. // 记录任务日志
  86. for _, taskId := range TaskIDList {
  87. err = db.CreateTaskLog(ctx, taskId, "链接不通过")
  88. if err != nil {
  89. logrus.WithContext(ctx).Errorf("[Link service] call CreateTaskLog error,err:%+v", err)
  90. return nil, err
  91. }
  92. err = db.CreateMessageByTaskId(ctx, 18, 3, taskId)
  93. if err != nil {
  94. logrus.WithContext(ctx).Errorf("[Script service] call CreateTaskLog error,err:%+v", err)
  95. return nil, err
  96. }
  97. }
  98. res := &http_model.RejectLinkData{
  99. TaskIds: TaskIDList,
  100. }
  101. return res, nil
  102. }