manual_amendment_data.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package handle
  4. import (
  5. "adm-ods/apis"
  6. "adm-ods/common.in/clinit"
  7. "adm-ods/common.in/utils"
  8. "adm-ods/model"
  9. dutils "adm-ods/utils"
  10. "encoding/json"
  11. "github.com/tidwall/gjson"
  12. "go.uber.org/zap"
  13. )
  14. // 处理手动修改
  15. func HandleManualAmendmentData(msg *apis.OdsMessage) error {
  16. // 1 存储到本地
  17. // 2 发送
  18. if msg.SourceCode == "" && len(msg.TaskList) <=0 {
  19. l.Error("func",
  20. zap.String("call", "HandleManualAmendmentData"),
  21. zap.String("args", msg.SourceCode),
  22. zap.String("error", "source code is null"))
  23. return nil
  24. }
  25. manual := &model.ManualAmendment{}
  26. manual.NewContent = gjson.Get(msg.Content, "new_content").String()
  27. if manual.NewContent == "" {
  28. l.Error("func",
  29. zap.String("call", "HandleManualAmendmentData"),
  30. zap.String("args", msg.SourceCode),
  31. zap.String("error", "new content is null "))
  32. return nil
  33. }
  34. manual.Source = msg.SourceCode
  35. manual.OldContent = gjson.Get(msg.Content, "old_content").String()
  36. err := manual.Insert(clinit.DB())
  37. if err != nil {
  38. return err
  39. }
  40. dwsMsg := dutils.NewDwsMessage(msg)
  41. var dataMapList []map[string]interface{}
  42. dataMap := make(map[string]interface{})
  43. json.Unmarshal([]byte(manual.NewContent) ,&dataMap)
  44. dataMapList = append(dataMapList, dataMap)
  45. dwsMsg.Content = utils.MarshalJsonString(dataMapList)
  46. err = dutils.SendDwsMsg(dwsMsg)
  47. return err
  48. }