This commit is contained in:
dongchangxi committed 2025-11-21 17:22:22 +08:00
1 parent 7c37ee63e9
commit e3ae862300
5 files changed
+683

No files matched your search

+57
View File
@@ -0,0 +1,57 @@
@echo off
chcp 65001 >nul
echo ========================================
echo 开始打包 type_setting_order.py 为 exe
echo ========================================
echo.
REM 检查 Python 是否安装
python --version >nul 2>&1
if errorlevel 1 (
echo [错误] 未找到 Python,请先安装 Python
pause
exit /b 1
)
echo [1/4] 检查并安装依赖包...
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
if errorlevel 1 (
echo [错误] 依赖包安装失败
pause
exit /b 1
)
echo.
echo [2/4] 清理之前的构建文件...
if exist build rmdir /s /q build
if exist dist rmdir /s /q dist
if exist __pycache__ rmdir /s /q __pycache__
echo.
echo [3/4] 使用 PyInstaller 打包...
python -m PyInstaller build_exe.spec
if errorlevel 1 (
echo [错误] 打包失败
pause
exit /b 1
)
echo.
echo [4/4] 打包完成!
echo.
echo ========================================
echo 打包结果:
echo ========================================
echo exe 文件位置: dist\type_setting_order.exe
echo.
echo 注意事项:
echo 1. 确保 Windows 系统上已安装 Visual C++ Redistributable
echo 2. 确保 Redis 服务可访问(172.31.1.254:6379)
echo 3. 确保网络连接正常(访问 OSS 和 API)
echo 4. 如果程序需要调用 download_print_out.py,请确保该文件在同一目录
echo.
pause
+5
View File
@@ -0,0 +1,5 @@
redis>=4.0.0
oss2>=2.17.0
requests>=2.28.0
pyinstaller>=5.0.0
@@ -0,0 +1,134 @@
import os
import redis
import oss2,time,sys
import requests
currentDir = os.path.dirname(os.path.abspath(__file__))
ENV = 'dev'
url = 'https://mp.api.suwa3d.com'
if ENV == 'dev':
url = 'http://mp.dev.api.com'
elif ENV == 'prod':
url = 'https://mp.api.suwa3d.com'
# 连接oss - 单例模式
class OSSClientSingleton:
_instance = None
_client = None
def __new__(cls):
if cls._instance is None:
cls._instance = super(OSSClientSingleton, cls).__new__(cls)
return cls._instance
def get_client(self):
if self._client is None:
AccessKeyId = 'LTAI5tSReWm8hz7dSYxxth8f'
AccessKeySecret = '8ywTDF9upPAtvgXtLKALY2iMYHIxdS'
Endpoint = 'oss-cn-shanghai.aliyuncs.com'
Bucket = 'suwa3d-securedata'
self._client = oss2.Bucket(oss2.Auth(AccessKeyId, AccessKeySecret), Endpoint, Bucket)
return self._client
def ossClient():
"""获取OSS客户端单例"""
return OSSClientSingleton().get_client()
#连接redis,单例模式
class RedisClientSingleton:
_instance = None
_client = None
def __new__(cls):
if cls._instance is None:
cls._instance = super(RedisClientSingleton, cls).__new__(cls)
return cls._instance
def get_client(self):
if self._client is None:
self._client = redis.Redis(host='172.31.1.254', password='', port=6379, db=6)
return self._client
def redisClient():
"""获取Redis客户端单例"""
return RedisClientSingleton().get_client()
# 根据批次id,进行切片中的状态变更
def requestApiToUpdateSliceStatus(versionId):
api_url = f"{url}/api/printTypeSettingOrder/updateBatchSliceing?batch_id={versionId}"
print(f'发起状态变更请求url={api_url}, versionId={versionId}')
res = requests.post(api_url)
if res.status_code != 200:
print(f'状态变更请求失败, res={res.text}')
return False
print(f'状态变更请求成功, res={res.text}')
return True
#判断是否上传了 JSON 文件
def step1(versionId):
jsonFilePath = f'batchPrint/{versionId}/{versionId}.json'
#判断oss 上是否存在
if not ossClient().object_exists(jsonFilePath):
return False
#下载文件到项目所在目录
dirNow = currentDir + '/batchPrint/' + versionId + '/json'
if not os.path.exists(dirNow):
os.makedirs(dirNow)
localFilePath = dirNow + '/' + versionId + '.json'
ossClient().get_object_to_file(jsonFilePath, localFilePath)
return True
#根据下载下来的JSON文件传递,调用其它参数,进行处理
def step2(jsonFilePath, versionId):
print(f'jsonFilePath={jsonFilePath}, versionId={versionId} {currentDir}/download_print_out.py')
# 调用 download_print_out.py 脚本,下载数据
os.system(f'python {currentDir}/download_print_out.py --pid_file {jsonFilePath} --workdir {currentDir}/batchPrint/{versionId}/data')
# 读取 队列中一个数据出来
def main():
# 循环处理,直到队列为空
while True:
r = redisClient()
#检测队列是否有值
if r.llen('pb:sliceing') == 0:
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} 队列为空,等待10秒')
time.sleep(10)
continue
#获取队列中的值
data = r.lpop('pb:sliceing')
if data is None:
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} 取出的数据为空,等待10秒')
time.sleep(10)
continue
data = data.decode('utf-8')
#判断是否是数字
if not data.isdigit():
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} 取出的数据不是数字,等待10秒')
time.sleep(10)
continue
versionId = str(data)
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} 正在处理版次ID={versionId}')
res = step1(versionId)
if not res:
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} JSON文件下载数据失败,等待10秒')
time.sleep(10)
continue
jsonFilePath = currentDir + '/batchPrint/' + versionId + '/json/' + versionId + '.json'
step2(jsonFilePath, versionId)
print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} 数据处理完成,等待10秒')
requestApiToUpdateSliceStatus(versionId)
time.sleep(10)
if __name__ == '__main__':
main()