def processProfitUpdate(self): print("正在读取文件...") Logger.addLog("READ profit!!") profitList = self.__readProfit() print("正在写入文件...") Logger.addLog("WRITE profit!!") self.__writeProfit(profitList)
def addError(ErrorList, _error): Logger.addLog(_error.toString()) if type(_error) == Error: ErrorList.__errorList.append(_error) elif type(_error) == Warning: ErrorList.__warningList.append(_error) elif type(_error) == NotFound: ErrorList.__notFoundList.append(_error)
def __init__(self, path = ""): Logger.addLog("CREAT NotFound: " + path) if path == "": self.notfoundBook = Workbook() self.path = "notfound.xlsx" else: try: self.notfoundBook = load_workbook(path) self.path = path except: processException()
def getNotfoundTable(self): Logger.addLog("GET notfoundTable!!") try: if len(self.notfoundBook.sheetnames) == 0: notfoundTable = self.notfoundBook.active self.__initNotFoundTable(notfoundTable) else: notfoundTable = self.notfoundBook[self.notfoundBook.sheetnames[0]] return notfoundTable except: processException()
def getReportPath(path, _tips, onlyXlsx = True, canSkip = False): _count = 0 _pathList = [] _isXls = False _files = listdir(path) # print file list for _file in _files: # 去除文件夹,非.xlsx文件以及临时文件 if (not osPath.isdir(path + '/' + _file)) and "~$" not in _file: if ".xlsx" in _file or (not onlyXlsx and ".xls" in _file): _count += 1 _pathList.append(path + '/' + _file) print(str(_count) + "、" + _file) # only at the onlyxlsx mode, will send the warning if onlyXlsx and ".xls" in _file and ".xlsx" not in _file : _isXls = True # do not find file if _count == 0: ErrorList.addError(Error("./", "do not find files")) print("do not find files") return None # warning find .xls file if _isXls: ErrorList.addError(Warning("./", "We have found .xls file in report list")) # input file number _index = 0 _tipStr = "input number to choose {} file{}:".format(_tips, "(zero for skipping)" if canSkip else "") while _index <= 0 or _index > _count: _input = input(_tipStr) if _input == "" or not _input.isdigit(): continue _index = int(_input) if canSkip and _index == 0 : return None if _index < 0 or _index > _count: print("wrong number\n") # output \n print("\n") Logger.addLog("GET {} PATH!! Path = {}".format(_tips, _pathList[_index - 1])) return _pathList[_index - 1]
def __init__(self, originPath, updatePath): Logger.addLog("CREATE profit! originPath = {}, updatePath = {}".format( originPath, updatePath)) self.updatePath = updatePath try: originBook = open_workbook(originPath) self.originTable = originBook.sheet_by_index(0) self.updateBook = load_workbook(updatePath) self.updateTable = self.updateBook[self.updateBook.sheetnames[0]] self.pidDict = self.__setupDict() except: processException()
def processRefundInfo(self, _filePath): try: Logger.addLog("OPEN REFUND FILE!! Path = " + _filePath) _refundBook = open_workbook(_filePath, formatting_info=True) _refundSheets = _refundBook.sheets() except Exception: processException() for _refundsheet in _refundSheets: _infoType = _refundsheet.name print("正在处理 " + _infoType + " 退款金额...") Logger.addLog("PROCESS {} 退款".format(_infoType)) _refundInfoList = self.__getRefundInfo(_refundsheet) self.__setRefundInfo(_infoType, _refundInfoList)
def doCommand(): # forever loop while True: # split the command and remove the none cmdLine = input(">>-->") Logger.addLog("COMMAND: " + cmdLine) if cmdLine == "": continue cmdList = cmdLine.strip().split(" ") for cmdIteration in cmdList: if cmdIteration == '': cmdList.remove(cmdIteration) # we have no different cmd now, so ignore it # cmd = cmdList[0] index = 1 result = {} while index < len(cmdList): # if it is the path Argument, then save it if cmdList[index] in pathArguDict: index += 1 if index >= len(cmdList): Logger.addLog("DATA NONE: " + cmdList[index - 1]) print("data none!!" + cmdList[index - 1]) break elif cmdList[index - 1] != "-sa" and not utils.is_excel_file( cmdList[index]): Logger.addLog("DATA ERROR, NOT EXCEL FILE : " + cmdList[index - 1]) print("DATA ERROR!!NOT EXCEL FILE!!" + cmdList[index - 1]) break else: Logger.addLog("COMMAND: {}, DATA: {}".format( cmdList[index - 1], cmdList[index])) result[pathArguDict[cmdList[index - 1]]] = cmdList[index] index += 1 elif cmdList[index] in systemArguDict: Logger.addLog("COMMAND: {}".format(cmdList[index])) systemArguDict[cmdList[index]]() break else: Logger.addLog("COMMAND ERROR:" + cmdList[index]) print("command error! " + cmdList[index]) break # 处理金额和退款 if "salePath" in result and "summaryPath" in result: Logger.addLog("process SA ") try: summary = load_workbook(result["summaryPath"]) except: processException() # get the notfound table notfoundPath = result[ "notfoundTable"] if "notfoundPath" in result else "" NF = notfound.NotFound(notfoundPath) notfoundTable = NF.getNotfoundTable() # process salesAmount SA = saleAmount.SaleAmount(summary, notfoundTable) SA.processDir(result["salePath"]) if "refundPath" in result: # process refund Logger.addLog("process RF ") RF = refund.Refund(summary, notfoundTable) RF.processRefundInfo(result["refundPath"]) # save file savePath = result[ "savePath"] if "savePath" in result else "summary.xlsx" summary.save(savePath) Logger.addPrefabLog(Logger.LOG_TYPE_SAVE, savePath) NF.save() # 处理退款 elif "summaryPath" in result and "refundPath" in result: Logger.addLog("process RF ") try: summary = load_workbook(result["summaryPath"]) except: processException() # get the notfound table notfoundPath = result[ "notfoundTable"] if "notfoundPath" in result else "" NF = notfound.NotFound(notfoundPath) notfoundTable = NF.getNotfoundTable() # process refund RF = refund.Refund(summary, notfoundTable) RF.processRefundInfo(result["refundPath"]) # save file savePath = result[ "savePath"] if "savePath" in result else "summary.xlsx" summary.save(savePath) NF.save() Logger.addPrefabLog(Logger.LOG_TYPE_SAVE, savePath) # 更新成本 elif "originPath" in result and "updatePath" in result: Logger.addLog("process PF ") PF = profit.Profit(result["originPath"], result["updatePath"]) PF.processProfitUpdate() savePath = result["savePath"] if "savePath" in result else "" PF.save(savePath) # print if len(result) != 0: ErrorList.printErrorList()
def __setInfo(self, _platform, _infoType, _infoList, _path): try: # find the infotype table if _infoType not in self.__summary.sheetnames: ErrorList.addError( Error(_path, "can not find correct sheet: " + _infoType)) return reportTable = self.__summary[_infoType] # to find the index of platform index, offset = utils.findPlatformIndex(reportTable, _platform) if index == -1: ErrorList.addError( Error(_path, "can not find correct platform: " + _platform)) return # for each data in infoList to write down in the report for infoInstance in _infoList: isFind = False # to mark the account is finded or not for row in range(index, index + offset): reportAccount = reportTable["D" + str(row)].value reportLocationList = reportTable["F" + str(row)].value.split(' ') reportLocation = reportLocationList[1] if len( reportLocationList) > 1 else reportLocationList[0] # to match corret account and location row if infoInstance.account == reportAccount and infoInstance.location == reportLocation: isFind = True self.__correctCount += 1 # if the name is wrong, then change the name reportName = reportTable["E" + str(row)].value if infoInstance.name != reportName: reportTable["E" + str(row)].value = infoInstance.name reportTable["F" + str( row )].value = infoInstance.name + " " + infoInstance.location # to judge the normal is true or not if infoInstance.normal: # if normal, then write down the salesAmount and profitRate reportTable[ "G" + str(row)].value = infoInstance.salesAmount reportTable[ "H" + str(row)].value = infoInstance.profitRate else: # else write down the margin reportTable[ "J" + str(row)].value = infoInstance.salesAmount # write down and break the for loop break if isFind: continue else: # insert a new row xlsutils.insert_rows(reportTable, index + offset + 1, True) offset += 1 # write the data row = index + offset reportTable["B" + str(row)].value = _infoType reportTable["D" + str(row)].value = infoInstance.account reportTable["E" + str(row)].value = infoInstance.name reportTable["F" + str( row )].value = infoInstance.name + " " + infoInstance.location if infoInstance.normal: reportTable["G" + str(row)].value = infoInstance.salesAmount reportTable["H" + str(row)].value = infoInstance.profitRate else: reportTable["J" + str(row)].value = infoInstance.salesAmount # set red color xlsutils.setColor(reportTable["D" + str(row)], "red") self.__failCount += 1 Logger.addLog("新增插入一行,插入时行号 {},账号 {}".format( row, infoInstance.account)) ErrorList.addError( NotFound(_path, "存在新增数据,请自行插入,数据已录入 notfound.xlsx")) self.__processNotFoundInfo(_platform, _infoType, infoInstance) except Exception: processException()
def __init__(self, _summary, _notfoundTable): Logger.addLog("CREATE refund!!") self.summary = _summary self.notfoundTable = _notfoundTable self.__correctCount = 0 self.__failCount = 0
import command import guide from log import Logger from error import ErrorList from os import system print("欢迎使用6.0版本的本系统了(连名字都没有,哎呀我去") print("有不懂不要问,去命令行模式输入 do -help ") print("汇总文件仅支持“.xlsx“格式, 退款文件仅支持”.xls“格式,出错了检查一下是不是这个问题\n") mode = input("输入点东西就进入命令行模式,啥也不输就进入引导模式:") if mode == "": Logger.addLog("输入:{},进入引导模式。".format(mode)) guide.doGuide("../data") else: Logger.addLog("输入:{},进入命令模式。".format(mode)) command.doCommand() ErrorList.printErrorList() Logger.writeLog() system("pause")