com.greenline.guahao.web.module.home.controllers.mobile.MobileHealthTopicController.java Source code

Java tutorial

Introduction

Here is the source code for com.greenline.guahao.web.module.home.controllers.mobile.MobileHealthTopicController.java

Source

/**
 * Project: guahao-portal-web-home
 * 
 * File Created at 2012-11-22
 * 
 * Copyright 2012 Greenline.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Greenline Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Greenline.com.
 */
package com.greenline.guahao.web.module.home.controllers.mobile;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.greenline.guahao.biz.dal.dao.healthtopics.dataobject.HealthTopicsContentDO;
import com.greenline.guahao.biz.dal.dao.healthtopics.dataobject.HealthTopicsDO;
import com.greenline.guahao.biz.manager.healthtopics.HealthTopicsManager;
import com.greenline.guahao.biz.util.HtmlUtils;
import com.greenline.guahao.web.module.common.annotation.MethodRemark;
import com.greenline.guahao.web.module.common.constants.MobileConstants;

/**
 * 
 * @Type MobileHealthTopicController
 * @Desc
 * @author qinying
 * @date 2014-2-11
 * @Version V1.0
 */
@Controller
public class MobileHealthTopicController {

    private static final Integer CONTENT_COUNT_LIMIT = 800;
    @Resource
    private HttpServletRequest request;
    @Resource
    private HealthTopicsManager healthTopicsManager;

    /**
     * ?
     * 
     * @return
     */
    @MethodRemark(value = "remark=?,method=get")
    @RequestMapping(value = "/mobile/jkx", method = RequestMethod.GET)
    public String jkzgx(ModelMap model) {
        request.setAttribute("noBack", Boolean.TRUE);

        // ?
        HealthTopicsDO startHealthTopics = healthTopicsManager.getHealthTopicByState("2");
        // 
        HealthTopicsDO currentHealthTopics = healthTopicsManager.getHealthTopicByState("3");
        List<HealthTopicsDO> list = healthTopicsManager.queryHTContentListByPageQuery();
        List<HealthTopicsDO> result = new ArrayList<HealthTopicsDO>();
        HealthTopicsDO topic = new HealthTopicsDO();
        List<HealthTopicsContentDO> listVideos = new ArrayList<HealthTopicsContentDO>();
        for (HealthTopicsDO healthTopicsDO : list) {
            if (result.size() == 0) {
                BeanUtils.copyProperties(healthTopicsDO, topic);
                for (HealthTopicsDO healthTopics : list) {
                    if (topic.getId().equals(healthTopics.getId())) {
                        HealthTopicsContentDO healthTopicsContentDO = new HealthTopicsContentDO();
                        healthTopicsContentDO.setTopicsID(healthTopics.getId());
                        healthTopicsContentDO.setTitle(healthTopics.getShortVideosTitle());
                        healthTopicsContentDO.setYoukuUrl(healthTopics.getShortYoukuUrl());
                        listVideos.add(healthTopicsContentDO);
                    }
                }
                topic.setHealthTopicsShortVideos(listVideos);
                result.add(topic);
            } else {
                BeanUtils.copyProperties(healthTopicsDO, topic);
                boolean flag = false;
                for (HealthTopicsDO resultTopic : result) {
                    if (topic.getId().equals(resultTopic.getId())) {
                        flag = true;
                        break;
                    }
                }
                if (!flag) {
                    for (HealthTopicsDO healthTopics : list) {
                        if (topic.getId().equals(healthTopics.getId())) {
                            HealthTopicsContentDO healthTopicsContentDO = new HealthTopicsContentDO();
                            healthTopicsContentDO.setTopicsID(healthTopics.getId());
                            healthTopicsContentDO.setTitle(healthTopics.getShortVideosTitle());
                            healthTopicsContentDO.setYoukuUrl(healthTopics.getShortYoukuUrl());
                            listVideos.add(healthTopicsContentDO);
                        }
                    }
                    topic.setHealthTopicsShortVideos(listVideos);
                    result.add(topic);
                }
            }
            if (list.indexOf(healthTopicsDO) != (list.size() - 1)) {
                topic = new HealthTopicsDO();
                listVideos = new ArrayList<HealthTopicsContentDO>();
            }
        }
        if (currentHealthTopics != null) {
            model.put("currentHealthTopics", currentHealthTopics);
        } else if (startHealthTopics != null) {
            model.put("currentHealthTopics", startHealthTopics);
        } else {
            model.put("currentHealthTopics", result.get(0));
        }

        model.put("list", result);
        return "mobile/jkx/index";
    }

    /**
     * ??
     * 
     * @return
     */
    @MethodRemark(value = "remark=?,method=get")
    @RequestMapping(value = "/mobile/jkx/info", method = RequestMethod.GET)
    public String jkzgxInfo() {
        return "mobile/jkx/info";
    }

    @MethodRemark(value = "remark=?? id=?id")
    @RequestMapping(value = "/mobile/jkx/view/{id}")
    public String view(ModelMap map, @PathVariable("id") String id) {
        if (!StringUtils.isNumeric(id)) {
            map.put("message", "????");
            return MobileConstants.M_ERROR;
        }
        HealthTopicsDO healthTopicsDO = healthTopicsManager.getHealthTopicsById(Integer.valueOf(id));
        if (null == healthTopicsDO) {
            map.put("message", "????");
            return MobileConstants.M_ERROR;
        }
        List<HealthTopicsContentDO> contentList = healthTopicsManager.queryShortVideosList(healthTopicsDO.getId());
        if (null != contentList) {
            List<HealthTopicsContentDO> videosList = new ArrayList<HealthTopicsContentDO>();
            List<HealthTopicsContentDO> articleList = new ArrayList<HealthTopicsContentDO>();
            for (HealthTopicsContentDO healthTopicsContentDO : contentList) {
                if (healthTopicsContentDO.getType() == 0) {
                    videosList.add(healthTopicsContentDO);
                } else if (healthTopicsContentDO.getType() == 1) {
                    articleList.add(healthTopicsContentDO);
                }
            }
            map.put("videosList", videosList);
            map.put("articleList", articleList);
        }

        int count = healthTopicsManager.getHealthTopicsCount();
        map.put("count", count);

        map.put("topic", healthTopicsDO);
        return "mobile/jkx/jkx_detail";
    }

    @MethodRemark(value = "remark=??id=id ")
    @RequestMapping(value = "/mobile/jkx/content/{id}")
    public String viewContent(ModelMap map, @PathVariable("id") String id) {
        if (!StringUtils.isNumeric(id)) {
            map.put("message", "????");
            return MobileConstants.M_ERROR;
        }
        HealthTopicsContentDO healthTopicsContentDO = healthTopicsManager.getContentById(Integer.valueOf(id));
        if (null == healthTopicsContentDO) {
            map.put("message", "????");
            return MobileConstants.M_ERROR;
        }

        map.put("content", healthTopicsContentDO);
        return "mobile/jkx/content_detail";
    }

    /**
     * ?
     * 
     * @return
     */
    @MethodRemark(value = "remark=?,method=get")
    @RequestMapping(value = "/mobile/jkdjt", method = RequestMethod.GET)
    public String jkdjtIndex(ModelMap model) {
        request.setAttribute("noBack", Boolean.TRUE);

        List<HealthTopicsDO> list = healthTopicsManager.queryHTContentListNew();
        model.put("list", list);

        return "mobile/jkx/jkdjt_index";
    }

    /**
     * ?
     * 
     * @return
     */
    @MethodRemark(value = "remark=?,method=get")
    @RequestMapping(value = "/mobile/jkdjt/{id}", method = RequestMethod.GET)
    public String jkdjtDetail(ModelMap map, @PathVariable("id") String id) {
        if (!StringUtils.isNumeric(id)) {
            map.put("message", "????");
            return MobileConstants.M_ERROR;
        }

        HealthTopicsDO healthTopicsDO = healthTopicsManager.getHealthTopicsByIdNew(Integer.valueOf(id));
        if (null == healthTopicsDO) {
            map.put("message", "????");
            return MobileConstants.M_ERROR;
        }

        String[] threepart = HtmlUtils.getContentWithoutHtml(healthTopicsDO.getContent(), 0, CONTENT_COUNT_LIMIT);
        //0  1  2 
        healthTopicsDO.setPreContent(threepart[0]);
        healthTopicsDO.setLastContent(threepart[2]);
        healthTopicsDO.setContent(healthTopicsDO.getContent());
        map.put("topic", healthTopicsDO);
        map.put("description", HtmlUtils.deleteHtml(healthTopicsDO.getContent()));

        return "mobile/jkx/jkdjt_detail";
    }
}