123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- // 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"
- "gorm.io/gorm"
- "strings"
- )
- func supplementDws6(old, new *model.Dws6) (bool,string) {
- isSupple := false
- dwsMsgStr := ""
- if old.InsuranceFirstDate == "" && new.InsuranceFirstDate != "" {
- isSupple = true
- old.InsuranceFirstDate = new.InsuranceFirstDate
- }else if old.InsuranceFirstDate != "" && new.InsuranceFirstDate != "" {
- if new.InsuranceFirstDate < old.InsuranceFirstDate{
- msg := map[string]string{"initial_registration_date":old.InsuranceFirstDate,"vin":old.Vin}
- msgByte, _ := json.Marshal(msg)
- dwsMsgStr = string(msgByte)
- isSupple = true
- old.InsuranceFirstDate = new.InsuranceFirstDate
- }else if new.InsuranceFirstDate > old.InsuranceFirstDate{
- msg := map[string]string{"initial_registration_date":new.InsuranceFirstDate,"vin":old.Vin}
- msgByte, _ := json.Marshal(msg)
- dwsMsgStr = string(msgByte)
- }
- }
- if old.Province == "" && new.Province != "" {
- isSupple = true
- old.Province = new.Province
- }
- if old.City == "" && new.City != "" {
- isSupple = true
- old.City = new.City
- }
- if old.District == "" && new.District != "" {
- isSupple = true
- old.District = new.District
- }
- if old.UsePropertyDetail == "" && new.UsePropertyDetail != "" {
- isSupple = true
- old.UsePropertyDetail = new.UsePropertyDetail
- }
- return isSupple,dwsMsgStr
- }
- // 交强险首保日期
- func Dws6Task(db *gorm.DB,dwsMessage *apis.DwsMessage, outputSourceCode string) (adsMsgList []*apis.AdsMessage, dwsMsgList []*apis.DwsMessage, err error) {
- dws6 := &model.Dws6{}
- err = json.Unmarshal([]byte(dwsMessage.Content), dws6)
- if err != nil {
- return nil, nil, nil
- }
- if (dws6.Vin == "") || (dws6.InsuranceFirstDate == "" && dws6.UsePropertyDetail == ""){
- return nil, nil, nil
- }
- if dws6.InsuranceFirstDate != ""{
- dws6.InsuranceFirstDate = strings.Split(dws6.InsuranceFirstDate," ")[0]
- }
- oldDws6 := &model.Dws6{}
- err = oldDws6.Query(db, map[string]interface{}{"vin": dws6.Vin})
- if err == nil {
- // 有数据
- isSupple,dwsMsgStr := supplementDws6(oldDws6,dws6)
- if dwsMsgStr != ""{
- dwsMsg := NewDwsMessage(dwsMessage, outputSourceCode)
- dwsMsg.Content = dwsMsgStr
- dwsMsgList = append(dwsMsgList,dwsMsg)
- }
- if isSupple {
- err = oldDws6.Update(db)
- if err != nil{
- return nil,nil,err
- }
- }else{
- return nil,dwsMsgList,nil
- }
- } else {
- if err == gorm.ErrRecordNotFound {
- // 没有数据
- err = dws6.Insert(db)
- if err != nil {
- if !strings.Contains(err.Error(), "Duplicate") {
- return nil,nil, err
- }
- }
- oldDws6 = dws6
- } else {
- // 数据库错误
- return nil, nil, err
- }
- }
- adsMsg := NewAdsMessage(dwsMessage, outputSourceCode, consts.ACTIONINSERT)
- msgByte, _ := json.Marshal(*oldDws6)
- adsMsg.Content = string(msgByte)
- adsMsgList = append(adsMsgList,adsMsg)
- return adsMsgList, dwsMsgList, nil
- }
|