xyc
2026-08-14 1f4a6cc6045f47861c3e8d49a782afc3e11e3843
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# -*- coding: utf-8 -*-
import io
path = r'C:\Users\jcxiong\Documents\Codex\MyProject\trafficAudit\traffic-audit-server\src\main\java\com\trafficaudit\reportexport\service\ReportExportService.java'
with io.open(path, encoding='utf-8') as f:
    content = f.read()
has_crlf = '\r\n' in content
lines = content.split('\n')
 
def patch_func(func, rowidx_from, rowidx_to, unit_from, unit_to):
    start = next(i for i, l in enumerate(lines) if l.strip().startswith('public byte[] ' + func + '('))
    end = len(lines)
    for i in range(start+1, len(lines)):
        if lines[i].strip().startswith('public byte[] '):
            end = i
            break
    cnt_r = cnt_u = 0
    for i in range(start, end):
        if lines[i].strip() == 'int rowIdx = ' + rowidx_from + ';':
            lines[i] = lines[i].replace('int rowIdx = ' + rowidx_from + ';', 'int rowIdx = ' + rowidx_to + ';')
            cnt_r += 1
        if '"' + unit_from + '"' in lines[i]:
            lines[i] = lines[i].replace('"' + unit_from + '"', '"' + unit_to + '"')
            cnt_u += 1
    print(func, '-> rowIdx:', cnt_r, '| unit:', cnt_u)
 
patch_func('exportFreightRank', '3', '1', '万吨', '吨')
patch_func('exportTurnoverRank', '3', '1', '万吨公里', '吨公里')
 
new_content = '\n'.join(lines)
if has_crlf:
    new_content = new_content.replace('\n', '\r\n')
with io.open(path, 'w', encoding='utf-8', newline='') as f:
    f.write(new_content)
print('saved')