Water quality monitoring is one of the critical aspects of industrial wastewater treatment, which is important for checking the treatment effect, optimizing the treatment technology and ensuring that the water quality meets the standard. Chemical oxygen demand (COD) is a key indicator for monitoring water quality, which reflects the degree of organic matter pollution in water bodies. However, the current methods for determining COD values have drawbacks such as slow speed and complicated operation, which hardly meet the demand of online monitoring. This article firstly proposed a novel quantitative analysis method based on NIR spectroscopy and multi-preprocessing stacking, successfully enabling real-time online monitoring of COD values during industrial wastewater treatment. First, the existing swarm intelligence algorithm was enhanced to optimize the hyperparameters of various base models. Next, multiple spectral preprocessing techniques were innovatively combined with a stacking strategy to construct multi-preprocessing stacking models, enabling comprehensive extraction of effective spectral information. Finally, various combinations of base models were evaluated, leading to the selection of the multi-preprocessing stacking model with optimal performance. The results indicate that the model achieves excellent predictive performance and strong generalization ability. For equalization tank samples, the R