task8.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package task
  4. import (
  5. "adm-dws/apis"
  6. "adm-dws/consts"
  7. "adm-dws/model"
  8. "encoding/json"
  9. "gorm.io/gorm"
  10. "strings"
  11. )
  12. // 交强险投保记录
  13. func Dws8Task(db *gorm.DB,dwsMessage *apis.DwsMessage, outputSourceCode string) (adsMsgList []*apis.AdsMessage, dwsMsgList []*apis.DwsMessage, err error) {
  14. dws8 := &model.Dws8{}
  15. err = json.Unmarshal([]byte(dwsMessage.Content), dws8)
  16. if err != nil {
  17. return nil, nil, nil
  18. }
  19. if (dws8.Vin == "") || (dws8.InsuranceFirstDate == "" && dws8.LastCompulsoryInsuranceDate == "" && dws8.InsuranceDate == ""){
  20. return nil, nil, nil
  21. }
  22. if dws8.InsuranceFirstDate != ""{
  23. dws8.InsuranceFirstDate = strings.Split(dws8.InsuranceFirstDate," ")[0]
  24. }
  25. if dws8.LastCompulsoryInsuranceDate != ""{
  26. dws8.LastCompulsoryInsuranceDate = strings.Split(dws8.LastCompulsoryInsuranceDate," ")[0]
  27. }
  28. if dws8.InsuranceDate != ""{
  29. dws8.InsuranceDate = strings.Split(dws8.InsuranceDate," ")[0]
  30. }
  31. /*adsMsg = NewAdsMessage(dwsMessage, outputSourceCode, consts.ACTIONINSERT)
  32. msgByte, _ := json.Marshal(*dws8)
  33. adsMsg.Content = string(msgByte)*/
  34. if dws8.InsuranceDate != "" {
  35. oldDws8 := &model.Dws8{}
  36. err = oldDws8.Query(db,map[string]interface{}{"vin":dws8.Vin,"insurance_date":dws8.InsuranceDate})
  37. if err != nil{
  38. err = dws8.Insert(db)
  39. if err != nil{
  40. if !strings.Contains(err.Error(), "Duplicate") {
  41. return nil, nil,err
  42. }
  43. }else{
  44. adsMsg := NewAdsMessage(dwsMessage, outputSourceCode, consts.ACTIONINSERT)
  45. msgByte, _ := json.Marshal(*dws8)
  46. adsMsg.Content = string(msgByte)
  47. adsMsgList = append(adsMsgList,adsMsg)
  48. }
  49. }
  50. }
  51. if dws8.InsuranceFirstDate != "" && dws8.LastCompulsoryInsuranceDate != ""{
  52. if strings.HasPrefix(dws8.InsuranceFirstDate,dws8.LastCompulsoryInsuranceDate){
  53. dws8.LastCompulsoryInsuranceDate = ""
  54. }
  55. }
  56. if dws8.InsuranceFirstDate != ""{
  57. dws8.ID = 0
  58. dws8.InsuranceDate = dws8.InsuranceFirstDate
  59. oldDws8 := &model.Dws8{}
  60. err = oldDws8.Query(db,map[string]interface{}{"vin":dws8.Vin,"insurance_date":dws8.InsuranceDate})
  61. if err != nil{
  62. err = dws8.Insert(db)
  63. if err != nil{
  64. if !strings.Contains(err.Error(), "Duplicate") {
  65. return nil, nil,err
  66. }
  67. }else{
  68. adsMsg := NewAdsMessage(dwsMessage, outputSourceCode, consts.ACTIONINSERT)
  69. msgByte, _ := json.Marshal(*dws8)
  70. adsMsg.Content = string(msgByte)
  71. adsMsgList = append(adsMsgList,adsMsg)
  72. }
  73. }
  74. }
  75. if dws8.LastCompulsoryInsuranceDate != ""{
  76. dws8.ID = 0
  77. dws8.InsuranceDate = dws8.LastCompulsoryInsuranceDate
  78. oldDws8 := &model.Dws8{}
  79. err = oldDws8.Query(db,map[string]interface{}{"vin":dws8.Vin,"insurance_date":dws8.InsuranceDate})
  80. if err != nil{
  81. err = dws8.Insert(db)
  82. if err != nil{
  83. if !strings.Contains(err.Error(), "Duplicate") {
  84. return nil, nil,err
  85. }
  86. }else{
  87. adsMsg := NewAdsMessage(dwsMessage, outputSourceCode, consts.ACTIONINSERT)
  88. msgByte, _ := json.Marshal(*dws8)
  89. adsMsg.Content = string(msgByte)
  90. adsMsgList = append(adsMsgList,adsMsg)
  91. }
  92. }
  93. }
  94. return adsMsgList, nil, nil
  95. }