123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- // Copyright 2019 autocareai.com. All rights reserved.
- // Use of this source code is governed by autocareai.com.
- package analysis
- import (
- "fmt"
- "gadm-ods/apis"
- "gadm-ods/common.in/clinit"
- "gadm-ods/model"
- "github.com/tidwall/gjson"
- "go.uber.org/zap"
- "strings"
- )
- // dybd 学位(DYXW = "104-001")
- func ParasOds5(content string) (ret []map[string]string, err error) {
- data := gjson.Parse(content)
- requestParams := data.Get("request_params").String()
- responseParams := data.Get("response_params").String()
- degreeId := gjson.Get(requestParams, "xwzsbh").String()
- name := gjson.Get(requestParams, "xm").String()
-
- if degreeId == "" || name == ""{
- return nil, fmt.Errorf("数据异常,车牌姓名不匹配")
- }
- code := gjson.Get(responseParams, "code").String()
- if code != "200" {
- return nil, fmt.Errorf("数据异常,没有数据")
- }
-
- arr := gjson.Get(responseParams, "data").Array()
-
-
- for _, v := range arr {
- dataMap := make(map[string]string)
- dataMap["birth_date"] = v.Get("csrq").String() // 出生日期
- dataMap["gender"] = v.Get("xb").String() // 性别
- dataMap["major"] = v.Get("xkzy").String() // 学科专业
- dataMap["degree_name"] = v.Get("xwlb").String() // 获学位名称
- dataMap["award_name"] = v.Get( "xwsydw").String() // 学位授予单位
- dataMap["name"] = name // 姓名
- dataMap["award_date"] = v.Get( "hxwrq").String() // 获学位日期
- dataMap["degree_id"] = degreeId
- ret = append(ret, dataMap)
- }
-
- if len(ret) == 0 {
- l.Error("func",
- zap.String("call", "ParasOds5"),
- zap.String("args", content),
- zap.String("error", "数据异常,无法解析"))
- return nil, fmt.Errorf("数据异常")
- } else {
- return ret, nil
- }
- }
- func HandleOnlineOds5(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
- dataMapList, err = ParasOds5(msg.Content)
- if err != nil {
- // 解析不出来数据直接返回
- return nil, nil
- }
- if len(dataMapList) == 0 {
- return nil, nil
- }
- // 入本地库
- ods5 := &model.Ods5{}
- ods5.DegreeId = dataMapList[0]["degree_id"]
- ods5.Name = dataMapList[0]["name"]
- ods5.Content = msg.Content
- err = ods5.Insert(clinit.DB())
- if err != nil {
- if !strings.Contains(err.Error(), "Duplicate") {
- return nil, err
- } else {
- where := map[string]interface{}{"degree_id": ods5.DegreeId,"name":ods5.Name}
- oldOds5 := &model.Ods5{}
- err = oldOds5.Query(clinit.DB(), where)
- if err == nil {
- oldDataMapList, _ := ParasOds5(oldOds5.Content)
- if checkDataMapListEqual(oldDataMapList, dataMapList) {
- return nil, nil
- }
- }
- ods5.UpdateWhere(clinit.DB(), where)
- }
- }
- return dataMapList, nil
- }
|