This commit is contained in:
Leo
2025-12-14 14:32:34 +08:00
parent f08fc60857
commit 8bd5ffc53d
3 changed files with 281 additions and 7 deletions

15
fix_line_endings.sh Normal file
View File

@@ -0,0 +1,15 @@
#!/bin/bash
# 修复 setup_centos.sh 的行尾符问题
# 方法1: 使用 dos2unix (如果已安装)
if command -v dos2unix >/dev/null 2>&1; then
dos2unix setup_centos.sh
echo "✅ 已使用 dos2unix 修复行尾符"
# 方法2: 使用 sed 删除 \r 字符
else
sed -i 's/\r$//' setup_centos.sh
echo "✅ 已使用 sed 修复行尾符"
fi
chmod +x setup_centos.sh
echo "✅ 已设置执行权限"

259
setup_centos.sh Normal file
View File

@@ -0,0 +1,259 @@
#!/bin/bash
# CentOS 环境快速设置脚本
set -e # 遇到错误立即退出
# 确保使用 bash 运行(兼容性问题处理)
if [ -z "$BASH_VERSION" ]; then
echo "警告: 此脚本需要使用 bash 运行"
echo "请使用: bash $0"
exit 1
fi
echo "=========================================="
echo "京东物流提取工具 - Linux 环境设置"
echo "=========================================="
echo ""
# 检测系统类型和包管理器
if [ -f /etc/os-release ]; then
. /etc/os-release
OS_NAME="$ID"
else
echo "❌ 错误: 无法检测操作系统类型"
exit 1
fi
# 根据系统类型选择包管理器
if [ "$OS_NAME" = "ubuntu" ] || [ "$OS_NAME" = "debian" ]; then
# Ubuntu/Debian 系统
PKG_MANAGER="apt"
PKG_INSTALL="apt install -y"
PKG_UPDATE="apt update"
PKG_CHECK="dpkg -l"
IS_UBUNTU=true
elif [ "$OS_NAME" = "centos" ] || [ "$OS_NAME" = "rhel" ] || [ "$OS_NAME" = "fedora" ] || [ "$OS_NAME" = "rocky" ] || [ "$OS_NAME" = "almalinux" ]; then
# CentOS/RHEL/Fedora 系统
if command -v dnf >/dev/null 2>&1; then
PKG_MANAGER="dnf"
PKG_INSTALL="dnf install -y"
PKG_UPDATE="dnf update -y"
elif command -v yum >/dev/null 2>&1; then
PKG_MANAGER="yum"
PKG_INSTALL="yum install -y"
PKG_UPDATE="yum update -y"
else
echo "❌ 错误: 未找到 yum 或 dnf 包管理器"
exit 1
fi
PKG_CHECK="rpm -q"
IS_UBUNTU=false
else
echo "❌ 错误: 不支持的操作系统: $OS_NAME"
echo "支持的系统: Ubuntu, Debian, CentOS, RHEL, Fedora, Rocky Linux, AlmaLinux"
exit 1
fi
echo "检测到操作系统: $OS_NAME"
echo "检测到包管理器: $PKG_MANAGER"
# 1. 检查并安装系统依赖
echo "步骤 1: 检查系统依赖..."
if ! command -v python3 >/dev/null 2>&1; then
echo "安装 Python3..."
$PKG_UPDATE
$PKG_INSTALL python3 python3-pip
# CentOS 可能需要单独安装 venv 模块
$PKG_INSTALL python3-devel || true
else
echo "✅ Python3 已安装"
fi
# 检查 Chrome/Chromium
CHROME_PATH=""
if command -v google-chrome >/dev/null 2>&1; then
CHROME_PATH=$(which google-chrome)
echo "✅ 找到 Google Chrome: $CHROME_PATH"
elif [ -f "/usr/bin/google-chrome" ]; then
CHROME_PATH="/usr/bin/google-chrome"
echo "✅ 找到 Google Chrome: $CHROME_PATH"
elif command -v chromium >/dev/null 2>&1; then
CHROME_PATH=$(which chromium)
echo "✅ 找到 Chromium: $CHROME_PATH"
elif [ -f "/usr/bin/chromium" ]; then
CHROME_PATH="/usr/bin/chromium"
echo "✅ 找到 Chromium: $CHROME_PATH"
elif [ -f "/usr/bin/chromium-browser" ]; then
CHROME_PATH="/usr/bin/chromium-browser"
echo "✅ 找到 Chromium: $CHROME_PATH"
else
echo "⚠️ 未找到 Chrome/Chromium将尝试安装..."
echo "选择要安装的浏览器:"
echo "1) Google Chrome (推荐)"
echo "2) Chromium (开源版本)"
read -p "请选择 [1-2]: " choice
if [ "$choice" = "1" ]; then
echo "正在安装 Google Chrome..."
# 创建临时目录
TEMP_DIR=$(mktemp -d)
cd "$TEMP_DIR"
# 根据系统类型下载对应的包
if [ "$(uname -m)" = "x86_64" ]; then
if [ "$IS_UBUNTU" = "true" ]; then
# Ubuntu/Debian 使用 DEB 包
wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo $PKG_INSTALL ./google-chrome-stable_current_amd64.deb
rm -f google-chrome-stable_current_amd64.deb
else
# CentOS/RHEL 使用 RPM 包
wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
sudo $PKG_INSTALL ./google-chrome-stable_current_x86_64.rpm
rm -f google-chrome-stable_current_x86_64.rpm
fi
else
echo "❌ 错误: 仅支持 x86_64 架构"
cd - >/dev/null
rm -rf "$TEMP_DIR"
exit 1
fi
cd - >/dev/null
rm -rf "$TEMP_DIR"
CHROME_PATH="/usr/bin/google-chrome"
elif [ "$choice" = "2" ]; then
echo "正在安装 Chromium..."
$PKG_UPDATE
if [ "$IS_UBUNTU" = "true" ]; then
# Ubuntu/Debian
$PKG_INSTALL chromium-browser
CHROME_PATH="/usr/bin/chromium-browser"
else
# CentOS/RHEL 可能需要启用 EPEL 仓库
if ! rpm -qa | grep -q epel-release; then
echo "安装 EPEL 仓库..."
$PKG_INSTALL epel-release || true
fi
$PKG_INSTALL chromium
CHROME_PATH="/usr/bin/chromium"
fi
fi
fi
# 2. 安装 Chrome 运行时依赖
echo ""
echo "步骤 2: 检查 Chrome 运行时依赖..."
# 根据系统类型设置依赖包名
if [ "$IS_UBUNTU" = "true" ]; then
# Ubuntu/Debian 依赖包名
DEPS="libnss3 libatk-bridge2.0-0 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm1 libasound2"
else
# CentOS/RHEL 依赖包名
DEPS="nss atk at-spi2-atk libdrm libxkbcommon libXcomposite libXdamage libXfixes libXrandr mesa-libgbm alsa-lib"
fi
MISSING_DEPS=""
for dep in $DEPS; do
if [ "$IS_UBUNTU" = "true" ]; then
# Ubuntu/Debian 使用 dpkg 检查
if ! dpkg -l 2>/dev/null | grep -q "^ii.*$dep"; then
if [ -z "$MISSING_DEPS" ]; then
MISSING_DEPS="$dep"
else
MISSING_DEPS="$MISSING_DEPS $dep"
fi
fi
else
# CentOS/RHEL 使用 rpm 检查
if ! rpm -q "$dep" >/dev/null 2>&1; then
if [ -z "$MISSING_DEPS" ]; then
MISSING_DEPS="$dep"
else
MISSING_DEPS="$MISSING_DEPS $dep"
fi
fi
fi
done
if [ -n "$MISSING_DEPS" ]; then
echo "安装缺失的依赖: $MISSING_DEPS"
# CentOS/RHEL 需要确保 EPEL 仓库已启用
if [ "$IS_UBUNTU" = "false" ]; then
if ! rpm -qa | grep -q epel-release; then
echo "安装 EPEL 仓库..."
$PKG_INSTALL epel-release || true
fi
fi
$PKG_INSTALL $MISSING_DEPS
else
echo "✅ 所有依赖已安装"
fi
# 3. 创建虚拟环境
echo ""
echo "步骤 3: 设置 Python 虚拟环境..."
if [ ! -d "venv" ]; then
echo "创建虚拟环境..."
python3 -m venv venv
echo "✅ 虚拟环境创建成功"
else
echo "✅ 虚拟环境已存在"
fi
# 4. 激活虚拟环境并安装 Python 包
echo ""
echo "步骤 4: 安装 Python 依赖包..."
source venv/bin/activate
# 升级 pip
pip install --upgrade pip
# 安装依赖
pip install DrissionPage
# 可选:如果需要数据库功能
read -p "是否需要数据库功能?(sqlalchemy, pymysql) [y/N]: " need_db
if [ "$need_db" = "y" ] || [ "$need_db" = "Y" ]; then
pip install sqlalchemy pymysql
fi
deactivate
# 5. 创建运行脚本
echo ""
echo "步骤 5: 创建便捷运行脚本..."
cat > run_logistics.sh << 'EOF'
#!/bin/bash
# 激活虚拟环境并运行物流提取脚本
cd "$(dirname "$0")"
source venv/bin/activate
# 运行脚本
python jd/fetch_logistics_centos.py "$@"
deactivate
EOF
chmod +x run_logistics.sh
# 6. 完成
echo ""
echo "=========================================="
echo "✅ 环境设置完成!"
echo "=========================================="
echo ""
echo "快速开始:"
echo " 方式1: 使用便捷脚本"
echo " ./run_logistics.sh"
echo ""
echo " 方式2: 手动运行"
echo " source venv/bin/activate"
echo " python jd/fetch_logistics_centos.py"
echo " deactivate"
echo ""
echo "浏览器路径: $CHROME_PATH"
echo "虚拟环境: $(pwd)/venv"
echo ""

View File

@@ -2720,9 +2720,9 @@ public class JDUtil {
List<JDOrder> byAddress = jdOrderRepository.findByAddressOrderByOrderTimeDesc(jdOrder.getAddress());
if (!byAddress.isEmpty()) {
int count = byAddress.size();
StringBuilder sb = new StringBuilder();
sb.append(DateUtil.dateToStr(byAddress.get(0).getOrderTime(), "yyyy-MM-dd HH:mm:ss"));
wxUtil.sendTextMessage(fromWxid, "[炸弹] [炸弹] [炸弹] 录单警告!!! \n收货地址重复请确认 !!! \n 此地址共" + count + "个订单,最近的订单时间:" + sb, 1, fromWxid, true);
StringBuilder addressSb = new StringBuilder();
addressSb.append(DateUtil.dateToStr(byAddress.get(0).getOrderTime(), "yyyy-MM-dd HH:mm:ss"));
wxUtil.sendTextMessage(fromWxid, "[炸弹] [炸弹] [炸弹] 录单警告!!! \n收货地址重复请确认 !!! \n 此地址共" + count + "个订单,最近的订单时间:" + addressSb, 1, fromWxid, true);
}
JDOrder byRemark = jdOrderRepository.findByRemark(jdOrder.getRemark());
String info;
@@ -2736,7 +2736,7 @@ public class JDUtil {
}
jdOrderRepository.save(jdOrder);
StringBuilder sb = new StringBuilder();
StringBuilder orderInfoSb = new StringBuilder();
// 单号 下单日期 型号 内部订单号 地址 物流 外派给谁 后返金额 谁的单 下单价格
String distributionMark = jdOrder.getDistributionMark();
String distributionMark2 = "";
@@ -2747,14 +2747,14 @@ public class JDUtil {
distributionMark2 = "";
}
}
sb.append(jdOrder.getRemark()).append("\t").append(jdOrder.getOrderId()).append("\t").append(DateUtil.dateToStr(jdOrder.getOrderTime(), "yyyy-MM-dd")).append("\t").append(jdOrder.getModelNumber()).append("\t").append(jdOrder.getAddress()).append("\t").append(jdOrder.getLogisticsLink()).append("\t\t").append(jdOrder.getBuyer()).append("\t").append(jdOrder.getPaymentAmount()).append("\t").append(jdOrder.getRebateAmount()).append("\t").append(distributionMark2);
orderInfoSb.append(jdOrder.getRemark()).append("\t").append(jdOrder.getOrderId()).append("\t").append(DateUtil.dateToStr(jdOrder.getOrderTime(), "yyyy-MM-dd")).append("\t").append(jdOrder.getModelNumber()).append("\t").append(jdOrder.getAddress()).append("\t").append(jdOrder.getLogisticsLink()).append("\t\t").append(jdOrder.getBuyer()).append("\t").append(jdOrder.getPaymentAmount()).append("\t").append(jdOrder.getRebateAmount()).append("\t").append(distributionMark2);
logger.info("订单信息:{}", sb);
logger.info("订单信息:{}", orderInfoSb);
if (fromWxid.isEmpty()) {
return;
}
wxUtil.sendTextMessage(fromWxid, info, 1, null, true);
wxUtil.sendTextMessage(fromWxid, sb.toString(), 1, null, true);
wxUtil.sendTextMessage(fromWxid, orderInfoSb.toString(), 1, null, true);
} else if (input.startsWith("TF")) {
/*
ZQD130F-EB130 1 张林 17530176250 湖北省 武汉市 东西湖区 径河街道 径河街道临空港小区二期 8栋2单元2204联系15783450649转6316