package org.xmx0632.deliciousfruit.web.share; import java.util.Locale; import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.support.ResourceBundleMessageSource; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.xmx0632.deliciousfruit.api.v1.bo.TerminalType; import org.xmx0632.deliciousfruit.api.v1.helper.PictureUrlHelper; import org.xmx0632.deliciousfruit.entity.FruitStory; import org.xmx0632.deliciousfruit.entity.FruitStoryMenu; import org.xmx0632.deliciousfruit.entity.FruitStoryProcedure; import org.xmx0632.deliciousfruit.service.ConfigService; import org.xmx0632.deliciousfruit.service.FruitStoryMaterialService; import org.xmx0632.deliciousfruit.service.FruitStoryMenuService; import org.xmx0632.deliciousfruit.service.FruitStoryProcedureService; import org.xmx0632.deliciousfruit.service.FruitStoryService; import org.xmx0632.deliciousfruit.web.admin.FruitStoryController; import com.google.common.collect.Maps; @Controller @RequestMapping(value = "/share/fruitStory") public class ShareStoryController { private static Logger log = LoggerFactory .getLogger(ShareStoryController.class); @Autowired private ResourceBundleMessageSource messageSource; private static Map<String, String> sortTypes = null; private static Map<String, String> allStatus = Maps.newHashMap(); static { allStatus.put(FruitStory.STATUS_CREATING, "creating"); allStatus.put(FruitStory.STATUS_OFFLINE, "offline"); allStatus.put(FruitStory.STATUS_ONLINE, "online"); } private Map<String, String> getSortTypes(Locale locale) { if (sortTypes == null) { sortTypes = Maps.newLinkedHashMap(); sortTypes.put("auto", messageSource.getMessage("common.auto", null, locale)); sortTypes.put("name", messageSource.getMessage("fruitStory.name", null, locale)); } return sortTypes; } @Autowired private FruitStoryService fruitStoryService; @Autowired private FruitStoryMenuService fruitStoryMenuService; @Autowired private FruitStoryMaterialService fruitStoryMaterialService; @Autowired private FruitStoryProcedureService fruitStoryProcedureService; @Autowired private ConfigService configService; @RequestMapping(value = "view/{id}", method = RequestMethod.GET) public String view(@PathVariable("id") Long id, Model model) { String imgAddress = PictureUrlHelper.genTerminalRootUrl( TerminalType.IOS_RETINA, configService); model.addAttribute("imgAddress", imgAddress); FruitStoryMenu fruitStoryMenu = fruitStoryService.getFruitStory(id) .getFruitStoryMenu(); fruitStoryMenu.getFruitStory().setPictureUrl( PictureUrlHelper.toWaterMarkFileName(fruitStoryMenu .getFruitStory().getPictureUrl(), configService)); fruitStoryMenu.setFruitStoryPicUrl(PictureUrlHelper .toWaterMarkFileName(fruitStoryMenu.getFruitStoryPicUrl(), configService)); for (FruitStoryProcedure procedure : fruitStoryMenu .getFruitStoryProcedureList()) { procedure.setProcedurePic(PictureUrlHelper.toWaterMarkFileName( procedure.getProcedurePic(), configService)); } model.addAttribute("fruitStoryMenu", fruitStoryMenu); return "share/storyShare"; } }