123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- // 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 supplementDws12(old, new *model.Dws12) (bool) {
- isSupple := false
- if old.PlateType == "" && new.PlateType != "" {
- isSupple = true
- old.PlateType = new.PlateType
- }
- if new.VehicleType != "" {
- 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 calcMoto(dws12 *model.Dws12){
- // 摩托车不处理
- if dws12.VehicleTypeDetail != "" && strings.Contains(dws12.VehicleTypeDetail,"摩托车"){
- if dws12.VehicleTypeDetail == "两轮轻便摩托车"{
- dws12.VehicleType = "M22"
- dws12.PlateType = "08"
- }else if dws12.VehicleTypeDetail == "两轮摩托车"{
- dws12.VehicleType = "M21"
- dws12.PlateType = "07"
- }else{
- if dws12.TyreNumber == "2"{
- if dws12.RatedPower <= "4" && dws12.Displacement<= "50"{
- dws12.VehicleType = "M22"
- dws12.PlateType = "08"
- }else{
- dws12.VehicleType = "M21"
- dws12.PlateType = "07"
- }
- }else{
- if dws12.RatedPower <= "4" && dws12.Displacement<= "50"{
- dws12.PlateType = "08"
- }else{
- dws12.PlateType = "07"
- }
- }
- }
- }else{
- dws12.VehicleType = ""
- dws12.PlateType = ""
- }
- }
- // 计算号牌种类
- func Dws12Task(db *gorm.DB,dwsMessage *apis.DwsMessage, outputSourceCode string) (adsMsgList []*apis.AdsMessage, dwsMsgList []*apis.DwsMessage, err error) {
- dws12 := &model.Dws12{}
- err = json.Unmarshal([]byte(dwsMessage.Content), dws12)
- if err != nil {
- return nil, nil, nil
- }
- if dws12.ModelNo == ""{
- return nil, nil, nil
- }
- // 摩托车不处理
- /*if dws12.VehicleTypeDetail != "" && strings.Contains(dws12.VehicleTypeDetail,"摩托车"){
- return nil,nil,nil
- }*/
- dws12.ModelNo = strings.Replace(dws12.ModelNo,",","",-1)
- if dws12.Long != ""{
- //dws12.Long,_ = strconv.Unquote(dws12.Long)
- dws12.Long = strings.Replace(dws12.Long,`"`,"",-1)
- dws12.Long = strings.Split(dws12.Long,",")[0]
- }
- if dws12.ApprovedNumber != ""{
- dws12.ApprovedNumber = strings.Replace(dws12.ApprovedNumber,`"`,"",-1)
- dws12.ApprovedNumber = strings.Split(dws12.ApprovedNumber,",")[0]
- }
- if dws12.GrossMass != ""{
- dws12.GrossMass = strings.Replace(dws12.GrossMass,`"`,"",-1)
- //dws12.GrossMass,_ = strconv.Unquote(dws12.GrossMass)
- dws12.GrossMass = strings.Split(dws12.GrossMass,",")[0]
- }
- if dws12.IsMoto == "1"{
- calcMoto(dws12)
- }else{
- if dws12.PlateType == ""{
- dws12.PlateType = calcPlateType(dws12.Long,dws12.ApprovedNumber,dws12.GrossMass)
- }
- }
- if dws12.PlateType == ""{
- return nil ,nil,nil
- }
- oldDws12 := &model.Dws12{}
- err = oldDws12.Query(db,map[string]interface{}{"model_no":dws12.ModelNo})
- if err == nil {
- if supplementDws12(oldDws12,dws12){
- err = oldDws12.Update(db)
- if err != nil{
- return nil,nil,err
- }
- }else{
- return nil, nil, nil
- }
- }else{
- if err != gorm.ErrRecordNotFound{
- return nil, nil, err
- }
- err = dws12.Insert(db)
- if err != nil{
- if !strings.Contains(err.Error(), "Duplicate") {
- return nil, nil,err
- }
- }
- oldDws12 = dws12
- }
- adsMsg := NewAdsMessage(dwsMessage, outputSourceCode, consts.ACTIONINSERT)
- msgByte, _ := json.Marshal(*oldDws12)
- adsMsg.Content = string(msgByte)
- adsMsgList = append(adsMsgList,adsMsg)
- return adsMsgList, nil, nil
- }
|