2025-08-04 17:45:44 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
2025-08-21 13:53:55 +02:00
|
|
|
"backend/parser"
|
2025-08-22 12:57:33 +02:00
|
|
|
"backend/typesdefs"
|
2025-08-21 13:53:55 +02:00
|
|
|
"backend/utils"
|
2025-08-04 17:45:44 +02:00
|
|
|
"encoding/xml"
|
|
|
|
|
"fmt"
|
|
|
|
|
"io"
|
|
|
|
|
"os"
|
2025-10-15 14:27:06 +02:00
|
|
|
"slices"
|
2025-11-25 12:05:14 +01:00
|
|
|
"strconv"
|
2025-08-04 17:45:44 +02:00
|
|
|
"strings"
|
|
|
|
|
"sync"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
2025-08-22 12:57:33 +02:00
|
|
|
func From_Backup() typesdefs.XmlBkp {
|
2025-08-04 17:45:44 +02:00
|
|
|
//open the bkp.xml file
|
|
|
|
|
xmlFile, err := os.Open("bkp.xml")
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
}
|
|
|
|
|
defer xmlFile.Close()
|
|
|
|
|
|
|
|
|
|
byteValue, err := io.ReadAll(xmlFile)
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
}
|
2025-08-22 12:57:33 +02:00
|
|
|
var miogest typesdefs.XmlBkp
|
2025-08-04 17:45:44 +02:00
|
|
|
xml.Unmarshal(byteValue, &miogest)
|
|
|
|
|
return miogest
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-22 12:57:33 +02:00
|
|
|
func ParseUpdateBkp(m *MiogestHandler) typesdefs.AnnunciParsed {
|
2025-08-04 17:45:44 +02:00
|
|
|
|
|
|
|
|
miogest := From_Backup()
|
|
|
|
|
|
2025-08-22 12:57:33 +02:00
|
|
|
var AnnunciArray typesdefs.AnnunciParsed
|
|
|
|
|
extractedData := make(chan typesdefs.AnnuncioParsed)
|
|
|
|
|
defaultCaratteristiche := m.GetCaratteristiche()
|
|
|
|
|
defaultCategorie := m.GetCategorie()
|
2025-08-04 17:45:44 +02:00
|
|
|
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
wg.Add(len(miogest.Annunci.Record))
|
|
|
|
|
|
|
|
|
|
for i := 0; i < len(miogest.Annunci.Record); i++ {
|
|
|
|
|
go func(i int) {
|
|
|
|
|
defer wg.Done()
|
|
|
|
|
extractData_bkp(miogest.Annunci.Record[i], extractedData, defaultCaratteristiche, defaultCategorie)
|
|
|
|
|
}(i)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
|
wg.Wait()
|
|
|
|
|
close(extractedData)
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
for result := range extractedData {
|
|
|
|
|
AnnunciArray.Annuncio = append(AnnunciArray.Annuncio, result)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return AnnunciArray
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-22 12:57:33 +02:00
|
|
|
func extractData_bkp(annuncio typesdefs.AnnuncioBKP, extractedData chan typesdefs.AnnuncioParsed, defaultCaratteristiche typesdefs.ListaCaratteristiche, defaultCategorie []typesdefs.Categoria) {
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-08-22 12:57:33 +02:00
|
|
|
var tmp typesdefs.AnnuncioParsed = typesdefs.AnnuncioParsed{}
|
2025-08-04 17:45:44 +02:00
|
|
|
|
2025-08-21 13:53:55 +02:00
|
|
|
codice := utils.RemoveWhitespace(utils.GetStringValue(annuncio.Codice))
|
2025-08-04 17:45:44 +02:00
|
|
|
tmp.Codice = codice
|
|
|
|
|
tmp.Email = nil
|
|
|
|
|
if annuncio.Proprietario != nil && annuncio.Proprietario.Cliente != nil && annuncio.Proprietario.Cliente.Nome != nil {
|
|
|
|
|
tmp.Locatore = annuncio.Proprietario.Cliente.Nome
|
|
|
|
|
}
|
|
|
|
|
tmp.Numero = nil
|
|
|
|
|
if annuncio.Proprietario != nil && annuncio.Proprietario.Cliente != nil && annuncio.Proprietario.Cliente.Nome != nil {
|
|
|
|
|
tmp.Idlocatore = annuncio.Proprietario.Cliente.ID
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-21 13:53:55 +02:00
|
|
|
upperIndirizzo := utils.MakeUppercase(utils.GetStringValue(annuncio.Indirizzo))
|
2025-08-04 17:45:44 +02:00
|
|
|
tmp.Indirizzo = &upperIndirizzo
|
|
|
|
|
tmp.Civico = annuncio.Civico
|
2025-08-21 13:53:55 +02:00
|
|
|
upperComune := utils.MakeUppercase(utils.GetStringValue(annuncio.Comune))
|
2025-08-04 17:45:44 +02:00
|
|
|
tmp.Comune = &upperComune
|
|
|
|
|
tmp.Cap = annuncio.Cap
|
|
|
|
|
tmp.Provincia = annuncio.Provincia
|
|
|
|
|
tmp.Regione = annuncio.Regione
|
2025-08-21 13:53:55 +02:00
|
|
|
tmp.Lat = utils.CommaToDot(annuncio.Lat)
|
|
|
|
|
tmp.Lon = utils.CommaToDot(annuncio.Lon)
|
2025-08-04 17:45:44 +02:00
|
|
|
tmp.Indirizzo_secondario = nil
|
|
|
|
|
tmp.Civico_secondario = nil
|
|
|
|
|
tmp.Lat_secondario = nil
|
|
|
|
|
tmp.Lon_secondario = nil
|
|
|
|
|
|
|
|
|
|
var tipo = tipologiaParser(*annuncio.Tipo)
|
|
|
|
|
tmp.Tipo = &tipo
|
|
|
|
|
|
2025-08-21 13:53:55 +02:00
|
|
|
tmpanno := utils.GetStringValue(annuncio.Anno)
|
2025-08-04 17:45:44 +02:00
|
|
|
if tmpanno != "0" && tmpanno != "" {
|
|
|
|
|
tmp.Anno = &tmpanno
|
|
|
|
|
}
|
2025-08-21 13:53:55 +02:00
|
|
|
tmp.Prezzo = parser.ParsePrezzo(annuncio.Prezzo)
|
|
|
|
|
tmp.Consegna = parser.ParseConsegna(annuncio.Consegna)
|
2025-08-04 17:45:44 +02:00
|
|
|
tmp.Classe = annuncio.Classe
|
|
|
|
|
|
|
|
|
|
if annuncio.Categorie != nil && annuncio.Categorie.Categoria != nil {
|
|
|
|
|
resultArray := make([]string, 0)
|
|
|
|
|
cats := *annuncio.Categorie.Categoria
|
|
|
|
|
for _, cat := range cats {
|
|
|
|
|
for _, catdef := range defaultCategorie {
|
|
|
|
|
if cat.ID == catdef.Id {
|
|
|
|
|
resultArray = append(resultArray, catdef.Nome)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if tmp.Categorie == nil {
|
|
|
|
|
tmp.Categorie = &[]string{}
|
|
|
|
|
}
|
|
|
|
|
*tmp.Categorie = resultArray
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-25 12:05:14 +01:00
|
|
|
if annuncio.Mq != nil {
|
|
|
|
|
replaced := strings.ReplaceAll(*annuncio.Mq, ",", ".")
|
|
|
|
|
if s, err := strconv.ParseFloat(replaced, 64); err == nil {
|
|
|
|
|
tmp.Mq = &s
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-04 17:45:44 +02:00
|
|
|
tmp.Piano = annuncio.Piano
|
|
|
|
|
tmp.Piano_palazzo = annuncio.PianoPalazzo
|
|
|
|
|
tmp.Unita_condominio = annuncio.UnitaImmobiliari
|
|
|
|
|
tmp.Numero_vani = annuncio.NumeroVani
|
|
|
|
|
tmp.Numero_camere = annuncio.NumeroCamere
|
|
|
|
|
tmp.Numero_bagni = annuncio.NumeroBagni
|
|
|
|
|
tmp.Numero_balconi = annuncio.NumeroBalconi
|
|
|
|
|
tmp.Numero_terrazzi = annuncio.NumeroTerrazzi
|
|
|
|
|
tmp.Numero_box = annuncio.NumeroBox
|
|
|
|
|
tmp.Numero_postiauto = annuncio.NumeroPostiauto
|
2025-08-21 13:53:55 +02:00
|
|
|
tmpstato := utils.GetStringValue(annuncio.Stato)
|
2025-08-04 17:45:44 +02:00
|
|
|
var tmpstatoString string
|
|
|
|
|
if tmpstato == "1" {
|
|
|
|
|
tmpstatoString = "Attivo"
|
|
|
|
|
}
|
|
|
|
|
if tmpstato == "2" {
|
|
|
|
|
tmpstatoString = "Trattativa"
|
|
|
|
|
} else {
|
|
|
|
|
tmpstatoString = "Sospeso"
|
|
|
|
|
}
|
|
|
|
|
tmp.Stato = &tmpstatoString
|
|
|
|
|
home := false
|
|
|
|
|
tmp.Homepage = &home
|
|
|
|
|
|
|
|
|
|
layout := "20060102150405"
|
|
|
|
|
if annuncio.Inserito != nil {
|
|
|
|
|
t, err := time.Parse(layout, *annuncio.Inserito)
|
|
|
|
|
if err != nil {
|
|
|
|
|
tmp.Creato_il = nil
|
|
|
|
|
} else {
|
|
|
|
|
tmp.Creato_il = &t
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tmp.Modificato_il = nil
|
|
|
|
|
|
|
|
|
|
var itlingua string = "it"
|
|
|
|
|
var enlingua string = "en"
|
|
|
|
|
var tmpTitoloIt *string = nil
|
|
|
|
|
var tmpTitoloEn *string = nil
|
|
|
|
|
var tmpDescIt *string = nil
|
|
|
|
|
var tmpDescEn *string = nil
|
|
|
|
|
|
|
|
|
|
if annuncio.Descrizioni != nil {
|
|
|
|
|
for _, desc := range *annuncio.Descrizioni.Descrizione {
|
|
|
|
|
|
|
|
|
|
if desc.Lingua != nil {
|
|
|
|
|
if *desc.Lingua == itlingua {
|
|
|
|
|
tmpTitoloIt = desc.Titolo
|
|
|
|
|
tmpDescIt = desc.Testo
|
|
|
|
|
}
|
|
|
|
|
if *desc.Lingua == enlingua {
|
|
|
|
|
tmpTitoloEn = desc.Titolo
|
|
|
|
|
tmpDescEn = desc.Testo
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tmp.Titolo_it = tmpTitoloIt
|
|
|
|
|
tmp.Titolo_en = tmpTitoloEn
|
|
|
|
|
tmp.Desc_it = tmpDescIt
|
|
|
|
|
tmp.Desc_en = tmpDescEn
|
|
|
|
|
w := false
|
|
|
|
|
tmp.Web = &w
|
|
|
|
|
|
2025-11-18 15:20:14 +01:00
|
|
|
tmp.External_videos = nil
|
2025-08-04 17:45:44 +02:00
|
|
|
|
|
|
|
|
if annuncio.Accessori != nil && annuncio.Accessori.Accessorio != nil {
|
|
|
|
|
tmpAcc := make([]string, 0)
|
|
|
|
|
for _, acc := range *annuncio.Accessori.Accessorio {
|
|
|
|
|
if acc.Nome != nil {
|
|
|
|
|
tmpAcc = append(tmpAcc, *acc.Nome)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if tmp.Accessori == nil {
|
|
|
|
|
tmp.Accessori = &[]string{}
|
|
|
|
|
}
|
|
|
|
|
*tmp.Accessori = tmpAcc
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tmpCaratteristiche := make(map[string]interface{})
|
|
|
|
|
|
|
|
|
|
if annuncio.Schede != nil && annuncio.Schede.Scheda != nil {
|
|
|
|
|
for _, scheda := range *annuncio.Schede.Scheda {
|
|
|
|
|
if scheda.Valore != nil {
|
|
|
|
|
var cossriponding_name *string = nil
|
|
|
|
|
for _, def := range defaultCaratteristiche.Caratteristiche {
|
|
|
|
|
if scheda.ID == def.Id {
|
|
|
|
|
cossriponding_name = &def.Tagxml
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if cossriponding_name != nil {
|
|
|
|
|
tmpCaratteristiche[*cossriponding_name] = *scheda.Valore
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, def := range defaultCaratteristiche.Caratteristiche {
|
|
|
|
|
|
|
|
|
|
if _, ok := tmpCaratteristiche[def.Tagxml]; !ok {
|
|
|
|
|
tmpCaratteristiche[def.Tagxml] = nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
tmp.Caratteristiche = &tmpCaratteristiche
|
|
|
|
|
|
2025-11-18 15:20:14 +01:00
|
|
|
tmp.External_videos = nil
|
2025-08-04 17:45:44 +02:00
|
|
|
|
|
|
|
|
extractedData <- tmp
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestTipologieBkp() {
|
|
|
|
|
|
|
|
|
|
bkp := From_Backup()
|
|
|
|
|
var tipologie []string
|
|
|
|
|
for _, r := range bkp.Annunci.Record {
|
|
|
|
|
if r.Tipo != nil {
|
2025-10-15 14:27:06 +02:00
|
|
|
if !slices.Contains(tipologie, *r.Tipo) {
|
2025-08-04 17:45:44 +02:00
|
|
|
tipologie = append(tipologie, *r.Tipo)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fmt.Println(strings.Join(tipologie, ","))
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func tipologiaParser(tipo string) string {
|
|
|
|
|
var result string
|
|
|
|
|
switch tipo {
|
|
|
|
|
case "Affitto Residenziale", "Affitto Turistico":
|
|
|
|
|
result = "Transitorio"
|
|
|
|
|
case "Vendita Residenziale", "Vendita Commerciale":
|
|
|
|
|
result = "Vendita"
|
|
|
|
|
case "Affitto Commerciale", "Affitto":
|
|
|
|
|
result = "Stabile"
|
|
|
|
|
case "Cessione Commerciale", "Cessione":
|
|
|
|
|
result = "Cessione"
|
|
|
|
|
default:
|
|
|
|
|
result = "Errore"
|
|
|
|
|
}
|
|
|
|
|
return result
|
|
|
|
|
}
|