feat: add tipo_locatore field to Annunci and related processing logic
This commit is contained in:
parent
1307f352a4
commit
337ca80fec
5 changed files with 76 additions and 22 deletions
|
|
@ -356,15 +356,58 @@ func extractData_update(annuncio *typesdefs.AnnuncioXML, updateImages bool, upda
|
||||||
return tmp
|
return tmp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func flatClienteTipologia(t []string) string {
|
||||||
|
if len(t) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
if slices.Contains(t, "Proprietario") {
|
||||||
|
return "proprietario"
|
||||||
|
} else if slices.Contains(t, "Delegato") {
|
||||||
|
return "delegato"
|
||||||
|
} else if slices.Contains(t, "Cliente") {
|
||||||
|
return "inquilino"
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
func tipologiaPriority(tipologie []string) int {
|
||||||
|
if slices.Contains(tipologie, "Delegato") {
|
||||||
|
return 3
|
||||||
|
}
|
||||||
|
if slices.Contains(tipologie, "Cliente") {
|
||||||
|
return 2
|
||||||
|
}
|
||||||
|
if slices.Contains(tipologie, "Proprietario") {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
func selectTargetCliente(annuncio *typesdefs.AnnuncioXML) (int, bool) {
|
||||||
|
if len(annuncio.Clienti) == 0 {
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
best := 0
|
||||||
|
bestPriority := tipologiaPriority(annuncio.Clienti[0].Tipologie)
|
||||||
|
for i := 1; i < len(annuncio.Clienti); i++ {
|
||||||
|
if p := tipologiaPriority(annuncio.Clienti[i].Tipologie); p > bestPriority {
|
||||||
|
bestPriority = p
|
||||||
|
best = i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return best, true
|
||||||
|
}
|
||||||
|
|
||||||
func processLocatore(tmp *typesdefs.AnnuncioParsed, annuncio *typesdefs.AnnuncioXML) {
|
func processLocatore(tmp *typesdefs.AnnuncioParsed, annuncio *typesdefs.AnnuncioXML) {
|
||||||
if annuncio.Clienti == nil || annuncio.Clienti.Cliente == nil {
|
idx, ok := selectTargetCliente(annuncio)
|
||||||
|
if !ok {
|
||||||
|
log.Printf("Annuncio %s has no client information", utils.GetStringValue(annuncio.Codice))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
trg := annuncio.Clienti[idx]
|
||||||
|
|
||||||
tmp.Email = parser.ParseEmail(annuncio.Clienti.Cliente.Email1)
|
tmp.Email = parser.ParseEmail(trg.Email1)
|
||||||
|
|
||||||
var number string
|
var number string
|
||||||
for _, tel := range []*string{annuncio.Clienti.Cliente.Tel1, annuncio.Clienti.Cliente.Tel2, annuncio.Clienti.Cliente.Tel3} {
|
for _, tel := range []*string{trg.Tel1, trg.Tel2, trg.Tel3} {
|
||||||
if tel != nil {
|
if tel != nil {
|
||||||
cleanedTel := re.ReplaceAllString(*tel, "")
|
cleanedTel := re.ReplaceAllString(*tel, "")
|
||||||
if cleanedTel != "" {
|
if cleanedTel != "" {
|
||||||
|
|
@ -374,10 +417,11 @@ func processLocatore(tmp *typesdefs.AnnuncioParsed, annuncio *typesdefs.Annuncio
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tmp.Numero = &number
|
tmp.Numero = &number
|
||||||
if annuncio.Clienti.Cliente.Cognome != nil && annuncio.Clienti.Cliente.Nome != nil {
|
if trg.Cognome != nil && trg.Nome != nil {
|
||||||
tmp.Locatore = strUpd(fmt.Sprintf("%s %s", utils.MakeUppercase(*annuncio.Clienti.Cliente.Cognome), utils.MakeUppercase(*annuncio.Clienti.Cliente.Nome)))
|
tmp.Locatore = strUpd(fmt.Sprintf("%s %s", utils.MakeUppercase(*trg.Cognome), utils.MakeUppercase(*trg.Nome)))
|
||||||
}
|
}
|
||||||
tmp.Idlocatore = annuncio.Clienti.Cliente.Id
|
tmp.Idlocatore = trg.Id
|
||||||
|
tmp.Tipo_locatore = strUpd(flatClienteTipologia(trg.Tipologie))
|
||||||
}
|
}
|
||||||
|
|
||||||
func processIndirizzo(tmp *typesdefs.AnnuncioParsed, annuncio *typesdefs.AnnuncioXML) {
|
func processIndirizzo(tmp *typesdefs.AnnuncioParsed, annuncio *typesdefs.AnnuncioXML) {
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,8 @@ func AnnunciInsert(annunci typesdefs.AnnunciParsed, resetAllBeforeUpdate bool) e
|
||||||
disponibile_da = $47,
|
disponibile_da = $47,
|
||||||
permanenza = $48,
|
permanenza = $48,
|
||||||
persone = $49,
|
persone = $49,
|
||||||
media_updated_at = NOW()
|
media_updated_at = NOW(),
|
||||||
|
tipo_locatore = $50
|
||||||
WHERE codice = $46
|
WHERE codice = $46
|
||||||
`, annuncio.Locatore, annuncio.Numero, annuncio.Idlocatore,
|
`, annuncio.Locatore, annuncio.Numero, annuncio.Idlocatore,
|
||||||
annuncio.Email, annuncio.Creato_il, annuncio.Modificato_il,
|
annuncio.Email, annuncio.Creato_il, annuncio.Modificato_il,
|
||||||
|
|
@ -101,7 +102,7 @@ func AnnunciInsert(annunci typesdefs.AnnunciParsed, resetAllBeforeUpdate bool) e
|
||||||
annuncio.Numero_balconi, annuncio.Numero_terrazzi, annuncio.Numero_box, annuncio.Numero_postiauto,
|
annuncio.Numero_balconi, annuncio.Numero_terrazzi, annuncio.Numero_box, annuncio.Numero_postiauto,
|
||||||
annuncio.Caratteristiche, annuncio.Accessori, annuncio.Titolo_it, annuncio.Desc_it, annuncio.Titolo_en,
|
annuncio.Caratteristiche, annuncio.Accessori, annuncio.Titolo_it, annuncio.Desc_it, annuncio.Titolo_en,
|
||||||
annuncio.Desc_en, annuncio.Stato, annuncio.Web, annuncio.Homepage,
|
annuncio.Desc_en, annuncio.Stato, annuncio.Web, annuncio.Homepage,
|
||||||
annuncio.External_videos, annuncio.Codice, annuncio.Disponibile_da, annuncio.Permanenza, annuncio.Persone)
|
annuncio.External_videos, annuncio.Codice, annuncio.Disponibile_da, annuncio.Permanenza, annuncio.Persone, annuncio.Tipo_locatore)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
batch.Queue(`
|
batch.Queue(`
|
||||||
|
|
@ -155,9 +156,10 @@ func AnnunciInsert(annunci typesdefs.AnnunciParsed, resetAllBeforeUpdate bool) e
|
||||||
disponibile_da,
|
disponibile_da,
|
||||||
permanenza,
|
permanenza,
|
||||||
persone,
|
persone,
|
||||||
media_updated_at
|
media_updated_at,
|
||||||
|
tipo_locatore
|
||||||
)
|
)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34, $35, $36, $37, $38, $39, $40, $41, $42, $43, $44, $45, $46, $47, $48, $49, NOW())
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34, $35, $36, $37, $38, $39, $40, $41, $42, $43, $44, $45, $46, $47, $48, $49, NOW(), $50)
|
||||||
`, annuncio.Locatore, annuncio.Numero, annuncio.Idlocatore,
|
`, annuncio.Locatore, annuncio.Numero, annuncio.Idlocatore,
|
||||||
annuncio.Email, annuncio.Creato_il, annuncio.Modificato_il,
|
annuncio.Email, annuncio.Creato_il, annuncio.Modificato_il,
|
||||||
annuncio.Indirizzo, annuncio.Civico, annuncio.Comune, annuncio.Cap,
|
annuncio.Indirizzo, annuncio.Civico, annuncio.Comune, annuncio.Cap,
|
||||||
|
|
@ -169,7 +171,7 @@ func AnnunciInsert(annunci typesdefs.AnnunciParsed, resetAllBeforeUpdate bool) e
|
||||||
annuncio.Numero_balconi, annuncio.Numero_terrazzi, annuncio.Numero_box, annuncio.Numero_postiauto,
|
annuncio.Numero_balconi, annuncio.Numero_terrazzi, annuncio.Numero_box, annuncio.Numero_postiauto,
|
||||||
annuncio.Caratteristiche, annuncio.Accessori, annuncio.Titolo_it, annuncio.Desc_it, annuncio.Titolo_en,
|
annuncio.Caratteristiche, annuncio.Accessori, annuncio.Titolo_it, annuncio.Desc_it, annuncio.Titolo_en,
|
||||||
annuncio.Desc_en, annuncio.Stato, annuncio.Web, annuncio.Homepage,
|
annuncio.Desc_en, annuncio.Stato, annuncio.Web, annuncio.Homepage,
|
||||||
annuncio.External_videos, annuncio.Codice, annuncio.Disponibile_da, annuncio.Permanenza, annuncio.Persone)
|
annuncio.External_videos, annuncio.Codice, annuncio.Disponibile_da, annuncio.Permanenza, annuncio.Persone, annuncio.Tipo_locatore)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = Db.Dbpool.SendBatch(Db.Ctx, batch).Close()
|
err = Db.Dbpool.SendBatch(Db.Ctx, batch).Close()
|
||||||
|
|
|
||||||
|
|
@ -110,17 +110,16 @@ type AnnuncioXML struct {
|
||||||
DescrizioneEn *string `xml:"Descrizione_En"`
|
DescrizioneEn *string `xml:"Descrizione_En"`
|
||||||
Foto *[]string `xml:"Foto"`
|
Foto *[]string `xml:"Foto"`
|
||||||
Consegna *string `xml:"Consegna"`
|
Consegna *string `xml:"Consegna"`
|
||||||
Clienti *struct {
|
Clienti []struct {
|
||||||
Cliente *struct {
|
|
||||||
Id *string `xml:"Id"`
|
Id *string `xml:"Id"`
|
||||||
|
Tipologie []string `xml:"Tipologie>Tipologia"`
|
||||||
Cognome *string `xml:"Cognome"`
|
Cognome *string `xml:"Cognome"`
|
||||||
Nome *string `xml:"Nome"`
|
Nome *string `xml:"Nome"`
|
||||||
Tel1 *string `xml:"Tel1"`
|
Tel1 *string `xml:"Tel1"`
|
||||||
Tel2 *string `xml:"Tel2"`
|
Tel2 *string `xml:"Tel2"`
|
||||||
Tel3 *string `xml:"Tel3"`
|
Tel3 *string `xml:"Tel3"`
|
||||||
Email1 *string `xml:"Email1"`
|
Email1 *string `xml:"Email1"`
|
||||||
} `xml:"Cliente"`
|
} `xml:"Clienti>Cliente"`
|
||||||
} `xml:"Clienti"`
|
|
||||||
Cap *string `xml:"Cap"`
|
Cap *string `xml:"Cap"`
|
||||||
Video *[]string `xml:"Video"`
|
Video *[]string `xml:"Video"`
|
||||||
AMMedias *struct {
|
AMMedias *struct {
|
||||||
|
|
@ -170,6 +169,7 @@ type AnnuncioParsed struct {
|
||||||
Regione *string
|
Regione *string
|
||||||
Caratteristiche *map[string]interface{}
|
Caratteristiche *map[string]interface{}
|
||||||
Locatore *string
|
Locatore *string
|
||||||
|
Tipo_locatore *string
|
||||||
Numero *string
|
Numero *string
|
||||||
Idlocatore *string
|
Idlocatore *string
|
||||||
Stato *string
|
Stato *string
|
||||||
|
|
@ -190,6 +190,7 @@ type AnnunciDB struct {
|
||||||
Id int
|
Id int
|
||||||
Codice string
|
Codice string
|
||||||
Locatore *string
|
Locatore *string
|
||||||
|
Tipo_locatore *string
|
||||||
Numero *string
|
Numero *string
|
||||||
Idlocatore *string
|
Idlocatore *string
|
||||||
Indirizzo *string
|
Indirizzo *string
|
||||||
|
|
|
||||||
5
apps/db/migrations/38_tipo_locatore_usernote.up.sql
Normal file
5
apps/db/migrations/38_tipo_locatore_usernote.up.sql
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
ALTER TABLE IF EXISTS public.annunci
|
||||||
|
ADD COLUMN IF NOT EXISTS tipo_locatore TEXT;
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.users
|
||||||
|
ADD COLUMN IF NOT EXISTS note TEXT;
|
||||||
|
|
@ -110,6 +110,8 @@ export default interface AnnunciTable {
|
||||||
persone: ColumnType<string[] | null, string[] | null, string[] | null>;
|
persone: ColumnType<string[] | null, string[] | null, string[] | null>;
|
||||||
|
|
||||||
media_updated_at: ColumnType<Date | null, Date | string | null, Date | string | null>;
|
media_updated_at: ColumnType<Date | null, Date | string | null, Date | string | null>;
|
||||||
|
|
||||||
|
tipo_locatore: ColumnType<string | null, string | null, string | null>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Annunci = Selectable<AnnunciTable>;
|
export type Annunci = Selectable<AnnunciTable>;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue