package com.wechat.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wechat.common.Constants;
import com.wechat.global.base.BaseController;
import com.wechat.global.message.InfoMsg;
import com.wechat.model.requestDto.MdeShowReq;
import com.wechat.model.responseDto.DPResp;
import com.wechat.model.responseDto.MdeShowListResp;
import com.wechat.model.responseDto.MdeShowResp;
import com.wechat.model.responseDto.ResultEntity;
import com.wechat.service.CommonService;
import com.wechat.service.MendunerShowService;


@Controller
@RequestMapping("mendunerShow")
public class MendunerShowController extends BaseController{
	@Autowired
	private CommonService commonService;
	
	@Autowired
	private MendunerShowService mdeShowService;
	
	/** 
	 * 获取福利信息
	 * @param request
	 * @return
	 */
	@RequestMapping(value="getWelfares",method = RequestMethod.GET)
    @ResponseBody
	public ResultEntity<List<DPResp>> getWelfares(HttpServletRequest request)
	{
		List<DPResp> list = commonService.getDictByType("welfare",Constants.LANG_CN);
		return new ResultEntity<List<DPResp>>(InfoMsg.SUCCESS_REQUEST,list);
	}
	
	
	
	/** 
	 *  创建、修改门墩秀
	 * @param request
	 * @return
	 */
	@RequestMapping(value="makeMdeShow",method = RequestMethod.POST)
    @ResponseBody
	public ResultEntity<Integer> makeMdeShow(HttpServletRequest request, @RequestBody MdeShowReq showReq)
	{
		ResultEntity<Integer> rest = new ResultEntity<Integer>();
		String userCode = commonService.getUserCode(request);
		Integer showId = mdeShowService.makeMdeShow(userCode, showReq);
		
		if(showId < 1)
		{
			rest.setMsg(InfoMsg.ERROR_INSERT_ERROR);
		}
		rest.setResult(showId);
		return rest;
	}
	
	
	/** 
	 *  获取创建门墩秀信息
	 * @param request
	 * @return
	 */
	@RequestMapping(value="getInfoAboutShow",method = RequestMethod.GET)
    @ResponseBody
	public ResultEntity<MdeShowReq> getInfoAboutShow(HttpServletRequest request, @RequestParam int showId)
	{
		ResultEntity<MdeShowReq> rest = new ResultEntity<MdeShowReq>();
		String userCode = commonService.getUserCode(request);
		rest.setResult(mdeShowService.getInfoAboutShow(userCode,showId));
		
		return rest;
	}
	
	/** 
	 *  删除门墩秀数据信息
	 * @param showId
	 * @return
	 */
	@RequestMapping(value="delShow",method = RequestMethod.POST)
    @ResponseBody
	public ResultEntity<MdeShowReq> delShow(HttpServletRequest request, @RequestParam int showId)
	{
		ResultEntity<MdeShowReq> rest = new ResultEntity<MdeShowReq>();
		String userCode = commonService.getUserCode(request);
		int count = mdeShowService.delShow(userCode,showId);
		if(count < 1)
		{
			rest.setMsg(InfoMsg.ERROR_DATA_UPDATE);
		}
		return rest;
	}
	
	
	/** 
	 *  获取门墩秀列表信息
	 * @param request
	 * @return
	 */
	@RequestMapping(value="getShowList",method = RequestMethod.GET)
    @ResponseBody
	public ResultEntity<List<MdeShowListResp>> getShowList(HttpServletRequest request)
	{
		ResultEntity<List<MdeShowListResp>> rest = new ResultEntity<List<MdeShowListResp>>();
		String userCode = commonService.getUserCode(request);
		rest.setResult(mdeShowService.getShowList(userCode));
		
		return rest;
	}
	
	
	/** 
	 *  获取门墩秀数据信息
	 * @param request
	 * @return
	 */
	@RequestMapping(value="getTheShow",method = RequestMethod.GET)
    @ResponseBody
	public ResultEntity<MdeShowResp> getTheShow(HttpServletRequest request, @RequestParam int showId)
	{
		ResultEntity<MdeShowResp> rest = new ResultEntity<MdeShowResp>();
		rest.setResult(mdeShowService.getTheShow(showId));
		return rest;
	}
	
}
