Provided herein are dihydropyrimidine compounds and their pharmaceutical applications, especially for use in treating and preventing HBV diseases. Specifically, provided herein are compounds having Formula (I) or (Ia), or an enantiomer, a diastereoisomer, a tautomer, a hydrate, a solvate, or a pharmaceutically acceptable salt thereof, wherein the variables of the formulas are as defined in the specification. Also provided herein is the use of the compounds having Formula (I) or (Ia), or an enantiomer, a diastereoisomer, a tautomer, a hydrate, a solvate, or a pharmaceutically acceptable salt thereof for treating and preventing HBV diseases.