Constraints on Gluon Distribution Functions in the Nucleon and Nucleus from Open Charm Hadron Production at the Electron-Ion Collider