package com.palmnest.webapp.controller.app;

import com.palmnest.application.AppConstants;
import com.palmnest.application.bean.AppResultDto;
import com.palmnest.application.core.util.AppResultUtil;
import com.palmnest.service.notice.AppNoticeManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/appuser/user")
public class NoticeController {

	@Autowired
	private AppNoticeManager appNoticeManager;

	/**
	 * @param request
	 * @return 查找banner图列表
	 */
	@RequestMapping(value = "/bannerList")
	@ResponseBody
	public AppResultDto bannerList(HttpServletRequest request) {
		try {
			String organizationId = request.getParameter("organizationId");
			String positionType   = "1,5";//展示位置 0-微信+app端/1-app端/2-微信/3-公众号/4-微信+公众号/5-app+公众号/6-微信+app+公众号
			return AppResultUtil.createSuccesDto(appNoticeManager.finByType(2, positionType, organizationId));
		} catch (Exception e) {
			e.printStackTrace();
			return AppResultUtil.createErrorDto(AppConstants.GET_BANNER_DETAIL_ERROR, "查询banner列表失败");
		}
	}

	/**
	 * @param request
	 * @return 查找公告列表
	 */
	@RequestMapping(value = "/noticeList")
	@ResponseBody
	public AppResultDto noticeList(HttpServletRequest request) {
		try {
			String organizationId = request.getParameter("organizationId");
			String positionType   = "1,5";//展示位置 0-微信+app端/1-app端/2-微信/3-公众号/4-微信+公众号/5-app+公众号/6-微信+app+公众号
			return AppResultUtil.createSuccesDto(appNoticeManager.finByType(1, positionType, organizationId));
		} catch (Exception e) {
			e.printStackTrace();
			return AppResultUtil.createErrorDto(AppConstants.GET_BANNER_DETAIL_ERROR, "查询banner列表失败");
		}
	}
}
