ods7.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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-003")
  14. func ParasOds7(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. idCard := gjson.Get(requestParams, "cardNo").String()
  19. name := gjson.Get(requestParams, "name").String()
  20. if idCard == "" || 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. respMap := make(map[string]string)
  30. respMap["name"] = name
  31. respMap["is_double_first_class_university"] = v.Get("isDoubleFirstClassUniversity").String() // 是否为双一流学校
  32. respMap["is_two_one_one_university"] = v.Get("isTwoOneOneUniversity").String() // 是否为211学校
  33. respMap["end_date"] = v.Get("endDate").String() // 毕业日期
  34. respMap["type_name"] = v.Get("typeName").String() // 研究类型
  35. respMap["edu_code"] = v.Get("eduCode").String() // 学校代码
  36. respMap["qualification_code"] = v.Get( "qualificationCode").String() // 教育类别代码
  37. respMap["major_category"] = v.Get( "majorCategory").String() // 专业名称
  38. respMap["edu_name"] = v.Get( "eduName").String() // 学校名
  39. respMap["qualification_name"] = v.Get( "qualificationName").String() // 教育类别
  40. respMap["type_code"] = v.Get( "typeCode").String() // 研究类型代码
  41. respMap["secondary_category"] = v.Get( "secondaryCategory").String() // 二级学科名称
  42. respMap["begin_date"] = v.Get( "beginDate").String() // 注册日期
  43. respMap["major_code"] = v.Get( "majorCode").String() // 专业代码
  44. respMap["is_nine_eight_five_university"] = v.Get( "isNineEightFiveUniversity").String() // 是否为985学校
  45. respMap["id_card"] = idCard
  46. ret = append(ret, respMap)
  47. }
  48. if len(ret) == 0 {
  49. l.Error("func",
  50. zap.String("call", "ParasOds7"),
  51. zap.String("args", content),
  52. zap.String("error", "数据异常,无法解析"))
  53. return nil, fmt.Errorf("数据异常")
  54. } else {
  55. return ret, nil
  56. }
  57. }
  58. func HandleOnlineOds7(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
  59. dataMapList, err = ParasOds7(msg.Content)
  60. if err != nil {
  61. // 解析不出来数据直接返回
  62. return nil, nil
  63. }
  64. if len(dataMapList) == 0 {
  65. return nil, nil
  66. }
  67. // 入本地库
  68. ods7 := &model.Ods7{}
  69. ods7.IdCard = dataMapList[0]["id_card"]
  70. ods7.Name = dataMapList[0]["name"]
  71. ods7.Content = msg.Content
  72. err = ods7.Insert(clinit.DB())
  73. if err != nil {
  74. if !strings.Contains(err.Error(), "Duplicate") {
  75. return nil, err
  76. } else {
  77. where := map[string]interface{}{"id_card": ods7.IdCard,"name":ods7.Name}
  78. oldOds7 := &model.Ods7{}
  79. err = oldOds7.Query(clinit.DB(), where)
  80. if err == nil {
  81. oldDataMapList, _ := ParasOds7(oldOds7.Content)
  82. if checkDataMapListEqual(oldDataMapList, dataMapList) {
  83. return nil, nil
  84. }
  85. }
  86. ods7.UpdateWhere(clinit.DB(), where)
  87. }
  88. }
  89. return dataMapList, nil
  90. }