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 学历(DYXL = "104-002")
- func ParasOds6(content string) (ret []map[string]string, err error) {
- data := gjson.Parse(content)
- requestParams := data.Get("request_params").String()
- responseParams := data.Get("response_params").String()
- educationId := gjson.Get(requestParams, "certificateid").String()
- name := gjson.Get(requestParams, "name").String()
- if educationId == "" || 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["name"] = name
- dataMap["level"] = v.Get("cc").String() // 层次 专科,本科
- dataMap["major"] = v.Get("zymc").String() //专业名称
- dataMap["university"] = v.Get("yxmc").String() //毕业学校名称
- dataMap["end_year"] = v.Get( "byrq").String() //毕业日期
- dataMap["start_year"] = v.Get( "rxrq").String() //入学日期
- dataMap["form"] = v.Get( "xxxs").String() //学习形式 普通全日制
- dataMap["education_id"] = educationId
- ret = append(ret, dataMap)
- }
- if len(ret) == 0 {
- l.Error("func",
- zap.String("call", "ParasOds6"),
- zap.String("args", content),
- zap.String("error", "数据异常,无法解析"))
- return nil, fmt.Errorf("数据异常")
- } else {
- return ret, nil
- }
- }
- func HandleOnlineOds6(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
- dataMapList, err = ParasOds6(msg.Content)
- if err != nil {
- // 解析不出来数据直接返回
- return nil, nil
- }
- if len(dataMapList) == 0 {
- return nil, nil
- }
- // 入本地库
- ods6 := &model.Ods6{}
- ods6.EducationId = dataMapList[0]["education_id"]
- ods6.Name = dataMapList[0]["name"]
- ods6.Content = msg.Content
- err = ods6.Insert(clinit.DB())
- if err != nil {
- if !strings.Contains(err.Error(), "Duplicate") {
- return nil, err
- } else {
- where := map[string]interface{}{"education_id": ods6.EducationId,"name":ods6.Name}
- oldOds6 := &model.Ods6{}
- err = oldOds6.Query(clinit.DB(), where)
- if err == nil {
- oldDataMapList, _ := ParasOds6(oldOds6.Content)
- if checkDataMapListEqual(oldDataMapList, dataMapList) {
- return nil, nil
- }
- }
- ods6.UpdateWhere(clinit.DB(), where)
- }
- }
- return dataMapList, nil
- }
|