First-principles study on the electronic structure and optical properties of MgCNi3