123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- // Copyright 2019 autocareai.com. All rights reserved.
- // Use of this source code is governed by autocareai.com.
- package task
- import (
- "gadm-dws/apis"
- "gadm-dws/common.in/utils"
- "gadm-dws/consts"
- "gadm-dws/model"
- "encoding/json"
- "fmt"
- "gorm.io/gorm"
- "strings"
- )
- func dws11TaskImpl(db *gorm.DB,dwsMessage *apis.DwsMessage, outputSourceCode string,dws11 *model.Dws11) (adsMsgList []*apis.AdsMessage, dwsMsgList []*apis.DwsMessage, err error) {
- dws11.ID = 0
- dws11.Uniq = utils.MD5(dws11.VinRule+dws11.ModelNo)
- err = dws11.Query(db,map[string]interface{}{"uniq":dws11.Uniq})
- if err != nil{
- if err != gorm.ErrRecordNotFound{
- return nil,nil,err
- }
- }else{
- return nil,nil,nil
- }
- err = dws11.Insert(db)
- if err != nil{
- if !strings.Contains(err.Error(), "Duplicate") {
- return nil, nil,err
- }else{
- return nil,nil ,nil
- }
- }
- adsMsg := NewAdsMessage(dwsMessage, outputSourceCode, consts.ACTIONINSERT)
- msgByte, _ := json.Marshal(*dws11)
- adsMsg.Content = string(msgByte)
- adsMsgList = append(adsMsgList,adsMsg)
- return adsMsgList, nil, nil
- }
- func checkIsNormalVin(vinRule string) bool {
- for _,v := range vinRule{
- if (v>=48 && v <=57) || (v>=65 && v<=90){
- continue
- }else{
- return false
- }
- }
- return true
- }
- // vin码model_no关系
- func Dws11Task(db *gorm.DB,dwsMessage *apis.DwsMessage, outputSourceCode string) (adsMsgList []*apis.AdsMessage, dwsMsgList []*apis.DwsMessage, err error) {
- dws11 := &model.Dws11{}
- err = json.Unmarshal([]byte(dwsMessage.Content), dws11)
- if err != nil {
- return nil, nil, nil
- }
- //fmt.Println("dws11:",*dws11)
- if dws11.ModelNo == "" || (dws11.Vin == "" && dws11.VinRules == ""){
- return nil, nil, nil
- }
- dws11.ModelNo = strings.Replace(dws11.ModelNo,",","",-1)
- if dws11.Vin != ""{
- if len(dws11.Vin) > 8 {
- dws11.VinRule = dws11.Vin[0:8]
- }else{
- return nil,nil,nil
- }
- return dws11TaskImpl(db,dwsMessage,outputSourceCode,dws11)
- }else {
- if dws11.VinRules != ""{
- /*var result string
- for _,v := range dws11.VinRules{
- if v == 13 || v == 10{
- result = result + ","
- }else{
- result = result + string(v)
- }
- }
- dws11.VinRules = result*/
- dws11.VinRules = strings.Replace(dws11.VinRules,"\r",",",-1)
- dws11.VinRules = strings.Replace(dws11.VinRules,"\n",",",-1)
- }
- // 整车:LFBJEBA7××××××××× 截断前缀
- /*vinRuleList := strings.Split( dws11.VinRules ,":")
- if len(vinRuleList) > 1{
- dws11.VinRules = vinRuleList[1]
- }*/
- vinRules := strings.Split( dws11.VinRules ,",")
- for _,v := range vinRules{
- // 整车:LFBJEBA7××××××××× 截断前缀
- if strings.Contains(v,":"){
- vinRuleList := strings.Split( v ,":")
- if len(vinRuleList) > 1{
- v = vinRuleList[1]
- }
- }
- vinLen := len(v)
- if vinLen > 8 {
- if vinLen > 18{
- fmt.Println("vin过长:",dws11.ModelNo,dws11.VinRules)
- }
- dws11.VinRule = v[0:8]
- dws11.VinRule = strings.ToUpper(dws11.VinRule)
- if !checkIsNormalVin(dws11.VinRule){
- fmt.Println("错误的vin rule:",dws11.ModelNo,dws11.VinRules)
- continue
- }
- /*if strings.Contains(dws11.VinRule,"×"){
- continue
- }*/
- adsMsgs,_,err := dws11TaskImpl(db,dwsMessage,outputSourceCode,dws11)
- if err != nil{
- return nil,nil,err
- }
- adsMsgList = append(adsMsgList,adsMsgs...)
- }
- }
- }
- /*dws11.Uniq = utils.MD5(dws11.VinRule+dws11.ModelNo)
- err = dws11.Query(db,map[string]interface{}{"uniq":dws11.Uniq})
- if err != nil{
- if err != gorm.ErrRecordNotFound{
- return nil,nil,err
- }
- }else{
- return nil,nil,nil
- }
- err = dws11.Insert(db)
- if err != nil{
- if !strings.Contains(err.Error(), "Duplicate") {
- return nil, nil,err
- }else{
- return nil,nil ,nil
- }
- }
- adsMsg := NewAdsMessage(dwsMessage, outputSourceCode, consts.ACTIONINSERT)
- msgByte, _ := json.Marshal(*dws11)
- adsMsg.Content = string(msgByte)
- adsMsgList = append(adsMsgList,adsMsg)*/
- return adsMsgList, nil, nil
- }
|