com.greenline.guahao.web.module.home.controllers.my.reservation.ReservationProcess.java Source code

Java tutorial

Introduction

Here is the source code for com.greenline.guahao.web.module.home.controllers.my.reservation.ReservationProcess.java

Source

/**
 * Project: guahao-portal-web-home
 * 
 * File Created at 2012-9-17
 * 
 * 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.my.reservation;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Component;
import org.springframework.ui.ModelMap;

import com.greenline.common.util.DESUtil;
import com.greenline.common.util.DateUtil;
import com.greenline.common.util.MD5Util;
import com.greenline.common.util.RegexUtil;
import com.greenline.eops.hessian.share.orderrequest.po.OrderRequestInfoQuery;
import com.greenline.framework.mursi.web.servlet.view.freemarker.MursiFreeMarkerViewResolver;
import com.greenline.guahao.biz.dal.dao.messageads.dataobject.MessageAdsDO;
import com.greenline.guahao.biz.enums.CertTypEnum;
import com.greenline.guahao.biz.enums.MedcardTypeEnum;
import com.greenline.guahao.biz.enums.ReservationErrMsgShowEnum;
import com.greenline.guahao.biz.enums.ReservationReturnErrMsgEnum;
import com.greenline.guahao.biz.enums.ShiftCaseStatusEnum;
import com.greenline.guahao.biz.enums.StatisticsTypeEnum;
import com.greenline.guahao.biz.enums.VCodeCachePrefixEnum;
import com.greenline.guahao.biz.enums.VerifyTypeEnum;
import com.greenline.guahao.biz.manager.OperateResult;
import com.greenline.guahao.biz.manager.apply.ApplyHaoyuanManager;
import com.greenline.guahao.biz.manager.area.AreaManager;
import com.greenline.guahao.biz.manager.cache.order.OrderValidLimitCacheManager;
import com.greenline.guahao.biz.manager.cache.valid.CodeCacheManager;
import com.greenline.guahao.biz.manager.healthrecord.HealthRecordManager;
import com.greenline.guahao.biz.manager.hrs.ExpertManager;
import com.greenline.guahao.biz.manager.hrs.dataobject.ExpertDO;
import com.greenline.guahao.biz.manager.messageads.MessageAdsManager;
import com.greenline.guahao.biz.manager.my.PatientManager;
import com.greenline.guahao.biz.manager.order.OrderManager;
import com.greenline.guahao.biz.manager.order.ShiftCaseManager;
import com.greenline.guahao.biz.manager.order.dataobject.NameValueDO;
import com.greenline.guahao.biz.manager.order.dataobject.OrderParamDO;
import com.greenline.guahao.biz.manager.order.dataobject.OrderResultDO;
import com.greenline.guahao.biz.manager.order.dataobject.ShiftCaseDO;
import com.greenline.guahao.biz.manager.remind.RemindManager;
import com.greenline.guahao.biz.manager.statistics.StatisticsManager;
import com.greenline.guahao.biz.manager.user.UserManager;
import com.greenline.guahao.biz.manager.user.dataobject.PatientInfoDO;
import com.greenline.guahao.biz.manager.user.dataobject.UserDO;
import com.greenline.guahao.biz.manager.user.result.PatientResult;
import com.greenline.guahao.biz.util.BizCommonUtils;
import com.greenline.guahao.biz.util.IllegalUserLog;
import com.greenline.guahao.healthrecord.service.dto.BasicInfoDTO;
import com.greenline.guahao.healthrecord.service.dto.PastMedicalHisDTO;
import com.greenline.guahao.healthrecord.service.dto.PastMedicalHisDetailDTO;
import com.greenline.guahao.healthrecord.service.dto.TreatmentHisDTO;
import com.greenline.guahao.web.module.common.constants.RemindConstants;
import com.greenline.guahao.web.module.common.constants.ReservationConstants;
import com.greenline.guahao.web.module.common.constants.ReservationMsgConstants;
import com.greenline.guahao.web.module.common.constants.UserPatientConstants;
import com.greenline.guahao.web.module.common.cookie.UserCookieUtil;
import com.greenline.guahao.web.module.common.json.BaseJsonObject;
import com.greenline.guahao.web.module.common.json.OperationJsonObject;
import com.greenline.guahao.web.module.common.utils.CommonUtils;
import com.greenline.guahao.web.module.common.utils.DateUtils;
import com.greenline.guahao.web.module.common.utils.IpUtil;
import com.greenline.guahao.web.module.common.utils.UserUtil;
import com.greenline.guahao.web.module.home.vo.order.OrderIpLimitVO;
import com.greenline.guahao.web.module.home.vo.reservation.PostReservationVO;
import com.greenline.guahao.web.module.home.vo.reservation.PostTumorInfoVO;
import com.greenline.guahao.web.module.home.vo.reservation.PostUpdateVO;
import com.greenline.guahao.web.module.home.vo.reservation.ReservationVO;
import com.greenline.guahao.web.module.home.vo.reservation.ShiftCaseVO;
import com.greenline.hrs.biz.service.dto.PatientTreatInfoDTO;
import com.greenline.hrs.biz.service.dto.ResponseCode;
import com.greenline.hrs.biz.service.dto.ResponseDTO;

/**
 * @Type ReservationProcess
 * @Desc ??
 * @author jianyun.zheng
 * @date 2012-9-17
 * @Version V1.0
 */
@Component
public class ReservationProcess {

    private static final Log log = LogFactory.getLog(ReservationProcess.class);

    @Resource
    private PatientManager patientManager;
    @Resource
    private ExpertManager expertManager;
    @Resource
    private AreaManager areaManager;
    @Resource
    private OrderManager orderManager;
    @Resource
    private ShiftCaseManager shiftCaseManager;
    @Resource
    private ReservationDOBuilder reservationDOBuilder;
    @Resource
    private StatisticsManager statisticsManager;
    @Resource
    private HttpServletRequest request;
    @Resource
    private CodeCacheManager codeCacheManager;
    @Resource
    private RemindManager remindManager;
    @Resource
    private UserManager userManager;
    @Resource
    private OrderValidLimitCacheManager orderValidLimitCacheManager;
    @Resource
    private MessageAdsManager messageAdsManager;
    @Resource
    private ApplyHaoyuanManager applyHaoyuanManager;
    @Resource
    private HealthRecordManager healthMgr;
    @Resource
    private MursiFreeMarkerViewResolver mursiFreeMarkerViewResolver;

    /**
     * ??
     * 
     * @param shiftCaseDO
     * @return BaseJsonObject
     */
    public BaseJsonObject checkShiftCase(ShiftCaseDO shiftCaseDO) {
        BaseJsonObject baseMsg = new BaseJsonObject();
        if (shiftCaseDO == null) {
            baseMsg.setMessage(ReservationMsgConstants.ERR_MSG_SHIFT_CASE_NOT_FOUND);
            baseMsg.setHasError(Boolean.TRUE);
            return baseMsg;
        } else if (shiftCaseDO.getAvailableSum() == null || shiftCaseDO.getAvailableSum() <= 0
                || shiftCaseDO.getStatus() == null
                || ShiftCaseStatusEnum.STATU2.getValue().equals(shiftCaseDO.getStatus())
                || ShiftCaseStatusEnum.STATU4.getValue().equals(shiftCaseDO.getStatus())
                || ShiftCaseStatusEnum.STATU5.getValue().equals(shiftCaseDO.getStatus())
                || ShiftCaseStatusEnum.STATU6.getValue().equals(shiftCaseDO.getStatus())
                || shiftCaseDO.getIsopen() == 1) {
            baseMsg.setMessage(ReservationMsgConstants.ERR_MSG_SHIFT_CASE_RESERVATION_OVER);
            baseMsg.setHasError(Boolean.TRUE);
            return baseMsg;
        }
        baseMsg.setHasError(Boolean.FALSE);

        return baseMsg;
    }

    /**
     * ???
     * 
     * @author wangbiao
     * @param error
     * @return String
     */
    public String getReservationErrorMessage(String error) {
        if (ReservationReturnErrMsgEnum.RETURN_MSG_1.getValue().equals(error)) {
            return ReservationErrMsgShowEnum.MSG_SHOW_1.getValue();
        } else if (ReservationReturnErrMsgEnum.RETURN_MSG_2.getValue().equals(error)) {
            return ReservationErrMsgShowEnum.MSG_SHOW_2.getValue();
        } else if (ReservationReturnErrMsgEnum.RETURN_MSG_3.getValue().equals(error)
                || ReservationReturnErrMsgEnum.RETURN_MSG_4.getValue().equals(error)
                || ReservationReturnErrMsgEnum.RETURN_MSG_7.getValue().equals(error)
                || ReservationReturnErrMsgEnum.RETURN_MSG_11.getValue().equals(error)) {
            return ReservationErrMsgShowEnum.MSG_SHOW_3.getValue();
        } else if (ReservationReturnErrMsgEnum.RETURN_MSG_5.getValue().equals(error)
                || ReservationReturnErrMsgEnum.RETURN_MSG_6.getValue().equals(error)) {
            return ReservationErrMsgShowEnum.MSG_SHOW_4.getValue();
        } else if (ReservationReturnErrMsgEnum.RETURN_MSG_8.getValue().equals(error)
                || ReservationReturnErrMsgEnum.RETURN_MSG_9.getValue().equals(error)) {
            return ReservationErrMsgShowEnum.MSG_SHOW_5.getValue();
        } else if (ReservationReturnErrMsgEnum.RETURN_MSG_10.getValue().equals(error)) {
            return ReservationErrMsgShowEnum.MSG_SHOW_6.getValue();
        } else {
            return error;
        }
    }

    /**
     * ??
     * 
     * @author wangbiao
     * @param model
     * @param user
     * @param shiftCaseDO
     */
    public void setPageValue(ModelMap model, Long userId, String mobile, ShiftCaseDO shiftCaseDO) {
        // ??
        ReservationVO reservationVO = reservationDOBuilder.getReservationVO(shiftCaseDO);
        // 
        List<PatientInfoDO> patientList = patientManager.ListMyPatient(userId);
        PatientInfoDO paient = new PatientInfoDO();
        //  
        if (null == patientList || patientList.size() < 1) {
            log.error(ReservationMsgConstants.ERR_MSG_PATIENT_LIST_NULL + userId);
        } else {
            paient = patientList.get(0);
        }

        String hospitalId = (String) model.get("hospitalId");
        if (ReservationConstants.TUMOR_ZZLZ_UUID.equalsIgnoreCase(hospitalId)) {
            model.put("isTumorFormShow", true);
            model.put("jzkName", ReservationConstants.CARD_TYPE_JZK_NAME);
        }

        // ?
        model.put("isFirstHosp", orderManager.isFirstVisitForHosp(String.valueOf(paient.getPatient_id()),
                shiftCaseDO.getHospitalUUID()));
        model.put("jzkValue",
                patientManager.getUserPatientCart(paient.getPatient_id(), shiftCaseDO.getHospitalUUID()));
        model.put("patientList", patientList);
        model.put("reservationVO", reservationVO);
        model.put("redict", patientManager.getRelationDictDef());
        // json????
        model.put("arrayPatient", CommonUtils.listToJson(patientList));
        // ?
        model.put("cerNopattern", ReservationConstants.CERNO_PATTERN);
        model.put("mobile", mobile);
        String encodeMobile = DESUtil.DESEncode(mobile, ReservationConstants.DESC_ORDER_KEY);
        model.put("encodeMobile", encodeMobile);
        model.put("provinces", areaManager.listProvinces());
        model.put("userId", userId);// ?????
    }

    /**
     * ??
     * 
     * @param model
     * @param shiftCaseDO
     */
    public void setLeftPageValue(ModelMap model, ShiftCaseDO shiftCaseDO) {
        ShiftCaseVO shiftCaseVO = reservationDOBuilder.getShiftCaseVO(shiftCaseDO);
        ExpertDO expert = expertManager.getExpert(shiftCaseDO.getExpertUuid());
        if (null == expert) {
            log.error(ReservationMsgConstants.ERR_MSG_EXPERT_NOT_EXIST);
        } else {
            shiftCaseVO.setExpertPhoto(expert.getPhoto());
            shiftCaseVO.setExpertSex(expert.getSex());
            shiftCaseVO.setHosptialName(expert.getHospitalName());
            shiftCaseVO.setDeptName(expert.getHospDeptName());
            shiftCaseVO.setHospitalStdName(expert.getHospitalStandardName());
        }

        model.put("shiftCaseVO", shiftCaseVO);
    }

    /**
     * ?
     * 
     * @param postUpdateVO
     * @param model
     * @param isAliIframe
     * @param userInfo
     * @return
     */
    public String checkSCWhenUpdate(PostUpdateVO postUpdateVO, ModelMap model, String type, Long userId,
            String mobile) {
        ShiftCaseDO shiftCaseDO = shiftCaseManager.getShiftCase(postUpdateVO.getHospitalId(),
                postUpdateVO.getShiftCaseId());
        if (null == shiftCaseDO) {
            model.put("error_message", ReservationMsgConstants.ERR_MSG_SHIFT_CASE_NOT_FOUND);
            return CommonUtils.getPartnersOrderErrorPage(type);
        }

        // ??
        this.setLeftPageValue(model, shiftCaseDO);
        // ??
        BaseJsonObject msgo = this.checkShiftCase(shiftCaseDO);
        if (msgo.getHasError()) {
            model.put("error_message", msgo.getMessage());
            model.put("hospDeptId", shiftCaseDO.getDeptUuid());
            return CommonUtils.getPartnersOrderErrorPage(type);
        }
        // ?
        this.setPageValue(model, userId, mobile, shiftCaseDO);
        return null;
    }

    /**
     * ?
     * 
     * @author wangbiao
     * @param model
     * @param orderResultDO
     * @param patientTelNumber
     * @param shiftCaseDO
     */
    public void setPageValue(ModelMap model, OrderResultDO orderResultDO, String patientTelNumber,
            ShiftCaseDO shiftCaseDO) {
        // ??
        model.put("mobileNo", patientTelNumber);
        // ??
        model.put("fetchAddress", shiftCaseDO.getFetchAddress());
        // ??
        // String time = StringUtils.EMPTY;
        // String dateWithoutTimeType =
        // DateUtils.getClinicDateStr(shiftCaseDO.getTheDate())
        // + ReservationConstants.EMPTY_STRING;
        // if (StringUtils.isNotBlank(orderResultDO.getTreatTime())) {
        // time = dateWithoutTimeType + orderResultDO.getTreatTime();
        // } else {
        // time = dateWithoutTimeType +
        // DateUtils.getApmStr(shiftCaseDO.getTimeType())
        // + ReservationConstants.EMPTY_STRING;
        // }
        // 
        String time = DateUtils.getClinicDateStr(shiftCaseDO.getTheDate()) + ReservationConstants.EMPTY_STRING;
        model.put("fetchTime", time);
    }

    /**
     * ?????? ?
     * 
     * @param json
     * @param jsonMap
     * @param postReservationVO
     */
    @SuppressWarnings("unchecked")
    public void checkRequires(OperationJsonObject json, Map<String, String> jsonMap,
            PostReservationVO postReservationVO) {

        // ?
        String namePrefix = postReservationVO.getVisitType().concat(ReservationConstants.REQUIRE_PREFIX);
        Map<String, String> mapmemo = this
                .strtoMap(request.getParameter("RequireNameStr" + postReservationVO.getVisitType()));
        // ????
        for (Enumeration<String> e = request.getParameterNames(); e.hasMoreElements();) {
            String name = e.nextElement();
            if (name.startsWith(namePrefix)) {
                String value = request.getParameter(name);
                // ?
                if (name.startsWith(namePrefix + ReservationConstants.IS_MUST)) {
                    if (StringUtils.isBlank(value)) {
                        json.setHasError(Boolean.TRUE);
                        String memo = mapmemo.get(name);
                        jsonMap.put(name, memo + ReservationMsgConstants.NOT_ALLOW_BLANK);
                        json.setMessage(memo + ReservationMsgConstants.NOT_ALLOW_BLANK);
                        break;
                    }
                }
                // ????
                String oldName = new String(name.replace(namePrefix, "").substring(1));
                if (ReservationConstants.CAR_TYPE.contains(oldName)) {
                    // ?
                    postReservationVO.setPatientMeCarType(value);
                } else if (ReservationConstants.CAR_VALUE.contains(oldName)) {
                    postReservationVO.setPatientMeCarNo(value);// ??
                    if (StringUtils.isNotBlank(value) && RegexUtil.isChinese(value)) {
                        json.setHasError(Boolean.TRUE);
                        String memo = mapmemo.get(name);
                        jsonMap.put(name, memo + ReservationMsgConstants.IS_NOT_CHINESE);
                        json.setMessage(memo + ReservationMsgConstants.IS_NOT_CHINESE);
                        break;
                    }

                }
            }
        }
    }

    /**
     * ??
     * 
     * @param json
     * @param jsonMap
     * @param postReservationVO
     */
    public void updatePatientInfo(OperationJsonObject json, Map<String, String> jsonMap,
            PostReservationVO postReservationVO) {
        PatientInfoDO patient = postReservationVO.getPatient();
        String carValue = postReservationVO.getPatientMeCarNo();
        String carType = postReservationVO.getPatientMeCarType();
        Long patientid = postReservationVO.getPatient().getPatient_id();

        String patientListSize = request.getParameter("patientListSize");
        if (8 < Integer.valueOf(patientListSize) && -1 == postReservationVO.getPatient().getPatient_id()) {
            json.setHasError(Boolean.TRUE);
            json.setMessage(ReservationMsgConstants.PATIENTSIZE);
        } else {
            // ????
            boolean isUpdateYbk = ReservationConstants.CAR_TYPE_YBK_VALUE.equals(carType);
            if (!isUpdateYbk) {
                patient.setUpdate_med_no(Boolean.FALSE);
            } else {
                patient.setPatient_med_type(MedcardTypeEnum.MEDIN.getValue());
                patient.setPatient_med_no(carValue);
            }
            if (!json.getHasError()) { // ???
                patient = this.changePatient(json, jsonMap, patient, null);
            }
            if (!json.getHasError()) {
                PatientInfoDO patientInfoDO = patientManager.getPatientByPatientId(patientid);
                if (patientInfoDO != null && StringUtils.isNotBlank(patientInfoDO.getPatient_cert_no())
                        && "15".equals(String.valueOf(patientInfoDO.getPatient_cert_no().length()))) {
                    json.setHasError(Boolean.TRUE);
                    json.setMessage(UserPatientConstants.CERNO_IS_ONE);
                }
            }
            if (!json.getHasError()) {
                // ????id
                if (StringUtils.isNotBlank(carValue) && !isUpdateYbk) {
                    patientManager.addUserPatientCart(patient.getPatient_id(), postReservationVO.getHospitalId(),
                            carValue);
                }
            }
        }
    }

    /**
     * ??
     * 
     * @param json
     * @param jsonMap
     * @param postReservationVO
     */
    public PatientInfoDO updatePatientInfoNew(OperationJsonObject json, Map<String, String> jsonMap, Integer type,
            PatientInfoDO patient) {
        return this.changePatient(json, jsonMap, patient, type);
    }

    /**
     * ??
     * 
     * @param json
     * @param jsonMap
     * @param patient
     * @param type
     */
    private PatientInfoDO changePatient(OperationJsonObject json, Map<String, String> jsonMap,
            PatientInfoDO patient, final Integer type) {
        // ???
        boolean isUpdate = null != patient.getPatient_birthday() && null != patient.getPatient_sex();
        if (isUpdate || MedcardTypeEnum.MEDIN.getValue().equals(patient.getPatient_med_type())) {
            String name = ReservationMsgConstants.PATIENT_NAME;
            String msg = ReservationMsgConstants.PATIENT;
            if (new Integer(1).equals(type)) {
                // 1?
                name = ReservationMsgConstants.AGENT_NAME;
                msg = ReservationMsgConstants.AGENT;
            }
            if (isUpdate) {
                this.checkPatientInfo(json, jsonMap, patient, name, msg);
                // ?
                if (StringUtils.isBlank(patient.getPatient_cert_type())) {
                    patient.setPatient_cert_type(CertTypEnum.IDCARD.getValue());
                }
            }
            if (!json.getHasError()) {
                long agenId = patient.getPatient_id();
                // ??id-1
                if (-1 == agenId) {
                    // 
                    return this.addPatient(json, jsonMap, patient, name);
                } else {
                    // 
                    this.updatePatient(json, patient, name);
                    if (!json.getHasError()) {
                        return patientManager.getPatientByPatientId(patient.getPatient_id());
                    }
                }
            }
        } else {
            PatientInfoDO patientInfoDO = patientManager.getPatientByPatientId(patient.getPatient_id());
            if (patientInfoDO != null && !"1".equals(patientInfoDO.getRelationship().toString())
                    && StringUtils.isNotBlank(patientInfoDO.getPatient_cert_no())
                    && "15".equals(String.valueOf(patientInfoDO.getPatient_cert_no().length()))) {
                json.setHasError(Boolean.TRUE);
                json.setMessage(UserPatientConstants.ERR_MSG_CERT_NO_ERROR);
            }
        }

        return patient;
    }

    /**
     * ?
     * 
     * @param json
     * @param jsonMap
     * @param patient
     * @param name
     */
    private PatientInfoDO addPatient(OperationJsonObject json, Map<String, String> jsonMap,
            final PatientInfoDO patient, final String name) {
        PatientResult pa = new PatientResult();
        // 
        patient.setUser_id(UserCookieUtil.getUserId(request));
        patient.setPatient_cert_no(StringUtils.trim(patient.getPatient_cert_no().toUpperCase()));
        patient.setPatient_birthday(patient.getPatient_birthday().replaceAll("-", ""));
        patient.setSource(UserPatientConstants.SOURCE_PORTAL);
        patient.setPatient_mobile(StringUtils.trim(patient.getPatient_mobile()));
        patient.setPatient_name(StringUtils.trim(patient.getPatient_name()));
        pa = patientManager.addPatient(patient);
        if (pa.isSystemError()) {
            // ?
            json.setHasError(Boolean.TRUE);
            json.setMessage(pa.getResponseDesc());

            return null;
        } else {
            // ?id
            patient.setPatient_id(pa.getPatientInfoDO().getPatient_id());
            // ????id?
            jsonMap.put(name + ".patient_id", String.valueOf(patient.getPatient_id()));

            return pa.getPatientInfoDO();
        }
    }

    /**
     * ???
     * 
     * @param json
     * @param patient
     * @param name
     */
    private void updatePatient(OperationJsonObject json, final PatientInfoDO patient, final String name) {
        PatientResult pa = new PatientResult();
        // 
        PatientInfoDO patientInfoDO = patientManager.getPatientByPatientId(patient.getPatient_id());
        if (null != patientInfoDO && patientInfoDO.getPatient_mobile().equals(patient.getPatient_mobile())) {
            patient.setPatient_mobile(null);
        }
        pa = patientManager.updatePatient(patient);
        if (pa.isSystemError()) {
            // ?
            json.setHasError(Boolean.TRUE);
            json.setMessage(pa.getResponseDesc());
        }
    }

    /**
     * ????
     * 
     * @param json
     * @param jsonMap
     * @param patient
     * @param name
     * @param msg
     */
    private void checkPatientInfo(OperationJsonObject json, Map<String, String> jsonMap,
            final PatientInfoDO patient, final String name, final String msg) {
        if (null != patient && null != patient.getPatient_birthday()) {
            if (null != patient.getRelationship()) {
                // ??
                if (!RegexUtil.isIdCard(StringUtils.trim(patient.getPatient_cert_no()))) {
                    json.setHasError(Boolean.TRUE);
                    jsonMap.put(name + "patient_cert_no", msg + ReservationMsgConstants.ERR_MSGCERT_NO);
                    json.setMessage(msg + ReservationMsgConstants.ERR_MSGCERT_NO);
                }
                // ?
                if (!json.getHasError() && !RegexUtil.isMobile(StringUtils.trim(patient.getPatient_mobile()))) {
                    json.setHasError(Boolean.TRUE);
                    jsonMap.put(name + "patient_mobile", msg + ReservationMsgConstants.ERR_MSG_MOBILE);
                    json.setMessage(msg + ReservationMsgConstants.ERR_MSG_MOBILE);
                }
            }
            if (!json.getHasError()) {
                if (DateUtil.getDatebyString(patient.getPatient_birthday()).after(new Date())) {
                    json.setHasError(Boolean.TRUE);
                    json.setMessage(msg + ReservationMsgConstants.BIRDAYISERROR);
                }
            }
        }
    }

    /**
     * ??
     * 
     * @param json
     * @param jsonMap
     * @param postReservationVO
     */
    public void checkReservation(OperationJsonObject json, Map<String, String> jsonMap,
            final PostReservationVO postReservationVO) {
        // 
        if (null == postReservationVO.getPatient()) {
            json.setHasError(Boolean.TRUE);
            json.setMessage(ReservationMsgConstants.MUST_CHECK_PATIENT);
            jsonMap.put("patient.patient_id", ReservationMsgConstants.MUST_CHECK_PATIENT);
        } else {
            if (-1 == postReservationVO.getPatient().getPatient_id()) {
                checkPatientInfo(json, postReservationVO.getPatient());
            }
        }
        if (!json.getHasError()) {
            // 
            if (StringUtils.isBlank(postReservationVO.getVisitType())) {
                json.setHasError(Boolean.TRUE);
                json.setMessage(ReservationMsgConstants.MUST_CHECK_VISITTYPE);
                jsonMap.put("visitType", ReservationMsgConstants.MUST_CHECK_VISITTYPE);
            }
        }
    }

    /**
     * ?
     * 
     * @param postReservationVO
     * @param patient
     */
    public void checkAgeSex(OperationJsonObject json, final PostReservationVO postReservationVO) {
        PatientInfoDO patient = postReservationVO.getPatient();
        if (null == patient.getRelationship()) {
            // ??
            PatientInfoDO oriPatient = patientManager.getPatientByPatientId(patient.getPatient_id());
            if (null != patient.getPatient_sex() && null != patient.getPatient_birthday()) {
                oriPatient.setPatient_sex(patient.getPatient_sex());
                oriPatient.setPatient_birthday(patient.getPatient_birthday());
            }
            patient = oriPatient;
        }

        int age = 0;
        if (StringUtils.isNotBlank(patient.getPatient_birthday())) {
            Date birdateDate = DateUtil.getDatebyString(patient.getPatient_birthday());
            if (birdateDate == null) {
                json.setHasError(Boolean.TRUE);
                json.setMessage("??");
                return;
            } else {
                Calendar now = Calendar.getInstance();
                Calendar bir = Calendar.getInstance();
                bir.setTime(DateUtil.getDatebyString(patient.getPatient_birthday()));
                age = now.get(Calendar.YEAR) - bir.get(Calendar.YEAR);
            }
        }

        int lowAge = (postReservationVO.getAgeLowerLimit() == null ? 0
                : postReservationVO.getAgeLowerLimit().intValue());
        int topAge = (postReservationVO.getAgeTopLimit() == null ? 150
                : postReservationVO.getAgeTopLimit().intValue());
        int limitSex = (postReservationVO.getSexLimit() == null ? 3 : postReservationVO.getSexLimit().intValue());
        int sex = patient.getPatient_sex() == null ? 3 : patient.getPatient_sex().intValue();
        if (lowAge > age || topAge < age) {
            json.setHasError(Boolean.TRUE);
            json.setMessage("?" + lowAge + "?" + topAge + "???.");
            return;
        }
        // 3??
        if (ReservationMsgConstants.DEFAULT_LIMIT_SEX != limitSex && sex != limitSex) {
            json.setHasError(Boolean.TRUE);
            json.setMessage("?" + (limitSex == 1 ? "" : "") + "??");
            return;
        }
    }

    /**
     * stringmap
     * 
     * @param str
     * @return Map<String, String>
     */
    private Map<String, String> strtoMap(String str) {
        Map<String, String> map = new HashMap<String, String>(0);
        if (StringUtils.isNotBlank(str)) {
            String[] nameValue = str.split(ReservationConstants.SPLIT_DOUBLE_COMMA2);
            if (null != nameValue && nameValue.length > 0) {
                for (String content : nameValue) {
                    String[] name = content.split(ReservationConstants.SPLIT_DOUBLE_COMMA);
                    if (name.length > 1) {
                        map.put(name[0], name[1]);
                    }
                }
            }
        }
        return map;
    }

    /**
     * ?,
     * 
     * orderIpLimitVO?ip??,true??false
     * 
     * @author wangbiao
     * @param postReservationVO
     * @return OperateResult<OrderResultDO>
     */
    public OperateResult<OrderResultDO> addOrder(PostReservationVO postReservationVO,
            OrderIpLimitVO orderIpLimitVO) {
        //  ??ip??
        String ip = null;
        String sessionId = null;
        boolean isHasIpKeyInCache = false;
        // ?04?IP???10
        SimpleDateFormat destsmf = new SimpleDateFormat("HHmm");
        int nowtime = Integer.parseInt(destsmf.format(new Date()));
        if (orderValidLimitCacheManager.exitsInLimitTimesRange(nowtime)) {
            ip = IpUtil.getIpAddr(request).split("\\,")[0];
            sessionId = UserCookieUtil.getSessionId(request);
            if (orderValidLimitCacheManager.hasIpKeyInCache(ip)
                    || orderValidLimitCacheManager.hasSessionIdKeyInCache(sessionId)) {
                // 
                IllegalUserLog illegaluserlog = new IllegalUserLog();
                illegaluserlog.setServerName(CommonUtils.getServerName(request));
                illegaluserlog.setRequestUrl(CommonUtils.getRequestUrl(request));
                illegaluserlog.setSource("1");// 1-?2-html5
                illegaluserlog.setCuserId(orderIpLimitVO.getUserid());
                illegaluserlog.setExpertId(postReservationVO.getExpertId());
                illegaluserlog.setHospDeptId(postReservationVO.getDeptId());
                illegaluserlog.setHospitalId(postReservationVO.getHospitalId());
                illegaluserlog.setScid(postReservationVO.getShiftCaseId());
                illegaluserlog.setRemark(
                        "?IPsessionId???sessionId=" + sessionId + ",ip=" + ip);
                illegaluserlog.setType("2");// 
                illegaluserlog.setOrderStep("4");// ?
                log.error(illegaluserlog.toString());

                isHasIpKeyInCache = true;
                orderIpLimitVO.setErrorMessage("??????");
                return null;
            }
        }

        // ??
        OrderParamDO param = reservationDOBuilder.getOrderParam(request, postReservationVO);
        OperateResult<OrderResultDO> orderResult;
        if (ReservationConstants.IS_NEED_AGENT_YES == postReservationVO.getIsNeedAgent()) {
            // ?
            orderResult = orderManager.order(param, reservationDOBuilder.getAgent(postReservationVO));
        } else {
            // ?
            orderResult = orderManager.order(param);
        }

        //  ??ip?
        if (!isHasIpKeyInCache && OperateResult.SUCCESS.equals(orderResult.getCode())
                && orderValidLimitCacheManager.exitsInLimitTimesRange(nowtime)) {
            orderValidLimitCacheManager.setIp(ip, orderValidLimitCacheManager.getTimeoutMinutes());
            orderValidLimitCacheManager.setSessionId(sessionId, orderValidLimitCacheManager.getTimeoutMinutes());
        }

        return orderResult;
    }

    /**
     * ?
     * 
     * @author wangbiao
     * @param postReservationVO
     * @param orderResult
     */
    public void addPatientTreatInfo(PostReservationVO postReservationVO, OperateResult<OrderResultDO> orderResult) {
        PatientTreatInfoDTO patientTreatInfoDTO = new PatientTreatInfoDTO();
        reservationDOBuilder.setPatientTreatInfoDTO(patientTreatInfoDTO, postReservationVO);
        if (null != orderResult && OperateResult.SUCCESS.equals(orderResult.getCode())
                && null != orderResult.getDataResult()) {
            // ?id
            patientTreatInfoDTO.setOrderUuid(orderResult.getDataResult().getOrderNo());
        }
        ResponseDTO<?> responseDTO = patientManager.addPatientTreatInfo(patientTreatInfoDTO);
        if (!ReservationConstants.RESPONSE_CODE_SUCCESS.equals(responseDTO.getCode())) {
            // 
            log.error(responseDTO.getMessage());
        }
    }

    /**
     * ???
     * 
     * @author wangbiao
     * @param model
     * @param postReservationVO
     * @param orderResult
     * @param needPay
     * @param shiftCaseDO
     * @param email
     * @return boolean
     */
    @SuppressWarnings("deprecation")
    public boolean afterOrderHandle(ModelMap model, PostReservationVO postReservationVO,
            OperateResult<OrderResultDO> orderResult, boolean needPay, ShiftCaseDO shiftCaseDO, String mobile,
            String email) {
        if (null == orderResult) {
            model.put("error_message", ReservationMsgConstants.ERR_MSG_SYSTEM_ERROR_RESERVATION_FAIL);
            return Boolean.FALSE;
        }
        if (OperateResult.SUCCESS.equals(orderResult.getCode())) {
            // ?
            OrderResultDO orderResultDO = orderResult.getDataResult();
            model.put("needPay", needPay);
            model.put("patientName", postReservationVO.getPatient().getPatient_name());

            // ???
            if (needPay) {
                // ??
                orderManager.sendSuccessMessage(postReservationVO.getPatient().getPatient_mobile(),
                        orderResultDO.getMessage());
            } else {
                orderManager.sendSuccessMessage(postReservationVO.getPatient().getPatient_mobile(),
                        orderResultDO.getMessage());
            }

            Long userId = UserCookieUtil.getUserId(request);
            // ? 
            if (needPay) {
                statisticsManager.updateStatistics(StatisticsTypeEnum.NEED_PAY.getValue(), userId.toString(), null,
                        "1");
            } else {
                // ?
                this.setPageValue(model, orderResultDO, postReservationVO.getPatient().getPatient_mobile(),
                        shiftCaseDO);
                model.put("orderMessage", orderResultDO.getMessage());

                // ???
                statisticsManager.updateStatistics(StatisticsTypeEnum.NOT_TREATMENT.getValue(), userId.toString(),
                        null, "1");
            }

            // ???(????)
            // if (CheckMobile.checkOperator(mobile) == 0) {
            // MessageAdsDO messageAdsDO = new MessageAdsDO();
            // messageAdsDO.setTelphoneEmail(mobile);
            // messageAdsDO.setSenddate(com.greenline.guahao.biz.util.DateUtils.getYmdDateString(new
            // Date()));
            // if (!messageAdsManager.isSendMessage(messageAdsDO)) {
            // orderManager.sendSuccessMessage(mobile,
            // ReservationMsgConstants.EXTEND_MESSAGE, 8);
            // messageAdsManager.insertSendTelEmail(messageAdsDO);
            // }
            // }

            // ??
            if (RegexUtil.isEmail(email)) {
                MessageAdsDO messageAdsDO = new MessageAdsDO();
                messageAdsDO.setTelphoneEmail(email);
                messageAdsDO.setSenddate(com.greenline.guahao.biz.util.DateUtils.getYmdDateString(new Date()));
                if (!messageAdsManager.isSendMessage(messageAdsDO)) {
                    if (messageAdsManager.sendAdsEmail(email)) {
                        messageAdsManager.insertSendTelEmail(messageAdsDO);
                    }
                }
            }

            // ??
            model.put("orderNo", orderResultDO.getOrderNo());
            model.put("orderDetail", orderManager.getOrder(orderResultDO.getOrderNo()));
            return Boolean.TRUE;
        } else {
            // ?
            if (StringUtils.isBlank(orderResult.getMessage())
                    || orderResult.getMessage().indexOf(ReservationMsgConstants.MSG_ORA) > 0) {
                model.put("error_message", ReservationMsgConstants.ERR_MSG_SYSTEM_ERROR_RESERVATION_FAIL);
            } else {
                model.put("error_message", getReservationErrorMessage(orderResult.getMessage()));
            }
            return Boolean.FALSE;
        }
    }

    /**
     * ?
     * 
     * @param patientId
     * @param expert_id
     * @return String
     */
    public String isFirstVisitForExp(long patientId, String expert_id) {
        boolean flag = orderManager.isFirstVisitForExp(patientId, expert_id);
        if (flag) {
            return ReservationConstants.IS_FIRST_VISIT;
        }
        return ReservationConstants.NOT_FIRST_VISIT;
    }

    /**
     * ???
     * 
     * @param json
     * @param postReservationVO
     */
    public void initReason(OperationJsonObject json, PostReservationVO postReservationVO) {
        Map<String, String> jsonMap = new HashMap<String, String>(0);
        // ?hdecode : md5(?id+id+1+mobilevalidcodepwd)
        String hdecodePage = postReservationVO.getHdecode();
        String hdecode = MD5Util.getMD5Format(postReservationVO.getShiftCaseId() + postReservationVO.getExpertId()
                + "1" + this.getMobilevalidcodepwd());
        if (!hdecode.equals(hdecodePage)) {
            // ?
            json.setHasError(Boolean.TRUE);
            json.setMessage("??");
            json.setCode(ReservationConstants.RESERVATION_ERROR_CODE_JSON);
            // 
            log.error(
                    "@pcres=2?@expertId="
                            + postReservationVO.getExpertId() + "@userId=" + UserCookieUtil.getUserId(request)
                            + StringUtils.EMPTY);
        } else {
            // ?
            jsonMap.put("rescodeFirst", MD5Util.getMD5Format(this.getMobilevalidcodepwd() + "1"
                    + postReservationVO.getExpertId() + postReservationVO.getShiftCaseId()));

            // ??
            ShiftCaseDO shiftCaseDO = shiftCaseManager.getShiftCase(postReservationVO.getHospitalId(),
                    postReservationVO.getShiftCaseId());
            // ??
            BaseJsonObject msg = this.checkShiftCase(shiftCaseDO);
            if (msg.getHasError()) {
                json.setHasError(Boolean.TRUE);
                json.setMessage(msg.getMessage());
                json.setCode(ReservationConstants.RESERVATION_ERROR_CODE_JSON);
                jsonMap.put("shiftCaseId", msg.getMessage());
            }
            if (!json.getHasError()) {
                // 
                this.checkReservation(json, jsonMap, postReservationVO);
            }
            if (!json.getHasError()) {
                // 
                this.checkRequires(json, jsonMap, postReservationVO);
            }
            // ?
            if (!json.getHasError()) {
                this.checkAgeSex(json, postReservationVO);
            }
            // ?
            if (!json.getHasError()) {
                this.updatePatientInfo(json, jsonMap, postReservationVO);
            }
            // ??
            if (!json.getHasError()) {
                jsonMap.put("isFirstVisit", this.isFirstVisitForExp(postReservationVO.getPatient().getPatient_id(),
                        postReservationVO.getExpertId()));
            }
            if (!json.getHasError()) {
                this.checkBeforeOrder(json, postReservationVO);
            }
        }
        json.setData(jsonMap);
    }

    private void checkBeforeOrder(OperationJsonObject json, PostReservationVO postReservationVO) {
        OrderParamDO orderParam = new OrderParamDO();
        orderParam.setShiftCaseId(postReservationVO.getShiftCaseId());
        String requireType = postReservationVO.getVisitType();
        List<NameValueDO> nameValueDOList = reservationDOBuilder.getRequiredData(request, requireType);
        reservationDOBuilder.addTumorInfoRequires(postReservationVO, nameValueDOList);
        orderParam.setRequiredData(nameValueDOList);
        if (postReservationVO.getPatient() != null) {
            PatientInfoDO patientInfoDO = patientManager
                    .getPatientByPatientId(postReservationVO.getPatient().getPatient_id());
            if (null != patientInfoDO) {
                postReservationVO.setPatient(patientInfoDO);
                orderParam.setUserId(String.valueOf(patientInfoDO.getUser_id()));
                orderParam.setPatient(reservationDOBuilder.getPatient(patientInfoDO,
                        Integer.valueOf(postReservationVO.getVisitType())));
                OperateResult<Boolean> result = orderManager.checkBeforeOrder(orderParam);
                if (null != result && ResponseCode.isSuccess(result.getCode())) {
                    if (result.getDataResult() != null && !result.getDataResult()) {
                        json.setHasError(true);
                        json.setMessage(result.getMessage());
                    }
                } else {
                    json.setHasError(true);
                    json.setMessage(result.getMessage());
                }
            } else {
                json.setHasError(true);
                json.setMessage("?");
            }
        } else {
            json.setHasError(true);
            json.setMessage("?");
        }
    }

    /**
     * ????,?
     * 
     * @param json
     * @param postReservationVO
     */
    public void initTumorInfo(OperationJsonObject json, PostReservationVO postReservationVO) {
        Map<String, String> jsonMap = new HashMap<String, String>(0);
        PostTumorInfoVO tumorInfo = postReservationVO.getTumorInfo();
        if (null == tumorInfo) {
            json.setHasError(Boolean.TRUE);
            json.setMessage(ReservationMsgConstants.TUMOR_ERR_MSG);
            json.setCode(ReservationConstants.RESERVATION_ERROR_CODE_JSON);
            jsonMap.put("tumorInfo.addrs", ReservationMsgConstants.TUMOR_ERR_MSG);
        }

        String addrs = tumorInfo.getAddrs();
        if (StringUtils.isBlank(addrs)) {
            json.setHasError(Boolean.TRUE);
            json.setCode(ReservationConstants.RESERVATION_ERROR_CODE_JSON);
            json.setMessage(ReservationMsgConstants.TUMOR_ADDR_ERR_MSG);
            jsonMap.put("tumorInfo.addrs", ReservationMsgConstants.TUMOR_ADDR_ERR_MSG);
        }

        String email = tumorInfo.getEmail();
        if (StringUtils.isBlank(email)) {
            json.setHasError(Boolean.TRUE);
            json.setMessage(ReservationMsgConstants.TUMOR_EMAIL_ERR_MSG);
            jsonMap.put("tumorInfo.email", ReservationMsgConstants.TUMOR_EMAIL_ERR_MSG);
        }

        // ????
        String hisOfDrugAllergyStatus = tumorInfo.getHisOfDrugAllergyStatus();
        String hisOfDrugAllergy = tumorInfo.getHisOfDrugAllergy();
        if ((ReservationConstants.TUMOR_HIS_FOR_YES.equals(hisOfDrugAllergyStatus))
                && StringUtils.isBlank(hisOfDrugAllergy)) {// ???
            json.setHasError(Boolean.TRUE);
            json.setMessage(ReservationMsgConstants.TUMOR_DRUG_ALLERGY_ERR_MSG);
            jsonMap.put("tumorInfo.hisOfDrugAllergy", ReservationMsgConstants.TUMOR_DRUG_ALLERGY_ERR_MSG);
        }

        String hisOfCancerDiseaseStatus = tumorInfo.getHisOfCancerDiseaseStatus();
        // ?
        String hisOfCancerDisease = tumorInfo.getHisOfCancerDisease();
        if ((ReservationConstants.TUMOR_HIS_FOR_YES.equals(hisOfCancerDiseaseStatus))
                && StringUtils.isBlank(hisOfCancerDisease)) {
            json.setHasError(Boolean.TRUE);
            json.setMessage(ReservationMsgConstants.TUMOR_CANCER_ERR_MSG);
            jsonMap.put("tumorInfo.hisOfCancerDisease", ReservationMsgConstants.TUMOR_CANCER_ERR_MSG);
        }

        String familyHistoryStatus = tumorInfo.getFamilyHistoryStatus();
        // ??
        String familyHis = tumorInfo.getFamilyHistory();
        if ((ReservationConstants.TUMOR_HIS_FOR_YES.equals(familyHistoryStatus))
                && StringUtils.isBlank(familyHis)) {
            json.setHasError(Boolean.TRUE);
            json.setMessage(ReservationMsgConstants.TUMOR_FAMILY_ERR_MSG);
            jsonMap.put("tumorInfo.familyHistory", ReservationMsgConstants.TUMOR_FAMILY_ERR_MSG);
        }

        if (ReservationConstants.TUMOR_HIS_FOR_YES.equals(tumorInfo.getDiseaseHisExist())) {
            String diaHis = tumorInfo.getDiabetesHis();
            String hyperHis = tumorInfo.getHypertensionHis();
            String emphHis = tumorInfo.getEmphysemaHis();
            boolean flag = false;
            if (StringUtils.isBlank(diaHis) && StringUtils.isBlank(hyperHis) && StringUtils.isBlank(emphHis)) {
                flag = true;
            }

            String otherHis = tumorInfo.getOtherHisStatus();
            if (flag && StringUtils.isBlank(otherHis)) {
                json.setHasError(Boolean.TRUE);
                json.setMessage(ReservationMsgConstants.TUMOR_CHRONIC_ERR_MSG);
                jsonMap.put("tumorInfo.diseaseHisExist", ReservationMsgConstants.TUMOR_CHRONIC_ERR_MSG);
            } else if (StringUtils.isNotBlank(otherHis)) {
                String otherHisValue = tumorInfo.getOtherHis();
                if (StringUtils.isBlank(otherHisValue)) {
                    json.setHasError(Boolean.TRUE);
                    json.setMessage(ReservationMsgConstants.TUMOR_CHRONIC_ERR_FOR_OTHER);
                    jsonMap.put("tumorInfo.diseaseHisExist", ReservationMsgConstants.TUMOR_CHRONIC_ERR_FOR_OTHER);
                }
            }

        }

        json.setData(jsonMap);
    }

    public void tumorInfoBackfill(OperationJsonObject json, String patientUserId) {
        if (StringUtils.isBlank(patientUserId)) {
            return;
        }
        // ?
        PatientInfoDO patientInfoDO = patientManager.getPatientByPatientId(Long.parseLong(patientUserId));
        if (null == patientInfoDO) {
            return;
        } else {
            Long userId = UserCookieUtil.getUserId(request);
            if (!userId.toString().equals(String.valueOf(patientInfoDO.getUser_id()))) {
                return;
            }
        }

        Map<String, PostTumorInfoVO> jsonMap = new HashMap<String, PostTumorInfoVO>(0);
        PostTumorInfoVO tumorInfo = new PostTumorInfoVO();
        BasicInfoDTO basic = healthMgr.getBasicInfo(Long.valueOf(patientUserId));
        if (null != basic) {
            tumorInfo.setPatientId(String.valueOf(basic.getUserId()));
            tumorInfo.setAddrs(basic.getAddress());
            tumorInfo.setEducation(basic.getEducationalStatus());
            tumorInfo.setEmail(basic.getEmail());
            tumorInfo.setFax(basic.getFax());
            tumorInfo.setNationality(basic.getNationality());
            tumorInfo.setProfession(basic.getJob());
            tumorInfo.setReligion(basic.getReligion());
        }

        PastMedicalHisDTO pastGmsHis = healthMgr.getPastMedicalHis(Long.valueOf(patientUserId),
                ReservationConstants.TUMOR_HIS_GMS);
        if (null != pastGmsHis) {
            List<PastMedicalHisDetailDTO> detailList = pastGmsHis.getMedicalHisList();
            for (int i = 0; i < detailList.size(); i++) {
                PastMedicalHisDetailDTO detail = detailList.get(i);
                if (ReservationConstants.TUMOR_HIS_GMS_NAME.equals(detail.getDisease())) {
                    tumorInfo.setHisOfDrugAllergyStatus(ReservationConstants.TUMOR_HIS_FOR_YES);
                    tumorInfo.setHisOfDrugAllergy(detail.getDrugName());
                    tumorInfo.setHealthRecordIdForDrugAllergy(detail.getId());
                    break;
                }
            }
        }

        PastMedicalHisDTO pastJzsHis = healthMgr.getPastMedicalHis(Long.valueOf(patientUserId),
                ReservationConstants.TUMOR_HIS_JZS);
        if (null != pastJzsHis) {
            List<PastMedicalHisDetailDTO> detailList = pastJzsHis.getMedicalHisList();
            for (int i = 0; i < detailList.size(); i++) {
                PastMedicalHisDetailDTO detail = detailList.get(i);
                if (ReservationConstants.TUMOR_HIS_JZS_NAME.equals(detail.getDisease())) {
                    tumorInfo.setFamilyHistoryStatus(ReservationConstants.TUMOR_HIS_FOR_YES);
                    tumorInfo.setFamilyHistory(detail.getDesc());
                    tumorInfo.setHealthRecordIdForFamilyHistory(detail.getId());
                } else if (ReservationConstants.TUMOR_HIS_ZLS_NAME.equals(detail.getDisease())) {
                    tumorInfo.setHisOfCancerDiseaseStatus(ReservationConstants.TUMOR_HIS_FOR_YES);
                    tumorInfo.setHisOfCancerDisease(detail.getDesc());
                    tumorInfo.setHealthRecordIdForCancerDisease(detail.getId());
                }
            }
        }

        List<TreatmentHisDTO> treatList = healthMgr.listTreatmentHis(Long.valueOf(patientUserId));
        if (CollectionUtils.isEmpty(treatList)) {
            tumorInfo.setDiseaseHisExist(ReservationConstants.TUMOR_DISEASE_EXIST_NO);
        } else {
            TreatmentHisDTO treatDo = null;
            for (TreatmentHisDTO treat : treatList) {
                if (ReservationConstants.TUMOR_HOSP_NAME.equals(treat.getTreatOrg())) {
                    treatDo = treat;
                    break;
                }
            }

            if ((null == treatDo) || StringUtils.isBlank(treatDo.getDisease())) {
                tumorInfo.setDiseaseHisExist(ReservationConstants.TUMOR_DISEASE_EXIST_NO);
            } else {
                String disease = treatDo.getDisease();
                String[] diseaseArr = disease.split(";");
                for (String disName : diseaseArr) {
                    if (StringUtils.isBlank(disName)) {
                        continue;
                    }

                    if (ReservationConstants.TUMOR_DISEASE_NAME_TNB.equals(StringUtils.trim(disName))) {
                        // 
                        tumorInfo.setDiabetesHis(ReservationConstants.TUMOR_HIS_FOR_YES);
                    } else if (ReservationConstants.TUMOR_DISEASE_NAME_GXY.equals(StringUtils.trim(disName))) {
                        // 
                        tumorInfo.setHypertensionHis(ReservationConstants.TUMOR_HIS_FOR_YES);
                    } else if (ReservationConstants.TUMOR_DISEASE_NAME_FQZ.equals(StringUtils.trim(disName))) {
                        // 
                        tumorInfo.setEmphysemaHis(ReservationConstants.TUMOR_HIS_FOR_YES);
                    } else if (StringUtils.contains(disName, ReservationConstants.TUMOR_HIS_CHRONIC_OTHERS)) {
                        // 
                        tumorInfo.setOtherHisStatus(ReservationConstants.TUMOR_HIS_FOR_YES);
                        tumorInfo.setOtherHis(StringUtils.substring(disName, disName.indexOf(":") + 1));
                    }
                }
                tumorInfo.setHealthRecordIdForChronicDisease(treatDo.getId());
                tumorInfo.setDiseaseHisExist(ReservationConstants.TUMOR_DISEASE_EXIST_YES);
            }
        }

        jsonMap.put("postTumorInfoVO", tumorInfo);
        json.setData(jsonMap);
    }

    private void addHealthRecordForZLYY(Long patientUserId, PostTumorInfoVO tumorInfo) {
        if (null == patientUserId || null == tumorInfo) {
            return;
        }

        saveBasicInfoForZlyy(patientUserId, tumorInfo);
        // ?????
        saveFamilyHisAndDrugAllergyHis(patientUserId, tumorInfo);
    }

    private void addTreatmentHis(TreatmentHisDTO treat) {
        if (StringUtils.isBlank(treat.getId())) {
            healthMgr.addTreatmentHis(treat);
        } else {
            List<TreatmentHisDTO> list = new ArrayList<TreatmentHisDTO>();
            list.add(treat);
            healthMgr.updateTreatmentHis(list);
        }
    }

    private void saveFamilyHisAndDrugAllergyHis(Long patientUserId, PostTumorInfoVO tumorInfo) {
        List<PastMedicalHisDetailDTO> medicalHisList = new ArrayList<PastMedicalHisDetailDTO>();
        PastMedicalHisDetailDTO medicalHisDetail = null;
        // ???
        if (ReservationConstants.TUMOR_HIS_FOR_YES.equals(tumorInfo.getHisOfDrugAllergyStatus())) {
            medicalHisDetail = new PastMedicalHisDetailDTO();
            medicalHisDetail.setHisType(ReservationConstants.TUMOR_HIS_GMS);
            medicalHisDetail.setDisease(ReservationConstants.TUMOR_HIS_GMS_NAME);
            medicalHisDetail.setDrugName(tumorInfo.getHisOfDrugAllergy());

            String id = tumorInfo.getHealthRecordIdForDrugAllergy();
            if (StringUtils.isNotBlank(id)) {
                medicalHisDetail.setId(id);
                medicalHisList.add(medicalHisDetail);
            } else {
                healthMgr.addPastMedicalHis(patientUserId, medicalHisDetail);
            }
        } else {
            String id = tumorInfo.getHealthRecordIdForDrugAllergy();
            if (StringUtils.isNotBlank(id)) {
                healthMgr.removePastMedicalHis(patientUserId, id);
            }
        }

        if (ReservationConstants.TUMOR_HIS_FOR_YES.equals(tumorInfo.getFamilyHistoryStatus())) {
            // ??
            medicalHisDetail = new PastMedicalHisDetailDTO();
            medicalHisDetail.setHisType(ReservationConstants.TUMOR_HIS_JZS);
            medicalHisDetail.setDisease(ReservationConstants.TUMOR_HIS_JZS_NAME);
            medicalHisDetail.setDesc(tumorInfo.getFamilyHistory());
            String id = tumorInfo.getHealthRecordIdForFamilyHistory();
            if (StringUtils.isNotBlank(id)) {
                medicalHisDetail.setId(id);
                medicalHisList.add(medicalHisDetail);
            } else {
                healthMgr.addPastMedicalHis(patientUserId, medicalHisDetail);
            }
        } else {
            String id = tumorInfo.getHealthRecordIdForFamilyHistory();
            if (StringUtils.isNotBlank(id)) {
                healthMgr.removePastMedicalHis(patientUserId, id);
            }
        }

        // ?
        if (ReservationConstants.TUMOR_HIS_FOR_YES.equals(tumorInfo.getHisOfCancerDiseaseStatus())) {
            medicalHisDetail = new PastMedicalHisDetailDTO();
            medicalHisDetail.setHisType(ReservationConstants.TUMOR_HIS_JZS);
            medicalHisDetail.setDisease(ReservationConstants.TUMOR_HIS_ZLS_NAME);
            medicalHisDetail.setDesc(tumorInfo.getHisOfCancerDisease());
            String id = tumorInfo.getHealthRecordIdForCancerDisease();
            if (StringUtils.isNotBlank(id)) {
                medicalHisDetail.setId(id);
                medicalHisList.add(medicalHisDetail);
            } else {
                healthMgr.addPastMedicalHis(patientUserId, medicalHisDetail);
            }
        } else {
            String id = tumorInfo.getHealthRecordIdForCancerDisease();
            if (StringUtils.isNotBlank(id)) {
                healthMgr.removePastMedicalHis(patientUserId, id);
            }
        }

        if (CollectionUtils.isNotEmpty(medicalHisList)) {
            PastMedicalHisDTO dto = new PastMedicalHisDTO();
            dto.setMedicalHisList(medicalHisList);
            dto.setUserId(patientUserId);
            healthMgr.updatePastMedicalHis(dto);
        }

        if (ReservationConstants.TUMOR_HIS_FOR_YES.equals(tumorInfo.getDiseaseHisExist())) {
            String chrnDiseseaId = tumorInfo.getHealthRecordIdForChronicDisease();

            StringBuffer buffer = new StringBuffer();
            String diaHis = tumorInfo.getDiabetesHis();
            if (StringUtils.isNotBlank(diaHis)) {
                buffer.append(diaHis + ";");
            }

            String hyperHis = tumorInfo.getHypertensionHis();
            if (StringUtils.isNotBlank(hyperHis)) {
                buffer.append(hyperHis + ";");
            }

            String emphHis = tumorInfo.getEmphysemaHis();
            if (StringUtils.isNotBlank(emphHis)) {
                buffer.append(emphHis + ";");
            }

            String otherHis = tumorInfo.getOtherHisStatus();
            String otherHisValue = tumorInfo.getOtherHis();
            if (StringUtils.isNotBlank(otherHis) && StringUtils.isNotBlank(otherHisValue)) {
                buffer.append(otherHis + ":" + otherHisValue);
            }

            TreatmentHisDTO treat = new TreatmentHisDTO();
            treat.setUserId(Long.valueOf(patientUserId));
            treat.setDisease(buffer.toString());
            treat.setTreatOrg(ReservationConstants.TUMOR_HOSP_NAME);
            treat.setId(chrnDiseseaId);
            addTreatmentHis(treat);
        } else {
            String id = tumorInfo.getHealthRecordIdForChronicDisease();
            if (StringUtils.isNotBlank(id)) {
                healthMgr.removeTreatmentHis(patientUserId, id);
            }
        }

    }

    private void saveBasicInfoForZlyy(Long patientUserId, PostTumorInfoVO tumorInfo) {
        // 1???
        BasicInfoDTO basic = new BasicInfoDTO();
        basic.setAddress(tumorInfo.getAddrs());
        basic.setUserId(patientUserId);
        basic.setEducationalStatus(tumorInfo.getEducation());
        basic.setJob(tumorInfo.getProfession());
        basic.setNationality(tumorInfo.getNationality());
        basic.setReligion(tumorInfo.getReligion());
        basic.setEmail(tumorInfo.getEmail());
        basic.setFax(tumorInfo.getFax());
        healthMgr.updateBasicInfo(basic);
    }

    /**
     * ?
     * 
     * @param json
     * @param jsonMap
     * @param patient
     * @return
     */
    private boolean checkPatientInfo(OperationJsonObject json, PatientInfoDO patient) {
        if (StringUtils.isBlank(patient.getPatient_name())) {
            json.setHasError(Boolean.TRUE);
            json.setMessage(UserPatientConstants.MUST_NAME);
            return Boolean.FALSE;
        }
        if (StringUtils.isBlank(patient.getPatient_cert_no())) {
            json.setHasError(Boolean.TRUE);
            json.setMessage(UserPatientConstants.MUST_CERNO);
            return Boolean.FALSE;
        }
        if (StringUtils.isBlank(patient.getPatient_mobile())) {
            json.setHasError(Boolean.TRUE);
            json.setMessage(UserPatientConstants.MUST_MOBILE);
            return Boolean.FALSE;
        }
        if (null == patient.getRelationship()) {
            json.setHasError(Boolean.TRUE);
            json.setMessage(UserPatientConstants.MUST_RELATIONSHIP);
            return Boolean.FALSE;
        }
        if (null == patient.getPatient_sex()) {
            json.setHasError(Boolean.TRUE);
            json.setMessage(UserPatientConstants.MUST_SEX);
            return Boolean.FALSE;
        }
        if (StringUtils.isBlank(patient.getPatient_birthday())) {
            json.setHasError(Boolean.TRUE);
            json.setMessage(UserPatientConstants.MUST_BIR);
            return Boolean.FALSE;
        }
        return Boolean.TRUE;
    }

    /**
     * ??????
     * 
     * @author wangbiao
     * @param model
     * @param postReservationVO
     * @param type
     * @return String
     */
    public String submitOrder(ModelMap model, PostReservationVO postReservationVO, String type, String code,
            String validCode) {
        // ********************************??********************************
        // ?id,??
        String userid = UserCookieUtil.getUserId(request) + StringUtils.EMPTY;// ""
        if (StringUtils.isBlank(userid) || !BizCommonUtils.isUUID(postReservationVO.getHospitalId())
                || !BizCommonUtils.isUUID(postReservationVO.getShiftCaseId())) {
            // 
            IllegalUserLog illegaluserlog = new IllegalUserLog();
            illegaluserlog.setServerName(CommonUtils.getServerName(request));
            illegaluserlog.setRequestUrl(CommonUtils.getRequestUrl(request));
            illegaluserlog.setSource("1");// 1-?2-html5
            illegaluserlog.setCuserId(userid);
            illegaluserlog.setExpertId(postReservationVO.getExpertId());
            illegaluserlog.setHospDeptId(postReservationVO.getDeptId());
            illegaluserlog.setHospitalId(postReservationVO.getHospitalId());
            illegaluserlog.setScid(postReservationVO.getShiftCaseId());
            illegaluserlog.setRemark("??");
            illegaluserlog.setType("2");// 
            illegaluserlog.setOrderStep("4");// ?
            log.error(illegaluserlog.toString());

            model.put("error_message", "???");
            return CommonUtils.getPartnersOrderErrorPage(type);
        }
        UserDO userdo = userManager.findUserByUserId(Long.valueOf(userid));
        if (userdo == null || userdo.getStatus() == null || userdo.getStatus().intValue() != 1
                || UserUtil.isBindMobile(userdo)) {
            // 
            IllegalUserLog illegaluserlog = new IllegalUserLog();
            illegaluserlog.setServerName(CommonUtils.getServerName(request));
            illegaluserlog.setRequestUrl(CommonUtils.getRequestUrl(request));
            illegaluserlog.setSource("1");// 1-?2-html5
            illegaluserlog.setCuserId(userid);
            illegaluserlog.setExpertId(postReservationVO.getExpertId());
            illegaluserlog.setHospDeptId(postReservationVO.getDeptId());
            illegaluserlog.setHospitalId(postReservationVO.getHospitalId());
            illegaluserlog.setScid(postReservationVO.getShiftCaseId());
            illegaluserlog.setRemark("??");
            illegaluserlog.setType("3");// 
            illegaluserlog.setOrderStep("4");// ?
            log.error(illegaluserlog.toString());

            model.put("error_message", "?");
            UserCookieUtil.logout(request);
            return CommonUtils.getPartnersOrderErrorPage(type);
        }

        // ???;key=??+id+?id
        String key = userdo.getMobile() + userid + postReservationVO.getShiftCaseId();
        // ??,key=??+id+?id
        if (!codeCacheManager.verifyMobileCode(VerifyTypeEnum.RES_CODE_MOBILE, key, code)) {
            // 
            IllegalUserLog illegaluserlog = new IllegalUserLog();
            illegaluserlog.setServerName(CommonUtils.getServerName(request));
            illegaluserlog.setRequestUrl(CommonUtils.getRequestUrl(request));
            illegaluserlog.setSource("1");// 1-?2-html5
            illegaluserlog.setCuserId(userid);
            illegaluserlog.setExpertId(postReservationVO.getExpertId());
            illegaluserlog.setHospDeptId(postReservationVO.getDeptId());
            illegaluserlog.setHospitalId(postReservationVO.getHospitalId());
            illegaluserlog.setScid(postReservationVO.getShiftCaseId());
            illegaluserlog.setRemark(ReservationMsgConstants.ERR_MSG_MOBILE_CODE_ERROR);
            illegaluserlog.setType("2");// 
            illegaluserlog.setOrderStep("4");// ?
            log.error(illegaluserlog.toString());

            // ??,?key
            codeCacheManager.delCode(VerifyTypeEnum.RES_CODE_MOBILE,
                    VCodeCachePrefixEnum.CODE_PRE.getValue() + key);
            model.put("error_message", ReservationMsgConstants.ERR_MSG_MOBILE_CODE_ERROR);
            return CommonUtils.getPartnersOrderErrorPage(type);
        }
        // ??
        codeCacheManager.delCode(VerifyTypeEnum.RES_CODE_MOBILE, VCodeCachePrefixEnum.CODE_PRE.getValue() + key);

        // ********************************??********************************
        String validcodekey = userid + postReservationVO.getShiftCaseId();
        if (!orderValidLimitCacheManager.verifyValidCode(validcodekey, validCode)) {
            // 
            IllegalUserLog illegaluserlog = new IllegalUserLog();
            illegaluserlog.setServerName(CommonUtils.getServerName(request));
            illegaluserlog.setRequestUrl(CommonUtils.getRequestUrl(request));
            illegaluserlog.setSource("1");// 1-?2-html5
            illegaluserlog.setCuserId(userid);
            illegaluserlog.setExpertId(postReservationVO.getExpertId());
            illegaluserlog.setHospDeptId(postReservationVO.getDeptId());
            illegaluserlog.setHospitalId(postReservationVO.getHospitalId());
            illegaluserlog.setScid(postReservationVO.getShiftCaseId());
            illegaluserlog.setRemark(ReservationMsgConstants.ERR_MSG_CODE_ERROR);
            illegaluserlog.setType("2");// 
            illegaluserlog.setOrderStep("4");// ?
            log.error(illegaluserlog.toString());

            orderValidLimitCacheManager.delValidCode(validcodekey);
            model.put("error_message", ReservationMsgConstants.ERR_MSG_CODE_ERROR);
            return CommonUtils.getPartnersOrderErrorPage(type);
        }
        orderValidLimitCacheManager.delValidCode(validcodekey);

        // ********************************/???********************************
        // ??
        String signdata = postReservationVO.getSigndata();
        if (StringUtils.isBlank(signdata)) {
            // 
            IllegalUserLog illegaluserlog = new IllegalUserLog();
            illegaluserlog.setServerName(CommonUtils.getServerName(request));
            illegaluserlog.setRequestUrl(CommonUtils.getRequestUrl(request));
            illegaluserlog.setSource("1");// 1-?2-html5
            illegaluserlog.setCuserId(userid);
            illegaluserlog.setExpertId(postReservationVO.getExpertId());
            illegaluserlog.setHospDeptId(postReservationVO.getDeptId());
            illegaluserlog.setHospitalId(postReservationVO.getHospitalId());
            illegaluserlog.setScid(postReservationVO.getShiftCaseId());
            illegaluserlog.setRemark(
                    "???,UserName:" + userdo.getUserName() + ",CertNo:" + userdo.getCertNo());
            illegaluserlog.setType("2");// 
            illegaluserlog.setOrderStep("4");// ?
            log.error(illegaluserlog.toString());

            model.put("error_message",
                    "??????");
            return CommonUtils.getPartnersOrderErrorPage(type);
        }
        boolean hasSignDataKeyInCache = orderValidLimitCacheManager.hasSignDataKeyInCache(userid);
        if (hasSignDataKeyInCache) {
            String signdatacache = orderValidLimitCacheManager.getSignData(userid);
            log.info("___________?:signdatacache=" + signdatacache);
            orderValidLimitCacheManager.delSignData(userid);
            log.info("___________?:????signdata=" + signdata);
            // ??
            String datasign = DESUtil.DESDecode(signdata, ReservationConstants.DESC_ORDER_KEY);
            log.info("___________?:?datasign=" + datasign);
            if (!datasign.equals(signdatacache)) {
                // 
                IllegalUserLog illegaluserlog = new IllegalUserLog();
                illegaluserlog.setServerName(CommonUtils.getServerName(request));
                illegaluserlog.setRequestUrl(CommonUtils.getRequestUrl(request));
                illegaluserlog.setSource("1");// 1-?2-html5
                illegaluserlog.setCuserId(userid);
                illegaluserlog.setExpertId(postReservationVO.getExpertId());
                illegaluserlog.setHospDeptId(postReservationVO.getDeptId());
                illegaluserlog.setHospitalId(postReservationVO.getHospitalId());
                illegaluserlog.setScid(postReservationVO.getShiftCaseId());
                illegaluserlog.setRemark("?????,UserName:"
                        + userdo.getUserName() + ",CertNo:" + userdo.getCertNo());
                illegaluserlog.setType("2");// 
                illegaluserlog.setOrderStep("4");// ?
                log.error(illegaluserlog.toString());

                model.put("error_message",
                        "??????");
                return CommonUtils.getPartnersOrderErrorPage(type);
            }
        } else {
            // 
            IllegalUserLog illegaluserlog = new IllegalUserLog();
            illegaluserlog.setServerName(CommonUtils.getServerName(request));
            illegaluserlog.setRequestUrl(CommonUtils.getRequestUrl(request));
            illegaluserlog.setSource("1");// 1-?2-html5
            illegaluserlog.setCuserId(userid);
            illegaluserlog.setExpertId(postReservationVO.getExpertId());
            illegaluserlog.setHospDeptId(postReservationVO.getDeptId());
            illegaluserlog.setHospitalId(postReservationVO.getHospitalId());
            illegaluserlog.setScid(postReservationVO.getShiftCaseId());
            illegaluserlog.setRemark("?????,UserName:" + userdo.getUserName()
                    + ",CertNo:" + userdo.getCertNo());
            illegaluserlog.setType("2");// 
            illegaluserlog.setOrderStep("4");// ?
            log.error(illegaluserlog.toString());

            model.put("error_message",
                    "??????");
            return CommonUtils.getPartnersOrderErrorPage(type);
        }

        // ?
        boolean hasOrderSpeedTimeKeyInCache = orderValidLimitCacheManager.hasOrderSpeedTimeKeyInCache(userid);
        if (hasOrderSpeedTimeKeyInCache) {
            String orderTime = orderValidLimitCacheManager.getOrderSpeedTime(userid);
            log.info("___________?:timeOld=" + orderTime);
            long timeOld = Long.parseLong(orderTime);
            Calendar nowDate = Calendar.getInstance();
            nowDate.setTime(new Date());
            long timeNow = nowDate.getTimeInMillis() / 1000;
            log.info("___________?:timeNow=" + timeNow);

            if ((timeNow - timeOld) <= orderValidLimitCacheManager.getOrderSpeedTime()) {
                // 
                IllegalUserLog illegaluserlog = new IllegalUserLog();
                illegaluserlog.setServerName(CommonUtils.getServerName(request));
                illegaluserlog.setRequestUrl(CommonUtils.getRequestUrl(request));
                illegaluserlog.setSource("1");// 1-?2-html5
                illegaluserlog.setCuserId(userid);
                illegaluserlog.setExpertId(postReservationVO.getExpertId());
                illegaluserlog.setHospDeptId(postReservationVO.getDeptId());
                illegaluserlog.setHospitalId(postReservationVO.getHospitalId());
                illegaluserlog.setScid(postReservationVO.getShiftCaseId());
                illegaluserlog.setRemark("?,:" + (timeNow - timeOld));
                illegaluserlog.setType("10");// 
                illegaluserlog.setOrderStep("4");// ?
                log.error(illegaluserlog.toString());

                model.put("error_message", "?????");
                return CommonUtils.getPartnersOrderErrorPage(type);
            }
        } else {
            // 
            IllegalUserLog illegaluserlog = new IllegalUserLog();
            illegaluserlog.setServerName(CommonUtils.getServerName(request));
            illegaluserlog.setRequestUrl(CommonUtils.getRequestUrl(request));
            illegaluserlog.setSource("1");// 1-?2-html5
            illegaluserlog.setCuserId(userid);
            illegaluserlog.setExpertId(postReservationVO.getExpertId());
            illegaluserlog.setHospDeptId(postReservationVO.getDeptId());
            illegaluserlog.setHospitalId(postReservationVO.getHospitalId());
            illegaluserlog.setScid(postReservationVO.getShiftCaseId());
            illegaluserlog.setRemark("?");
            illegaluserlog.setType("2");// 
            illegaluserlog.setOrderStep("4");// ?
            log.error(illegaluserlog.toString());

            model.put("error_message", "???");
            return CommonUtils.getPartnersOrderErrorPage(type);
        }

        // ********************************?************************************
        // ?
        ShiftCaseDO shiftCaseDO = shiftCaseManager.getShiftCase(postReservationVO.getHospitalId(),
                postReservationVO.getShiftCaseId());
        if (null == shiftCaseDO) {
            // 
            IllegalUserLog illegaluserlog = new IllegalUserLog();
            illegaluserlog.setServerName(CommonUtils.getServerName(request));
            illegaluserlog.setRequestUrl(CommonUtils.getRequestUrl(request));
            illegaluserlog.setSource("1");// 1-?2-html5
            illegaluserlog.setCuserId(userid);
            illegaluserlog.setExpertId(postReservationVO.getExpertId());
            illegaluserlog.setHospDeptId(postReservationVO.getDeptId());
            illegaluserlog.setHospitalId(postReservationVO.getHospitalId());
            illegaluserlog.setScid(postReservationVO.getShiftCaseId());
            illegaluserlog.setRemark("??");
            illegaluserlog.setType("4");// 
            illegaluserlog.setOrderStep("4");// ?
            log.error(illegaluserlog.toString());

            model.put("error_message", ReservationMsgConstants.ERR_MSG_SHIFT_CASE_NOT_FOUND);
            return CommonUtils.getPartnersOrderErrorPage(type);
        }

        // ??
        this.setLeftPageValue(model, shiftCaseDO);
        BaseJsonObject msg = this.checkShiftCase(shiftCaseDO);
        if (msg.getHasError()) {
            // 
            IllegalUserLog illegaluserlog = new IllegalUserLog();
            illegaluserlog.setServerName(CommonUtils.getServerName(request));
            illegaluserlog.setRequestUrl(CommonUtils.getRequestUrl(request));
            illegaluserlog.setSource("1");// 1-?2-html5
            illegaluserlog.setCuserId(userid);
            illegaluserlog.setExpertId(postReservationVO.getExpertId());
            illegaluserlog.setHospDeptId(postReservationVO.getDeptId());
            illegaluserlog.setHospitalId(postReservationVO.getHospitalId());
            illegaluserlog.setScid(postReservationVO.getShiftCaseId());
            illegaluserlog.setRemark(msg.getMessage());
            illegaluserlog.setType("5");// 
            illegaluserlog.setOrderStep("4");// ?
            log.error(illegaluserlog.toString());

            // ?
            model.put("error_message", msg.getMessage());
            model.put("hospDeptId", shiftCaseDO.getDeptUuid());
            return CommonUtils.getPartnersOrderErrorPage(type);
        }

        // ********************************ip?************************************
        // ?,ip?
        OrderIpLimitVO orderIpLimitVO = new OrderIpLimitVO();
        orderIpLimitVO.setUserid(userid);
        OperateResult<OrderResultDO> orderResult = this.addOrder(postReservationVO, orderIpLimitVO);
        // ip???
        if (StringUtils.isNotBlank(orderIpLimitVO.getErrorMessage())) {
            // 
            IllegalUserLog illegaluserlog = new IllegalUserLog();
            illegaluserlog.setServerName(CommonUtils.getServerName(request));
            illegaluserlog.setRequestUrl(CommonUtils.getRequestUrl(request));
            illegaluserlog.setSource("1");// 1-?2-html5
            illegaluserlog.setCuserId(userid);
            illegaluserlog.setExpertId(postReservationVO.getExpertId());
            illegaluserlog.setHospDeptId(postReservationVO.getDeptId());
            illegaluserlog.setHospitalId(postReservationVO.getHospitalId());
            illegaluserlog.setScid(postReservationVO.getShiftCaseId());
            illegaluserlog.setRemark(orderIpLimitVO.getErrorMessage());
            illegaluserlog.setType("2");// 
            illegaluserlog.setOrderStep("4");// ?
            log.error(illegaluserlog.toString());

            model.put("error_message", orderIpLimitVO.getErrorMessage());
            return CommonUtils.getPartnersOrderErrorPage(type);
        }

        // ********************************?**********************************************
        // ??
        boolean needPay = false;
        if (orderResult != null && orderResult.getDataResult() != null) {
            if (2 == orderResult.getDataResult().getPayState()) {
                needPay = true;
            }
        }

        // ???
        boolean isSuccess = this.afterOrderHandle(model, postReservationVO, orderResult, needPay, shiftCaseDO,
                userdo.getMobile(), userdo.getEmail());
        // ?
        this.addPatientTreatInfo(postReservationVO, orderResult);
        // ?????
        if (ReservationConstants.TUMOR_ZZLZ_UUID.equalsIgnoreCase(postReservationVO.getHospitalId())) {
            addHealthRecordForZLYY(postReservationVO.getPatient().getPatient_id(),
                    postReservationVO.getTumorInfo());
        }
        if (isSuccess) {
            // ???
            remindManager.startRemind(userid, RemindConstants.TYPE);
            if (needPay) {
                // 
                IllegalUserLog illegaluserlog = new IllegalUserLog();
                illegaluserlog.setServerName(CommonUtils.getServerName(request));
                illegaluserlog.setRequestUrl(CommonUtils.getRequestUrl(request));
                illegaluserlog.setSource("1");// 1-?2-html5
                illegaluserlog.setCuserId(userid);
                illegaluserlog.setExpertId(postReservationVO.getExpertId());
                illegaluserlog.setHospDeptId(postReservationVO.getDeptId());
                illegaluserlog.setHospitalId(postReservationVO.getHospitalId());
                illegaluserlog.setScid(postReservationVO.getShiftCaseId());
                illegaluserlog.setRemark("??");
                illegaluserlog.setType("12");// 
                illegaluserlog.setOrderStep("4");// ?
                log.error(illegaluserlog.toString());

                return CommonUtils.getPartnersPaymentPage(model, type);
            }
            return CommonUtils.getPartnersSucessPage(model, type);
        } else {
            // 
            IllegalUserLog illegaluserlog = new IllegalUserLog();
            illegaluserlog.setServerName(CommonUtils.getServerName(request));
            illegaluserlog.setRequestUrl(CommonUtils.getRequestUrl(request));
            illegaluserlog.setSource("1");// 1-?2-html5
            illegaluserlog.setCuserId(userid);
            illegaluserlog.setExpertId(postReservationVO.getExpertId());
            illegaluserlog.setHospDeptId(postReservationVO.getDeptId());
            illegaluserlog.setHospitalId(postReservationVO.getHospitalId());
            illegaluserlog.setScid(postReservationVO.getShiftCaseId());
            illegaluserlog.setRemark((String) model.get("error_message"));
            illegaluserlog.setType("11");// 
            illegaluserlog.setOrderStep("4");// ?
            log.error(illegaluserlog.toString());

            return CommonUtils.getPartnersFailePage(model, type);
        }
    }

    /**
     * ??
     * 
     * @param shiftCaseDO
     * @return BaseJsonObject
     */
    public BaseJsonObject isCanReservation(ShiftCaseDO shiftCaseDO, Long userId) {
        BaseJsonObject baseMsg = new BaseJsonObject();
        if (shiftCaseDO == null || shiftCaseDO.getDeptUuid() == null) {
            baseMsg.setMessage(ReservationMsgConstants.ERR_MSG_SHIFT_CASE_NOT_FOUND);
            baseMsg.setHasError(Boolean.TRUE);
            return baseMsg;
        }

        OrderRequestInfoQuery orderRequestInfoQuery = new OrderRequestInfoQuery();
        orderRequestInfoQuery.setUserId(userId);
        List<String> hospdeptids = new ArrayList<String>();
        hospdeptids.add(shiftCaseDO.getDeptUuid());
        orderRequestInfoQuery.setHospdeptids(hospdeptids);
        List<Integer> states = new ArrayList<Integer>();
        states.add(0);
        states.add(1);
        orderRequestInfoQuery.setStates(states);
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat destsmf = new SimpleDateFormat("yyyyMMdd");
        orderRequestInfoQuery.setStartClinicalDate(destsmf.format(calendar.getTime()));
        Integer result = applyHaoyuanManager.getCountByOrderRequestQuery(orderRequestInfoQuery);
        if (result > 0) {
            baseMsg.setMessage(ReservationMsgConstants.CAN_NOT_RESERVATION);
            baseMsg.setHasError(Boolean.TRUE);
            return baseMsg;
        }
        baseMsg.setHasError(Boolean.FALSE);
        return baseMsg;
    }

    /**
     * ?
     * 
     * @return String
     */
    public String getMobilevalidcodepwd() {
        return (String) mursiFreeMarkerViewResolver.getAttributesMap().get("mobilevalidcodepwd");
    }
}