From 46ba6828484b2600338e2451fe06efb9d8046f1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=B0=A7?= Date: Sun, 27 Apr 2025 14:26:31 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jikimo_work_reporting_api/controllers/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jikimo_work_reporting_api/controllers/main.py b/jikimo_work_reporting_api/controllers/main.py index c3ea7daa..189c2d0a 100644 --- a/jikimo_work_reporting_api/controllers/main.py +++ b/jikimo_work_reporting_api/controllers/main.py @@ -59,7 +59,7 @@ class MainController(http.Controller): target_ftp_info, '/' + str(model_id), '/', - match_str=r'^\d*_\d*-' + tool_groups_id.name + r'-\w{2}-all\.nc$' + match_str=r'^\d*-' + tool_groups_id.name + r'-\w{2}-all\.nc$' ) if len(result) > 0: return {'code': 200, 'message': '传输成功', 'file_list': result} From 72415d633ca090bed67e78b49ce948cc222f5e2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=B0=A7?= Date: Sun, 27 Apr 2025 14:36:13 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E9=80=80=E5=9B=9E=E5=AD=97=E4=BD=93?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_base/commons/common.py | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/sf_base/commons/common.py b/sf_base/commons/common.py index 5190772f..aa27c46f 100644 --- a/sf_base/commons/common.py +++ b/sf_base/commons/common.py @@ -129,23 +129,23 @@ class PrintingUtils(models.AbstractModel): output_temp_path = '/tmp/output_temp.pdf' try: + # 使用reportlab创建一个新的PDF + + # 注册中文字体 font_paths = [ - "c:/windows/fonts/simsun.ttc", # Windows系统宋体 "/usr/share/fonts/windows/simsun.ttc", # Windows系统宋体 + "c:/windows/fonts/simsun.ttc", # Windows系统宋体另一个位置 "/usr/share/fonts/truetype/droid/DroidSansFallbackFull.ttf", # Linux Droid字体 "/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc", # 文泉驿正黑 "/usr/share/fonts/chinese/TrueType/simsun.ttc", # 某些Linux发行版位置 - "/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc", # Noto Sans CJK ] font_found = False for font_path in font_paths: if os.path.exists(font_path): try: - # 注册两个字体,一个用于中文,一个用于数字 pdfmetrics.registerFont(TTFont('SimSun', font_path)) - pdfmetrics.registerFont(TTFont('Arial', 'c:/windows/fonts/arial.ttf')) font_found = True break except: @@ -167,7 +167,7 @@ class PrintingUtils(models.AbstractModel): # 设置字体 if font_found: - c.setFont('SimSun', 10) # 用于中文文本 + c.setFont('SimSun', 10) # 增大字体大小到14pt else: # 如果没有找到中文字体,使用默认字体 c.setFont('Helvetica', 10) @@ -181,23 +181,11 @@ class PrintingUtils(models.AbstractModel): if buttom_text: # 在二维码下方绘制文字 - # 分离中文和数字 - import re - text_parts = re.split('(\d+)', buttom_text) - text_x = page_width - qr_size - margin + (qr_size - c.stringWidth(buttom_text, "SimSun", 10)) / 2 - text_y = margin + 20 - - current_x = text_x - for part in text_parts: - if part: # 跳过空字符串 - if part.isdigit(): - c.setFont('Arial', 10) # 数字使用Arial字体 - current_font = 'Arial' - else: - c.setFont('SimSun', 10) # 中文使用宋体 - current_font = 'SimSun' - c.drawString(current_x, text_y, part) - current_x += c.stringWidth(part, current_font, 10) + text = buttom_text + text_width = c.stringWidth(text, "SimSun" if font_found else "Helvetica", 10) # 准确计算文字宽度 + text_x = page_width - qr_size - margin + (qr_size - text_width) / 2 # 文字居中对齐 + text_y = margin + 20 # 文字位置靠近底部 + c.drawString(text_x, text_y, text) c.save() @@ -229,4 +217,5 @@ class PrintingUtils(models.AbstractModel): if os.path.exists(qr_temp_path): os.remove(qr_temp_path) if os.path.exists(output_temp_path): + os.remove(output_temp_path) os.remove(output_temp_path) \ No newline at end of file From 57789dc5a52bbf08794fa4ab373802f0e2bdb5cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=B0=A7?= Date: Sun, 27 Apr 2025 15:10:22 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=8A=E4=BC=A0ftp?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_machine_connect/models/ftp_operate.py | 46 ++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/sf_machine_connect/models/ftp_operate.py b/sf_machine_connect/models/ftp_operate.py index 8265b351..89230170 100644 --- a/sf_machine_connect/models/ftp_operate.py +++ b/sf_machine_connect/models/ftp_operate.py @@ -261,8 +261,50 @@ def transfer_files( target_path = f"{target_dir}/{relative_path}/{item}" else: target_path = f"{target_dir}/{item}" - with open(temp_path, 'rb') as f: - target_ftp.ftp.storbinary(f'STOR {target_path}', f) + + # 规范化路径 + target_path = target_path.replace('\\', '/').strip('/') + + # 确保目标目录存在 + target_dir_path = '/'.join(target_path.split('/')[:-1]) + try: + target_ftp.ftp.cwd('/') # 回到根目录 + for dir_part in target_dir_path.split('/'): + if dir_part: + try: + target_ftp.ftp.cwd(dir_part) + except: + try: + target_ftp.ftp.mkd(dir_part) + target_ftp.ftp.cwd(dir_part) + except Exception as e: + logging.error(f"创建目录失败 {dir_part}: {str(e)}") + raise + except Exception as e: + logging.error(f"处理目标目录失败: {str(e)}") + raise + + # 检查FTP连接状态 + try: + target_ftp.ftp.voidcmd('NOOP') + except: + logging.error("FTP连接已断开,尝试重新连接") + target_ftp.ftp.connect(target_ftp_info['host'], target_ftp_info['port']) + target_ftp.ftp.login(target_ftp_info['username'], target_ftp_info['password']) + + # 上传文件 + try: + with open(temp_path, 'rb') as f: + # 检查文件是否可读 + content = f.read() + if not content: + raise Exception("临时文件为空") + f.seek(0) # 重置文件指针 + target_ftp.ftp.storbinary(f'STOR {target_path}', f) + except Exception as e: + logging.error(f"上传文件失败: {str(e)}") + logging.error(f"目标路径: {target_path}") + raise transfered_file_list.append(item) # 删除临时文件 From 404c56e1348fe79edd811f91184a45a24775481f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=B0=A7?= Date: Sun, 27 Apr 2025 15:24:28 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=B1=8F=E8=94=BD=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_machine_connect/models/ftp_operate.py | 56 ++++++++++++------------ 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/sf_machine_connect/models/ftp_operate.py b/sf_machine_connect/models/ftp_operate.py index 89230170..b6724588 100644 --- a/sf_machine_connect/models/ftp_operate.py +++ b/sf_machine_connect/models/ftp_operate.py @@ -312,37 +312,37 @@ def transfer_files( logging.info(f"已传输文件: {item}") # 清空目标目录下的所有内容 - try: - target_ftp.ftp.cwd(target_dir) - files = target_ftp.ftp.nlst() + # try: + # target_ftp.ftp.cwd(target_dir) + # files = target_ftp.ftp.nlst() - for f in files: - try: - # 尝试删除文件 - target_ftp.ftp.delete(f) - except: - try: - # 如果删除失败,可能是目录,递归删除目录 - def remove_dir(path): - target_ftp.ftp.cwd(path) - sub_files = target_ftp.ftp.nlst() - for sf in sub_files: - try: - target_ftp.ftp.delete(sf) - except: - remove_dir(f"{path}/{sf}") - target_ftp.ftp.cwd('..') - target_ftp.ftp.rmd(path) + # for f in files: + # try: + # # 尝试删除文件 + # target_ftp.ftp.delete(f) + # except: + # try: + # # 如果删除失败,可能是目录,递归删除目录 + # def remove_dir(path): + # target_ftp.ftp.cwd(path) + # sub_files = target_ftp.ftp.nlst() + # for sf in sub_files: + # try: + # target_ftp.ftp.delete(sf) + # except: + # remove_dir(f"{path}/{sf}") + # target_ftp.ftp.cwd('..') + # target_ftp.ftp.rmd(path) - remove_dir(f"{target_dir}/{f}") - except: - logging.error(f"无法删除 {f}") - pass + # remove_dir(f"{target_dir}/{f}") + # except: + # logging.error(f"无法删除 {f}") + # pass - logging.info(f"已清空目标目录 {target_dir}") - except Exception as e: - logging.error(f"清空目标目录失败: {str(e)}") - raise Exception(f"清空目标目录失败: {str(e)}") + # logging.info(f"已清空目标目录 {target_dir}") + # except Exception as e: + # logging.error(f"清空目标目录失败: {str(e)}") + # raise Exception(f"清空目标目录失败: {str(e)}") # 开始遍历 traverse_dir(source_dir) From ed90ad34e69c34861bb73c9f894c129ba19dacc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=B0=A7?= Date: Sun, 27 Apr 2025 15:32:08 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E9=80=80=E5=9B=9E=E5=AD=97=E4=BD=93?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_base/commons/common.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sf_base/commons/common.py b/sf_base/commons/common.py index aa27c46f..30c06b6d 100644 --- a/sf_base/commons/common.py +++ b/sf_base/commons/common.py @@ -217,5 +217,4 @@ class PrintingUtils(models.AbstractModel): if os.path.exists(qr_temp_path): os.remove(qr_temp_path) if os.path.exists(output_temp_path): - os.remove(output_temp_path) os.remove(output_temp_path) \ No newline at end of file