com.greenline.guahao.web.module.home.controllers.promotion.hosptopic.HospitalTopicController.java Source code

Java tutorial

Introduction

Here is the source code for com.greenline.guahao.web.module.home.controllers.promotion.hosptopic.HospitalTopicController.java

Source

/*
 * Project: guahao-portal-web-home
 * 
 * File Created at 2014-5-23
 * 
 * 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.promotion.hosptopic;

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

import javax.annotation.Resource;

import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.greenline.guahao.biz.manager.common.LocalPageModel;
import com.greenline.guahao.biz.manager.common.LocalResponseDO;
import com.greenline.guahao.biz.manager.hrs.HospitalManager;
import com.greenline.guahao.biz.manager.hrs.dataobject.ExpertDO;
import com.greenline.guahao.biz.manager.hrs.dataobject.HospitalDO;
import com.greenline.guahao.biz.manager.hrs.dataobject.HospitalRelationDO;
import com.greenline.guahao.biz.manager.hrs.dataobject.PropDO;
import com.greenline.guahao.biz.manager.search.BizSearchConstants;
import com.greenline.guahao.biz.manager.search.ExpertSearchManager;
import com.greenline.guahao.biz.manager.search.dataobject.SearchExpertsDO;
import com.greenline.guahao.biz.manager.search.dataobject.SearchParamDO;
import com.greenline.guahao.biz.util.BizCommonUtils;
import com.greenline.guahao.biz.util.JsonUtils;
import com.greenline.guahao.web.module.common.constants.GlobalConstants;
import com.greenline.guahao.web.module.common.constants.HospitalConstants;
import com.greenline.guahao.web.module.common.constants.SearchConstants;
import com.greenline.guahao.web.module.home.controllers.comment.CommentExpertProcess;
import com.greenline.guahao.web.module.home.controllers.hospital.HospitalProcess;
import com.greenline.guahao.web.module.home.controllers.search.ExpertSearchProcess;

/**
 * @Type HospitalTopicController
 * @Desc ?
 * @author Tony
 * @date 2014-5-23
 * @Version V1.0
 */
@Controller
public class HospitalTopicController {

    private static final Log log = LogFactory.getLog(HospitalTopicController.class);
    private static final String HOSPTOPIC_FTL_PATH = "promotion/hosptopic/hosptopic";
    private static final String JSON_FILE_PATH_SUFFIX = ".json";
    private static final String JSON_FILE_PATH_PRE = "/hosptopic/";
    private static final String JSON_MAP_KEY_THEME = "theme";
    private static final String JSON_MAP_KEY_APPDL = "showAppDownload";
    private static final String JSON_MAP_KEY_WEICHAT = "showWeiChat";
    private static final String JSON_MAP_KEY_PLACARD = "placard";
    /** ?? */
    private static final int SHARE_EXPERIENCE_COUNT = 12;
    /** 21?? */
    private static final String DEFAULT_HOT_DOCT_COUNT = "21";

    @Resource
    private HospitalProcess hospitalProcess;
    @Resource
    private HospitalManager hospitalManager;
    @Resource
    private PropDO propDO;
    @Resource
    private CommentExpertProcess commentExpertProcess;
    @Resource
    private ExpertSearchManager expertSearchManager;
    @Resource
    private ExpertSearchProcess expertSearchProcess;

    @RequestMapping("/hosptopic/{hospuuid}")
    public String showHospitalTopicPage(ModelMap model, @PathVariable("hospuuid") String hospId) {
        if (!BizCommonUtils.isUUID(hospId)) {
            // ?
            log.error(HospitalConstants.ERR_MSG_HOSPITAL_NOT_EXIST + hospId);
            model.put("error_message", HospitalConstants.ERR_MSG_HOSPITAL_NOT_EXIST);
            return GlobalConstants.ERROR_PAGE;
        }

        HospitalDO hospital = hospitalManager.getHospital(hospId);
        if (null == hospital) {
            // ?
            log.error(HospitalConstants.ERR_MSG_HOSPITAL_NOT_EXIST + hospId);
            model.put("error_message", HospitalConstants.ERR_MSG_HOSPITAL_NOT_EXIST);
            return GlobalConstants.ERROR_PAGE;
        }

        // ?json?
        boolean bool = analyseJsonProps(model, hospId);
        if (!bool) {
            model.put("error_message", "???");
            return GlobalConstants.ERROR_PAGE;
        }

        model.put("hospital", hospital);
        // ??
        model.put("experts", searchExpertForHospTopic(hospId));
        // ?
        hospitalProcess.getHospitalPhoto(model, hospId);
        // ??
        hospitalProcess.listHospitalDepts(model, hospId);
        // ?12?
        String result = getHospitalComment(model, hospId, hospital);
        if (StringUtils.isNotBlank(result)) {
            return result;
        }
        // ? 
        hospitalProcess.getHospitalNews(model, hospId);

        return HOSPTOPIC_FTL_PATH;
    }

    /**
     * ?????
     * 
     * @param model
     * @param hospId
     */
    private List<ExpertDO> searchExpertForHospTopic(String hospId) {
        SearchExpertsDO searchExperts = new SearchExpertsDO();
        searchExperts.setHospitalId(hospId);
        SearchParamDO searchParamDO = expertSearchProcess.getSearchExpertParam();
        searchParamDO.setFg("1");
        searchExperts.setOpen(SearchExpertsDO.NOT_LIMIT);
        searchExperts.setDoctorTitle(SearchExpertsDO.NOT_LIMIT);
        searchExperts.setSort(SearchConstants.SEARCH_SORT_BY_DOCTOR_HAOYUAN);
        searchExperts.setFl(BizSearchConstants.EXPERT_LIST_SEARCH_FL);
        searchExperts.setPageNo("1");
        searchExperts.setPageSize(DEFAULT_HOT_DOCT_COUNT);
        // ?
        searchExperts.setTravel("2");
        // ???
        searchExperts.setSecondSort("0");
        // ??
        LocalResponseDO<Object> lrd = new LocalResponseDO<Object>();
        // ??
        LocalPageModel<ExpertDO> lpm = expertSearchManager.searchExperts(lrd, searchExperts);
        if (!lrd.isSuccess()) {
            // ?
            log.error(lrd.getMessage() + ";" + lrd.getProfessionalInfo());

            return null;
        }

        return lpm.getList();
    }

    /**
     * ??12?
     * 
     * @param model
     * @param hospId
     * @param hospital
     */
    private String getHospitalComment(ModelMap model, String hospId, HospitalDO hospital) {
        List<String> hospitalids = null;
        List<HospitalRelationDO> hospitalRelationList = hospital.getHospitalRelationList();
        if (hospitalRelationList != null && hospitalRelationList.size() > 0) {
            hospitalids = new ArrayList<String>();
            for (HospitalRelationDO hospitalrelation : hospitalRelationList) {
                hospitalids.add(hospitalrelation.getHospitalId());
            }
        }

        if (hospitalids == null) {
            hospitalids = new ArrayList<String>();
            hospitalids.add(hospId);
        }

        return commentExpertProcess.commentHospitalList(model, hospitalids, false, 1, SHARE_EXPERIENCE_COUNT, 1,
                "0");
    }

    /**
     * ?hospId?hospId.json??
     * 
     * @param model
     * @param hospId
     */
    private boolean analyseJsonProps(ModelMap model, String hospId) {
        // ?hospuuid?json
        String jsonProp = BizCommonUtils
                .readTxtFile(propDO.getImgUploadBasePath() + JSON_FILE_PATH_PRE + hospId + JSON_FILE_PATH_SUFFIX);
        if (StringUtils.isBlank(jsonProp)) {
            // ??
            return false;
        }

        try {
            Map<Object, Object> map = JsonUtils.getMap4Json(jsonProp);
            if (CollectionUtils.isEmpty(map)) {
                // ??
                return false;
            }

            model.put("theme", map.get(JSON_MAP_KEY_THEME));
            model.put("showAppDL", map.get(JSON_MAP_KEY_APPDL));
            model.put("showWeichat", map.get(JSON_MAP_KEY_WEICHAT));
            JSONObject jsonObj = (JSONObject) map.get(JSON_MAP_KEY_PLACARD);
            if (!jsonObj.isEmpty() && !jsonObj.isNullObject()) {
                String placardStr = jsonObj.toString();
                model.put("placardMap", JsonUtils.getMap4Json(placardStr));
            }
        } catch (Exception e) {
            log.error("json analyse error!", e);
            return false;
        }

        return true;
    }
}