init 5377
Showing
1 changed file
with
47 additions
and
0 deletions
... | @@ -498,6 +498,8 @@ class BSWorkbook(Workbook, LoggerMixin): | ... | @@ -498,6 +498,8 @@ class BSWorkbook(Workbook, LoggerMixin): |
498 | return row_value | 498 | return row_value |
499 | 499 | ||
500 | def build_month_sheet(self, ms, role_name, card, month_mapping, is_reverse, statistics_header_info, max_column, classify): | 500 | def build_month_sheet(self, ms, role_name, card, month_mapping, is_reverse, statistics_header_info, max_column, classify): |
501 | self.online_log.warn('{0} [build_month_sheet] [role_name={1}] [card={2}] [month_mapping={3}] [is_reverse={4}] [statistics_header_info={5}] [max_column={6}]'.format( | ||
502 | self.log_base, role_name, card, month_mapping, is_reverse, statistics_header_info, max_column)) | ||
501 | summary_cell_idx = statistics_header_info.get(consts.SUMMARY_KEY) | 503 | summary_cell_idx = statistics_header_info.get(consts.SUMMARY_KEY) |
502 | date_cell_idx = statistics_header_info.get(consts.DATE_KEY) | 504 | date_cell_idx = statistics_header_info.get(consts.DATE_KEY) |
503 | amount_cell_idx = statistics_header_info.get(consts.AMOUNT_KEY) # None or src or append | 505 | amount_cell_idx = statistics_header_info.get(consts.AMOUNT_KEY) # None or src or append |
... | @@ -506,6 +508,8 @@ class BSWorkbook(Workbook, LoggerMixin): | ... | @@ -506,6 +508,8 @@ class BSWorkbook(Workbook, LoggerMixin): |
506 | outlay_cell_idx = statistics_header_info.get(consts.OUTLAY_KEY) | 508 | outlay_cell_idx = statistics_header_info.get(consts.OUTLAY_KEY) |
507 | borrow_cell_idx = statistics_header_info.get(consts.BORROW_KEY) | 509 | borrow_cell_idx = statistics_header_info.get(consts.BORROW_KEY) |
508 | header = list(statistics_header_info.get(consts.HEADER_KEY)) | 510 | header = list(statistics_header_info.get(consts.HEADER_KEY)) |
511 | self.online_log.warn('{0} [build_month_sheet] [summary_cell_idx={1}] [date_cell_idx={2}] [amount_cell_idx={3}] [over_cell_idx={4}] [income_cell_idx={5}] [outlay_cell_idx={6}] [borrow_cell_idx={7}]'.format( | ||
512 | self.log_base, summary_cell_idx, date_cell_idx, amount_cell_idx, over_cell_idx, income_cell_idx, outlay_cell_idx, borrow_cell_idx)) | ||
509 | src_header_len = len(header) | 513 | src_header_len = len(header) |
510 | if max_column > src_header_len: | 514 | if max_column > src_header_len: |
511 | for i in range(max_column - src_header_len): | 515 | for i in range(max_column - src_header_len): |
... | @@ -809,6 +813,49 @@ class BSWorkbook(Workbook, LoggerMixin): | ... | @@ -809,6 +813,49 @@ class BSWorkbook(Workbook, LoggerMixin): |
809 | for sheet in sheets_list: | 813 | for sheet in sheets_list: |
810 | self.remove(self.get_sheet_by_name(sheet)) | 814 | self.remove(self.get_sheet_by_name(sheet)) |
811 | 815 | ||
816 | # 5.新增统计项 | ||
817 | # jyds_per_month 统计主要交易对手,按月提示交易频繁的交易对手信息(如前三名对手姓名及交易总金额) | ||
818 | jyds_per_month = {} | ||
819 | sheet_date_pattern = re.compile(r'^\d{4}-\d{2}') | ||
820 | number_of_sheets = len(self.worksheets) | ||
821 | self.online_log.warn('{0} [bs_rebuild new ==========>] [number_of_sheets={1}]'.format(self.log_base, number_of_sheets)) | ||
822 | for sheet in self.worksheets: | ||
823 | sheet_name = sheet.title | ||
824 | #self.online_log.warn('{0} [bs_rebuild new ==========>] [sheet name={1}]'.format(self.log_base, sheet_name)) | ||
825 | #for row in sheet.iter_rows(values_only=True): | ||
826 | # self.online_log.warn('{0} [bs_rebuild new ==========>] [sheet row={1}]'.format( | ||
827 | # self.log_base, row)) | ||
828 | # self.online_log.warn('-' * 40) | ||
829 | if sheet_date_pattern.match(sheet_name[:7]): | ||
830 | self.online_log.warn('{0} [bs_rebuild new ==========>] [sheet name={1}] 的前7位满足 yyyy-MM 格式'.format(self.log_base, sheet_name)) | ||
831 | # 月明细sheet中,统计jyds_per_month信息 | ||
832 | jyds_name_idx = -1 | ||
833 | jyds_amount_idx = -1 | ||
834 | for row in sheet.iter_rows(min_row=1, max_row=1, values_only=True): | ||
835 | for cell_idx, cell_value in row: | ||
836 | if cell_value == '交易对手': | ||
837 | jyds_name_idx = cell_idx | ||
838 | if cell_value == '金额': | ||
839 | jyds_amount_idx = cell_idx | ||
840 | one_month_detail = {} | ||
841 | for row in sheet.iter_rows(min_row=2, values_only=True): | ||
842 | jyds_name = row[jyds_name_idx] | ||
843 | jyds_amount = row[jyds_amount_idx] | ||
844 | if jyds_amount is None or jyds_amount == "": | ||
845 | jyds_amount_float = 0.0 | ||
846 | else: | ||
847 | jyds_amount_float = float(jyds_amount) | ||
848 | if jyds_name in one_month_detail: | ||
849 | one_month_detail[jyds_name] += jyds_amount_float | ||
850 | else: | ||
851 | one_month_detail[jyds_name] = jyds_amount_float | ||
852 | sorted_data = sorted(one_month_detail.items(), key=lambda x: int(x[1]), reverse=True)[:3] | ||
853 | jyds_per_month[sheet_name] = sorted_data | ||
854 | else: | ||
855 | self.online_log.warn('{0} [bs_rebuild new ==========>] [sheet name={1}] 的前7位不满足 yyyy-MM 格式'.format(self.log_base, sheet_name)) | ||
856 | self.online_log.warn('{0} [bs_rebuild new ==========>] [jyds_per_month={1}]'.format(self.log_base, jyds_per_month)) | ||
857 | |||
858 | |||
812 | def license_rebuild(self, license_summary, document_scheme, count_list): | 859 | def license_rebuild(self, license_summary, document_scheme, count_list): |
813 | for classify, (_, name, field_order, side_diff, scheme_diff, field_str) in consts.LICENSE_ORDER: | 860 | for classify, (_, name, field_order, side_diff, scheme_diff, field_str) in consts.LICENSE_ORDER: |
814 | license_list = license_summary.get(classify) | 861 | license_list = license_summary.get(classify) | ... | ... |
-
Please register or sign in to post a comment