Refactor Code&mock db

1.Refactor Code
2.mock db