task17.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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-ads/apis"
  6. "adm-ads/common.in/clinit"
  7. "adm-ads/consts"
  8. "adm-ads/model"
  9. "encoding/json"
  10. "gorm.io/gorm"
  11. "strings"
  12. )
  13. // 处理任务8的删除
  14. func handleTask17Delete(ads17 *model.Ads17) error {
  15. err := ads17.Delete(clinit.DB(),map[string]interface{}{"vin":ads17.Vin})
  16. if err == gorm.ErrRecordNotFound{
  17. return nil
  18. }
  19. return err
  20. }
  21. // 处理任务8的插入
  22. func handleTask17InsertOrUpdate(ads17 *model.Ads17)error{
  23. err := ads17.Insert(clinit.DB())
  24. if err != nil && !strings.Contains(err.Error(), "Duplicate") {
  25. return err
  26. }
  27. return nil
  28. }
  29. // 交强险投保记录
  30. func Task17(adsMsg *apis.AdsMessage) (err error) {
  31. ads17 := &model.Ads17{}
  32. json.Unmarshal([]byte(adsMsg.Content),&ads17)
  33. if (ads17.Vin == "") || (ads17.InsuranceDate == "" ){
  34. return nil
  35. }
  36. ads17.InsuranceDate = strings.Split(ads17.InsuranceDate," ")[0]
  37. if adsMsg.Action == consts.ACTIONDELETE{
  38. // 删除
  39. err = handleTask17Delete(ads17)
  40. }else{
  41. // 新增或插入
  42. err = handleTask17InsertOrUpdate(ads17)
  43. }
  44. return err
  45. }