123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- // 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 Dws8Task(db *gorm.DB,dwsMessage *apis.DwsMessage, outputSourceCode string) (adsMsgList []*apis.AdsMessage, dwsMsgList []*apis.DwsMessage, err error) {
- dws8 := &model.Dws8{}
- err = json.Unmarshal([]byte(dwsMessage.Content), dws8)
- if err != nil {
- return nil, nil, nil
- }
- if (dws8.Vin == "") || (dws8.InsuranceFirstDate == "" && dws8.LastCompulsoryInsuranceDate == "" && dws8.InsuranceDate == ""){
- return nil, nil, nil
- }
- if dws8.InsuranceFirstDate != ""{
- dws8.InsuranceFirstDate = strings.Split(dws8.InsuranceFirstDate," ")[0]
- }
- if dws8.LastCompulsoryInsuranceDate != ""{
- dws8.LastCompulsoryInsuranceDate = strings.Split(dws8.LastCompulsoryInsuranceDate," ")[0]
- }
- if dws8.InsuranceDate != ""{
- dws8.InsuranceDate = strings.Split(dws8.InsuranceDate," ")[0]
- }
- /*adsMsg = NewAdsMessage(dwsMessage, outputSourceCode, consts.ACTIONINSERT)
- msgByte, _ := json.Marshal(*dws8)
- adsMsg.Content = string(msgByte)*/
- if dws8.InsuranceDate != "" {
- oldDws8 := &model.Dws8{}
- err = oldDws8.Query(db,map[string]interface{}{"vin":dws8.Vin,"insurance_date":dws8.InsuranceDate})
- if err != nil{
- err = dws8.Insert(db)
- if err != nil{
- if !strings.Contains(err.Error(), "Duplicate") {
- return nil, nil,err
- }
- }else{
- adsMsg := NewAdsMessage(dwsMessage, outputSourceCode, consts.ACTIONINSERT)
- msgByte, _ := json.Marshal(*dws8)
- adsMsg.Content = string(msgByte)
- adsMsgList = append(adsMsgList,adsMsg)
- }
- }
- }
- if dws8.InsuranceFirstDate != "" && dws8.LastCompulsoryInsuranceDate != ""{
- if strings.HasPrefix(dws8.InsuranceFirstDate,dws8.LastCompulsoryInsuranceDate){
- dws8.LastCompulsoryInsuranceDate = ""
- }
- }
- if dws8.InsuranceFirstDate != ""{
- dws8.ID = 0
- dws8.InsuranceDate = dws8.InsuranceFirstDate
- oldDws8 := &model.Dws8{}
- err = oldDws8.Query(db,map[string]interface{}{"vin":dws8.Vin,"insurance_date":dws8.InsuranceDate})
- if err != nil{
- err = dws8.Insert(db)
- if err != nil{
- if !strings.Contains(err.Error(), "Duplicate") {
- return nil, nil,err
- }
- }else{
- adsMsg := NewAdsMessage(dwsMessage, outputSourceCode, consts.ACTIONINSERT)
- msgByte, _ := json.Marshal(*dws8)
- adsMsg.Content = string(msgByte)
- adsMsgList = append(adsMsgList,adsMsg)
- }
- }
- }
- if dws8.LastCompulsoryInsuranceDate != ""{
- dws8.ID = 0
- dws8.InsuranceDate = dws8.LastCompulsoryInsuranceDate
- oldDws8 := &model.Dws8{}
- err = oldDws8.Query(db,map[string]interface{}{"vin":dws8.Vin,"insurance_date":dws8.InsuranceDate})
- if err != nil{
- err = dws8.Insert(db)
- if err != nil{
- if !strings.Contains(err.Error(), "Duplicate") {
- return nil, nil,err
- }
- }else{
- adsMsg := NewAdsMessage(dwsMessage, outputSourceCode, consts.ACTIONINSERT)
- msgByte, _ := json.Marshal(*dws8)
- adsMsg.Content = string(msgByte)
- adsMsgList = append(adsMsgList,adsMsg)
- }
- }
- }
- return adsMsgList, nil, nil
- }
|