package com.palmnest.webapp.controller.notice;

import com.palmnest.application.dto.OrgDto;
import com.palmnest.model.User;
import com.palmnest.service.AppUserService;
import com.palmnest.service.redis.BaseRedisService;
import com.palmnest.webapp.controller.BaseFormController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ExtendedModelMap;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
@RequestMapping("/notice")
public class NoticeMenuController extends BaseFormController {

	@Autowired
	private AppUserService   appUserService;
	@Autowired
	private BaseRedisService baseRedisService;

	/**
	 * 跳转到界面
	 * 发布邮件
	 *
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/emailPublish")
	public ModelAndView emailPublish(HttpServletRequest request,
									 HttpServletResponse response) {
		Model        model = new ExtendedModelMap();
		User         user  = (User) request.getSession().getAttribute("UserCache");
		List<OrgDto> dtos  = appUserService.getUserOrgs(user.getId());
		model.addAttribute("orgs", dtos);
		return new ModelAndView("admin/notice/noticeEmailPublish", model.asMap());
	}

	/**
	 * 跳转到界面
	 * 发布短信
	 *
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/msgPublish")
	public ModelAndView msgPublish(HttpServletRequest request,
								   HttpServletResponse response) {
		Model        model = new ExtendedModelMap();
		User         user  = (User) request.getSession().getAttribute("UserCache");
		List<OrgDto> dtos  = appUserService.getUserOrgs(user.getId());
		model.addAttribute("orgs", dtos);
		return new ModelAndView("admin/notice/noticeMsgPublish", model.asMap());
	}

	/**
	 * 跳转到界面
	 * 发布微信消息
	 *
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/wxPublish")
	public ModelAndView wxPublish(HttpServletRequest request,
								  HttpServletResponse response) {
		Model        model = new ExtendedModelMap();
		User         user  = (User) request.getSession().getAttribute("UserCache");
		List<OrgDto> dtos  = appUserService.getUserOrgs(user.getId());
		model.addAttribute("orgs", dtos);
		return new ModelAndView("admin/notice/noticeWxPublish", model.asMap());
	}

	/**
	 * 跳转到界面-发布公告
	 *
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/noticeAppPublish*")
	public ModelAndView noticeAppPublish(HttpServletRequest request,
										 HttpServletResponse response) {
		ModelAndView model = new ModelAndView();
		User         user  = (User) request.getSession().getAttribute("UserCache");
		List<OrgDto> dtos  = appUserService.getUserOrgs(user.getId());
		model.addObject("orgs", dtos);
		model.setViewName("admin/notice/noticeAppPublish");
		return model;
	}

	/**
	 * 跳转到界面-公告审核
	 *
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "audit/noticeAppVerify*")
	public ModelAndView noticeAppVerify(HttpServletRequest request,
										HttpServletResponse response) {
		Model        model = new ExtendedModelMap();
		User         user  = (User) request.getSession().getAttribute("UserCache");
		List<OrgDto> dtos  = appUserService.getUserOrgs(user.getId());
		model.addAttribute("orgs", dtos);
		model.addAttribute("userType", user == null ? null : user.getUserType());
		return new ModelAndView("admin/notice/noticeAppVerify", model.asMap());
	}

	/**
	 * 跳转到界面-邮件审核
	 *
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "audit/noticeEmailVerify*")
	public ModelAndView noticeEmailVerify(HttpServletRequest request,
										  HttpServletResponse response) {
		Model        model = new ExtendedModelMap();
		User         user  = (User) request.getSession().getAttribute("UserCache");
		List<OrgDto> dtos  = appUserService.getUserOrgs(user.getId());
		model.addAttribute("orgs", dtos);
		model.addAttribute("userType", user == null ? null : user.getUserType());
		return new ModelAndView("admin/notice/noticeEmailVerify", model.asMap());
	}

	/**
	 * 跳转到界面-短信审核
	 *
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "audit/noticeMsgVerify*")
	public ModelAndView noticeMsgVerify(HttpServletRequest request,
										HttpServletResponse response) {
		Model        model = new ExtendedModelMap();
		User         user  = (User) request.getSession().getAttribute("UserCache");
		List<OrgDto> dtos  = appUserService.getUserOrgs(user.getId());
		model.addAttribute("orgs", dtos);
		model.addAttribute("userType", user == null ? null : user.getUserType());
		return new ModelAndView("admin/notice/noticeMsgVerify", model.asMap());
	}

	/**
	 * 跳转到界面-微信审核
	 *
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "audit/noticeWxVerify*")
	public ModelAndView noticeWxVerify(HttpServletRequest request,
									   HttpServletResponse response) {
		Model        model = new ExtendedModelMap();
		User         user  = (User) request.getSession().getAttribute("UserCache");
		List<OrgDto> dtos  = appUserService.getUserOrgs(user.getId());
		model.addAttribute("orgs", dtos);
		model.addAttribute("userType", user == null ? null : user.getUserType());
		return new ModelAndView("admin/notice/noticeWxVerify", model.asMap());
	}


	/**
	 * 跳转到界面
	 * app发送历史
	 *
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "history/noticeAppSend")
	public ModelAndView noticeAppSend(HttpServletRequest request,
									  HttpServletResponse response) {
		Model        model = new ExtendedModelMap();
		User         user  = (User) request.getSession().getAttribute("UserCache");
		List<OrgDto> dtos  = appUserService.getUserOrgs(user.getId());
		model.addAttribute("orgs", dtos);
		model.addAttribute("userType", user == null ? null : user.getUserType());
		return new ModelAndView("admin/notice/noticeAppSend", model.asMap());
	}

	/**
	 * 跳转到界面
	 * email发送历史
	 *
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "history/noticeEmailSend")
	public ModelAndView noticeEmailSend(HttpServletRequest request,
										HttpServletResponse response) {
		Model        model = new ExtendedModelMap();
		User         user  = (User) request.getSession().getAttribute("UserCache");
		List<OrgDto> dtos  = appUserService.getUserOrgs(user.getId());
		model.addAttribute("orgs", dtos);
		model.addAttribute("userType", user == null ? null : user.getUserType());
		return new ModelAndView("admin/notice/noticeEmailSend", model.asMap());
	}

	/**
	 * 跳转到界面
	 * wx发送历史
	 *
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "history/noticeWxSend")
	public ModelAndView noticeWxSend(HttpServletRequest request,
									 HttpServletResponse response) {
		Model        model = new ExtendedModelMap();
		User         user  = (User) request.getSession().getAttribute("UserCache");
		List<OrgDto> dtos  = appUserService.getUserOrgs(user.getId());
		model.addAttribute("orgs", dtos);
		model.addAttribute("userType", user == null ? null : user.getUserType());
		return new ModelAndView("admin/notice/noticeWxSend", model.asMap());
	}

	/**
	 * 跳转到界面
	 * wx发送历史
	 *
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "history/noticeMsgSend")
	public ModelAndView noticeMsgSend(HttpServletRequest request,
									  HttpServletResponse response) {
		Model        model = new ExtendedModelMap();
		User         user  = (User) request.getSession().getAttribute("UserCache");
		List<OrgDto> dtos  = appUserService.getUserOrgs(user.getId());
		model.addAttribute("orgs", dtos);
		model.addAttribute("userType", user == null ? null : user.getUserType());
		return new ModelAndView("admin/notice/noticeMsgSend", model.asMap());
	}

	/**
	 * 跳转到界面
	 * banner管理 APP
	 *
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "banner/appBanner")
	public ModelAndView appBanner(HttpServletRequest request,
								  HttpServletResponse response) {
		return new ModelAndView("admin/notice/appBanner");
	}

	/**
	 * 跳转到界面
	 * banner管理 WX
	 *
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "banner/wxBanner")
	public ModelAndView wxBanner(HttpServletRequest request,
								 HttpServletResponse response) {
		return new ModelAndView("admin/notice/wxBanner");
	}

	/**
	 * 跳转商圈发现 banner页面
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "banner/discoverBannerPage")
	public ModelAndView discoverBannerPage(HttpServletRequest request) {
		return new ModelAndView("admin/notice/tradeBannerManage");
	}

	/**
	 * 跳转商圈发现 banner新增编辑页面
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "banner/discoverBannerEditPage")
	public ModelAndView discoverBannerEditPage(HttpServletRequest request) {
		return new ModelAndView("admin/notice/tradeAreaBanner");
	}
}
