package com.lightinit.hsdataportal.controller.open;

import com.lightinit.hsdataportal.common.ConfigUtils;
import com.lightinit.hsdataportal.common.SysContants;
import com.lightinit.hsdataportal.dictionary.DicPlatformType;
import com.lightinit.hsdataportal.dictionary.DicPublishSettingChargeMethod;
import com.lightinit.hsdataportal.dictionary.DicResourceCatelogType;
import com.lightinit.hsdataportal.dictionary.DicResourceType;
import com.lightinit.hsdataportal.entity.BaseExample;
import com.lightinit.hsdataportal.model.*;
import com.lightinit.hsdataportal.service.INotificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @Author: sunxiang
 * @Date: 2018/7/11 14:54
 * @Description:
 **/
@Controller
@RequestMapping(value = "/open/notification")
public class NotificationOpenController {
    @Autowired
    private INotificationService notificationService;
    @RequestMapping(value="index.htm")
    public ModelAndView getDataIndex(@RequestParam(defaultValue = "1") int pageNo, HttpSession session){
        ModelAndView modelAndView = new ModelAndView("open/notification/index");
        BaseExample.Page pager = new BaseExample.Page();
        pager.setPageNo(pageNo);
        LoginUser loginUser= (LoginUser)session.getAttribute(LoginUser.SESSION_KEY_LOGIN_USER);
        long id=0;
        if(loginUser!=null){
            id=loginUser.getId();
        }
        List<NotificationListModel> outputModel=notificationService.getNotificationIndex(pager,id);
        pager.setTotal(notificationService.getNotificationCount(id));
        modelAndView.addObject("outputModel", outputModel);
        modelAndView.addObject("pager",pager);
        return modelAndView;
    }

}
