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 (
|
||||
id INT IDENTITY(1,1) PRIMARY KEY,
|
||||
date DATE DEFAULT CAST(GETDATE() AS DATE),
|
||||
loja_id NVARCHAR(50),
|
||||
code NVARCHAR(50),
|
||||
description NVARCHAR(255),
|
||||
launch NVARCHAR(50),
|
||||
deactivation NVARCHAR(50),
|
||||
loja_id VARCHAR(50),
|
||||
code VARCHAR(50),
|
||||
description VARCHAR(255),
|
||||
launch VARCHAR(50),
|
||||
deactivation VARCHAR(50),
|
||||
thirdToLastCycleSales INT,
|
||||
secondToLastCycleSales INT,
|
||||
lastCycleSales INT,
|
||||
@ -173,21 +173,21 @@ def create_draft_temp_table(cursor):
|
||||
smartPurchase_purchaseSuggestionCycle INT,
|
||||
smartPurchase_nextCyclePurchaseSuggestion INT,
|
||||
pendingOrder INT,
|
||||
salesCurve NVARCHAR(50),
|
||||
salesCurve VARCHAR(50),
|
||||
promotions_description NVARCHAR(MAX),
|
||||
promotions_discountPercent NVARCHAR(MAX),
|
||||
priceSellin FLOAT,
|
||||
businessUnit NVARCHAR(50),
|
||||
codCategory NVARCHAR(255),
|
||||
criticalItem_dtProvidedRegularization NVARCHAR(50),
|
||||
criticalItem_blockedWallet BIT,
|
||||
criticalItem_isCritical BIT,
|
||||
codSubCategory NVARCHAR(255),
|
||||
isProductDeactivated BIT,
|
||||
brandGroupCode NVARCHAR(50),
|
||||
priceSellin DECIMAL(18, 2),
|
||||
businessUnit VARCHAR(50),
|
||||
codCategory VARCHAR(255),
|
||||
criticalItem_dtProvidedRegularization VARCHAR(50),
|
||||
criticalItem_blockedWallet NVARCHAR(MAX),
|
||||
criticalItem_isCritical NVARCHAR(MAX),
|
||||
codSubCategory VARCHAR(255),
|
||||
isProductDeactivated NVARCHAR(MAX),
|
||||
brandGroupCode VARCHAR(50),
|
||||
daysWithoutSales INT,
|
||||
coverageDays INT,
|
||||
hasCoverage BIT
|
||||
hasCoverage VARCHAR(50)
|
||||
)
|
||||
END
|
||||
""")
|
||||
@ -356,32 +356,14 @@ def fetch_and_insert_data(store_code, index, total, cursor, retry_count=1):
|
||||
def finalize_tables(cursor):
|
||||
"""
|
||||
Finaliza o processo:
|
||||
1. Exclui a tabela dbo.draft
|
||||
2. Renomeia dbo.draft_temp para dbo.draft
|
||||
3. Atualiza dbo.draft_historico com os dados do dia
|
||||
1. Atualiza dbo.draft_historico com os dados da dbo.draft_temp
|
||||
2. Exclui a tabela dbo.draft_temp
|
||||
"""
|
||||
try:
|
||||
print("\n=== Iniciando finalização das tabelas ===")
|
||||
|
||||
# Passo 1: Excluir a tabela draft se existir
|
||||
print("Passo 1: Excluindo tabela dbo.draft...")
|
||||
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...")
|
||||
# Passo 1: Atualizar draft_historico
|
||||
print("Passo 1: Atualizando dbo.draft_historico...")
|
||||
|
||||
# Obter a data de hoje
|
||||
today = datetime.now().strftime("%Y-%m-%d")
|
||||
@ -399,8 +381,8 @@ def finalize_tables(cursor):
|
||||
else:
|
||||
print(f"Nenhum registro encontrado para a data {today}.")
|
||||
|
||||
# Inserir dados da tabela draft na draft_historico
|
||||
print("Inserindo dados da dbo.draft na dbo.draft_historico...")
|
||||
# Inserir dados da tabela draft_temp na draft_historico
|
||||
print("Inserindo dados da dbo.draft_temp na dbo.draft_historico...")
|
||||
cursor.execute("""
|
||||
INSERT INTO dbo.draft_historico (
|
||||
loja_id, code, description, launch, deactivation,
|
||||
@ -427,7 +409,7 @@ def finalize_tables(cursor):
|
||||
criticalItem_dtProvidedRegularization, criticalItem_blockedWallet, criticalItem_isCritical,
|
||||
codSubCategory, isProductDeactivated, brandGroupCode,
|
||||
daysWithoutSales, coverageDays, hasCoverage, date
|
||||
FROM dbo.draft
|
||||
FROM dbo.draft_temp
|
||||
""")
|
||||
conn.commit()
|
||||
|
||||
@ -436,6 +418,17 @@ def finalize_tables(cursor):
|
||||
inserted_count = cursor.fetchone()[0]
|
||||
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")
|
||||
return True
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user