This study aims to analyze the current situation of water resource management in Shaanxi Province, study the basic principles of ecological compensation, evaluate the impact of water conservation projects on the ecological environment by establishing a model, and propose a sustainable water resource management model. Hanzhong City has certain typicality and representativeness within Shaanxi Province, and the problems it faces in water resource management and ecological environment may represent the entire province or similar regions. At the same time, Hanzhong City has rich data and research foundations. Therefore, by conducting a detailed analysis of the current water resource status in the Hanzhong City area of Shaanxi Province, the problems in current water resource management are revealed, and the basic principles of ecological compensation are intensely studied. The original ecological compensation plan in Shaanxi Province has been summarized. Guided by the concept of sustainable development, an ecological compensation model is established using algorithms, and the model is applied to sustainable water resource management. Establish a model for water conservation and water resource management through data collection, preprocessing, and cleaning, and apply it to practical cases in Hanzhong City. Through simulation and analysis of Hanzhong City, the new water resource management model effectively mitigates the adverse effects of water conservation projects on the ecological environment while improving water resource utilization efficiency. The changes in various environmental parameters indicate that the new plan has improved the ecological environment. Through the application of the model, the ecological compensation plan formulated has achieved sustainable protection of the ecological environment while promoting economic development. This study proposes a sustainable water resource management model through a comprehensive study of water resource management and ecological compensation in Shaanxi Province and verifies it in practical cases, demonstrating that the model has not only good applicability but also has significant effects in promoting economic growth and ecological environment protection.