ods6.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright 2019 autocareai.com. All rights reserved.
  2. // Use of this source code is governed by autocareai.com.
  3. package analysis
  4. import (
  5. "fmt"
  6. "gadm-ods/apis"
  7. "gadm-ods/common.in/clinit"
  8. "gadm-ods/model"
  9. "github.com/tidwall/gjson"
  10. "go.uber.org/zap"
  11. "strings"
  12. )
  13. // dybd 学历(DYXL = "104-002")
  14. func ParasOds6(content string) (ret []map[string]string, err error) {
  15. data := gjson.Parse(content)
  16. requestParams := data.Get("request_params").String()
  17. responseParams := data.Get("response_params").String()
  18. educationId := gjson.Get(requestParams, "certificateid").String()
  19. name := gjson.Get(requestParams, "name").String()
  20. if educationId == "" || name == ""{
  21. return nil, fmt.Errorf("数据异常,车牌姓名不匹配")
  22. }
  23. code := gjson.Get(responseParams, "code").String()
  24. if code != "200" {
  25. return nil, fmt.Errorf("数据异常,没有数据")
  26. }
  27. arr := gjson.Get(responseParams, "data").Array()
  28. for _, v := range arr {
  29. dataMap := make(map[string]string)
  30. dataMap["name"] = name
  31. dataMap["level"] = v.Get("cc").String() // 层次 专科,本科
  32. dataMap["major"] = v.Get("zymc").String() //专业名称
  33. dataMap["university"] = v.Get("yxmc").String() //毕业学校名称
  34. dataMap["end_year"] = v.Get( "byrq").String() //毕业日期
  35. dataMap["start_year"] = v.Get( "rxrq").String() //入学日期
  36. dataMap["form"] = v.Get( "xxxs").String() //学习形式 普通全日制
  37. dataMap["education_id"] = educationId
  38. ret = append(ret, dataMap)
  39. }
  40. if len(ret) == 0 {
  41. l.Error("func",
  42. zap.String("call", "ParasOds6"),
  43. zap.String("args", content),
  44. zap.String("error", "数据异常,无法解析"))
  45. return nil, fmt.Errorf("数据异常")
  46. } else {
  47. return ret, nil
  48. }
  49. }
  50. func HandleOnlineOds6(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
  51. dataMapList, err = ParasOds6(msg.Content)
  52. if err != nil {
  53. // 解析不出来数据直接返回
  54. return nil, nil
  55. }
  56. if len(dataMapList) == 0 {
  57. return nil, nil
  58. }
  59. // 入本地库
  60. ods6 := &model.Ods6{}
  61. ods6.EducationId = dataMapList[0]["education_id"]
  62. ods6.Name = dataMapList[0]["name"]
  63. ods6.Content = msg.Content
  64. err = ods6.Insert(clinit.DB())
  65. if err != nil {
  66. if !strings.Contains(err.Error(), "Duplicate") {
  67. return nil, err
  68. } else {
  69. where := map[string]interface{}{"education_id": ods6.EducationId,"name":ods6.Name}
  70. oldOds6 := &model.Ods6{}
  71. err = oldOds6.Query(clinit.DB(), where)
  72. if err == nil {
  73. oldDataMapList, _ := ParasOds6(oldOds6.Content)
  74. if checkDataMapListEqual(oldDataMapList, dataMapList) {
  75. return nil, nil
  76. }
  77. }
  78. ods6.UpdateWhere(clinit.DB(), where)
  79. }
  80. }
  81. return dataMapList, nil
  82. }