123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- package task
- import (
- "adm-dws/apis"
- "adm-dws/consts"
- "adm-dws/model"
- "encoding/json"
- "strings"
- "gorm.io/gorm"
- )
- // 姓名身份证对应关系(正确关系)
- func Dws15Task(db *gorm.DB,dwsMessage *apis.DwsMessage, outputSourceCode string) (adsMsgList []*apis.AdsMessage, dwsMsgList []*apis.DwsMessage, err error) {
- dws15 := &model.Dws15{}
- err = json.Unmarshal([]byte(dwsMessage.Content), dws15)
- if err != nil {
- return nil, nil, nil
- }
- dws15.UpdatedAt = dwsMessage.Timestamp
- dws15.CreatedAt = dwsMessage.Timestamp
- if dws15.Name == "" || dws15.IdCard == ""{
- return nil, nil, nil
- }
- oldDws15 := &model.Dws15{}
- where := map[string]interface{}{"id_card": dws15.IdCard}
- err = oldDws15.Query(db, where)
- if err == nil {
- // 有数据
- if oldDws15.Name == dws15.Name {
- // 不处理
- return nil, nil,nil
- } else {
- // 更新时间大于消息时间表示是后面的消息,不处理
- if oldDws15.UpdatedAt > dws15.UpdatedAt{
- return nil,nil,nil
- }
- oldDws15.Name = dws15.Name
- oldDws15.UpdatedAt = dws15.UpdatedAt
- err = oldDws15.Update(db)
- if err != nil{
- if err != gorm.ErrRecordNotFound{
- return nil,nil,err
- }
- }
- }
- } else {
- // 无数据
- if err == gorm.ErrRecordNotFound {
- err = dws15.Insert(db)
- if err != nil {
- if !strings.Contains(err.Error(), "Duplicate") {
- return nil,nil, err
- }
- }
- oldDws15 = dws15
- } else{
- return nil,nil,err
- }
- }
- adsMsg := NewAdsMessage(dwsMessage, outputSourceCode, consts.ACTIONINSERT)
- msgByte, _ := json.Marshal(*oldDws15)
- adsMsg.Content = string(msgByte)
- adsMsgList = append(adsMsgList,adsMsg)
- return adsMsgList, nil, nil
- }
|