package org.xmx0632.deliciousfruit.web.account; import java.util.Date; import org.joda.time.DateTime; import org.slf4j.Logger; import org.slf4j.LoggerFactory; 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.xmx0632.deliciousfruit.entity.UserAccount; import org.xmx0632.deliciousfruit.service.FruitProductService; import org.xmx0632.deliciousfruit.service.FruitStoryService; import org.xmx0632.deliciousfruit.service.FruitSubcategoryService; import org.xmx0632.deliciousfruit.service.UserAccountService; /** * show Dashboard info * * @author xmx0632 * */ @Controller @RequestMapping(value = "/dashboard") public class DashboardController { private static Logger log = LoggerFactory .getLogger(DashboardController.class); @Autowired private FruitProductService fruitProductService; @Autowired private FruitSubcategoryService fruitSubcategoryService; @Autowired private FruitStoryService fruitStoryService; @Autowired private UserAccountService userAccountService; @RequestMapping(value = "", method = RequestMethod.GET) public String welcome(Model model) { // 当前总用户数 long totalUserCount = userAccountService.getUserCount(); // 手机平台用户数 long mobileUserCount = userAccountService .countByPlatform(UserAccount.PLATFORM_MOBILE); // ERP平台用户数 long erpUserCount = userAccountService .countByPlatform(UserAccount.PLATFORM_ERP); DateTime yestoday = new DateTime().minusDays(1); Date startTime = yestoday.withTimeAtStartOfDay().toDate(); Date endTime = DateTime.now().toDate(); log.debug("startTime:{},endTime:{}", startTime, endTime); // 最近一天注册的手机用户数 long lastestRegisterMobileUserCount = userAccountService .countByPlatformAndCreateTime(startTime, endTime, UserAccount.PLATFORM_MOBILE); // 最近一天从ERP同步的用户数 long lastestSyncErpUserCount = userAccountService .countByPlatformAndCreateTime(startTime, endTime, UserAccount.PLATFORM_ERP); // 当前系统水果故事总数 long totalFruitStory = fruitStoryService.getFruitStoryCount(); // 产品总数 long totalFruitProduct = fruitProductService.getFruitProductCount(); long totalFruitSubcategory = fruitSubcategoryService .getFruitSubcategoryCount(); model.addAttribute("totalUserCount", totalUserCount); model.addAttribute("mobileUserCount", mobileUserCount); model.addAttribute("erpUserCount", erpUserCount); model.addAttribute("lastestRegisterMobileUserCount", lastestRegisterMobileUserCount); model.addAttribute("lastestSyncErpUserCount", lastestSyncErpUserCount); model.addAttribute("totalFruitStory", totalFruitStory); model.addAttribute("totalFruitProduct", totalFruitProduct); model.addAttribute("totalFruitSubcategory", totalFruitSubcategory); log.debug("totalUserCount:{}", totalUserCount); log.debug("mobileUserCount:{}", mobileUserCount); log.debug("erpUserCount:{}", erpUserCount); log.debug("lastestRegisterMobileUserCount:{}", lastestRegisterMobileUserCount); log.debug("lastestSyncErpUserCount:{}", lastestSyncErpUserCount); log.debug("totalFruitStory:{}", totalFruitStory); log.debug("totalFruitProduct:{}", totalFruitProduct); log.debug("totalFruitSubcategory:{}", totalFruitSubcategory); // TODO 当月销售额 long totalSales = 100; model.addAttribute("totalSales", totalSales); // TODO 当月新增销售额 long newSales = 20; model.addAttribute("newSales", newSales); return "account/dashboard"; } }