package no.dusken.barweb.plugin.statisticsplugin.control; import no.dusken.barweb.model.Gjeng; import no.dusken.barweb.plugin.statisticsplugin.model.StatisticsElement; import no.dusken.barweb.plugin.statisticsplugin.service.StatisticsService; import no.dusken.barweb.service.BarPersonService; import no.dusken.barweb.service.GjengService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import java.util.List; /** * @author Marvin B. Lillehaug <lillehau@underdusken.no> * Handles showing of statistics. */ @Controller public class StatisticsController { private String view = "no/dusken/barweb/plugin/statisticsplugin/statistics/view"; private StatisticsService statisticsService; private GjengService gjengService; private BarPersonService barPersonService; @RequestMapping(value="/statistics/person/balance.do", method = RequestMethod.GET) public String showPersonBalance(@RequestParam(value = "personID") Long personID, Model model){ addPersonAndElements(personID, model, StatisticsConstants.PERSON_BALANCE, "saldo"); return view; } @RequestMapping(value="/statistics/person/spent.do", method = RequestMethod.GET) public String showPersonSpentMoney(@RequestParam(value = "personID") Long personID, Model model){ addPersonAndElements(personID, model, StatisticsConstants.PERSON_MONEY_SPENT_LAST_WEEK, "penger brukt"); return view; } @RequestMapping(value="/statistics/person/beer.do", method = RequestMethod.GET) public String showPersonBeers(@RequestParam(value = "personID") Long personID, Model model){ addPersonAndElements(personID, model, StatisticsConstants.PERSON_BEER_LAST_WEEK, "øl"); return view; } private void addPersonAndElements(Long personID, Model model, String statisticsKey, String statisticsName){ List<StatisticsElement> elements = statisticsService.getByTrackedObjectIdAndName(personID, statisticsKey); model.addAttribute("elements", elements); model.addAttribute("entity", barPersonService.findOne(personID)); model.addAttribute("statisticsName", statisticsName); } @RequestMapping(value="/statistics/totalbeer.do", method = RequestMethod.GET) public String showTotalBeers(Model model){ addGjengAndElements(model, StatisticsConstants.GJENG_BEER_LAST_WEEK, "øl, gjeng"); return view; } @RequestMapping(value="/statistics/totalmoney.do", method = RequestMethod.GET) public String showTotalMoneySpent(Model model){ addGjengAndElements(model, StatisticsConstants.GJENG_MONEY_SPENT_LAST_WEEK, "penger brukt, gjeng"); return view; } @RequestMapping(value="/admin/statistics/sumPersonBalance.do", method = RequestMethod.GET) public String showSumPersonBalance(Model model){ addGjengAndElements(model, StatisticsConstants.SUM_PERSON_BALANCE, "sum person-saldoer"); return view; } @RequestMapping(value="/admin/statistics/valueInBar.do", method = RequestMethod.GET) public String showValueInBar(Model model){ addGjengAndElements(model, StatisticsConstants.GJENG_VALUE_BAR, "verdi i baren"); return view; } @RequestMapping(value="/admin/statistics/valueInBank.do", method = RequestMethod.GET) public String showValueInBank(Model model){ addGjengAndElements(model, StatisticsConstants.GJENG_VALUE_BANK, "verdi i banken"); return view; } @RequestMapping(value="/admin/statistics/liquidity.do", method = RequestMethod.GET) public String showLiquidity(Model model){ addGjengAndElements(model, StatisticsConstants.GJENG_LIQUIDITY, "barens likviditet"); return view; } private void addGjengAndElements(Model model, String statisticsKey, String statisticsName){ Gjeng g = gjengService.getByDefaultGjengTrue(); List<StatisticsElement> elements = statisticsService.getByTrackedObjectIdAndName(g.getId(), statisticsKey); model.addAttribute("elements", elements); model.addAttribute("entity", gjengService.findOne(g.getId())); model.addAttribute("statisticsName", statisticsName); } @Autowired public void setStatisticsService(StatisticsService statisticsService) { this.statisticsService = statisticsService; } @Autowired public void setGjengService(GjengService gjengService) { this.gjengService = gjengService; } @Autowired public void setBarPersonService(BarPersonService barPersonService) { this.barPersonService = barPersonService; } }