att
This commit is contained in:
parent
736016ea99
commit
7e2fe4a785
75
draft_mar.py
75
draft_mar.py
@ -156,11 +156,11 @@ def create_draft_temp_table(cursor):
|
|||||||
CREATE TABLE dbo.draft_temp (
|
CREATE TABLE dbo.draft_temp (
|
||||||
id INT IDENTITY(1,1) PRIMARY KEY,
|
id INT IDENTITY(1,1) PRIMARY KEY,
|
||||||
date DATE DEFAULT CAST(GETDATE() AS DATE),
|
date DATE DEFAULT CAST(GETDATE() AS DATE),
|
||||||
loja_id NVARCHAR(50),
|
loja_id VARCHAR(50),
|
||||||
code NVARCHAR(50),
|
code VARCHAR(50),
|
||||||
description NVARCHAR(255),
|
description VARCHAR(255),
|
||||||
launch NVARCHAR(50),
|
launch VARCHAR(50),
|
||||||
deactivation NVARCHAR(50),
|
deactivation VARCHAR(50),
|
||||||
thirdToLastCycleSales INT,
|
thirdToLastCycleSales INT,
|
||||||
secondToLastCycleSales INT,
|
secondToLastCycleSales INT,
|
||||||
lastCycleSales INT,
|
lastCycleSales INT,
|
||||||
@ -173,21 +173,21 @@ def create_draft_temp_table(cursor):
|
|||||||
smartPurchase_purchaseSuggestionCycle INT,
|
smartPurchase_purchaseSuggestionCycle INT,
|
||||||
smartPurchase_nextCyclePurchaseSuggestion INT,
|
smartPurchase_nextCyclePurchaseSuggestion INT,
|
||||||
pendingOrder INT,
|
pendingOrder INT,
|
||||||
salesCurve NVARCHAR(50),
|
salesCurve VARCHAR(50),
|
||||||
promotions_description NVARCHAR(MAX),
|
promotions_description NVARCHAR(MAX),
|
||||||
promotions_discountPercent NVARCHAR(MAX),
|
promotions_discountPercent NVARCHAR(MAX),
|
||||||
priceSellin FLOAT,
|
priceSellin DECIMAL(18, 2),
|
||||||
businessUnit NVARCHAR(50),
|
businessUnit VARCHAR(50),
|
||||||
codCategory NVARCHAR(255),
|
codCategory VARCHAR(255),
|
||||||
criticalItem_dtProvidedRegularization NVARCHAR(50),
|
criticalItem_dtProvidedRegularization VARCHAR(50),
|
||||||
criticalItem_blockedWallet BIT,
|
criticalItem_blockedWallet NVARCHAR(MAX),
|
||||||
criticalItem_isCritical BIT,
|
criticalItem_isCritical NVARCHAR(MAX),
|
||||||
codSubCategory NVARCHAR(255),
|
codSubCategory VARCHAR(255),
|
||||||
isProductDeactivated BIT,
|
isProductDeactivated NVARCHAR(MAX),
|
||||||
brandGroupCode NVARCHAR(50),
|
brandGroupCode VARCHAR(50),
|
||||||
daysWithoutSales INT,
|
daysWithoutSales INT,
|
||||||
coverageDays INT,
|
coverageDays INT,
|
||||||
hasCoverage BIT
|
hasCoverage VARCHAR(50)
|
||||||
)
|
)
|
||||||
END
|
END
|
||||||
""")
|
""")
|
||||||
@ -356,32 +356,14 @@ def fetch_and_insert_data(store_code, index, total, cursor, retry_count=1):
|
|||||||
def finalize_tables(cursor):
|
def finalize_tables(cursor):
|
||||||
"""
|
"""
|
||||||
Finaliza o processo:
|
Finaliza o processo:
|
||||||
1. Exclui a tabela dbo.draft
|
1. Atualiza dbo.draft_historico com os dados da dbo.draft_temp
|
||||||
2. Renomeia dbo.draft_temp para dbo.draft
|
2. Exclui a tabela dbo.draft_temp
|
||||||
3. Atualiza dbo.draft_historico com os dados do dia
|
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
print("\n=== Iniciando finalização das tabelas ===")
|
print("\n=== Iniciando finalização das tabelas ===")
|
||||||
|
|
||||||
# Passo 1: Excluir a tabela draft se existir
|
# Passo 1: Atualizar draft_historico
|
||||||
print("Passo 1: Excluindo tabela dbo.draft...")
|
print("Passo 1: Atualizando dbo.draft_historico...")
|
||||||
cursor.execute("""
|
|
||||||
IF EXISTS (SELECT * FROM sys.tables WHERE name = 'draft' AND schema_id = SCHEMA_ID('dbo'))
|
|
||||||
BEGIN
|
|
||||||
DROP TABLE dbo.draft
|
|
||||||
END
|
|
||||||
""")
|
|
||||||
conn.commit()
|
|
||||||
print("Tabela dbo.draft excluída com sucesso.")
|
|
||||||
|
|
||||||
# Passo 2: Renomear draft_temp para draft
|
|
||||||
print("Passo 2: Renomeando dbo.draft_temp para dbo.draft...")
|
|
||||||
cursor.execute("EXEC sp_rename 'dbo.draft_temp', 'draft'")
|
|
||||||
conn.commit()
|
|
||||||
print("Tabela renomeada com sucesso: dbo.draft_temp -> dbo.draft")
|
|
||||||
|
|
||||||
# Passo 3: Atualizar draft_historico
|
|
||||||
print("Passo 3: Atualizando dbo.draft_historico...")
|
|
||||||
|
|
||||||
# Obter a data de hoje
|
# Obter a data de hoje
|
||||||
today = datetime.now().strftime("%Y-%m-%d")
|
today = datetime.now().strftime("%Y-%m-%d")
|
||||||
@ -399,8 +381,8 @@ def finalize_tables(cursor):
|
|||||||
else:
|
else:
|
||||||
print(f"Nenhum registro encontrado para a data {today}.")
|
print(f"Nenhum registro encontrado para a data {today}.")
|
||||||
|
|
||||||
# Inserir dados da tabela draft na draft_historico
|
# Inserir dados da tabela draft_temp na draft_historico
|
||||||
print("Inserindo dados da dbo.draft na dbo.draft_historico...")
|
print("Inserindo dados da dbo.draft_temp na dbo.draft_historico...")
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
INSERT INTO dbo.draft_historico (
|
INSERT INTO dbo.draft_historico (
|
||||||
loja_id, code, description, launch, deactivation,
|
loja_id, code, description, launch, deactivation,
|
||||||
@ -427,7 +409,7 @@ def finalize_tables(cursor):
|
|||||||
criticalItem_dtProvidedRegularization, criticalItem_blockedWallet, criticalItem_isCritical,
|
criticalItem_dtProvidedRegularization, criticalItem_blockedWallet, criticalItem_isCritical,
|
||||||
codSubCategory, isProductDeactivated, brandGroupCode,
|
codSubCategory, isProductDeactivated, brandGroupCode,
|
||||||
daysWithoutSales, coverageDays, hasCoverage, date
|
daysWithoutSales, coverageDays, hasCoverage, date
|
||||||
FROM dbo.draft
|
FROM dbo.draft_temp
|
||||||
""")
|
""")
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
@ -436,6 +418,17 @@ def finalize_tables(cursor):
|
|||||||
inserted_count = cursor.fetchone()[0]
|
inserted_count = cursor.fetchone()[0]
|
||||||
print(f"{inserted_count} registros inseridos na dbo.draft_historico com sucesso.")
|
print(f"{inserted_count} registros inseridos na dbo.draft_historico com sucesso.")
|
||||||
|
|
||||||
|
# Passo 2: Excluir a tabela draft_temp
|
||||||
|
print("Passo 2: Excluindo tabela dbo.draft_temp...")
|
||||||
|
cursor.execute("""
|
||||||
|
IF EXISTS (SELECT * FROM sys.tables WHERE name = 'draft_temp' AND schema_id = SCHEMA_ID('dbo'))
|
||||||
|
BEGIN
|
||||||
|
DROP TABLE dbo.draft_temp
|
||||||
|
END
|
||||||
|
""")
|
||||||
|
conn.commit()
|
||||||
|
print("Tabela dbo.draft_temp excluída com sucesso.")
|
||||||
|
|
||||||
print("=== Finalização das tabelas concluída com sucesso ===\n")
|
print("=== Finalização das tabelas concluída com sucesso ===\n")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user