Refactor controller functions as a service
Solved GroupBy bug when export to csv