12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- package task
- import (
- "adm-ads/apis"
- "adm-ads/common.in/clinit"
- "adm-ads/model"
- "encoding/json"
- "gorm.io/gorm"
- "strings"
- )
- func supplementAds18(old, new *model.Ads18) (bool) {
- isSupple := false
- if old.PlateType == "" && new.PlateType != "" {
- isSupple = true
- old.PlateType = new.PlateType
- }
- if old.VehicleType == "" && new.VehicleType != "" {
- isSupple = true
- old.VehicleType = new.VehicleType
- }
- if old.VehicleTypeDetail == "" && new.VehicleTypeDetail != "" {
- isSupple = true
- old.VehicleTypeDetail = new.VehicleTypeDetail
- }
- return isSupple
- }
- // 计算号牌种类
- func Task18(adsMsg *apis.AdsMessage) (err error) {
- ads18 := &model.Ads18{}
- json.Unmarshal([]byte(adsMsg.Content), ads18)
- if ads18.ModelNo == "" || ads18.PlateType == ""{
- return nil
- }
- db := clinit.DB()
- oldAds18 := &model.Ads18{}
- err = oldAds18.Query(db,map[string]interface{}{"model_no":ads18.ModelNo})
- if err == nil {
- if supplementAds18(oldAds18,ads18){
- err = oldAds18.Update(db)
- if err != nil{
- return err
- }
- }
- return nil
- }else{
- if err != gorm.ErrRecordNotFound{
- return err
- }
- }
- err = ads18.Insert(db)
- if err != nil{
- if !strings.Contains(err.Error(), "Duplicate") {
- return err
- }
- }
- return nil
- }
|