package com.goafanti.sc.controller;


import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.goafanti.common.controller.BaseController;
import com.goafanti.common.model.ScDemand;
import com.goafanti.sc.bo.ScMessageListBo;
import com.goafanti.sc.bo.inputAchievement;
import com.goafanti.sc.bo.inputDemands;
import com.goafanti.sc.service.CommonService;
import com.goafanti.sc.service.ScAchievementService;
import com.goafanti.sc.service.ScDemandService;


@Controller
public class ScWebController extends BaseController{
	@Resource
    private ScAchievementService		scAchievementService;
	@Resource
    private ScDemandService		scDemandService;
	@Resource
    private CommonService		commonService;
	
	
	@RequestMapping(value = "/open/achievementDetails", method = RequestMethod.GET)
	public ModelAndView achievementDetails(HttpServletRequest request, ModelAndView modelview,String id) {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("sc/achievement");
		inputAchievement s=scAchievementService.AchievementDetails(id);
		if (StringUtils.isNotBlank(s.getIntroduce())) 
			s.setIntroduce(s.getIntroduce().replace("\n","<br>"));
		if (StringUtils.isNotBlank(s.getpIntroduce())) 
		s.setpIntroduce(s.getpIntroduce().replace("\n", "<br>"));
		mv.addObject("achievementList",s);
		@SuppressWarnings("unchecked")
		List<ScMessageListBo> l=(List<ScMessageListBo>) commonService.listMessage(id,10,1).getList();
		for (ScMessageListBo m : l) {
			if (StringUtils.isNotBlank(m.getContent())) 
				m.setContent(m.getContent().replace("\n", "<br>"));
		}
		mv.addObject("listMessage",l);
		return mv;
	}
	
	@RequestMapping(value = "/open/demandDetails", method = RequestMethod.GET)
	public ModelAndView demandDetails(HttpServletRequest request, ModelAndView modelview,String id) {
		ModelAndView mv = new ModelAndView();
		ScDemand sd= scDemandService.demandDetails(id);
		if (sd.getType()==0) {
			mv.setViewName("sc/demand");
		}else {
			mv.setViewName("sc/man");
		}
		inputDemands s=scDemandService.demandDetails(id);
		if (StringUtils.isNotBlank(s.getIntroduce())) 
			s.setIntroduce(s.getIntroduce().replace("\n","<br>"));
		if (StringUtils.isNotBlank(s.getPintroduce())) 
		s.setPintroduce(s.getPintroduce().replace("\n", "<br>"));
		mv.addObject("demandList", s);
		@SuppressWarnings("unchecked")
		List<ScMessageListBo> l=(List<ScMessageListBo>) commonService.listMessage(id,10,1).getList();
		for (ScMessageListBo m : l) {
			if (StringUtils.isNotBlank(m.getContent())) 
				m.setContent(m.getContent().replace("\n", "<br>"));
		}
		mv.addObject("listMessage", l);
		return mv;
	}
	
	
	
	
	@RequestMapping(value = "/open/message", method = RequestMethod.GET)
	public ModelAndView home(HttpServletRequest request, ModelAndView modelview,String id) {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("sc/words");
		return mv;
	}
}
