123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- // 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 学历(DYXL = "104-003")
- func ParasOds7(content string) (ret []map[string]string, err error) {
- data := gjson.Parse(content)
- requestParams := data.Get("request_params").String()
- responseParams := data.Get("response_params").String()
- idCard := gjson.Get(requestParams, "cardNo").String()
- name := gjson.Get(requestParams, "name").String()
- if idCard == "" || 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 {
- respMap := make(map[string]string)
- respMap["name"] = name
- respMap["is_double_first_class_university"] = v.Get("isDoubleFirstClassUniversity").String() // 是否为双一流学校
- respMap["is_two_one_one_university"] = v.Get("isTwoOneOneUniversity").String() // 是否为211学校
- respMap["end_date"] = v.Get("endDate").String() // 毕业日期
- respMap["type_name"] = v.Get("typeName").String() // 研究类型
- respMap["edu_code"] = v.Get("eduCode").String() // 学校代码
- respMap["qualification_code"] = v.Get( "qualificationCode").String() // 教育类别代码
- respMap["major_category"] = v.Get( "majorCategory").String() // 专业名称
- respMap["edu_name"] = v.Get( "eduName").String() // 学校名
- respMap["qualification_name"] = v.Get( "qualificationName").String() // 教育类别
- respMap["type_code"] = v.Get( "typeCode").String() // 研究类型代码
- respMap["secondary_category"] = v.Get( "secondaryCategory").String() // 二级学科名称
- respMap["begin_date"] = v.Get( "beginDate").String() // 注册日期
- respMap["major_code"] = v.Get( "majorCode").String() // 专业代码
- respMap["is_nine_eight_five_university"] = v.Get( "isNineEightFiveUniversity").String() // 是否为985学校
- respMap["id_card"] = idCard
- ret = append(ret, respMap)
- }
- if len(ret) == 0 {
- l.Error("func",
- zap.String("call", "ParasOds7"),
- zap.String("args", content),
- zap.String("error", "数据异常,无法解析"))
- return nil, fmt.Errorf("数据异常")
- } else {
- return ret, nil
- }
- }
- func HandleOnlineOds7(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
- dataMapList, err = ParasOds7(msg.Content)
- if err != nil {
- // 解析不出来数据直接返回
- return nil, nil
- }
- if len(dataMapList) == 0 {
- return nil, nil
- }
- // 入本地库
- ods7 := &model.Ods7{}
- ods7.IdCard = dataMapList[0]["id_card"]
- ods7.Name = dataMapList[0]["name"]
- ods7.Content = msg.Content
- err = ods7.Insert(clinit.DB())
- if err != nil {
- if !strings.Contains(err.Error(), "Duplicate") {
- return nil, err
- } else {
- where := map[string]interface{}{"id_card": ods7.IdCard,"name":ods7.Name}
- oldOds7 := &model.Ods7{}
- err = oldOds7.Query(clinit.DB(), where)
- if err == nil {
- oldDataMapList, _ := ParasOds7(oldOds7.Content)
- if checkDataMapListEqual(oldDataMapList, dataMapList) {
- return nil, nil
- }
- }
- ods7.UpdateWhere(clinit.DB(), where)
- }
- }
- return dataMapList, nil
- }
|