This study proposes a deep learning framework that combines graph neural networks (GNN) and temporal modeling to enhance the accuracy and stability of supply chain risk prediction and optimization in pharmaceutical enterprises. By modeling the pharmaceutical supply chain as a complex graph structure, this research effectively captures the dependencies between nodes while using temporal networks to capture long-term dynamic changes within the supply chain. We design a model incorporating a multi-head attention mechanism, which provides accurate risk predictions under different demand fluctuation scenarios. The experimental results demonstrate that the proposed model outperforms existing traditional machine learning models and deep learning methods across multiple evaluation metrics, including Precision, Recall, F1-Score, and AUC-ROC. Particularly in complex environments, the model effectively identifies potential supply chain risk events, such as logistics delays, supply disruptions, and inventory fluctuations. Compared to traditional rule-based or statistical supply chain risk prediction methods, the proposed model shows greater robustness and accuracy by deeply exploring the structural and temporal features between supply chain nodes. Sensitivity analysis of model performance under varying demand fluctuation intensities and environmental changes further validates the model's feasibility and stability in real-world applications, providing effective technical support for the pharmaceutical industry in areas such as resource scheduling, inventory management, and risk early warning.