
from base_class import *
from base_class import BaseVariableFunction
from openpyxl.utils import get_column_letter, column_index_from_string
from openpyxl.styles import PatternFill
import openpyxl
import shutil


# # openpyxl填充色说明
# # 调用openpyxl中PatternFill
# # 纯色填充使用solid


baseclass = BaseVariableFunction(__file__)
old_print = print


def timestamped_print(*args, **kwargs):
    old_print(datetime.datetime.utcnow().replace(
        microsecond=0), *args, **kwargs)


print = timestamped_print

print('\n'*5)
print(f"{'{:<6}'.format('ENTER')} {baseclass.scriptfilename} ----------------NOTE-----------NOTE---------------")


def analysisprofit_handle_sum(read_excel_pathname):
    wb = openpyxl.load_workbook(read_excel_pathname)
    ws = wb.active
    col_range = ws.max_column
    row_range = ws.max_row
    for col_idx in range(1, col_range+1):
     # 设置列宽
        if col_idx == 1:
            ws.column_dimensions[get_column_letter(col_idx)].width = 11
    wb.save(read_excel_pathname)


def modify_excel_style(read_excel_pathname):
    # 使用openpyxl读取xlsx文件，创建workbook
    wb = openpyxl.load_workbook(read_excel_pathname)
    ws = wb.active
    col_range = ws.max_column
    row_range = ws.max_row
    for col_idx in range(1, col_range+1):
     # 设置列宽
        ws.column_dimensions[get_column_letter(col_idx)].width = 5
        col_header = ws.cell(row=1, column=col_idx).value
        col_header_list = col_header.split("_")
        if col_header_list[0] not in ["03d", "07d", "11d", "15d"]:
            continue
        col_header_list.pop(0)
        coltype = "_".join(col_header_list)
        match coltype:
            # case "earnper":
            #     fill = PatternFill('darkDown', fgColor='80C530')
            #     for row_idx in range(1, row_range+1):
            #         ws.cell(row=row_idx, column=col_idx).fill = fill
            # case "difper":
            #     fill = PatternFill('darkDown', fgColor='00B050')
            #     for row_idx in range(1, row_range+1):
            #         ws.cell(row=row_idx, column=col_idx).fill = fill
            # case "cost_noaddouttoken":
            #     fill = PatternFill('solid', fgColor='FEB8B8')
            #     for row_idx in range(1, row_range+1):
            #         ws.cell(row=row_idx, column=col_idx).fill = fill
            # case "earn_noaddouttoken":
            #     fill = PatternFill('solid', fgColor='9FF3A0')
            #     for row_idx in range(1, row_range+1):
            #         ws.cell(row=row_idx, column=col_idx).fill = fill
            # case "earnper_noaddouttoken":
            #     fill = PatternFill('solid', fgColor='80C530')
            #     for row_idx in range(1, row_range+1):
            #         ws.cell(row=row_idx, column=col_idx).fill = fill
            # case "difcost_noaddouttoken":
            #     fill = PatternFill('solid', fgColor='FF0000')
            #     for row_idx in range(1, row_range+1):
            #         ws.cell(row=row_idx, column=col_idx).fill = fill
            # case "difearn_noaddouttoken":
            #     fill = PatternFill('solid', fgColor='C4D79B')
            #     for row_idx in range(1, row_range+1):
            #         ws.cell(row=row_idx, column=col_idx).fill = fill
            # case "difper_noaddouttoken":
            #     fill = PatternFill('solid', fgColor='00B050')
            #     for row_idx in range(1, row_range+1):
            #         ws.cell(row=row_idx, column=col_idx).fill = fill
            case "mine_noadd_fir_earnper":
                fill = PatternFill('solid', fgColor='00FF00')
                for row_idx in range(1, row_range+1):
                    ws.cell(row=row_idx, column=col_idx).fill = fill
            case "mine_noadd_fir_earnper_dropmax":
                fill = PatternFill('solid', fgColor='008000')
                for row_idx in range(1, row_range+1):
                    ws.cell(row=row_idx, column=col_idx).fill = fill
            case "trans":
                fill = PatternFill('solid', fgColor='FFFF00')
                for row_idx in range(1, row_range+1):
                    ws.cell(row=row_idx, column=col_idx).fill = fill
    wb.save(read_excel_pathname)


modify_excel_style(
    read_excel_pathname=baseclass.dalao_total_ana_fm_path/f"totalana.xlsx")

modify_excel_style(
    read_excel_pathname=baseclass.dalao_total_ana_fm_path/f"increase_totalana.xlsx")


print(f"{'{:<6}'.format('END')} {baseclass.scriptfilename} ----------------NOTE-----------NOTE---------------")

# =IF(BJ2-BS2<=0.01,0,BJ2-BS2)
