InfoAction.java 4.15 KB
package com.cjs.site.action.info;

import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import com.cjs.site.model.user.account.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mobile.device.Device;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cjs.site.dao.info.ArticleDao;
import com.cjs.site.dao.pub.BannerDao;
import com.cjs.site.util.lang.JsonUtil;
import com.cjs.site.util.web.PageUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 资讯
 * 
 * @author tongyufu
 *
 */
@Controller
@RequestMapping("/info")
public class InfoAction {
    @Autowired
    private ArticleDao articleDao;
    @Autowired
    private BannerDao  bannerDao;

    @RequestMapping("/gonggao")
    public String gonggao(@RequestParam Map<String, Object> params, Model model, Device device) {
        if (device.isMobile()) {
            model.addAttribute("pageRouter", "infolist");
            return "/mobile/index.jsp";
        }
        params.put("type",0);
        params = PageUtils.processPage(params);
        // 托管公告、公告通知
        params.put("cids", Arrays.asList(13, 24));
        params.put("_total", articleDao.searchTotal(params));
        model.addAttribute("gonggao", articleDao.search(params));
        model.addAttribute("cid", 24);
        model.addAttribute("params", params);
        return "info/gonggao.jsp";
    }

    @RequestMapping("/gonggao2")
    public String gonggao2(@RequestParam Map<String, Object> params, Model model, Device device, HttpServletRequest request, HttpServletResponse response) {
        Object obj = request.getSession().getAttribute(UserInfo.USER);

        if(obj == null) {
            try {
                request.getRequestDispatcher("/login").forward(request, response);
            } catch (ServletException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (device.isMobile()) {
            model.addAttribute("pageRouter", "infolist");
            return "/mobile/index.jsp";
        }
        params.put("type",1);
        params = PageUtils.processPage(params);
        // 托管公告、公告通知
        params.put("cids", Arrays.asList(13, 24));
        params.put("_total", articleDao.searchTotal(params));
        model.addAttribute("gonggao", articleDao.search(params));
        model.addAttribute("cid", 24);
        model.addAttribute("params", params);
        return "info/gonggao2.jsp";
    }

    @RequestMapping("/news")
    public String news(@RequestParam Map<String, Object> params, Model model) {
        params = PageUtils.processPage(params);
        params.put("cid", 25);
        params.put("_total", articleDao.searchTotal(params));
        model.addAttribute("news", articleDao.search(params));
        model.addAttribute("params", params);
        return "info/news.jsp";
    }

    /** 手机客户端公告列表 */
    @RequestMapping("/moblieGongGao")
    public @ResponseBody String moblieGongGao(@RequestParam Map<String, Object> params,
                                              Model model) {
        params.put("limit", Integer.parseInt(params.get("limit").toString()));
        params.put("start", Integer.parseInt(params.get("start").toString()));
        params.put("cids", Arrays.asList(13, 24, 25));
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("gonggao", articleDao.search(params));
        map.put("gonggao_total", articleDao.searchTotal(params));
        map.put("params", params);
        map.put("news", articleDao.searchOneNew());
        Map<String, Object> map2 = new HashMap<String, Object>();
        map2.put("type", 1);
        map2.put("bannerLocation", 0);
        map.put("banner", bannerDao.getBannerList(map2));
        return JsonUtil.toJson(map);
    }

}