ods5.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 学位(DYXW = "104-001")
  14. func ParasOds5(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. degreeId := gjson.Get(requestParams, "xwzsbh").String()
  19. name := gjson.Get(requestParams, "xm").String()
  20. if degreeId == "" || 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["birth_date"] = v.Get("csrq").String() // 出生日期
  31. dataMap["gender"] = v.Get("xb").String() // 性别
  32. dataMap["major"] = v.Get("xkzy").String() // 学科专业
  33. dataMap["degree_name"] = v.Get("xwlb").String() // 获学位名称
  34. dataMap["award_name"] = v.Get( "xwsydw").String() // 学位授予单位
  35. dataMap["name"] = name // 姓名
  36. dataMap["award_date"] = v.Get( "hxwrq").String() // 获学位日期
  37. dataMap["degree_id"] = degreeId
  38. ret = append(ret, dataMap)
  39. }
  40. if len(ret) == 0 {
  41. l.Error("func",
  42. zap.String("call", "ParasOds5"),
  43. zap.String("args", content),
  44. zap.String("error", "数据异常,无法解析"))
  45. return nil, fmt.Errorf("数据异常")
  46. } else {
  47. return ret, nil
  48. }
  49. }
  50. func HandleOnlineOds5(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
  51. dataMapList, err = ParasOds5(msg.Content)
  52. if err != nil {
  53. // 解析不出来数据直接返回
  54. return nil, nil
  55. }
  56. if len(dataMapList) == 0 {
  57. return nil, nil
  58. }
  59. // 入本地库
  60. ods5 := &model.Ods5{}
  61. ods5.DegreeId = dataMapList[0]["degree_id"]
  62. ods5.Name = dataMapList[0]["name"]
  63. ods5.Content = msg.Content
  64. err = ods5.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{}{"degree_id": ods5.DegreeId,"name":ods5.Name}
  70. oldOds5 := &model.Ods5{}
  71. err = oldOds5.Query(clinit.DB(), where)
  72. if err == nil {
  73. oldDataMapList, _ := ParasOds5(oldOds5.Content)
  74. if checkDataMapListEqual(oldDataMapList, dataMapList) {
  75. return nil, nil
  76. }
  77. }
  78. ods5.UpdateWhere(clinit.DB(), where)
  79. }
  80. }
  81. return dataMapList, nil
  82. }