Skip to content

Commit

Permalink
add naf to entreprise (#125)
Browse files Browse the repository at this point in the history
* add naf to entreprise

* fix autoremove = false pour postgres

* fix rogue NumVoie

---------

Co-authored-by: Christophe Ninucci <[email protected]>
  • Loading branch information
chrnin and Christophe Ninucci authored Mar 2, 2023
1 parent 953cd1a commit 6aa5637
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 15 deletions.
5 changes: 5 additions & 0 deletions migrations/230301_0_feat_sirene_ul.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE entreprise ADD COLUMN IF NOT EXISTS code_activite text;
ALTER TABLE entreprise ADD COLUMN IF NOT EXISTS nomen_activite text;

create or replace view entreprise0 as
select * from entreprise where version = 0;
36 changes: 25 additions & 11 deletions src/core/entreprise.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Entreprise struct {
Nom *string `json:"nom,omitempty"`
NomUsage *string `json:"nomUsage,omitempty"`
Creation time.Time `json:"creation,omitempty"`
NAF NAF `json:"naf,omitempty"`
}
Paydex *Paydex `json:"paydex,omitempty"`
Diane []diane `json:"diane"`
Expand Down Expand Up @@ -71,6 +72,17 @@ type Etablissements struct {
Entreprises map[string]Entreprise `json:"entreprises,omitempty"`
}

type NAF struct {
LibelleActivite *string `json:"libelleActivite,omitempty"`
LibelleSecteur *string `json:"libelleSecteur,omitempty"`
CodeSecteur *string `json:"codeSecteur,omitempty"`
CodeActivite *string `json:"codeActivite,omitempty"`
LibelleN2 *string `json:"libelleN2,omitempty"`
LibelleN3 *string `json:"libelleN3,omitempty"`
LibelleN4 *string `json:"libelleN4,omitempty"`
NomenActivite *string `json:"nomenActivite,omitempty"`
}

// Etablissement type établissement pour l'API
type Etablissement struct {
Siren string `json:"siren"`
Expand Down Expand Up @@ -100,16 +112,7 @@ type Etablissement struct {
Region *string `json:"region"`
Latitude *float64 `json:"latitude"`
Longitude *float64 `json:"longitude"`
NAF struct {
LibelleActivite *string `json:"libelleActivite"`
LibelleSecteur *string `json:"libelleSecteur"`
CodeSecteur *string `json:"codeSecteur"`
CodeActivite *string `json:"codeActivite"`
LibelleN2 *string `json:"libelleN2"`
LibelleN3 *string `json:"libelleN3"`
LibelleN4 *string `json:"libelleN4"`
NomenActivite *string `json:"nomenActivite"`
} `json:"naf"`
NAF NAF `json:"naf"`
} `json:"sirene"`
PeriodeUrssaf EtablissementPeriodeUrssaf `json:"periodeUrssaf,omitempty"`
Delai []EtablissementDelai `json:"delai,omitempty"`
Expand Down Expand Up @@ -344,7 +347,15 @@ func (e *Etablissements) intoBatch(roles scope, username string) *pgx.Batch {
p.dgefp as permDGEFP,
p.bdf as permBDF,
p.pge as permPGE,
p.in_zone as in_zone
p.in_zone as in_zone,
ne.libelle_n1 as libelle_n1_entreprise,
ne.code_n1 as code_n1_entreprise,
ne.libelle_n5 as libelle_n5_entreprise,
ne.code_n5 as code_n5_entreprise,
ne.libelle_n2 as libelle_n2_entreprise,
ne.libelle_n3 as libelle_n3_entreprise,
ne.libelle_n4 as libelle_n4_entreprise,
en.nomen_activite as nomen_activite_entreprise
from etablissement0 et
inner join f_etablissement_permissions($1, $2) p on p.id = et.id
inner join departements d on d.code = et.departement
Expand All @@ -353,6 +364,7 @@ func (e *Etablissements) intoBatch(roles scope, username string) *pgx.Batch {
left join v_naf n on n.code_n5 = et.code_activite
left join etablissement_follow f on f.siret = et.siret and f.active and f.username = $2
left join entreprise0 en on en.siren = et.siren
left join v_naf ne on ne.code_n5 = en.code_activite
left join categorie_juridique j on j.code = en.statut_juridique
left join categorie_juridique j2 on substring(j.code from 0 for 3) = j2.code
left join categorie_juridique j1 on substring(j.code from 0 for 2) = j1.code
Expand Down Expand Up @@ -817,6 +829,8 @@ func (e *Etablissements) loadSirene(rows *pgx.Rows) error {
&el.PersonnePouMGroupe, &el.NiveauDetention, &el.PartFinanciere,
&el.CodeFiliere, &el.RefIDFiliere, &el.PersonnePouMFiliere, &ti.Code, &ti.Libelle,
&et.PermScore, &et.PermUrssaf, &et.PermDGEFP, &et.PermBDF, &et.PermPGE, &et.InZone,
&en.Sirene.NAF.LibelleSecteur, &en.Sirene.NAF.CodeSecteur, &en.Sirene.NAF.LibelleActivite, &en.Sirene.NAF.CodeActivite,
&en.Sirene.NAF.LibelleN2, &en.Sirene.NAF.LibelleN3, &en.Sirene.NAF.LibelleN4, &en.Sirene.NAF.NomenActivite,
)

if err != nil {
Expand Down
17 changes: 13 additions & 4 deletions src/core/sirene.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ func sqlSireneUL(ctx context.Context, data []goSirene.SireneUL) error {
etat_administratif text,
economie_sociale_solidaire boolean,
caractere_employeur boolean,
code_naf text,
nomenclature_naf text,
insert bool)
on commit drop;`)

Expand All @@ -255,9 +257,11 @@ func sqlSireneUL(ctx context.Context, data []goSirene.SireneUL) error {
annee_categorie,
etat_administratif,
economie_sociale_solidaire,
caractere_employeur) values
caractere_employeur,
code_naf,
nomenclature_naf) values
($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,
$12,$13,$14,$15,$16,$17,$18,$19,$20);`
$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22);`
for _, sirene := range data {
d := sireneULdata(sirene)
batch.Queue(sql, d...)
Expand All @@ -268,7 +272,8 @@ func sqlSireneUL(ctx context.Context, data []goSirene.SireneUL) error {
prenom4, nom, nom_usage, statut_juridique, creation, sigle,
identifiant_association, tranche_effectif, annee_effectif,
categorie, annee_categorie, etat_administratif,
economie_sociale_solidaire, caractere_employeur) select
economie_sociale_solidaire, caractere_employeur,
code_naf, nomenclature_naf) select
ul.siren,
ul.siret_siege,
ul.raison_sociale,
Expand All @@ -288,7 +293,9 @@ func sqlSireneUL(ctx context.Context, data []goSirene.SireneUL) error {
ul.annee_categorie,
ul.etat_administratif,
ul.economie_sociale_solidaire,
ul.caractere_employeur
ul.caractere_employeur,
ul.code_naf,
ul.nomenclature_naf
from tmp_sirene_ul ul
`)
results := tx.SendBatch(ctx, batch)
Expand Down Expand Up @@ -322,6 +329,8 @@ func sireneULdata(s goSirene.SireneUL) []interface{} {
null(s.EtatAdministratifUniteLegale),
s.EconomieSocialeSolidaireUniteLegale,
s.CaractereEmployeurUniteLegale,
s.ActivitePrincipaleUniteLegale,
s.NomenclatureActivitePrincipaleUniteLegale,
}
}

Expand Down
Binary file modified test/data/getEtablissement-VAF-03889351603035.json.gz
Binary file not shown.
Binary file modified test/data/getEtablissement-VAf-05826983715134.json.gz
Binary file not shown.
Binary file modified test/data/getEtablissement-VaF-02176220713665.json.gz
Binary file not shown.
Binary file modified test/data/getEtablissement-Vaf-02862648217576.json.gz
Binary file not shown.
Binary file modified test/data/getEtablissement-vAF-02052333785743.json.gz
Binary file not shown.
Binary file modified test/data/getEtablissement-vAf-02285281015164.json.gz
Binary file not shown.
Binary file modified test/data/getEtablissement-vaF-00785301892202.json.gz
Binary file not shown.
Binary file modified test/data/getEtablissement-vaf-01808286354803.json.gz
Binary file not shown.

0 comments on commit 6aa5637

Please sign in to comment.