A dihydropyrimidine compound and a pharmaceutical application thereof, especially the application used for treating and preventing HBV diseases. Specifically, a compound 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, use of the compound having Formula (I) or (Ia), or an enantiomer, a diastereoisomer, a tautomer, a hydrate, a solvate, or a pharmaceutically acceptable salt thereof as a medicine, especially for treating and preventing HBV diseases.