question.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package service
  2. import (
  3. "context"
  4. "encoding/json"
  5. "go-common/app/job/main/answer/model"
  6. "go-common/library/log"
  7. )
  8. // AddLabourQuestion add labour question.
  9. func (s *Service) AddLabourQuestion(c context.Context, msg *model.MsgCanal) (err error) {
  10. var que = &model.LabourQs{}
  11. if err = json.Unmarshal(msg.New, que); err != nil {
  12. log.Error("json.Unmarshal(%v) err(%v)", msg, err)
  13. return
  14. }
  15. log.Info("labour add (%+v)", que)
  16. if err = s.createBFSImg(c, que); err != nil {
  17. log.Error("createBFSImg(%v) err(%v)", que, err)
  18. return
  19. }
  20. que.State = model.HadCreateImg
  21. s.dao.AddQs(c, que)
  22. return
  23. }
  24. // ModifyLabourQuestion nodify labour question.
  25. func (s *Service) ModifyLabourQuestion(c context.Context, msg *model.MsgCanal) (err error) {
  26. var (
  27. newq = &model.LabourQs{}
  28. oldq = &model.LabourQs{}
  29. )
  30. if err = json.Unmarshal(msg.New, newq); err != nil {
  31. log.Error("newlqs json.Unmarshal(%v) err(%v)", msg, err)
  32. return
  33. }
  34. if err = json.Unmarshal(msg.Old, oldq); err != nil {
  35. log.Error("oldlqs json.Unmarshal(%v) err(%v)", msg, err)
  36. return
  37. }
  38. log.Info("labour modify (%+v)(%+v)", newq, oldq)
  39. if newq.Status == oldq.Status && newq.Ans == oldq.Ans && newq.Isdel == oldq.Isdel {
  40. log.Error("ModifyLabourQuestion no change(%v, %v)", newq, oldq)
  41. return
  42. }
  43. s.dao.UpdateQs(c, newq)
  44. return
  45. }
  46. // UploadQueImg uplaod que img.
  47. func (s *Service) UploadQueImg(c context.Context, que *model.LabourQs) (err error) {
  48. if err = s.createBFSImg(c, que); err != nil {
  49. log.Error("createBFSImg(%v) err(%v)", que, err)
  50. return
  51. }
  52. que.State = model.HadCreateImg
  53. s.dao.UpdateState(c, que)
  54. return
  55. }