package com.goafanti.admin.controller;


import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.goafanti.admin.service.NoticeService;
import com.goafanti.common.bo.Result;
import com.goafanti.common.controller.CertifyApiController;
import com.goafanti.common.utils.StringUtils;
import com.goafanti.core.shiro.token.TokenManager;
@RestController
@RequestMapping(value = "/api/admin/notice")
public class AdminNoticeApiController extends CertifyApiController{
	
	@Resource
	private NoticeService noticeService;
	
	/**
	 * 未读通知数量
	 * @return
	 */
	@RequestMapping(value = "/unreadCount", method = RequestMethod.GET)
	public Result unreadCount(){
		Result res = new Result();
		res.setData(noticeService.findUnreadNoticeCount());
		return res;
	}
	
	/**
	 * 
	 * 未读通知列表
	 * @return
	 */
	@RequestMapping(value = "/unread", method = RequestMethod.GET)
	public Result unread(String pageNo, String pageSize){
		Result res = new Result();
		Integer pNo = 1;
		Integer pSize = 10;
		if (StringUtils.isNumeric(pageSize)) {
			pSize = Integer.parseInt(pageSize);
		}
		if (StringUtils.isNumeric(pageNo)) {
			pNo = Integer.parseInt(pageNo);
		}
		
		res.setData(noticeService.updateListUnreadNoticeByAid(pNo, pSize, TokenManager.getAdminId()));
		return res;
	}
	
	/**
	 * 已读通知列表
	 * @return
	 */
	@RequestMapping(value = "/readed", method = RequestMethod.GET)
	public Result readed(String pageNo, String pageSize){
		Result res = new Result();
		Integer pNo = 1;
		Integer pSize = 10;
		if (StringUtils.isNumeric(pageSize)) {
			pSize = Integer.parseInt(pageSize);
		}
		if (StringUtils.isNumeric(pageNo)) {
			pNo = Integer.parseInt(pageNo);
		}
		res.setData(noticeService.ListReadedNoticeByAid(pNo, pSize, TokenManager.getAdminId()));
		return res;
	}
}
