package com.cloudcross.ssp.web.operator.main;

import java.util.HashMap;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.cloudcross.ssp.base.web.SimpleController;
import com.cloudcross.ssp.model.CodeSite;
import com.cloudcross.ssp.service.ICodeSiteService;


@Controller("operator.codeSiteController")
@RequestMapping("/operator/main/code-site")
public  class CodeSiteController extends SimpleController {
	private static final Logger LOG = Logger.getLogger(CodeSiteController.class);
	
	@Autowired
	protected ICodeSiteService codeSiteService;
	
	/**
	 * @return 返回到广告主管理第一页。
	 */
	@RequestMapping
	public String index() {
		return redirect(page("list"));
	}
	
	@RequestMapping("/list")
	public String list(Model model,
			@RequestParam HashMap<String, Object> paramMap,
			@RequestParam(defaultValue="1") int page) {


		return page("list");
	}
	
	/**
	 * @return 创建广告主账号。
	 */
	@RequestMapping("/script")
	public String script(Model model) {	
					
		Long advertiserId = new Long(1);
		CodeSite codeSite = codeSiteService.findByAdvertiserId(advertiserId);
	
			System.out.println(codeSite.getScript()+"9999");

		model.addAttribute("codeSite", codeSite);
			
		return page("script");
		
	}
	
	
	@RequestMapping("/picture")
	public String picture(Model model) {	
		
		Long advertiserId = new Long(1);
		CodeSite codeSite = codeSiteService.findByAdvertiserId(advertiserId);
	
			System.out.println(codeSite.getPicture()+"8888");

		model.addAttribute("codeSite", codeSite);
		
 		return page("picture");
	}
	

	/**
	 * 在保存对象前要验证数据是否合法。
	 * 
	 * @return 保存成功返回到广告主管理页面。
	 */
@RequestMapping("/save")
public String save(
			@ModelAttribute("form") CodeSite codeSite) {
		// 校验参数

   	
   	if (codeSite.getId() == null){
   		codeSiteService.add(codeSite);
   	}else{
   		codeSiteService.edit(codeSite);
   	}
		return redirect(page("list"));
	}
}

