123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- package analysis
- import (
- "adm-ods/apis"
- "adm-ods/common.in/clinit"
- "adm-ods/model"
- "fmt"
- "github.com/tidwall/gjson"
- "strings"
- )
- // DY身份认证()
- func ParasOds15(content string) (ret []map[string]string, err error) {
- data := gjson.Parse(content)
- requestParams := data.Get("request_params").String()
- requestParamsArray := gjson.Parse(requestParams).Array()
- if len(requestParamsArray) < 1 {
- return nil, fmt.Errorf("数据异常,没有数据")
- }
- requestParam := requestParamsArray[0]
- idCard := requestParam.Get("identityCard").String()
- name := requestParam.Get("name").String()
- if idCard == "" || name == "" {
- return nil, fmt.Errorf("数据异常,身份证姓名任意为空")
- }
- responseParams := data.Get("response_params").String()
- errorCode := gjson.Get(responseParams, "code").String()
- if errorCode != "0" {
- return nil, fmt.Errorf("数据异常,没有数据", errorCode)
- }
- compStatus := gjson.Get(responseParams, "data.compStatus").String()
- if compStatus != "1" {
- return nil, fmt.Errorf("数据异常,不匹配")
- }
- dataMap := make(map[string]string)
- dataMap["id_card"] = idCard
- dataMap["name"] = name
- ret = append(ret, dataMap)
- return ret, nil
- }
- func HandleOnlineOds15(msg *apis.OdsMessage) (dataMapList []map[string]string, err error) {
- dataMapList, err = ParasOds15(msg.Content)
- if err != nil {
- // 解析不出来数据直接返回
- return nil, nil
- }
- if len(dataMapList) == 0 {
- return nil, nil
- }
- // 入本地库
- ods15 := &model.Ods15{}
- ods15.Name = dataMapList[0]["name"]
- ods15.IdCard = dataMapList[0]["id_card"]
- ods15.Content = msg.Content
- err = ods15.Insert(clinit.DB())
- if err != nil {
- if !strings.Contains(err.Error(), "Duplicate") {
- return nil, err
- } /*else {
- where := map[string]interface{}{"name": ods15.Name, "id_card": ods15.IdCard}
- oldods15 := &model.Ods15{}
- err = oldods15.Query(clinit.DB(), where)
- if err == nil {
- oldDataMapList, _ := ParasOds15(oldods15.Content)
- if checkDataMapListEqual(oldDataMapList, dataMapList) {
- return nil, nil
- }
- }
- ods15.UpdateWhere(clinit.DB(), where)
- }*/
- return nil, nil
- }
- return dataMapList, nil
- }
|